From 10add498e31f50b45483df48bf52ae32521c9bde Mon Sep 17 00:00:00 2001 From: martyall Date: Tue, 17 Sep 2024 16:44:49 -0700 Subject: [PATCH 01/29] delete node config values where possible --- src/lib/node_config/node_config.ml | 103 ---------------------------- src/lib/node_config/node_config.mli | 4 +- 2 files changed, 3 insertions(+), 104 deletions(-) diff --git a/src/lib/node_config/node_config.ml b/src/lib/node_config/node_config.ml index 78485f82a17..8491bfe4419 100644 --- a/src/lib/node_config/node_config.ml +++ b/src/lib/node_config/node_config.ml @@ -1,108 +1,5 @@ [%%import "/src/config.mlh"] -(** This file consists of compile-time constants that are not in - Genesis_constants. - This file includes all of the constants defined at compile-time for both - tests and production. -*) - -include Node_config_version -include Node_config_unconfigurable_constants - -[%%inject "ledger_depth", ledger_depth] - -[%%inject "curve_size", curve_size] - -[%%inject "coinbase", coinbase] - -[%%inject "k", k] - -[%%inject "delta", delta] - -[%%inject "slots_per_epoch", slots_per_epoch] - -[%%inject "slots_per_sub_window", slots_per_sub_window] - -[%%inject "sub_windows_per_window", sub_windows_per_window] - -[%%inject "grace_period_slots", grace_period_slots] - -[%%inject "scan_state_with_tps_goal", scan_state_with_tps_goal] - -[%%ifndef scan_state_transaction_capacity_log_2] - -let scan_state_transaction_capacity_log_2 : int option = None - -[%%else] - -[%%inject -"scan_state_transaction_capacity_log_2", scan_state_transaction_capacity_log_2] - -let scan_state_transaction_capacity_log_2 = - Some scan_state_transaction_capacity_log_2 - -[%%endif] - -[%%inject "scan_state_work_delay", scan_state_work_delay] - -[%%inject "proof_level", proof_level] - -[%%inject "pool_max_size", pool_max_size] - -[%%inject "account_creation_fee_int", account_creation_fee_int] - -[%%inject "default_transaction_fee", default_transaction_fee] - -[%%inject "default_snark_worker_fee", default_snark_worker_fee] - -[%%inject "minimum_user_command_fee", minimum_user_command_fee] - -[%%inject "supercharged_coinbase_factor", supercharged_coinbase_factor] - -[%%inject "plugins", plugins] - -[%%inject "genesis_state_timestamp", genesis_state_timestamp] - [%%inject "block_window_duration", block_window_duration] -[%%inject "itn_features", itn_features] - -[%%ifndef compaction_interval] - -let compaction_interval = None - -[%%else] - -[%%inject "compaction_interval", compaction_interval] - -let compaction_interval = Some compaction_interval - -[%%endif] - [%%inject "network", network] - -[%%inject "vrf_poll_interval", vrf_poll_interval] - -[%%ifndef zkapp_cmd_limit] - -let zkapp_cmd_limit = None - -[%%else] - -[%%inject "zkapp_cmd_limit", zkapp_cmd_limit] - -let zkapp_cmd_limit = Some zkapp_cmd_limit - -[%%endif] - -[%%ifndef scan_state_tps_goal_x10] - -let scan_state_tps_goal_x10 : int option = None - -[%%else] - -[%%inject "scan_state_tps_goal_x10", scan_state_tps_goal_x10] - -let scan_state_tps_goal_x10 = Some scan_state_tps_goal_x10 - -[%%endif] diff --git a/src/lib/node_config/node_config.mli b/src/lib/node_config/node_config.mli index eb996f25855..e105f31c675 100644 --- a/src/lib/node_config/node_config.mli +++ b/src/lib/node_config/node_config.mli @@ -1 +1,3 @@ -include Node_config_intf.S +val network : string + +val block_window_duration : int From d50c0e87b3313114e157d67438a482a2b129ab90 Mon Sep 17 00:00:00 2001 From: martyall Date: Tue, 17 Sep 2024 16:47:34 -0700 Subject: [PATCH 02/29] update genesis_constants and compile_config --- .../genesis_constants/genesis_constants.ml | 389 +++++++++--------- src/lib/mina_compile_config/dune | 2 +- .../mina_compile_config.ml | 119 +++--- 3 files changed, 242 insertions(+), 268 deletions(-) diff --git a/src/lib/genesis_constants/genesis_constants.ml b/src/lib/genesis_constants/genesis_constants.ml index 35259dd34ba..dd1ff158102 100644 --- a/src/lib/genesis_constants/genesis_constants.ml +++ b/src/lib/genesis_constants/genesis_constants.ml @@ -1,7 +1,8 @@ open Core_kernel module Proof_level = struct - type t = Full | Check | None [@@deriving bin_io_unversioned, equal] + type t = Full | Check | None + [@@deriving bin_io_unversioned, equal, yojson, sexp, compare] let to_string = function Full -> "full" | Check -> "check" | None -> "none" @@ -27,6 +28,23 @@ module Fork_constants = struct end module Constraint_constants = struct + module Inputs = struct + type t = + { scan_state_with_tps_goal : bool + ; scan_state_tps_goal_x10 : int option + ; block_window_duration : int + ; scan_state_transaction_capacity_log_2 : int option + ; supercharged_coinbase_factor : int + ; scan_state_work_delay : int + ; coinbase : string + ; account_creation_fee_int : string + ; ledger_depth : int + ; sub_windows_per_window : int + ; fork : Fork_constants.t option + } + [@@deriving yojson] + end + type t = { sub_windows_per_window : int ; ledger_depth : int @@ -41,6 +59,71 @@ module Constraint_constants = struct } [@@deriving bin_io_unversioned, sexp, equal, compare, yojson] + let make (inputs : Inputs.t) : t = + (* All the proofs before the last [work_delay] blocks must be + completed to add transactions. [work_delay] is the minimum number + of blocks and will increase if the throughput is less. + - If [work_delay = 0], all the work that was added to the scan + state in the previous block is expected to be completed and + included in the current block if any transactions/coinbase are to + be included. + - [work_delay >= 1] means that there's at least two block times for + completing the proofs. + *) + let transaction_capacity_log_2 = + match + (inputs.scan_state_with_tps_goal, inputs.scan_state_tps_goal_x10) + with + | true, Some tps_goal_x10 -> + let max_coinbases = 2 in + + (* block_window_duration is in milliseconds, so divide by 1000 divide + by 10 again because we have tps * 10 + *) + let max_user_commands_per_block = + tps_goal_x10 * inputs.block_window_duration / (1000 * 10) + in + + (* Log of the capacity of transactions per transition. + - 1 will only work if we don't have prover fees. + - 2 will work with prover fees, but not if we want a transaction + included in every block. + - At least 3 ensures a transaction per block and the staged-ledger + unit tests pass. + *) + 1 + + Core_kernel.Int.ceil_log2 + (max_user_commands_per_block + max_coinbases) + | _ -> ( + match inputs.scan_state_transaction_capacity_log_2 with + | Some a -> + a + | None -> + failwith + "scan_state_transaction_capacity_log_2 must be set if \ + scan_state_with_tps_goal is false" ) + in + let supercharged_coinbase_factor = inputs.supercharged_coinbase_factor in + + let pending_coinbase_depth = + Core_kernel.Int.ceil_log2 + ( ((transaction_capacity_log_2 + 1) * (inputs.scan_state_work_delay + 1)) + + 1 ) + in + + { sub_windows_per_window = inputs.sub_windows_per_window + ; ledger_depth = inputs.ledger_depth + ; work_delay = inputs.scan_state_work_delay + ; block_window_duration_ms = inputs.block_window_duration + ; transaction_capacity_log_2 + ; pending_coinbase_depth + ; coinbase_amount = Currency.Amount.of_mina_string_exn inputs.coinbase + ; supercharged_coinbase_factor + ; account_creation_fee = + Currency.Fee.of_mina_string_exn inputs.account_creation_fee_int + ; fork = inputs.fork + } + let to_snark_keys_header (t : t) : Snark_keys_header.Constraint_constants.t = { sub_windows_per_window = t.sub_windows_per_window ; ledger_depth = t.ledger_depth @@ -55,12 +138,11 @@ module Constraint_constants = struct ( match t.fork with | Some { blockchain_length; state_hash; global_slot_since_genesis } -> Some - { blockchain_length = Unsigned.UInt32.to_int blockchain_length + { blockchain_length = Mina_numbers.Length.to_int blockchain_length ; state_hash = Pickles.Backend.Tick.Field.to_string state_hash ; global_slot_since_genesis = - Unsigned.UInt32.to_int - (Mina_numbers.Global_slot_since_genesis.to_uint32 - global_slot_since_genesis ) + Mina_numbers.Global_slot_since_genesis.to_int + global_slot_since_genesis } | None -> None ) @@ -204,6 +286,28 @@ module Protocol = struct end module T = struct + module Inputs = struct + type t = + { genesis_state_timestamp : string + ; k : int + ; slots_per_epoch : int + ; slots_per_sub_window : int + ; grace_period_slots : int + ; delta : int + ; pool_max_size : int + ; num_accounts : int option + ; zkapp_proof_update_cost : float + ; zkapp_signed_single_update_cost : float + ; zkapp_signed_pair_update_cost : float + ; zkapp_transaction_cost_limit : float + ; max_event_elements : int + ; max_action_elements : int + ; zkapp_cmd_limit_hardcap : int + ; minimum_user_command_fee : string + } + [@@deriving yojson] + end + (* bin_io is for printing chain id inputs *) type t = { protocol : Protocol.Stable.Latest.t @@ -220,6 +324,30 @@ module T = struct } [@@deriving to_yojson, sexp_of, bin_io_unversioned] + let make (inputs : Inputs.t) : t = + { protocol = + { k = inputs.k + ; slots_per_epoch = inputs.slots_per_epoch + ; slots_per_sub_window = inputs.slots_per_sub_window + ; grace_period_slots = inputs.grace_period_slots + ; delta = inputs.delta + ; genesis_state_timestamp = + genesis_timestamp_of_string inputs.genesis_state_timestamp + |> of_time + } + ; txpool_max_size = inputs.pool_max_size + ; num_accounts = inputs.num_accounts + ; zkapp_proof_update_cost = inputs.zkapp_proof_update_cost + ; zkapp_signed_single_update_cost = inputs.zkapp_signed_single_update_cost + ; zkapp_signed_pair_update_cost = inputs.zkapp_signed_pair_update_cost + ; zkapp_transaction_cost_limit = inputs.zkapp_transaction_cost_limit + ; max_event_elements = inputs.max_event_elements + ; max_action_elements = inputs.max_action_elements + ; zkapp_cmd_limit_hardcap = inputs.zkapp_cmd_limit_hardcap + ; minimum_user_command_fee = + Currency.Fee.of_mina_string_exn inputs.minimum_user_command_fee + } + let hash (t : t) = let str = ( List.map @@ -242,210 +370,77 @@ end include T -module type S = sig - module Proof_level : sig - include module type of Proof_level with type t = Proof_level.t - - val t : t - end - - module Fork_constants = Fork_constants +module For_unit_tests = struct + let inputs = + { T.Inputs.genesis_state_timestamp = + Node_config_for_unit_tests.genesis_state_timestamp + ; k = Node_config_for_unit_tests.k + ; slots_per_epoch = Node_config_for_unit_tests.slots_per_epoch + ; slots_per_sub_window = Node_config_for_unit_tests.slots_per_sub_window + ; grace_period_slots = Node_config_for_unit_tests.grace_period_slots + ; delta = Node_config_for_unit_tests.delta + ; pool_max_size = Node_config_for_unit_tests.pool_max_size + ; num_accounts = None + ; zkapp_proof_update_cost = + Node_config_for_unit_tests.zkapp_proof_update_cost + ; zkapp_signed_single_update_cost = + Node_config_for_unit_tests.zkapp_signed_single_update_cost + ; zkapp_signed_pair_update_cost = + Node_config_for_unit_tests.zkapp_signed_pair_update_cost + ; zkapp_transaction_cost_limit = + Node_config_for_unit_tests.zkapp_transaction_cost_limit + ; max_event_elements = Node_config_for_unit_tests.max_event_elements + ; max_action_elements = Node_config_for_unit_tests.max_action_elements + ; zkapp_cmd_limit_hardcap = + Node_config_for_unit_tests.zkapp_cmd_limit_hardcap + ; minimum_user_command_fee = + Node_config_for_unit_tests.minimum_user_command_fee + } - module Constraint_constants : sig - include - module type of Constraint_constants with type t = Constraint_constants.t + let t = T.make inputs - val t : t + module Constraint_constants = struct + let inputs = + { Constraint_constants.Inputs.scan_state_with_tps_goal = + Node_config_for_unit_tests.scan_state_with_tps_goal + ; scan_state_tps_goal_x10 = + Node_config_for_unit_tests.scan_state_tps_goal_x10 + ; block_window_duration = Node_config_for_unit_tests.block_window_duration + ; scan_state_transaction_capacity_log_2 = + Node_config_for_unit_tests.scan_state_transaction_capacity_log_2 + ; supercharged_coinbase_factor = + Node_config_for_unit_tests.supercharged_coinbase_factor + ; scan_state_work_delay = Node_config_for_unit_tests.scan_state_work_delay + ; coinbase = Node_config_for_unit_tests.coinbase + ; account_creation_fee_int = + Node_config_for_unit_tests.account_creation_fee_int + ; ledger_depth = Node_config_for_unit_tests.ledger_depth + ; sub_windows_per_window = + Node_config_for_unit_tests.sub_windows_per_window + ; fork = None + } + + let t = Constraint_constants.make inputs end - val genesis_timestamp_of_string : string -> Time.t - - val of_time : Time.t -> int64 - - val to_time : int64 -> Time.t - - val validate_time : string option -> (int64, string) result - - val genesis_timestamp_to_string : int64 -> string - - module Protocol = Protocol - - include module type of T with type t = T.t - - val genesis_state_timestamp_string : string - - val k : int - - val slots_per_epoch : int - - val slots_per_sub_window : int - - val grace_period_slots : int - - val delta : int - - val pool_max_size : int - - val t : t -end - -module Make (Node_config : Node_config_intf.S) : S = struct module Proof_level = struct - include Proof_level + let inputs = Node_config_for_unit_tests.proof_level - let t = of_string Node_config.proof_level + let t = Proof_level.of_string inputs end - module Fork_constants = Fork_constants - - (** Constants that affect the constraint systems for proofs (and thus also key - generation). - - Care must be taken to ensure that these match against the proving/ - verification keys when [proof_level=Full], otherwise generated proofs will - be invalid. - *) - module Constraint_constants = struct - include Constraint_constants - - (* Generate the compile-time constraint constants, using a signature to hide - the optcomp constants that we import. - *) - include ( - struct - (** All the proofs before the last [work_delay] blocks must be - completed to add transactions. [work_delay] is the minimum number - of blocks and will increase if the throughput is less. - - If [work_delay = 0], all the work that was added to the scan - state in the previous block is expected to be completed and - included in the current block if any transactions/coinbase are to - be included. - - [work_delay >= 1] means that there's at least two block times for - completing the proofs. - *) - - let transaction_capacity_log_2 = - match - ( Node_config.scan_state_with_tps_goal - , Node_config.scan_state_tps_goal_x10 ) - with - | true, Some tps_goal_x10 -> - let max_coinbases = 2 in - - (* block_window_duration is in milliseconds, so divide by 1000 divide - by 10 again because we have tps * 10 - *) - let max_user_commands_per_block = - tps_goal_x10 * Node_config.block_window_duration / (1000 * 10) - in - - (* Log of the capacity of transactions per transition. - - 1 will only work if we don't have prover fees. - - 2 will work with prover fees, but not if we want a transaction - included in every block. - - At least 3 ensures a transaction per block and the staged-ledger - unit tests pass. - *) - 1 - + Core_kernel.Int.ceil_log2 - (max_user_commands_per_block + max_coinbases) - | _ -> ( - match Node_config.scan_state_transaction_capacity_log_2 with - | Some a -> - a - | None -> - failwith - "scan_state_transaction_capacity_log_2 must be set if \ - scan_state_with_tps_goal is false" ) - - let supercharged_coinbase_factor = - Node_config.supercharged_coinbase_factor - - let pending_coinbase_depth = - Core_kernel.Int.ceil_log2 - ( (transaction_capacity_log_2 + 1) - * (Node_config.scan_state_work_delay + 1) - + 1 ) - - let t = - { sub_windows_per_window = Node_config.sub_windows_per_window - ; ledger_depth = Node_config.ledger_depth - ; work_delay = Node_config.scan_state_work_delay - ; block_window_duration_ms = Node_config.block_window_duration - ; transaction_capacity_log_2 - ; pending_coinbase_depth - ; coinbase_amount = - Currency.Amount.of_mina_string_exn Node_config.coinbase - ; supercharged_coinbase_factor - ; account_creation_fee = - Currency.Fee.of_mina_string_exn - Node_config.account_creation_fee_int - ; fork = None - } - end : - sig - val t : t - end ) - end - - include Helpers - module Protocol = Protocol - include T - - let genesis_state_timestamp_string = Node_config.genesis_state_timestamp - - let k = Node_config.k - - let slots_per_epoch = Node_config.slots_per_epoch - - let slots_per_sub_window = Node_config.slots_per_sub_window - - let grace_period_slots = Node_config.grace_period_slots - - let delta = Node_config.delta - - let pool_max_size = Node_config.pool_max_size - - let t : t = - { protocol = - { k - ; slots_per_epoch - ; slots_per_sub_window - ; grace_period_slots - ; delta - ; genesis_state_timestamp = - genesis_timestamp_of_string genesis_state_timestamp_string - |> of_time - } - ; txpool_max_size = pool_max_size - ; num_accounts = None - ; zkapp_proof_update_cost = Node_config.zkapp_proof_update_cost - ; zkapp_signed_single_update_cost = - Node_config.zkapp_signed_single_update_cost - ; zkapp_signed_pair_update_cost = Node_config.zkapp_signed_pair_update_cost - ; zkapp_transaction_cost_limit = Node_config.zkapp_transaction_cost_limit - ; max_event_elements = Node_config.max_event_elements - ; max_action_elements = Node_config.max_action_elements - ; zkapp_cmd_limit_hardcap = Node_config.zkapp_cmd_limit_hardcap - ; minimum_user_command_fee = - Currency.Fee.of_mina_string_exn Node_config.minimum_user_command_fee - } -end - -module For_unit_tests = Make (Node_config_for_unit_tests) + let genesis_state_timestamp_string = + Node_config_for_unit_tests.genesis_state_timestamp -module Compiled : sig - val genesis_constants : t + let k = Node_config_for_unit_tests.k - val constraint_constants : Constraint_constants.t + let slots_per_epoch = Node_config_for_unit_tests.slots_per_epoch - val proof_level : Proof_level.t -end = struct - include Make (Node_config) + let slots_per_sub_window = Node_config_for_unit_tests.slots_per_sub_window - let genesis_constants = t + let grace_period_slots = Node_config_for_unit_tests.grace_period_slots - let constraint_constants = Constraint_constants.t + let delta = Node_config_for_unit_tests.delta - let proof_level = Proof_level.t + let pool_max_size = Node_config_for_unit_tests.pool_max_size end diff --git a/src/lib/mina_compile_config/dune b/src/lib/mina_compile_config/dune index fac058923b4..181360fbaf2 100644 --- a/src/lib/mina_compile_config/dune +++ b/src/lib/mina_compile_config/dune @@ -1,6 +1,6 @@ (library (name mina_compile_config) (public_name mina_compile_config) - (libraries mina_node_config mina_node_config.for_unit_tests core_kernel currency) + (libraries mina_node_config node_config_for_unit_tests core_kernel currency) (instrumentation (backend bisect_ppx)) (preprocess (pps ppx_version ppx_base ppx_deriving_yojson))) diff --git a/src/lib/mina_compile_config/mina_compile_config.ml b/src/lib/mina_compile_config/mina_compile_config.ml index 067bc5b7bac..1f42cfbf9c5 100644 --- a/src/lib/mina_compile_config/mina_compile_config.ml +++ b/src/lib/mina_compile_config/mina_compile_config.ml @@ -29,6 +29,8 @@ module Inputs = struct ; max_action_elements : int ; zkapp_cmd_limit_hardcap : int ; zkapps_disabled : bool + ; slot_chain_end : int option + ; slot_tx_end : int option } [@@deriving yojson] end @@ -55,6 +57,8 @@ type t = ; max_action_elements : int ; zkapp_cmd_limit_hardcap : int ; zkapps_disabled : bool + ; slot_chain_end : Mina_numbers.Global_slot_since_hard_fork.t option + ; slot_tx_end : Mina_numbers.Global_slot_since_hard_fork.t option } let make (inputs : Inputs.t) = @@ -88,6 +92,12 @@ let make (inputs : Inputs.t) = ; zkapp_cmd_limit = inputs.zkapp_cmd_limit ; zkapp_cmd_limit_hardcap = inputs.zkapp_cmd_limit_hardcap ; zkapps_disabled = inputs.zkapps_disabled + ; slot_chain_end = + Option.map ~f:Mina_numbers.Global_slot_since_hard_fork.of_int + inputs.slot_chain_end + ; slot_tx_end = + Option.map ~f:Mina_numbers.Global_slot_since_hard_fork.of_int + inputs.slot_tx_end } let to_yojson t = @@ -127,75 +137,44 @@ let to_yojson t = ; ("zkapps_disabled", `Bool t.zkapps_disabled) ] -(*TODO: Delete this module and read in a value from the environment*) -module Compiled = struct - let t : t = - let (inputs : Inputs.t) = - { curve_size = Node_config.curve_size - ; default_transaction_fee_string = Node_config.default_transaction_fee - ; default_snark_worker_fee_string = Node_config.default_snark_worker_fee - ; minimum_user_command_fee_string = Node_config.minimum_user_command_fee - ; itn_features = Node_config.itn_features - ; compaction_interval_ms = Node_config.compaction_interval - ; block_window_duration_ms = Node_config.block_window_duration - ; vrf_poll_interval_ms = Node_config.vrf_poll_interval - ; rpc_handshake_timeout_sec = Node_config.rpc_handshake_timeout_sec - ; rpc_heartbeat_timeout_sec = Node_config.rpc_heartbeat_timeout_sec - ; rpc_heartbeat_send_every_sec = Node_config.rpc_heartbeat_send_every_sec - ; zkapp_proof_update_cost = Node_config.zkapp_proof_update_cost - ; zkapp_signed_pair_update_cost = - Node_config.zkapp_signed_pair_update_cost - ; zkapp_signed_single_update_cost = - Node_config.zkapp_signed_single_update_cost - ; zkapp_transaction_cost_limit = Node_config.zkapp_transaction_cost_limit - ; max_event_elements = Node_config.max_event_elements - ; max_action_elements = Node_config.max_action_elements - ; network_id = Node_config.network - ; zkapp_cmd_limit = Node_config.zkapp_cmd_limit - ; zkapp_cmd_limit_hardcap = Node_config.zkapp_cmd_limit_hardcap - ; zkapps_disabled = Node_config.zkapps_disabled - } - in - make inputs -end - module For_unit_tests = struct - let t : t = - let inputs : Inputs.t = - { curve_size = Node_config_for_unit_tests.curve_size - ; default_transaction_fee_string = - Node_config_for_unit_tests.default_transaction_fee - ; default_snark_worker_fee_string = - Node_config_for_unit_tests.default_snark_worker_fee - ; minimum_user_command_fee_string = - Node_config_for_unit_tests.minimum_user_command_fee - ; itn_features = Node_config_for_unit_tests.itn_features - ; compaction_interval_ms = Node_config_for_unit_tests.compaction_interval - ; block_window_duration_ms = - Node_config_for_unit_tests.block_window_duration - ; vrf_poll_interval_ms = Node_config_for_unit_tests.vrf_poll_interval - ; rpc_handshake_timeout_sec = - Node_config_for_unit_tests.rpc_handshake_timeout_sec - ; rpc_heartbeat_timeout_sec = - Node_config_for_unit_tests.rpc_heartbeat_timeout_sec - ; rpc_heartbeat_send_every_sec = - Node_config_for_unit_tests.rpc_heartbeat_send_every_sec - ; zkapp_proof_update_cost = - Node_config_for_unit_tests.zkapp_proof_update_cost - ; zkapp_signed_pair_update_cost = - Node_config_for_unit_tests.zkapp_signed_pair_update_cost - ; zkapp_signed_single_update_cost = - Node_config_for_unit_tests.zkapp_signed_single_update_cost - ; zkapp_transaction_cost_limit = - Node_config_for_unit_tests.zkapp_transaction_cost_limit - ; max_event_elements = Node_config_for_unit_tests.max_event_elements - ; max_action_elements = Node_config_for_unit_tests.max_action_elements - ; network_id = Node_config_for_unit_tests.network - ; zkapp_cmd_limit = Node_config_for_unit_tests.zkapp_cmd_limit - ; zkapp_cmd_limit_hardcap = - Node_config_for_unit_tests.zkapp_cmd_limit_hardcap - ; zkapps_disabled = Node_config_for_unit_tests.zkapps_disabled - } - in - make inputs + let inputs : Inputs.t = + { curve_size = Node_config_for_unit_tests.curve_size + ; default_transaction_fee_string = + Node_config_for_unit_tests.default_transaction_fee + ; default_snark_worker_fee_string = + Node_config_for_unit_tests.default_snark_worker_fee + ; minimum_user_command_fee_string = + Node_config_for_unit_tests.minimum_user_command_fee + ; itn_features = Node_config_for_unit_tests.itn_features + ; compaction_interval_ms = Node_config_for_unit_tests.compaction_interval + ; block_window_duration_ms = + Node_config_for_unit_tests.block_window_duration + ; vrf_poll_interval_ms = Node_config_for_unit_tests.vrf_poll_interval + ; rpc_handshake_timeout_sec = + Node_config_for_unit_tests.rpc_handshake_timeout_sec + ; rpc_heartbeat_timeout_sec = + Node_config_for_unit_tests.rpc_heartbeat_timeout_sec + ; rpc_heartbeat_send_every_sec = + Node_config_for_unit_tests.rpc_heartbeat_send_every_sec + ; zkapp_proof_update_cost = + Node_config_for_unit_tests.zkapp_proof_update_cost + ; zkapp_signed_pair_update_cost = + Node_config_for_unit_tests.zkapp_signed_pair_update_cost + ; zkapp_signed_single_update_cost = + Node_config_for_unit_tests.zkapp_signed_single_update_cost + ; zkapp_transaction_cost_limit = + Node_config_for_unit_tests.zkapp_transaction_cost_limit + ; max_event_elements = Node_config_for_unit_tests.max_event_elements + ; max_action_elements = Node_config_for_unit_tests.max_action_elements + ; network_id = Node_config_for_unit_tests.network + ; zkapp_cmd_limit = Node_config_for_unit_tests.zkapp_cmd_limit + ; zkapp_cmd_limit_hardcap = + Node_config_for_unit_tests.zkapp_cmd_limit_hardcap + ; zkapps_disabled = Node_config_for_unit_tests.zkapps_disabled + ; slot_chain_end = None + ; slot_tx_end = None + } + + let t : t = make inputs end From 43983fd42ab34229fb7ebe21911332aa2ebbef26 Mon Sep 17 00:00:00 2001 From: martyall Date: Tue, 17 Sep 2024 16:52:53 -0700 Subject: [PATCH 03/29] add all config to runtime config. Remove the config semigroup methods. Remove all the unused code (e.g. gen functions, unused yojson, etc --- src/lib/runtime_config/runtime_config.ml | 810 ++++------------------- src/lib/transition_handler/validator.ml | 7 +- 2 files changed, 113 insertions(+), 704 deletions(-) diff --git a/src/lib/runtime_config/runtime_config.ml b/src/lib/runtime_config/runtime_config.ml index ca1ff7d1912..99bad34efb8 100644 --- a/src/lib/runtime_config/runtime_config.ml +++ b/src/lib/runtime_config/runtime_config.ml @@ -1,24 +1,5 @@ open Core_kernel -module Fork_config = struct - (* Note that length might be smaller than the gernesis_slot - or equal if a block was produced in every slot possible. *) - type t = - { state_hash : string - ; blockchain_length : int (* number of blocks produced since genesis *) - ; global_slot_since_genesis : int (* global slot since genesis *) - } - [@@deriving yojson, bin_io_unversioned] - - let gen = - let open Quickcheck.Generator.Let_syntax in - let%bind global_slot_since_genesis = Int.gen_incl 0 1_000_000 in - let%bind blockchain_length = Int.gen_incl 0 global_slot_since_genesis in - let%map state_hash = Mina_base.State_hash.gen in - let state_hash = Mina_base.State_hash.to_base58_check state_hash in - { state_hash; blockchain_length; global_slot_since_genesis } -end - let yojson_strip_fields ~keep_fields = function | `Assoc l -> `Assoc @@ -403,86 +384,6 @@ module Json_layout = struct let of_yojson json = of_yojson_generic ~fields of_yojson json end - module Proof_keys = struct - module Transaction_capacity = struct - type t = - { log_2 : int option [@default None] [@key "2_to_the"] - ; txns_per_second_x10 : int option [@default None] - } - [@@deriving yojson] - - (* we don't deriving the field names here, because the first one differs from the - field in the record type - *) - let fields = [| "2_to_the"; "txns_per_second_x10" |] - - let alternates = [| ("two_to_the", "2_to_the"); ("log_2", "2_to_the") |] - - let of_yojson json = - json - |> yojson_rename_fields ~alternates - |> yojson_strip_fields ~keep_fields:fields - |> of_yojson |> dump_on_error json - end - - type t = - { level : string option [@default None] - ; sub_windows_per_window : int option [@default None] - ; ledger_depth : int option [@default None] - ; work_delay : int option [@default None] - ; block_window_duration_ms : int option [@default None] - ; transaction_capacity : Transaction_capacity.t option [@default None] - ; coinbase_amount : Currency.Amount.t option [@default None] - ; supercharged_coinbase_factor : int option [@default None] - ; account_creation_fee : Currency.Fee.t option [@default None] - ; fork : Fork_config.t option [@default None] - } - [@@deriving yojson, fields] - - let fields = Fields.names |> Array.of_list - - let of_yojson json = of_yojson_generic ~fields of_yojson json - end - - module Genesis = struct - type t = - { k : int option [@default None] - ; delta : int option [@default None] - ; slots_per_epoch : int option [@default None] - ; slots_per_sub_window : int option [@default None] - ; grace_period_slots : int option [@default None] - ; genesis_state_timestamp : string option [@default None] - } - [@@deriving yojson, fields] - - let fields = Fields.names |> Array.of_list - - let of_yojson json = of_yojson_generic ~fields of_yojson json - end - - module Daemon = struct - type t = - { txpool_max_size : int option [@default None] - ; peer_list_url : string option [@default None] - ; zkapp_proof_update_cost : float option [@default None] - ; zkapp_signed_single_update_cost : float option [@default None] - ; zkapp_signed_pair_update_cost : float option [@default None] - ; zkapp_transaction_cost_limit : float option [@default None] - ; max_event_elements : int option [@default None] - ; max_action_elements : int option [@default None] - ; zkapp_cmd_limit_hardcap : int option [@default None] - ; slot_tx_end : int option [@default None] - ; slot_chain_end : int option [@default None] - ; minimum_user_command_fee : Currency.Fee.t option [@default None] - ; network_id : string option [@default None] - } - [@@deriving yojson, fields] - - let fields = Fields.names |> Array.of_list - - let of_yojson json = of_yojson_generic ~fields of_yojson json - end - module Epoch_data = struct module Data = struct type t = @@ -509,57 +410,28 @@ module Json_layout = struct let of_yojson json = of_yojson_generic ~fields of_yojson json end + module Constraint_config = struct + type t = + { constraint_constants : Genesis_constants.Constraint_constants.Inputs.t + ; proof_level : string + } + [@@deriving yojson, fields] + + let fields = Fields.names |> Array.of_list + + let of_yojson json = of_yojson_generic ~fields of_yojson json + end + type t = - { daemon : Daemon.t option [@default None] - ; genesis : Genesis.t option [@default None] - ; proof : Proof_keys.t option [@default None] - ; ledger : Ledger.t option [@default None] + { daemon : Mina_compile_config.Inputs.t + ; genesis : Genesis_constants.Inputs.t + ; proof : Constraint_config.t + ; ledger : Ledger.t ; epoch_data : Epoch_data.t option [@default None] } - [@@deriving yojson, fields] - - let fields = Fields.names |> Array.of_list - - let of_yojson json = of_yojson_generic ~fields of_yojson json + [@@deriving yojson] end -(** JSON representation: - - { "daemon": - { "txpool_max_size": 1 - , "peer_list_url": "https://www.example.com/peer-list.txt" } - , "genesis": { "k": 1, "delta": 1 } - , "proof": - { "level": "check" - , "sub_windows_per_window": 8 - , "ledger_depth": 14 - , "work_delay": 2 - , "block_window_duration_ms": 120000 - , "transaction_capacity": {"txns_per_second_x10": 2} - , "coinbase_amount": "200" - , "supercharged_coinbase_factor": 2 - , "account_creation_fee": "0.001" } - , "ledger": - { "name": "release" - , "accounts": - [ { "pk": "public_key" - , "sk": "secret_key" - , "balance": "0.000600000" - , "delegate": "public_key" } - , { "pk": "public_key" - , "sk": "secret_key" - , "balance": "0.000000000" - , "delegate": "public_key" } ] - , "hash": "root_hash" - , "num_accounts": 10 - , "genesis_state_timestamp": "2000-00-00 12:00:00+0100" } } - - All fields are optional *except*: - * each account in [ledger.accounts] must have a [balance] field - * if [ledger] is present, it must feature one of [name], [accounts] or [hash]. - -*) - module Accounts = struct module Single = struct module Timed = struct @@ -592,15 +464,10 @@ module Accounts = struct } [@@deriving bin_io_unversioned, sexp] - let to_json_layout : t -> Json_layout.Accounts.Single.t = Fn.id - let of_json_layout : Json_layout.Accounts.Single.t -> (t, string) Result.t = Result.return - let to_yojson x = Json_layout.Accounts.Single.to_yojson (to_json_layout x) - - let of_yojson json = - Result.bind ~f:of_json_layout (Json_layout.Accounts.Single.of_yojson json) + let to_yojson = Json_layout.Accounts.Single.to_yojson let default = Json_layout.Accounts.Single.default @@ -747,11 +614,6 @@ module Accounts = struct ; permissions ; zkapp = Option.map ~f:mk_zkapp a.zkapp } - - let gen = - Quickcheck.Generator.map Mina_base.Account.gen ~f:(fun a -> - (* This will never fail with a proper account generator. *) - of_account a |> Result.ok_or_failwith ) end type single = Single.t = @@ -771,9 +633,6 @@ module Accounts = struct type t = Single.t list [@@deriving bin_io_unversioned] - let to_json_layout : t -> Json_layout.Accounts.t = - List.map ~f:Single.to_json_layout - let of_json_layout (t : Json_layout.Accounts.t) : (t, string) Result.t = let exception Stop of string in try @@ -786,10 +645,7 @@ module Accounts = struct raise (Stop err) ) with Stop err -> Error err - let to_yojson x = Json_layout.Accounts.to_yojson (to_json_layout x) - - let of_yojson json = - Result.bind ~f:of_json_layout (Json_layout.Accounts.of_yojson json) + let to_yojson x = Json_layout.Accounts.to_yojson (Fn.id x) end module Ledger = struct @@ -838,10 +694,12 @@ module Ledger = struct | Named name -> { without_base with name = Some name } | Accounts accounts -> - { without_base with accounts = Some (Accounts.to_json_layout accounts) } + { without_base with accounts = Some accounts } | Hash -> without_base + let to_yojson x = Json_layout.Ledger.to_yojson (to_json_layout x) + let of_json_layout ({ accounts ; num_accounts @@ -884,435 +742,17 @@ module Ledger = struct ; name ; add_genesis_winner } - - let to_yojson x = Json_layout.Ledger.to_yojson (to_json_layout x) - - let of_yojson json = - Result.bind ~f:of_json_layout (Json_layout.Ledger.of_yojson json) - - let gen = - let open Quickcheck in - let open Generator.Let_syntax in - let%bind accounts = Generator.list Accounts.Single.gen in - let num_accounts = List.length accounts in - let balances = - List.mapi accounts ~f:(fun number a -> (number, a.balance)) - in - let%bind hash = - Mina_base.Ledger_hash.(Generator.map ~f:to_base58_check gen) - |> Option.quickcheck_generator - in - let%bind name = String.gen_nonempty in - let%map add_genesis_winner = Bool.quickcheck_generator in - { base = Accounts accounts - ; num_accounts = Some num_accounts - ; balances - ; hash - ; s3_data_hash = None - ; name = Some name - ; add_genesis_winner = Some add_genesis_winner - } -end - -module Proof_keys = struct - module Level = struct - type t = Full | Check | None [@@deriving bin_io_unversioned, equal] - - let to_string = function - | Full -> - "full" - | Check -> - "check" - | None -> - "none" - - let of_string str = - match String.lowercase str with - | "full" -> - Ok Full - | "check" -> - Ok Check - | "none" -> - Ok None - | _ -> - Error "Expected one of 'full', 'check', or 'none'" - - let to_json_layout = to_string - - let of_json_layout str = - Result.map_error (of_string str) ~f:(fun err -> - "Runtime_config.Proof_keys.Level.of_json_layout: Could not decode \ - field 'level'. " ^ err ) - - let to_yojson x = `String (to_json_layout x) - - let of_yojson = function - | `String str -> - of_json_layout str - | _ -> - Error - "Runtime_config.Proof_keys.Level.of_json_layout: Expected the \ - field 'level' to contain a string" - - let gen = Quickcheck.Generator.of_list [ Full; Check; None ] - end - - module Transaction_capacity = struct - type t = Log_2 of int | Txns_per_second_x10 of int - [@@deriving bin_io_unversioned] - - let to_json_layout : t -> Json_layout.Proof_keys.Transaction_capacity.t = - function - | Log_2 i -> - { log_2 = Some i; txns_per_second_x10 = None } - | Txns_per_second_x10 i -> - { log_2 = None; txns_per_second_x10 = Some i } - - let of_json_layout : - Json_layout.Proof_keys.Transaction_capacity.t -> (t, string) Result.t = - function - | { log_2 = Some i; txns_per_second_x10 = None } -> - Ok (Log_2 i) - | { txns_per_second_x10 = Some i; log_2 = None } -> - Ok (Txns_per_second_x10 i) - | _ -> - Error - "Runtime_config.Proof_keys.Transaction_capacity.of_json_layout: \ - Expected exactly one of the fields '2_to_the' or \ - 'txns_per_second_x10'" - - let to_yojson x = - Json_layout.Proof_keys.Transaction_capacity.to_yojson (to_json_layout x) - - let of_yojson json = - Result.bind ~f:of_json_layout - (Json_layout.Proof_keys.Transaction_capacity.of_yojson json) - - let gen = - let open Quickcheck in - let log_2_gen = - Generator.map ~f:(fun i -> Log_2 i) @@ Int.gen_incl 0 10 - in - let txns_per_second_x10_gen = - Generator.map ~f:(fun i -> Txns_per_second_x10 i) @@ Int.gen_incl 0 1000 - in - Generator.union [ log_2_gen; txns_per_second_x10_gen ] - - let small : t = Log_2 2 - - let medium : t = Log_2 3 - end - - type t = - { level : Level.t option - ; sub_windows_per_window : int option - ; ledger_depth : int option - ; work_delay : int option - ; block_window_duration_ms : int option - ; transaction_capacity : Transaction_capacity.t option - ; coinbase_amount : Currency.Amount.Stable.Latest.t option - ; supercharged_coinbase_factor : int option - ; account_creation_fee : Currency.Fee.Stable.Latest.t option - ; fork : Fork_config.t option - } - [@@deriving bin_io_unversioned] - - let make ?level ?sub_windows_per_window ?ledger_depth ?work_delay - ?block_window_duration_ms ?transaction_capacity ?coinbase_amount - ?supercharged_coinbase_factor ?account_creation_fee ?fork () = - { level - ; sub_windows_per_window - ; ledger_depth - ; work_delay - ; block_window_duration_ms - ; transaction_capacity - ; coinbase_amount - ; supercharged_coinbase_factor - ; account_creation_fee - ; fork - } - - let to_json_layout - { level - ; sub_windows_per_window - ; ledger_depth - ; work_delay - ; block_window_duration_ms - ; transaction_capacity - ; coinbase_amount - ; supercharged_coinbase_factor - ; account_creation_fee - ; fork - } = - { Json_layout.Proof_keys.level = Option.map ~f:Level.to_json_layout level - ; sub_windows_per_window - ; ledger_depth - ; work_delay - ; block_window_duration_ms - ; transaction_capacity = - Option.map ~f:Transaction_capacity.to_json_layout transaction_capacity - ; coinbase_amount - ; supercharged_coinbase_factor - ; account_creation_fee - ; fork - } - - let of_json_layout - { Json_layout.Proof_keys.level - ; sub_windows_per_window - ; ledger_depth - ; work_delay - ; block_window_duration_ms - ; transaction_capacity - ; coinbase_amount - ; supercharged_coinbase_factor - ; account_creation_fee - ; fork - } = - let open Result.Let_syntax in - let%map level = result_opt ~f:Level.of_json_layout level - and transaction_capacity = - result_opt ~f:Transaction_capacity.of_json_layout transaction_capacity - in - { level - ; sub_windows_per_window - ; ledger_depth - ; work_delay - ; block_window_duration_ms - ; transaction_capacity - ; coinbase_amount - ; supercharged_coinbase_factor - ; account_creation_fee - ; fork - } - - let to_yojson x = Json_layout.Proof_keys.to_yojson (to_json_layout x) - - let of_yojson json = - Result.bind ~f:of_json_layout (Json_layout.Proof_keys.of_yojson json) - - let combine t1 t2 = - { level = opt_fallthrough ~default:t1.level t2.level - ; sub_windows_per_window = - opt_fallthrough ~default:t1.sub_windows_per_window - t2.sub_windows_per_window - ; ledger_depth = opt_fallthrough ~default:t1.ledger_depth t2.ledger_depth - ; work_delay = opt_fallthrough ~default:t1.work_delay t2.work_delay - ; block_window_duration_ms = - opt_fallthrough ~default:t1.block_window_duration_ms - t2.block_window_duration_ms - ; transaction_capacity = - opt_fallthrough ~default:t1.transaction_capacity t2.transaction_capacity - ; coinbase_amount = - opt_fallthrough ~default:t1.coinbase_amount t2.coinbase_amount - ; supercharged_coinbase_factor = - opt_fallthrough ~default:t1.supercharged_coinbase_factor - t2.supercharged_coinbase_factor - ; account_creation_fee = - opt_fallthrough ~default:t1.account_creation_fee t2.account_creation_fee - ; fork = opt_fallthrough ~default:t1.fork t2.fork - } - - let gen = - let open Quickcheck.Generator.Let_syntax in - let%bind level = Level.gen in - let%bind sub_windows_per_window = Int.gen_incl 0 1000 in - let%bind ledger_depth = Int.gen_incl 0 64 in - let%bind work_delay = Int.gen_incl 0 1000 in - let%bind block_window_duration_ms = Int.gen_incl 1_000 360_000 in - let%bind transaction_capacity = Transaction_capacity.gen in - let%bind coinbase_amount = - Currency.Amount.(gen_incl zero (of_mina_int_exn 1)) - in - let%bind supercharged_coinbase_factor = Int.gen_incl 0 100 in - let%bind account_creation_fee = - Currency.Fee.(gen_incl one (of_mina_int_exn 10)) - in - let%map fork = - let open Quickcheck.Generator in - union [ map ~f:Option.some Fork_config.gen; return None ] - in - { level = Some level - ; sub_windows_per_window = Some sub_windows_per_window - ; ledger_depth = Some ledger_depth - ; work_delay = Some work_delay - ; block_window_duration_ms = Some block_window_duration_ms - ; transaction_capacity = Some transaction_capacity - ; coinbase_amount = Some coinbase_amount - ; supercharged_coinbase_factor = Some supercharged_coinbase_factor - ; account_creation_fee = Some account_creation_fee - ; fork - } -end - -module Genesis = struct - type t = Json_layout.Genesis.t = - { k : int option (* the depth of finality constant (in slots) *) - ; delta : int option (* max permissible delay of packets (in slots) *) - ; slots_per_epoch : int option - ; slots_per_sub_window : int option - ; grace_period_slots : int option - ; genesis_state_timestamp : string option - } - [@@deriving bin_io_unversioned] - - let to_json_layout : t -> Json_layout.Genesis.t = Fn.id - - let of_json_layout : Json_layout.Genesis.t -> (t, string) Result.t = - Result.return - - let to_yojson x = Json_layout.Genesis.to_yojson (to_json_layout x) - - let of_yojson json = - Result.bind ~f:of_json_layout (Json_layout.Genesis.of_yojson json) - - let combine t1 t2 = - { k = opt_fallthrough ~default:t1.k t2.k - ; delta = opt_fallthrough ~default:t1.delta t2.delta - ; slots_per_epoch = - opt_fallthrough ~default:t1.slots_per_epoch t2.slots_per_epoch - ; slots_per_sub_window = - opt_fallthrough ~default:t1.slots_per_sub_window t2.slots_per_sub_window - ; grace_period_slots = - opt_fallthrough ~default:t1.grace_period_slots t2.grace_period_slots - ; genesis_state_timestamp = - opt_fallthrough ~default:t1.genesis_state_timestamp - t2.genesis_state_timestamp - } - - let gen = - let open Quickcheck.Generator.Let_syntax in - let%bind k = Int.gen_incl 0 1000 in - let%bind delta = Int.gen_incl 0 1000 in - let%bind slots_per_epoch = Int.gen_incl 1 1_000_000 in - let%bind slots_per_sub_window = Int.gen_incl 1 1_000 in - let%bind grace_period_slots = - Quickcheck.Generator.union - [ return None - ; Quickcheck.Generator.map ~f:Option.some @@ Int.gen_incl 0 1000 - ] - in - let%map genesis_state_timestamp = - Time.(gen_incl epoch (of_string "2050-01-01 00:00:00Z")) - |> Quickcheck.Generator.map ~f:Time.to_string - in - { k = Some k - ; delta = Some delta - ; slots_per_epoch = Some slots_per_epoch - ; slots_per_sub_window = Some slots_per_sub_window - ; grace_period_slots - ; genesis_state_timestamp = Some genesis_state_timestamp - } -end - -module Daemon = struct - (* Peer list URL should usually be None. This option is better provided with - a command line argument. Putting it in the config makes the network explicitly - rely on a certain number of nodes, reducing decentralisation. See #14766 *) - type t = Json_layout.Daemon.t = - { txpool_max_size : int option - ; peer_list_url : string option - ; zkapp_proof_update_cost : float option [@default None] - ; zkapp_signed_single_update_cost : float option [@default None] - ; zkapp_signed_pair_update_cost : float option [@default None] - ; zkapp_transaction_cost_limit : float option [@default None] - ; max_event_elements : int option [@default None] - ; max_action_elements : int option [@default None] - ; zkapp_cmd_limit_hardcap : int option [@default None] - ; slot_tx_end : int option [@default None] - ; slot_chain_end : int option [@default None] - ; minimum_user_command_fee : Currency.Fee.Stable.Latest.t option - [@default None] - ; network_id : string option [@default None] - } - [@@deriving bin_io_unversioned] - - let to_json_layout : t -> Json_layout.Daemon.t = Fn.id - - let of_json_layout : Json_layout.Daemon.t -> (t, string) Result.t = - Result.return - - let to_yojson x = Json_layout.Daemon.to_yojson (to_json_layout x) - - let of_yojson json = - Result.bind ~f:of_json_layout (Json_layout.Daemon.of_yojson json) - - let combine t1 t2 = - { txpool_max_size = - opt_fallthrough ~default:t1.txpool_max_size t2.txpool_max_size - ; peer_list_url = opt_fallthrough ~default:t1.peer_list_url t2.peer_list_url - ; zkapp_proof_update_cost = - opt_fallthrough ~default:t1.zkapp_proof_update_cost - t2.zkapp_proof_update_cost - ; zkapp_signed_single_update_cost = - opt_fallthrough ~default:t1.zkapp_signed_single_update_cost - t2.zkapp_signed_single_update_cost - ; zkapp_signed_pair_update_cost = - opt_fallthrough ~default:t1.zkapp_signed_pair_update_cost - t2.zkapp_signed_pair_update_cost - ; zkapp_transaction_cost_limit = - opt_fallthrough ~default:t1.zkapp_transaction_cost_limit - t2.zkapp_transaction_cost_limit - ; max_event_elements = - opt_fallthrough ~default:t1.max_event_elements t2.max_event_elements - ; max_action_elements = - opt_fallthrough ~default:t1.max_action_elements t2.max_action_elements - ; zkapp_cmd_limit_hardcap = - opt_fallthrough ~default:t1.zkapp_cmd_limit_hardcap - t2.zkapp_cmd_limit_hardcap - ; slot_tx_end = opt_fallthrough ~default:t1.slot_tx_end t2.slot_tx_end - ; slot_chain_end = - opt_fallthrough ~default:t1.slot_chain_end t2.slot_chain_end - ; minimum_user_command_fee = - opt_fallthrough ~default:t1.minimum_user_command_fee - t2.minimum_user_command_fee - ; network_id = opt_fallthrough ~default:t1.network_id t2.network_id - } - - let gen = - let open Quickcheck.Generator.Let_syntax in - let%bind txpool_max_size = Int.gen_incl 0 1000 in - let%bind zkapp_proof_update_cost = Float.gen_incl 0.0 100.0 in - let%bind zkapp_signed_single_update_cost = Float.gen_incl 0.0 100.0 in - let%bind zkapp_signed_pair_update_cost = Float.gen_incl 0.0 100.0 in - let%bind zkapp_transaction_cost_limit = Float.gen_incl 0.0 100.0 in - let%bind max_event_elements = Int.gen_incl 0 100 in - let%bind zkapp_cmd_limit_hardcap = Int.gen_incl 0 1000 in - let%bind minimum_user_command_fee = - Currency.Fee.(gen_incl one (of_mina_int_exn 10)) - in - let%map max_action_elements = Int.gen_incl 0 1000 in - { txpool_max_size = Some txpool_max_size - ; peer_list_url = None - ; zkapp_proof_update_cost = Some zkapp_proof_update_cost - ; zkapp_signed_single_update_cost = Some zkapp_signed_single_update_cost - ; zkapp_signed_pair_update_cost = Some zkapp_signed_pair_update_cost - ; zkapp_transaction_cost_limit = Some zkapp_transaction_cost_limit - ; max_event_elements = Some max_event_elements - ; max_action_elements = Some max_action_elements - ; zkapp_cmd_limit_hardcap = Some zkapp_cmd_limit_hardcap - ; slot_tx_end = None - ; slot_chain_end = None - ; minimum_user_command_fee = Some minimum_user_command_fee - ; network_id = None - } end module Epoch_data = struct module Data = struct type t = { ledger : Ledger.t; seed : string } - [@@deriving bin_io_unversioned, yojson] - - let gen = - let open Quickcheck.Generator.Let_syntax in - let%bind ledger = Ledger.gen in - let%map seed = String.gen_nonempty in - { ledger; seed } + [@@deriving bin_io_unversioned, to_yojson] end type t = { staking : Data.t; next : Data.t option (*If None, then next = staking*) } - [@@deriving bin_io_unversioned, yojson] + [@@deriving bin_io_unversioned, to_yojson] let to_json_layout : t -> Json_layout.Epoch_data.t = fun { staking; next } -> @@ -1379,119 +819,89 @@ module Epoch_data = struct { staking; next } let to_yojson x = Json_layout.Epoch_data.to_yojson (to_json_layout x) +end - let of_yojson json = - Result.bind ~f:of_json_layout (Json_layout.Epoch_data.of_yojson json) +module Constraint = struct + type t = + { constraint_constants : Genesis_constants.Constraint_constants.t + ; proof_level : Genesis_constants.Proof_level.t + } + [@@deriving to_yojson] - let gen = - let open Quickcheck.Generator.Let_syntax in - let%bind staking = Data.gen in - let%map next = Option.quickcheck_generator Data.gen in - { staking; next } + let of_json_layout : Json_layout.Constraint_config.t -> t = + fun { constraint_constants; proof_level } -> + { constraint_constants = + Genesis_constants.Constraint_constants.make constraint_constants + ; proof_level = Genesis_constants.Proof_level.of_string proof_level + } end type t = - { daemon : Daemon.t option - ; genesis : Genesis.t option - ; proof : Proof_keys.t option - ; ledger : Ledger.t option + { compile_config : Mina_compile_config.t + ; genesis_constants : Genesis_constants.t + ; constraint_config : Constraint.t + ; ledger : Ledger.t ; epoch_data : Epoch_data.t option } -[@@deriving bin_io_unversioned] - -let make ?daemon ?genesis ?proof ?ledger ?epoch_data () = - { daemon; genesis; proof; ledger; epoch_data } - -let to_json_layout { daemon; genesis; proof; ledger; epoch_data } = - { Json_layout.daemon = Option.map ~f:Daemon.to_json_layout daemon - ; genesis = Option.map ~f:Genesis.to_json_layout genesis - ; proof = Option.map ~f:Proof_keys.to_json_layout proof - ; ledger = Option.map ~f:Ledger.to_json_layout ledger - ; epoch_data = Option.map ~f:Epoch_data.to_json_layout epoch_data - } +[@@deriving to_yojson] -let of_json_layout { Json_layout.daemon; genesis; proof; ledger; epoch_data } = - let open Result.Let_syntax in - let%map daemon = result_opt ~f:Daemon.of_json_layout daemon - and genesis = result_opt ~f:Genesis.of_json_layout genesis - and proof = result_opt ~f:Proof_keys.of_json_layout proof - and ledger = result_opt ~f:Ledger.of_json_layout ledger - and epoch_data = result_opt ~f:Epoch_data.of_json_layout epoch_data in - { daemon; genesis; proof; ledger; epoch_data } - -let to_yojson x = Json_layout.to_yojson (to_json_layout x) - -let to_yojson_without_accounts x = - let layout = to_json_layout x in +let format_as_json_without_accounts (_ : t) : Yojson.Safe.t = failwith "TODO" +(* let genesis_accounts = - let%bind.Option { accounts; _ } = layout.ledger in + let%bind.Option { accounts; _ } = + Option.map ~f:Ledger.to_json_layout x.ledger + in Option.map ~f:List.length accounts in let staking_accounts = - let%bind.Option { staking; _ } = layout.epoch_data in - Option.map ~f:List.length staking.accounts + let%bind.Option { staking; _ } = x.epoch_data in + Option.map ~f:List.length (Ledger.to_json_layout staking.ledger).accounts in let next_accounts = - let%bind.Option { next; _ } = layout.epoch_data in - let%bind.Option { accounts; _ } = next in - Option.map ~f:List.length accounts + let%bind.Option { next; _ } = x.epoch_data in + let%bind.Option { ledger; _ } = next in + Option.map ~f:List.length (Ledger.to_json_layout ledger).accounts + in + let f ledger = + { (Ledger.to_json_layout ledger) with Json_layout.Ledger.accounts = None } in - let layout = - let f ledger = { ledger with Json_layout.Ledger.accounts = None } in - { layout with - ledger = Option.map ~f layout.ledger - ; epoch_data = - Option.map layout.epoch_data ~f:(fun { staking; next } -> - { Json_layout.Epoch_data.staking = { staking with accounts = None } - ; next = Option.map next ~f:(fun n -> { n with accounts = None }) + let g ({ staking; next } : Epoch_data.t) = + { Json_layout.Epoch_data.staking = + (let l = f staking.ledger in + { accounts = None + ; seed = staking.seed + ; hash = l.hash + ; s3_data_hash = l.s3_data_hash + } ) + ; next = + Option.map next ~f:(fun n -> + let l = f n.ledger in + { Json_layout.Epoch_data.Data.accounts = None + ; seed = n.seed + ; hash = l.hash + ; s3_data_hash = l.s3_data_hash } ) } in - ( Json_layout.to_yojson layout + let json = + `Assoc + [ ("daemon", Mina_compile_config.to_yojson x.compile_config) + ; ("genesis", Genesis_constants.to_yojson x.genesis_constants) + ; ("proof", Genesis_constants.Constraint_constants.to_yojson x.constraint_constants) + ; ( "ledger" + , Option.value_map ~default:`Null ~f:Json_layout.Ledger.to_yojson + (Option.map ~f x.ledger) ) + ; ( "epoch_data" + , Option.value_map ~default:`Null ~f:Json_layout.Epoch_data.to_yojson + (Option.map ~f:g x.epoch_data) ) + ] + in + ( json , `Accounts_omitted (`Genesis genesis_accounts, `Staking staking_accounts, `Next next_accounts) ) -let of_yojson json = Result.bind ~f:of_json_layout (Json_layout.of_yojson json) - -let default = - { daemon = None - ; genesis = None - ; proof = None - ; ledger = None - ; epoch_data = None - } - -let combine t1 t2 = - let merge ~combine t1 t2 = - match (t1, t2) with - | Some t1, Some t2 -> - Some (combine t1 t2) - | Some t, None | None, Some t -> - Some t - | None, None -> - None - in - { daemon = merge ~combine:Daemon.combine t1.daemon t2.daemon - ; genesis = merge ~combine:Genesis.combine t1.genesis t2.genesis - ; proof = merge ~combine:Proof_keys.combine t1.proof t2.proof - ; ledger = opt_fallthrough ~default:t1.ledger t2.ledger - ; epoch_data = opt_fallthrough ~default:t1.epoch_data t2.epoch_data - } - -let gen = - let open Quickcheck.Generator.Let_syntax in - let%map daemon = Daemon.gen - and genesis = Genesis.gen - and proof = Proof_keys.gen - and ledger = Ledger.gen - and epoch_data = Epoch_data.gen in - { daemon = Some daemon - ; genesis = Some genesis - ; proof = Some proof - ; ledger = Some ledger - ; epoch_data = Some epoch_data - } +*) let ledger_accounts (ledger : Mina_ledger.Ledger.Any_ledger.witness) = let open Async.Deferred.Result.Let_syntax in @@ -1524,7 +934,8 @@ let ledger_of_accounts accounts = let make_fork_config ~staged_ledger ~global_slot_since_genesis ~state_hash ~blockchain_length ~staking_ledger ~staking_epoch_seed ~next_epoch_ledger - ~next_epoch_seed = + ~next_epoch_seed ~genesis_constants + ~(constraint_config : Constraint.t) ~compile_config = let open Async.Deferred.Result.Let_syntax in let global_slot_since_genesis = Mina_numbers.Global_slot_since_genesis.to_int global_slot_since_genesis @@ -1544,10 +955,12 @@ let make_fork_config ~staged_ledger ~global_slot_since_genesis ~state_hash @@ Mina_ledger.Ledger.merkle_root staged_ledger in let fork = - Fork_config. - { state_hash = Mina_base.State_hash.to_base58_check state_hash - ; blockchain_length - ; global_slot_since_genesis + Genesis_constants.Fork_constants. + { state_hash + ; blockchain_length = Mina_numbers.Length.of_int blockchain_length + ; global_slot_since_genesis = + Mina_numbers.Global_slot_since_genesis.of_int + global_slot_since_genesis } in let%bind () = yield () in @@ -1572,17 +985,16 @@ let make_fork_config ~staged_ledger ~global_slot_since_genesis ~state_hash { ledger = ledger_of_accounts accounts; seed = next_epoch_seed } ) } in - make - (* add_genesis_winner must be set to false, because this - config effectively creates a continuation of the current - blockchain state and therefore the genesis ledger already - contains the winner of the previous block. No need to - artificially add it. In fact, it wouldn't work at all, - because the new node would try to create this account at - startup, even though it already exists, leading to an error.*) - ~epoch_data - ~ledger: - { base = Accounts accounts + { (* add_genesis_winner must be set to false, because this + config effectively creates a continuation of the current + blockchain state and therefore the genesis ledger already + contains the winner of the previous block. No need to + artificially add it. In fact, it wouldn't work at all, + because the new node would try to create this account at + startup, even though it already exists, leading to an error.*) + epoch_data = Some epoch_data + ; ledger = + { Ledger.base = Accounts accounts ; num_accounts = None ; balances = [] ; hash @@ -1590,11 +1002,11 @@ let make_fork_config ~staged_ledger ~global_slot_since_genesis ~state_hash ; name = None ; add_genesis_winner = Some false } - ~proof:(Proof_keys.make ~fork ()) () - -let slot_tx_end, slot_chain_end = - let f get_runtime t = - let open Option.Let_syntax in - t.daemon >>= get_runtime >>| Mina_numbers.Global_slot_since_hard_fork.of_int - in - (f (fun d -> d.slot_tx_end), f (fun d -> d.slot_chain_end)) + ; constraint_config = + { constraint_config with + constraint_constants = + { constraint_config.constraint_constants with fork = Some fork } + } + ; genesis_constants + ; compile_config + } diff --git a/src/lib/transition_handler/validator.ml b/src/lib/transition_handler/validator.ml index 1cd4894de62..d94339ca105 100644 --- a/src/lib/transition_handler/validator.ml +++ b/src/lib/transition_handler/validator.ml @@ -136,12 +136,9 @@ let run ~context:(module Context : CONTEXT) ~trust_system ~time_controller @@ fun () -> let transition = With_hash.data transition_with_hash in let sender = Envelope.Incoming.sender transition_env in - let slot_tx_end = - Runtime_config.slot_tx_end - precomputed_values.Precomputed_values.runtime_config - in + let slot_tx_end = precomputed_values.compile_config.slot_tx_end in let slot_chain_end = - Runtime_config.slot_chain_end precomputed_values.runtime_config + precomputed_values.compile_config.slot_chain_end in match validate_transition_is_relevant From 9e5ef9353143f99742e9805430d076cc55398c06 Mon Sep 17 00:00:00 2001 From: martyall Date: Tue, 17 Sep 2024 17:10:38 -0700 Subject: [PATCH 04/29] update logic for loading in config file from json --- .../genesis_ledger_helper.ml | 274 +++++++++--------- .../lib/genesis_ledger_helper_lib.ml | 195 +------------ src/lib/runtime_config/runtime_config.ml | 19 +- 3 files changed, 151 insertions(+), 337 deletions(-) diff --git a/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml b/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml index 29aab4f6b9a..a827379cf36 100644 --- a/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml +++ b/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml @@ -415,8 +415,9 @@ module Ledger = struct let depth = depth end) ) - let load ~proof_level ~genesis_dir ~logger ~constraint_constants - ?(ledger_name_prefix = "genesis_ledger") ?overwrite_version + let load ~genesis_dir ~logger + ~(constraint_constants : Genesis_constants.Constraint_constants.t) + ~proof_level ?(ledger_name_prefix = "genesis_ledger") ?overwrite_version (config : Runtime_config.Ledger.t) = Monitor.try_with_join_or_error ~here:[%here] (fun () -> let padded_accounts_opt = @@ -556,7 +557,7 @@ module Ledger = struct end module Epoch_data = struct - let load ~proof_level ~genesis_dir ~logger ~constraint_constants + let load ~genesis_dir ~logger ~constraint_constants ~proof_level (config : Runtime_config.Epoch_data.t option) = let open Deferred.Or_error.Let_syntax in match config with @@ -565,8 +566,8 @@ module Epoch_data = struct | Some config -> let ledger_name_prefix = "epoch_ledger" in let load_ledger ledger = - Ledger.load ~proof_level ~genesis_dir ~logger ~constraint_constants - ~ledger_name_prefix ledger + Ledger.load ~genesis_dir ~logger ~constraint_constants + ~ledger_name_prefix ~proof_level ledger in let%bind staking, staking_config = let%map staking_ledger, config', ledger_file = @@ -665,30 +666,31 @@ module Genesis_proof = struct ~metadata:[ ("base_hash", Base_hash.to_yojson base_hash) ] ; return None - let generate_inputs ~runtime_config ~proof_level ~ledger ~genesis_epoch_data - ~constraint_constants ~blockchain_proof_system_id - ~(genesis_constants : Genesis_constants.t) = + let generate_inputs ~ledger ~genesis_epoch_data ~blockchain_proof_system_id + ~(config : Runtime_config.t) : Genesis_proof.Inputs.t = let consensus_constants = - Consensus.Constants.create ~constraint_constants - ~protocol_constants:genesis_constants.protocol + Consensus.Constants.create + ~constraint_constants:config.constraint_config.constraint_constants + ~protocol_constants:config.genesis_constants.protocol in let open Staged_ledger_diff in let protocol_state_with_hashes = Mina_state.Genesis_protocol_state.t ~genesis_ledger:(Genesis_ledger.Packed.t ledger) - ~genesis_epoch_data ~constraint_constants ~consensus_constants - ~genesis_body_reference + ~genesis_epoch_data + ~constraint_constants:config.constraint_config.constraint_constants + ~consensus_constants ~genesis_body_reference in - { Genesis_proof.Inputs.runtime_config - ; constraint_constants - ; proof_level + { constraint_constants = config.constraint_config.constraint_constants + ; proof_level = config.constraint_config.proof_level + ; compile_config = config.compile_config ; blockchain_proof_system_id ; genesis_ledger = ledger ; genesis_epoch_data ; consensus_constants ; protocol_state_with_hashes ; constraint_system_digests = None - ; genesis_constants + ; genesis_constants = config.genesis_constants ; genesis_body_reference } @@ -699,7 +701,7 @@ module Genesis_proof = struct @@ Genesis_proof.create_values_no_proof { genesis_ledger = inputs.genesis_ledger ; genesis_epoch_data = inputs.genesis_epoch_data - ; runtime_config = inputs.runtime_config + ; compile_config = inputs.compile_config ; proof_level = inputs.proof_level ; blockchain_proof_system_id = None ; constraint_system_digests = None @@ -731,34 +733,49 @@ module Genesis_proof = struct let create_values_no_proof = Genesis_proof.create_values_no_proof end -let load_config_json filename = - Monitor.try_with_or_error ~here:[%here] (fun () -> - let%map json = Reader.file_contents filename in - Yojson.Safe.from_string json ) - -let load_config_file filename = - let open Deferred.Or_error.Let_syntax in - Monitor.try_with_join_or_error ~here:[%here] (fun () -> - let%map json = load_config_json filename in - match Runtime_config.of_yojson json with - | Ok config -> - Ok config - | Error err -> - Or_error.error_string err ) +module type Config_loader = sig + val load_config : + ?genesis_dir:string + -> ?overwrite_version:Unsigned.UInt32.t + -> ?cli_proof_level:Genesis_constants.Proof_level.t + -> config_file:string + -> logger:Logger.t + -> unit + -> (Precomputed_values.t * Runtime_config.t) Deferred.Or_error.t + + val load_config_exn : + ?genesis_dir:string + -> ?overwrite_version:Unsigned.UInt32.t + -> ?cli_proof_level:Genesis_constants.Proof_level.t + -> config_file:string + -> logger:Logger.t + -> unit + -> (Precomputed_values.t * Runtime_config.t) Deferred.t + + val init_from_config_file : + ?overwrite_version:Unsigned.UInt32.t + -> ?cli_proof_level:Genesis_constants.Proof_level.t + -> genesis_dir:string + -> logger:Logger.t + -> Runtime_config.Json_layout.t + -> (Precomputed_values.t * Runtime_config.t) Deferred.Or_error.t +end + +module Config_loader : Config_loader = struct + let load_config_json filename = + Monitor.try_with_or_error ~here:[%here] (fun () -> + let%map json = Reader.file_contents filename in + Yojson.Safe.from_string json ) let print_config ~logger config = - let ledger_name_json = - Option.value ~default:`Null - @@ let%bind.Option ledger = config.Runtime_config.ledger in - let%map.Option name = ledger.name in - `String name - in + let ledger_name_json = Option.value_map ~default:`Null ~f:(fun a -> `String a) + config.Runtime_config.ledger.name in let ( json_config , `Accounts_omitted ( `Genesis genesis_accounts_omitted , `Staking staking_accounts_omitted , `Next next_accounts_omitted ) ) = - Runtime_config.to_yojson_without_accounts config + Runtime_config.format_as_json_without_accounts config in let append_accounts_omitted s = Option.value_map @@ -774,110 +791,84 @@ let print_config ~logger config = [%log info] "Initializing with runtime configuration. Ledger name: $name" ~metadata -let inputs_from_config_file ?(genesis_dir = Cache_dir.autogen_path) ~logger - ~cli_proof_level ~(genesis_constants : Genesis_constants.t) - ~(constraint_constants : Genesis_constants.Constraint_constants.t) - ~proof_level:compiled_proof_level ?overwrite_version - (config : Runtime_config.t) = - print_config ~logger config ; - let open Deferred.Or_error.Let_syntax in - let proof_level = - List.find_map_exn ~f:Fn.id - [ cli_proof_level - ; Option.Let_syntax.( - let%bind proof = config.proof in - match%map proof.level with - | Full -> - Genesis_constants.Proof_level.Full - | Check -> - Check - | None -> - None) - ; Some compiled_proof_level - ] - in - let constraint_constants, blockchain_proof_system_id = - match config.proof with - | None -> - [%log info] "Using the compiled constraint constants" ; - (constraint_constants, Some (Pickles.Verification_key.Id.dummy ())) - | Some config -> - [%log info] "Using the constraint constants from the configuration file" ; - let blockchain_proof_system_id = - (* We pass [None] here, which will force the constraint systems to be - set up and their hashes evaluated before we can calculate the - genesis proof's filename. - This adds no overhead if we are generating a genesis proof, since - we will do these evaluations anyway to load the blockchain proving - key. Otherwise, this will in a slight slowdown. - *) - None - in - ( make_constraint_constants ~default:constraint_constants config - , blockchain_proof_system_id ) - in - let%bind () = - match (proof_level, compiled_proof_level) with - | _, Full | (Check | None), _ -> - return () - | Full, ((Check | None) as compiled) -> - let str = Genesis_constants.Proof_level.to_string in - [%log fatal] - "Proof level $proof_level is not compatible with compile-time proof \ - level $compiled_proof_level" - ~metadata: - [ ("proof_level", `String (str proof_level)) - ; ("compiled_proof_level", `String (str compiled)) - ] ; - Deferred.Or_error.errorf - "Proof level %s is not compatible with compile-time proof level %s" - (str proof_level) (str compiled) - in - let%bind genesis_ledger, ledger_config, ledger_file = - match config.ledger with - | Some ledger -> - Ledger.load ~proof_level ~genesis_dir ~logger ~constraint_constants - ?overwrite_version ledger - | None -> - [%log fatal] "No ledger was provided in the runtime configuration" ; - Deferred.Or_error.errorf - "No ledger was provided in the runtime configuration" - in - [%log info] "Loaded genesis ledger from $ledger_file" - ~metadata:[ ("ledger_file", `String ledger_file) ] ; - let%bind genesis_epoch_data, genesis_epoch_data_config = - Epoch_data.load ~proof_level ~genesis_dir ~logger ~constraint_constants - config.epoch_data - in - let config = - { config with - ledger = Option.map config.ledger ~f:(fun _ -> ledger_config) - ; epoch_data = genesis_epoch_data_config - } - in - let%map genesis_constants = - Deferred.return - @@ make_genesis_constants ~logger ~default:genesis_constants config - in - let proof_inputs = - Genesis_proof.generate_inputs ~runtime_config:config ~proof_level - ~ledger:genesis_ledger ~constraint_constants ~genesis_constants - ~blockchain_proof_system_id ~genesis_epoch_data - in - (proof_inputs, config) - -let init_from_config_file ?genesis_dir ~cli_proof_level ~genesis_constants - ~constraint_constants ~logger ~proof_level ?overwrite_version - (config : Runtime_config.t) : - (Precomputed_values.t * Runtime_config.t) Deferred.Or_error.t = - let open Deferred.Or_error.Let_syntax in - let%map inputs, config = - inputs_from_config_file ?genesis_dir ~cli_proof_level ~genesis_constants - ~constraint_constants ~logger ~proof_level ?overwrite_version config - in - let values = Genesis_proof.create_values_no_proof inputs in - (values, config) + let init_from_config_file ?overwrite_version ?cli_proof_level ~genesis_dir + ~logger (config : Runtime_config.Json_layout.t) : + (Precomputed_values.t * Runtime_config.t) Deferred.Or_error.t = + let open Deferred.Or_error.Let_syntax in + let constraint_config = + let c = Runtime_config.Constraint_config.of_json_layout config.proof in + { c with + proof_level = Option.value ~default:c.proof_level cli_proof_level + } + in + let { Runtime_config.Constraint_config.constraint_constants; proof_level } = + constraint_config + in + let genesis_constants = Genesis_constants.make config.genesis in + let compile_config = Mina_compile_config.make config.daemon in + let%bind genesis_ledger, runtime_ledger = + match Runtime_config.Ledger.of_json_layout config.ledger with + | Error e -> + Deferred.Or_error.error_string e + | Ok c -> + let%bind genesis_ledger, runtime_ledger, ledger_file = + Ledger.load ~genesis_dir ~logger ~constraint_constants ~proof_level + ?overwrite_version c + in + [%log info] "Loaded genesis ledger from $ledger_file" + ~metadata:[ ("ledger_file", `String ledger_file) ] ; + Deferred.Or_error.return (genesis_ledger, runtime_ledger) + in + let%map genesis_epoch_data, genesis_epoch_data_config = + match config.epoch_data with + | None -> + Deferred.Or_error.return (None, None) + | Some conf -> ( + match Runtime_config.Epoch_data.of_json_layout conf with + | Error e -> + Deferred.Or_error.error_string e + | Ok c -> + Epoch_data.load ~genesis_dir ~logger ~constraint_constants + ~proof_level (Some c) ) + in + let config : Runtime_config.t = + { constraint_config = { constraint_constants; proof_level } + ; genesis_constants + ; compile_config + ; ledger = runtime_ledger + ; epoch_data = genesis_epoch_data_config + } + in + let inputs = + Genesis_proof.generate_inputs ~config ~ledger:genesis_ledger + ~blockchain_proof_system_id:None ~genesis_epoch_data + in + let values = Genesis_proof.create_values_no_proof inputs in + (values, config) + + let load_config ?(genesis_dir = Cache_dir.autogen_path) ?overwrite_version + ?cli_proof_level ~config_file ~logger () = + let open Deferred.Or_error.Let_syntax in + let%bind config_json = load_config_json config_file in + match Runtime_config.Json_layout.of_yojson config_json with + | Error e -> + Deferred.Or_error.error_string e + | Ok c -> + init_from_config_file ?overwrite_version ?cli_proof_level ~genesis_dir + ~logger c + + let load_config_exn ?genesis_dir ?overwrite_version ?cli_proof_level + ~config_file ~logger () = + let open Deferred.Let_syntax in + let%bind config = + load_config ?genesis_dir ?overwrite_version ?cli_proof_level ~config_file + ~logger () + in + Deferred.return (Or_error.ok_exn config) +end + +(* let upgrade_old_config ~logger filename json = match json with | `Assoc fields -> @@ -943,6 +934,7 @@ let upgrade_old_config ~logger filename json = (* This error will get handled properly elsewhere, do nothing here. *) return json +*) let%test_module "Account config test" = ( module struct let%test_unit "Runtime config <=> Account" = diff --git a/src/lib/genesis_ledger_helper/lib/genesis_ledger_helper_lib.ml b/src/lib/genesis_ledger_helper/lib/genesis_ledger_helper_lib.ml index 7b8b553a119..eb807a0c896 100644 --- a/src/lib/genesis_ledger_helper/lib/genesis_ledger_helper_lib.ml +++ b/src/lib/genesis_ledger_helper/lib/genesis_ledger_helper_lib.ml @@ -414,186 +414,6 @@ module Accounts = struct with Stop -> accounts end -let make_constraint_constants - ~(default : Genesis_constants.Constraint_constants.t) - (config : Runtime_config.Proof_keys.t) : - Genesis_constants.Constraint_constants.t = - let work_delay = Option.value ~default:default.work_delay config.work_delay in - let block_window_duration_ms = - Option.value ~default:default.block_window_duration_ms - config.block_window_duration_ms - in - let transaction_capacity_log_2 = - match config.transaction_capacity with - | Some (Log_2 i) -> - i - | Some (Txns_per_second_x10 tps_goal_x10) -> - let max_coinbases = 2 in - let max_user_commands_per_block = - (* block_window_duration is in milliseconds, so divide by 1000 divide - by 10 again because we have tps * 10 - *) - tps_goal_x10 * block_window_duration_ms / (1000 * 10) - in - (* Log of the capacity of transactions per transition. - - 1 will only work if we don't have prover fees. - - 2 will work with prover fees, but not if we want a transaction - included in every block. - - At least 3 ensures a transaction per block and the staged-ledger - unit tests pass. - *) - 1 - + Core_kernel.Int.ceil_log2 (max_user_commands_per_block + max_coinbases) - | None -> - default.transaction_capacity_log_2 - in - let pending_coinbase_depth = - Core_kernel.Int.ceil_log2 - (((transaction_capacity_log_2 + 1) * (work_delay + 1)) + 1) - in - { sub_windows_per_window = - Option.value ~default:default.sub_windows_per_window - config.sub_windows_per_window - ; ledger_depth = - Option.value ~default:default.ledger_depth config.ledger_depth - ; work_delay - ; block_window_duration_ms - ; transaction_capacity_log_2 - ; pending_coinbase_depth - ; coinbase_amount = - Option.value ~default:default.coinbase_amount config.coinbase_amount - ; supercharged_coinbase_factor = - Option.value ~default:default.supercharged_coinbase_factor - config.supercharged_coinbase_factor - ; account_creation_fee = - Option.value ~default:default.account_creation_fee - config.account_creation_fee - ; fork = - ( match config.fork with - | None -> - default.fork - | Some { state_hash; blockchain_length; global_slot_since_genesis } -> - Some - { state_hash = State_hash.of_base58_check_exn state_hash - ; blockchain_length = Mina_numbers.Length.of_int blockchain_length - ; global_slot_since_genesis = - Mina_numbers.Global_slot_since_genesis.of_int - global_slot_since_genesis - } ) - } - -let runtime_config_of_constraint_constants - ~(proof_level : Genesis_constants.Proof_level.t) - (constraint_constants : Genesis_constants.Constraint_constants.t) : - Runtime_config.Proof_keys.t = - { level = - ( match proof_level with - | Full -> - Some Full - | Check -> - Some Check - | None -> - Some None ) - ; sub_windows_per_window = Some constraint_constants.sub_windows_per_window - ; ledger_depth = Some constraint_constants.ledger_depth - ; work_delay = Some constraint_constants.work_delay - ; block_window_duration_ms = - Some constraint_constants.block_window_duration_ms - ; transaction_capacity = - Some (Log_2 constraint_constants.transaction_capacity_log_2) - ; coinbase_amount = Some constraint_constants.coinbase_amount - ; supercharged_coinbase_factor = - Some constraint_constants.supercharged_coinbase_factor - ; account_creation_fee = Some constraint_constants.account_creation_fee - ; fork = - Option.map constraint_constants.fork - ~f:(fun { state_hash; blockchain_length; global_slot_since_genesis } -> - { Runtime_config.Fork_config.state_hash = - State_hash.to_base58_check state_hash - ; blockchain_length = Mina_numbers.Length.to_int blockchain_length - ; global_slot_since_genesis = - Mina_numbers.Global_slot_since_genesis.to_int - global_slot_since_genesis - } ) - } - -let make_genesis_constants ~logger ~(default : Genesis_constants.t) - (config : Runtime_config.t) = - let open Or_error.Let_syntax in - let%map genesis_state_timestamp = - let open Option.Let_syntax in - match - let%bind daemon = config.genesis in - let%map genesis_state_timestamp = daemon.genesis_state_timestamp in - Genesis_constants.validate_time (Some genesis_state_timestamp) - with - | Some (Ok time) -> - Ok (Some time) - | Some (Error msg) -> - [%log error] - "Could not build genesis constants from the configuration file: \ - $error" - ~metadata:[ ("error", `String msg) ] ; - Or_error.errorf - "Could not build genesis constants from the configuration file: %s" - msg - | None -> - Ok None - in - let open Option.Let_syntax in - { Genesis_constants.protocol = - { k = - Option.value ~default:default.protocol.k - (config.genesis >>= fun cfg -> cfg.k) - ; delta = - Option.value ~default:default.protocol.delta - (config.genesis >>= fun cfg -> cfg.delta) - ; slots_per_epoch = - Option.value ~default:default.protocol.slots_per_epoch - (config.genesis >>= fun cfg -> cfg.slots_per_epoch) - ; slots_per_sub_window = - Option.value ~default:default.protocol.slots_per_sub_window - (config.genesis >>= fun cfg -> cfg.slots_per_sub_window) - ; grace_period_slots = - Option.value ~default:default.protocol.grace_period_slots - (config.genesis >>= fun cfg -> cfg.grace_period_slots) - ; genesis_state_timestamp = - Option.value ~default:default.protocol.genesis_state_timestamp - genesis_state_timestamp - } - ; txpool_max_size = - Option.value ~default:default.txpool_max_size - (config.daemon >>= fun cfg -> cfg.txpool_max_size) - ; zkapp_proof_update_cost = - Option.value ~default:default.zkapp_proof_update_cost - (config.daemon >>= fun cfg -> cfg.zkapp_proof_update_cost) - ; zkapp_signed_single_update_cost = - Option.value ~default:default.zkapp_signed_single_update_cost - (config.daemon >>= fun cfg -> cfg.zkapp_signed_single_update_cost) - ; zkapp_signed_pair_update_cost = - Option.value ~default:default.zkapp_signed_pair_update_cost - (config.daemon >>= fun cfg -> cfg.zkapp_signed_pair_update_cost) - ; zkapp_transaction_cost_limit = - Option.value ~default:default.zkapp_transaction_cost_limit - (config.daemon >>= fun cfg -> cfg.zkapp_transaction_cost_limit) - ; max_event_elements = - Option.value ~default:default.max_event_elements - (config.daemon >>= fun cfg -> cfg.max_event_elements) - ; max_action_elements = - Option.value ~default:default.max_action_elements - (config.daemon >>= fun cfg -> cfg.max_action_elements) - ; num_accounts = - Option.value_map ~default:default.num_accounts - (config.ledger >>= fun cfg -> cfg.num_accounts) - ~f:(fun num_accounts -> Some num_accounts) - ; zkapp_cmd_limit_hardcap = - Option.value ~default:default.zkapp_cmd_limit_hardcap - (config.daemon >>= fun cfg -> cfg.zkapp_cmd_limit_hardcap) - ; minimum_user_command_fee = - Option.value ~default:default.minimum_user_command_fee - (config.daemon >>= fun cfg -> cfg.minimum_user_command_fee) - } - let%test_module "Runtime config" = ( module struct [@@@warning "-32"] @@ -615,7 +435,10 @@ let%test_module "Runtime config" = pk in let json = Yojson.Safe.from_string s in - Runtime_config.Ledger.of_yojson json |> Result.ok_or_failwith + Result.( + Runtime_config.Json_layout.Ledger.of_yojson json + >>= Runtime_config.Ledger.of_json_layout) + |> Result.ok_or_failwith let nondefault_token = let owner = @@ -640,7 +463,10 @@ let%test_module "Runtime config" = pk token_id in let json = Yojson.Safe.from_string s in - Runtime_config.Ledger.of_yojson json |> Result.ok_or_failwith + Result.( + Runtime_config.Json_layout.Ledger.of_yojson json + >>= Runtime_config.Ledger.of_json_layout) + |> Result.ok_or_failwith let zkapp_ledger = (* in zkApp account, all fields are required *) @@ -663,7 +489,10 @@ let%test_module "Runtime config" = pk in let json = Yojson.Safe.from_string s in - Runtime_config.Ledger.of_yojson json |> Result.ok_or_failwith + Result.( + Runtime_config.Json_layout.Ledger.of_yojson json + >>= Runtime_config.Ledger.of_json_layout) + |> Result.ok_or_failwith (* omitted account fields in runtime config same as those given by `Account.create` on same public key *) let%test_unit "non-zkApp ledger" = diff --git a/src/lib/runtime_config/runtime_config.ml b/src/lib/runtime_config/runtime_config.ml index 99bad34efb8..6c36f0eea42 100644 --- a/src/lib/runtime_config/runtime_config.ml +++ b/src/lib/runtime_config/runtime_config.ml @@ -845,13 +845,10 @@ type t = } [@@deriving to_yojson] -let format_as_json_without_accounts (_ : t) : Yojson.Safe.t = failwith "TODO" -(* +let format_as_json_without_accounts (x: t) = let genesis_accounts = - let%bind.Option { accounts; _ } = - Option.map ~f:Ledger.to_json_layout x.ledger - in - Option.map ~f:List.length accounts + let { accounts; _ } : Json_layout.Ledger.t = Ledger.to_json_layout x.ledger + in Option.map ~f:List.length accounts in let staking_accounts = let%bind.Option { staking; _ } = x.epoch_data in @@ -883,14 +880,12 @@ let format_as_json_without_accounts (_ : t) : Yojson.Safe.t = failwith "TODO" } ) } in - let json = + let json : Yojson.Safe.t = `Assoc [ ("daemon", Mina_compile_config.to_yojson x.compile_config) ; ("genesis", Genesis_constants.to_yojson x.genesis_constants) - ; ("proof", Genesis_constants.Constraint_constants.to_yojson x.constraint_constants) - ; ( "ledger" - , Option.value_map ~default:`Null ~f:Json_layout.Ledger.to_yojson - (Option.map ~f x.ledger) ) + ; ("proof", Genesis_constants.Constraint_constants.to_yojson x.constraint_config.constraint_constants) + ; ( "ledger", Json_layout.Ledger.to_yojson @@ f x.ledger) ; ( "epoch_data" , Option.value_map ~default:`Null ~f:Json_layout.Epoch_data.to_yojson (Option.map ~f:g x.epoch_data) ) @@ -901,8 +896,6 @@ let format_as_json_without_accounts (_ : t) : Yojson.Safe.t = failwith "TODO" (`Genesis genesis_accounts, `Staking staking_accounts, `Next next_accounts) ) -*) - let ledger_accounts (ledger : Mina_ledger.Ledger.Any_ledger.witness) = let open Async.Deferred.Result.Let_syntax in let yield = Async_unix.Scheduler.yield_every ~n:100 |> Staged.unstage in From 65255674a4104210fcf8a907ea950ecb2097b390 Mon Sep 17 00:00:00 2001 From: martyall Date: Tue, 17 Sep 2024 17:25:57 -0700 Subject: [PATCH 05/29] remove runtime_config from precomputed values, add runtime_config to mina_lib config --- src/lib/genesis_proof/genesis_proof.ml | 24 +++++----- src/lib/mina_lib/config.ml | 2 +- src/lib/mina_lib/mina_lib.ml | 19 ++++---- src/lib/mina_lib/tests/tests.ml | 46 +++++++++---------- .../precomputed_values/precomputed_values.ml | 14 ++++-- 5 files changed, 55 insertions(+), 50 deletions(-) diff --git a/src/lib/genesis_proof/genesis_proof.ml b/src/lib/genesis_proof/genesis_proof.ml index 9d3c74d6a18..a0d63a287c5 100644 --- a/src/lib/genesis_proof/genesis_proof.ml +++ b/src/lib/genesis_proof/genesis_proof.ml @@ -4,10 +4,10 @@ open Mina_state module Inputs = struct type t = - { runtime_config : Runtime_config.t - ; constraint_constants : Genesis_constants.Constraint_constants.t + { constraint_constants : Genesis_constants.Constraint_constants.t ; proof_level : Genesis_constants.Proof_level.t ; genesis_constants : Genesis_constants.t + ; compile_config : Mina_compile_config.t ; genesis_ledger : Genesis_ledger.Packed.t ; genesis_epoch_data : Consensus.Genesis_epoch_data.t ; genesis_body_reference : Consensus.Body_reference.t @@ -24,12 +24,12 @@ module Inputs = struct Pickles.Verification_key.Id.t option } - let runtime_config { runtime_config; _ } = runtime_config - let constraint_constants { constraint_constants; _ } = constraint_constants let genesis_constants { genesis_constants; _ } = genesis_constants + let compile_config { compile_config; _ } = compile_config + let proof_level { proof_level; _ } = proof_level let protocol_constants t = (genesis_constants t).protocol @@ -81,9 +81,9 @@ end module T = struct type t = - { runtime_config : Runtime_config.t - ; constraint_constants : Genesis_constants.Constraint_constants.t + { constraint_constants : Genesis_constants.Constraint_constants.t ; genesis_constants : Genesis_constants.t + ; compile_config : Mina_compile_config.t ; proof_level : Genesis_constants.Proof_level.t ; genesis_ledger : Genesis_ledger.Packed.t ; genesis_epoch_data : Consensus.Genesis_epoch_data.t @@ -95,12 +95,12 @@ module T = struct ; proof_data : Proof_data.t option } - let runtime_config { runtime_config; _ } = runtime_config - let constraint_constants { constraint_constants; _ } = constraint_constants let genesis_constants { genesis_constants; _ } = genesis_constants + let compile_config { compile_config; _ } = compile_config + let proof_level { proof_level; _ } = proof_level let protocol_constants t = (genesis_constants t).protocol @@ -219,10 +219,10 @@ let blockchain_snark_state (inputs : Inputs.t) : ((module T), (module B)) let create_values_no_proof (t : Inputs.t) = - { runtime_config = t.runtime_config - ; constraint_constants = t.constraint_constants + { constraint_constants = t.constraint_constants ; proof_level = t.proof_level ; genesis_constants = t.genesis_constants + ; compile_config = t.compile_config ; genesis_ledger = t.genesis_ledger ; genesis_epoch_data = t.genesis_epoch_data ; genesis_body_reference = t.genesis_body_reference @@ -236,10 +236,10 @@ let create_values_no_proof (t : Inputs.t) = } let to_inputs (t : t) : Inputs.t = - { runtime_config = t.runtime_config - ; constraint_constants = t.constraint_constants + { constraint_constants = t.constraint_constants ; proof_level = t.proof_level ; genesis_constants = t.genesis_constants + ; compile_config = t.compile_config ; genesis_ledger = t.genesis_ledger ; genesis_epoch_data = t.genesis_epoch_data ; genesis_body_reference = t.genesis_body_reference diff --git a/src/lib/mina_lib/config.ml b/src/lib/mina_lib/config.ml index c7e00d2471c..f404858e2a3 100644 --- a/src/lib/mina_lib/config.ml +++ b/src/lib/mina_lib/config.ml @@ -63,6 +63,6 @@ type t = ; stop_time : int ; graphql_control_port : int option [@default None] ; zkapp_cmd_limit : int option ref - ; compile_config : Mina_compile_config.t + ; runtime_config : Runtime_config.t } [@@deriving make] diff --git a/src/lib/mina_lib/mina_lib.ml b/src/lib/mina_lib/mina_lib.ml index 1e627f17b9d..e5441740908 100644 --- a/src/lib/mina_lib/mina_lib.ml +++ b/src/lib/mina_lib/mina_lib.ml @@ -131,7 +131,7 @@ let subscription t = t.subscriptions let commit_id t = t.commit_id -let compile_config t = t.config.compile_config +let compile_config t = t.config.runtime_config.compile_config let peek_frontier frontier_broadcast_pipe = Broadcast_pipe.Reader.peek frontier_broadcast_pipe @@ -1159,7 +1159,7 @@ let check_and_stop_daemon t ~wait = else `Check_in wait_for | Evaluating_vrf _last_checked_slot -> let vrf_poll_interval = - (config t).compile_config.vrf_poll_interval + (config t).runtime_config.compile_config.vrf_poll_interval in `Check_in (Core.Time.Span.scale vrf_poll_interval 2.0) ) @@ -1260,11 +1260,13 @@ let context ~commit_id (config : Config.t) : (module CONTEXT) = let commit_id = commit_id - let vrf_poll_interval = config.compile_config.vrf_poll_interval + let vrf_poll_interval = + config.runtime_config.compile_config.vrf_poll_interval let zkapp_cmd_limit = config.zkapp_cmd_limit - let compaction_interval = config.compile_config.compaction_interval + let compaction_interval = + config.runtime_config.compile_config.compaction_interval end ) let start t = @@ -1353,7 +1355,8 @@ let start t = ~vrf_evaluation_state:t.vrf_evaluation_state ~net:t.components.net ~zkapp_cmd_limit_hardcap: t.config.precomputed_values.genesis_constants.zkapp_cmd_limit_hardcap ) ; - perform_compaction t.config.compile_config.compaction_interval t ; + perform_compaction t.config.runtime_config.compile_config.compaction_interval + t ; let () = match t.config.node_status_url with | Some node_status_url -> @@ -1498,7 +1501,7 @@ let create ~commit_id ?wallets (config : Config.t) = Async.Scheduler.within' ~monitor (fun () -> let set_itn_data (type t) (module M : Itn_settable with type t = t) (t : t) = - if config.compile_config.itn_features then + if config.runtime_config.compile_config.itn_features then let ({ client_port; _ } : Node_addrs_and_ports.t) = config.gossip_net_params.addrs_and_ports in @@ -1798,7 +1801,7 @@ let create ~commit_id ?wallets (config : Config.t) = } ) in let slot_tx_end = - Runtime_config.slot_tx_end config.precomputed_values.runtime_config + config.precomputed_values.compile_config.slot_tx_end in let txn_pool_config = Network_pool.Transaction_pool.Resource_pool.make_config ~verifier @@ -2210,7 +2213,7 @@ let create ~commit_id ?wallets (config : Config.t) = let net { components = { net; _ }; _ } = net -let runtime_config t = t.config.precomputed_values.runtime_config +let runtime_config t = t.config.runtime_config let start_filtered_log ({ in_memory_reverse_structured_log_messages_for_integration_test diff --git a/src/lib/mina_lib/tests/tests.ml b/src/lib/mina_lib/tests/tests.ml index a9bf37afd4b..0214e9663b7 100644 --- a/src/lib/mina_lib/tests/tests.ml +++ b/src/lib/mina_lib/tests/tests.ml @@ -36,11 +36,6 @@ let%test_module "Epoch ledger sync tests" = let dir_prefix = "sync_test_data" - let genesis_constants = Genesis_constants.For_unit_tests.t - - let constraint_constants = - Genesis_constants.For_unit_tests.Constraint_constants.t - let make_dirname s = let open Core in let uuid = Uuid_unix.create () |> Uuid.to_string in @@ -48,28 +43,31 @@ let%test_module "Epoch ledger sync tests" = let make_context () : (module CONTEXT) Deferred.t = let%bind precomputed_values = - let runtime_config : Runtime_config.t = - { daemon = None - ; genesis = None - ; proof = None + let runtime_config : Runtime_config.Json_layout.t = + { daemon = Mina_compile_config.For_unit_tests.inputs + ; genesis = Genesis_constants.For_unit_tests.inputs + ; proof = + { constraint_constants = + Genesis_constants.For_unit_tests.Constraint_constants.inputs + ; proof_level = + Genesis_constants.For_unit_tests.Proof_level.inputs + } ; ledger = - Some - { base = Named "test" - ; num_accounts = None - ; balances = [] - ; hash = None - ; s3_data_hash = None - ; name = None - ; add_genesis_winner = None - } + { accounts = None + ; num_accounts = None + ; balances = [] + ; hash = None + ; s3_data_hash = None + ; name = Some "test" + ; add_genesis_winner = None + } ; epoch_data = None } in match%map - Genesis_ledger_helper.init_from_config_file + Genesis_ledger_helper.Config_loader.init_from_config_file ~genesis_dir:(make_dirname "genesis_dir") - ~constraint_constants ~genesis_constants ~logger ~proof_level:None - runtime_config ~cli_proof_level:None + ~logger runtime_config with | Ok (precomputed_values, _) -> precomputed_values @@ -79,9 +77,9 @@ let%test_module "Epoch ledger sync tests" = in let constraint_constants = precomputed_values.constraint_constants in let consensus_constants = - let genesis_constants = Genesis_constants.For_unit_tests.t in - Consensus.Constants.create ~constraint_constants - ~protocol_constants:genesis_constants.protocol + Consensus.Constants.create + ~constraint_constants:precomputed_values.constraint_constants + ~protocol_constants:precomputed_values.genesis_constants.protocol in let%bind trust_system = Trust_system.create (make_dirname "trust_system") diff --git a/src/lib/precomputed_values/precomputed_values.ml b/src/lib/precomputed_values/precomputed_values.ml index fd97c4ec317..0dd559855a3 100644 --- a/src/lib/precomputed_values/precomputed_values.ml +++ b/src/lib/precomputed_values/precomputed_values.ml @@ -17,7 +17,12 @@ let hashes = in ts @ bs ) -let for_unit_tests = +let for_unit_tests : T.t Lazy.t = + let constraint_constants = + Genesis_constants.For_unit_tests.Constraint_constants.t + in + let genesis_constants = Genesis_constants.For_unit_tests.t in + let compile_config = Mina_compile_config.For_unit_tests.t in lazy (let open Staged_ledger_diff in let protocol_state_with_hashes = @@ -31,11 +36,10 @@ let for_unit_tests = ~consensus_constants:(Lazy.force Consensus.Constants.for_unit_tests) ~genesis_body_reference in - { runtime_config = Runtime_config.default - ; constraint_constants = - Genesis_constants.For_unit_tests.Constraint_constants.t + { constraint_constants + ; compile_config ; proof_level = Genesis_constants.For_unit_tests.Proof_level.t - ; genesis_constants = Genesis_constants.For_unit_tests.t + ; genesis_constants ; genesis_ledger = Genesis_ledger.for_unit_tests ; genesis_epoch_data = Consensus.Genesis_epoch_data.for_unit_tests ; genesis_body_reference From 44678f95aad656a87ea5ba92d797d80f892d0a56 Mon Sep 17 00:00:00 2001 From: martyall Date: Tue, 17 Sep 2024 17:27:51 -0700 Subject: [PATCH 06/29] access slot_tx_end and slot_chain_end through compile_config --- src/lib/block_producer/block_producer.ml | 8 ++------ src/lib/ledger_catchup/normal_catchup.ml | 8 ++------ src/lib/ledger_catchup/super_catchup.ml | 8 ++------ 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/lib/block_producer/block_producer.ml b/src/lib/block_producer/block_producer.ml index f1b6e5facb2..dfc198bb92f 100644 --- a/src/lib/block_producer/block_producer.ml +++ b/src/lib/block_producer/block_producer.ml @@ -698,12 +698,8 @@ let run ~context:(module Context : CONTEXT) ~vrf_evaluator ~prover ~verifier let log_bootstrap_mode () = [%log info] "Pausing block production while bootstrapping" in - let slot_tx_end = - Runtime_config.slot_tx_end precomputed_values.runtime_config - in - let slot_chain_end = - Runtime_config.slot_chain_end precomputed_values.runtime_config - in + let slot_tx_end = precomputed_values.compile_config.slot_tx_end in + let slot_chain_end = precomputed_values.compile_config.slot_chain_end in let module Breadcrumb = Transition_frontier.Breadcrumb in let produce ivar (scheduled_time, block_data, winner_pubkey) = let open Interruptible.Let_syntax in diff --git a/src/lib/ledger_catchup/normal_catchup.ml b/src/lib/ledger_catchup/normal_catchup.ml index 694ceea39c3..b993f0824cc 100644 --- a/src/lib/ledger_catchup/normal_catchup.ml +++ b/src/lib/ledger_catchup/normal_catchup.ml @@ -528,12 +528,8 @@ let verify_transitions_and_build_breadcrumbs ~context:(module Context : CONTEXT) @@ diff verification_end_time verification_start_time) ) ] "verification of proofs complete" ; - let slot_tx_end = - Runtime_config.slot_tx_end precomputed_values.runtime_config - in - let slot_chain_end = - Runtime_config.slot_chain_end precomputed_values.runtime_config - in + let slot_tx_end = precomputed_values.compile_config.slot_tx_end in + let slot_chain_end = precomputed_values.compile_config.slot_chain_end in fold_until (List.rev tvs) ~init:[] ~f:(fun acc transition -> let open Deferred.Let_syntax in diff --git a/src/lib/ledger_catchup/super_catchup.ml b/src/lib/ledger_catchup/super_catchup.ml index d544f34c3af..132b846be9d 100644 --- a/src/lib/ledger_catchup/super_catchup.ml +++ b/src/lib/ledger_catchup/super_catchup.ml @@ -645,12 +645,8 @@ let initial_validate ~context:(module Context : CONTEXT) ~trust_system ; ("state_hash", state_hash) ] "initial_validate: verification of proofs complete" ; - let slot_tx_end = - Runtime_config.slot_tx_end precomputed_values.runtime_config - in - let slot_chain_end = - Runtime_config.slot_chain_end precomputed_values.runtime_config - in + let slot_tx_end = precomputed_values.compile_config.slot_tx_end in + let slot_chain_end = precomputed_values.compile_config.slot_chain_end in verify_transition ~context:(module Context) ~trust_system ~frontier ~unprocessed_transition_cache ~slot_tx_end From 4f957c323c25108968889e0f8dfb3034c1d87876 Mon Sep 17 00:00:00 2001 From: martyall Date: Tue, 17 Sep 2024 17:31:54 -0700 Subject: [PATCH 07/29] fix module typos. add print_config back in --- src/lib/genesis_ledger_helper/genesis_ledger_helper.ml | 5 +++-- src/lib/runtime_config/runtime_config.ml | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml b/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml index a827379cf36..d22370be34e 100644 --- a/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml +++ b/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml @@ -797,12 +797,12 @@ let print_config ~logger config = (Precomputed_values.t * Runtime_config.t) Deferred.Or_error.t = let open Deferred.Or_error.Let_syntax in let constraint_config = - let c = Runtime_config.Constraint_config.of_json_layout config.proof in + let c = Runtime_config.Constraint.of_json_layout config.proof in { c with proof_level = Option.value ~default:c.proof_level cli_proof_level } in - let { Runtime_config.Constraint_config.constraint_constants; proof_level } = + let { Runtime_config.Constraint.constraint_constants; proof_level } = constraint_config in let genesis_constants = Genesis_constants.make config.genesis in @@ -840,6 +840,7 @@ let print_config ~logger config = ; epoch_data = genesis_epoch_data_config } in + print_config ~logger config ; let inputs = Genesis_proof.generate_inputs ~config ~ledger:genesis_ledger ~blockchain_proof_system_id:None ~genesis_epoch_data diff --git a/src/lib/runtime_config/runtime_config.ml b/src/lib/runtime_config/runtime_config.ml index 6c36f0eea42..74561629e56 100644 --- a/src/lib/runtime_config/runtime_config.ml +++ b/src/lib/runtime_config/runtime_config.ml @@ -410,7 +410,7 @@ module Json_layout = struct let of_yojson json = of_yojson_generic ~fields of_yojson json end - module Constraint_config = struct + module Constraint = struct type t = { constraint_constants : Genesis_constants.Constraint_constants.Inputs.t ; proof_level : string @@ -425,7 +425,7 @@ module Json_layout = struct type t = { daemon : Mina_compile_config.Inputs.t ; genesis : Genesis_constants.Inputs.t - ; proof : Constraint_config.t + ; proof : Constraint.t ; ledger : Ledger.t ; epoch_data : Epoch_data.t option [@default None] } @@ -828,7 +828,7 @@ module Constraint = struct } [@@deriving to_yojson] - let of_json_layout : Json_layout.Constraint_config.t -> t = + let of_json_layout : Json_layout.Constraint.t -> t = fun { constraint_constants; proof_level } -> { constraint_constants = Genesis_constants.Constraint_constants.make constraint_constants From 62bc88239ac6ffe78580ba32e27b22d3658d62db Mon Sep 17 00:00:00 2001 From: martyall Date: Tue, 17 Sep 2024 17:33:24 -0700 Subject: [PATCH 08/29] add config_file to cli_lib flags --- src/lib/cli_lib/commands.ml | 34 +++++++++++++++++++++------------- src/lib/cli_lib/dune | 4 +++- src/lib/cli_lib/flag.ml | 5 +++++ src/lib/cli_lib/flag.mli | 2 ++ 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/lib/cli_lib/commands.ml b/src/lib/cli_lib/commands.ml index 375a130d6e7..0e81b9ab2b6 100644 --- a/src/lib/cli_lib/commands.ml +++ b/src/lib/cli_lib/commands.ml @@ -230,16 +230,18 @@ module Vrf = struct flag "--total-stake" ~doc:"AMOUNT The total balance of all accounts in the epoch ledger" (optional int) - in + and config_file = Flag.conf_file in Exceptions.handle_nicely @@ fun () -> let env = Secrets.Keypair.env in - let constraint_constants = - Genesis_constants.Compiled.constraint_constants + let logger = Logger.create () in + let open Deferred.Let_syntax in + let%bind _, { constraint_config = { constraint_constants; _ }; _ } = + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger + () in if Option.is_some (Sys.getenv env) then eprintf "Using password from environment variable %s\n" env ; - let open Deferred.Let_syntax in (* TODO-someday: constraint constants from config file. *) let%bind () = let password = @@ -297,17 +299,19 @@ module Vrf = struct \"epochSeed\": _, \"delegatorIndex\": _} JSON message objects read on \ stdin" (let open Command.Let_syntax in - let%map_open privkey_path = Flag.privkey_read_path in + let%map_open privkey_path = Flag.privkey_read_path + and config_file = Flag.conf_file in Exceptions.handle_nicely @@ fun () -> - let constraint_constants = - Genesis_constants.Compiled.constraint_constants - in let env = Secrets.Keypair.env in if Option.is_some (Sys.getenv env) then eprintf "Using password from environment variable %s\n" env ; + let logger = Logger.create () in let open Deferred.Let_syntax in - (* TODO-someday: constraint constants from config file. *) + let%bind _, { constraint_config = { constraint_constants; _ }; _ } = + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger + () + in let%bind () = let password = lazy @@ -362,11 +366,15 @@ module Vrf = struct totalStake: 1000000000}. The threshold is not checked against a \ ledger; this should be done manually to confirm whether threshold_met \ in the output corresponds to an actual won block." - ( Command.Param.return @@ Exceptions.handle_nicely + (let open Command.Let_syntax in + let%map_open config_file = Flag.conf_file in + Exceptions.handle_nicely @@ fun () -> let open Deferred.Let_syntax in - let constraint_constants = - Genesis_constants.Compiled.constraint_constants + let logger = Logger.create () in + let%bind _, { constraint_config = { constraint_constants; _ }; _ } = + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger + () in (* TODO-someday: constraint constants from config file. *) let lexbuf = Lexing.from_channel In_channel.stdin in @@ -399,7 +407,7 @@ module Vrf = struct (Error_json.error_to_yojson err) ) ; `Repeat () ) in - exit 0 ) + exit 0) let command_group = Command.group ~summary:"Commands for vrf evaluations" diff --git a/src/lib/cli_lib/dune b/src/lib/cli_lib/dune index dc0f9c72a9d..e2a8a6e3239 100644 --- a/src/lib/cli_lib/dune +++ b/src/lib/cli_lib/dune @@ -45,7 +45,9 @@ kimchi_pasta.basic ppx_version.runtime gossip_net - mina_runtime_config) + runtime_config + genesis_ledger_helper + ) (preprocess (pps ppx_version ppx_jane ppx_deriving_yojson ppx_deriving.make)) (instrumentation (backend bisect_ppx)) diff --git a/src/lib/cli_lib/flag.ml b/src/lib/cli_lib/flag.ml index c96200feb9e..ab6651e4bfa 100644 --- a/src/lib/cli_lib/flag.ml +++ b/src/lib/cli_lib/flag.ml @@ -33,6 +33,11 @@ let conf_dir = flag "--config-directory" ~aliases:[ "config-directory" ] ~doc:"DIR Configuration directory" (optional string) +let conf_file = + let open Command.Param in + flag "--config-file" ~aliases:[ "config-file" ] ~doc:"FILE Configuration file" + (required string) + module Doc_builder = struct type 'value t = { type_name : string diff --git a/src/lib/cli_lib/flag.mli b/src/lib/cli_lib/flag.mli index 69ff38f86f3..25b2e2860ee 100644 --- a/src/lib/cli_lib/flag.mli +++ b/src/lib/cli_lib/flag.mli @@ -12,6 +12,8 @@ val privkey_read_path : string Command.Param.t val conf_dir : string option Command.Param.t +val conf_file : string Command.Param.t + module Types : sig type 'a with_name = { name : string; value : 'a } From 8c316a0657ffb97d8a18db0220b155ae23512f36 Mon Sep 17 00:00:00 2001 From: martyall Date: Tue, 17 Sep 2024 17:34:48 -0700 Subject: [PATCH 09/29] access slot_tx_end through compile_config --- src/app/archive/lib/processor.ml | 224 +++++++++++++-------------- src/lib/mina_graphql/mina_graphql.ml | 7 +- 2 files changed, 112 insertions(+), 119 deletions(-) diff --git a/src/app/archive/lib/processor.ml b/src/app/archive/lib/processor.ml index db9a4af803a..4446f434ff2 100644 --- a/src/app/archive/lib/processor.ml +++ b/src/app/archive/lib/processor.ml @@ -4728,123 +4728,110 @@ let run pool reader ~genesis_constants ~constraint_constants ~logger Deferred.unit ) (* [add_genesis_accounts] is called when starting the archive process *) -let add_genesis_accounts ~logger ~(runtime_config_opt : Runtime_config.t option) - ~(genesis_constants : Genesis_constants.t) - ~(constraint_constants : Genesis_constants.Constraint_constants.t) pool = - match runtime_config_opt with - | None -> - Deferred.unit - | Some runtime_config -> ( - let%bind precomputed_values = - match%map - Genesis_ledger_helper.init_from_config_file ~logger ~proof_level:None - ~genesis_constants ~constraint_constants runtime_config - ~cli_proof_level:None - with - | Ok (precomputed_values, _) -> - precomputed_values - | Error err -> - failwithf "Could not get precomputed values, error: %s" - (Error.to_string_hum err) () - in - let ledger = - Precomputed_values.genesis_ledger precomputed_values |> Lazy.force - in - let%bind account_ids = - let%map account_id_set = Mina_ledger.Ledger.accounts ledger in - Account_id.Set.to_list account_id_set - in - let genesis_block = - let With_hash.{ data = block; hash = the_hash }, _ = - Mina_block.genesis ~precomputed_values +let add_genesis_accounts ~logger ~(config_file : string) pool = + let%bind precomputed_values, (config : Runtime_config.t) = + match%map + Genesis_ledger_helper.Config_loader.load_config ~config_file ~logger () + with + | Ok a -> + a + | Error err -> + failwithf "Could not get precomputed values, error: %s" + (Error.to_string_hum err) () + in + let ledger = + Precomputed_values.genesis_ledger precomputed_values |> Lazy.force + in + let%bind account_ids = + let%map account_id_set = Mina_ledger.Ledger.accounts ledger in + Account_id.Set.to_list account_id_set + in + let genesis_block = + let With_hash.{ data = block; hash = the_hash }, _ = + Mina_block.genesis ~precomputed_values + in + With_hash.{ data = block; hash = the_hash } + in + let add_accounts () = + Caqti_async.Pool.use + (fun (module Conn : CONNECTION) -> + let%bind.Deferred.Result genesis_block_id = + Block.add_if_doesn't_exist + (module Conn) + ~constraint_constants:config.constraint_config.constraint_constants + genesis_block in - With_hash.{ data = block; hash = the_hash } - in - let add_accounts () = - Caqti_async.Pool.use - (fun (module Conn : CONNECTION) -> - let%bind.Deferred.Result genesis_block_id = - Block.add_if_doesn't_exist - (module Conn) - ~constraint_constants genesis_block - in - let%bind.Deferred.Result { ledger_hash; _ } = - Block.load (module Conn) ~id:genesis_block_id - in - let db_ledger_hash = Ledger_hash.of_base58_check_exn ledger_hash in - let actual_ledger_hash = Mina_ledger.Ledger.merkle_root ledger in - if Ledger_hash.equal db_ledger_hash actual_ledger_hash then - [%log info] - "Archived genesis block ledger hash equals actual genesis \ - ledger hash" - ~metadata: - [ ("ledger_hash", Ledger_hash.to_yojson actual_ledger_hash) ] - else ( - [%log error] - "Archived genesis block ledger hash different than actual \ - genesis ledger hash" - ~metadata: - [ ( "archived_ledger_hash" - , Ledger_hash.to_yojson db_ledger_hash ) - ; ( "actual_ledger_hash" - , Ledger_hash.to_yojson actual_ledger_hash ) - ] ; - exit 1 ) ; - let%bind.Deferred.Result () = Conn.start () in - let open Deferred.Let_syntax in - let%bind () = - Deferred.List.iter account_ids ~f:(fun acct_id -> - match - Mina_ledger.Ledger.location_of_account ledger acct_id + let%bind.Deferred.Result { ledger_hash; _ } = + Block.load (module Conn) ~id:genesis_block_id + in + let db_ledger_hash = Ledger_hash.of_base58_check_exn ledger_hash in + let actual_ledger_hash = Mina_ledger.Ledger.merkle_root ledger in + if Ledger_hash.equal db_ledger_hash actual_ledger_hash then + [%log info] + "Archived genesis block ledger hash equals actual genesis ledger \ + hash" + ~metadata: + [ ("ledger_hash", Ledger_hash.to_yojson actual_ledger_hash) ] + else ( + [%log error] + "Archived genesis block ledger hash different than actual genesis \ + ledger hash" + ~metadata: + [ ("archived_ledger_hash", Ledger_hash.to_yojson db_ledger_hash) + ; ("actual_ledger_hash", Ledger_hash.to_yojson actual_ledger_hash) + ] ; + exit 1 ) ; + let%bind.Deferred.Result () = Conn.start () in + let open Deferred.Let_syntax in + let%bind () = + Deferred.List.iter account_ids ~f:(fun acct_id -> + match Mina_ledger.Ledger.location_of_account ledger acct_id with + | None -> + [%log error] "Could not get location for account" + ~metadata:[ ("account_id", Account_id.to_yojson acct_id) ] ; + failwith "Could not get location for genesis account" + | Some loc -> ( + let index = + Mina_ledger.Ledger.index_of_account_exn ledger acct_id + in + let acct = + match Mina_ledger.Ledger.get ledger loc with + | None -> + [%log error] "Could not get account, given a location" + ~metadata: + [ ("account_id", Account_id.to_yojson acct_id) ] ; + failwith + "Could not get genesis account, given a location" + | Some acct -> + acct + in + match%bind + Accounts_accessed.add_if_doesn't_exist + (module Conn) + genesis_block_id (index, acct) with - | None -> - [%log error] "Could not get location for account" + | Ok _ -> + return () + | Error err -> + [%log error] "Could not add genesis account" ~metadata: - [ ("account_id", Account_id.to_yojson acct_id) ] ; - failwith "Could not get location for genesis account" - | Some loc -> ( - let index = - Mina_ledger.Ledger.index_of_account_exn ledger acct_id - in - let acct = - match Mina_ledger.Ledger.get ledger loc with - | None -> - [%log error] - "Could not get account, given a location" - ~metadata: - [ ("account_id", Account_id.to_yojson acct_id) ] ; - failwith - "Could not get genesis account, given a location" - | Some acct -> - acct - in - match%bind - Accounts_accessed.add_if_doesn't_exist - (module Conn) - genesis_block_id (index, acct) - with - | Ok _ -> - return () - | Error err -> - [%log error] "Could not add genesis account" - ~metadata: - [ ("account_id", Account_id.to_yojson acct_id) - ; ("error", `String (Caqti_error.show err)) - ] ; - failwith "Could not add add genesis account" ) ) - in - Conn.commit () ) - pool - in - match%map - retry ~f:add_accounts ~logger ~error_str:"add_genesis_accounts" 3 - with - | Error e -> - [%log warn] "genesis accounts could not be added" - ~metadata:[ ("error", `String (Caqti_error.show e)) ] ; - failwith "Failed to add genesis accounts" - | Ok () -> - () ) + [ ("account_id", Account_id.to_yojson acct_id) + ; ("error", `String (Caqti_error.show err)) + ] ; + failwith "Could not add add genesis account" ) ) + in + Conn.commit () ) + pool + in + match%map + retry ~f:add_accounts ~logger ~error_str:"add_genesis_accounts" 3 + with + | Error e -> + [%log warn] "genesis accounts could not be added" + ~metadata:[ ("error", `String (Caqti_error.show e)) ] ; + failwith "Failed to add genesis accounts" + | Ok () -> + () let create_metrics_server ~logger ~metrics_server_port ~missing_blocks_width ~block_window_duration_ms pool = @@ -4873,7 +4860,7 @@ let create_metrics_server ~logger ~metrics_server_port ~missing_blocks_width let setup_server ~(genesis_constants : Genesis_constants.t) ~(constraint_constants : Genesis_constants.Constraint_constants.t) ~metrics_server_port ~logger ~postgres_address ~server_port - ~delete_older_than ~runtime_config_opt ~missing_blocks_width = + ~delete_older_than ~config_file_opt ~missing_blocks_width = let where_to_listen = Async.Tcp.Where_to_listen.bind_to All_addresses (On_port server_port) in @@ -4903,8 +4890,11 @@ let setup_server ~(genesis_constants : Genesis_constants.t) Deferred.unit | Ok pool -> let%bind () = - add_genesis_accounts pool ~logger ~genesis_constants - ~constraint_constants ~runtime_config_opt + match config_file_opt with + | None -> + Deferred.unit + | Some config_file -> + add_genesis_accounts pool ~logger ~config_file in run ~constraint_constants ~genesis_constants pool reader ~logger ~delete_older_than diff --git a/src/lib/mina_graphql/mina_graphql.ml b/src/lib/mina_graphql/mina_graphql.ml index f39abf50342..5a4b6a63217 100644 --- a/src/lib/mina_graphql/mina_graphql.ml +++ b/src/lib/mina_graphql/mina_graphql.ml @@ -2487,7 +2487,7 @@ module Queries = struct Deferred.Result.fail "Daemon is bootstrapping" | `Active breadcrumb -> ( let txn_stop_slot_opt = - Runtime_config.slot_tx_end runtime_config + runtime_config.compile_config.slot_tx_end in match txn_stop_slot_opt with | None -> @@ -2574,6 +2574,9 @@ module Queries = struct ~global_slot_since_genesis ~state_hash ~staking_ledger ~staking_epoch_seed ~next_epoch_ledger:(Some next_epoch_ledger) ~next_epoch_seed ~blockchain_length + ~compile_config:runtime_config.compile_config + ~constraint_config:runtime_config.constraint_config + ~genesis_constants:runtime_config.genesis_constants in let%map () = let open Async.Deferred.Infix in @@ -2672,7 +2675,7 @@ module Queries = struct ~args:Arg.[] ~resolve:(fun { ctx = mina; _ } () -> let cfg = Mina_lib.config mina in - "mina:" ^ cfg.compile_config.network_id ) + "mina:" ^ cfg.runtime_config.compile_config.network_id ) let signature_kind = field "signatureKind" From 1d5d6327a9220bbfc4818cfdfeeb2ff1db9cd47d Mon Sep 17 00:00:00 2001 From: martyall Date: Tue, 17 Sep 2024 17:40:21 -0700 Subject: [PATCH 10/29] load in config for snark-worker --- src/lib/crypto/snarky_tests/snarky_tests.ml | 3 ++- src/lib/snark_worker/standalone/run_snark_worker.ml | 13 ++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/lib/crypto/snarky_tests/snarky_tests.ml b/src/lib/crypto/snarky_tests/snarky_tests.ml index 51db1241b6d..74b404a22cf 100644 --- a/src/lib/crypto/snarky_tests/snarky_tests.ml +++ b/src/lib/crypto/snarky_tests/snarky_tests.ml @@ -604,7 +604,8 @@ module Protocol_circuits = struct (* Full because we want to be sure nothing changes *) let proof_level = Genesis_constants.Proof_level.Full - let constraint_constants = Genesis_constants.Compiled.constraint_constants + let constraint_constants = + Genesis_constants.For_unit_tests.Constraint_constants.t let print_hash print expected digest : unit = if print then ( diff --git a/src/lib/snark_worker/standalone/run_snark_worker.ml b/src/lib/snark_worker/standalone/run_snark_worker.ml index 771f647c6c2..91348ef1127 100644 --- a/src/lib/snark_worker/standalone/run_snark_worker.ml +++ b/src/lib/snark_worker/standalone/run_snark_worker.ml @@ -8,7 +8,8 @@ let command = (let%map_open spec = flag "--spec-sexp" ~doc:"" (required (sexp_conv Prod.single_spec_of_sexp)) - and proof_level = + and config_file = Cli_lib.Flag.conf_file + and cli_proof_level = flag "--proof-level" ~doc:"" (optional_with_default Genesis_constants.Proof_level.Full (Command.Arg_type.of_alist_exn @@ -19,8 +20,14 @@ let command = in fun () -> let open Async in - let constraint_constants = - Genesis_constants.Compiled.constraint_constants + let open Deferred.Let_syntax in + let logger = Logger.create () in + let%bind ( _ + , { constraint_config = { constraint_constants; proof_level } + ; _ + } ) = + Genesis_ledger_helper.Config_loader.load_config_exn ~cli_proof_level + ~config_file ~logger () in let%bind worker_state = Prod.Worker_state.create ~constraint_constants ~proof_level () From 0cbd700d82feb822e1736869d9164b7d23f07239 Mon Sep 17 00:00:00 2001 From: martyall Date: Tue, 17 Sep 2024 17:43:08 -0700 Subject: [PATCH 11/29] integratin test libs --- .../mina_automation.ml | 113 ++++++++---------- src/lib/integration_test_lib/test_config.ml | 55 ++------- .../mina_docker.ml | 98 ++++++++------- 3 files changed, 106 insertions(+), 160 deletions(-) diff --git a/src/lib/integration_test_cloud_engine/mina_automation.ml b/src/lib/integration_test_cloud_engine/mina_automation.ml index 5a5491d4ac2..420b9aab7cc 100644 --- a/src/lib/integration_test_cloud_engine/mina_automation.ml +++ b/src/lib/integration_test_cloud_engine/mina_automation.ml @@ -108,7 +108,7 @@ module Network_config = struct in assoc - let expand ~logger ~test_name ~(cli_inputs : Cli_inputs.t) ~(debug : bool) + let expand ~logger:_ ~test_name ~(cli_inputs : Cli_inputs.t) ~(debug : bool) ~(images : Test_config.Container_images.t) ~test_config ~(constants : Test_config.constants) = let ({ requires_graphql @@ -219,10 +219,6 @@ module Network_config = struct let genesis_accounts_and_keys = List.zip_exn genesis_ledger keypairs in let genesis_ledger_accounts = add_accounts genesis_accounts_and_keys in (* DAEMON CONFIG *) - let constraint_constants = - Genesis_ledger_helper.make_constraint_constants - ~default:constants.constraint_constants proof_config - in let ledger_is_prefix ledger1 ledger2 = List.is_prefix ledger2 ~prefix:ledger1 ~equal:(fun @@ -231,8 +227,19 @@ module Network_config = struct -> String.equal name1 name2 ) in let runtime_config = - { Runtime_config.daemon = - Some + { Runtime_config.compile_config = + { constants.compile_config with + network_id = + Option.value ~default:constants.compile_config.network_id + network_id + ; slot_tx_end = + Option.map ~f:Mina_numbers.Global_slot_since_hard_fork.of_int + slot_tx_end + ; slot_chain_end = + Option.map ~f:Mina_numbers.Global_slot_since_hard_fork.of_int + slot_chain_end + } + (* { txpool_max_size = Some txpool_max_size ; peer_list_url = None ; zkapp_proof_update_cost = None @@ -247,30 +254,38 @@ module Network_config = struct ; minimum_user_command_fee = None ; network_id } - ; genesis = - Some - { k = Some k - ; delta = Some delta - ; slots_per_epoch = Some slots_per_epoch - ; slots_per_sub_window = Some slots_per_sub_window - ; grace_period_slots = Some grace_period_slots - ; genesis_state_timestamp = - Some Core.Time.(to_string_abs ~zone:Zone.utc (now ())) - } - ; proof = Some proof_config (* TODO: prebake ledger and only set hash *) +*) + ; genesis_constants = + { constants.genesis_constants with + protocol = + { k + ; delta + ; slots_per_epoch + ; slots_per_sub_window + ; grace_period_slots + ; genesis_state_timestamp = + (let t = Core.Time.(to_string_abs ~zone:Zone.utc (now ())) in + Genesis_constants.genesis_timestamp_of_string t + |> Genesis_constants.of_time ) + } + ; txpool_max_size + } + ; constraint_config = + { proof_level = constants.proof_level + ; constraint_constants = proof_config + } ; ledger = - Some - { base = - Accounts - (List.map genesis_ledger_accounts ~f:(fun (_name, acct) -> - acct ) ) - ; add_genesis_winner = None - ; num_accounts = None - ; balances = [] - ; hash = None - ; s3_data_hash = None - ; name = None - } + { base = + Accounts + (List.map genesis_ledger_accounts ~f:(fun (_name, acct) -> + acct ) ) + ; add_genesis_winner = None + ; num_accounts = None + ; balances = [] + ; hash = None + ; s3_data_hash = None + ; name = None + } ; epoch_data = (* each staking epoch ledger account must also be a genesis ledger account, though the balance may be different; the converse is not necessarily true, since @@ -375,13 +390,12 @@ module Network_config = struct ({ staking; next } : Runtime_config.Epoch_data.t) ) } in - let genesis_constants = - Or_error.ok_exn - (Genesis_ledger_helper.make_genesis_constants ~logger - ~default:constants.genesis_constants runtime_config ) - in let constants : Test_config.constants = - { constants with genesis_constants; constraint_constants } + { constants with + genesis_constants = runtime_config.genesis_constants + ; constraint_constants = + runtime_config.constraint_config.constraint_constants + } in (* BLOCK PRODUCER CONFIG *) let mk_net_keypair keypair_name (pk, sk) = @@ -679,33 +693,6 @@ module Network_manager = struct | None -> (Core.String.Map.of_alist_exn [], Core.String.Map.of_alist_exn []) in - (* - let snark_coordinator_id = - String.lowercase - (String.sub network_config.terraform.snark_worker_public_key - ~pos: - (String.length network_config.terraform.snark_worker_public_key - 6) - ~len:6 ) - in - let snark_coordinator_workloads = - if network_config.terraform.snark_worker_replicas > 0 then - [ Kubernetes_network.Workload_to_deploy.construct_workload - ("snark-coordinator-" ^ snark_coordinator_id) - [ Kubernetes_network.Workload_to_deploy.cons_pod_info "mina" ] - ] - else [] - in - let snark_worker_workloads = - if network_config.terraform.snark_worker_replicas > 0 then - [ Kubernetes_network.Workload_to_deploy.construct_workload - ("snark-worker-" ^ snark_coordinator_id) - (List.init network_config.terraform.snark_worker_replicas - ~f:(fun _i -> - Kubernetes_network.Workload_to_deploy.cons_pod_info "worker" ) - ) - ] - else [] - in *) let block_producer_workloads = List.map network_config.terraform.block_producer_configs ~f:(fun bp_config -> diff --git a/src/lib/integration_test_lib/test_config.ml b/src/lib/integration_test_lib/test_config.ml index fa06f656fc3..2cfaf78026d 100644 --- a/src/lib/integration_test_lib/test_config.ml +++ b/src/lib/integration_test_lib/test_config.ml @@ -55,6 +55,7 @@ type constants = { constraint_constants : Genesis_constants.Constraint_constants.t ; genesis_constants : Genesis_constants.t ; compile_config : Mina_compile_config.t + ; proof_level : Genesis_constants.Proof_level.t } [@@deriving to_yojson] @@ -72,7 +73,7 @@ type t = ; start_filtered_logs : string list (* ; num_plain_nodes : int *) (* blockchain constants *) - ; proof_config : Runtime_config.Proof_keys.t + ; proof_config : Genesis_constants.Constraint_constants.t ; k : int ; delta : int ; slots_per_epoch : int @@ -86,19 +87,6 @@ type t = ; transaction_capacity_log_2 : int } -let proof_config_default : Runtime_config.Proof_keys.t = - { level = Some Full - ; sub_windows_per_window = None - ; ledger_depth = None - ; work_delay = None - ; block_window_duration_ms = Some 120000 - ; transaction_capacity = None - ; coinbase_amount = None - ; supercharged_coinbase_factor = None - ; account_creation_fee = None - ; fork = None - } - let log_filter_of_event_type ev_existential = let open Event_type in let (Event_type ev_type) = ev_existential in @@ -126,7 +114,8 @@ let default ~(constants : constants) = ; log_precomputed_blocks = false (* ; num_plain_nodes = 0 *) ; start_filtered_logs = List.bind ~f:log_filter_of_event_type Event_type.all_event_types - ; proof_config = proof_config_default + ; proof_config = + { constraint_constants with block_window_duration_ms = 12000 } ; k = genesis_constants.protocol.k ; slots_per_epoch = genesis_constants.protocol.slots_per_epoch ; slots_per_sub_window = genesis_constants.protocol.slots_per_sub_window @@ -140,43 +129,15 @@ let default ~(constants : constants) = ; transaction_capacity_log_2 = constraint_constants.transaction_capacity_log_2 } -let transaction_capacity_log_2 (config : t) = - match config.proof_config.transaction_capacity with - | None -> - config.transaction_capacity_log_2 - | Some (Log_2 i) -> - i - | Some (Txns_per_second_x10 tps_goal_x10) -> - let max_coinbases = 2 in - let block_window_duration_ms = - Option.value ~default:config.block_window_duration_ms - config.proof_config.block_window_duration_ms - in - let max_user_commands_per_block = - (* block_window_duration is in milliseconds, so divide by 1000 divide - by 10 again because we have tps * 10 - *) - tps_goal_x10 * block_window_duration_ms / (1000 * 10) - in - (* Log of the capacity of transactions per transition. - - 1 will only work if we don't have prover fees. - - 2 will work with prover fees, but not if we want a transaction - included in every block. - - At least 3 ensures a transaction per block and the staged-ledger - unit tests pass. - *) - 1 + Core_kernel.Int.ceil_log2 (max_user_commands_per_block + max_coinbases) - let transaction_capacity config = - let i = transaction_capacity_log_2 config in + let i = config.transaction_capacity_log_2 in Int.pow 2 i let blocks_for_first_ledger_proof (config : t) = - let work_delay = - Option.value ~default:config.block_window_duration_ms - config.proof_config.work_delay + let work_delay = config.proof_config.work_delay in + let transaction_capacity_log_2 = + config.proof_config.transaction_capacity_log_2 in - let transaction_capacity_log_2 = transaction_capacity_log_2 config in ((work_delay + 1) * (transaction_capacity_log_2 + 1)) + 1 let slots_for_blocks blocks = diff --git a/src/lib/integration_test_local_engine/mina_docker.ml b/src/lib/integration_test_local_engine/mina_docker.ml index 9a92fe18304..109e477d50b 100644 --- a/src/lib/integration_test_local_engine/mina_docker.ml +++ b/src/lib/integration_test_local_engine/mina_docker.ml @@ -46,7 +46,7 @@ module Network_config = struct } [@@deriving to_yojson] - let expand ~logger ~test_name ~(cli_inputs : Cli_inputs.t) ~(debug : bool) + let expand ~logger:_ ~test_name ~(cli_inputs : Cli_inputs.t) ~(debug : bool) ~(images : Test_config.Container_images.t) ~(test_config : Test_config.t) ~(constants : Test_config.constants) = let _ = cli_inputs in @@ -142,10 +142,6 @@ module Network_config = struct in let genesis_accounts_and_keys = List.zip_exn genesis_ledger keypairs in let genesis_ledger_accounts = add_accounts genesis_accounts_and_keys in - let constraint_constants = - Genesis_ledger_helper.make_constraint_constants - ~default:constants.constraint_constants proof_config - in let ledger_is_prefix ledger1 ledger2 = List.is_prefix ledger2 ~prefix:ledger1 ~equal:(fun @@ -154,46 +150,49 @@ module Network_config = struct -> String.equal name1 name2 ) in let runtime_config = - { Runtime_config.daemon = - Some - { txpool_max_size = Some txpool_max_size - ; peer_list_url = None - ; zkapp_proof_update_cost = None - ; zkapp_signed_single_update_cost = None - ; zkapp_signed_pair_update_cost = None - ; zkapp_transaction_cost_limit = None - ; max_event_elements = None - ; max_action_elements = None - ; zkapp_cmd_limit_hardcap = None - ; slot_tx_end - ; slot_chain_end - ; minimum_user_command_fee = None - ; network_id - } - ; genesis = - Some - { k = Some k - ; delta = Some delta - ; slots_per_epoch = Some slots_per_epoch - ; slots_per_sub_window = Some slots_per_sub_window - ; grace_period_slots = Some grace_period_slots - ; genesis_state_timestamp = - Some Core.Time.(to_string_abs ~zone:Zone.utc (now ())) - } - ; proof = Some proof_config (* TODO: prebake ledger and only set hash *) + { Runtime_config.compile_config = + { constants.compile_config with + network_id = + Option.value ~default:constants.compile_config.network_id + network_id + ; slot_tx_end = + Option.map ~f:Mina_numbers.Global_slot_since_hard_fork.of_int + slot_tx_end + ; slot_chain_end = + Option.map ~f:Mina_numbers.Global_slot_since_hard_fork.of_int + slot_chain_end + } + ; genesis_constants = + { constants.genesis_constants with + protocol = + { k + ; delta + ; slots_per_epoch + ; slots_per_sub_window + ; grace_period_slots + ; genesis_state_timestamp = + (let t = Core.Time.(to_string_abs ~zone:Zone.utc (now ())) in + Genesis_constants.genesis_timestamp_of_string t + |> Genesis_constants.of_time ) + } + ; txpool_max_size + } + ; constraint_config = + { proof_level = constants.proof_level + ; constraint_constants = proof_config + } ; ledger = - Some - { base = - Accounts - (List.map genesis_ledger_accounts ~f:(fun (_name, acct) -> - acct ) ) - ; add_genesis_winner = None - ; num_accounts = None - ; balances = [] - ; hash = None - ; s3_data_hash = None - ; name = None - } + { base = + Accounts + (List.map genesis_ledger_accounts ~f:(fun (_name, acct) -> + acct ) ) + ; add_genesis_winner = None + ; num_accounts = None + ; balances = [] + ; hash = None + ; s3_data_hash = None + ; name = None + } ; epoch_data = Option.map epoch_data ~f:(fun { staking = staking_ledger; next } -> let genesis_winner_account : Runtime_config.Accounts.single = @@ -278,13 +277,12 @@ module Network_config = struct ({ staking; next } : Runtime_config.Epoch_data.t) ) } in - let genesis_constants = - Or_error.ok_exn - (Genesis_ledger_helper.make_genesis_constants ~logger - ~default:constants.genesis_constants runtime_config ) - in let constants : Test_config.constants = - { constants with genesis_constants; constraint_constants } + { constants with + genesis_constants = runtime_config.genesis_constants + ; constraint_constants = + runtime_config.constraint_config.constraint_constants + } in let mk_net_keypair keypair_name (pk, sk) = let keypair = From d8350bd210e5ca3e37b5927e33024c920379b505 Mon Sep 17 00:00:00 2001 From: martyall Date: Wed, 18 Sep 2024 07:44:04 -0700 Subject: [PATCH 12/29] formatting --- .../genesis_ledger_helper.ml | 135 +++++------------- src/lib/runtime_config/runtime_config.ml | 18 ++- 2 files changed, 46 insertions(+), 107 deletions(-) diff --git a/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml b/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml index d22370be34e..7048f37c431 100644 --- a/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml +++ b/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml @@ -415,9 +415,8 @@ module Ledger = struct let depth = depth end) ) - let load ~genesis_dir ~logger - ~(constraint_constants : Genesis_constants.Constraint_constants.t) - ~proof_level ?(ledger_name_prefix = "genesis_ledger") ?overwrite_version + let load ~proof_level ~genesis_dir ~logger ~constraint_constants + ?(ledger_name_prefix = "genesis_ledger") ?overwrite_version (config : Runtime_config.Ledger.t) = Monitor.try_with_join_or_error ~here:[%here] (fun () -> let padded_accounts_opt = @@ -557,7 +556,7 @@ module Ledger = struct end module Epoch_data = struct - let load ~genesis_dir ~logger ~constraint_constants ~proof_level + let load ~proof_level ~genesis_dir ~logger ~constraint_constants (config : Runtime_config.Epoch_data.t option) = let open Deferred.Or_error.Let_syntax in match config with @@ -566,8 +565,8 @@ module Epoch_data = struct | Some config -> let ledger_name_prefix = "epoch_ledger" in let load_ledger ledger = - Ledger.load ~genesis_dir ~logger ~constraint_constants - ~ledger_name_prefix ~proof_level ledger + Ledger.load ~proof_level ~genesis_dir ~logger ~constraint_constants + ~ledger_name_prefix ledger in let%bind staking, staking_config = let%map staking_ledger, config', ledger_file = @@ -666,8 +665,8 @@ module Genesis_proof = struct ~metadata:[ ("base_hash", Base_hash.to_yojson base_hash) ] ; return None - let generate_inputs ~ledger ~genesis_epoch_data ~blockchain_proof_system_id - ~(config : Runtime_config.t) : Genesis_proof.Inputs.t = + let generate_inputs ~(config : Runtime_config.t) ~ledger ~genesis_epoch_data + ~blockchain_proof_system_id = let consensus_constants = Consensus.Constants.create ~constraint_constants:config.constraint_config.constraint_constants @@ -681,7 +680,8 @@ module Genesis_proof = struct ~constraint_constants:config.constraint_config.constraint_constants ~consensus_constants ~genesis_body_reference in - { constraint_constants = config.constraint_config.constraint_constants + { Genesis_proof.Inputs.constraint_constants = + config.constraint_config.constraint_constants ; proof_level = config.constraint_config.proof_level ; compile_config = config.compile_config ; blockchain_proof_system_id @@ -767,30 +767,32 @@ module Config_loader : Config_loader = struct let%map json = Reader.file_contents filename in Yojson.Safe.from_string json ) -let print_config ~logger config = - let ledger_name_json = Option.value_map ~default:`Null ~f:(fun a -> `String a) - config.Runtime_config.ledger.name in - let ( json_config - , `Accounts_omitted - ( `Genesis genesis_accounts_omitted - , `Staking staking_accounts_omitted - , `Next next_accounts_omitted ) ) = - Runtime_config.format_as_json_without_accounts config - in - let append_accounts_omitted s = - Option.value_map - ~f:(fun i -> List.cons (s ^ "_accounts_omitted", `Int i)) - ~default:Fn.id - in - let metadata = - append_accounts_omitted "genesis" genesis_accounts_omitted - @@ append_accounts_omitted "staking" staking_accounts_omitted - @@ append_accounts_omitted "next" next_accounts_omitted - [ ("name", ledger_name_json); ("config", json_config) ] - in - [%log info] "Initializing with runtime configuration. Ledger name: $name" - ~metadata - + let print_config ~logger config = + let ledger_name_json = + Option.value_map ~default:`Null + ~f:(fun a -> `String a) + config.Runtime_config.ledger.name + in + let ( json_config + , `Accounts_omitted + ( `Genesis genesis_accounts_omitted + , `Staking staking_accounts_omitted + , `Next next_accounts_omitted ) ) = + Runtime_config.format_as_json_without_accounts config + in + let append_accounts_omitted s = + Option.value_map + ~f:(fun i -> List.cons (s ^ "_accounts_omitted", `Int i)) + ~default:Fn.id + in + let metadata = + append_accounts_omitted "genesis" genesis_accounts_omitted + @@ append_accounts_omitted "staking" staking_accounts_omitted + @@ append_accounts_omitted "next" next_accounts_omitted + [ ("name", ledger_name_json); ("config", json_config) ] + in + [%log info] "Initializing with runtime configuration. Ledger name: $name" + ~metadata let init_from_config_file ?overwrite_version ?cli_proof_level ~genesis_dir ~logger (config : Runtime_config.Json_layout.t) : @@ -869,73 +871,6 @@ let print_config ~logger config = Deferred.return (Or_error.ok_exn config) end -(* -let upgrade_old_config ~logger filename json = - match json with - | `Assoc fields -> - (* Fields previously part of daemon.json *) - let old_fields = - [ "client_port" - ; "libp2p-port" - ; "rest-port" - ; "block-producer-key" - ; "block-producer-pubkey" - ; "block-producer-password" - ; "coinbase-receiver" - ; "run-snark-worker" - ; "snark-worker-fee" - ; "peers" - ; "work-selection" - ; "work-reassignment-wait" - ; "log-received-blocks" - ; "log-txn-pool-gossip" - ; "log-snark-work-gossip" - ; "log-block-creation" - ] - in - let found_daemon = ref false in - let old_fields, remaining_fields = - List.partition_tf fields ~f:(fun (key, _) -> - if String.equal key "daemon" then ( - found_daemon := true ; - false ) - else List.mem ~equal:String.equal old_fields key ) - in - if List.is_empty old_fields then return json - else if !found_daemon then ( - (* This file has already been upgraded, or was written for the new - format. Do not accept old-style fields. - *) - [%log warn] - "Ignoring old-format values $values from the config file $filename. \ - These flags are now fields in the 'daemon' object of the config \ - file." - ~metadata: - [ ("values", `Assoc old_fields); ("filename", `String filename) ] ; - return (`Assoc remaining_fields) ) - else ( - (* This file was written for the old format. Upgrade it. *) - [%log warn] - "Automatically upgrading the config file $filename. The values \ - $values have been moved to the 'daemon' object." - ~metadata: - [ ("filename", `String filename); ("values", `Assoc old_fields) ] ; - let upgraded_json = - `Assoc (("daemon", `Assoc old_fields) :: remaining_fields) - in - let%map () = - Deferred.Or_error.try_with ~here:[%here] (fun () -> - Writer.with_file filename ~f:(fun w -> - Deferred.return - @@ Writer.write w (Yojson.Safe.pretty_to_string upgraded_json) ) ) - |> Deferred.ignore_m - in - upgraded_json ) - | _ -> - (* This error will get handled properly elsewhere, do nothing here. *) - return json - -*) let%test_module "Account config test" = ( module struct let%test_unit "Runtime config <=> Account" = diff --git a/src/lib/runtime_config/runtime_config.ml b/src/lib/runtime_config/runtime_config.ml index 74561629e56..6b30c28bce2 100644 --- a/src/lib/runtime_config/runtime_config.ml +++ b/src/lib/runtime_config/runtime_config.ml @@ -845,10 +845,12 @@ type t = } [@@deriving to_yojson] -let format_as_json_without_accounts (x: t) = +let format_as_json_without_accounts (x : t) = let genesis_accounts = - let { accounts; _ } : Json_layout.Ledger.t = Ledger.to_json_layout x.ledger - in Option.map ~f:List.length accounts + let ({ accounts; _ } : Json_layout.Ledger.t) = + Ledger.to_json_layout x.ledger + in + Option.map ~f:List.length accounts in let staking_accounts = let%bind.Option { staking; _ } = x.epoch_data in @@ -884,8 +886,10 @@ let format_as_json_without_accounts (x: t) = `Assoc [ ("daemon", Mina_compile_config.to_yojson x.compile_config) ; ("genesis", Genesis_constants.to_yojson x.genesis_constants) - ; ("proof", Genesis_constants.Constraint_constants.to_yojson x.constraint_config.constraint_constants) - ; ( "ledger", Json_layout.Ledger.to_yojson @@ f x.ledger) + ; ( "proof" + , Genesis_constants.Constraint_constants.to_yojson + x.constraint_config.constraint_constants ) + ; ("ledger", Json_layout.Ledger.to_yojson @@ f x.ledger) ; ( "epoch_data" , Option.value_map ~default:`Null ~f:Json_layout.Epoch_data.to_yojson (Option.map ~f:g x.epoch_data) ) @@ -927,8 +931,8 @@ let ledger_of_accounts accounts = let make_fork_config ~staged_ledger ~global_slot_since_genesis ~state_hash ~blockchain_length ~staking_ledger ~staking_epoch_seed ~next_epoch_ledger - ~next_epoch_seed ~genesis_constants - ~(constraint_config : Constraint.t) ~compile_config = + ~next_epoch_seed ~genesis_constants ~(constraint_config : Constraint.t) + ~compile_config = let open Async.Deferred.Result.Let_syntax in let global_slot_since_genesis = Mina_numbers.Global_slot_since_genesis.to_int global_slot_since_genesis From e7e471072b81b675d9558beadcfef6e854a52eea Mon Sep 17 00:00:00 2001 From: martyall Date: Wed, 18 Sep 2024 09:37:06 -0700 Subject: [PATCH 13/29] zkapp_limits --- src/app/zkapp_limits/dune | 8 ++++++-- src/app/zkapp_limits/zkapp_limits.ml | 19 ++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/app/zkapp_limits/dune b/src/app/zkapp_limits/dune index 6cb781b71b2..f911a942a52 100644 --- a/src/app/zkapp_limits/dune +++ b/src/app/zkapp_limits/dune @@ -4,13 +4,17 @@ (public_name zkapp_limits) (libraries ;; opam libraries + async + async.async_command base base.caml core_kernel ;; local libraries - mina_base - genesis_constants bounded_types + cli_lib + genesis_ledger_helper + mina_base + runtime_config ) (instrumentation (backend bisect_ppx)) (preprocess (pps ppx_version ppx_mina ppx_custom_printf ppx_let ppx_hash ppx_compare ppx_sexp_conv))) diff --git a/src/app/zkapp_limits/zkapp_limits.ml b/src/app/zkapp_limits/zkapp_limits.ml index 47f78d8f873..2e34e7d1fa5 100644 --- a/src/app/zkapp_limits/zkapp_limits.ml +++ b/src/app/zkapp_limits/zkapp_limits.ml @@ -1,8 +1,8 @@ (*All the limits set for zkApp transactions*) open Core_kernel +open Async -let main () = - let genesis_constants = Genesis_constants.Compiled.genesis_constants in +let main ({ genesis_constants; _ } : Runtime_config.t) = let cost_limit = genesis_constants.zkapp_transaction_cost_limit in let max_event_elements = genesis_constants.max_event_elements in let max_action_elements = genesis_constants.max_action_elements in @@ -29,4 +29,17 @@ let main () = (proofs + signed_single_segments + (signed_pair_segments * 2)) cost ) ) ) -let () = main () +let () = + Command.run + @@ + let open Command.Let_syntax in + Command.async ~summary:"All the limits set for zkApp transactions" + (let%map_open config_file = Cli_lib.Flag.conf_file in + fun () -> + let open Deferred.Let_syntax in + let logger = Logger.create () in + let%map _, config = + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file + ~logger () + in + main config ) From 8718312fdedfd160e2e1e0a832d369b620274450 Mon Sep 17 00:00:00 2001 From: martyall Date: Wed, 18 Sep 2024 09:48:31 -0700 Subject: [PATCH 14/29] runtime_genesis_ledger --- src/app/runtime_genesis_ledger/dune | 1 + .../runtime_genesis_ledger.ml | 75 +++++-------------- 2 files changed, 21 insertions(+), 55 deletions(-) diff --git a/src/app/runtime_genesis_ledger/dune b/src/app/runtime_genesis_ledger/dune index 0a1191a086d..967e38e958c 100644 --- a/src/app/runtime_genesis_ledger/dune +++ b/src/app/runtime_genesis_ledger/dune @@ -13,6 +13,7 @@ yojson async_unix ;;local libraries + cli_lib genesis_constants mina_runtime_config mina_ledger diff --git a/src/app/runtime_genesis_ledger/runtime_genesis_ledger.ml b/src/app/runtime_genesis_ledger/runtime_genesis_ledger.ml index 3c8b0317975..4db7da0c1d7 100644 --- a/src/app/runtime_genesis_ledger/runtime_genesis_ledger.ml +++ b/src/app/runtime_genesis_ledger/runtime_genesis_ledger.ml @@ -58,23 +58,6 @@ let generate_hash_json ~genesis_dir ledger staking_ledger next_ledger = in { Hash_json.ledger = ledger_hashes; epoch_data = { staking; next } } -let is_dirty_proof = function - | Runtime_config.Proof_keys. - { level = None - ; sub_windows_per_window = None - ; ledger_depth = None - ; work_delay = None - ; block_window_duration_ms = None - ; transaction_capacity = None - ; coinbase_amount = None - ; supercharged_coinbase_factor = None - ; account_creation_fee = None - ; fork = _ - } -> - false - | _ -> - true - let extract_accounts_exn = function | { Runtime_config.Ledger.base = Accounts accounts ; num_accounts = None @@ -88,41 +71,26 @@ let extract_accounts_exn = function | _ -> failwith "Wrong ledger supplied" -let load_config_exn config_file = - let%map config_json = - Deferred.Or_error.ok_exn - @@ Genesis_ledger_helper.load_config_json config_file - in - let config = - Runtime_config.of_yojson config_json - |> Result.map_error ~f:(fun err -> - Failure ("Could not parse configuration: " ^ err) ) - |> Result.ok_exn - in - if - Option.( - is_some config.daemon || is_some config.genesis - || Option.value_map ~default:false ~f:is_dirty_proof config.proof) - then failwith "Runtime config has unexpected fields" ; - let ledger = Option.value_exn ~message:"No ledger provided" config.ledger in - let staking_ledger = - let%map.Option { staking; _ } = config.epoch_data in - staking.ledger +let main ~config_file ~genesis_dir ~hash_output_file () = + let%bind _, config = + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger () in - let next_ledger = - let%bind.Option { next; _ } = config.epoch_data in - let%map.Option { ledger; _ } = next in - ledger - in - ( extract_accounts_exn ledger - , Option.map ~f:extract_accounts_exn staking_ledger - , Option.map ~f:extract_accounts_exn next_ledger ) - -let main ~(constraint_constants : Genesis_constants.Constraint_constants.t) - ~config_file ~genesis_dir ~hash_output_file () = - let%bind accounts, staking_accounts_opt, next_accounts_opt = - load_config_exn config_file + let accounts, staking_accounts_opt, next_accounts_opt = + let ledger = config.ledger in + let staking_ledger = + let%map.Option { staking; _ } = config.epoch_data in + staking.ledger + in + let next_ledger = + let%bind.Option { next; _ } = config.epoch_data in + let%map.Option { ledger; _ } = next in + ledger + in + ( extract_accounts_exn ledger + , Option.map ~f:extract_accounts_exn staking_ledger + , Option.map ~f:extract_accounts_exn next_ledger ) in + let constraint_constants = config.constraint_config.constraint_constants in let ledger = load_ledger ~constraint_constants accounts in let staking_ledger : Ledger.t = Option.value_map ~default:ledger @@ -141,7 +109,6 @@ let main ~(constraint_constants : Genesis_constants.Constraint_constants.t) ~contents:(Yojson.Safe.to_string (Hash_json.to_yojson hash_json)) let () = - let constraint_constants = Genesis_constants.Compiled.constraint_constants in Command.run (Command.async ~summary: @@ -151,9 +118,7 @@ let () = Command.( let open Let_syntax in let open Command.Param in - let%map config_file = - flag "--config-file" ~doc:"PATH path to the JSON configuration file" - (required string) + let%map config_file = Cli_lib.Flag.conf_file and genesis_dir = flag "--genesis-dir" ~doc: @@ -168,4 +133,4 @@ let () = "PATH path to the file where the hashes of the ledgers are to \ be saved" in - main ~constraint_constants ~config_file ~genesis_dir ~hash_output_file) ) + main ~config_file ~genesis_dir ~hash_output_file) ) From fdb866010e05e0c039763f7fb78aafb452bdcc5f Mon Sep 17 00:00:00 2001 From: martyall Date: Wed, 18 Sep 2024 10:22:38 -0700 Subject: [PATCH 15/29] ledger_export_benchmark --- .../ledger_export_bench/ledger_export_benchmark.ml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/app/ledger_export_bench/ledger_export_benchmark.ml b/src/app/ledger_export_bench/ledger_export_benchmark.ml index 5125f8ba904..aa3c503bb16 100644 --- a/src/app/ledger_export_bench/ledger_export_benchmark.ml +++ b/src/app/ledger_export_bench/ledger_export_benchmark.ml @@ -3,13 +3,14 @@ open Core_bench let load_daemon_cfg filename () = let json = Yojson.Safe.from_file filename in - match Runtime_config.of_yojson json with + match Runtime_config.Json_layout.of_yojson json with | Ok cfg -> cfg | Error err -> raise (Failure err) -let serialize cfg () = Runtime_config.to_yojson cfg |> Yojson.Safe.to_string +let serialize cfg () = + Runtime_config.Json_layout.to_yojson cfg |> Yojson.Safe.to_string let map_results ~f = List.fold ~init:(Ok []) ~f:(fun acc x -> @@ -25,10 +26,12 @@ let () = let runtime_config = Sys.getenv_exn "RUNTIME_CONFIG" in let cfg = load_daemon_cfg runtime_config () in let accounts = - match cfg.ledger with - | None | Some { base = Named _; _ } | Some { base = Hash; _ } -> + match + Runtime_config.Ledger.of_json_layout cfg.ledger |> Result.ok_or_failwith + with + | { base = Named _; _ } | { base = Hash; _ } -> [] - | Some { base = Accounts accs; _ } -> + | { base = Accounts accs; _ } -> List.map ~f:Runtime_config.Accounts.Single.to_account accs in Command.run From 334519aaa52685592f63ac44623377de6f37f022 Mon Sep 17 00:00:00 2001 From: martyall Date: Wed, 18 Sep 2024 10:30:17 -0700 Subject: [PATCH 16/29] archive_blocks --- src/app/archive_blocks/archive_blocks.ml | 19 +++++++++++-------- src/app/archive_blocks/dune | 1 + 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/app/archive_blocks/archive_blocks.ml b/src/app/archive_blocks/archive_blocks.ml index 6c001ef801c..48f32743630 100644 --- a/src/app/archive_blocks/archive_blocks.ml +++ b/src/app/archive_blocks/archive_blocks.ml @@ -4,8 +4,14 @@ open Core_kernel open Async open Archive_lib -let main ~genesis_constants ~constraint_constants ~archive_uri ~precomputed - ~extensional ~success_file ~failure_file ~log_successes ~files () = +let main ~config_file ~archive_uri ~precomputed ~extensional ~success_file + ~failure_file ~log_successes ~files () = + let logger = Logger.create () in + let%bind _, config = + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger () + in + let genesis_constants = config.genesis_constants in + let constraint_constants = config.constraint_config.constraint_constants in let output_file_line path = match path with | Some path -> @@ -99,10 +105,6 @@ let main ~genesis_constants ~constraint_constants ~archive_uri ~precomputed let () = Command.( - let genesis_constants = Genesis_constants.Compiled.genesis_constants in - let constraint_constants = - Genesis_constants.Compiled.constraint_constants - in run (let open Let_syntax in async ~summary:"Write blocks to an archive database" @@ -133,6 +135,7 @@ let () = "true/false Whether to log messages for files that were \ processed successfully" (Flag.optional_with_default true Param.bool) + and config_file = Cli_lib.Flag.conf_file and files = Param.anon Anons.(sequence ("FILES" %: Param.string)) in - main ~genesis_constants ~constraint_constants ~archive_uri ~precomputed - ~extensional ~success_file ~failure_file ~log_successes ~files ))) + main ~config_file ~archive_uri ~precomputed ~extensional ~success_file + ~failure_file ~log_successes ~files ))) diff --git a/src/app/archive_blocks/dune b/src/app/archive_blocks/dune index 48f0db5aabd..54a34a3297c 100644 --- a/src/app/archive_blocks/dune +++ b/src/app/archive_blocks/dune @@ -19,6 +19,7 @@ base.caml async.async_command ;; local libraries + cli_lib logger mina_block bounded_types From 294b16fe5d3ffbca67573f69408fdc7f33509737 Mon Sep 17 00:00:00 2001 From: martyall Date: Wed, 18 Sep 2024 11:25:02 -0700 Subject: [PATCH 17/29] archive --- src/app/archive/cli/archive_cli.ml | 23 ++++++++++------------ src/app/archive/lib/processor.ml | 31 ++++++++++-------------------- 2 files changed, 20 insertions(+), 34 deletions(-) diff --git a/src/app/archive/cli/archive_cli.ml b/src/app/archive/cli/archive_cli.ml index d9835087e91..c72f577248c 100644 --- a/src/app/archive/cli/archive_cli.ml +++ b/src/app/archive/cli/archive_cli.ml @@ -28,36 +28,33 @@ let command_run = Archive_lib.Metrics.default_missing_blocks_width ) (optional int) and postgres = Flag.Uri.Archive.postgres - and runtime_config_file = - flag "--config-file" ~aliases:[ "-config-file" ] (optional string) - ~doc:"PATH to the configuration file containing the genesis ledger" and delete_older_than = flag "--delete-older-than" ~aliases:[ "-delete-older-than" ] (optional int) ~doc: "int Delete blocks that are more than n blocks lower than the \ maximum seen block." - in - let runtime_config_opt = - Option.map runtime_config_file ~f:(fun file -> - Yojson.Safe.from_file file |> Runtime_config.of_yojson - |> Result.ok_or_failwith ) + and config_file = Cli_lib.Flag.conf_file + and add_genesis_accounts_opt = + Command.Param.flag "--add-genesis-accounts" + ~doc:"add genesis accounts to the db" Command.Param.no_arg in fun () -> let logger = Logger.create () in - let genesis_constants = Genesis_constants.Compiled.genesis_constants in - let constraint_constants = - Genesis_constants.Compiled.constraint_constants + let open Deferred.Let_syntax in + let%bind precomputed_values, _ = + Genesis_ledger_helper.Config_loader.load_config_exn ~logger + ~config_file () in Stdout_log.setup log_json log_level ; [%log info] "Starting archive process; built with commit $commit" ~metadata:[ ("commit", `String Mina_version.commit_id) ] ; Archive_lib.Processor.setup_server ~metrics_server_port ~logger - ~genesis_constants ~constraint_constants ~postgres_address:postgres.value ~server_port: (Option.value server_port.value ~default:server_port.default) - ~delete_older_than ~runtime_config_opt ~missing_blocks_width ) + ~delete_older_than ~missing_blocks_width ~precomputed_values + ~add_genesis_accounts_opt ) let time_arg = (* Same timezone as Genesis_constants.genesis_state_timestamp. *) diff --git a/src/app/archive/lib/processor.ml b/src/app/archive/lib/processor.ml index 4446f434ff2..3c947cbb2bc 100644 --- a/src/app/archive/lib/processor.ml +++ b/src/app/archive/lib/processor.ml @@ -4728,17 +4728,7 @@ let run pool reader ~genesis_constants ~constraint_constants ~logger Deferred.unit ) (* [add_genesis_accounts] is called when starting the archive process *) -let add_genesis_accounts ~logger ~(config_file : string) pool = - let%bind precomputed_values, (config : Runtime_config.t) = - match%map - Genesis_ledger_helper.Config_loader.load_config ~config_file ~logger () - with - | Ok a -> - a - | Error err -> - failwithf "Could not get precomputed values, error: %s" - (Error.to_string_hum err) () - in +let add_genesis_accounts ~logger ~(precomputed_values : Genesis_proof.t) pool = let ledger = Precomputed_values.genesis_ledger precomputed_values |> Lazy.force in @@ -4758,7 +4748,7 @@ let add_genesis_accounts ~logger ~(config_file : string) pool = let%bind.Deferred.Result genesis_block_id = Block.add_if_doesn't_exist (module Conn) - ~constraint_constants:config.constraint_config.constraint_constants + ~constraint_constants:precomputed_values.constraint_constants genesis_block in let%bind.Deferred.Result { ledger_hash; _ } = @@ -4857,10 +4847,11 @@ let create_metrics_server ~logger ~metrics_server_port ~missing_blocks_width go () (* for running the archive process *) -let setup_server ~(genesis_constants : Genesis_constants.t) - ~(constraint_constants : Genesis_constants.Constraint_constants.t) - ~metrics_server_port ~logger ~postgres_address ~server_port - ~delete_older_than ~config_file_opt ~missing_blocks_width = +let setup_server ~metrics_server_port ~logger ~postgres_address ~server_port + ~delete_older_than ~(precomputed_values : Genesis_proof.t) + ~missing_blocks_width ~add_genesis_accounts_opt = + let genesis_constants = precomputed_values.genesis_constants in + let constraint_constants = precomputed_values.constraint_constants in let where_to_listen = Async.Tcp.Where_to_listen.bind_to All_addresses (On_port server_port) in @@ -4890,11 +4881,9 @@ let setup_server ~(genesis_constants : Genesis_constants.t) Deferred.unit | Ok pool -> let%bind () = - match config_file_opt with - | None -> - Deferred.unit - | Some config_file -> - add_genesis_accounts pool ~logger ~config_file + if add_genesis_accounts_opt then + add_genesis_accounts pool ~logger ~precomputed_values + else Deferred.unit in run ~constraint_constants ~genesis_constants pool reader ~logger ~delete_older_than From 6d964712fbe68e0600fa2ebc8d59552fc884ce5a Mon Sep 17 00:00:00 2001 From: martyall Date: Wed, 18 Sep 2024 11:28:39 -0700 Subject: [PATCH 18/29] snark_work_debugger --- src/app/snark_work_debugger/dune | 1 + src/app/snark_work_debugger/snark_work_debugger.ml | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/app/snark_work_debugger/dune b/src/app/snark_work_debugger/dune index 0f8b91aaea9..7a2c5c856b5 100644 --- a/src/app/snark_work_debugger/dune +++ b/src/app/snark_work_debugger/dune @@ -14,6 +14,7 @@ core_kernel sexplib0 ;; local libraries + cli_lib mina_base snark_worker bounded_types diff --git a/src/app/snark_work_debugger/snark_work_debugger.ml b/src/app/snark_work_debugger/snark_work_debugger.ml index 06f29637ba9..44a208d29a0 100644 --- a/src/app/snark_work_debugger/snark_work_debugger.ml +++ b/src/app/snark_work_debugger/snark_work_debugger.ml @@ -37,12 +37,17 @@ let cmd = let%map path = let open Command.Param in flag "--spec" ~doc:"PATH Spec path" (required string) - in + and config_file = Cli_lib.Flag.conf_file in fun () -> - let constraint_constants = - Genesis_constants.Compiled.constraint_constants + let logger = Logger.create () in + let open Deferred.Let_syntax in + let%bind _, config = + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file + ~logger () + in + let { Runtime_config.Constraint.constraint_constants; proof_level } = + config.constraint_config in - let proof_level = Genesis_constants.Compiled.proof_level in Obj.magic (main path ~constraint_constants ~proof_level)) let () = Command.run cmd From 2a73d07419abe2cfa7e93e3d4dc1ceeff7b41ec3 Mon Sep 17 00:00:00 2001 From: martyall Date: Wed, 18 Sep 2024 11:35:55 -0700 Subject: [PATCH 19/29] delegation_verify --- .../delegation_verify/delegation_verify.ml | 69 ++++--------------- 1 file changed, 15 insertions(+), 54 deletions(-) diff --git a/src/app/delegation_verify/delegation_verify.ml b/src/app/delegation_verify/delegation_verify.ml index 883494c5a28..b22a5f91339 100644 --- a/src/app/delegation_verify/delegation_verify.ml +++ b/src/app/delegation_verify/delegation_verify.ml @@ -13,9 +13,7 @@ let get_filenames = let verify_snark_work ~verify_transaction_snarks ~proof ~message = verify_transaction_snarks [ (proof, message) ] -let config_flag = - let open Command.Param in - flag "--config-file" ~doc:"FILE config file" (optional string) +let config_flag = Cli_lib.Flag.conf_file let keyspace_flag = let open Command.Param in @@ -44,36 +42,16 @@ let timestamp = let open Command.Param in anon ("timestamp" %: string) -let instantiate_verify_functions ~logger ~genesis_constants - ~constraint_constants ~proof_level ~cli_proof_level = function - | None -> - Deferred.return - (Verifier.verify_functions ~constraint_constants ~proof_level ()) - | Some config_file -> - let%bind.Deferred precomputed_values = - let%bind.Deferred.Or_error config_json = - Genesis_ledger_helper.load_config_json config_file - in - let%bind.Deferred.Or_error config = - Deferred.return - @@ Result.map_error ~f:Error.of_string - @@ Runtime_config.of_yojson config_json - in - Genesis_ledger_helper.init_from_config_file ~logger ~proof_level - ~constraint_constants ~genesis_constants config ~cli_proof_level - in - let%map.Deferred precomputed_values = - match precomputed_values with - | Ok (precomputed_values, _) -> - Deferred.return precomputed_values - | Error _ -> - Output.display_error "fail to read config file" ; - exit 4 - in - let constraint_constants = - Precomputed_values.constraint_constants precomputed_values - in - Verifier.verify_functions ~constraint_constants ~proof_level:Full () +(*We use the cli_proof_level arg to overide the config settings *) +let instantiate_verify_functions ~logger ~config_file = + let%map.Deferred precomputed_values, _ = + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger + ~cli_proof_level:Full () + in + let constraint_constants = + Precomputed_values.constraint_constants precomputed_values + in + Verifier.verify_functions ~constraint_constants ~proof_level:Full () module Make_verifier (Source : Submission.Data_source) = struct let verify_transaction_snarks = Source.verify_transaction_snarks @@ -153,15 +131,10 @@ let filesystem_command = and config_file = config_flag in fun () -> let logger = Logger.create () in - let genesis_constants = Genesis_constants.Compiled.genesis_constants in - let constraint_constants = - Genesis_constants.Compiled.constraint_constants - in - let proof_level = Genesis_constants.Compiled.proof_level in let%bind.Deferred verify_blockchain_snarks, verify_transaction_snarks = - instantiate_verify_functions ~logger config_file ~genesis_constants - ~constraint_constants ~proof_level ~cli_proof_level:None + instantiate_verify_functions ~logger ~config_file in + let submission_paths = get_filenames inputs in let module V = Make_verifier (struct include Submission.Filesystem @@ -192,14 +165,8 @@ let cassandra_command = fun () -> let open Deferred.Let_syntax in let logger = Logger.create () in - let genesis_constants = Genesis_constants.Compiled.genesis_constants in - let constraint_constants = - Genesis_constants.Compiled.constraint_constants - in - let proof_level = Genesis_constants.Compiled.proof_level in let%bind.Deferred verify_blockchain_snarks, verify_transaction_snarks = - instantiate_verify_functions ~logger config_file ~genesis_constants - ~constraint_constants ~proof_level ~cli_proof_level:None + instantiate_verify_functions ~logger ~config_file in let module V = Make_verifier (struct include Submission.Cassandra @@ -230,14 +197,8 @@ let stdin_command = fun () -> let open Deferred.Let_syntax in let logger = Logger.create () in - let genesis_constants = Genesis_constants.Compiled.genesis_constants in - let constraint_constants = - Genesis_constants.Compiled.constraint_constants - in - let proof_level = Genesis_constants.Compiled.proof_level in let%bind.Deferred verify_blockchain_snarks, verify_transaction_snarks = - instantiate_verify_functions ~logger config_file ~genesis_constants - ~constraint_constants ~proof_level ~cli_proof_level:None + instantiate_verify_functions ~logger ~config_file in let module V = Make_verifier (struct include Submission.Stdin From c8354730d51605d56b5c10b28e3f793abd0396f7 Mon Sep 17 00:00:00 2001 From: martyall Date: Wed, 18 Sep 2024 11:52:37 -0700 Subject: [PATCH 20/29] replayer --- src/app/replayer/replayer.ml | 13 +++++++++---- src/lib/runtime_config/runtime_config.ml | 4 ++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/app/replayer/replayer.ml b/src/app/replayer/replayer.ml index 957f4a0f234..5620cd5f036 100644 --- a/src/app/replayer/replayer.ml +++ b/src/app/replayer/replayer.ml @@ -631,7 +631,7 @@ let write_replayer_checkpoint ~logger ~ledger ~last_global_slot_since_genesis let main ~input_file ~output_file_opt ~archive_uri ~continue_on_error ~checkpoint_interval ~checkpoint_output_folder_opt ~checkpoint_file_prefix ~genesis_dir_opt ~log_json ~log_level ~log_filename ~file_log_level - ~constraint_constants ~proof_level () = + ~config_file () = Cli_lib.Stdout_log.setup log_json log_level ; Option.iter log_filename ~f:(fun log_filename -> Logger.Consumer_registry.register ~id:"default" @@ -639,6 +639,12 @@ let main ~input_file ~output_file_opt ~archive_uri ~continue_on_error ~transport:(Logger_file_system.evergrowing ~log_filename) () ) ; let logger = Logger.create () in + let%bind _, config = + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger () + in + let { Runtime_config.Constraint.constraint_constants; proof_level } = + config.constraint_config + in let json = Yojson.Safe.from_file input_file in let input = match input_of_yojson json with @@ -1683,8 +1689,6 @@ let main ~input_file ~output_file_opt ~archive_uri ~continue_on_error exit 1 ) ) ) let () = - let constraint_constants = Genesis_constants.Compiled.constraint_constants in - let proof_level = Genesis_constants.Proof_level.Full in Command.( run (let open Let_syntax in @@ -1722,6 +1726,7 @@ let () = Param.flag "--checkpoint-file-prefix" ~doc:"string Checkpoint file prefix (default: 'replayer')" Param.(optional_with_default "replayer" string) + and config_file = Cli_lib.Flag.conf_file and log_json = Cli_lib.Flag.Log.json and log_level = Cli_lib.Flag.Log.level and file_log_level = Cli_lib.Flag.Log.file_log_level @@ -1729,4 +1734,4 @@ let () = main ~input_file ~output_file_opt ~archive_uri ~checkpoint_interval ~continue_on_error ~checkpoint_output_folder_opt ~checkpoint_file_prefix ~genesis_dir_opt ~log_json ~log_level - ~file_log_level ~log_filename ~constraint_constants ~proof_level ))) + ~file_log_level ~log_filename ~config_file ))) diff --git a/src/lib/runtime_config/runtime_config.ml b/src/lib/runtime_config/runtime_config.ml index 6b30c28bce2..1bb518e103a 100644 --- a/src/lib/runtime_config/runtime_config.ml +++ b/src/lib/runtime_config/runtime_config.ml @@ -742,6 +742,8 @@ module Ledger = struct ; name ; add_genesis_winner } + + let of_yojson x = Result.(Json_layout.Ledger.of_yojson x >>= of_json_layout) end module Epoch_data = struct @@ -819,6 +821,8 @@ module Epoch_data = struct { staking; next } let to_yojson x = Json_layout.Epoch_data.to_yojson (to_json_layout x) + + let of_yojson x = Result.(Json_layout.Epoch_data.of_yojson x >>= of_json_layout) end module Constraint = struct From 226058180e6b6926111111f5fd3e6ec54cff6275 Mon Sep 17 00:00:00 2001 From: martyall Date: Wed, 18 Sep 2024 12:18:38 -0700 Subject: [PATCH 21/29] zkapp_test_transation --- .../zkapp_test_transaction/lib/commands.ml | 134 +++++++++++------- .../zkapp_test_transaction.ml | 128 ++++++----------- 2 files changed, 124 insertions(+), 138 deletions(-) diff --git a/src/app/zkapp_test_transaction/lib/commands.ml b/src/app/zkapp_test_transaction/lib/commands.ml index 08fe3ee5860..e78184d1f89 100644 --- a/src/app/zkapp_test_transaction/lib/commands.ml +++ b/src/app/zkapp_test_transaction/lib/commands.ml @@ -45,9 +45,11 @@ let get_second_pass_ledger_mask ~ledger ~constraint_constants ~global_slot second_pass_ledger let gen_proof ?(zkapp_account = None) (zkapp_command : Zkapp_command.t) - ~(genesis_constants : Genesis_constants.t) - ~(proof_level : Genesis_constants.Proof_level.t) - ~(constraint_constants : Genesis_constants.Constraint_constants.t) = + ~(config : Runtime_config.t) = + let genesis_constants = config.genesis_constants in + let { Runtime_config.Constraint.constraint_constants; proof_level } = + config.constraint_config + in let ledger = Ledger.create ~depth:constraint_constants.ledger_depth () in let _v = let id = @@ -146,8 +148,7 @@ let gen_proof ?(zkapp_account = None) (zkapp_command : Zkapp_command.t) () let generate_zkapp_txn (keypair : Signature_lib.Keypair.t) (ledger : Ledger.t) - ~zkapp_kp ~(genesis_constants : Genesis_constants.t) ~proof_level - ~constraint_constants = + ~zkapp_kp ~(config : Runtime_config.t) = let open Deferred.Let_syntax in let receiver = Quickcheck.random_value Signature_lib.Public_key.Compressed.gen @@ -160,6 +161,10 @@ let generate_zkapp_txn (keypair : Signature_lib.Keypair.t) (ledger : Ledger.t) ; amount = Currency.Amount.of_mina_int_exn 10 (*10 Mina*) } in + let { Runtime_config.Constraint.constraint_constants; proof_level } = + config.constraint_config + in + let genesis_constants = config.genesis_constants in let consensus_constants = Consensus.Constants.create ~constraint_constants ~protocol_constants:genesis_constants.protocol @@ -326,20 +331,16 @@ module Util = struct end let test_zkapp_with_genesis_ledger_main keyfile zkapp_keyfile config_file () = - let constraint_constants = Genesis_constants.Compiled.constraint_constants in - let genesis_constants = Genesis_constants.Compiled.genesis_constants in let open Deferred.Let_syntax in let%bind keypair = Util.fee_payer_keypair_of_file keyfile in let%bind zkapp_kp = Util.snapp_keypair_of_file zkapp_keyfile in - let%bind ledger = - let%map config_json = Genesis_ledger_helper.load_config_json config_file in - let runtime_config = - Or_error.ok_exn config_json - |> Runtime_config.of_yojson |> Result.ok_or_failwith - in + let%bind _, config = + let logger = Logger.create () in + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger () + in + let ledger = let accounts = - let config = Option.value_exn runtime_config.Runtime_config.ledger in - match config.base with + match config.ledger.base with | Accounts accounts -> lazy (Genesis_ledger_helper.Accounts.to_full accounts) | _ -> @@ -347,17 +348,15 @@ let test_zkapp_with_genesis_ledger_main keyfile zkapp_keyfile config_file () = in let packed = Genesis_ledger_helper.Ledger.packed_genesis_ledger_of_accounts - ~depth:constraint_constants.ledger_depth accounts + ~depth:config.constraint_config.constraint_constants.ledger_depth + accounts in Lazy.force (Genesis_ledger.Packed.t packed) in - generate_zkapp_txn keypair ledger ~zkapp_kp ~constraint_constants - ~proof_level:Full ~genesis_constants + generate_zkapp_txn keypair ledger ~zkapp_kp ~config let create_zkapp_account ~debug ~sender ~sender_nonce ~fee ~fee_payer - ~fee_payer_nonce ~zkapp_keyfile ~amount ~memo = - let constraint_constants = Genesis_constants.Compiled.constraint_constants in - let genesis_constants = Genesis_constants.Compiled.genesis_constants in + ~fee_payer_nonce ~zkapp_keyfile ~amount ~memo ~config_file = let open Deferred.Let_syntax in let%bind sender_keypair = Util.keypair_of_file sender ~which:"Sender" in let%bind fee_payer_keypair = Util.fee_payer_keypair_of_file fee_payer in @@ -376,21 +375,21 @@ let create_zkapp_account ~debug ~sender ~sender_nonce ~fee ~fee_payer ; authorization_kind = Signature } in + let%bind _, config = + let logger = Logger.create () in + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger + ~cli_proof_level:Full () + in + let constraint_constants = config.constraint_config.constraint_constants in let%bind zkapp_command = Transaction_snark.For_tests.deploy_snapp ~permissions:Permissions.user_default ~constraint_constants spec in - let%map () = - if debug then - gen_proof ~genesis_constants ~constraint_constants ~proof_level:Full - zkapp_command - else return () - in + let%map () = if debug then gen_proof ~config zkapp_command else return () in zkapp_command -let upgrade_zkapp ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile - ~constraint_constants ~genesis_constants ~verification_key ~zkapp_uri ~auth - = +let upgrade_zkapp ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile ~config_file + ~verification_key ~zkapp_uri ~auth = let open Deferred.Let_syntax in let%bind keypair = Util.fee_payer_keypair_of_file keyfile in let%bind zkapp_account_keypair = Util.snapp_keypair_of_file zkapp_keyfile in @@ -423,6 +422,12 @@ let upgrade_zkapp ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile ; preconditions = None } in + let%bind _, config = + let logger = Logger.create () in + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger + ~cli_proof_level:Full () + in + let constraint_constants = config.constraint_config.constraint_constants in let%bind zkapp_command = let `VK vk, `Prover prover = Lazy.force @@ vk_and_prover ~constraint_constants @@ -432,8 +437,7 @@ let upgrade_zkapp ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile in let%map () = if debug then - gen_proof zkapp_command ~constraint_constants ~genesis_constants - ~proof_level:Full + gen_proof zkapp_command ~config ~zkapp_account: (Some (Signature_lib.Public_key.compress zkapp_account_keypair.public_key) @@ -443,7 +447,7 @@ let upgrade_zkapp ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile zkapp_command let transfer_funds ~debug ~sender ~sender_nonce ~fee ~fee_payer ~fee_payer_nonce - ~memo ~receivers ~genesis_constants ~constraint_constants = + ~memo ~receivers ~config_file = let open Deferred.Let_syntax in let%bind receivers = receivers in let amount = @@ -469,21 +473,24 @@ let transfer_funds ~debug ~sender ~sender_nonce ~fee ~fee_payer ~fee_payer_nonce ; preconditions = None } in + let%bind _, config = + let logger = Logger.create () in + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger + ~cli_proof_level:Full () + in let zkapp_command = Transaction_snark.For_tests.multiple_transfers ~constraint_constants: Genesis_constants.For_unit_tests.Constraint_constants.t spec in let%map () = - if debug then - gen_proof zkapp_command ~zkapp_account:None ~genesis_constants - ~constraint_constants ~proof_level:Full + if debug then gen_proof zkapp_command ~zkapp_account:None ~config else return () in zkapp_command let update_state ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile ~app_state - ~genesis_constants ~constraint_constants = + ~config_file = let open Deferred.Let_syntax in let%bind keypair = Util.fee_payer_keypair_of_file keyfile in let%bind zkapp_keypair = Util.snapp_keypair_of_file zkapp_keyfile in @@ -505,6 +512,12 @@ let update_state ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile ~app_state ; preconditions = None } in + let%bind _, config = + let logger = Logger.create () in + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger + ~cli_proof_level:Full () + in + let constraint_constants = config.constraint_config.constraint_constants in let%bind zkapp_command = let `VK vk, `Prover prover = Lazy.force @@ vk_and_prover ~constraint_constants @@ -514,8 +527,7 @@ let update_state ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile ~app_state in let%map () = if debug then - gen_proof zkapp_command ~genesis_constants ~constraint_constants - ~proof_level:Full + gen_proof zkapp_command ~config ~zkapp_account: (Some (Signature_lib.Public_key.compress zkapp_keypair.public_key)) else return () @@ -523,7 +535,7 @@ let update_state ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile ~app_state zkapp_command let update_zkapp_uri ~debug ~keyfile ~fee ~nonce ~memo ~snapp_keyfile ~zkapp_uri - ~auth ~constraint_constants ~genesis_constants = + ~auth ~config_file = let open Deferred.Let_syntax in let%bind keypair = Util.fee_payer_keypair_of_file keyfile in let%bind zkapp_account_keypair = Util.snapp_keypair_of_file snapp_keyfile in @@ -545,6 +557,12 @@ let update_zkapp_uri ~debug ~keyfile ~fee ~nonce ~memo ~snapp_keyfile ~zkapp_uri ; preconditions = None } in + let%bind _, config = + let logger = Logger.create () in + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger + ~cli_proof_level:Full () + in + let constraint_constants = config.constraint_config.constraint_constants in let%bind zkapp_command = let `VK vk, `Prover prover = Lazy.force @@ vk_and_prover ~constraint_constants @@ -554,8 +572,7 @@ let update_zkapp_uri ~debug ~keyfile ~fee ~nonce ~memo ~snapp_keyfile ~zkapp_uri in let%map () = if debug then - gen_proof zkapp_command ~genesis_constants ~constraint_constants - ~proof_level:Full + gen_proof zkapp_command ~config ~zkapp_account: (Some (Signature_lib.Public_key.compress zkapp_account_keypair.public_key) @@ -565,7 +582,7 @@ let update_zkapp_uri ~debug ~keyfile ~fee ~nonce ~memo ~snapp_keyfile ~zkapp_uri zkapp_command let update_action_state ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile - ~action_state ~genesis_constants ~constraint_constants = + ~action_state ~config_file = let open Deferred.Let_syntax in let%bind keypair = Util.fee_payer_keypair_of_file keyfile in let%bind zkapp_keypair = Util.snapp_keypair_of_file zkapp_keyfile in @@ -587,6 +604,12 @@ let update_action_state ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile ; preconditions = None } in + let%bind _, config = + let logger = Logger.create () in + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger + ~cli_proof_level:Full () + in + let constraint_constants = config.constraint_config.constraint_constants in let%bind zkapp_command = let `VK vk, `Prover prover = Lazy.force @@ vk_and_prover ~constraint_constants @@ -596,8 +619,7 @@ let update_action_state ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile in let%map () = if debug then - gen_proof zkapp_command ~genesis_constants ~constraint_constants - ~proof_level:Full + gen_proof zkapp_command ~config ~zkapp_account: (Some (Signature_lib.Public_key.compress zkapp_keypair.public_key)) else return () @@ -605,7 +627,7 @@ let update_action_state ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile zkapp_command let update_token_symbol ~debug ~keyfile ~fee ~nonce ~memo ~snapp_keyfile - ~token_symbol ~auth ~genesis_constants ~constraint_constants = + ~token_symbol ~auth ~config_file = let open Deferred.Let_syntax in let%bind keypair = Util.fee_payer_keypair_of_file keyfile in let%bind zkapp_account_keypair = Util.snapp_keypair_of_file snapp_keyfile in @@ -627,6 +649,12 @@ let update_token_symbol ~debug ~keyfile ~fee ~nonce ~memo ~snapp_keyfile ; preconditions = None } in + let%bind _, config = + let logger = Logger.create () in + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger + ~cli_proof_level:Full () + in + let constraint_constants = config.constraint_config.constraint_constants in let%bind zkapp_command = let `VK vk, `Prover prover = Lazy.force @@ vk_and_prover ~constraint_constants @@ -636,8 +664,7 @@ let update_token_symbol ~debug ~keyfile ~fee ~nonce ~memo ~snapp_keyfile in let%map () = if debug then - gen_proof zkapp_command ~genesis_constants ~constraint_constants - ~proof_level:Full + gen_proof zkapp_command ~config ~zkapp_account: (Some (Signature_lib.Public_key.compress zkapp_account_keypair.public_key) @@ -647,7 +674,7 @@ let update_token_symbol ~debug ~keyfile ~fee ~nonce ~memo ~snapp_keyfile zkapp_command let update_snapp ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile ~snapp_update - ~current_auth ~genesis_constants ~constraint_constants = + ~current_auth ~config_file = let open Deferred.Let_syntax in let%bind keypair = Util.fee_payer_keypair_of_file keyfile in let%bind zkapp_keypair = Util.snapp_keypair_of_file zkapp_keyfile in @@ -668,6 +695,12 @@ let update_snapp ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile ~snapp_update ; preconditions = None } in + let%bind _, config = + let logger = Logger.create () in + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger + ~cli_proof_level:Full () + in + let constraint_constants = config.constraint_config.constraint_constants in let%bind zkapp_command = let `VK vk, `Prover prover = Lazy.force @@ vk_and_prover ~constraint_constants @@ -678,8 +711,7 @@ let update_snapp ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile ~snapp_update (*Util.print_snapp_transaction zkapp_command ;*) let%map () = if debug then - gen_proof zkapp_command ~genesis_constants ~constraint_constants - ~proof_level:Full + gen_proof zkapp_command ~config ~zkapp_account: (Some (Signature_lib.Public_key.compress zkapp_keypair.public_key)) else return () diff --git a/src/app/zkapp_test_transaction/zkapp_test_transaction.ml b/src/app/zkapp_test_transaction/zkapp_test_transaction.ml index 2e4221c6d12..394d90563d3 100644 --- a/src/app/zkapp_test_transaction/zkapp_test_transaction.ml +++ b/src/app/zkapp_test_transaction/zkapp_test_transaction.ml @@ -54,11 +54,11 @@ end let create_zkapp_account = let create_command ~debug ~sender ~sender_nonce ~fee ~fee_payer - ~fee_payer_nonce ~zkapp_keyfile ~amount ~memo () = + ~fee_payer_nonce ~zkapp_keyfile ~amount ~memo ~config_file () = let open Deferred.Let_syntax in let%map zkapp_command = create_zkapp_account ~debug ~sender ~sender_nonce ~fee ~fee_payer - ~fee_payer_nonce ~zkapp_keyfile ~amount ~memo + ~fee_payer_nonce ~zkapp_keyfile ~amount ~memo ~config_file in Util.print_snapp_transaction ~debug zkapp_command ; () @@ -81,6 +81,7 @@ let create_zkapp_account = Param.flag "--zkapp-account-key" ~doc:"KEYFILE Private key file for the zkApp account to be created" Param.(required string) + and config_file = Cli_lib.Flag.conf_file and amount = Flags.amount in let fee = Option.value ~default:Flags.default_fee fee in if Currency.Fee.(fee < Flags.min_fee) then @@ -88,17 +89,15 @@ let create_zkapp_account = (sprintf "Fee must at least be %s" (Currency.Fee.to_mina_string Flags.min_fee) ) ; create_command ~debug ~sender ~sender_nonce ~fee ~fee_payer - ~fee_payer_nonce ~zkapp_keyfile ~amount ~memo )) + ~fee_payer_nonce ~zkapp_keyfile ~amount ~memo ~config_file )) let upgrade_zkapp = let create_command ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile - ~verification_key ~zkapp_uri ~auth ~constraint_constants - ~genesis_constants () = + ~verification_key ~zkapp_uri ~auth ~config_file () = let open Deferred.Let_syntax in let%map zkapp_command = upgrade_zkapp ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile - ~verification_key ~zkapp_uri ~auth ~constraint_constants - ~genesis_constants + ~verification_key ~zkapp_uri ~auth ~config_file in Util.print_snapp_transaction ~debug zkapp_command ; () @@ -119,6 +118,7 @@ let upgrade_zkapp = and zkapp_uri_str = Param.flag "--zkapp-uri" ~doc:"URI the URI for the zkApp account" Param.(optional string) + and config_file = Cli_lib.Flag.conf_file and auth = Param.flag "--auth" ~doc: @@ -128,27 +128,21 @@ let upgrade_zkapp = in let fee = Option.value ~default:Flags.default_fee fee in let auth = Util.auth_of_string auth in - let constraint_constants = - Genesis_constants.Compiled.constraint_constants - in - let genesis_constants = Genesis_constants.Compiled.genesis_constants in if Currency.Fee.(fee < Flags.min_fee) then failwith (sprintf "Fee must at least be %s" (Currency.Fee.to_mina_string Flags.min_fee) ) ; let zkapp_uri = Zkapp_basic.Set_or_keep.of_option zkapp_uri_str in create_command ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile - ~verification_key ~zkapp_uri ~auth ~constraint_constants - ~genesis_constants )) + ~verification_key ~zkapp_uri ~auth ~config_file )) let transfer_funds_one_receiver = let create_command ~debug ~sender ~sender_nonce ~fee ~fee_payer - ~fee_payer_nonce ~memo ~receiver ~amount ~genesis_constants - ~constraint_constants () = + ~fee_payer_nonce ~memo ~receiver ~amount ~config_file () = let open Deferred.Let_syntax in let%map zkapp_command = transfer_funds ~debug ~sender ~sender_nonce ~fee ~fee_payer - ~fee_payer_nonce ~memo ~genesis_constants ~constraint_constants + ~fee_payer_nonce ~memo ~config_file ~receivers:(Deferred.return [ (receiver, amount) ]) in Util.print_snapp_transaction ~debug zkapp_command ; @@ -174,29 +168,23 @@ let transfer_funds_one_receiver = Param.flag "--receiver" ~doc:"PUBLIC_KEY the public key of the receiver" Param.(required public_key_compressed) + and config_file = Cli_lib.Flag.conf_file and amount = Flags.amount in let fee = Option.value ~default:Flags.default_fee fee in if Currency.Fee.(fee < Flags.min_fee) then failwithf "Fee must at least be %s" (Currency.Fee.to_mina_string Flags.min_fee) () ; - let constraint_constants = - Genesis_constants.Compiled.constraint_constants - in - let genesis_constants = Genesis_constants.Compiled.genesis_constants in create_command ~debug ~sender ~sender_nonce ~fee ~fee_payer - ~fee_payer_nonce ~memo ~receiver ~amount ~genesis_constants - ~constraint_constants )) + ~fee_payer_nonce ~memo ~receiver ~amount ~config_file )) let transfer_funds = let create_command ~debug ~sender ~sender_nonce ~fee ~fee_payer - ~fee_payer_nonce ~memo ~receivers ~genesis_constants ~constraint_constants - () = + ~fee_payer_nonce ~memo ~receivers ~config_file () = let open Deferred.Let_syntax in let%map zkapp_command = transfer_funds ~debug ~sender ~sender_nonce ~fee ~fee_payer - ~fee_payer_nonce ~memo ~receivers ~genesis_constants - ~constraint_constants + ~fee_payer_nonce ~memo ~receivers ~config_file in Util.print_snapp_transaction ~debug zkapp_command ; () @@ -257,7 +245,7 @@ let transfer_funds = and sender_nonce = Param.flag "--sender-nonce" ~doc:"NN Nonce of the sender account" Param.(required txn_nonce) - in + and config_file = Cli_lib.Flag.conf_file in let fee = Option.value ~default:Flags.default_fee fee in if Currency.Fee.(fee < Flags.min_fee) then failwithf "Fee must at least be %s" @@ -265,21 +253,16 @@ let transfer_funds = () ; let max_keys = 10 in let receivers = read_key_and_amount max_keys in - let constraint_constants = - Genesis_constants.Compiled.constraint_constants - in - let genesis_constants = Genesis_constants.Compiled.genesis_constants in create_command ~debug ~sender ~sender_nonce ~fee ~fee_payer - ~fee_payer_nonce ~memo ~receivers ~genesis_constants - ~constraint_constants )) + ~fee_payer_nonce ~memo ~receivers ~config_file )) let update_state = let create_command ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile ~app_state - ~genesis_constants ~constraint_constants () = + ~config_file () = let open Deferred.Let_syntax in let%map zkapp_command = update_state ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile ~app_state - ~genesis_constants ~constraint_constants + ~config_file in Util.print_snapp_transaction ~debug zkapp_command ; () @@ -299,26 +282,22 @@ let update_state = "String(hash)|Integer(field element) a list of 8 elements that \ represent the zkApp state (Use empty string for no-op)" Param.(listed string) - in + and config_file = Cli_lib.Flag.conf_file in let fee = Option.value ~default:Flags.default_fee fee in - let constraint_constants = - Genesis_constants.Compiled.constraint_constants - in - let genesis_constants = Genesis_constants.Compiled.genesis_constants in if Currency.Fee.(fee < Flags.min_fee) then failwith (sprintf "Fee must at least be %s" (Currency.Fee.to_mina_string Flags.min_fee) ) ; create_command ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile - ~app_state ~genesis_constants ~constraint_constants )) + ~app_state ~config_file )) let update_zkapp_uri = let create_command ~debug ~keyfile ~fee ~nonce ~memo ~snapp_keyfile ~zkapp_uri - ~auth ~genesis_constants ~constraint_constants () = + ~auth ~config_file () = let open Deferred.Let_syntax in let%map zkapp_command = update_zkapp_uri ~debug ~keyfile ~fee ~nonce ~memo ~snapp_keyfile - ~zkapp_uri ~auth ~genesis_constants ~constraint_constants + ~zkapp_uri ~auth ~config_file in Util.print_snapp_transaction ~debug zkapp_command ; () @@ -342,27 +321,23 @@ let update_zkapp_uri = "Proof|Signature|Either|None Current authorization in the account \ to change the zkApp URI" Param.(required string) - in + and config_file = Cli_lib.Flag.conf_file in let fee = Option.value ~default:Flags.default_fee fee in let auth = Util.auth_of_string auth in if Currency.Fee.(fee < Flags.min_fee) then failwith (sprintf "Fee must at least be %s" (Currency.Fee.to_mina_string Flags.min_fee) ) ; - let genesis_constants = Genesis_constants.Compiled.genesis_constants in - let constraint_constants = - Genesis_constants.Compiled.constraint_constants - in create_command ~debug ~keyfile ~fee ~nonce ~memo ~snapp_keyfile - ~zkapp_uri ~auth ~genesis_constants ~constraint_constants )) + ~zkapp_uri ~auth ~config_file )) let update_action_state = let create_command ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile - ~action_state ~genesis_constants ~constraint_constants () = + ~action_state ~config_file () = let open Deferred.Let_syntax in let%map zkapp_command = update_action_state ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile - ~action_state ~genesis_constants ~constraint_constants + ~action_state ~config_file in Util.print_snapp_transaction ~debug zkapp_command ; () @@ -404,31 +379,27 @@ let update_action_state = optional_with_default [] (Arg_type.comma_separated ~allow_empty:false ~strip_whitespace:true string )) - in + and config_file = Cli_lib.Flag.conf_file in let fee = Option.value ~default:Flags.default_fee fee in let action_state = List.filter_map ~f:(fun s -> if List.is_empty s then None else Some (Array.of_list s)) [ action_state0; action_state1; action_state2; action_state3 ] in - let genesis_constants = Genesis_constants.Compiled.genesis_constants in - let constraint_constants = - Genesis_constants.Compiled.constraint_constants - in if Currency.Fee.(fee < Flags.min_fee) then failwith (sprintf "Fee must at least be %s" (Currency.Fee.to_mina_string Flags.min_fee) ) ; create_command ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile - ~action_state ~genesis_constants ~constraint_constants )) + ~action_state ~config_file )) let update_token_symbol = let create_command ~debug ~keyfile ~fee ~nonce ~memo ~snapp_keyfile - ~token_symbol ~auth ~genesis_constants ~constraint_constants () = + ~token_symbol ~auth ~config_file () = let open Deferred.Let_syntax in let%map zkapp_command = update_token_symbol ~debug ~keyfile ~fee ~nonce ~memo ~snapp_keyfile - ~token_symbol ~auth ~genesis_constants ~constraint_constants + ~token_symbol ~auth ~config_file in Util.print_snapp_transaction ~debug zkapp_command ; () @@ -452,27 +423,23 @@ let update_token_symbol = "Proof|Signature|Either|None Current authorization in the account \ to change the token symbol" Param.(required string) - in + and config_file = Cli_lib.Flag.conf_file in let fee = Option.value ~default:Flags.default_fee fee in let auth = Util.auth_of_string auth in - let constraint_constants = - Genesis_constants.Compiled.constraint_constants - in - let genesis_constants = Genesis_constants.Compiled.genesis_constants in if Currency.Fee.(fee < Flags.min_fee) then failwith (sprintf "Fee must at least be %s" (Currency.Fee.to_mina_string Flags.min_fee) ) ; create_command ~debug ~keyfile ~fee ~nonce ~memo ~snapp_keyfile - ~token_symbol ~auth ~genesis_constants ~constraint_constants )) + ~token_symbol ~auth ~config_file )) let update_permissions = let create_command ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile - ~snapp_update ~current_auth ~genesis_constants ~constraint_constants () = + ~snapp_update ~current_auth ~config_file () = let open Deferred.Let_syntax in let%map zkapp_command = update_snapp ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile - ~snapp_update ~current_auth ~genesis_constants ~constraint_constants + ~snapp_update ~current_auth ~config_file in Util.print_snapp_transaction ~debug zkapp_command ; () @@ -533,7 +500,7 @@ let update_permissions = "Proof|Signature|Either|None Current authorization in the account \ to change permissions" Param.(required string) - in + and config_file = Cli_lib.Flag.conf_file in let fee = Option.value ~default:Flags.default_fee fee in let permissions : Permissions.t Zkapp_basic.Set_or_keep.t = Zkapp_basic.Set_or_keep.Set @@ -555,25 +522,21 @@ let update_permissions = } in let snapp_update = { Account_update.Update.dummy with permissions } in - let constraint_constants = - Genesis_constants.Compiled.constraint_constants - in - let genesis_constants = Genesis_constants.Compiled.genesis_constants in if Currency.Fee.(fee < Flags.min_fee) then failwith (sprintf "Fee must at least be %s" (Currency.Fee.to_mina_string Flags.min_fee) ) ; create_command ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile - ~genesis_constants ~constraint_constants ~snapp_update + ~config_file ~snapp_update ~current_auth:(Util.auth_of_string current_auth) )) let update_timings = let create_command ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile - ~snapp_update ~current_auth ~genesis_constants ~constraint_constants () = + ~snapp_update ~current_auth ~config_file () = let open Deferred.Let_syntax in let%map zkapp_command = update_snapp ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile - ~snapp_update ~current_auth ~genesis_constants ~constraint_constants + ~snapp_update ~current_auth ~config_file in Util.print_snapp_transaction ~debug zkapp_command ; () @@ -610,7 +573,7 @@ let update_timings = "Proof|Signature|Either|None Current authorization in the account \ to change permissions" Param.(required string) - in + and config_file = Cli_lib.Flag.conf_file in let fee = Option.value ~default:Flags.default_fee fee in let timing = Zkapp_basic.Set_or_keep.Set @@ -627,16 +590,12 @@ let update_timings = : Account_update.Update.Timing_info.value ) in let snapp_update = { Account_update.Update.dummy with timing } in - let constraint_constants = - Genesis_constants.Compiled.constraint_constants - in - let genesis_constants = Genesis_constants.Compiled.genesis_constants in if Currency.Fee.(fee < Flags.min_fee) then failwith (sprintf "Fee must at least be %s" (Currency.Fee.to_mina_string Flags.min_fee) ) ; create_command ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile - ~snapp_update ~genesis_constants ~constraint_constants + ~snapp_update ~config_file ~current_auth:(Util.auth_of_string current_auth) )) let test_zkapp_with_genesis_ledger = @@ -656,12 +615,7 @@ let test_zkapp_with_genesis_ledger = Param.flag "--zkapp-account-key" ~doc:"KEYFILE Private key file to create a new zkApp account" Param.(required string) - and config_file = - Param.flag "--config-file" ~aliases:[ "config-file" ] - ~doc: - "PATH path to a configuration file consisting the genesis ledger" - Param.(required string) - in + and config_file = Cli_lib.Flag.conf_file in test_zkapp_with_genesis_ledger_main keyfile zkapp_keyfile config_file )) let txn_commands = From d2005610f608d1c00a2ba4c5535c69af963e0078 Mon Sep 17 00:00:00 2001 From: martyall Date: Wed, 18 Sep 2024 14:42:05 -0700 Subject: [PATCH 22/29] cli args cannot be dependent on config values --- src/lib/cli_lib/flag.ml | 31 +++++++++---------------------- src/lib/cli_lib/flag.mli | 17 ++++------------- 2 files changed, 13 insertions(+), 35 deletions(-) diff --git a/src/lib/cli_lib/flag.ml b/src/lib/cli_lib/flag.ml index ab6651e4bfa..527cb51b334 100644 --- a/src/lib/cli_lib/flag.ml +++ b/src/lib/cli_lib/flag.ml @@ -348,32 +348,24 @@ end type signed_command_common = { sender : Signature_lib.Public_key.Compressed.t - ; fee : Currency.Fee.t + ; fee : Currency.Fee.t option ; nonce : Mina_base.Account.Nonce.t option ; memo : string option } -let fee_common ~default_transaction_fee ~minimum_user_command_fee : - Currency.Fee.t Command.Param.t = +let fee_common : Currency.Fee.t option Command.Param.t = Command.Param.flag "--fee" ~aliases:[ "fee" ] - ~doc: - (Printf.sprintf - "FEE Amount you are willing to pay to process the transaction \ - (default: %s) (minimum: %s)" - (Currency.Fee.to_mina_string default_transaction_fee) - (Currency.Fee.to_mina_string minimum_user_command_fee) ) - (Command.Param.optional_with_default default_transaction_fee - Arg_type.txn_fee ) - -let signed_command_common ~default_transaction_fee ~minimum_user_command_fee : - signed_command_common Command.Param.t = + ~doc:"FEE Amount you are willing to pay to process the transaction" + (Command.Param.optional Arg_type.txn_fee) + +let signed_command_common : signed_command_common Command.Param.t = let open Command.Let_syntax in let open Arg_type in let%map_open sender = flag "--sender" ~aliases:[ "sender" ] (required public_key_compressed) ~doc:"PUBLICKEY Public key from which you want to send the transaction" - and fee = fee_common ~default_transaction_fee ~minimum_user_command_fee + and fee = fee_common and nonce = flag "--nonce" ~aliases:[ "nonce" ] ~doc: @@ -406,15 +398,10 @@ module Signed_command = struct flag "--amount" ~aliases:[ "amount" ] ~doc:"VALUE Payment amount you want to send" (required txn_amount) - let fee ~default_transaction_fee ~minimum_user_command_fee = + let fee = let open Command.Param in flag "--fee" ~aliases:[ "fee" ] - ~doc: - (Printf.sprintf - "FEE Amount you are willing to pay to process the transaction \ - (default: %s) (minimum: %s)" - (Currency.Fee.to_mina_string default_transaction_fee) - (Currency.Fee.to_mina_string minimum_user_command_fee) ) + ~doc:"FEE Amount you are willing to pay to process the transaction" (optional txn_fee) let valid_until = diff --git a/src/lib/cli_lib/flag.mli b/src/lib/cli_lib/flag.mli index 25b2e2860ee..2f9e3eae0c9 100644 --- a/src/lib/cli_lib/flag.mli +++ b/src/lib/cli_lib/flag.mli @@ -83,20 +83,14 @@ end type signed_command_common = { sender : Signature_lib.Public_key.Compressed.t - ; fee : Currency.Fee.t + ; fee : Currency.Fee.t option ; nonce : Mina_base.Account.Nonce.t option ; memo : string option } -val fee_common : - default_transaction_fee:Currency.Fee.t - -> minimum_user_command_fee:Currency.Fee.t - -> Currency.Fee.t Command.Param.t +val fee_common : Currency.Fee.t option Command.Param.t -val signed_command_common : - default_transaction_fee:Currency.Fee.t - -> minimum_user_command_fee:Currency.Fee.t - -> signed_command_common Command.Param.t +val signed_command_common : signed_command_common Command.Param.t module Signed_command : sig val hd_index : Mina_numbers.Hd_index.t Command.Param.t @@ -105,10 +99,7 @@ module Signed_command : sig val amount : Currency.Amount.t Command.Param.t - val fee : - default_transaction_fee:Currency.Fee.t - -> minimum_user_command_fee:Currency.Fee.t - -> Currency.Fee.t option Command.Param.t + val fee : Currency.Fee.t option Command.Param.t val valid_until : Mina_numbers.Global_slot_since_genesis.t option Command.Param.t From 110c998b757ac8a3907b61201a92d350d416beb5 Mon Sep 17 00:00:00 2001 From: martyall Date: Wed, 18 Sep 2024 15:25:28 -0700 Subject: [PATCH 23/29] src/app/cli --- src/app/cli/src/init/client.ml | 263 ++++++++++-------- src/app/cli/src/init/itn.ml | 2 +- src/app/cli/src/init/mina_run.ml | 2 +- .../src/init/transaction_snark_profiler.ml | 94 ++++--- 4 files changed, 197 insertions(+), 164 deletions(-) diff --git a/src/app/cli/src/init/client.ml b/src/app/cli/src/init/client.ml index dc046388752..271f57067a8 100644 --- a/src/app/cli/src/init/client.ml +++ b/src/app/cli/src/init/client.ml @@ -513,21 +513,30 @@ let send_payment_graphql = flag "--amount" ~aliases:[ "amount" ] ~doc:"VALUE Payment amount you want to send" (required txn_amount) in - let genesis_constants = Genesis_constants.Compiled.genesis_constants in - let compile_config = Mina_compile_config.Compiled.t in + let config_file = Cli_lib.Flag.conf_file in let args = - Args.zip3 - (Cli_lib.Flag.signed_command_common - ~minimum_user_command_fee:genesis_constants.minimum_user_command_fee - ~default_transaction_fee:compile_config.default_transaction_fee ) - receiver_flag amount_flag + Args.zip4 Cli_lib.Flag.signed_command_common receiver_flag amount_flag + config_file in Command.async ~summary:"Send payment to an address" (Cli_lib.Background_daemon.graphql_init args ~f:(fun graphql_endpoint - ({ Cli_lib.Flag.sender; fee; nonce; memo }, receiver, amount) + ( { Cli_lib.Flag.sender; fee; nonce; memo } + , receiver + , amount + , config_file ) -> + let open Deferred.Let_syntax in + let%bind _, config = + let logger = Logger.create () in + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file + ~logger () + in + let fee = + Option.value ~default:config.compile_config.default_transaction_fee + fee + in let%map response = let input = Mina_graphql.Types.Input.SendPaymentInput.make_input ~to_:receiver @@ -548,21 +557,27 @@ let delegate_stake_graphql = ~doc:"PUBLICKEY Public key to which you want to delegate your stake" (required public_key_compressed) in - let genesis_constants = Genesis_constants.Compiled.genesis_constants in - let compile_config = Mina_compile_config.Compiled.t in + let config_file = Cli_lib.Flag.conf_file in let args = - Args.zip2 - (Cli_lib.Flag.signed_command_common - ~minimum_user_command_fee:genesis_constants.minimum_user_command_fee - ~default_transaction_fee:compile_config.default_transaction_fee ) - receiver_flag + Args.zip3 Cli_lib.Flag.signed_command_common receiver_flag config_file in + Command.async ~summary:"Delegate your stake to another public key" (Cli_lib.Background_daemon.graphql_init args ~f:(fun graphql_endpoint - ({ Cli_lib.Flag.sender; fee; nonce; memo }, receiver) + ({ Cli_lib.Flag.sender; fee; nonce; memo }, receiver, config_file) -> + let open Deferred.Let_syntax in + let%bind _, config = + let logger = Logger.create () in + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file + ~logger () + in + let fee = + Option.value ~default:config.compile_config.default_transaction_fee + fee + in let%map response = Graphql_client.query_exn Graphql_queries.Send_delegation.( @@ -818,15 +833,20 @@ let hash_ledger = flag "--ledger-file" ~doc:"LEDGER-FILE File containing an exported ledger" (required string)) + and config_file = Cli_lib.Flag.conf_file and plaintext = Cli_lib.Flag.plaintext in fun () -> - let constraint_constants = - Genesis_constants.Compiled.constraint_constants + let open Deferred.Let_syntax in + let%bind _, config = + let logger = Logger.create () in + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file + ~logger () in let process_accounts accounts = let packed_ledger = Genesis_ledger_helper.Ledger.packed_genesis_ledger_of_accounts - ~depth:constraint_constants.ledger_depth accounts + ~depth:config.constraint_config.constraint_constants.ledger_depth + accounts in let ledger = Lazy.force @@ Genesis_ledger.Packed.t packed_ledger in Format.printf "%s@." @@ -846,7 +866,11 @@ let hash_ledger = process_accounts accounts ) else let json = Yojson.Safe.from_file ledger_file in - match Runtime_config.Accounts.of_yojson json with + match + Result.( + Runtime_config.Json_layout.Accounts.of_yojson json + >>= Runtime_config.Accounts.of_json_layout) + with | Ok runtime_accounts -> let accounts = lazy (Genesis_ledger_helper.Accounts.to_full runtime_accounts) @@ -909,7 +933,11 @@ let currency_in_ledger = process_accounts accounts ) else let json = Yojson.Safe.from_file ledger_file in - match Runtime_config.Accounts.of_yojson json with + match + Result.( + Runtime_config.Json_layout.Accounts.of_yojson json + >>= Runtime_config.Accounts.of_json_layout) + with | Ok runtime_accounts -> let accounts = Genesis_ledger_helper.Accounts.to_full runtime_accounts @@ -922,22 +950,29 @@ let currency_in_ledger = ignore (exit 1 : 'a Deferred.t) ) let constraint_system_digests = + let open Command.Let_syntax in Command.async ~summary:"Print MD5 digest of each SNARK constraint" - (Command.Param.return (fun () -> - let constraint_constants = - Genesis_constants.Compiled.constraint_constants - in - let proof_level = Genesis_constants.Compiled.proof_level in - let all = - Transaction_snark.constraint_system_digests ~constraint_constants () - @ Blockchain_snark.Blockchain_snark_state.constraint_system_digests - ~proof_level ~constraint_constants () - in - let all = - List.sort ~compare:(fun (k1, _) (k2, _) -> String.compare k1 k2) all - in - List.iter all ~f:(fun (k, v) -> printf "%s\t%s\n" k (Md5.to_hex v)) ; - Deferred.unit ) ) + (let%map_open config_file = Cli_lib.Flag.conf_file in + fun () -> + let open Deferred.Let_syntax in + let%bind _, config = + let logger = Logger.create () in + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file + ~logger () + in + let { Runtime_config.Constraint.constraint_constants; proof_level } = + config.constraint_config + in + let all = + Transaction_snark.constraint_system_digests ~constraint_constants () + @ Blockchain_snark.Blockchain_snark_state.constraint_system_digests + ~proof_level ~constraint_constants () + in + let all = + List.sort ~compare:(fun (k1, _) (k2, _) -> String.compare k1 k2) all + in + List.iter all ~f:(fun (k, v) -> printf "%s\t%s\n" k (Md5.to_hex v)) ; + Deferred.unit ) let snark_job_list = let open Deferred.Let_syntax in @@ -1791,76 +1826,53 @@ let add_peers_graphql = } ) ) ) ) let compile_time_constants = - let genesis_constants = Genesis_constants.Compiled.genesis_constants in - let constraint_constants = Genesis_constants.Compiled.constraint_constants in - let proof_level = Genesis_constants.Compiled.proof_level in + let open Command.Let_syntax in Command.async ~summary:"Print a JSON map of the compile-time consensus parameters" - (Command.Param.return (fun () -> - let home = Core.Sys.home_directory () in - let conf_dir = home ^/ Cli_lib.Default.conf_dir_name in - let genesis_dir = - let home = Core.Sys.home_directory () in - home ^/ Cli_lib.Default.conf_dir_name - in - let config_file = - match Sys.getenv "MINA_CONFIG_FILE" with - | Some config_file -> - config_file - | None -> - conf_dir ^/ "daemon.json" - in - let open Async in - let%map ({ consensus_constants; _ } as precomputed_values), _ = - config_file |> Genesis_ledger_helper.load_config_json >>| Or_error.ok - >>| Option.value - ~default: - (`Assoc [ ("ledger", `Assoc [ ("accounts", `List []) ]) ]) - >>| Runtime_config.of_yojson >>| Result.ok - >>| Option.value ~default:Runtime_config.default - >>= Genesis_ledger_helper.init_from_config_file ~genesis_constants - ~constraint_constants ~logger:(Logger.null ()) ~proof_level - ~cli_proof_level:None ~genesis_dir - >>| Or_error.ok_exn - in - let all_constants = - `Assoc - [ ( "genesis_state_timestamp" - , `String - ( Block_time.to_time_exn - consensus_constants.genesis_state_timestamp - |> Core.Time.to_string_iso8601_basic ~zone:Core.Time.Zone.utc - ) ) - ; ("k", `Int (Unsigned.UInt32.to_int consensus_constants.k)) - ; ( "coinbase" - , `String - (Currency.Amount.to_mina_string - precomputed_values.constraint_constants.coinbase_amount ) - ) - ; ( "block_window_duration_ms" - , `Int - precomputed_values.constraint_constants - .block_window_duration_ms ) - ; ("delta", `Int (Unsigned.UInt32.to_int consensus_constants.delta)) - ; ( "sub_windows_per_window" - , `Int - (Unsigned.UInt32.to_int - consensus_constants.sub_windows_per_window ) ) - ; ( "slots_per_sub_window" - , `Int - (Unsigned.UInt32.to_int - consensus_constants.slots_per_sub_window ) ) - ; ( "slots_per_window" - , `Int - (Unsigned.UInt32.to_int consensus_constants.slots_per_window) - ) - ; ( "slots_per_epoch" - , `Int - (Unsigned.UInt32.to_int consensus_constants.slots_per_epoch) - ) - ] - in - Core_kernel.printf "%s\n%!" (Yojson.Safe.to_string all_constants) ) ) + (let%map_open config_file = Cli_lib.Flag.conf_file in + fun () -> + let open Deferred.Let_syntax in + let%map ({ consensus_constants; _ } as precomputed_values), _ = + let logger = Logger.create () in + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file + ~logger () + in + let all_constants = + `Assoc + [ ( "genesis_state_timestamp" + , `String + ( Block_time.to_time_exn + consensus_constants.genesis_state_timestamp + |> Core.Time.to_string_iso8601_basic ~zone:Core.Time.Zone.utc + ) ) + ; ("k", `Int (Unsigned.UInt32.to_int consensus_constants.k)) + ; ( "coinbase" + , `String + (Currency.Amount.to_mina_string + precomputed_values.constraint_constants.coinbase_amount ) ) + ; ( "block_window_duration_ms" + , `Int + precomputed_values.constraint_constants + .block_window_duration_ms ) + ; ("delta", `Int (Unsigned.UInt32.to_int consensus_constants.delta)) + ; ( "sub_windows_per_window" + , `Int + (Unsigned.UInt32.to_int + consensus_constants.sub_windows_per_window ) ) + ; ( "slots_per_sub_window" + , `Int + (Unsigned.UInt32.to_int + consensus_constants.slots_per_sub_window ) ) + ; ( "slots_per_window" + , `Int + (Unsigned.UInt32.to_int consensus_constants.slots_per_window) + ) + ; ( "slots_per_epoch" + , `Int (Unsigned.UInt32.to_int consensus_constants.slots_per_epoch) + ) + ] + in + Core_kernel.printf "%s\n%!" (Yojson.Safe.to_string all_constants) ) let node_status = let open Command.Param in @@ -2304,26 +2316,30 @@ let test_ledger_application = flag "--has-second-partition" ~doc:"Assume there is a second partition (scan state)" no_arg and tracing = flag "--tracing" ~doc:"Wrap test into tracing" no_arg + and config_file = Cli_lib.Flag.conf_file and no_masks = flag "--no-masks" ~doc:"Do not create masks" no_arg in Cli_lib.Exceptions.handle_nicely @@ fun () -> + let open Deferred.Let_syntax in + let%bind _, config = + let logger = Logger.create () in + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger + () + in let first_partition_slots = Option.value ~default:128 first_partition_slots in let num_txs_per_round = Option.value ~default:3 num_txs_per_round in let rounds = Option.value ~default:580 rounds in let max_depth = Option.value ~default:290 max_depth in - let constraint_constants = - Genesis_constants.Compiled.constraint_constants - in - let genesis_constants = Genesis_constants.Compiled.genesis_constants in + let constraint_constants = config.constraint_config.constraint_constants in + let genesis_constants = config.genesis_constants in Test_ledger_application.test ~privkey_path ~ledger_path ?prev_block_path ~first_partition_slots ~no_new_stack ~has_second_partition ~num_txs_per_round ~rounds ~no_masks ~max_depth ~tracing num_txs ~constraint_constants ~genesis_constants ) let itn_create_accounts = - let compile_config = Mina_compile_config.Compiled.t in Command.async ~summary:"Fund new accounts for incentivized testnet" (let open Command.Param in let privkey_path = Cli_lib.Flag.privkey_read_path in @@ -2334,10 +2350,7 @@ let itn_create_accounts = flag "--num-accounts" ~doc:"NN Number of new accounts" (required int) in let fee = - flag "--fee" - ~doc: - (sprintf "NN Fee in nanomina paid to create an account (minimum: %s)" - (Currency.Fee.to_string compile_config.minimum_user_command_fee) ) + flag "--fee" ~doc:"NN Fee in nanomina paid to create an account" (required int) in let amount = @@ -2345,13 +2358,27 @@ let itn_create_accounts = ~doc:"NN Amount in nanomina to be divided among new accounts" (required int) in - let args = Args.zip5 privkey_path key_prefix num_accounts fee amount in - let genesis_constants = Genesis_constants.Compiled.genesis_constants in - let constraint_constants = - Genesis_constants.Compiled.constraint_constants + let config_file = Cli_lib.Flag.conf_file in + let args = + Args.zip6 privkey_path key_prefix num_accounts fee amount config_file in Cli_lib.Background_daemon.rpc_init args - ~f:(Itn.create_accounts ~genesis_constants ~constraint_constants)) + ~f:(fun + port + (privkey_path, key_prefix, num_accounts, fee, amount, config_file) + -> + let open Deferred.Let_syntax in + let%bind _, config = + let logger = Logger.create () in + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file + ~logger () + in + let args' = (privkey_path, key_prefix, num_accounts, fee, amount) in + let genesis_constants = config.genesis_constants in + let constraint_constants = + config.constraint_config.constraint_constants + in + Itn.create_accounts ~genesis_constants ~constraint_constants ~port args' )) module Visualization = struct let create_command (type rpc_response) ~name ~f diff --git a/src/app/cli/src/init/itn.ml b/src/app/cli/src/init/itn.ml index d02c987f0b0..8d947c9cd6c 100644 --- a/src/app/cli/src/init/itn.ml +++ b/src/app/cli/src/init/itn.ml @@ -7,7 +7,7 @@ open Mina_base open Mina_transaction let create_accounts ~(genesis_constants : Genesis_constants.t) - ~(constraint_constants : Genesis_constants.Constraint_constants.t) port + ~(constraint_constants : Genesis_constants.Constraint_constants.t) ~port (privkey_path, key_prefix, num_accounts, fee, amount) = let keys_per_zkapp = 8 in let zkapps_per_block = 10 in diff --git a/src/app/cli/src/init/mina_run.ml b/src/app/cli/src/init/mina_run.ml index 62063088c4a..677ca0c724f 100644 --- a/src/app/cli/src/init/mina_run.ml +++ b/src/app/cli/src/init/mina_run.ml @@ -212,7 +212,7 @@ let make_report exn_json ~conf_dir ~top_logger coda_ref = let setup_local_server ?(client_trustlist = []) ?rest_server_port ?limited_graphql_port ?itn_graphql_port ?auth_keys ?(open_limited_graphql_port = false) ?(insecure_rest_server = false) mina = - let compile_config = (Mina_lib.config mina).compile_config in + let compile_config = (Mina_lib.config mina).runtime_config.compile_config in let client_trustlist = ref (Unix.Cidr.Set.of_list diff --git a/src/app/cli/src/init/transaction_snark_profiler.ml b/src/app/cli/src/init/transaction_snark_profiler.ml index ef4e26d284b..fbfc2ae6500 100644 --- a/src/app/cli/src/init/transaction_snark_profiler.ml +++ b/src/app/cli/src/init/transaction_snark_profiler.ml @@ -1,5 +1,6 @@ open Core open Snark_profiler_lib +open Async let name = "transaction-snark-profiler" @@ -102,7 +103,7 @@ let main ~(genesis_constants : Genesis_constants.t) let command = let open Command.Let_syntax in - Command.basic ~summary:"transaction snark profiler" + Command.async ~summary:"transaction snark profiler" (let%map_open n = flag "--k" ~aliases:[ "-k" ] ~doc: @@ -145,47 +146,52 @@ let command = "Minimum number of account updates per transaction (excluding the \ fee payer). Minimum: 1 Default: 1 " (optional int) - in - let num_transactions = - Option.map n ~f:(fun n -> `Count (Int.pow 2 n)) - |> Option.value ~default:`Two_from_same - in - let max_num_updates = Option.value max_num_updates ~default:6 in - Option.value_map ~default:() min_num_updates ~f:(fun m -> - if m > max_num_updates then - failwith - "min-num-updates should be less than or equal to max-num-updates" ) ; - if use_zkapps then ( - let incompatible_flags = ref [] in - let add_incompatible_flag flag = - incompatible_flags := flag :: !incompatible_flags + and config_file = Cli_lib.Flag.conf_file in + fun () -> + let open Deferred.Let_syntax in + let logger = Logger.create () in + let%map _, config = + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file + ~logger ~cli_proof_level:Full () in - ( match preeval with - | None -> - () - | Some b -> - if b then add_incompatible_flag "--preeval true" ) ; - if check_only then add_incompatible_flag "--check-only" ; - if witness_only then add_incompatible_flag "--witness-only" ; - if not @@ List.is_empty !incompatible_flags then ( - eprintf "These flags are incompatible with --zkapps: %s\n" - (String.concat !incompatible_flags ~sep:", ") ; - exit 1 ) ) ; - let repeats = Option.value repeats ~default:1 in - let genesis_constants = Genesis_constants.Compiled.genesis_constants in - let constraint_constants = - Genesis_constants.Compiled.constraint_constants - in - let proof_level = Genesis_constants.Proof_level.Full in - if witness_only then - witness ~genesis_constants ~constraint_constants ~proof_level - ~max_num_updates ?min_num_updates num_transactions repeats preeval - use_zkapps - else if check_only then - dry ~genesis_constants ~constraint_constants ~proof_level - ~max_num_updates ?min_num_updates num_transactions repeats preeval - use_zkapps - else - main ~genesis_constants ~constraint_constants ~proof_level - ~max_num_updates ?min_num_updates num_transactions repeats preeval - use_zkapps ) + let num_transactions = + Option.map n ~f:(fun n -> `Count (Int.pow 2 n)) + |> Option.value ~default:`Two_from_same + in + let max_num_updates = Option.value max_num_updates ~default:6 in + Option.value_map ~default:() min_num_updates ~f:(fun m -> + if m > max_num_updates then + failwith + "min-num-updates should be less than or equal to max-num-updates" ) ; + if use_zkapps then ( + let incompatible_flags = ref [] in + let add_incompatible_flag flag = + incompatible_flags := flag :: !incompatible_flags + in + ( match preeval with + | None -> + () + | Some b -> + if b then add_incompatible_flag "--preeval true" ) ; + if check_only then add_incompatible_flag "--check-only" ; + if witness_only then add_incompatible_flag "--witness-only" ; + if not @@ List.is_empty !incompatible_flags then + eprintf "These flags are incompatible with --zkapps: %s\n" + (String.concat !incompatible_flags ~sep:", ") ) ; + let repeats = Option.value repeats ~default:1 in + let { Runtime_config.Constraint.constraint_constants; proof_level } = + config.constraint_config + in + let genesis_constants = config.genesis_constants in + if witness_only then + witness ~genesis_constants ~constraint_constants ~proof_level + ~max_num_updates ?min_num_updates num_transactions repeats preeval + use_zkapps () + else if check_only then + dry ~genesis_constants ~constraint_constants ~proof_level + ~max_num_updates ?min_num_updates num_transactions repeats preeval + use_zkapps () + else + main ~genesis_constants ~constraint_constants ~proof_level + ~max_num_updates ?min_num_updates num_transactions repeats preeval + use_zkapps () ) From 500ac2007e6042d5229ef1a8f9c5b52eccd337af Mon Sep 17 00:00:00 2001 From: martyall Date: Wed, 18 Sep 2024 15:32:47 -0700 Subject: [PATCH 24/29] heap_usage --- src/app/heap_usage/heap_usage.ml | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/app/heap_usage/heap_usage.ml b/src/app/heap_usage/heap_usage.ml index 5fa54b3f535..e734f9ad4fa 100644 --- a/src/app/heap_usage/heap_usage.ml +++ b/src/app/heap_usage/heap_usage.ml @@ -43,10 +43,20 @@ let main ~genesis_constants ~constraint_constants () = Async.return () let () = - let genesis_constants = Genesis_constants.Compiled.genesis_constants in - let constraint_constants = Genesis_constants.Compiled.constraint_constants in - Command.( - run - (async ~summary:"Print heap usage of selected Mina data structures" - (let%map.Command () = Let_syntax.return () in - main ~genesis_constants ~constraint_constants ) )) + Command.run + @@ + let open Command.Let_syntax in + Command.async ~summary:"Print heap usage of selected Mina data structures" + (let%map_open config_file = Cli_lib.Flag.conf_file in + fun () -> + let open Deferred.Let_syntax in + let logger = Logger.create () in + let%bind _, config = + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file + ~logger () + in + let genesis_constants = config.genesis_constants in + let constraint_constants = + config.constraint_config.constraint_constants + in + main ~genesis_constants ~constraint_constants () ) From a01eeb2403671acf3ac7901c1183a11c0decea9c Mon Sep 17 00:00:00 2001 From: martyall Date: Wed, 18 Sep 2024 15:44:29 -0700 Subject: [PATCH 25/29] rosetta --- src/app/rosetta/lib/dune | 1 + src/app/rosetta/lib/rosetta.ml | 14 ++++++++++++-- src/app/rosetta/rosetta.ml | 6 +----- src/app/rosetta/rosetta_mainnet_signatures.ml | 6 +----- src/app/rosetta/rosetta_testnet_signatures.ml | 6 +----- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/app/rosetta/lib/dune b/src/app/rosetta/lib/dune index 9c6bf25cd02..aa5e33e0bd8 100644 --- a/src/app/rosetta/lib/dune +++ b/src/app/rosetta/lib/dune @@ -52,6 +52,7 @@ mina_numbers mina_transaction mina_version + cli_lib ) (preprocessor_deps ../../../graphql-ppx-config.inc diff --git a/src/app/rosetta/lib/rosetta.ml b/src/app/rosetta/lib/rosetta.ml index f315b6e1e81..524f506a03d 100644 --- a/src/app/rosetta/lib/rosetta.ml +++ b/src/app/rosetta/lib/rosetta.ml @@ -153,7 +153,7 @@ let server_handler ~pool ~graphql_uri ~logger ~minimum_user_command_fee [%log warn] ~metadata "Error response: $error" ; respond_500 error -let command ~minimum_user_command_fee ~account_creation_fee = +let command = let open Command.Let_syntax in let%map_open archive_uri = flag "--archive-uri" ~aliases:[ "archive-uri" ] @@ -171,11 +171,21 @@ let command ~minimum_user_command_fee ~account_creation_fee = and port = flag "--port" ~aliases:[ "port" ] ~doc:"Port to expose Rosetta server" (required int) - in + and config_file = Cli_lib.Flag.conf_file in let open Deferred.Let_syntax in fun () -> let logger = Logger.create () in Cli.logger_setup log_json log_level ; + let%bind _, config = + Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger + () + in + let account_creation_fee = + config.constraint_config.constraint_constants.account_creation_fee + in + let minimum_user_command_fee = + config.genesis_constants.minimum_user_command_fee + in let pool = lazy (let open Deferred.Result.Let_syntax in diff --git a/src/app/rosetta/rosetta.ml b/src/app/rosetta/rosetta.ml index 410201c7039..b7a558d7145 100644 --- a/src/app/rosetta/rosetta.ml +++ b/src/app/rosetta/rosetta.ml @@ -2,9 +2,5 @@ open Lib.Rosetta open Async let () = - let genesis_constants = Genesis_constants.Compiled.genesis_constants in - let constraint_constants = Genesis_constants.Compiled.constraint_constants in Command.run - (Command.async ~summary:"Run Rosetta process on top of Mina" - (command ~account_creation_fee:constraint_constants.account_creation_fee - ~minimum_user_command_fee:genesis_constants.minimum_user_command_fee ) ) + (Command.async ~summary:"Run Rosetta process on top of Mina" command) diff --git a/src/app/rosetta/rosetta_mainnet_signatures.ml b/src/app/rosetta/rosetta_mainnet_signatures.ml index 410201c7039..b7a558d7145 100644 --- a/src/app/rosetta/rosetta_mainnet_signatures.ml +++ b/src/app/rosetta/rosetta_mainnet_signatures.ml @@ -2,9 +2,5 @@ open Lib.Rosetta open Async let () = - let genesis_constants = Genesis_constants.Compiled.genesis_constants in - let constraint_constants = Genesis_constants.Compiled.constraint_constants in Command.run - (Command.async ~summary:"Run Rosetta process on top of Mina" - (command ~account_creation_fee:constraint_constants.account_creation_fee - ~minimum_user_command_fee:genesis_constants.minimum_user_command_fee ) ) + (Command.async ~summary:"Run Rosetta process on top of Mina" command) diff --git a/src/app/rosetta/rosetta_testnet_signatures.ml b/src/app/rosetta/rosetta_testnet_signatures.ml index 410201c7039..b7a558d7145 100644 --- a/src/app/rosetta/rosetta_testnet_signatures.ml +++ b/src/app/rosetta/rosetta_testnet_signatures.ml @@ -2,9 +2,5 @@ open Lib.Rosetta open Async let () = - let genesis_constants = Genesis_constants.Compiled.genesis_constants in - let constraint_constants = Genesis_constants.Compiled.constraint_constants in Command.run - (Command.async ~summary:"Run Rosetta process on top of Mina" - (command ~account_creation_fee:constraint_constants.account_creation_fee - ~minimum_user_command_fee:genesis_constants.minimum_user_command_fee ) ) + (Command.async ~summary:"Run Rosetta process on top of Mina" command) From 60e62ef88156aff225d6a8ce68e5fd87a1d512ff Mon Sep 17 00:00:00 2001 From: martyall Date: Thu, 19 Sep 2024 10:49:03 -0700 Subject: [PATCH 26/29] break up config loading into json-file-reading+pure-transformations and initialization (which includes ledger manipulation and doesn't even apply most of the time)' --- src/app/archive/cli/archive_cli.ml | 7 +- src/app/archive_blocks/archive_blocks.ml | 5 +- src/app/batch_txn_tool/batch_txn_tool.ml | 21 +-- src/app/batch_txn_tool/dune | 1 + src/app/cli/src/init/client.ml | 43 ++--- .../src/init/transaction_snark_profiler.ml | 7 +- .../delegation_verify/delegation_verify.ml | 24 ++- src/app/heap_usage/heap_usage.ml | 6 +- src/app/replayer/replayer.ml | 4 +- src/app/rosetta/lib/rosetta.ml | 5 +- .../runtime_genesis_ledger.ml | 4 +- .../snark_work_debugger.ml | 6 +- src/app/zkapp_limits/zkapp_limits.ml | 6 +- .../zkapp_test_transaction/lib/commands.ml | 45 ++--- src/lib/cli_lib/commands.ml | 18 +- .../genesis_ledger_helper.ml | 100 +++-------- src/lib/mina_lib/tests/tests.ml | 8 +- src/lib/runtime_config/runtime_config.ml | 157 +++++++++--------- .../standalone/run_snark_worker.ml | 11 +- 19 files changed, 192 insertions(+), 286 deletions(-) diff --git a/src/app/archive/cli/archive_cli.ml b/src/app/archive/cli/archive_cli.ml index c72f577248c..d7259047b29 100644 --- a/src/app/archive/cli/archive_cli.ml +++ b/src/app/archive/cli/archive_cli.ml @@ -43,8 +43,11 @@ let command_run = let logger = Logger.create () in let open Deferred.Let_syntax in let%bind precomputed_values, _ = - Genesis_ledger_helper.Config_loader.load_config_exn ~logger - ~config_file () + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file () + in + Deferred.Or_error.ok_exn + @@ Genesis_ledger_helper.Config_initializer.initialize ~logger config in Stdout_log.setup log_json log_level ; [%log info] "Starting archive process; built with commit $commit" diff --git a/src/app/archive_blocks/archive_blocks.ml b/src/app/archive_blocks/archive_blocks.ml index 48f32743630..75bebe0b0cd 100644 --- a/src/app/archive_blocks/archive_blocks.ml +++ b/src/app/archive_blocks/archive_blocks.ml @@ -6,9 +6,8 @@ open Archive_lib let main ~config_file ~archive_uri ~precomputed ~extensional ~success_file ~failure_file ~log_successes ~files () = - let logger = Logger.create () in - let%bind _, config = - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger () + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file () in let genesis_constants = config.genesis_constants in let constraint_constants = config.constraint_config.constraint_constants in diff --git a/src/app/batch_txn_tool/batch_txn_tool.ml b/src/app/batch_txn_tool/batch_txn_tool.ml index 79741438d56..817ebd10de6 100644 --- a/src/app/batch_txn_tool/batch_txn_tool.ml +++ b/src/app/batch_txn_tool/batch_txn_tool.ml @@ -154,11 +154,18 @@ let there_and_back_again ~num_txn_per_acct ~txns_per_block ~slot_time ~fill_rate ~origin_sender_secret_key_path ~(origin_sender_secret_key_pw_option : string option) ~returner_secret_key_path ~(returner_secret_key_pw_option : string option) - ~graphql_target_node_option ~minimum_user_command_fee () = + ~graphql_target_node_option ~minimum_user_command_fee_opt ~config_file () = let open Deferred.Let_syntax in (* define the rate limiting function *) let open Logger in let logger = Logger.create () in + let%bind minimum_user_command_fee = + let%map config = + Runtime_config.Config_loader.load_config_exn ~config_file () + in + Option.value ~default:config.genesis_constants.minimum_user_command_fee + minimum_user_command_fee_opt + in let limit_level = let slot_limit = Float.( @@ -310,8 +317,6 @@ let there_and_back_again ~num_txn_per_acct ~txns_per_block ~slot_time ~fill_rate return () let output_there_and_back_cmds = - let genesis_constants = Genesis_constants.Compiled.genesis_constants in - let compile_config = Mina_compile_config.Compiled.t in let open Command.Let_syntax in Command.async ~summary: @@ -390,23 +395,19 @@ let output_there_and_back_cmds = transactions, if this is not present then we use the env var \ MINA_PRIVKEY_PASS" (optional string) + and config_file = Cli_lib.Flag.conf_file and graphql_target_node_option = flag "--graphql-target-node" ~aliases:[ "graphql-target-node" ] ~doc: "URL The graphql node to send graphl commands to. must be in \ format `:`. default is `127.0.0.1:3085`" (optional string) - and minimum_user_command_fee = - let default = compile_config.default_transaction_fee in - Cli_lib.Flag.fee_common - ~minimum_user_command_fee:genesis_constants.minimum_user_command_fee - ~default_transaction_fee:default - in + and minimum_user_command_fee_opt = Cli_lib.Flag.fee_common in there_and_back_again ~num_txn_per_acct ~txns_per_block ~txn_fee_option ~slot_time ~fill_rate ~rate_limit ~rate_limit_level ~rate_limit_interval ~origin_sender_secret_key_path ~origin_sender_secret_key_pw_option ~returner_secret_key_path ~returner_secret_key_pw_option - ~graphql_target_node_option ~minimum_user_command_fee ) + ~graphql_target_node_option ~minimum_user_command_fee_opt ~config_file ) let () = Command.run diff --git a/src/app/batch_txn_tool/dune b/src/app/batch_txn_tool/dune index f55ebfdf875..7e4ac24e7a5 100644 --- a/src/app/batch_txn_tool/dune +++ b/src/app/batch_txn_tool/dune @@ -27,6 +27,7 @@ integration_test_lib logger bounded_types + runtime_config ) (instrumentation (backend bisect_ppx)) (preprocessor_deps ../../../graphql_schema.json) diff --git a/src/app/cli/src/init/client.ml b/src/app/cli/src/init/client.ml index 271f57067a8..2403247fb80 100644 --- a/src/app/cli/src/init/client.ml +++ b/src/app/cli/src/init/client.ml @@ -528,10 +528,8 @@ let send_payment_graphql = , config_file ) -> let open Deferred.Let_syntax in - let%bind _, config = - let logger = Logger.create () in - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file - ~logger () + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file () in let fee = Option.value ~default:config.compile_config.default_transaction_fee @@ -569,10 +567,8 @@ let delegate_stake_graphql = ({ Cli_lib.Flag.sender; fee; nonce; memo }, receiver, config_file) -> let open Deferred.Let_syntax in - let%bind _, config = - let logger = Logger.create () in - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file - ~logger () + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file () in let fee = Option.value ~default:config.compile_config.default_transaction_fee @@ -837,10 +833,8 @@ let hash_ledger = and plaintext = Cli_lib.Flag.plaintext in fun () -> let open Deferred.Let_syntax in - let%bind _, config = - let logger = Logger.create () in - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file - ~logger () + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file () in let process_accounts accounts = let packed_ledger = @@ -955,10 +949,8 @@ let constraint_system_digests = (let%map_open config_file = Cli_lib.Flag.conf_file in fun () -> let open Deferred.Let_syntax in - let%bind _, config = - let logger = Logger.create () in - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file - ~logger () + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file () in let { Runtime_config.Constraint.constraint_constants; proof_level } = config.constraint_config @@ -1834,8 +1826,11 @@ let compile_time_constants = let open Deferred.Let_syntax in let%map ({ consensus_constants; _ } as precomputed_values), _ = let logger = Logger.create () in - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file - ~logger () + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file () + in + Deferred.Or_error.ok_exn + @@ Genesis_ledger_helper.Config_initializer.initialize ~logger config in let all_constants = `Assoc @@ -2321,10 +2316,8 @@ let test_ledger_application = Cli_lib.Exceptions.handle_nicely @@ fun () -> let open Deferred.Let_syntax in - let%bind _, config = - let logger = Logger.create () in - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger - () + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file () in let first_partition_slots = Option.value ~default:128 first_partition_slots @@ -2368,10 +2361,8 @@ let itn_create_accounts = (privkey_path, key_prefix, num_accounts, fee, amount, config_file) -> let open Deferred.Let_syntax in - let%bind _, config = - let logger = Logger.create () in - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file - ~logger () + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file () in let args' = (privkey_path, key_prefix, num_accounts, fee, amount) in let genesis_constants = config.genesis_constants in diff --git a/src/app/cli/src/init/transaction_snark_profiler.ml b/src/app/cli/src/init/transaction_snark_profiler.ml index fbfc2ae6500..493b523e17d 100644 --- a/src/app/cli/src/init/transaction_snark_profiler.ml +++ b/src/app/cli/src/init/transaction_snark_profiler.ml @@ -149,10 +149,9 @@ let command = and config_file = Cli_lib.Flag.conf_file in fun () -> let open Deferred.Let_syntax in - let logger = Logger.create () in - let%map _, config = - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file - ~logger ~cli_proof_level:Full () + let%map config = + Runtime_config.Config_loader.load_config_exn ~config_file + ~cli_proof_level:Full () in let num_transactions = Option.map n ~f:(fun n -> `Count (Int.pow 2 n)) diff --git a/src/app/delegation_verify/delegation_verify.ml b/src/app/delegation_verify/delegation_verify.ml index b22a5f91339..fe2a9089dfa 100644 --- a/src/app/delegation_verify/delegation_verify.ml +++ b/src/app/delegation_verify/delegation_verify.ml @@ -43,15 +43,16 @@ let timestamp = anon ("timestamp" %: string) (*We use the cli_proof_level arg to overide the config settings *) -let instantiate_verify_functions ~logger ~config_file = - let%map.Deferred precomputed_values, _ = - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger - ~cli_proof_level:Full () +let instantiate_verify_functions ~config_file = + let open Deferred.Let_syntax in + let%map config = + Runtime_config.Config_loader.load_config_exn ~cli_proof_level:Full + ~config_file () in - let constraint_constants = - Precomputed_values.constraint_constants precomputed_values + let { Runtime_config.Constraint.constraint_constants; proof_level } = + config.constraint_config in - Verifier.verify_functions ~constraint_constants ~proof_level:Full () + Verifier.verify_functions ~constraint_constants ~proof_level () module Make_verifier (Source : Submission.Data_source) = struct let verify_transaction_snarks = Source.verify_transaction_snarks @@ -130,9 +131,8 @@ let filesystem_command = and no_checks = no_checks_flag and config_file = config_flag in fun () -> - let logger = Logger.create () in let%bind.Deferred verify_blockchain_snarks, verify_transaction_snarks = - instantiate_verify_functions ~logger ~config_file + instantiate_verify_functions ~config_file in let submission_paths = get_filenames inputs in @@ -164,9 +164,8 @@ let cassandra_command = and period_end = timestamp in fun () -> let open Deferred.Let_syntax in - let logger = Logger.create () in let%bind.Deferred verify_blockchain_snarks, verify_transaction_snarks = - instantiate_verify_functions ~logger ~config_file + instantiate_verify_functions ~config_file in let module V = Make_verifier (struct include Submission.Cassandra @@ -196,9 +195,8 @@ let stdin_command = let%map_open config_file = config_flag and no_checks = no_checks_flag in fun () -> let open Deferred.Let_syntax in - let logger = Logger.create () in let%bind.Deferred verify_blockchain_snarks, verify_transaction_snarks = - instantiate_verify_functions ~logger ~config_file + instantiate_verify_functions ~config_file in let module V = Make_verifier (struct include Submission.Stdin diff --git a/src/app/heap_usage/heap_usage.ml b/src/app/heap_usage/heap_usage.ml index e734f9ad4fa..08f45adb626 100644 --- a/src/app/heap_usage/heap_usage.ml +++ b/src/app/heap_usage/heap_usage.ml @@ -50,10 +50,8 @@ let () = (let%map_open config_file = Cli_lib.Flag.conf_file in fun () -> let open Deferred.Let_syntax in - let logger = Logger.create () in - let%bind _, config = - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file - ~logger () + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file () in let genesis_constants = config.genesis_constants in let constraint_constants = diff --git a/src/app/replayer/replayer.ml b/src/app/replayer/replayer.ml index 5620cd5f036..49f93fc75d5 100644 --- a/src/app/replayer/replayer.ml +++ b/src/app/replayer/replayer.ml @@ -639,8 +639,8 @@ let main ~input_file ~output_file_opt ~archive_uri ~continue_on_error ~transport:(Logger_file_system.evergrowing ~log_filename) () ) ; let logger = Logger.create () in - let%bind _, config = - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger () + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file () in let { Runtime_config.Constraint.constraint_constants; proof_level } = config.constraint_config diff --git a/src/app/rosetta/lib/rosetta.ml b/src/app/rosetta/lib/rosetta.ml index 524f506a03d..cb5f1903c30 100644 --- a/src/app/rosetta/lib/rosetta.ml +++ b/src/app/rosetta/lib/rosetta.ml @@ -176,9 +176,8 @@ let command = fun () -> let logger = Logger.create () in Cli.logger_setup log_json log_level ; - let%bind _, config = - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger - () + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file () in let account_creation_fee = config.constraint_config.constraint_constants.account_creation_fee diff --git a/src/app/runtime_genesis_ledger/runtime_genesis_ledger.ml b/src/app/runtime_genesis_ledger/runtime_genesis_ledger.ml index 4db7da0c1d7..99e89fb7b14 100644 --- a/src/app/runtime_genesis_ledger/runtime_genesis_ledger.ml +++ b/src/app/runtime_genesis_ledger/runtime_genesis_ledger.ml @@ -72,8 +72,8 @@ let extract_accounts_exn = function failwith "Wrong ledger supplied" let main ~config_file ~genesis_dir ~hash_output_file () = - let%bind _, config = - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger () + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file () in let accounts, staking_accounts_opt, next_accounts_opt = let ledger = config.ledger in diff --git a/src/app/snark_work_debugger/snark_work_debugger.ml b/src/app/snark_work_debugger/snark_work_debugger.ml index 44a208d29a0..47f8b13ebeb 100644 --- a/src/app/snark_work_debugger/snark_work_debugger.ml +++ b/src/app/snark_work_debugger/snark_work_debugger.ml @@ -39,11 +39,9 @@ let cmd = flag "--spec" ~doc:"PATH Spec path" (required string) and config_file = Cli_lib.Flag.conf_file in fun () -> - let logger = Logger.create () in let open Deferred.Let_syntax in - let%bind _, config = - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file - ~logger () + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file () in let { Runtime_config.Constraint.constraint_constants; proof_level } = config.constraint_config diff --git a/src/app/zkapp_limits/zkapp_limits.ml b/src/app/zkapp_limits/zkapp_limits.ml index 2e34e7d1fa5..481e7717efb 100644 --- a/src/app/zkapp_limits/zkapp_limits.ml +++ b/src/app/zkapp_limits/zkapp_limits.ml @@ -37,9 +37,7 @@ let () = (let%map_open config_file = Cli_lib.Flag.conf_file in fun () -> let open Deferred.Let_syntax in - let logger = Logger.create () in - let%map _, config = - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file - ~logger () + let%map config = + Runtime_config.Config_loader.load_config_exn ~config_file () in main config ) diff --git a/src/app/zkapp_test_transaction/lib/commands.ml b/src/app/zkapp_test_transaction/lib/commands.ml index e78184d1f89..28fec231e0d 100644 --- a/src/app/zkapp_test_transaction/lib/commands.ml +++ b/src/app/zkapp_test_transaction/lib/commands.ml @@ -334,9 +334,8 @@ let test_zkapp_with_genesis_ledger_main keyfile zkapp_keyfile config_file () = let open Deferred.Let_syntax in let%bind keypair = Util.fee_payer_keypair_of_file keyfile in let%bind zkapp_kp = Util.snapp_keypair_of_file zkapp_keyfile in - let%bind _, config = - let logger = Logger.create () in - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger () + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file () in let ledger = let accounts = @@ -375,9 +374,8 @@ let create_zkapp_account ~debug ~sender ~sender_nonce ~fee ~fee_payer ; authorization_kind = Signature } in - let%bind _, config = - let logger = Logger.create () in - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file ~cli_proof_level:Full () in let constraint_constants = config.constraint_config.constraint_constants in @@ -422,9 +420,8 @@ let upgrade_zkapp ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile ~config_file ; preconditions = None } in - let%bind _, config = - let logger = Logger.create () in - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file ~cli_proof_level:Full () in let constraint_constants = config.constraint_config.constraint_constants in @@ -473,9 +470,8 @@ let transfer_funds ~debug ~sender ~sender_nonce ~fee ~fee_payer ~fee_payer_nonce ; preconditions = None } in - let%bind _, config = - let logger = Logger.create () in - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file ~cli_proof_level:Full () in let zkapp_command = @@ -512,9 +508,8 @@ let update_state ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile ~app_state ; preconditions = None } in - let%bind _, config = - let logger = Logger.create () in - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file ~cli_proof_level:Full () in let constraint_constants = config.constraint_config.constraint_constants in @@ -557,9 +552,8 @@ let update_zkapp_uri ~debug ~keyfile ~fee ~nonce ~memo ~snapp_keyfile ~zkapp_uri ; preconditions = None } in - let%bind _, config = - let logger = Logger.create () in - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file ~cli_proof_level:Full () in let constraint_constants = config.constraint_config.constraint_constants in @@ -604,9 +598,8 @@ let update_action_state ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile ; preconditions = None } in - let%bind _, config = - let logger = Logger.create () in - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file ~cli_proof_level:Full () in let constraint_constants = config.constraint_config.constraint_constants in @@ -649,9 +642,8 @@ let update_token_symbol ~debug ~keyfile ~fee ~nonce ~memo ~snapp_keyfile ; preconditions = None } in - let%bind _, config = - let logger = Logger.create () in - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file ~cli_proof_level:Full () in let constraint_constants = config.constraint_config.constraint_constants in @@ -695,9 +687,8 @@ let update_snapp ~debug ~keyfile ~fee ~nonce ~memo ~zkapp_keyfile ~snapp_update ; preconditions = None } in - let%bind _, config = - let logger = Logger.create () in - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file ~cli_proof_level:Full () in let constraint_constants = config.constraint_config.constraint_constants in diff --git a/src/lib/cli_lib/commands.ml b/src/lib/cli_lib/commands.ml index 0e81b9ab2b6..9fd055d79ae 100644 --- a/src/lib/cli_lib/commands.ml +++ b/src/lib/cli_lib/commands.ml @@ -234,11 +234,9 @@ module Vrf = struct Exceptions.handle_nicely @@ fun () -> let env = Secrets.Keypair.env in - let logger = Logger.create () in let open Deferred.Let_syntax in - let%bind _, { constraint_config = { constraint_constants; _ }; _ } = - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger - () + let%bind { constraint_config = { constraint_constants; _ }; _ } = + Runtime_config.Config_loader.load_config_exn ~config_file () in if Option.is_some (Sys.getenv env) then eprintf "Using password from environment variable %s\n" env ; @@ -306,11 +304,9 @@ module Vrf = struct let env = Secrets.Keypair.env in if Option.is_some (Sys.getenv env) then eprintf "Using password from environment variable %s\n" env ; - let logger = Logger.create () in let open Deferred.Let_syntax in - let%bind _, { constraint_config = { constraint_constants; _ }; _ } = - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger - () + let%bind { constraint_config = { constraint_constants; _ }; _ } = + Runtime_config.Config_loader.load_config_exn ~config_file () in let%bind () = let password = @@ -371,10 +367,8 @@ module Vrf = struct Exceptions.handle_nicely @@ fun () -> let open Deferred.Let_syntax in - let logger = Logger.create () in - let%bind _, { constraint_config = { constraint_constants; _ }; _ } = - Genesis_ledger_helper.Config_loader.load_config_exn ~config_file ~logger - () + let%bind { constraint_config = { constraint_constants; _ }; _ } = + Runtime_config.Config_loader.load_config_exn ~config_file () in (* TODO-someday: constraint constants from config file. *) let lexbuf = Lexing.from_channel In_channel.stdin in diff --git a/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml b/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml index 7048f37c431..92d942e692c 100644 --- a/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml +++ b/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml @@ -733,40 +733,16 @@ module Genesis_proof = struct let create_values_no_proof = Genesis_proof.create_values_no_proof end -module type Config_loader = sig - val load_config : +module type Config_initializer_intf = sig + val initialize : ?genesis_dir:string -> ?overwrite_version:Unsigned.UInt32.t - -> ?cli_proof_level:Genesis_constants.Proof_level.t - -> config_file:string -> logger:Logger.t - -> unit - -> (Precomputed_values.t * Runtime_config.t) Deferred.Or_error.t - - val load_config_exn : - ?genesis_dir:string - -> ?overwrite_version:Unsigned.UInt32.t - -> ?cli_proof_level:Genesis_constants.Proof_level.t - -> config_file:string - -> logger:Logger.t - -> unit - -> (Precomputed_values.t * Runtime_config.t) Deferred.t - - val init_from_config_file : - ?overwrite_version:Unsigned.UInt32.t - -> ?cli_proof_level:Genesis_constants.Proof_level.t - -> genesis_dir:string - -> logger:Logger.t - -> Runtime_config.Json_layout.t + -> Runtime_config.t -> (Precomputed_values.t * Runtime_config.t) Deferred.Or_error.t end -module Config_loader : Config_loader = struct - let load_config_json filename = - Monitor.try_with_or_error ~here:[%here] (fun () -> - let%map json = Reader.file_contents filename in - Yojson.Safe.from_string json ) - +module Config_initializer : Config_initializer_intf = struct let print_config ~logger config = let ledger_name_json = Option.value_map ~default:`Null @@ -794,51 +770,33 @@ module Config_loader : Config_loader = struct [%log info] "Initializing with runtime configuration. Ledger name: $name" ~metadata - let init_from_config_file ?overwrite_version ?cli_proof_level ~genesis_dir - ~logger (config : Runtime_config.Json_layout.t) : + let initialize ?(genesis_dir = Cache_dir.autogen_path) ?overwrite_version + ~logger (config : Runtime_config.t) : (Precomputed_values.t * Runtime_config.t) Deferred.Or_error.t = let open Deferred.Or_error.Let_syntax in - let constraint_config = - let c = Runtime_config.Constraint.of_json_layout config.proof in - { c with - proof_level = Option.value ~default:c.proof_level cli_proof_level - } - in let { Runtime_config.Constraint.constraint_constants; proof_level } = - constraint_config + config.constraint_config in - let genesis_constants = Genesis_constants.make config.genesis in - let compile_config = Mina_compile_config.make config.daemon in let%bind genesis_ledger, runtime_ledger = - match Runtime_config.Ledger.of_json_layout config.ledger with - | Error e -> - Deferred.Or_error.error_string e - | Ok c -> - let%bind genesis_ledger, runtime_ledger, ledger_file = - Ledger.load ~genesis_dir ~logger ~constraint_constants ~proof_level - ?overwrite_version c - in - [%log info] "Loaded genesis ledger from $ledger_file" - ~metadata:[ ("ledger_file", `String ledger_file) ] ; - Deferred.Or_error.return (genesis_ledger, runtime_ledger) + let%bind genesis_ledger, runtime_ledger, ledger_file = + Ledger.load ~genesis_dir ~logger ~constraint_constants ~proof_level + ?overwrite_version config.ledger + in + [%log info] "Loaded genesis ledger from $ledger_file" + ~metadata:[ ("ledger_file", `String ledger_file) ] ; + Deferred.Or_error.return (genesis_ledger, runtime_ledger) in let%map genesis_epoch_data, genesis_epoch_data_config = match config.epoch_data with | None -> Deferred.Or_error.return (None, None) - | Some conf -> ( - match Runtime_config.Epoch_data.of_json_layout conf with - | Error e -> - Deferred.Or_error.error_string e - | Ok c -> - Epoch_data.load ~genesis_dir ~logger ~constraint_constants - ~proof_level (Some c) ) + | Some conf -> + Epoch_data.load ~genesis_dir ~logger ~constraint_constants + ~proof_level (Some conf) in let config : Runtime_config.t = - { constraint_config = { constraint_constants; proof_level } - ; genesis_constants - ; compile_config - ; ledger = runtime_ledger + { config with + ledger = runtime_ledger ; epoch_data = genesis_epoch_data_config } in @@ -849,26 +807,6 @@ module Config_loader : Config_loader = struct in let values = Genesis_proof.create_values_no_proof inputs in (values, config) - - let load_config ?(genesis_dir = Cache_dir.autogen_path) ?overwrite_version - ?cli_proof_level ~config_file ~logger () = - let open Deferred.Or_error.Let_syntax in - let%bind config_json = load_config_json config_file in - match Runtime_config.Json_layout.of_yojson config_json with - | Error e -> - Deferred.Or_error.error_string e - | Ok c -> - init_from_config_file ?overwrite_version ?cli_proof_level ~genesis_dir - ~logger c - - let load_config_exn ?genesis_dir ?overwrite_version ?cli_proof_level - ~config_file ~logger () = - let open Deferred.Let_syntax in - let%bind config = - load_config ?genesis_dir ?overwrite_version ?cli_proof_level ~config_file - ~logger () - in - Deferred.return (Or_error.ok_exn config) end let%test_module "Account config test" = diff --git a/src/lib/mina_lib/tests/tests.ml b/src/lib/mina_lib/tests/tests.ml index 0214e9663b7..cff13c9de9f 100644 --- a/src/lib/mina_lib/tests/tests.ml +++ b/src/lib/mina_lib/tests/tests.ml @@ -64,10 +64,14 @@ let%test_module "Epoch ledger sync tests" = ; epoch_data = None } in + let config = + Runtime_config.Config_loader.of_json_layout runtime_config + |> Result.ok_or_failwith + in match%map - Genesis_ledger_helper.Config_loader.init_from_config_file + Genesis_ledger_helper.Config_initializer.initialize ~genesis_dir:(make_dirname "genesis_dir") - ~logger runtime_config + ~logger config with | Ok (precomputed_values, _) -> precomputed_values diff --git a/src/lib/runtime_config/runtime_config.ml b/src/lib/runtime_config/runtime_config.ml index 1bb518e103a..75d9c635117 100644 --- a/src/lib/runtime_config/runtime_config.ml +++ b/src/lib/runtime_config/runtime_config.ml @@ -1,43 +1,5 @@ open Core_kernel - -let yojson_strip_fields ~keep_fields = function - | `Assoc l -> - `Assoc - (List.filter l ~f:(fun (fld, _) -> - Array.mem ~equal:String.equal keep_fields fld ) ) - | json -> - json - -let yojson_rename_fields ~alternates = function - | `Assoc l -> - `Assoc - (List.map l ~f:(fun (fld, json) -> - let fld = - Option.value ~default:fld - (Array.find_map alternates ~f:(fun (alt, orig) -> - if String.equal fld alt then Some orig else None ) ) - in - (fld, json) ) ) - | json -> - json - -let opt_fallthrough ~default x2 = - Option.value_map ~default x2 ~f:(fun x -> Some x) - -let result_opt ~f x = - match x with - | Some x -> - Result.map ~f:Option.some (f x) - | None -> - Result.return None - -let dump_on_error yojson x = - Result.map_error x ~f:(fun str -> - str ^ "\n\nCould not parse JSON:\n" ^ Yojson.Safe.pretty_to_string yojson ) - -let of_yojson_generic ~fields of_yojson json = - dump_on_error json @@ of_yojson - @@ yojson_strip_fields ~keep_fields:fields json +open Async let rec deferred_list_fold ~init ~f = function | [] -> @@ -58,11 +20,7 @@ module Json_layout = struct ; vesting_period : Mina_numbers.Global_slot_span.t ; vesting_increment : Currency.Amount.t } - [@@deriving yojson, fields, sexp] - - let fields = Fields.names |> Array.of_list - - let of_yojson json = of_yojson_generic ~fields of_yojson json + [@@deriving yojson, sexp] end module Permissions = struct @@ -201,11 +159,7 @@ module Json_layout = struct Auth_required.of_account_perm Mina_base.Permissions.user_default.set_timing] } - [@@deriving yojson, fields, sexp, bin_io_unversioned] - - let fields = Fields.names |> Array.of_list - - let of_yojson json = of_yojson_generic ~fields of_yojson json + [@@deriving yojson, sexp, bin_io_unversioned] let to_yojson t = `Assoc @@ -299,11 +253,7 @@ module Json_layout = struct ; proved_state : bool ; zkapp_uri : string } - [@@deriving sexp, fields, yojson, bin_io_unversioned] - - let fields = Fields.names |> Array.of_list - - let of_yojson json = of_yojson_generic ~fields of_yojson json + [@@deriving sexp, yojson, bin_io_unversioned] let of_zkapp (zkapp : Mina_base.Zkapp_account.t) : t = let open Mina_base.Zkapp_account in @@ -337,11 +287,7 @@ module Json_layout = struct ; permissions : Permissions.t option [@default None] ; token_symbol : string option [@default None] } - [@@deriving sexp, fields, yojson] - - let fields = Fields.names |> Array.of_list - - let of_yojson json = of_yojson_generic ~fields of_yojson json + [@@deriving sexp, yojson] let default : t = { pk = Signature_lib.Public_key.Compressed.(to_base58_check empty) @@ -377,11 +323,7 @@ module Json_layout = struct ; name : string option [@default None] ; add_genesis_winner : bool option [@default None] } - [@@deriving yojson, fields] - - let fields = Fields.names |> Array.of_list - - let of_yojson json = of_yojson_generic ~fields of_yojson json + [@@deriving yojson] end module Epoch_data = struct @@ -392,22 +334,14 @@ module Json_layout = struct ; s3_data_hash : string option [@default None] ; hash : string option [@default None] } - [@@deriving yojson, fields] - - let fields = Fields.names |> Array.of_list - - let of_yojson json = of_yojson_generic ~fields of_yojson json + [@@deriving yojson] end type t = { staking : Data.t ; next : (Data.t option[@default None]) (*If None then next = staking*) } - [@@deriving yojson, fields] - - let fields = Fields.names |> Array.of_list - - let of_yojson json = of_yojson_generic ~fields of_yojson json + [@@deriving yojson] end module Constraint = struct @@ -415,11 +349,7 @@ module Json_layout = struct { constraint_constants : Genesis_constants.Constraint_constants.Inputs.t ; proof_level : string } - [@@deriving yojson, fields] - - let fields = Fields.names |> Array.of_list - - let of_yojson json = of_yojson_generic ~fields of_yojson json + [@@deriving yojson] end type t = @@ -822,7 +752,8 @@ module Epoch_data = struct let to_yojson x = Json_layout.Epoch_data.to_yojson (to_json_layout x) - let of_yojson x = Result.(Json_layout.Epoch_data.of_yojson x >>= of_json_layout) + let of_yojson x = + Result.(Json_layout.Epoch_data.of_yojson x >>= of_json_layout) end module Constraint = struct @@ -1011,3 +942,69 @@ let make_fork_config ~staged_ledger ~global_slot_since_genesis ~state_hash ; genesis_constants ; compile_config } + +module type Config_loader = sig + val load_config : + ?cli_proof_level:Genesis_constants.Proof_level.t + -> config_file:string + -> unit + -> t Deferred.Or_error.t + + val load_config_exn : + ?cli_proof_level:Genesis_constants.Proof_level.t + -> config_file:string + -> unit + -> t Deferred.t + + val of_json_layout : Json_layout.t -> (t, string) Result.t +end + +module Config_loader : Config_loader = struct + let load_config_json filename : Json_layout.t Deferred.Or_error.t = + let open Deferred.Or_error.Let_syntax in + let%bind json = + Monitor.try_with_or_error (fun () -> + Deferred.map ~f:Yojson.Safe.from_string + @@ Reader.file_contents filename ) + in + match Json_layout.of_yojson json with + | Ok config -> + Deferred.Or_error.return config + | Error e -> + Deferred.Or_error.error_string e + + let of_json_layout (config : Json_layout.t) : (t, string) result = + let open Result.Let_syntax in + let constraint_config = Constraint.of_json_layout config.proof in + let genesis_constants = Genesis_constants.make config.genesis in + let compile_config = Mina_compile_config.make config.daemon in + let%bind ledger = Ledger.of_json_layout config.ledger in + let%map epoch_data = + match config.epoch_data with + | None -> + Ok None + | Some conf -> + Epoch_data.of_json_layout conf |> Result.map ~f:Option.some + in + { constraint_config; genesis_constants; compile_config; ledger; epoch_data } + + let load_config ?cli_proof_level ~config_file () = + let open Deferred.Or_error.Let_syntax in + let%bind config = load_config_json config_file in + let e_config = of_json_layout config in + match e_config with + | Ok config -> + let { Constraint.proof_level; _ } = config.constraint_config in + Deferred.Or_error.return + { config with + constraint_config = + { config.constraint_config with + proof_level = Option.value ~default:proof_level cli_proof_level + } + } + | Error e -> + Deferred.Or_error.error_string e + + let load_config_exn ?cli_proof_level ~config_file () = + Deferred.Or_error.ok_exn @@ load_config ?cli_proof_level ~config_file () +end diff --git a/src/lib/snark_worker/standalone/run_snark_worker.ml b/src/lib/snark_worker/standalone/run_snark_worker.ml index 91348ef1127..8e8b58bc2ac 100644 --- a/src/lib/snark_worker/standalone/run_snark_worker.ml +++ b/src/lib/snark_worker/standalone/run_snark_worker.ml @@ -21,13 +21,10 @@ let command = fun () -> let open Async in let open Deferred.Let_syntax in - let logger = Logger.create () in - let%bind ( _ - , { constraint_config = { constraint_constants; proof_level } - ; _ - } ) = - Genesis_ledger_helper.Config_loader.load_config_exn ~cli_proof_level - ~config_file ~logger () + let%bind { constraint_config = { constraint_constants; proof_level }; _ } + = + Runtime_config.Config_loader.load_config_exn ~cli_proof_level + ~config_file () in let%bind worker_state = Prod.Worker_state.create ~constraint_constants ~proof_level () From ac144dd1bd25d6e34967d06bc5f24d0d7763d1f5 Mon Sep 17 00:00:00 2001 From: martyall Date: Thu, 19 Sep 2024 10:58:15 -0700 Subject: [PATCH 27/29] disk_caching_stats --- .../disk_caching_stats/disk_caching_stats.ml | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/app/disk_caching_stats/disk_caching_stats.ml b/src/app/disk_caching_stats/disk_caching_stats.ml index c7ebdf0b5bd..a62ff4c0ba5 100644 --- a/src/app/disk_caching_stats/disk_caching_stats.ml +++ b/src/app/disk_caching_stats/disk_caching_stats.ml @@ -721,21 +721,21 @@ let compute_ram_usage ~config (sizes : size_params) = in Printf.printf "TOTAL: %fGB\n" (format_gb total_size) -let () = +let main config () = Async.Thread_safe.block_on_async_exn @@ fun () -> - let genesis_constants = Genesis_constants.Compiled.genesis_constants in - let constraint_constants = Genesis_constants.Compiled.constraint_constants in - let config = { constraint_constants; genesis_constants } in let%bind.Async_kernel.Deferred _, generated_zkapps = let num_updates = 1 in - Snark_profiler_lib.create_ledger_and_zkapps ~genesis_constants - ~constraint_constants ~min_num_updates:num_updates - ~num_proof_updates:num_updates ~max_num_updates:num_updates () + Snark_profiler_lib.create_ledger_and_zkapps + ~genesis_constants:config.genesis_constants + ~constraint_constants:config.constraint_constants + ~min_num_updates:num_updates ~num_proof_updates:num_updates + ~max_num_updates:num_updates () in let%map.Async_kernel.Deferred vk = let `VK vk, `Prover _ = - Transaction_snark.For_tests.create_trivial_snapp ~constraint_constants () + Transaction_snark.For_tests.create_trivial_snapp + ~constraint_constants:config.constraint_constants () in vk in @@ -836,3 +836,23 @@ let () = *. Time.Span.to_ns ledger_proof_serial_times.read ) in Time.Span.(zkapps + snark_works) ) + +let () = + Command.run + @@ + let open Command.Let_syntax in + Async.Command.async + ~summary: + "Estimate the memory usage of the daemon in the fully saturated max-cost \ + transaction environment" + (let%map_open config_file = Cli_lib.Flag.conf_file in + fun () -> + let open Async.Deferred.Let_syntax in + let%map config = + Runtime_config.Config_loader.load_config_exn ~config_file () + in + let genesis_constants = config.genesis_constants in + let constraint_constants = + config.constraint_config.constraint_constants + in + main { genesis_constants; constraint_constants } () ) From 5f2da17068183ef268bb96163cf475ae50042b39 Mon Sep 17 00:00:00 2001 From: martyall Date: Thu, 19 Sep 2024 14:17:43 -0700 Subject: [PATCH 28/29] mina_cli_entrypoint --- .../src/cli_entrypoint/mina_cli_entrypoint.ml | 619 +++++------------- src/lib/runtime_config/runtime_config.ml | 14 +- src/lib/snark_worker/functor.ml | 20 +- src/lib/snark_worker/intf.ml | 8 +- 4 files changed, 170 insertions(+), 491 deletions(-) diff --git a/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml b/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml index f9b4f49f279..68f2d82dbb7 100644 --- a/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml +++ b/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml @@ -40,104 +40,7 @@ let chain_id ~constraint_system_digests ~genesis_state_hash ~genesis_constants in Blake2.to_hex b2 -let plugin_flag = - if Node_config.plugins then - let open Command.Param in - flag "--load-plugin" ~aliases:[ "load-plugin" ] (listed string) - ~doc: - "PATH The path to load a .cmxs plugin from. May be passed multiple \ - times" - else Command.Param.return [] - -let load_config_files ~logger ~genesis_constants ~constraint_constants ~conf_dir - ~genesis_dir ~cli_proof_level ~proof_level config_files = - let%bind config_jsons = - let config_files_paths = - List.map config_files ~f:(fun (config_file, _) -> `String config_file) - in - [%log info] "Reading configuration files $config_files" - ~metadata:[ ("config_files", `List config_files_paths) ] ; - Deferred.List.filter_map config_files - ~f:(fun (config_file, handle_missing) -> - match%bind Genesis_ledger_helper.load_config_json config_file with - | Ok config_json -> - let%map config_json = - Genesis_ledger_helper.upgrade_old_config ~logger config_file - config_json - in - Some (config_file, config_json) - | Error err -> ( - match handle_missing with - | `Must_exist -> - Mina_user_error.raisef ~where:"reading configuration file" - "The configuration file %s could not be read:\n%s" config_file - (Error.to_string_hum err) - | `May_be_missing -> - [%log warn] "Could not read configuration from $config_file" - ~metadata: - [ ("config_file", `String config_file) - ; ("error", Error_json.error_to_yojson err) - ] ; - return None ) ) - in - let config = - List.fold ~init:Runtime_config.default config_jsons - ~f:(fun config (config_file, config_json) -> - match Runtime_config.of_yojson config_json with - | Ok loaded_config -> - Runtime_config.combine config loaded_config - | Error err -> - [%log fatal] - "Could not parse configuration from $config_file: $error" - ~metadata: - [ ("config_file", `String config_file) - ; ("config_json", config_json) - ; ("error", `String err) - ] ; - failwithf "Could not parse configuration file: %s" err () ) - in - let genesis_dir = Option.value ~default:(conf_dir ^/ "genesis") genesis_dir in - let%bind precomputed_values = - match%map - Genesis_ledger_helper.init_from_config_file ~cli_proof_level ~genesis_dir - ~logger ~genesis_constants ~constraint_constants ~proof_level config - with - | Ok (precomputed_values, _) -> - precomputed_values - | Error err -> - let ( json_config - , `Accounts_omitted - ( `Genesis genesis_accounts_omitted - , `Staking staking_accounts_omitted - , `Next next_accounts_omitted ) ) = - Runtime_config.to_yojson_without_accounts config - in - let append_accounts_omitted s = - Option.value_map - ~f:(fun i -> List.cons (s ^ "_accounts_omitted", `Int i)) - ~default:Fn.id - in - let metadata = - append_accounts_omitted "genesis" genesis_accounts_omitted - @@ append_accounts_omitted "staking" staking_accounts_omitted - @@ append_accounts_omitted "next" next_accounts_omitted [] - @ [ ("config", json_config) - ; ( "name" - , `String - (Option.value ~default:"not provided" - (let%bind.Option ledger = config.ledger in - Option.first_some ledger.name ledger.hash ) ) ) - ; ("error", Error_json.error_to_yojson err) - ] - in - [%log info] - "Initializing with runtime configuration. Ledger source: $name" - ~metadata ; - Error.raise err - in - return (precomputed_values, config_jsons, config) - -let setup_daemon logger ~itn_features ~default_snark_worker_fee = +let setup_daemon logger ~itn_features = let open Command.Let_syntax in let open Cli_lib.Arg_type in let receiver_key_warning = Cli_lib.Default.receiver_key_warning in @@ -165,16 +68,6 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = `block-producer-pubkey`. (default: don't produce blocks) %s" receiver_key_warning ) (optional public_key_compressed) - and block_production_password = - flag "--block-producer-password" - ~aliases:[ "block-producer-password" ] - ~doc: - "PASSWORD Password associated with the block-producer key. Setting \ - this is equivalent to setting the MINA_PRIVKEY_PASS environment \ - variable. Be careful when setting it in the commandline as it will \ - likely get tracked in your history. Mainly to be used from the \ - daemon.json config file" - (optional string) and itn_keys = if itn_features then flag "--itn-keys" ~aliases:[ "itn-keys" ] (optional string) @@ -232,12 +125,12 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = "NUM Run the SNARK worker using this many threads. Equivalent to \ setting OMP_NUM_THREADS, but doesn't affect block production." (optional int) - and work_selection_method_flag = + and work_selection_method = flag "--work-selection" ~aliases:[ "work-selection" ] ~doc: "seq|rand|roffset Choose work sequentially (seq), randomly (rand), or \ sequentially with a random offset (roffset) (default: rand)" - (optional work_selection_method) + (optional_with_default Work_selection_method.Random work_selection_method) and libp2p_port = Flag.Port.Daemon.external_ and client_port = Flag.Port.Daemon.client and rest_server_port = Flag.Port.Daemon.rest_server @@ -304,10 +197,8 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = and snark_work_fee = flag "--snark-worker-fee" ~aliases:[ "snark-worker-fee" ] ~doc: - (sprintf - "FEE Amount a worker wants to get compensated for generating a \ - snark proof (default: %d)" - (Currency.Fee.to_nanomina_int default_snark_worker_fee) ) + "FEE Amount a worker wants to get compensated for generating a snark \ + proof" (optional txn_fee) and work_reassignment_wait = flag "--work-reassignment-wait" @@ -344,19 +235,19 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = flag "--log-snark-work-gossip" ~aliases:[ "log-snark-work-gossip" ] ~doc:"true|false Log snark-pool diff received from peers (default: false)" - (optional bool) + (optional_with_default false bool) and log_transaction_pool_diff = flag "--log-txn-pool-gossip" ~aliases:[ "log-txn-pool-gossip" ] ~doc: "true|false Log transaction-pool diff received from peers (default: \ false)" - (optional bool) + (optional_with_default false bool) and log_block_creation = flag "--log-block-creation" ~aliases:[ "log-block-creation" ] ~doc: "true|false Log the steps involved in including transactions and snark \ work in a block (default: true)" - (optional bool) + (optional_with_default true bool) and libp2p_keypair = flag "--libp2p-keypair" ~aliases:[ "libp2p-keypair" ] (optional string) ~doc: @@ -373,13 +264,13 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = ~doc: "true|false Publish our own blocks/transactions to every peer we can \ find (default: false)" - (optional bool) + (optional_with_default false bool) and peer_exchange = flag "--enable-peer-exchange" ~aliases:[ "enable-peer-exchange" ] ~doc: "true|false Help keep the mesh connected when closing connections \ (default: false)" - (optional bool) + (optional_with_default false bool) and peer_protection_ratio = flag "--peer-protection-rate" ~aliases:[ "peer-protection-rate" ] ~doc:"float Proportion of peers to be marked as protected (default: 0.2)" @@ -428,7 +319,7 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = ~doc: "true|false Only allow connections to the peers passed on the command \ line or configured through GraphQL. (default: false)" - (optional bool) + (optional_with_default false bool) and libp2p_peers_raw = flag "--peer" ~aliases:[ "peer" ] ~doc: @@ -450,13 +341,7 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = ~aliases:[ "proposed-protocol-version" ] (optional string) ~doc:"NN.NN.NN Proposed protocol version to signal other nodes" - and config_files = - flag "--config-file" ~aliases:[ "config-file" ] - ~doc: - "PATH path to a configuration file (overrides MINA_CONFIG_FILE, \ - default: /daemon.json). Pass multiple times to override \ - fields from earlier config files" - (listed string) + and config_file = Cli_lib.Flag.conf_file and _may_generate = flag "--generate-genesis-proof" ~aliases:[ "generate-genesis-proof" ] @@ -472,7 +357,14 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = "full|check|none Internal, for testing. Start or connect to a network \ with full proving (full), snark-testing with dummy proofs (check), or \ dummy proofs (none)" - and plugins = plugin_flag + and plugins = + if itn_features then + let open Command.Param in + flag "--load-plugin" ~aliases:[ "load-plugin" ] (listed string) + ~doc: + "PATH The path to load a .cmxs plugin from. May be passed multiple \ + times" + else Command.Param.return [] and precomputed_blocks_path = flag "--precomputed-blocks-file" ~aliases:[ "precomputed-blocks-file" ] @@ -569,20 +461,6 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = the uptime service. (default: false)" no_arg in - let to_pubsub_topic_mode_option = - let open Gossip_net.Libp2p in - function - | `String "ro" -> - Some RO - | `String "rw" -> - Some RW - | `String "none" -> - Some N - | `Null -> - None - | _ -> - raise (Error.to_exn (Error.of_string "Invalid pubsub topic mode")) - in fun () -> O1trace.thread "mina" (fun () -> let open Deferred.Let_syntax in @@ -732,161 +610,29 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = in let pids = Child_processes.Termination.create_pid_table () in let mina_initialization_deferred () = - let config_file_installed = - (* Search for config files installed as part of a deb/brew package. - These files are commit-dependent, to ensure that we don't clobber - configuration for dev builds or use incompatible configs. - *) - let config_file_installed = - let json = "config_" ^ Mina_version.commit_id_short ^ ".json" in - List.fold_until ~init:None - (Cache_dir.possible_paths json) - ~f:(fun _acc f -> - match Core.Sys.file_exists f with - | `Yes -> - Stop (Some f) - | _ -> - Continue None ) - ~finish:Fn.id - in - match config_file_installed with - | Some config_file -> - Some (config_file, `Must_exist) - | None -> - None - in - let config_file_configdir = - (conf_dir ^/ "daemon.json", `May_be_missing) - in - let config_file_envvar = - match Sys.getenv "MINA_CONFIG_FILE" with - | Some config_file -> - Some (config_file, `Must_exist) - | None -> - None - in - let config_files = - Option.to_list config_file_installed - @ (config_file_configdir :: Option.to_list config_file_envvar) - @ List.map config_files ~f:(fun config_file -> - (config_file, `Must_exist) ) - in - let genesis_constants = - Genesis_constants.Compiled.genesis_constants - in - let constraint_constants = - Genesis_constants.Compiled.constraint_constants - in - let compile_config = Mina_compile_config.Compiled.t in - let%bind precomputed_values, config_jsons, config = - load_config_files ~logger ~conf_dir ~genesis_dir - ~proof_level:Genesis_constants.Compiled.proof_level config_files - ~genesis_constants ~constraint_constants ~cli_proof_level - in - let rev_daemon_configs = - List.rev_filter_map config_jsons - ~f:(fun (config_file, config_json) -> - Option.map - YJ.Util.( - to_option Fn.id (YJ.Util.member "daemon" config_json)) - ~f:(fun daemon_config -> (config_file, daemon_config)) ) - in - let maybe_from_config (type a) (f : YJ.t -> a option) - (keyname : string) (actual_value : a option) : a option = - let open Option.Let_syntax in - let open YJ.Util in - match actual_value with - | Some v -> - Some v - | None -> - (* Load value from the latest config file that both - * has the key we are looking for, and - * has the key in a format that [f] can parse. - *) - let%map config_file, data = - List.find_map rev_daemon_configs - ~f:(fun (config_file, daemon_config) -> - let%bind json_val = - to_option Fn.id (member keyname daemon_config) - in - let%map data = f json_val in - (config_file, data) ) - in - [%log debug] "Key $key being used from config file $config_file" - ~metadata: - [ ("key", `String keyname) - ; ("config_file", `String config_file) - ] ; - data - in - let or_from_config map keyname actual_value ~default = - match maybe_from_config map keyname actual_value with - | Some x -> - x - | None -> - [%log trace] - "Key '$key' not found in the config file, using default" - ~metadata:[ ("key", `String keyname) ] ; - default - in - let get_port { Flag.Types.value; default; name } = - or_from_config YJ.Util.to_int_option name ~default value - in - let libp2p_port = get_port libp2p_port in - let rest_server_port = get_port rest_server_port in - let limited_graphql_port = - let ({ value; name } : int option Flag.Types.with_name) = - limited_graphql_port - in - maybe_from_config YJ.Util.to_int_option name value - in - let client_port = get_port client_port in - let snark_work_fee_flag = - let json_to_currency_fee_option json = - YJ.Util.to_int_option json - |> Option.map ~f:Currency.Fee.of_nanomina_int_exn + let%bind precomputed_values, (*config_jsons,*) config = + let%bind conf = + Runtime_config.Config_loader.load_config_exn ?cli_proof_level + ~config_file () in - or_from_config json_to_currency_fee_option "snark-worker-fee" - ~default:compile_config.default_snark_worker_fee snark_work_fee - in - let node_status_url = - maybe_from_config YJ.Util.to_string_option "node-status-url" - node_status_url + Deferred.Or_error.ok_exn + @@ Genesis_ledger_helper.Config_initializer.initialize ?genesis_dir + ~logger conf in - (* FIXME #4095: pass this through to Gossip_net.Libp2p *) - let _max_concurrent_connections = - (*if - or_from_config YJ.Util.to_bool_option "max-concurrent-connections" - ~default:true limit_connections - then Some 40 - else *) - None + let compile_config = config.compile_config in + let rest_server_port = + Option.value ~default:rest_server_port.default + rest_server_port.value in - let work_selection_method = - or_from_config - (Fn.compose Option.return - (Fn.compose work_selection_method_val YJ.Util.to_string) ) - "work-selection" - ~default:Cli_lib.Arg_type.Work_selection_method.Random - work_selection_method_flag + let limited_graphql_port = limited_graphql_port.value in + let snark_work_fee = + Option.value ~default:compile_config.default_snark_worker_fee + snark_work_fee in let work_reassignment_wait = - or_from_config YJ.Util.to_int_option "work-reassignment-wait" - ~default:Cli_lib.Default.work_reassignment_wait + Option.value ~default:Cli_lib.Default.work_reassignment_wait work_reassignment_wait in - let log_received_snark_pool_diff = - or_from_config YJ.Util.to_bool_option "log-snark-work-gossip" - ~default:false log_received_snark_pool_diff - in - let log_transaction_pool_diff = - or_from_config YJ.Util.to_bool_option "log-txn-pool-gossip" - ~default:false log_transaction_pool_diff - in - let log_block_creation = - or_from_config YJ.Util.to_bool_option "log-block-creation" - ~default:true log_block_creation - in let log_gossip_heard = { Mina_networking.Config.snark_pool_diff = log_received_snark_pool_diff @@ -894,81 +640,31 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = ; new_state = true } in - let json_to_publickey_compressed_option which json = - YJ.Util.to_string_option json - |> Option.bind ~f:(fun pk_str -> - match Public_key.Compressed.of_base58_check pk_str with - | Ok key -> ( - match Public_key.decompress key with - | None -> - Mina_user_error.raisef - ~where:"decompressing a public key" - "The %s public key %s could not be decompressed." - which pk_str - | Some _ -> - Some key ) - | Error _e -> - Mina_user_error.raisef ~where:"decoding a public key" - "The %s public key %s could not be decoded." which - pk_str ) - in - let run_snark_worker_flag = - maybe_from_config - (json_to_publickey_compressed_option "snark worker") - "run-snark-worker" run_snark_worker_flag - in - let run_snark_coordinator_flag = - maybe_from_config - (json_to_publickey_compressed_option "snark coordinator") - "run-snark-coordinator" run_snark_coordinator_flag - in - let snark_worker_parallelism_flag = - maybe_from_config YJ.Util.to_int_option "snark-worker-parallelism" - snark_worker_parallelism_flag - in - let coinbase_receiver_flag = - maybe_from_config - (json_to_publickey_compressed_option "coinbase receiver") - "coinbase-receiver" coinbase_receiver_flag - in - let%bind external_ip = - match external_ip_opt with - | None -> - Find_ip.find ~logger - | Some ip -> - return @@ Unix.Inet_addr.of_string ip - in - let bind_ip = - Option.value bind_ip_opt ~default:"0.0.0.0" - |> Unix.Inet_addr.of_string - in - let addrs_and_ports : Node_addrs_and_ports.t = - { external_ip; bind_ip; peer = None; client_port; libp2p_port } - in - let block_production_key = - maybe_from_config YJ.Util.to_string_option "block-producer-key" - block_production_key - in - let block_production_pubkey = - maybe_from_config - (json_to_publickey_compressed_option "block producer") - "block-producer-pubkey" block_production_pubkey - in - let block_production_password = - maybe_from_config YJ.Util.to_string_option "block-producer-password" - block_production_password + let%bind addrs_and_ports = + let%map external_ip = + match external_ip_opt with + | None -> + Find_ip.find ~logger + | Some ip -> + return @@ Unix.Inet_addr.of_string ip + in + let bind_ip = + Option.value bind_ip_opt ~default:"0.0.0.0" + |> Unix.Inet_addr.of_string + in + let client_port = + Option.value ~default:client_port.default client_port.value + in + let libp2p_port = + Option.value ~default:libp2p_port.default libp2p_port.value + in + { Node_addrs_and_ports.external_ip + ; bind_ip + ; peer = None + ; client_port + ; libp2p_port + } in - Option.iter - ~f:(fun password -> - match Sys.getenv Secrets.Keypair.env with - | Some env_pass when not (String.equal env_pass password) -> - [%log warn] - "$envkey environment variable doesn't match value provided \ - on command-line or daemon.json. Using value from $envkey" - ~metadata:[ ("envkey", `String Secrets.Keypair.env) ] - | _ -> - Unix.putenv ~key:Secrets.Keypair.env ~data:password ) - block_production_password ; let%bind block_production_keypair = match ( block_production_key @@ -1186,23 +882,18 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = List.concat [ List.map ~f:Mina_net2.Multiaddr.of_string libp2p_peers_raw ; peer_list_file_contents_or_empty - ; List.map ~f:Mina_net2.Multiaddr.of_string - @@ or_from_config - (Fn.compose Option.some - (YJ.Util.convert_each YJ.Util.to_string) ) - "peers" None ~default:[] ] in let direct_peers = List.map ~f:Mina_net2.Multiaddr.of_string direct_peers_raw in let min_connections = - or_from_config YJ.Util.to_int_option "min-connections" - ~default:Cli_lib.Default.min_connections min_connections + Option.value ~default:Cli_lib.Default.min_connections + min_connections in let max_connections = - or_from_config YJ.Util.to_int_option "max-connections" - ~default:Cli_lib.Default.max_connections max_connections + Option.value ~default:Cli_lib.Default.max_connections + max_connections in let pubsub_v1 = Gossip_net.Libp2p.N in (* TODO uncomment after introducing Bitswap-based block retrieval *) @@ -1211,17 +902,14 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = ~default:Cli_lib.Default.pubsub_v1 pubsub_v1 in *) let pubsub_v0 = - or_from_config to_pubsub_topic_mode_option "pubsub-v0" - ~default:Cli_lib.Default.pubsub_v0 None + Option.value ~default:Cli_lib.Default.pubsub_v0 None in let validation_queue_size = - or_from_config YJ.Util.to_int_option "validation-queue-size" - ~default:Cli_lib.Default.validation_queue_size + Option.value ~default:Cli_lib.Default.validation_queue_size validation_queue_size in let stop_time = - or_from_config YJ.Util.to_int_option "stop-time" - ~default:Cli_lib.Default.stop_time stop_time + Option.value ~default:Cli_lib.Default.stop_time stop_time in if enable_tracing then Mina_tracing.start conf_dir |> don't_wait_for ; let%bind () = @@ -1230,13 +918,6 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = `Enabled else Deferred.unit in - let seed_peer_list_url = - Option.value_map seed_peer_list_url ~f:Option.some - ~default: - (Option.bind config.daemon - ~f:(fun { Runtime_config.Daemon.peer_list_url; _ } -> - peer_list_url ) ) - in if is_seed then [%log info] "Starting node as a seed node" else if demo_mode then [%log info] "Starting node in demo mode" else if @@ -1275,14 +956,14 @@ Pass one of -peer, -peer-list-file, -seed, -peer-list-url.|} ; ; addrs_and_ports ; metrics_port = libp2p_metrics_port ; trust_system - ; flooding = Option.value ~default:false enable_flooding + ; flooding = enable_flooding ; direct_peers ; peer_protection_ratio - ; peer_exchange = Option.value ~default:false peer_exchange + ; peer_exchange ; min_connections ; max_connections ; validation_queue_size - ; isolate = Option.value ~default:false isolate + ; isolate ; keypair = libp2p_keypair ; all_peers_seen_metric ; known_private_ip_nets = @@ -1392,18 +1073,18 @@ Pass one of -peer, -peer-list-file, -seed, -peer-list-url.|} ; ~wallets_disk_location:(conf_dir ^/ "wallets") ~persistent_root_location:(conf_dir ^/ "root") ~persistent_frontier_location:(conf_dir ^/ "frontier") - ~epoch_ledger_location ~snark_work_fee:snark_work_fee_flag - ~time_controller ~block_production_keypairs ~monitor - ~consensus_local_state ~is_archive_rocksdb - ~work_reassignment_wait ~archive_process_location - ~log_block_creation ~precomputed_values ~start_time - ?precomputed_blocks_path ~log_precomputed_blocks - ~start_filtered_logs ~upload_blocks_to_gcloud - ~block_reward_threshold ~uptime_url ~uptime_submitter_keypair - ~uptime_send_node_commit ~stop_time ~node_status_url - ~graphql_control_port:itn_graphql_port ~simplified_node_stats + ~epoch_ledger_location ~snark_work_fee ~time_controller + ~block_production_keypairs ~monitor ~consensus_local_state + ~is_archive_rocksdb ~work_reassignment_wait + ~archive_process_location ~log_block_creation + ~precomputed_values ~start_time ?precomputed_blocks_path + ~log_precomputed_blocks ~start_filtered_logs + ~upload_blocks_to_gcloud ~block_reward_threshold ~uptime_url + ~uptime_submitter_keypair ~uptime_send_node_commit ~stop_time + ~node_status_url ~graphql_control_port:itn_graphql_port + ~simplified_node_stats ~zkapp_cmd_limit:(ref compile_config.zkapp_cmd_limit) - ~compile_config () ) + ~runtime_config:config () ) in { mina ; client_trustlist @@ -1462,12 +1143,9 @@ Pass one of -peer, -peer-list-file, -seed, -peer-list-url.|} ; let () = Mina_plugins.init_plugins ~logger mina plugins in return mina ) -let daemon logger = - let compile_config = Mina_compile_config.Compiled.t in +let daemon logger ~itn_features = Command.async ~summary:"Mina daemon" - (Command.Param.map - (setup_daemon logger ~itn_features:compile_config.itn_features - ~default_snark_worker_fee:compile_config.default_snark_worker_fee ) + (Command.Param.map (setup_daemon logger ~itn_features) ~f:(fun setup_daemon () -> (* Immediately disable updating the time offset. *) Block_time.Controller.disable_setting_offset () ; @@ -1476,7 +1154,7 @@ let daemon logger = [%log info] "Daemon ready. Clients can now connect" ; Async.never () ) ) -let replay_blocks logger = +let replay_blocks logger ~itn_features = let replay_flag = let open Command.Param in flag "--blocks-filename" ~aliases:[ "-blocks-filename" ] (required string) @@ -1487,11 +1165,9 @@ let replay_blocks logger = flag "--format" ~aliases:[ "-format" ] (optional string) ~doc:"json|sexp The format to read lines of the file in (default: json)" in - let compile_config = Mina_compile_config.Compiled.t in Command.async ~summary:"Start mina daemon with blocks replayed from a file" (Command.Param.map3 replay_flag read_kind - (setup_daemon logger ~itn_features:compile_config.itn_features - ~default_snark_worker_fee:compile_config.default_snark_worker_fee ) + (setup_daemon logger ~itn_features) ~f:(fun blocks_filename read_kind setup_daemon () -> (* Enable updating the time offset. *) Block_time.Controller.enable_setting_offset () ; @@ -1683,34 +1359,37 @@ let snark_hashes = let json = Cli_lib.Flag.json in fun () -> if json then Core.printf "[]\n%!"] -let internal_commands logger = +let internal_commands logger ~itn_features = [ ( Snark_worker.Intf.command_name - , Snark_worker.command ~proof_level:Genesis_constants.Compiled.proof_level - ~constraint_constants:Genesis_constants.Compiled.constraint_constants - ~commit_id:Mina_version.commit_id ) + , Snark_worker.command ~commit_id:Mina_version.commit_id ) ; ("snark-hashes", snark_hashes) ; ( "run-prover" , Command.async ~summary:"Run prover on a sexp provided on a single line of stdin" - (Command.Param.return (fun () -> - let logger = Logger.create () in - let constraint_constants = - Genesis_constants.Compiled.constraint_constants - in - let proof_level = Genesis_constants.Compiled.proof_level in - Parallel.init_master () ; - match%bind Reader.read_sexp (Lazy.force Reader.stdin) with - | `Ok sexp -> - let%bind conf_dir = Unix.mkdtemp "/tmp/mina-prover" in - [%log info] "Prover state being logged to %s" conf_dir ; - let%bind prover = - Prover.create ~commit_id:Mina_version.commit_id ~logger - ~proof_level ~constraint_constants - ~pids:(Pid.Table.create ()) ~conf_dir () - in - Prover.prove_from_input_sexp prover sexp >>| ignore - | `Eof -> - failwith "early EOF while reading sexp" ) ) ) + (let open Command.Let_syntax in + let%map_open config_file = Cli_lib.Flag.conf_file in + fun () -> + let logger = Logger.create () in + let open Deferred.Let_syntax in + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file () + in + let { Runtime_config.Constraint.constraint_constants; proof_level } = + config.constraint_config + in + Parallel.init_master () ; + match%bind Reader.read_sexp (Lazy.force Reader.stdin) with + | `Ok sexp -> + let%bind conf_dir = Unix.mkdtemp "/tmp/mina-prover" in + [%log info] "Prover state being logged to %s" conf_dir ; + let%bind prover = + Prover.create ~commit_id:Mina_version.commit_id ~logger + ~proof_level ~constraint_constants ~pids:(Pid.Table.create ()) + ~conf_dir () + in + Prover.prove_from_input_sexp prover sexp >>| ignore + | `Eof -> + failwith "early EOF while reading sexp") ) ; ( "run-snark-worker-single" , Command.async ~summary:"Run snark-worker on a sexp provided on a single line of stdin" @@ -1718,14 +1397,16 @@ let internal_commands logger = let%map_open filename = flag "--file" (required string) ~doc:"File containing the s-expression of the snark work to execute" - in + and config_file = Cli_lib.Flag.conf_file in fun () -> let open Deferred.Let_syntax in let logger = Logger.create () in - let constraint_constants = - Genesis_constants.Compiled.constraint_constants + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file () + in + let { Runtime_config.Constraint.constraint_constants; proof_level } = + config.constraint_config in - let proof_level = Genesis_constants.Compiled.proof_level in Parallel.init_master () ; match%bind Reader.with_file filename ~f:(fun reader -> @@ -1769,14 +1450,16 @@ let internal_commands logger = and format = flag "--format" ~aliases:[ "-format" ] (optional string) ~doc:"sexp/json the format to parse input in" - in + and config_file = Cli_lib.Flag.conf_file in fun () -> let open Async in let logger = Logger.create () in - let constraint_constants = - Genesis_constants.Compiled.constraint_constants + let%bind config = + Runtime_config.Config_loader.load_config_exn ~config_file () + in + let { Runtime_config.Constraint.constraint_constants; proof_level } = + config.constraint_config in - let proof_level = Genesis_constants.Compiled.proof_level in Parallel.init_master () ; let%bind conf_dir = Unix.mkdtemp "/tmp/mina-verifier" in let mode = @@ -1909,46 +1592,32 @@ let internal_commands logger = () ) ; Deferred.return ()) ) ; ("dump-type-shapes", dump_type_shapes) - ; ("replay-blocks", replay_blocks logger) + ; ("replay-blocks", replay_blocks logger ~itn_features) ; ("audit-type-shapes", audit_type_shapes) ; ( "test-genesis-block-generation" , Command.async ~summary:"Generate a genesis proof" (let open Command.Let_syntax in - let%map_open config_files = - flag "--config-file" ~aliases:[ "config-file" ] - ~doc: - "PATH path to a configuration file (overrides MINA_CONFIG_FILE, \ - default: /daemon.json). Pass multiple times to \ - override fields from earlier config files" - (listed string) - and conf_dir = Cli_lib.Flag.conf_dir + let%map_open conf_dir = Cli_lib.Flag.conf_dir and genesis_dir = flag "--genesis-ledger-dir" ~aliases:[ "genesis-ledger-dir" ] ~doc: "DIR Directory that contains the genesis ledger and the genesis \ blockchain proof (default: )" (optional string) - in + and config_file = Cli_lib.Flag.conf_file in fun () -> let open Deferred.Let_syntax in Parallel.init_master () ; let logger = Logger.create () in let conf_dir = Mina_lib.Conf_dir.compute_conf_dir conf_dir in - let genesis_constants = - Genesis_constants.Compiled.genesis_constants - in - let constraint_constants = - Genesis_constants.Compiled.constraint_constants - in - let proof_level = Genesis_constants.Proof_level.Full in - let config_files = - List.map config_files ~f:(fun config_file -> - (config_file, `Must_exist) ) - in - let%bind precomputed_values, _config_jsons, _config = - load_config_files ~logger ~conf_dir ~genesis_dir ~genesis_constants - ~constraint_constants ~proof_level config_files - ~cli_proof_level:None + let%bind precomputed_values, _ = + let%bind config = + Runtime_config.Config_loader.load_config_exn ~cli_proof_level:Full + ~config_file () + in + Deferred.Or_error.ok_exn + @@ Genesis_ledger_helper.Config_initializer.initialize ?genesis_dir + ~logger config in let pids = Child_processes.Termination.create_pid_table () in let%bind prover = @@ -1956,7 +1625,7 @@ let internal_commands logger = realistic test. *) Prover.create ~commit_id:Mina_version.commit_id ~logger ~pids - ~conf_dir ~proof_level + ~conf_dir ~proof_level:precomputed_values.proof_level ~constraint_constants:precomputed_values.constraint_constants () in match%bind @@ -1976,13 +1645,14 @@ let internal_commands logger = let mina_commands logger ~itn_features = [ ("accounts", Client.accounts) - ; ("daemon", daemon logger) + ; ("daemon", daemon logger ~itn_features) ; ("client", Client.client) ; ("advanced", Client.advanced ~itn_features) ; ("ledger", Client.ledger) ; ("libp2p", Client.libp2p) ; ( "internal" - , Command.group ~summary:"Internal commands" (internal_commands logger) ) + , Command.group ~summary:"Internal commands" + (internal_commands logger ~itn_features) ) ; (Parallel.worker_command_name, Parallel.worker_command) ; ("transaction-snark-profiler", Transaction_snark_profiler.command) ] @@ -2004,6 +1674,11 @@ let print_version_help coda_exe version = let print_version_info () = Core.printf "Commit %s\n" Mina_version.commit_id +let itn_features_flag = + Command.Param.flag "--open-limited-graphql-port" + ~aliases:[ "open-limited-graphql-port" ] + Command.Param.no_arg ~doc:"enable itn features" + let () = Random.self_init () ; let logger = Logger.create () in @@ -2020,11 +1695,13 @@ let () = | [| _mina_exe; version |] when is_version_cmd version -> Mina_version.print_version () | _ -> - let compile_config = Mina_compile_config.Compiled.t in + let itn_features = + Sys.getenv "MINA_ITN_FEATURES" + |> Option.value_map ~f:bool_of_string ~default:false + in Command.run (Command.group ~summary:"Mina" ~preserve_subcommand_order:() - (mina_commands logger ~itn_features:compile_config.itn_features) ) - ) ; + (mina_commands logger ~itn_features) ) ) ; Core.exit 0 let linkme = () diff --git a/src/lib/runtime_config/runtime_config.ml b/src/lib/runtime_config/runtime_config.ml index 75d9c635117..9ad95bb6295 100644 --- a/src/lib/runtime_config/runtime_config.ml +++ b/src/lib/runtime_config/runtime_config.ml @@ -945,13 +945,15 @@ let make_fork_config ~staged_ledger ~global_slot_since_genesis ~state_hash module type Config_loader = sig val load_config : - ?cli_proof_level:Genesis_constants.Proof_level.t + ?itn_features:bool + -> ?cli_proof_level:Genesis_constants.Proof_level.t -> config_file:string -> unit -> t Deferred.Or_error.t val load_config_exn : - ?cli_proof_level:Genesis_constants.Proof_level.t + ?itn_features:bool + -> ?cli_proof_level:Genesis_constants.Proof_level.t -> config_file:string -> unit -> t Deferred.t @@ -988,7 +990,7 @@ module Config_loader : Config_loader = struct in { constraint_config; genesis_constants; compile_config; ledger; epoch_data } - let load_config ?cli_proof_level ~config_file () = + let load_config ?(itn_features = false) ?cli_proof_level ~config_file () = let open Deferred.Or_error.Let_syntax in let%bind config = load_config_json config_file in let e_config = of_json_layout config in @@ -1001,10 +1003,12 @@ module Config_loader : Config_loader = struct { config.constraint_config with proof_level = Option.value ~default:proof_level cli_proof_level } + ; compile_config = { config.compile_config with itn_features } } | Error e -> Deferred.Or_error.error_string e - let load_config_exn ?cli_proof_level ~config_file () = - Deferred.Or_error.ok_exn @@ load_config ?cli_proof_level ~config_file () + let load_config_exn ?itn_features ?cli_proof_level ~config_file () = + Deferred.Or_error.ok_exn + @@ load_config ?itn_features ?cli_proof_level ~config_file () end diff --git a/src/lib/snark_worker/functor.ml b/src/lib/snark_worker/functor.ml index a62453e2877..f208e38218a 100644 --- a/src/lib/snark_worker/functor.ml +++ b/src/lib/snark_worker/functor.ml @@ -228,7 +228,14 @@ module Make (Inputs : Intf.Inputs_intf) : let main (module Rpcs_versioned : Intf.Rpcs_versioned_S with type Work.ledger_proof = Inputs.Ledger_proof.t ) ~logger - ~proof_level ~constraint_constants daemon_address shutdown_on_disconnect = + ~config_file ~cli_proof_level daemon_address shutdown_on_disconnect = + let%bind config = + Runtime_config.Config_loader.load_config_exn ?cli_proof_level ~config_file + () + in + let { Runtime_config.Constraint.constraint_constants; proof_level } = + config.constraint_config + in let%bind state = Worker_state.create ~constraint_constants ~proof_level () in @@ -340,8 +347,7 @@ module Make (Inputs : Intf.Inputs_intf) : in go () - let command_from_rpcs ~commit_id ~proof_level:default_proof_level - ~constraint_constants + let command_from_rpcs ~commit_id (module Rpcs_versioned : Intf.Rpcs_versioned_S with type Work.ledger_proof = Inputs.Ledger_proof.t ) = Command.async ~summary:"Snark worker" @@ -350,7 +356,7 @@ module Make (Inputs : Intf.Inputs_intf) : flag "--daemon-address" ~aliases:[ "daemon-address" ] (required (Arg_type.create Host_and_port.of_string)) ~doc:"HOST-AND-PORT address daemon is listening on" - and proof_level = + and cli_proof_level = flag "--proof-level" ~aliases:[ "proof-level" ] (optional (Arg_type.create Genesis_constants.Proof_level.of_string)) ~doc:"full|check|none" @@ -360,14 +366,12 @@ module Make (Inputs : Intf.Inputs_intf) : (optional bool) ~doc: "true|false Shutdown when disconnected from daemon (default:true)" + and config_file = Cli_lib.Flag.conf_file and conf_dir = Cli_lib.Flag.conf_dir in fun () -> let logger = Logger.create () ~metadata:[ ("process", `String "Snark Worker") ] in - let proof_level = - Option.value ~default:default_proof_level proof_level - in Option.value_map ~default:() conf_dir ~f:(fun conf_dir -> let logrotate_max_size = 1024 * 10 in let logrotate_num_rotate = 1 in @@ -385,7 +389,7 @@ module Make (Inputs : Intf.Inputs_intf) : Core.exit 0 ) ; main (module Rpcs_versioned) - ~logger ~proof_level ~constraint_constants daemon_port + ~logger ~config_file ~cli_proof_level daemon_port (Option.value ~default:true shutdown_on_disconnect)) let arguments ~proof_level ~daemon_address ~shutdown_on_disconnect = diff --git a/src/lib/snark_worker/intf.ml b/src/lib/snark_worker/intf.ml index 9173d066d9c..2a9d93bb03c 100644 --- a/src/lib/snark_worker/intf.ml +++ b/src/lib/snark_worker/intf.ml @@ -154,8 +154,6 @@ module type S0 = sig val command_from_rpcs : commit_id:string - -> proof_level:Genesis_constants.Proof_level.t - -> constraint_constants:Genesis_constants.Constraint_constants.t -> (module Rpcs_versioned_S with type Work.ledger_proof = ledger_proof) -> Command.t @@ -173,9 +171,5 @@ module type S = sig module Rpcs_versioned : Rpcs_versioned_S with type Work.ledger_proof = ledger_proof - val command : - commit_id:string - -> proof_level:Genesis_constants.Proof_level.t - -> constraint_constants:Genesis_constants.Constraint_constants.t - -> Command.t + val command : commit_id:string -> Command.t end From 626566566aca79c8efe7725c58eb846d93376b1f Mon Sep 17 00:00:00 2001 From: martyall Date: Thu, 19 Sep 2024 16:02:48 -0700 Subject: [PATCH 29/29] rework test executive config for sanity sake --- .../mina_automation.ml | 110 +++++++----------- src/lib/integration_test_lib/intf.ml | 1 - src/lib/integration_test_lib/test_config.ml | 73 +++++------- .../mina_docker.ml | 62 +++------- 4 files changed, 91 insertions(+), 155 deletions(-) diff --git a/src/lib/integration_test_cloud_engine/mina_automation.ml b/src/lib/integration_test_cloud_engine/mina_automation.ml index 420b9aab7cc..6def8424b57 100644 --- a/src/lib/integration_test_cloud_engine/mina_automation.ml +++ b/src/lib/integration_test_cloud_engine/mina_automation.ml @@ -109,28 +109,19 @@ module Network_config = struct assoc let expand ~logger:_ ~test_name ~(cli_inputs : Cli_inputs.t) ~(debug : bool) - ~(images : Test_config.Container_images.t) ~test_config - ~(constants : Test_config.constants) = + ~(images : Test_config.Container_images.t) ~test_config = let ({ requires_graphql ; genesis_ledger ; epoch_data ; block_producers ; snark_coordinator - ; snark_worker_fee ; num_archive_nodes ; log_precomputed_blocks (* ; num_plain_nodes *) ; start_filtered_logs - ; proof_config - ; k - ; delta - ; slots_per_epoch - ; slots_per_sub_window - ; grace_period_slots - ; txpool_max_size - ; slot_tx_end - ; slot_chain_end - ; network_id - ; _ + ; genesis_constants + ; constraint_constants + ; compile_config + ; proof_level } : Test_config.t ) = test_config @@ -227,53 +218,20 @@ module Network_config = struct -> String.equal name1 name2 ) in let runtime_config = - { Runtime_config.compile_config = - { constants.compile_config with - network_id = - Option.value ~default:constants.compile_config.network_id - network_id - ; slot_tx_end = - Option.map ~f:Mina_numbers.Global_slot_since_hard_fork.of_int - slot_tx_end - ; slot_chain_end = - Option.map ~f:Mina_numbers.Global_slot_since_hard_fork.of_int - slot_chain_end - } - (* - { txpool_max_size = Some txpool_max_size - ; peer_list_url = None - ; zkapp_proof_update_cost = None - ; zkapp_signed_single_update_cost = None - ; zkapp_signed_pair_update_cost = None - ; zkapp_transaction_cost_limit = None - ; max_event_elements = None - ; max_action_elements = None - ; zkapp_cmd_limit_hardcap = None - ; slot_tx_end - ; slot_chain_end - ; minimum_user_command_fee = None - ; network_id - } -*) + { Runtime_config.compile_config ; genesis_constants = - { constants.genesis_constants with + { genesis_constants with protocol = - { k - ; delta - ; slots_per_epoch - ; slots_per_sub_window - ; grace_period_slots - ; genesis_state_timestamp = - (let t = Core.Time.(to_string_abs ~zone:Zone.utc (now ())) in - Genesis_constants.genesis_timestamp_of_string t - |> Genesis_constants.of_time ) + { genesis_constants.protocol with + genesis_state_timestamp = + Genesis_constants.( + genesis_timestamp_of_string + Core.Time.(to_string_abs ~zone:Zone.utc (now ())) + |> of_time) } - ; txpool_max_size } ; constraint_config = - { proof_level = constants.proof_level - ; constraint_constants = proof_config - } + { Runtime_config.Constraint.constraint_constants; proof_level } ; ledger = { base = Accounts @@ -390,13 +348,6 @@ module Network_config = struct ({ staking; next } : Runtime_config.Epoch_data.t) ) } in - let constants : Test_config.constants = - { constants with - genesis_constants = runtime_config.genesis_constants - ; constraint_constants = - runtime_config.constraint_config.constraint_constants - } - in (* BLOCK PRODUCER CONFIG *) let mk_net_keypair keypair_name (pk, sk) = let keypair = @@ -482,7 +433,8 @@ module Network_config = struct { mina_automation_location = cli_inputs.mina_automation_location ; debug_arg = debug ; genesis_keypairs - ; constants + ; constants = + { genesis_constants; constraint_constants; compile_config; proof_level } ; terraform = { cluster_name ; cluster_region @@ -502,7 +454,8 @@ module Network_config = struct ; mina_archive_schema ; mina_archive_schema_aux_files ; snark_coordinator_config - ; snark_worker_fee + ; snark_worker_fee = + Currency.Fee.to_mina_string compile_config.default_snark_worker_fee ; aws_route53_zone_id ; cpu_request = 6 ; mem_request = "12Gi" @@ -693,6 +646,33 @@ module Network_manager = struct | None -> (Core.String.Map.of_alist_exn [], Core.String.Map.of_alist_exn []) in + (* + let snark_coordinator_id = + String.lowercase + (String.sub network_config.terraform.snark_worker_public_key + ~pos: + (String.length network_config.terraform.snark_worker_public_key - 6) + ~len:6 ) + in + let snark_coordinator_workloads = + if network_config.terraform.snark_worker_replicas > 0 then + [ Kubernetes_network.Workload_to_deploy.construct_workload + ("snark-coordinator-" ^ snark_coordinator_id) + [ Kubernetes_network.Workload_to_deploy.cons_pod_info "mina" ] + ] + else [] + in + let snark_worker_workloads = + if network_config.terraform.snark_worker_replicas > 0 then + [ Kubernetes_network.Workload_to_deploy.construct_workload + ("snark-worker-" ^ snark_coordinator_id) + (List.init network_config.terraform.snark_worker_replicas + ~f:(fun _i -> + Kubernetes_network.Workload_to_deploy.cons_pod_info "worker" ) + ) + ] + else [] + in *) let block_producer_workloads = List.map network_config.terraform.block_producer_configs ~f:(fun bp_config -> diff --git a/src/lib/integration_test_lib/intf.ml b/src/lib/integration_test_lib/intf.ml index 0fa9687f858..baacfe7c1cd 100644 --- a/src/lib/integration_test_lib/intf.ml +++ b/src/lib/integration_test_lib/intf.ml @@ -39,7 +39,6 @@ module Engine = struct -> debug:bool -> images:Test_config.Container_images.t -> test_config:Test_config.t - -> constants:Test_config.constants -> t end diff --git a/src/lib/integration_test_lib/test_config.ml b/src/lib/integration_test_lib/test_config.ml index 2cfaf78026d..e3f2b58f1ff 100644 --- a/src/lib/integration_test_lib/test_config.ml +++ b/src/lib/integration_test_lib/test_config.ml @@ -59,6 +59,18 @@ type constants = } [@@deriving to_yojson] +let log_filter_of_event_type ev_existential = + let open Event_type in + let (Event_type ev_type) = ev_existential in + let (module Ty) = event_type_module ev_type in + match Ty.parse with + | From_error_log _ -> + [] (* TODO: Do we need this? *) + | From_daemon_log (struct_id, _) -> + [ Structured_log_events.string_of_id struct_id ] + | From_puppeteer_log _ -> + [] + type t = { requires_graphql : bool (* temporary flag to enable/disable graphql ingress deployments *) @@ -67,41 +79,18 @@ type t = ; epoch_data : Epoch_data.t option ; block_producers : Block_producer_node.t list ; snark_coordinator : Snark_coordinator_node.t option - ; snark_worker_fee : string ; num_archive_nodes : int ; log_precomputed_blocks : bool ; start_filtered_logs : string list - (* ; num_plain_nodes : int *) - (* blockchain constants *) - ; proof_config : Genesis_constants.Constraint_constants.t - ; k : int - ; delta : int - ; slots_per_epoch : int - ; slots_per_sub_window : int - ; grace_period_slots : int - ; txpool_max_size : int - ; slot_tx_end : int option - ; slot_chain_end : int option - ; network_id : string option - ; block_window_duration_ms : int - ; transaction_capacity_log_2 : int + ; genesis_constants : Genesis_constants.t + ; constraint_constants : Genesis_constants.Constraint_constants.t + ; proof_level : Genesis_constants.Proof_level.t + ; compile_config : Mina_compile_config.t } -let log_filter_of_event_type ev_existential = - let open Event_type in - let (Event_type ev_type) = ev_existential in - let (module Ty) = event_type_module ev_type in - match Ty.parse with - | From_error_log _ -> - [] (* TODO: Do we need this? *) - | From_daemon_log (struct_id, _) -> - [ Structured_log_events.string_of_id struct_id ] - | From_puppeteer_log _ -> - [] (* TODO: Do we need this? *) let default ~(constants : constants) = - let { constraint_constants; genesis_constants; _ } = constants in { requires_graphql = true (* require_graphql maybe should just be phased out, because it always needs to be enable. Now with the graphql polling engine, everything will definitely fail if graphql is not enabled. But even before that, most tests relied on some sort of graphql interaction *) @@ -109,34 +98,28 @@ let default ~(constants : constants) = ; epoch_data = None ; block_producers = [] ; snark_coordinator = None - ; snark_worker_fee = "0.025" ; num_archive_nodes = 0 - ; log_precomputed_blocks = false (* ; num_plain_nodes = 0 *) + ; log_precomputed_blocks = false ; start_filtered_logs = List.bind ~f:log_filter_of_event_type Event_type.all_event_types - ; proof_config = - { constraint_constants with block_window_duration_ms = 12000 } - ; k = genesis_constants.protocol.k - ; slots_per_epoch = genesis_constants.protocol.slots_per_epoch - ; slots_per_sub_window = genesis_constants.protocol.slots_per_sub_window - ; grace_period_slots = genesis_constants.protocol.grace_period_slots - ; delta = genesis_constants.protocol.delta - ; txpool_max_size = genesis_constants.txpool_max_size - ; slot_tx_end = None - ; slot_chain_end = None - ; network_id = None - ; block_window_duration_ms = constraint_constants.block_window_duration_ms - ; transaction_capacity_log_2 = constraint_constants.transaction_capacity_log_2 + ; genesis_constants = constants.genesis_constants + ; constraint_constants = + { constants.constraint_constants with block_window_duration_ms = 120000 } + ; proof_level = Full + ; compile_config = + { constants.compile_config with + default_snark_worker_fee = Currency.Fee.of_mina_string_exn "0.025" + } } let transaction_capacity config = - let i = config.transaction_capacity_log_2 in + let i = config.constraint_constants.transaction_capacity_log_2 in Int.pow 2 i let blocks_for_first_ledger_proof (config : t) = - let work_delay = config.proof_config.work_delay in + let work_delay = config.constraint_constants.work_delay in let transaction_capacity_log_2 = - config.proof_config.transaction_capacity_log_2 + config.constraint_constants.transaction_capacity_log_2 in ((work_delay + 1) * (transaction_capacity_log_2 + 1)) + 1 diff --git a/src/lib/integration_test_local_engine/mina_docker.ml b/src/lib/integration_test_local_engine/mina_docker.ml index 109e477d50b..b4da4b5fee1 100644 --- a/src/lib/integration_test_local_engine/mina_docker.ml +++ b/src/lib/integration_test_local_engine/mina_docker.ml @@ -48,26 +48,19 @@ module Network_config = struct let expand ~logger:_ ~test_name ~(cli_inputs : Cli_inputs.t) ~(debug : bool) ~(images : Test_config.Container_images.t) ~(test_config : Test_config.t) - ~(constants : Test_config.constants) = + = let _ = cli_inputs in let ({ genesis_ledger ; epoch_data ; block_producers ; snark_coordinator - ; snark_worker_fee ; num_archive_nodes ; log_precomputed_blocks (* ; num_plain_nodes *) ; start_filtered_logs - ; proof_config - ; k - ; delta - ; slots_per_epoch - ; slots_per_sub_window - ; grace_period_slots - ; txpool_max_size - ; slot_tx_end - ; slot_chain_end - ; network_id + ; genesis_constants + ; constraint_constants + ; compile_config + ; proof_level ; _ } : Test_config.t ) = @@ -150,37 +143,20 @@ module Network_config = struct -> String.equal name1 name2 ) in let runtime_config = - { Runtime_config.compile_config = - { constants.compile_config with - network_id = - Option.value ~default:constants.compile_config.network_id - network_id - ; slot_tx_end = - Option.map ~f:Mina_numbers.Global_slot_since_hard_fork.of_int - slot_tx_end - ; slot_chain_end = - Option.map ~f:Mina_numbers.Global_slot_since_hard_fork.of_int - slot_chain_end - } + { Runtime_config.compile_config ; genesis_constants = - { constants.genesis_constants with + { genesis_constants with protocol = - { k - ; delta - ; slots_per_epoch - ; slots_per_sub_window - ; grace_period_slots - ; genesis_state_timestamp = - (let t = Core.Time.(to_string_abs ~zone:Zone.utc (now ())) in - Genesis_constants.genesis_timestamp_of_string t - |> Genesis_constants.of_time ) + { genesis_constants.protocol with + genesis_state_timestamp = + Genesis_constants.( + genesis_timestamp_of_string + Core.Time.(to_string_abs ~zone:Zone.utc (now ())) + |> of_time) } - ; txpool_max_size } ; constraint_config = - { proof_level = constants.proof_level - ; constraint_constants = proof_config - } + { Runtime_config.Constraint.constraint_constants; proof_level } ; ledger = { base = Accounts @@ -278,11 +254,7 @@ module Network_config = struct } in let constants : Test_config.constants = - { constants with - genesis_constants = runtime_config.genesis_constants - ; constraint_constants = - runtime_config.constraint_config.constraint_constants - } + { genesis_constants; constraint_constants; compile_config; proof_level } in let mk_net_keypair keypair_name (pk, sk) = let keypair = @@ -531,7 +503,9 @@ module Network_config = struct in let snark_coordinator_config : Snark_coordinator_config.config = { worker_nodes - ; snark_worker_fee + ; snark_worker_fee = + Currency.Fee.to_mina_string + compile_config.default_snark_worker_fee ; snark_coordinator_key = public_key ; work_selection = "seq" ; base_config =