Skip to content

Commit

Permalink
move sync ledger constants back to compile time
Browse files Browse the repository at this point in the history
  • Loading branch information
deepthiskumar committed Nov 19, 2024
1 parent a27d3cc commit 0d0f6dc
Show file tree
Hide file tree
Showing 31 changed files with 104 additions and 66 deletions.
2 changes: 1 addition & 1 deletion src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ let setup_daemon logger ~itn_features =
let module Context = struct
let logger = logger

let genesis_constants = precomputed_values.genesis_constants
let compile_config = precomputed_values.compile_config

let constraint_constants = precomputed_values.constraint_constants

Expand Down
4 changes: 4 additions & 0 deletions src/config/dev.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,7 @@
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
[%%undef zkapp_cmd_limit]

(* Sync ledger query/response size*)
[%%define sync_ledger_max_subtree_depth 4]
[%%define sync_ledger_default_subtree_depth 3]
4 changes: 4 additions & 0 deletions src/config/devnet.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@
[%%define vrf_poll_interval 5000]
[%%define zkapp_cmd_limit 24]
[%%undef scan_state_transaction_capacity_log_2]

(* Constants determining sync ledger query/response size*)
[%%define sync_ledger_max_subtree_depth 8]
[%%define sync_ledger_default_subtree_depth 6]
4 changes: 4 additions & 0 deletions src/config/lightnet.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@
[%%define compaction_interval 360000]
[%%define vrf_poll_interval 5000]
[%%undef zkapp_cmd_limit]

(* Constants determining sync ledger query/response size*)
[%%define sync_ledger_max_subtree_depth 8]
[%%define sync_ledger_default_subtree_depth 6]
4 changes: 4 additions & 0 deletions src/config/mainnet.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@
[%%define vrf_poll_interval 5000]
[%%define zkapp_cmd_limit 24]
[%%undef scan_state_transaction_capacity_log_2]

(* Constants determining sync ledger query/response size*)
[%%define sync_ledger_max_subtree_depth 8]
[%%define sync_ledger_default_subtree_depth 6]
4 changes: 2 additions & 2 deletions src/lib/block_producer/block_producer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ let produce ~genesis_breadcrumb ~context:(module Context : CONTEXT) ~prover
let module Consensus_context = struct
include Context

let genesis_constants = precomputed_values.genesis_constants
let compile_config = precomputed_values.compile_config
end in
Internal_tracing.with_state_hash protocol_state_hashes.state_hash
@@ fun () ->
Expand Down Expand Up @@ -1419,7 +1419,7 @@ let run_precomputed ~context:(module Context : CONTEXT) ~verifier ~trust_system
let module Consensus_context = struct
include Context

