Skip to content

Commit

Permalink
move subtree depth constants to genesis constants, Runtime_config.dae…
Browse files Browse the repository at this point in the history
…mon; use block window duration from runtime config and not compile config; remove compile_config from impacted contexts
  • Loading branch information
deepthiskumar committed Nov 12, 2024
1 parent d26d015 commit db10629
Show file tree
Hide file tree
Showing 36 changed files with 184 additions and 155 deletions.
4 changes: 1 addition & 3 deletions src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1045,13 +1045,11 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee =
let module Context = struct
let logger = logger

let precomputed_values = precomputed_values
let genesis_constants = precomputed_values.genesis_constants

let constraint_constants = precomputed_values.constraint_constants

let consensus_constants = precomputed_values.consensus_constants

let compile_config = compile_config
end in
let consensus_local_state =
Consensus.Data.Local_state.create
Expand Down
26 changes: 17 additions & 9 deletions src/lib/block_producer/block_producer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ module type CONTEXT = sig
val zkapp_cmd_limit : int option ref

val vrf_poll_interval : Time.Span.t

val compile_config : Mina_compile_config.t
end

type Structured_log_events.t += Block_produced
Expand Down Expand Up @@ -664,7 +662,12 @@ let run ~context:(module Context : CONTEXT) ~vrf_evaluator ~prover ~verifier
~transition_writer ~set_next_producer_timing ~log_block_creation
~block_reward_threshold ~block_produced_bvar ~vrf_evaluation_state ~net
~zkapp_cmd_limit_hardcap =
let open Context in
let module Consensus_context = struct
include Context

let genesis_constants = precomputed_values.genesis_constants
end in
let open Consensus_context in
let constraint_constants = precomputed_values.constraint_constants in
let consensus_constants = precomputed_values.consensus_constants in
O1trace.sync_thread "produce_blocks" (fun () ->
Expand Down Expand Up @@ -849,7 +852,7 @@ let run ~context:(module Context : CONTEXT) ~vrf_evaluator ~prover ~verifier
Debug_assert.debug_assert (fun () ->
[%test_result: [ `Take | `Keep ]]
(Consensus.Hooks.select
~context:(module Context)
~context:(module Consensus_context)
~existing:
(With_hash.map ~f:Mina_block.consensus_state
previous_transition )
Expand All @@ -864,7 +867,7 @@ let run ~context:(module Context : CONTEXT) ~vrf_evaluator ~prover ~verifier
in
[%test_result: [ `Take | `Keep ]]
(Consensus.Hooks.select
~context:(module Context)
~context:(module Consensus_context)
~existing:root_consensus_state_with_hashes
~candidate:consensus_state_with_hashes )
~expect:`Take
Expand Down Expand Up @@ -937,7 +940,7 @@ let run ~context:(module Context : CONTEXT) ~vrf_evaluator ~prover ~verifier
`This_block_was_not_received_via_gossip
>>= Validation.validate_frontier_dependencies
~to_header:Mina_block.header
~context:(module Context)
~context:(module Consensus_context)
~root_block:
( Transition_frontier.root frontier
|> Breadcrumb.block_with_hash )
Expand Down Expand Up @@ -1412,10 +1415,15 @@ let run_precomputed ~context:(module Context : CONTEXT) ~verifier ~trust_system
Header.protocol_state
@@ Mina_block.header (With_hash.data previous_transition)
in
let module Consensus_context = struct
include Context

let genesis_constants = precomputed_values.genesis_constants
end in
Debug_assert.debug_assert (fun () ->
[%test_result: [ `Take | `Keep ]]
(Consensus.Hooks.select
~context:(module Context)
~context:(module Consensus_context)
~existing:
(With_hash.map ~f:Mina_block.consensus_state
previous_transition )
Expand All @@ -1430,7 +1438,7 @@ let run_precomputed ~context:(module Context : CONTEXT) ~verifier ~trust_system
in
[%test_result: [ `Take | `Keep ]]
(Consensus.Hooks.select
~context:(module Context)
~context:(module Consensus_context)
~existing:root_consensus_state_with_hashes
~candidate:consensus_state_with_hashes )
~expect:`Take
Expand Down Expand Up @@ -1468,7 +1476,7 @@ let run_precomputed ~context:(module Context : CONTEXT) ~verifier ~trust_system
previous_protocol_state )
>>= Validation.validate_frontier_dependencies
~to_header:Mina_block.header
~context:(module Context)
~context:(module Consensus_context)
~root_block:
( Transition_frontier.root frontier
|> Breadcrumb.block_with_hash )
Expand Down
58 changes: 32 additions & 26 deletions src/lib/bootstrap_controller/bootstrap_controller.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ module type CONTEXT = sig
val constraint_constants : Genesis_constants.Constraint_constants.t

val consensus_constants : Consensus.Constants.t

val compile_config : Mina_compile_config.t
end

type Structured_log_events.t += Bootstrap_complete
Expand Down Expand Up @@ -69,6 +67,8 @@ let worth_getting_root ({ context = (module Context); _ } as t) candidate =
let module Context = struct
include Context

let genesis_constants = precomputed_values.genesis_constants

let logger =
Logger.extend logger
[ ( "selection_context"
Expand Down Expand Up @@ -153,7 +153,7 @@ let to_consensus_state h =
the existing one, then reset the Sync_ledger's target by calling
[start_sync_job_with_peer] function. *)
let on_transition ({ context = (module Context); _ } as t) ~sender
~root_sync_ledger ~genesis_constants candidate_header =
~root_sync_ledger candidate_header =
let open Context in
let candidate_consensus_state =
With_hash.map ~f:to_consensus_state candidate_header
Expand All @@ -176,7 +176,7 @@ let on_transition ({ context = (module Context); _ } as t) ~sender
match%bind
Sync_handler.Root.verify
~context:(module Context)
~verifier:t.verifier ~genesis_constants candidate_consensus_state
~verifier:t.verifier candidate_consensus_state
peer_root_with_proof.data
with
| Ok (`Root root, `Best_tip best_tip) ->
Expand All @@ -190,7 +190,7 @@ let on_transition ({ context = (module Context); _ } as t) ~sender
incoming transitions, add those to the transition_cache and calls
[on_transition] function. *)
let sync_ledger ({ context = (module Context); _ } as t) ~preferred
~root_sync_ledger ~transition_graph ~sync_ledger_reader ~genesis_constants =
~root_sync_ledger ~transition_graph ~sync_ledger_reader =
let open Context in
let query_reader = Sync_ledger.Db.query_reader root_sync_ledger in
let response_writer = Sync_ledger.Db.answer_writer root_sync_ledger in
Expand Down Expand Up @@ -233,11 +233,15 @@ let sync_ledger ({ context = (module Context); _ } as t) ~preferred
] ;

Deferred.ignore_m
@@ on_transition t ~sender ~root_sync_ledger ~genesis_constants
header_with_hash )
@@ on_transition t ~sender ~root_sync_ledger header_with_hash )
else Deferred.unit )

let external_transition_compare ~context:(module Context : CONTEXT) =
let module Consensus_context = struct
include Context

let genesis_constants = precomputed_values.genesis_constants
end in
let get_consensus_state =
Fn.compose Protocol_state.consensus_state Mina_block.Header.protocol_state
in
Expand All @@ -251,7 +255,9 @@ let external_transition_compare ~context:(module Context : CONTEXT) =
then 0
else if
Consensus.Hooks.equal_select_status `Keep
@@ Consensus.Hooks.select ~context:(module Context) ~existing ~candidate
@@ Consensus.Hooks.select
~context:(module Consensus_context)
~existing ~candidate
then -1
else 1 )
~f:(With_hash.map ~f:get_consensus_state)
Expand All @@ -274,10 +280,6 @@ let run ~context:(module Context : CONTEXT) ~trust_system ~verifier ~network
~persistent_frontier ~initial_root_transition ~catchup_mode =
let open Context in
O1trace.thread "bootstrap" (fun () ->
let genesis_constants =
Precomputed_values.genesis_constants precomputed_values
in
let constraint_constants = precomputed_values.constraint_constants in
let rec loop previous_cycles =
let sync_ledger_pipe = "sync ledger pipe" in
let sync_ledger_reader, sync_ledger_writer =
Expand Down Expand Up @@ -332,16 +334,21 @@ let run ~context:(module Context : CONTEXT) ~trust_system ~verifier ~network
temp_persistent_root_instance
in
(* step 1. download snarked_ledger *)
let module Consensus_context = struct
include Context

let genesis_constants = precomputed_values.genesis_constants
end in
let%bind sync_ledger_time, (hash, sender, expected_staged_ledger_hash) =
time_deferred
(let root_sync_ledger =
Sync_ledger.Db.create temp_snarked_ledger
~context:(module Context)
~context:(module Consensus_context)
~trust_system
in
don't_wait_for
(sync_ledger t ~preferred:preferred_peers ~root_sync_ledger
~transition_graph ~sync_ledger_reader ~genesis_constants ) ;
~transition_graph ~sync_ledger_reader ) ;
(* We ignore the resulting ledger returned here since it will always
* be the same as the ledger we started with because we are syncing
* a db ledger. *)
Expand Down Expand Up @@ -568,7 +575,7 @@ let run ~context:(module Context : CONTEXT) ~trust_system ~verifier ~network
[%log info] "Synchronizing consensus local state" ;
let%map result =
Consensus.Hooks.sync_local_state
~context:(module Context)
~context:(module Consensus_context)
~local_state:consensus_local_state ~trust_system
~glue_sync_ledger:
(Mina_networking.glue_sync_ledger t.network)
Expand Down Expand Up @@ -619,7 +626,7 @@ let run ~context:(module Context : CONTEXT) ~trust_system ~verifier ~network
bootstrapping: " ^ msg )
in
Transition_frontier.load
~context:(module Context)
~context:(module Consensus_context)
~retry_with_fresh_db:false ~verifier ~consensus_local_state
~persistent_root ~persistent_frontier ~catchup_mode ()
>>| function
Expand Down Expand Up @@ -661,7 +668,7 @@ let run ~context:(module Context : CONTEXT) ~trust_system ~verifier ~network
in
Consensus.Hooks.equal_select_status `Take
@@ Consensus.Hooks.select
~context:(module Context)
~context:(module Consensus_context)
~existing:root_consensus_state
~candidate:
(With_hash.map
Expand Down Expand Up @@ -730,8 +737,6 @@ let%test_module "Bootstrap_controller tests" =

let constraint_constants = precomputed_values.constraint_constants

let compile_config = Mina_compile_config.For_unit_tests.t

module Context = struct
let logger = Logger.create ()

Expand All @@ -741,8 +746,6 @@ let%test_module "Bootstrap_controller tests" =
Genesis_constants.For_unit_tests.Constraint_constants.t

let consensus_constants = precomputed_values.consensus_constants

let compile_config = compile_config
end

let verifier =
Expand Down Expand Up @@ -791,8 +794,7 @@ let%test_module "Bootstrap_controller tests" =
let%bind fake_network =
Fake_network.Generator.(
gen ~precomputed_values ~verifier ~max_frontier_length
~compile_config [ fresh_peer; fresh_peer ]
~use_super_catchup:false)
[ fresh_peer; fresh_peer ] ~use_super_catchup:false)
in
let%map make_branch =
Transition_frontier.Breadcrumb.For_tests.gen_seq ~precomputed_values
Expand Down Expand Up @@ -820,17 +822,21 @@ let%test_module "Bootstrap_controller tests" =
let bootstrap =
make_non_running_bootstrap ~genesis_root ~network:me.network
in
let module Consensus_context = struct
include Context

let genesis_constants = precomputed_values.genesis_constants
end in
let root_sync_ledger =
Sync_ledger.Db.create
(Transition_frontier.root_snarked_ledger me.state.frontier)
~context:(module Context)
~context:(module Consensus_context)
~trust_system
in
Async.Thread_safe.block_on_async_exn (fun () ->
let sync_deferred =
sync_ledger bootstrap ~root_sync_ledger ~transition_graph
~preferred:[] ~sync_ledger_reader
~genesis_constants:Genesis_constants.For_unit_tests.t
in
let%bind () =
Deferred.List.iter branch ~f:(fun breadcrumb ->
Expand Down Expand Up @@ -927,7 +933,7 @@ let%test_module "Bootstrap_controller tests" =
Quickcheck.test ~trials:1
Fake_network.Generator.(
gen ~precomputed_values ~verifier ~max_frontier_length
~use_super_catchup:false ~compile_config
~use_super_catchup:false
[ fresh_peer
; peer_with_branch
~frontier_branch_size:((max_frontier_length * 2) + 2)
Expand Down
2 changes: 0 additions & 2 deletions src/lib/bootstrap_controller/bootstrap_controller.mli
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ module type CONTEXT = sig
val constraint_constants : Genesis_constants.Constraint_constants.t

val consensus_constants : Consensus.Constants.t

val compile_config : Mina_compile_config.t
end

type Structured_log_events.t += Bootstrap_complete [@@deriving register_event]
Expand Down
2 changes: 1 addition & 1 deletion src/lib/consensus/intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module type CONTEXT = sig

val consensus_constants : Constants.t

val compile_config : Mina_compile_config.t
val genesis_constants : Genesis_constants.t
end

module type Constants = sig
Expand Down
6 changes: 3 additions & 3 deletions src/lib/consensus/proof_of_stake.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module Make_str (A : Wire_types.Concrete) = struct

val consensus_constants : Constants.t

val compile_config : Mina_compile_config.t
val genesis_constants : Genesis_constants.t
end

let make_checked t = Snark_params.Tick.Run.make_checked t
Expand Down Expand Up @@ -3111,7 +3111,7 @@ module Make_str (A : Wire_types.Concrete) = struct

let consensus_constants = Lazy.force Constants.for_unit_tests

let compile_config = Mina_compile_config.For_unit_tests.t
let genesis_constants = Genesis_constants.For_unit_tests.t
end in
(* Even when consensus constants are of prod sizes, candidate should still trigger a bootstrap *)
should_bootstrap_len
Expand Down Expand Up @@ -3439,7 +3439,7 @@ module Make_str (A : Wire_types.Concrete) = struct

let consensus_constants = constants

let compile_config = Mina_compile_config.For_unit_tests.t
let genesis_constants = Genesis_constants.For_unit_tests.t
end

let test_update constraint_constants =
Expand Down
Loading

0 comments on commit db10629

Please sign in to comment.