let genesis_constants = precomputed_values.genesis_constants
let compile_config = precomputed_values.compile_config
end in
Debug_assert.debug_assert (fun () ->
[%test_result: [ `Take | `Keep ]]
Expand Down
12 changes: 6 additions & 6 deletions src/lib/bootstrap_controller/bootstrap_controller.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ let time_deferred deferred =
(Time.diff end_time start_time, result)

let worth_getting_root ({ context = (module Context); _ } as t) candidate =
let module Context = struct
let module Consensus_context = struct
include Context

let genesis_constants = precomputed_values.genesis_constants
let compile_config = precomputed_values.compile_config

let logger =
Logger.extend logger
Expand All @@ -77,7 +77,7 @@ let worth_getting_root ({ context = (module Context); _ } as t) candidate =
end in
Consensus.Hooks.equal_select_status `Take
@@ Consensus.Hooks.select
~context:(module Context)
~context:(module Consensus_context)
~existing:
( t.best_seen_transition |> Mina_block.Validation.block_with_hash
|> With_hash.map ~f:Mina_block.consensus_state )
Expand Down Expand Up @@ -240,7 +240,7 @@ let external_transition_compare ~context:(module Context : CONTEXT) =
let module Consensus_context = struct
include Context

let genesis_constants = precomputed_values.genesis_constants
let compile_config = precomputed_values.compile_config
end in
let get_consensus_state =
Fn.compose Protocol_state.consensus_state Mina_block.Header.protocol_state
Expand Down Expand Up @@ -337,7 +337,7 @@ let run ~context:(module Context : CONTEXT) ~trust_system ~verifier ~network
let module Consensus_context = struct
include Context

let genesis_constants = precomputed_values.genesis_constants
let compile_config = precomputed_values.compile_config
end in
let%bind sync_ledger_time, (hash, sender, expected_staged_ledger_hash) =
time_deferred
Expand Down Expand Up @@ -823,7 +823,7 @@ let%test_module "Bootstrap_controller tests" =
let module Consensus_context = struct
include Context

let genesis_constants = precomputed_values.genesis_constants
let compile_config = precomputed_values.compile_config
end in
let root_sync_ledger =
Sync_ledger.Db.create
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 genesis_constants : Genesis_constants.t
val compile_config : Mina_compile_config.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 genesis_constants : Genesis_constants.t
val compile_config : Mina_compile_config.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 genesis_constants = Genesis_constants.For_unit_tests.t
let compile_config = Mina_compile_config.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 genesis_constants = Genesis_constants.For_unit_tests.t
let compile_config = Mina_compile_config.For_unit_tests.t
end

let test_update constraint_constants =
Expand Down
4 changes: 2 additions & 2 deletions src/lib/fake_network/fake_network.ml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ module Generator = struct
let module Consensus_context = struct
include Context

let genesis_constants = precomputed_values.genesis_constants
let compile_config = precomputed_values.compile_config
end in
let open Context in
let epoch_ledger_location =
Expand Down Expand Up @@ -263,7 +263,7 @@ module Generator = struct
let module Consensus_context = struct
include Context

let genesis_constants = precomputed_values.genesis_constants
let compile_config = precomputed_values.compile_config
end in
let open Context in
let epoch_ledger_location =
Expand Down
4 changes: 0 additions & 4 deletions src/lib/genesis_constants/genesis_constants.ml
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ module T = struct
; max_action_elements : int
; zkapp_cmd_limit_hardcap : int
; minimum_user_command_fee : Currency.Fee.Stable.Latest.t
; sync_ledger_default_subtree_depth : int
; sync_ledger_max_subtree_depth : int
}
[@@deriving to_yojson, sexp_of, bin_io_unversioned]

Expand Down Expand Up @@ -436,8 +434,6 @@ module Make (Node_config : Node_config_intf.S) : S = struct
; zkapp_cmd_limit_hardcap = 128
; minimum_user_command_fee =
Currency.Fee.of_mina_string_exn Node_config.minimum_user_command_fee
; sync_ledger_max_subtree_depth = 8
; sync_ledger_default_subtree_depth = 6
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,12 +577,6 @@ let make_genesis_constants ~logger ~(default : Genesis_constants.t)
; minimum_user_command_fee =
Option.value ~default:default.minimum_user_command_fee
(config.daemon >>= fun cfg -> cfg.minimum_user_command_fee)
; sync_ledger_default_subtree_depth =
Option.value ~default:default.sync_ledger_default_subtree_depth
(config.daemon >>= fun cfg -> cfg.sync_ledger_default_subtree_depth)
; sync_ledger_max_subtree_depth =
Option.value ~default:default.sync_ledger_max_subtree_depth
(config.daemon >>= fun cfg -> cfg.sync_ledger_max_subtree_depth)
}

let%test_module "Runtime config" =
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ledger_catchup/super_catchup.ml
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ let pick ~context:(module Context : CONTEXT)
let module Context = struct
include Context

let genesis_constants = precomputed_values.genesis_constants
let compile_config = precomputed_values.compile_config
end in
match
Consensus.Hooks.select
Expand Down
2 changes: 1 addition & 1 deletion src/lib/mina_block/validation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module type CONTEXT = sig

val consensus_constants : Consensus.Constants.t

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

let validation (_, v) = v
Expand Down
2 changes: 1 addition & 1 deletion src/lib/mina_block/validation.mli
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module type CONTEXT = sig

val consensus_constants : Consensus.Constants.t

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

val validation :
Expand Down
23 changes: 20 additions & 3 deletions src/lib/mina_compile_config/mina_compile_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ module Inputs = struct
; rpc_heartbeat_timeout_sec : float
; rpc_heartbeat_send_every_sec : float
; zkapps_disabled : bool
; sync_ledger_max_subtree_depth : int
; sync_ledger_default_subtree_depth : int
}
[@@deriving yojson, bin_io_unversioned]
end

type t =
{ curve_size : int
; default_snark_worker_fee : Currency.Fee.t
; minimum_user_command_fee : Currency.Fee.t
; default_snark_worker_fee : Currency.Fee.Stable.Latest.t
; minimum_user_command_fee : Currency.Fee.Stable.Latest.t
; itn_features : bool
; compaction_interval : Time.Span.t option
; block_window_duration : Time.Span.t
Expand All @@ -39,8 +41,10 @@ type t =
; rpc_heartbeat_timeout : Time_ns.Span.t
; rpc_heartbeat_send_every : Time_ns.Span.t
; zkapps_disabled : bool
; sync_ledger_max_subtree_depth : int
; sync_ledger_default_subtree_depth : int
}
[@@deriving sexp_of]
[@@deriving sexp_of, bin_io_unversioned]

let make (inputs : Inputs.t) =
{ curve_size = inputs.curve_size
Expand All @@ -64,6 +68,8 @@ let make (inputs : Inputs.t) =
; network_id = inputs.network_id
; zkapp_cmd_limit = inputs.zkapp_cmd_limit
; zkapps_disabled = inputs.zkapps_disabled
; sync_ledger_max_subtree_depth = inputs.sync_ledger_max_subtree_depth
; sync_ledger_default_subtree_depth = inputs.sync_ledger_default_subtree_depth
}

let to_yojson t =
Expand Down Expand Up @@ -91,6 +97,9 @@ let to_yojson t =
, Option.value_map ~default:`Null ~f:(fun x -> `Int x) t.zkapp_cmd_limit
)
; ("zkapps_disabled", `Bool t.zkapps_disabled)
; ("sync_ledger_max_subtree_depth", `Int t.sync_ledger_max_subtree_depth)
; ( "sync_ledger_default_subtree_depth"
, `Int t.sync_ledger_default_subtree_depth )
]

(*TODO: Delete this module and read in a value from the environment*)
Expand All @@ -110,6 +119,10 @@ module Compiled = struct
; rpc_heartbeat_timeout_sec = 60.0
; rpc_heartbeat_send_every_sec = 10.0
; zkapps_disabled = false
; sync_ledger_max_subtree_depth =
Node_config.sync_ledger_max_subtree_depth
; sync_ledger_default_subtree_depth =
Node_config.sync_ledger_default_subtree_depth
}
in
make inputs
Expand Down Expand Up @@ -137,6 +150,10 @@ module For_unit_tests = struct
; network_id = Node_config_for_unit_tests.network
; zkapp_cmd_limit = Node_config_for_unit_tests.zkapp_cmd_limit
; zkapps_disabled = Node_config_for_unit_tests.zkapps_disabled
; sync_ledger_max_subtree_depth =
Node_config_for_unit_tests.sync_ledger_max_subtree_depth
; sync_ledger_default_subtree_depth =
Node_config_for_unit_tests.sync_ledger_default_subtree_depth
}
in
make inputs
Expand Down
5 changes: 3 additions & 2 deletions src/lib/mina_lib/mina_lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,7 @@ let context ~commit_id (config : Config.t) : (module CONTEXT) =

let compaction_interval = config.compile_config.compaction_interval

(*Same as config.precomputed_values.compile_config. TODO: Remove redundant fields *)
let compile_config = config.compile_config
end )

Expand Down Expand Up @@ -1618,8 +1619,8 @@ let create ~commit_id ?wallets (config : Config.t) =
~pids:config.pids ~logger:config.logger
~conf_dir:config.conf_dir ~consensus_constants
~keypairs:config.block_production_keypairs
~genesis_constants:
config.precomputed_values.genesis_constants ) )
~compile_config:config.precomputed_values.compile_config )
)
>>| Result.ok_exn
in
let snark_worker =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,7 @@ let rpc_handshake_timeout_sec = 60.0
let rpc_heartbeat_timeout_sec = 60.0

let rpc_heartbeat_send_every_sec = 10.0 (*same as the default*)

let sync_ledger_max_subtree_depth = 4

let sync_ledger_default_subtree_depth = 3
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ val rpc_handshake_timeout_sec : float
val rpc_heartbeat_timeout_sec : float

val rpc_heartbeat_send_every_sec : float

val sync_ledger_max_subtree_depth : int

val sync_ledger_default_subtree_depth : int
4 changes: 4 additions & 0 deletions src/lib/node_config/intf/node_config_intf.mli
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ module type S = sig
val zkapp_cmd_limit : int option

val scan_state_tps_goal_x10 : int option

val sync_ledger_max_subtree_depth : int

val sync_ledger_default_subtree_depth : int
end
5 changes: 5 additions & 0 deletions src/lib/node_config/node_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ include Node_config_version

[%%inject "scan_state_with_tps_goal", scan_state_with_tps_goal]

[%%inject "sync_ledger_max_subtree_depth", sync_ledger_max_subtree_depth]

[%%inject
"sync_ledger_default_subtree_depth", sync_ledger_default_subtree_depth]

[%%ifndef scan_state_transaction_capacity_log_2]

let scan_state_transaction_capacity_log_2 : int option = None
Expand Down
15 changes: 7 additions & 8 deletions src/lib/runtime_config/runtime_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1892,14 +1892,6 @@ module Constants : Constants_intf = struct
; minimum_user_command_fee =
Option.value ~default:a.genesis_constants.minimum_user_command_fee
Option.(b.daemon >>= fun d -> d.minimum_user_command_fee)
; sync_ledger_default_subtree_depth =
Option.value
~default:a.genesis_constants.sync_ledger_default_subtree_depth
Option.(b.daemon >>= fun d -> d.sync_ledger_default_subtree_depth)
; sync_ledger_max_subtree_depth =
Option.value
~default:a.genesis_constants.sync_ledger_max_subtree_depth
Option.(b.daemon >>= fun d -> d.sync_ledger_max_subtree_depth)
}
in
let constraint_constants =
Expand Down Expand Up @@ -1975,6 +1967,13 @@ module Constants : Constants_intf = struct
; network_id =
Option.value ~default:a.compile_config.network_id
Option.(b.daemon >>= fun d -> d.network_id)
; sync_ledger_max_subtree_depth =
Option.value ~default:a.compile_config.sync_ledger_max_subtree_depth
Option.(b.daemon >>= fun d -> d.sync_ledger_max_subtree_depth)
; sync_ledger_default_subtree_depth =
Option.value
~default:a.compile_config.sync_ledger_default_subtree_depth
Option.(b.daemon >>= fun d -> d.sync_ledger_default_subtree_depth)
}
in
{ genesis_constants; constraint_constants; proof_level; compile_config }
Expand Down
Loading

0 comments on commit 0d0f6dc

Please sign in to comment.