From efe604932606174049be5ad9ca8e5ee24c5cb0f1 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 28 Jan 2025 23:40:48 +0000 Subject: [PATCH 01/16] Revert "Merge pull request #16538 from MinaProtocol/feature/stop-useless-logging" This reverts commit a2aac90c3b93e00515d265ca142634a26422d15e, reversing changes made to 9b8de11c258a5b9e6ddeaee26a7396170fa7da46. --- src/lib/runtime_config/runtime_config.ml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lib/runtime_config/runtime_config.ml b/src/lib/runtime_config/runtime_config.ml index f67088b8cfe..b0b4f6d3ae3 100644 --- a/src/lib/runtime_config/runtime_config.ml +++ b/src/lib/runtime_config/runtime_config.ml @@ -1775,9 +1775,8 @@ module Json_loader : Json_loader_intf = struct let config_files_paths = List.map config_files ~f:(fun (config_file, _) -> `String config_file) in - if not (List.is_empty config_files_paths) then - [%log info] "Reading configuration files $config_files" - ~metadata:[ ("config_files", `List config_files_paths) ] ; + [%log info] "Reading configuration files $config_files" + ~metadata:[ ("config_files", `List config_files_paths) ] ; Deferred.Or_error.List.filter_map config_files ~f:(fun (config_file, handle_missing) -> From 9bcecb51909ae1f51e9a7c4cb37f73cf9782ea9e Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 28 Jan 2025 23:40:53 +0000 Subject: [PATCH 02/16] Revert "Merge pull request #16512 from MinaProtocol/georgeee/redo-16186-after-review-fixes" This reverts commit 6c93aa928aece8dcbd3de11200bf09a643fff8bc, reversing changes made to c7e6fc2336710f01166e7da6789129059f103ead. --- .../cli/src/cli_entrypoint/mina_cli_entrypoint.ml | 5 +++-- src/app/cli/src/init/client.ml | 2 ++ .../genesis_ledger_helper/genesis_ledger_helper.ml | 8 ++++---- src/lib/runtime_config/runtime_config.ml | 14 +++++++++----- 4 files changed, 18 insertions(+), 11 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 caf57889cab..441d7329f59 100644 --- a/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml +++ b/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml @@ -228,8 +228,9 @@ let setup_daemon logger ~itn_features = and snark_work_fee = flag "--snark-worker-fee" ~aliases:[ "snark-worker-fee" ] ~doc: - "FEE Amount a worker wants to get compensated for generating a snark \ - proof" + (sprintf + "FEE Amount a worker wants to get compensated for generating a \ + snark proof" ) (optional txn_fee) and work_reassignment_wait = flag "--work-reassignment-wait" diff --git a/src/app/cli/src/init/client.ml b/src/app/cli/src/init/client.ml index ffdb99d30dc..39c55a4a02a 100644 --- a/src/app/cli/src/init/client.ml +++ b/src/app/cli/src/init/client.ml @@ -567,6 +567,7 @@ let send_payment_graphql = graphql_endpoint ({ Cli_lib.Flag.sender; fee; nonce; memo }, receiver, amount) -> + let open Deferred.Let_syntax in let fee = Option.value ~default:default_transaction_fee fee in let%map response = let input = @@ -595,6 +596,7 @@ let delegate_stake_graphql = graphql_endpoint ({ Cli_lib.Flag.sender; fee; nonce; memo }, receiver) -> + let open Deferred.Let_syntax in let fee = Option.value ~default:default_transaction_fee fee in let%map response = Graphql_client.query_exn diff --git a/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml b/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml index 39c93dd40f8..4871d48c26a 100644 --- a/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml +++ b/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml @@ -847,14 +847,14 @@ module Config_loader : Config_loader_intf = struct let%map.Option conf_dir = conf_dir in Option.value ~default:(conf_dir ^/ "genesis") genesis_dir in + let%bind.Deferred constants = + Runtime_config.Constants.load_constants_with_logging ?conf_dir + ?cli_proof_level ~logger ~itn_features config_files + in let%bind config = Runtime_config.Json_loader.load_config_files ?conf_dir ~logger config_files in - let constants = - Runtime_config.Constants.load_constants' ?cli_proof_level ~itn_features - config - in match%bind.Deferred init_from_config_file ?overwrite_version ?genesis_dir ~logger ~constants config diff --git a/src/lib/runtime_config/runtime_config.ml b/src/lib/runtime_config/runtime_config.ml index b0b4f6d3ae3..4a17bd9b725 100644 --- a/src/lib/runtime_config/runtime_config.ml +++ b/src/lib/runtime_config/runtime_config.ml @@ -2038,11 +2038,15 @@ module Constants : Constants_intf = struct (* Use this function if you don't need/want the ledger configuration *) let load_constants_with_logging ?conf_dir ?commit_id_short ?itn_features ?cli_proof_level ~logger config_files = - Deferred.Or_error.( - ok_exn - ( Json_loader.load_config_files ?conf_dir ?commit_id_short ~logger - config_files - >>| load_constants' ?itn_features ?cli_proof_level )) + (* do not log reading compile time constants as this impacs cli command output *) + Deferred.Or_error.ok_exn + @@ + let open Deferred.Or_error.Let_syntax in + let%map runtime_config = + Json_loader.load_config_files ?conf_dir ?commit_id_short ~logger + config_files + in + load_constants' ?itn_features ?cli_proof_level runtime_config let load_constants = load_constants_with_logging ~logger:(Logger.null ()) From 939896b7a060ab4d4e5dc1257f2f4ec5bc769ef0 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 28 Jan 2025 23:40:59 +0000 Subject: [PATCH 03/16] Revert "Merge pull request #16403 from MinaProtocol/sai/removing-logging-from-cfg-loading" This reverts commit c3c7c34b0719c016239f83c770603eb7768f9adc, reversing changes made to 40c86e21cb660860106dddd9134c4de861eebf9e. --- src/app/batch_txn_tool/batch_txn_tool.ml | 3 +-- .../src/cli_entrypoint/mina_cli_entrypoint.ml | 9 +++---- src/app/cli/src/init/client.ml | 25 +++++++++++++------ .../delegation_verify/delegation_verify.ml | 2 +- src/lib/cli_lib/commands.ml | 15 ++++++++--- .../genesis_ledger_helper.ml | 4 +-- src/lib/pickles/snarky_tests/snarky_tests.ml | 3 ++- src/lib/runtime_config/runtime_config.ml | 16 ++---------- src/lib/snark_worker/functor.ml | 4 +-- .../standalone/run_snark_worker.ml | 5 ++-- 10 files changed, 45 insertions(+), 41 deletions(-) diff --git a/src/app/batch_txn_tool/batch_txn_tool.ml b/src/app/batch_txn_tool/batch_txn_tool.ml index 81b233acae3..9331c5a4207 100644 --- a/src/app/batch_txn_tool/batch_txn_tool.ml +++ b/src/app/batch_txn_tool/batch_txn_tool.ml @@ -400,8 +400,7 @@ let output_there_and_back_cmds = let logger = Logger.create () in let%bind minimum_user_command_fee = let%map conf = - Runtime_config.Constants.load_constants_with_logging ~logger - config_file + Runtime_config.Constants.load_constants ~logger config_file in Option.value ~default: 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 441d7329f59..491c63c8125 100644 --- a/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml +++ b/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml @@ -1567,8 +1567,7 @@ let internal_commands ~itn_features logger = let open Deferred.Let_syntax in let%bind constraint_constants, proof_level, compile_config = let%map conf = - Runtime_config.Constants.load_constants_with_logging ~logger - config_file + Runtime_config.Constants.load_constants ~logger config_file in Runtime_config.Constants. (constraint_constants conf, proof_level conf, compile_config conf) @@ -1600,8 +1599,7 @@ let internal_commands ~itn_features logger = let open Deferred.Let_syntax in let%bind constraint_constants, proof_level, compile_config = let%map conf = - Runtime_config.Constants.load_constants_with_logging ~logger - config_file + Runtime_config.Constants.load_constants ~logger config_file in Runtime_config.Constants. (constraint_constants conf, proof_level conf, compile_config conf) @@ -1658,8 +1656,7 @@ let internal_commands ~itn_features logger = let open Async in let%bind constraint_constants, proof_level, compile_config = let%map conf = - Runtime_config.Constants.load_constants_with_logging ~logger - config_file + Runtime_config.Constants.load_constants ~logger config_file in Runtime_config.Constants. (constraint_constants conf, proof_level conf, compile_config conf) diff --git a/src/app/cli/src/init/client.ml b/src/app/cli/src/init/client.ml index 39c55a4a02a..ca4ecd202c2 100644 --- a/src/app/cli/src/init/client.ml +++ b/src/app/cli/src/init/client.ml @@ -43,8 +43,8 @@ let or_error_str ~f_ok ~error = function | Error e -> sprintf "%s\n%s\n" error (Error.to_string_hum e) -let load_compile_config config_files = - let%map conf = Runtime_config.Constants.load_constants config_files in +let load_compile_config ?(logger = Logger.null ()) config_files = + let%map conf = Runtime_config.Constants.load_constants ~logger config_files in Runtime_config.Constants.compile_config conf let stop_daemon = @@ -865,7 +865,10 @@ let hash_ledger = fun () -> let open Deferred.Let_syntax in let%bind constraint_constants = - let%map conf = Runtime_config.Constants.load_constants config_files in + let logger = Logger.create () in + let%map conf = + Runtime_config.Constants.load_constants ~logger config_files + in Runtime_config.Constants.constraint_constants conf in let process_accounts accounts = @@ -973,7 +976,10 @@ let constraint_system_digests = fun () -> let open Deferred.Let_syntax in let%bind constraint_constants, proof_level = - let%map conf = Runtime_config.Constants.load_constants config_files in + let logger = Logger.create () in + let%map conf = + Runtime_config.Constants.load_constants ~logger config_files + in Runtime_config.Constants.(constraint_constants conf, proof_level conf) in let all = @@ -1864,7 +1870,7 @@ let compile_time_constants = let%map ({ consensus_constants; _ } as precomputed_values), _ = (* This is kind of ugly because we are allowing for supplying a runtime_config value directly, rather than force what is read from the environment *) (* TODO: See if we can initialize consensus_constants without also initializing the ledger *) - let logger = Logger.null () in + let logger = Logger.create () in let%bind m_conf = Runtime_config.Json_loader.load_config_files ~conf_dir ~logger config_files @@ -2388,9 +2394,9 @@ let test_ledger_application = @@ fun () -> let open Deferred.Let_syntax in let%bind genesis_constants, constraint_constants = + let logger = Logger.create () in let%map conf = - Runtime_config.Constants.load_constants_with_logging - ~logger:(Logger.create ()) config_files + Runtime_config.Constants.load_constants ~logger config_files in Runtime_config.Constants. (genesis_constants conf, constraint_constants conf) @@ -2436,7 +2442,10 @@ let itn_create_accounts = -> let open Deferred.Let_syntax in let%bind genesis_constants, constraint_constants, compile_config = - let%map conf = Runtime_config.Constants.load_constants config_files in + let logger = Logger.create () in + let%map conf = + Runtime_config.Constants.load_constants ~logger config_files + in Runtime_config.Constants. ( genesis_constants conf , constraint_constants conf diff --git a/src/app/delegation_verify/delegation_verify.ml b/src/app/delegation_verify/delegation_verify.ml index 0d90a7204a2..ac643b1db67 100644 --- a/src/app/delegation_verify/delegation_verify.ml +++ b/src/app/delegation_verify/delegation_verify.ml @@ -45,7 +45,7 @@ let timestamp = let instantiate_verify_functions ~logger config_file = let open Deferred.Let_syntax in let%map constants = - Runtime_config.Constants.load_constants_with_logging ~logger config_file + Runtime_config.Constants.load_constants ~logger config_file in let constraint_constants = Runtime_config.Constants.constraint_constants constants diff --git a/src/lib/cli_lib/commands.ml b/src/lib/cli_lib/commands.ml index cdc6bd4299f..4467e4cb915 100644 --- a/src/lib/cli_lib/commands.ml +++ b/src/lib/cli_lib/commands.ml @@ -236,7 +236,10 @@ module Vrf = struct let env = Secrets.Keypair.env in let open Deferred.Let_syntax in let%bind constraint_constants = - let%map conf = Runtime_config.Constants.load_constants config_file in + let logger = Logger.create () in + let%map conf = + Runtime_config.Constants.load_constants ~logger config_file + in Runtime_config.Constants.constraint_constants conf in if Option.is_some (Sys.getenv env) then @@ -307,7 +310,10 @@ module Vrf = struct eprintf "Using password from environment variable %s\n" env ; let open Deferred.Let_syntax in let%bind constraint_constants = - let%map conf = Runtime_config.Constants.load_constants config_file in + let logger = Logger.create () in + let%map conf = + Runtime_config.Constants.load_constants ~logger config_file + in Runtime_config.Constants.constraint_constants conf in let%bind () = @@ -370,7 +376,10 @@ module Vrf = struct @@ fun () -> let open Deferred.Let_syntax in let%bind constraint_constants = - let%map conf = Runtime_config.Constants.load_constants config_file in + let logger = Logger.create () in + let%map conf = + Runtime_config.Constants.load_constants ~logger config_file + in Runtime_config.Constants.constraint_constants conf in 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 4871d48c26a..afe2056a428 100644 --- a/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml +++ b/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml @@ -848,8 +848,8 @@ module Config_loader : Config_loader_intf = struct Option.value ~default:(conf_dir ^/ "genesis") genesis_dir in let%bind.Deferred constants = - Runtime_config.Constants.load_constants_with_logging ?conf_dir - ?cli_proof_level ~logger ~itn_features config_files + Runtime_config.Constants.load_constants ?conf_dir ?cli_proof_level + ~itn_features ~logger config_files in let%bind config = Runtime_config.Json_loader.load_config_files ?conf_dir ~logger diff --git a/src/lib/pickles/snarky_tests/snarky_tests.ml b/src/lib/pickles/snarky_tests/snarky_tests.ml index 06ef5142b32..82aad430d4b 100644 --- a/src/lib/pickles/snarky_tests/snarky_tests.ml +++ b/src/lib/pickles/snarky_tests/snarky_tests.ml @@ -650,9 +650,10 @@ let () = let range_checks = List.map ~f:QCheck_alcotest.to_alcotest [ RangeCircuits.test_range_gates ] in + let logger = Logger.create () in let%map.Async.Deferred constraint_constants = let%map.Async.Deferred config = - Runtime_config.Constants.load_constants [] + Runtime_config.Constants.load_constants ~logger [] in Runtime_config.Constants.constraint_constants config in diff --git a/src/lib/runtime_config/runtime_config.ml b/src/lib/runtime_config/runtime_config.ml index 4a17bd9b725..a5b9630c6dd 100644 --- a/src/lib/runtime_config/runtime_config.ml +++ b/src/lib/runtime_config/runtime_config.ml @@ -1777,7 +1777,6 @@ module Json_loader : Json_loader_intf = struct in [%log info] "Reading configuration files $config_files" ~metadata:[ ("config_files", `List config_files_paths) ] ; - Deferred.Or_error.List.filter_map config_files ~f:(fun (config_file, handle_missing) -> match%bind.Deferred load_config_file config_file with @@ -1821,14 +1820,6 @@ module type Constants_intf = sig -> ?commit_id_short:string -> ?itn_features:bool -> ?cli_proof_level:Genesis_constants.Proof_level.t - -> string list - -> constants Deferred.t - - val load_constants_with_logging : - ?conf_dir:string - -> ?commit_id_short:string - -> ?itn_features:bool - -> ?cli_proof_level:Genesis_constants.Proof_level.t -> logger:Logger.t -> string list -> constants Deferred.t @@ -2036,9 +2027,8 @@ module Constants : Constants_intf = struct } (* Use this function if you don't need/want the ledger configuration *) - let load_constants_with_logging ?conf_dir ?commit_id_short ?itn_features - ?cli_proof_level ~logger config_files = - (* do not log reading compile time constants as this impacs cli command output *) + let load_constants ?conf_dir ?commit_id_short ?itn_features ?cli_proof_level + ~logger config_files = Deferred.Or_error.ok_exn @@ let open Deferred.Or_error.Let_syntax in @@ -2048,8 +2038,6 @@ module Constants : Constants_intf = struct in load_constants' ?itn_features ?cli_proof_level runtime_config - let load_constants = load_constants_with_logging ~logger:(Logger.null ()) - let magic_for_unit_tests t = let compile_constants = { genesis_constants = Genesis_constants.For_unit_tests.t diff --git a/src/lib/snark_worker/functor.ml b/src/lib/snark_worker/functor.ml index 5c1cdbba827..05c79a0e528 100644 --- a/src/lib/snark_worker/functor.ml +++ b/src/lib/snark_worker/functor.ml @@ -362,8 +362,8 @@ module Make (Inputs : Intf.Inputs_intf) : in let%bind.Deferred constraint_constants, proof_level, compile_config = let%map.Deferred config = - Runtime_config.Constants.load_constants_with_logging ~logger - ?conf_dir ?cli_proof_level config_file + Runtime_config.Constants.load_constants ?conf_dir ?cli_proof_level + ~logger config_file in Runtime_config.Constants. ( constraint_constants config diff --git a/src/lib/snark_worker/standalone/run_snark_worker.ml b/src/lib/snark_worker/standalone/run_snark_worker.ml index 9dc29333f07..9421ccde2b1 100644 --- a/src/lib/snark_worker/standalone/run_snark_worker.ml +++ b/src/lib/snark_worker/standalone/run_snark_worker.ml @@ -107,9 +107,10 @@ let command = let open Async in let open Deferred.Let_syntax in let%bind constraint_constants, proof_level = + let logger = Logger.create () in let%map conf = - Runtime_config.Constants.load_constants_with_logging - ~logger:(Logger.create ()) ~cli_proof_level config_file + Runtime_config.Constants.load_constants ~cli_proof_level ~logger + config_file in Runtime_config.Constants.(constraint_constants conf, proof_level conf) in From af4dfb88985363c66d6f42184477cb3239b00a0b Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 28 Jan 2025 23:41:05 +0000 Subject: [PATCH 04/16] Revert "Merge pull request #16381 from MinaProtocol/sai/fix-compile-config-logging" This reverts commit c701a315ad9b2997250d5f577232c8de839f552c, reversing changes made to 9dbaa6df59e30326d2f0dd62493795cee78a8f29. --- src/app/cli/src/init/client.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/cli/src/init/client.ml b/src/app/cli/src/init/client.ml index ca4ecd202c2..5f7813438dc 100644 --- a/src/app/cli/src/init/client.ml +++ b/src/app/cli/src/init/client.ml @@ -43,7 +43,7 @@ let or_error_str ~f_ok ~error = function | Error e -> sprintf "%s\n%s\n" error (Error.to_string_hum e) -let load_compile_config ?(logger = Logger.null ()) config_files = +let load_compile_config ?(logger = Logger.create ()) config_files = let%map conf = Runtime_config.Constants.load_constants ~logger config_files in Runtime_config.Constants.compile_config conf From 246dfb1c69dd3d726ded4ebe2ebe74cc98cccc17 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 28 Jan 2025 23:43:25 +0000 Subject: [PATCH 05/16] Revert "Merge pull request #16356 from MinaProtocol/martin/provide-full-rt-config-to-graphql" This reverts commit ec43a6b7eaaf4b1acc9e9dc812cd19f5311f51d2, reversing changes made to 4ac4143f28d26e3e52e1c5cb10db862e372ac054. --- .../genesis_ledger_helper.ml | 19 +- .../lib/genesis_ledger_helper_lib.ml | 165 +++++++++ .../mina_docker.ml | 17 +- .../mina_compile_config.ml | 11 +- src/lib/runtime_config/runtime_config.ml | 347 ++++++------------ 5 files changed, 313 insertions(+), 246 deletions(-) diff --git a/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml b/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml index afe2056a428..e3c4b62cbb3 100644 --- a/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml +++ b/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml @@ -808,37 +808,38 @@ module Config_loader : Config_loader_intf = struct in [%log info] "Loaded genesis ledger from $ledger_file" ~metadata:[ ("ledger_file", `String ledger_file) ] ; - let%map genesis_epoch_data, genesis_epoch_data_config = + let%bind genesis_epoch_data, genesis_epoch_data_config = Epoch_data.load ~proof_level ~genesis_dir ~logger ~constraint_constants config.epoch_data in - let c1 = + let config = { config with ledger = Option.map config.ledger ~f:(fun _ -> ledger_config) ; epoch_data = genesis_epoch_data_config } in - let c2 = Runtime_config.of_constants constants in - (* This should give us the entire configuration object, including the implied constants *) - let runtime_config = Runtime_config.combine c1 c2 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 ~proof_level + Genesis_proof.generate_inputs ~runtime_config:config ~proof_level ~ledger:genesis_ledger ~constraint_constants ~genesis_constants ~compile_config ~blockchain_proof_system_id:None ~genesis_epoch_data in - (proof_inputs, runtime_config) + (proof_inputs, config) let init_from_config_file ?overwrite_version ?genesis_dir ~logger ~(constants : Runtime_config.Constants.constants) (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, runtime_config = + let%map inputs, config = inputs_from_config_file ?genesis_dir ~constants ~logger ?overwrite_version config in let values = Genesis_proof.create_values_no_proof inputs in - (values, runtime_config) + (values, config) let load_config_files ?overwrite_version ?genesis_dir ?(itn_features = false) ?cli_proof_level ?conf_dir ~logger (config_files : string list) = 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 6934a8ff547..6b324d0cdb8 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 @@ -413,6 +413,171 @@ 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 transaction_capacity -> + Runtime_config.Proof_keys.Transaction_capacity + .to_transaction_capacity_log_2 ~block_window_duration_ms + ~transaction_capacity + | 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 + | No_check -> + Some No_check ) + ; 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"] diff --git a/src/lib/integration_test_local_engine/mina_docker.ml b/src/lib/integration_test_local_engine/mina_docker.ml index 6b23207352e..2a29814bb5c 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,6 +142,10 @@ 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 @@ -166,7 +170,7 @@ module Network_config = struct ; slots_per_sub_window = Some slots_per_sub_window ; grace_period_slots = Some grace_period_slots ; genesis_state_timestamp = - Some (Core.Time.(now ()) |> Genesis_constants.of_time) + Some Core.Time.(to_string_abs ~zone:Zone.utc (now ())) } ; proof = Some proof_config (* TODO: prebake ledger and only set hash *) ; ledger = @@ -266,13 +270,10 @@ module Network_config = struct ({ staking; next } : Runtime_config.Epoch_data.t) ) } in - let constraint_constants = - Runtime_config.make_constraint_constants constants.constraint_constants - runtime_config - in let genesis_constants = - Runtime_config.make_genesis_constants constants.genesis_constants - runtime_config + 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 } diff --git a/src/lib/mina_compile_config/mina_compile_config.ml b/src/lib/mina_compile_config/mina_compile_config.ml index 4c0d05fa4a7..b3c9b47278d 100644 --- a/src/lib/mina_compile_config/mina_compile_config.ml +++ b/src/lib/mina_compile_config/mina_compile_config.ml @@ -9,6 +9,7 @@ open Core_kernel module Inputs = struct type t = { default_snark_worker_fee_string : string + ; minimum_user_command_fee_string : string ; itn_features : bool ; compaction_interval_ms : int option ; vrf_poll_interval_ms : int @@ -25,7 +26,8 @@ module Inputs = struct end type t = - { default_snark_worker_fee : Currency.Fee.Stable.Latest.t + { default_snark_worker_fee : Currency.Fee.Stable.Latest.t.t + ; minimum_user_command_fee : Currency.Fee.Stable.Latest.t.t ; itn_features : bool ; compaction_interval : Time.Span.t option ; vrf_poll_interval : Time.Span.t @@ -43,6 +45,8 @@ type t = let make (inputs : Inputs.t) = { default_snark_worker_fee = Currency.Fee.of_mina_string_exn inputs.default_snark_worker_fee_string + ; minimum_user_command_fee = + Currency.Fee.of_mina_string_exn inputs.minimum_user_command_fee_string ; itn_features = inputs.itn_features ; compaction_interval = Option.map @@ -65,6 +69,8 @@ let to_yojson t = `Assoc [ ( "default_snark_worker_fee" , Currency.Fee.to_yojson t.default_snark_worker_fee ) + ; ( "minimum_user_command_fee" + , Currency.Fee.to_yojson t.minimum_user_command_fee ) ; ("itn_features", `Bool t.itn_features) ; ( "compaction_interval" , Option.value_map ~default:`Null @@ -92,6 +98,7 @@ module Compiled = struct let t : t = let (inputs : Inputs.t) = { 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 ; vrf_poll_interval_ms = Node_config.vrf_poll_interval @@ -115,6 +122,8 @@ module For_unit_tests = struct let inputs : Inputs.t = { 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 ; vrf_poll_interval_ms = Node_config_for_unit_tests.vrf_poll_interval diff --git a/src/lib/runtime_config/runtime_config.ml b/src/lib/runtime_config/runtime_config.ml index a5b9630c6dd..790d6e8c44c 100644 --- a/src/lib/runtime_config/runtime_config.ml +++ b/src/lib/runtime_config/runtime_config.ml @@ -1184,49 +1184,20 @@ module Proof_keys = struct end module Genesis = struct - type t = + 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 : int64 option + ; genesis_state_timestamp : string option } [@@deriving bin_io_unversioned] - let to_json_layout : t -> Json_layout.Genesis.t = - fun a -> - { Json_layout.Genesis.k = a.k - ; delta = a.delta - ; slots_per_epoch = a.slots_per_epoch - ; slots_per_sub_window = a.slots_per_sub_window - ; grace_period_slots = a.grace_period_slots - ; genesis_state_timestamp = - Option.map a.genesis_state_timestamp - ~f:Genesis_constants.genesis_timestamp_to_string - } + let to_json_layout : t -> Json_layout.Genesis.t = Fn.id let of_json_layout : Json_layout.Genesis.t -> (t, string) Result.t = - fun a -> - match a.genesis_state_timestamp with - | None -> - Ok - { k = a.k - ; delta = a.delta - ; slots_per_epoch = a.slots_per_epoch - ; slots_per_sub_window = a.slots_per_sub_window - ; grace_period_slots = a.grace_period_slots - ; genesis_state_timestamp = None - } - | Some ts -> - let%map.Result ts = Genesis_constants.validate_time (Some ts) in - { k = a.k - ; delta = a.delta - ; slots_per_epoch = a.slots_per_epoch - ; slots_per_sub_window = a.slots_per_sub_window - ; grace_period_slots = a.grace_period_slots - ; genesis_state_timestamp = Some ts - } + Result.return let to_yojson x = Json_layout.Genesis.to_yojson (to_json_layout x) @@ -1842,118 +1813,6 @@ module type Constants_intf = sig val magic_for_unit_tests : t -> constants end -let make_genesis_constants (a : Genesis_constants.t) (b : t) : - Genesis_constants.t = - { Genesis_constants.protocol = - { k = - Option.value ~default:a.protocol.k Option.(b.genesis >>= fun g -> g.k) - ; delta = - Option.value ~default:a.protocol.delta - Option.(b.genesis >>= fun g -> g.delta) - ; slots_per_epoch = - Option.value ~default:a.protocol.slots_per_epoch - Option.(b.genesis >>= fun g -> g.slots_per_epoch) - ; slots_per_sub_window = - Option.value ~default:a.protocol.slots_per_sub_window - Option.(b.genesis >>= fun g -> g.slots_per_sub_window) - ; grace_period_slots = - Option.value ~default:a.protocol.grace_period_slots - Option.(b.genesis >>= fun g -> g.grace_period_slots) - ; genesis_state_timestamp = - Option.value ~default:a.protocol.genesis_state_timestamp - Option.(b.genesis >>= fun g -> g.genesis_state_timestamp) - } - ; txpool_max_size = - Option.value ~default:a.txpool_max_size - Option.(b.daemon >>= fun d -> d.txpool_max_size) - ; num_accounts = - Option.first_some - Option.(b.ledger >>= fun l -> l.num_accounts) - a.num_accounts - ; zkapp_proof_update_cost = - Option.value ~default:a.zkapp_proof_update_cost - Option.(b.daemon >>= fun d -> d.zkapp_proof_update_cost) - ; zkapp_signed_single_update_cost = - Option.value ~default:a.zkapp_signed_single_update_cost - Option.(b.daemon >>= fun d -> d.zkapp_signed_single_update_cost) - ; zkapp_signed_pair_update_cost = - Option.value ~default:a.zkapp_signed_pair_update_cost - Option.(b.daemon >>= fun d -> d.zkapp_signed_pair_update_cost) - ; zkapp_transaction_cost_limit = - Option.value ~default:a.zkapp_transaction_cost_limit - Option.(b.daemon >>= fun d -> d.zkapp_transaction_cost_limit) - ; max_event_elements = - Option.value ~default:a.max_event_elements - Option.(b.daemon >>= fun d -> d.max_event_elements) - ; max_action_elements = - Option.value ~default:a.max_action_elements - Option.(b.daemon >>= fun d -> d.max_action_elements) - ; zkapp_cmd_limit_hardcap = - Option.value ~default:a.zkapp_cmd_limit_hardcap - Option.(b.daemon >>= fun d -> d.zkapp_cmd_limit_hardcap) - ; minimum_user_command_fee = - Option.value ~default:a.minimum_user_command_fee - Option.(b.daemon >>= fun d -> d.minimum_user_command_fee) - } - -let make_constraint_constants (a : Genesis_constants.Constraint_constants.t) - (b : t) : Genesis_constants.Constraint_constants.t = - let fork = - let a = a.fork in - let b = - let%map.Option f = Option.(b.proof >>= fun x -> x.fork) in - { Genesis_constants.Fork_constants.state_hash = - Mina_base.State_hash.of_base58_check_exn f.state_hash - ; blockchain_length = Mina_numbers.Length.of_int f.blockchain_length - ; global_slot_since_genesis = - Mina_numbers.Global_slot_since_genesis.of_int - f.global_slot_since_genesis - } - in - Option.first_some b a - in - let block_window_duration_ms = - Option.value ~default:a.block_window_duration_ms - Option.(b.proof >>= fun p -> p.block_window_duration_ms) - in - let transaction_capacity_log_2 = - Option.value ~default:a.transaction_capacity_log_2 - Option.( - b.proof - >>= fun p -> - p.transaction_capacity - >>| fun transaction_capacity -> - Proof_keys.Transaction_capacity.to_transaction_capacity_log_2 - ~block_window_duration_ms ~transaction_capacity) - in - let work_delay = - Option.value ~default:a.work_delay - Option.(b.proof >>= fun p -> p.work_delay) - in - { Genesis_constants.Constraint_constants.sub_windows_per_window = - Option.value ~default:a.sub_windows_per_window - Option.(b.proof >>= fun p -> p.sub_windows_per_window) - ; ledger_depth = - Option.value ~default:a.ledger_depth - Option.(b.proof >>= fun p -> p.ledger_depth) - ; work_delay - ; block_window_duration_ms - ; transaction_capacity_log_2 - ; pending_coinbase_depth = - Core_kernel.Int.ceil_log2 - (((transaction_capacity_log_2 + 1) * (work_delay + 1)) + 1) - ; coinbase_amount = - Option.value ~default:a.coinbase_amount - Option.(b.proof >>= fun p -> p.coinbase_amount) - ; supercharged_coinbase_factor = - Option.value ~default:a.supercharged_coinbase_factor - Option.(b.proof >>= fun p -> p.supercharged_coinbase_factor) - ; account_creation_fee = - Option.value ~default:a.account_creation_fee - Option.(b.proof >>= fun p -> p.account_creation_fee) - ; fork - } - module Constants : Constants_intf = struct type constants = { genesis_constants : Genesis_constants.t @@ -1971,9 +1830,122 @@ module Constants : Constants_intf = struct let compile_config t = t.compile_config let combine (a : constants) (b : t) : constants = - let genesis_constants = make_genesis_constants a.genesis_constants b in + let genesis_constants = + { Genesis_constants.protocol = + { k = + Option.value ~default:a.genesis_constants.protocol.k + Option.(b.genesis >>= fun g -> g.k) + ; delta = + Option.value ~default:a.genesis_constants.protocol.delta + Option.(b.genesis >>= fun g -> g.delta) + ; slots_per_epoch = + Option.value ~default:a.genesis_constants.protocol.slots_per_epoch + Option.(b.genesis >>= fun g -> g.slots_per_epoch) + ; slots_per_sub_window = + Option.value + ~default:a.genesis_constants.protocol.slots_per_sub_window + Option.(b.genesis >>= fun g -> g.slots_per_sub_window) + ; grace_period_slots = + Option.value + ~default:a.genesis_constants.protocol.grace_period_slots + Option.(b.genesis >>= fun g -> g.grace_period_slots) + ; genesis_state_timestamp = + Option.value + ~default:a.genesis_constants.protocol.genesis_state_timestamp + Option.( + b.genesis + >>= fun g -> + g.genesis_state_timestamp + >>| Genesis_constants.genesis_timestamp_of_string + >>| Genesis_constants.of_time) + } + ; txpool_max_size = + Option.value ~default:a.genesis_constants.txpool_max_size + Option.(b.daemon >>= fun d -> d.txpool_max_size) + ; num_accounts = + Option.first_some + Option.(b.ledger >>= fun l -> l.num_accounts) + a.genesis_constants.num_accounts + ; zkapp_proof_update_cost = + Option.value ~default:a.genesis_constants.zkapp_proof_update_cost + Option.(b.daemon >>= fun d -> d.zkapp_proof_update_cost) + ; zkapp_signed_single_update_cost = + Option.value + ~default:a.genesis_constants.zkapp_signed_single_update_cost + Option.(b.daemon >>= fun d -> d.zkapp_signed_single_update_cost) + ; zkapp_signed_pair_update_cost = + Option.value + ~default:a.genesis_constants.zkapp_signed_pair_update_cost + Option.(b.daemon >>= fun d -> d.zkapp_signed_pair_update_cost) + ; zkapp_transaction_cost_limit = + Option.value ~default:a.genesis_constants.zkapp_transaction_cost_limit + Option.(b.daemon >>= fun d -> d.zkapp_transaction_cost_limit) + ; max_event_elements = + Option.value ~default:a.genesis_constants.max_event_elements + Option.(b.daemon >>= fun d -> d.max_event_elements) + ; max_action_elements = + Option.value ~default:a.genesis_constants.max_action_elements + Option.(b.daemon >>= fun d -> d.max_action_elements) + ; zkapp_cmd_limit_hardcap = + Option.value ~default:a.genesis_constants.zkapp_cmd_limit_hardcap + Option.(b.daemon >>= fun d -> d.zkapp_cmd_limit_hardcap) + ; minimum_user_command_fee = + Option.value ~default:a.genesis_constants.minimum_user_command_fee + Option.(b.daemon >>= fun d -> d.minimum_user_command_fee) + } + in let constraint_constants = - make_constraint_constants a.constraint_constants b + let fork = + let a = a.constraint_constants.fork in + let b = + let%map.Option f = Option.(b.proof >>= fun x -> x.fork) in + { Genesis_constants.Fork_constants.state_hash = + Mina_base.State_hash.of_base58_check_exn f.state_hash + ; blockchain_length = Mina_numbers.Length.of_int f.blockchain_length + ; global_slot_since_genesis = + Mina_numbers.Global_slot_since_genesis.of_int + f.global_slot_since_genesis + } + in + Option.first_some b a + in + let block_window_duration_ms = + Option.value ~default:a.constraint_constants.block_window_duration_ms + Option.(b.proof >>= fun p -> p.block_window_duration_ms) + in + { a.constraint_constants with + sub_windows_per_window = + Option.value ~default:a.constraint_constants.sub_windows_per_window + Option.(b.proof >>= fun p -> p.sub_windows_per_window) + ; ledger_depth = + Option.value ~default:a.constraint_constants.ledger_depth + Option.(b.proof >>= fun p -> p.ledger_depth) + ; work_delay = + Option.value ~default:a.constraint_constants.work_delay + Option.(b.proof >>= fun p -> p.work_delay) + ; block_window_duration_ms + ; transaction_capacity_log_2 = + Option.value + ~default:a.constraint_constants.transaction_capacity_log_2 + Option.( + b.proof + >>= fun p -> + p.transaction_capacity + >>| fun transaction_capacity -> + Proof_keys.Transaction_capacity.to_transaction_capacity_log_2 + ~block_window_duration_ms ~transaction_capacity) + ; coinbase_amount = + Option.value ~default:a.constraint_constants.coinbase_amount + Option.(b.proof >>= fun p -> p.coinbase_amount) + ; supercharged_coinbase_factor = + Option.value + ~default:a.constraint_constants.supercharged_coinbase_factor + Option.(b.proof >>= fun p -> p.supercharged_coinbase_factor) + ; account_creation_fee = + Option.value ~default:a.constraint_constants.account_creation_fee + Option.(b.proof >>= fun p -> p.account_creation_fee) + ; fork + } in let proof_level = let coerce_proof_level = function @@ -1999,11 +1971,6 @@ module Constants : Constants_intf = struct Option.value ~default:a.compile_config.sync_ledger_default_subtree_depth Option.(b.daemon >>= fun d -> d.sync_ledger_default_subtree_depth) - ; default_snark_worker_fee = - Option.value ~default:a.compile_config.default_snark_worker_fee - Option.( - b.daemon - >>= fun d -> d.snark_worker_fee >>= Currency.Fee.of_mina_int) } in { genesis_constants; constraint_constants; proof_level; compile_config } @@ -2049,79 +2016,3 @@ module Constants : Constants_intf = struct in combine compile_constants t end - -(* This function is useful when you want to generate a runtime config which can recreate - the provided constants. -*) -let of_constants (constants : Constants.constants) : t = - let genesis_constants = Constants.genesis_constants constants in - let constraint_constants = Constants.constraint_constants constants in - let proof_level = Constants.proof_level constants in - let compile_config = Constants.compile_config constants in - let proof = - { Proof_keys.level = - ( match proof_level with - | Full -> - Some Full - | Check -> - Some Check - | No_check -> - Some No_check ) - ; 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 } - -> - { Fork_config.state_hash = - Mina_base.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 - } ) - } - in - let genesis = - { Genesis.k = Some genesis_constants.protocol.k - ; delta = Some genesis_constants.protocol.delta - ; slots_per_epoch = Some genesis_constants.protocol.slots_per_epoch - ; slots_per_sub_window = - Some genesis_constants.protocol.slots_per_sub_window - ; grace_period_slots = Some genesis_constants.protocol.grace_period_slots - ; genesis_state_timestamp = - Some genesis_constants.protocol.genesis_state_timestamp - } - in - let daemon = - { Daemon.default with - txpool_max_size = Some genesis_constants.txpool_max_size - ; zkapp_proof_update_cost = Some genesis_constants.zkapp_proof_update_cost - ; zkapp_signed_single_update_cost = - Some genesis_constants.zkapp_signed_single_update_cost - ; zkapp_signed_pair_update_cost = - Some genesis_constants.zkapp_signed_pair_update_cost - ; zkapp_transaction_cost_limit = - Some genesis_constants.zkapp_transaction_cost_limit - ; max_event_elements = Some genesis_constants.max_event_elements - ; max_action_elements = Some genesis_constants.max_action_elements - ; zkapp_cmd_limit_hardcap = Some genesis_constants.zkapp_cmd_limit_hardcap - ; minimum_user_command_fee = Some genesis_constants.minimum_user_command_fee - ; snark_worker_fee = - Some (Currency.Fee.to_mina_int compile_config.default_snark_worker_fee) - } - in - { default with - genesis = Some genesis - ; proof = Some proof - ; daemon = Some daemon - } From 4b7875e1dcb86c81a162126431341a17f76d9b15 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 28 Jan 2025 23:44:08 +0000 Subject: [PATCH 06/16] Revert "Merge pull request #16304 from MinaProtocol/martin/remove-redundant-fields-from-compile_config-type" This reverts commit c130dfab6b7a99ed882e293540876ac95a1ff599, reversing changes made to ecc244a621d17cbd3026427e9916ae923eb4c00f. --- src/config/dev.mlh | 5 ++++ src/config/devnet.mlh | 5 ++++ src/config/lightnet.mlh | 5 ++++ src/config/mainnet.mlh | 5 ++++ .../mina_compile_config.ml | 28 ++++++++++++++----- src/lib/mina_lib/mina_lib.ml | 6 +--- src/lib/mina_lib/tests/tests.ml | 11 ++------ src/lib/network_pool/snark_pool.ml | 5 +--- src/lib/network_pool/test.ml | 5 +--- src/lib/network_pool/transaction_pool.ml | 5 +--- .../node_config_for_unit_tests.ml | 2 ++ src/lib/node_config/intf/node_config_intf.mli | 2 ++ src/lib/node_config/node_config.ml | 2 ++ src/lib/runtime_config/runtime_config.ml | 5 +++- .../transaction_inclusion_status.ml | 5 +--- src/lib/transition_handler/processor.ml | 8 +++++- 16 files changed, 65 insertions(+), 39 deletions(-) diff --git a/src/config/dev.mlh b/src/config/dev.mlh index a948916349c..a2bea1045b3 100644 --- a/src/config/dev.mlh +++ b/src/config/dev.mlh @@ -4,6 +4,11 @@ (*END src/config/ledger_depth/small.mlh*) +(*BEGIN src/config/curve/medium.mlh*) +[%%define curve_size 255] +(*END src/config/curve/medium.mlh*) + + (*BEGIN src/config/coinbase/standard.mlh*) [%%define coinbase "20"] (*END src/config/coinbase/standard.mlh*) diff --git a/src/config/devnet.mlh b/src/config/devnet.mlh index 9c203a208ee..0b27ffe230b 100644 --- a/src/config/devnet.mlh +++ b/src/config/devnet.mlh @@ -1,5 +1,10 @@ [%%define ledger_depth 35] +(*BEGIN src/config/curve/medium.mlh*) +[%%define curve_size 255] +(*END src/config/curve/medium.mlh*) + + (*BEGIN src/config/coinbase/realistic.mlh*) [%%define coinbase "720"] (*END src/config/coinbase/realistic.mlh*) diff --git a/src/config/lightnet.mlh b/src/config/lightnet.mlh index 6551a8c6adc..d59207c06cf 100644 --- a/src/config/lightnet.mlh +++ b/src/config/lightnet.mlh @@ -1,5 +1,10 @@ [%%define ledger_depth 35] +(*BEGIN src/config/curve/medium.mlh*) +[%%define curve_size 255] +(*END src/config/curve/medium.mlh*) + + (*BEGIN src/config/coinbase/realistic.mlh*) [%%define coinbase "720"] (*END src/config/coinbase/realistic.mlh*) diff --git a/src/config/mainnet.mlh b/src/config/mainnet.mlh index 11e8c897db9..1af34773c8a 100644 --- a/src/config/mainnet.mlh +++ b/src/config/mainnet.mlh @@ -1,5 +1,10 @@ [%%define ledger_depth 35] +(*BEGIN src/config/curve/medium.mlh*) +[%%define curve_size 255] +(*END src/config/curve/medium.mlh*) + + (*BEGIN src/config/coinbase/realistic.mlh*) [%%define coinbase "720"] (*END src/config/coinbase/realistic.mlh*) diff --git a/src/lib/mina_compile_config/mina_compile_config.ml b/src/lib/mina_compile_config/mina_compile_config.ml index b3c9b47278d..fd47b4f12b2 100644 --- a/src/lib/mina_compile_config/mina_compile_config.ml +++ b/src/lib/mina_compile_config/mina_compile_config.ml @@ -8,10 +8,12 @@ open Core_kernel module Inputs = struct type t = - { default_snark_worker_fee_string : string + { curve_size : int + ; default_snark_worker_fee_string : string ; minimum_user_command_fee_string : string ; itn_features : bool ; compaction_interval_ms : int option + ; block_window_duration_ms : int ; vrf_poll_interval_ms : int ; network_id : string ; zkapp_cmd_limit : int option @@ -26,10 +28,12 @@ module Inputs = struct end type t = - { default_snark_worker_fee : Currency.Fee.Stable.Latest.t.t - ; minimum_user_command_fee : Currency.Fee.Stable.Latest.t.t + { curve_size : int + ; default_snark_worker_fee : Currency.Fee.Stable.Latest.t + ; minimum_user_command_fee : Currency.Fee.Stable.Latest.t ; itn_features : bool ; compaction_interval : Time.Span.t option + ; block_window_duration : Time.Span.t ; vrf_poll_interval : Time.Span.t ; network_id : string ; zkapp_cmd_limit : int option @@ -43,7 +47,8 @@ type t = [@@deriving sexp_of, bin_io_unversioned] let make (inputs : Inputs.t) = - { default_snark_worker_fee = + { curve_size = inputs.curve_size + ; default_snark_worker_fee = Currency.Fee.of_mina_string_exn inputs.default_snark_worker_fee_string ; minimum_user_command_fee = Currency.Fee.of_mina_string_exn inputs.minimum_user_command_fee_string @@ -52,6 +57,8 @@ let make (inputs : Inputs.t) = Option.map ~f:(fun x -> Float.of_int x |> Time.Span.of_ms) inputs.compaction_interval_ms + ; block_window_duration = + Float.of_int inputs.block_window_duration_ms |> Time.Span.of_ms ; vrf_poll_interval = Float.of_int inputs.vrf_poll_interval_ms |> Time.Span.of_ms ; rpc_handshake_timeout = Time.Span.of_sec inputs.rpc_handshake_timeout_sec @@ -67,7 +74,8 @@ let make (inputs : Inputs.t) = let to_yojson t = `Assoc - [ ( "default_snark_worker_fee" + [ ("curve_size", `Int t.curve_size) + ; ( "default_snark_worker_fee" , Currency.Fee.to_yojson t.default_snark_worker_fee ) ; ( "minimum_user_command_fee" , Currency.Fee.to_yojson t.minimum_user_command_fee ) @@ -76,6 +84,7 @@ let to_yojson t = , Option.value_map ~default:`Null ~f:(fun x -> `Float (Time.Span.to_ms x)) t.compaction_interval ) + ; ("block_window_duration", `Float (Time.Span.to_ms t.block_window_duration)) ; ("vrf_poll_interval", `Float (Time.Span.to_ms t.vrf_poll_interval)) ; ( "rpc_handshake_timeout" , `Float (Time.Span.to_sec t.rpc_handshake_timeout) ) @@ -97,10 +106,12 @@ let to_yojson t = module Compiled = struct let t : t = let (inputs : Inputs.t) = - { default_snark_worker_fee_string = Node_config.default_snark_worker_fee + { curve_size = Node_config.curve_size + ; 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 ; network_id = Node_config.network ; zkapp_cmd_limit = Node_config.zkapp_cmd_limit @@ -120,12 +131,15 @@ end module For_unit_tests = struct let t : t = let inputs : Inputs.t = - { default_snark_worker_fee_string = + { curve_size = Node_config_for_unit_tests.curve_size + ; 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 diff --git a/src/lib/mina_lib/mina_lib.ml b/src/lib/mina_lib/mina_lib.ml index 42b0b91a62f..a63781e02dc 100644 --- a/src/lib/mina_lib/mina_lib.ml +++ b/src/lib/mina_lib/mina_lib.ml @@ -1639,11 +1639,7 @@ let create ~commit_id ?wallets (config : Config.t) = let constraint_constants = config.precomputed_values.constraint_constants in let consensus_constants = config.precomputed_values.consensus_constants in let compile_config = config.precomputed_values.compile_config in - let block_window_duration = - Float.of_int - config.precomputed_values.constraint_constants.block_window_duration_ms - |> Time.Span.of_ms - in + let block_window_duration = config.compile_config.block_window_duration in let monitor = Option.value ~default:(Monitor.create ()) config.monitor in Async.Scheduler.within' ~monitor (fun () -> let set_itn_data (type t) (module M : Itn_settable with type t = t) (t : t) diff --git a/src/lib/mina_lib/tests/tests.ml b/src/lib/mina_lib/tests/tests.ml index 1876c9525ff..5bb967fb048 100644 --- a/src/lib/mina_lib/tests/tests.ml +++ b/src/lib/mina_lib/tests/tests.ml @@ -210,10 +210,7 @@ let%test_module "Epoch ledger sync tests" = ~consensus_constants ~time_controller ~logger ~frontier_broadcast_pipe:frontier_broadcast_pipe_r ~on_remote_push ~log_gossip_heard:false - ~block_window_duration: - ( Float.of_int - precomputed_values.constraint_constants.block_window_duration_ms - |> Time.Span.of_ms ) + ~block_window_duration:compile_config.block_window_duration in let snark_remote_sink, snark_pool = let config = @@ -226,11 +223,7 @@ let%test_module "Epoch ledger sync tests" = ~consensus_constants ~time_controller ~logger ~frontier_broadcast_pipe:frontier_broadcast_pipe_r ~on_remote_push ~log_gossip_heard:false - ~block_window_duration: - ( Float.of_int - precomputed_values.constraint_constants - .block_window_duration_ms - |> Time.Span.of_ms ) + ~block_window_duration:compile_config.block_window_duration in (snark_remote_sink, snark_pool) in diff --git a/src/lib/network_pool/snark_pool.ml b/src/lib/network_pool/snark_pool.ml index d49cfe9a450..7298617e1c3 100644 --- a/src/lib/network_pool/snark_pool.ml +++ b/src/lib/network_pool/snark_pool.ml @@ -572,10 +572,7 @@ let%test_module "random set test" = let precomputed_values = Lazy.force Precomputed_values.for_unit_tests let block_window_duration = - Float.of_int - Genesis_constants.For_unit_tests.Constraint_constants.t - .block_window_duration_ms - |> Time.Span.of_ms + Mina_compile_config.For_unit_tests.t.block_window_duration (* SNARK work is rejected if the prover doesn't have an account and the fee is below the account creation fee. So, just to make generating valid SNARK diff --git a/src/lib/network_pool/test.ml b/src/lib/network_pool/test.ml index 6c615b9a98f..42f36dd27ef 100644 --- a/src/lib/network_pool/test.ml +++ b/src/lib/network_pool/test.ml @@ -20,10 +20,7 @@ let%test_module "network pool test" = let time_controller = Block_time.Controller.basic ~logger let block_window_duration = - Float.of_int - Genesis_constants.For_unit_tests.Constraint_constants.t - .block_window_duration_ms - |> Time.Span.of_ms + Mina_compile_config.For_unit_tests.t.block_window_duration let verifier = Async.Thread_safe.block_on_async_exn (fun () -> diff --git a/src/lib/network_pool/transaction_pool.ml b/src/lib/network_pool/transaction_pool.ml index 1adc7cf9247..b4eb6ea92a1 100644 --- a/src/lib/network_pool/transaction_pool.ml +++ b/src/lib/network_pool/transaction_pool.ml @@ -1648,10 +1648,7 @@ let%test_module _ = let num_extra_keys = 30 let block_window_duration = - Float.of_int - Genesis_constants.For_unit_tests.Constraint_constants.t - .block_window_duration_ms - |> Time.Span.of_ms + Mina_compile_config.For_unit_tests.t.block_window_duration (* keys that can be used when generating new accounts *) let extra_keys = diff --git a/src/lib/node_config/for_unit_tests/node_config_for_unit_tests.ml b/src/lib/node_config/for_unit_tests/node_config_for_unit_tests.ml index 356424ef342..5b35e3b0529 100644 --- a/src/lib/node_config/for_unit_tests/node_config_for_unit_tests.ml +++ b/src/lib/node_config/for_unit_tests/node_config_for_unit_tests.ml @@ -7,6 +7,8 @@ include Node_config_version let (ledger_depth : int) = (10 : int) +let (curve_size : int) = (255 : int) + let (coinbase : string) = ("20" : string) let (k : int) = (24 : int) diff --git a/src/lib/node_config/intf/node_config_intf.mli b/src/lib/node_config/intf/node_config_intf.mli index 3cac2856a08..55d3e444ad6 100644 --- a/src/lib/node_config/intf/node_config_intf.mli +++ b/src/lib/node_config/intf/node_config_intf.mli @@ -11,6 +11,8 @@ module type S = sig val ledger_depth : int + val curve_size : int + val coinbase : string val k : int diff --git a/src/lib/node_config/node_config.ml b/src/lib/node_config/node_config.ml index 29cfb48045c..7b411144ee9 100644 --- a/src/lib/node_config/node_config.ml +++ b/src/lib/node_config/node_config.ml @@ -10,6 +10,8 @@ include Node_config_version [%%inject "ledger_depth", ledger_depth] +[%%inject "curve_size", curve_size] + [%%inject "coinbase", coinbase] [%%inject "k", k] diff --git a/src/lib/runtime_config/runtime_config.ml b/src/lib/runtime_config/runtime_config.ml index 790d6e8c44c..3daae5df956 100644 --- a/src/lib/runtime_config/runtime_config.ml +++ b/src/lib/runtime_config/runtime_config.ml @@ -1961,7 +1961,10 @@ module Constants : Constants_intf = struct in let compile_config = { a.compile_config with - network_id = + block_window_duration = + constraint_constants.block_window_duration_ms |> Float.of_int + |> Time.Span.of_ms + ; network_id = Option.value ~default:a.compile_config.network_id Option.(b.daemon >>= fun d -> d.network_id) ; sync_ledger_max_subtree_depth = diff --git a/src/lib/transaction_inclusion_status/transaction_inclusion_status.ml b/src/lib/transaction_inclusion_status/transaction_inclusion_status.ml index 8fb2f5a24c3..65e22b95254 100644 --- a/src/lib/transaction_inclusion_status/transaction_inclusion_status.ml +++ b/src/lib/transaction_inclusion_status/transaction_inclusion_status.ml @@ -101,10 +101,7 @@ let%test_module "transaction_status" = let pool_max_size = precomputed_values.genesis_constants.txpool_max_size let block_window_duration = - Float.of_int - Genesis_constants.For_unit_tests.Constraint_constants.t - .block_window_duration_ms - |> Time.Span.of_ms + Mina_compile_config.For_unit_tests.t.block_window_duration let verifier = Async.Thread_safe.block_on_async_exn (fun () -> diff --git a/src/lib/transition_handler/processor.ml b/src/lib/transition_handler/processor.ml index 8ae18aa925e..c10457491c9 100644 --- a/src/lib/transition_handler/processor.ml +++ b/src/lib/transition_handler/processor.ml @@ -42,7 +42,8 @@ let cached_transform_deferred_result ~transform_cached ~transform_result cached (* add a breadcrumb and perform post processing *) let add_and_finalize ~logger ~frontier ~catchup_scheduler ~processed_transition_writer ~only_if_present ~time_controller ~source - ~valid_cb cached_breadcrumb ~(precomputed_values : Precomputed_values.t) = + ~valid_cb cached_breadcrumb ~(precomputed_values : Precomputed_values.t) + ~block_window_duration:_ (*TODO remove unused var*) = let module Inclusion_time = Mina_metrics.Block_latency.Inclusion_time in let breadcrumb = if Cached.is_pure cached_breadcrumb then Cached.peek cached_breadcrumb @@ -284,6 +285,7 @@ let process_transition ~context:(module Context : CONTEXT) ~trust_system add_and_finalize ~logger ~frontier ~catchup_scheduler ~processed_transition_writer ~only_if_present:false ~time_controller ~source:`Gossip breadcrumb ~precomputed_values ~valid_cb + ~block_window_duration:compile_config.block_window_duration in ( match result with | Ok () -> @@ -377,6 +379,8 @@ let run ~context:(module Context : CONTEXT) ~verifier ~trust_system let%map result = add_and_finalize ~logger ~only_if_present:true ~source:`Catchup ~valid_cb b + ~block_window_duration: + compile_config.block_window_duration in Internal_tracing.with_state_hash state_hash @@ fun () -> @@ -440,6 +444,8 @@ let run ~context:(module Context : CONTEXT) ~verifier ~trust_system match%map add_and_finalize ~logger ~only_if_present:false ~source:`Internal breadcrumb ~valid_cb:None + ~block_window_duration: + compile_config.block_window_duration with | Ok () -> [%log internal] "Breadcrumb_integrated" ; From 3d3d7561bdb7f973dbb69e19eaa0b1453c025dca Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 28 Jan 2025 23:47:52 +0000 Subject: [PATCH 07/16] Revert "Merge pull request #16196 from MinaProtocol/martin/force-unconfigurable_constants-to-toplevel" This reverts commit 8a2a077d80aac3ed5181a694e1f2aa841a9e15e7, reversing changes made to e130ac77a50149ebb0ff3840e4ac5dae32afe201. --- .../src/cli_entrypoint/mina_cli_entrypoint.ml | 36 +- src/app/cli/src/init/client.ml | 313 +++++++----------- src/app/cli/src/init/itn.ml | 17 +- src/app/cli/src/init/mina_run.ml | 21 +- src/lib/daemon_rpcs/client.ml | 34 +- src/lib/daemon_rpcs/dune | 1 + .../genesis_constants/genesis_constants.ml | 15 +- src/lib/itn_logger/dune | 2 + src/lib/itn_logger/itn_logger.ml | 39 ++- src/lib/logger/fake/logger.ml | 10 +- src/lib/logger/logger.mli | 12 +- src/lib/logger/native/logger.ml | 43 +-- src/lib/mina_base/dune | 1 - .../test/verification_key_permission_test.ml | 2 - src/lib/mina_base/test/zero_vesting_period.ml | 2 - src/lib/mina_base/user_command.ml | 9 +- .../mina_compile_config.ml | 70 +++- src/lib/mina_graphql/mina_graphql.ml | 12 +- src/lib/mina_lib/archive_client.ml | 12 +- src/lib/mina_lib/archive_client.mli | 6 +- src/lib/mina_lib/mina_lib.ml | 8 +- src/lib/mina_lib/tests/tests.ml | 3 +- src/lib/mina_metrics/prometheus_metrics/dune | 1 + src/lib/network_pool/intf.ml | 1 - src/lib/network_pool/transaction_pool.ml | 11 +- src/lib/node_config/dune | 2 +- src/lib/node_config/for_unit_tests/dune | 2 +- .../node_config_for_unit_tests.ml | 36 +- .../node_config_for_unit_tests.mli | 26 -- src/lib/node_config/intf/node_config_intf.mli | 27 ++ src/lib/node_config/node_config.ml | 1 + .../node_config/unconfigurable_constants/dune | 7 + .../node_config_unconfigurable_constants.ml | 38 +++ .../node_config_unconfigurable_constants.mli | 1 + src/lib/runtime_config/runtime_config.ml | 11 + src/lib/snark_worker/dune | 1 + src/lib/snark_worker/functor.ml | 41 +-- src/lib/transaction/transaction.ml | 4 +- .../transaction_inclusion_status.ml | 2 +- src/lib/transition_handler/block_sink.ml | 7 +- src/lib/transition_handler/block_sink.mli | 1 - 41 files changed, 412 insertions(+), 476 deletions(-) create mode 100644 src/lib/node_config/unconfigurable_constants/dune create mode 100644 src/lib/node_config/unconfigurable_constants/node_config_unconfigurable_constants.ml create mode 100644 src/lib/node_config/unconfigurable_constants/node_config_unconfigurable_constants.mli 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 491c63c8125..a9e49283fa2 100644 --- a/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml +++ b/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml @@ -49,18 +49,6 @@ let plugin_flag = times" else Command.Param.return [] -let with_itn_logger ~itn_features ~(compile_config : Mina_compile_config.t) - ~logger = - if itn_features then - let conf = - Logger.make_itn_logger_config - ~rpc_handshake_timeout:compile_config.rpc_handshake_timeout - ~rpc_heartbeat_timeout:compile_config.rpc_heartbeat_timeout - ~rpc_heartbeat_send_every:compile_config.rpc_heartbeat_send_every - in - Logger.with_itn conf logger - else logger - let setup_daemon logger ~itn_features = let open Command.Let_syntax in let open Cli_lib.Arg_type in @@ -660,7 +648,6 @@ let setup_daemon logger ~itn_features = in let constraint_constants = precomputed_values.consensus_constants in let compile_config = precomputed_values.compile_config in - let logger = with_itn_logger ~itn_features ~compile_config ~logger in constraint_constants.block_window_duration_ms |> Block_time.Span.to_ms |> Float.of_int64 |> Time.Span.of_ms |> Mina_metrics.initialize_all ; @@ -1564,15 +1551,15 @@ let internal_commands ~itn_features logger = (let open Command.Let_syntax in let%map_open config_file = Cli_lib.Flag.config_files in fun () -> + let logger = Logger.create () in let open Deferred.Let_syntax in - let%bind constraint_constants, proof_level, compile_config = + let%bind constraint_constants, proof_level = let%map conf = Runtime_config.Constants.load_constants ~logger config_file in Runtime_config.Constants. - (constraint_constants conf, proof_level conf, compile_config conf) + (constraint_constants conf, proof_level conf) in - let logger = with_itn_logger ~itn_features ~compile_config ~logger in Parallel.init_master () ; match%bind Reader.read_sexp (Lazy.force Reader.stdin) with | `Ok sexp -> @@ -1597,14 +1584,14 @@ let internal_commands ~itn_features logger = fun () -> let open Deferred.Let_syntax in - let%bind constraint_constants, proof_level, compile_config = + let logger = Logger.create () in + let%bind constraint_constants, proof_level = let%map conf = Runtime_config.Constants.load_constants ~logger config_file in Runtime_config.Constants. - (constraint_constants conf, proof_level conf, compile_config conf) + (constraint_constants conf, proof_level conf) in - let logger = with_itn_logger ~itn_features ~compile_config ~logger in Parallel.init_master () ; match%bind Reader.with_file filename ~f:(fun reader -> @@ -1654,14 +1641,14 @@ let internal_commands ~itn_features logger = and config_file = Cli_lib.Flag.config_files in fun () -> let open Async in - let%bind constraint_constants, proof_level, compile_config = + let logger = Logger.create () in + let%bind constraint_constants, proof_level = let%map conf = Runtime_config.Constants.load_constants ~logger config_file in Runtime_config.Constants. - (constraint_constants conf, proof_level conf, compile_config conf) + (constraint_constants conf, proof_level conf) in - let logger = with_itn_logger ~itn_features ~compile_config ~logger in Parallel.init_master () ; let%bind conf_dir = Unix.mkdtemp "/tmp/mina-verifier" in let mode = @@ -1815,6 +1802,7 @@ let internal_commands ~itn_features logger = 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%bind precomputed_values, _ = Genesis_ledger_helper.Config_loader.load_config_files ~logger @@ -1822,10 +1810,6 @@ let internal_commands ~itn_features logger = config_file |> Deferred.Or_error.ok_exn in - let logger = - with_itn_logger ~itn_features - ~compile_config:precomputed_values.compile_config ~logger - in let pids = Child_processes.Termination.create_pid_table () in let%bind prover = (* We create a prover process (unnecessarily) here, to have a more diff --git a/src/app/cli/src/init/client.ml b/src/app/cli/src/init/client.ml index 5f7813438dc..1c426b8a7dc 100644 --- a/src/app/cli/src/init/client.ml +++ b/src/app/cli/src/init/client.ml @@ -43,20 +43,13 @@ let or_error_str ~f_ok ~error = function | Error e -> sprintf "%s\n%s\n" error (Error.to_string_hum e) -let load_compile_config ?(logger = Logger.create ()) config_files = - let%map conf = Runtime_config.Constants.load_constants ~logger config_files in - Runtime_config.Constants.compile_config conf - let stop_daemon = let open Deferred.Let_syntax in let open Daemon_rpcs in + let open Command.Param in Command.async ~summary:"Stop the daemon" - (Cli_lib.Background_daemon.rpc_init Cli_lib.Flag.config_files - ~f:(fun port config_files -> - let%bind compile_config = load_compile_config config_files in - let%map res = - Daemon_rpcs.Client.dispatch ~compile_config Stop_daemon.rpc () port - in + (Cli_lib.Background_daemon.rpc_init (return ()) ~f:(fun port () -> + let%map res = Daemon_rpcs.Client.dispatch Stop_daemon.rpc () port in printf "%s" (or_error_str res ~f_ok:(fun _ -> "Daemon stopping\n") @@ -179,15 +172,12 @@ let get_trust_status = (required Cli_lib.Arg_type.ip_address) in let json_flag = Cli_lib.Flag.json in - let config_files = Cli_lib.Flag.config_files in - let flags = Args.zip3 config_files address_flag json_flag in + let flags = Args.zip2 address_flag json_flag in Command.async ~summary:"Get the trust status associated with an IP address" - (Cli_lib.Background_daemon.rpc_init flags - ~f:(fun port (config_files, ip_address, json) -> - let%bind compile_config = load_compile_config config_files in + (Cli_lib.Background_daemon.rpc_init flags ~f:(fun port (ip_address, json) -> match%map - Daemon_rpcs.Client.dispatch ~compile_config - Daemon_rpcs.Get_trust_status.rpc ip_address port + Daemon_rpcs.Client.dispatch Daemon_rpcs.Get_trust_status.rpc + ip_address port with | Ok statuses -> print_trust_statuses @@ -217,16 +207,13 @@ let get_trust_status_all = ~doc:"Only show trust statuses whose trust score is nonzero" in let json_flag = Cli_lib.Flag.json in - let config_files = Cli_lib.Flag.config_files in - let flags = Args.zip3 config_files nonzero_flag json_flag in + let flags = Args.zip2 nonzero_flag json_flag in Command.async ~summary:"Get trust statuses for all peers known to the trust system" - (Cli_lib.Background_daemon.rpc_init flags - ~f:(fun port (config_files, nonzero, json) -> - let%bind compile_config = load_compile_config config_files in + (Cli_lib.Background_daemon.rpc_init flags ~f:(fun port (nonzero, json) -> match%map - Daemon_rpcs.Client.dispatch ~compile_config - Daemon_rpcs.Get_trust_status_all.rpc () port + Daemon_rpcs.Client.dispatch Daemon_rpcs.Get_trust_status_all.rpc () + port with | Ok ip_trust_statuses -> (* always round the trust scores for display *) @@ -257,15 +244,12 @@ let reset_trust_status = (required Cli_lib.Arg_type.ip_address) in let json_flag = Cli_lib.Flag.json in - let config_files = Cli_lib.Flag.config_files in - let flags = Args.zip3 config_files address_flag json_flag in + let flags = Args.zip2 address_flag json_flag in Command.async ~summary:"Reset the trust status associated with an IP address" - (Cli_lib.Background_daemon.rpc_init flags - ~f:(fun port (config_files, ip_address, json) -> - let%bind compile_config = load_compile_config config_files in + (Cli_lib.Background_daemon.rpc_init flags ~f:(fun port (ip_address, json) -> match%map - Daemon_rpcs.Client.dispatch ~compile_config - Daemon_rpcs.Reset_trust_status.rpc ip_address port + Daemon_rpcs.Client.dispatch Daemon_rpcs.Reset_trust_status.rpc + ip_address port with | Ok status -> print_trust_statuses status json @@ -281,19 +265,17 @@ let get_public_keys = ~doc:"Show extra details (eg. balance, nonce) in addition to public keys" in let error_ctx = "Failed to get public-keys" in - let config_files = Cli_lib.Flag.config_files in Command.async ~summary:"Get public keys" (Cli_lib.Background_daemon.rpc_init - (Args.zip3 config_files with_details_flag Cli_lib.Flag.json) - ~f:(fun port (config_files, is_balance_included, json) -> - let%bind compile_config = load_compile_config config_files in + (Args.zip2 with_details_flag Cli_lib.Flag.json) + ~f:(fun port (is_balance_included, json) -> if is_balance_included then - Daemon_rpcs.Client.dispatch_pretty_message ~compile_config ~json + Daemon_rpcs.Client.dispatch_pretty_message ~json ~join_error:Or_error.join ~error_ctx (module Cli_lib.Render.Public_key_with_details) Get_public_keys_with_details.rpc () port else - Daemon_rpcs.Client.dispatch_pretty_message ~compile_config ~json + Daemon_rpcs.Client.dispatch_pretty_message ~json ~join_error:Or_error.join ~error_ctx (module Cli_lib.Render.String_list_formatter) Get_public_keys.rpc () port ) ) @@ -336,13 +318,10 @@ let verify_receipt = ~doc:"TOKEN_ID The token ID for the account" (optional_with_default Token_id.default Cli_lib.Arg_type.token_id) in - let config_files = Cli_lib.Flag.config_files in Command.async ~summary:"Verify a receipt of a sent payment" (Cli_lib.Background_daemon.rpc_init - (Args.zip5 config_files payment_path_flag proof_path_flag address_flag - token_flag ) - ~f:(fun port (config_files, payment_path, proof_path, pk, token_id) -> - let%bind compile_config = load_compile_config config_files in + (Args.zip4 payment_path_flag proof_path_flag address_flag token_flag) + ~f:(fun port (payment_path, proof_path, pk, token_id) -> let account_id = Account_id.create pk token_id in let dispatch_result = let open Deferred.Or_error.Let_syntax in @@ -367,7 +346,7 @@ let verify_receipt = ~error: (sprintf "Proof file %s has invalid json format" proof_path) in - Daemon_rpcs.Client.dispatch ~compile_config Verify_proof.rpc + Daemon_rpcs.Client.dispatch Verify_proof.rpc (account_id, payment, proof) port in @@ -379,16 +358,13 @@ let verify_receipt = ) let get_nonce : - compile_config:Mina_compile_config.t - -> rpc:(Account_id.t, Account.Nonce.t option Or_error.t) Rpc.Rpc.t + rpc:(Account_id.t, Account.Nonce.t option Or_error.t) Rpc.Rpc.t -> Account_id.t -> Host_and_port.t -> (Account.Nonce.t, string) Deferred.Result.t = - fun ~compile_config ~rpc account_id port -> + fun ~rpc account_id port -> let open Deferred.Let_syntax in - let%map res = - Daemon_rpcs.Client.dispatch ~compile_config rpc account_id port - in + let%map res = Daemon_rpcs.Client.dispatch rpc account_id port in match Or_error.join res with | Ok (Some n) -> Ok n @@ -410,16 +386,12 @@ let get_nonce_cmd = ~doc:"TOKEN_ID The token ID for the account" (optional_with_default Token_id.default Cli_lib.Arg_type.token_id) in - let config_files = Cli_lib.Flag.config_files in - let flags = Args.zip3 config_files address_flag token_flag in + let flags = Args.zip2 address_flag token_flag in Command.async ~summary:"Get the current nonce for an account" - (Cli_lib.Background_daemon.rpc_init flags - ~f:(fun port (config_files, pk, token_flag) -> + (Cli_lib.Background_daemon.rpc_init flags ~f:(fun port (pk, token_flag) -> let account_id = Account_id.create pk token_flag in - let%bind compile_config = load_compile_config config_files in match%bind - get_nonce ~compile_config ~rpc:Daemon_rpcs.Get_nonce.rpc account_id - port + get_nonce ~rpc:Daemon_rpcs.Get_nonce.rpc account_id port with | Error e -> eprintf "Failed to get nonce\n%s\n" e ; @@ -430,16 +402,11 @@ let get_nonce_cmd = let status = let open Daemon_rpcs in - let flag = - Args.zip3 Cli_lib.Flag.config_files Cli_lib.Flag.json - Cli_lib.Flag.performance - in + let flag = Args.zip2 Cli_lib.Flag.json Cli_lib.Flag.performance in Command.async ~summary:"Get running daemon status" - (Cli_lib.Background_daemon.rpc_init flag - ~f:(fun port (config_files, json, performance) -> - let%bind compile_config = load_compile_config config_files in - Daemon_rpcs.Client.dispatch_pretty_message ~compile_config ~json - ~join_error:Fn.id ~error_ctx:"Failed to get status" + (Cli_lib.Background_daemon.rpc_init flag ~f:(fun port (json, performance) -> + Daemon_rpcs.Client.dispatch_pretty_message ~json ~join_error:Fn.id + ~error_ctx:"Failed to get status" (module Daemon_rpcs.Types.Status) Get_status.rpc (if performance then `Performance else `None) @@ -447,24 +414,18 @@ let status = let status_clear_hist = let open Daemon_rpcs in - let flag = - Args.zip3 Cli_lib.Flag.config_files Cli_lib.Flag.json - Cli_lib.Flag.performance - in + let flag = Args.zip2 Cli_lib.Flag.json Cli_lib.Flag.performance in Command.async ~summary:"Clear histograms reported in status" - (Cli_lib.Background_daemon.rpc_init flag - ~f:(fun port (config_files, json, performance) -> - let%bind compile_config = load_compile_config config_files in - Daemon_rpcs.Client.dispatch_pretty_message ~compile_config ~json - ~join_error:Fn.id + (Cli_lib.Background_daemon.rpc_init flag ~f:(fun port (json, performance) -> + Daemon_rpcs.Client.dispatch_pretty_message ~json ~join_error:Fn.id ~error_ctx:"Failed to clear histograms reported in status" (module Daemon_rpcs.Types.Status) Clear_hist_status.rpc (if performance then `Performance else `None) port ) ) -let get_nonce_exn ~compile_config ~rpc public_key port = - match%bind get_nonce ~compile_config ~rpc public_key port with +let get_nonce_exn ~rpc public_key port = + match%bind get_nonce ~rpc public_key port with | Error e -> eprintf "Failed to get nonce\n%s\n" e ; exit 3 @@ -513,9 +474,8 @@ let batch_send_payments = (List.init 3 ~f:(fun _ -> sample_info ())) ) ) ; exit 5 in - let main port (config_files, privkey_path, payments_path) = + let main port (privkey_path, payments_path) = let open Deferred.Let_syntax in - let%bind compile_config = load_compile_config config_files in let%bind keypair = Secrets.Keypair.Terminal_stdin.read_exn ~which:"Mina keypair" privkey_path and infos = get_infos payments_path in @@ -530,8 +490,8 @@ let batch_send_payments = ~body:(Payment { receiver_pk; amount }) ~sign_choice:(User_command_input.Sign_choice.Keypair keypair) () ) in - Daemon_rpcs.Client.dispatch_with_message ~compile_config - Daemon_rpcs.Send_user_commands.rpc ts port + Daemon_rpcs.Client.dispatch_with_message Daemon_rpcs.Send_user_commands.rpc + ts port ~success:(fun _ -> "Successfully enqueued payments in pool") ~error:(fun e -> sprintf "Failed to send payments %s" (Error.to_string_hum e) ) @@ -539,8 +499,7 @@ let batch_send_payments = in Command.async ~summary:"Send multiple payments from a file" (Cli_lib.Background_daemon.rpc_init - (Args.zip3 Cli_lib.Flag.config_files Cli_lib.Flag.privkey_read_path - payment_path_flag ) + (Args.zip2 Cli_lib.Flag.privkey_read_path payment_path_flag) ~f:main ) let transaction_id_to_string id = @@ -799,19 +758,14 @@ let export_ledger = Command.Param.(anon (ledger_args %: t)) in let plaintext_flag = Cli_lib.Flag.plaintext in - let flags = - Args.zip4 Cli_lib.Flag.config_files state_hash_flag plaintext_flag - ledger_kind - in + let flags = Args.zip3 state_hash_flag plaintext_flag ledger_kind in Command.async ~summary: "Print the specified ledger (default: staged ledger at the best tip). \ Note: Exporting snarked ledger is an expensive operation and can take a \ few seconds" (Cli_lib.Background_daemon.rpc_init flags - ~f:(fun port (config_files, state_hash, plaintext, ledger_kind) -> - let open Deferred.Let_syntax in - let%bind compile_config = load_compile_config config_files in + ~f:(fun port (state_hash, plaintext, ledger_kind) -> let check_for_state_hash () = if Option.is_some state_hash then ( Format.eprintf "A state hash should not be given for %s@." @@ -824,25 +778,23 @@ let export_ledger = let state_hash = Option.map ~f:State_hash.of_base58_check_exn state_hash in - Daemon_rpcs.Client.dispatch ~compile_config - Daemon_rpcs.Get_ledger.rpc state_hash port + Daemon_rpcs.Client.dispatch Daemon_rpcs.Get_ledger.rpc state_hash + port | "snarked-ledger" -> let state_hash = Option.map ~f:State_hash.of_base58_check_exn state_hash in printf "Generating snarked ledger(this may take a few seconds)...\n" ; - Daemon_rpcs.Client.dispatch ~compile_config - Daemon_rpcs.Get_snarked_ledger.rpc state_hash port + Daemon_rpcs.Client.dispatch Daemon_rpcs.Get_snarked_ledger.rpc + state_hash port | "staking-epoch-ledger" -> check_for_state_hash () ; - Daemon_rpcs.Client.dispatch ~compile_config - Daemon_rpcs.Get_staking_ledger.rpc + Daemon_rpcs.Client.dispatch Daemon_rpcs.Get_staking_ledger.rpc Daemon_rpcs.Get_staking_ledger.Current port | "next-epoch-ledger" -> check_for_state_hash () ; - Daemon_rpcs.Client.dispatch ~compile_config - Daemon_rpcs.Get_staking_ledger.rpc + Daemon_rpcs.Client.dispatch Daemon_rpcs.Get_staking_ledger.rpc Daemon_rpcs.Get_staking_ledger.Next port | _ -> (* unreachable *) @@ -860,14 +812,14 @@ let hash_ledger = flag "--ledger-file" ~doc:"LEDGER-FILE File containing an exported ledger" (required string)) - and config_files = Cli_lib.Flag.config_files + and config_file = Cli_lib.Flag.config_files and plaintext = Cli_lib.Flag.plaintext in fun () -> let open Deferred.Let_syntax in let%bind constraint_constants = let logger = Logger.create () in let%map conf = - Runtime_config.Constants.load_constants ~logger config_files + Runtime_config.Constants.load_constants ~logger config_file in Runtime_config.Constants.constraint_constants conf in @@ -972,13 +924,13 @@ let currency_in_ledger = let constraint_system_digests = let open Command.Let_syntax in Command.async ~summary:"Print MD5 digest of each SNARK constraint" - (let%map_open config_files = Cli_lib.Flag.config_files in + (let%map_open config_file = Cli_lib.Flag.config_files in fun () -> let open Deferred.Let_syntax in let%bind constraint_constants, proof_level = let logger = Logger.create () in let%map conf = - Runtime_config.Constants.load_constants ~logger config_files + Runtime_config.Constants.load_constants ~logger config_file in Runtime_config.Constants.(constraint_constants conf, proof_level conf) in @@ -994,15 +946,15 @@ let constraint_system_digests = Deferred.unit ) let snark_job_list = + let open Deferred.Let_syntax in + let open Command.Param in Command.async ~summary: "List of snark jobs in JSON format that are yet to be included in the \ blocks" - (Cli_lib.Background_daemon.rpc_init Cli_lib.Flag.config_files - ~f:(fun port config_files -> - let%bind compile_config = load_compile_config config_files in + (Cli_lib.Background_daemon.rpc_init (return ()) ~f:(fun port () -> match%map - Daemon_rpcs.Client.dispatch_join_errors ~compile_config + Daemon_rpcs.Client.dispatch_join_errors Daemon_rpcs.Snark_job_list.rpc () port with | Ok str -> @@ -1123,14 +1075,13 @@ let pending_snark_work = print_string (Yojson.Safe.to_string lst) ) ) ) let start_tracing = + let open Deferred.Let_syntax in + let open Command.Param in Command.async ~summary:"Start async tracing to $config-directory/trace/$pid.trace" - (Cli_lib.Background_daemon.rpc_init Cli_lib.Flag.config_files - ~f:(fun port config_files -> - let%bind compile_config = load_compile_config config_files in + (Cli_lib.Background_daemon.rpc_init (return ()) ~f:(fun port () -> match%map - Daemon_rpcs.Client.dispatch ~compile_config - Daemon_rpcs.Start_tracing.rpc () port + Daemon_rpcs.Client.dispatch Daemon_rpcs.Start_tracing.rpc () port with | Ok () -> print_endline "Daemon started tracing!" @@ -1138,13 +1089,12 @@ let start_tracing = Daemon_rpcs.Client.print_rpc_error e ) ) let stop_tracing = + let open Deferred.Let_syntax in + let open Command.Param in Command.async ~summary:"Stop async tracing" - (Cli_lib.Background_daemon.rpc_init Cli_lib.Flag.config_files - ~f:(fun port config_files -> - let%bind compile_config = load_compile_config config_files in + (Cli_lib.Background_daemon.rpc_init (return ()) ~f:(fun port () -> match%map - Daemon_rpcs.Client.dispatch ~compile_config - Daemon_rpcs.Stop_tracing.rpc () port + Daemon_rpcs.Client.dispatch Daemon_rpcs.Stop_tracing.rpc () port with | Ok () -> print_endline "Daemon stopped printing!" @@ -1152,16 +1102,16 @@ let stop_tracing = Daemon_rpcs.Client.print_rpc_error e ) ) let start_internal_tracing = + let open Deferred.Let_syntax in + let open Command.Param in Command.async ~summary: "Start internal tracing to \ $config-directory/internal-tracing/internal-trace.jsonl" - (Cli_lib.Background_daemon.rpc_init Cli_lib.Flag.config_files - ~f:(fun port config_files -> - let%bind compile_config = load_compile_config config_files in + (Cli_lib.Background_daemon.rpc_init (return ()) ~f:(fun port () -> match%map - Daemon_rpcs.Client.dispatch ~compile_config - Daemon_rpcs.Start_internal_tracing.rpc () port + Daemon_rpcs.Client.dispatch Daemon_rpcs.Start_internal_tracing.rpc () + port with | Ok () -> print_endline "Daemon internal started tracing!" @@ -1169,13 +1119,13 @@ let start_internal_tracing = Daemon_rpcs.Client.print_rpc_error e ) ) let stop_internal_tracing = + let open Deferred.Let_syntax in + let open Command.Param in Command.async ~summary:"Stop internal tracing" - (Cli_lib.Background_daemon.rpc_init Cli_lib.Flag.config_files - ~f:(fun port config_files -> - let%bind compile_config = load_compile_config config_files in + (Cli_lib.Background_daemon.rpc_init (return ()) ~f:(fun port () -> match%map - Daemon_rpcs.Client.dispatch ~compile_config - Daemon_rpcs.Stop_internal_tracing.rpc () port + Daemon_rpcs.Client.dispatch Daemon_rpcs.Stop_internal_tracing.rpc () + port with | Ok () -> print_endline "Daemon internal tracing stopped!" @@ -1282,6 +1232,7 @@ let import_key = ] and privkey_path = Cli_lib.Flag.privkey_read_path in fun () -> + let open Deferred.Let_syntax in let initial_password = ref None in let do_graphql graphql_endpoint = let%bind password = @@ -1411,6 +1362,7 @@ let export_key = (key will be exported using the same password)." (Cli_lib.Background_daemon.graphql_init flags ~f:(fun _ (export_path, pk, conf_dir) -> + let open Deferred.Let_syntax in let%bind home = Sys.home_directory () in let conf_dir = Option.value @@ -1428,6 +1380,7 @@ let export_key = "Password for exported account: " ~env:Secrets.Keypair.env ) in let%bind account = + let open Deferred.Result.Let_syntax in let%bind _ = Secrets.Wallets.unlock wallets ~needle:pk ~password in Secrets.Wallets.find_identity wallets ~needle:pk |> Result.of_option ~error:`Not_found @@ -1729,14 +1682,10 @@ let trustlist_add = let open Deferred.Let_syntax in let open Daemon_rpcs in Command.async ~summary:"Add an IP to the trustlist" - (Cli_lib.Background_daemon.rpc_init - (Args.zip2 Cli_lib.Flag.config_files trustlist_ip_flag) - ~f:(fun port (config_files, trustlist_ip) -> + (Cli_lib.Background_daemon.rpc_init trustlist_ip_flag + ~f:(fun port trustlist_ip -> let trustlist_ip_string = Unix.Cidr.to_string trustlist_ip in - let%bind compile_config = load_compile_config config_files in - match%map - Client.dispatch ~compile_config Add_trustlist.rpc trustlist_ip port - with + match%map Client.dispatch Add_trustlist.rpc trustlist_ip port with | Ok (Ok ()) -> printf "Added %s to client trustlist" trustlist_ip_string | Ok (Error e) -> @@ -1750,15 +1699,10 @@ let trustlist_remove = let open Deferred.Let_syntax in let open Daemon_rpcs in Command.async ~summary:"Remove a CIDR mask from the trustlist" - (Cli_lib.Background_daemon.rpc_init - (Args.zip2 Cli_lib.Flag.config_files trustlist_ip_flag) - ~f:(fun port (config_files, trustlist_ip) -> + (Cli_lib.Background_daemon.rpc_init trustlist_ip_flag + ~f:(fun port trustlist_ip -> let trustlist_ip_string = Unix.Cidr.to_string trustlist_ip in - let%bind compile_config = load_compile_config config_files in - match%map - Client.dispatch ~compile_config Remove_trustlist.rpc trustlist_ip - port - with + match%map Client.dispatch Remove_trustlist.rpc trustlist_ip port with | Ok (Ok ()) -> printf "Removed %s to client trustlist" trustlist_ip_string | Ok (Error e) -> @@ -1769,14 +1713,12 @@ let trustlist_remove = (Error.to_string_hum e) ) ) let trustlist_list = + let open Deferred.Let_syntax in let open Daemon_rpcs in + let open Command.Param in Command.async ~summary:"List the CIDR masks in the trustlist" - (Cli_lib.Background_daemon.rpc_init Cli_lib.Flag.config_files - ~f:(fun port config_files -> - let%bind compile_config = load_compile_config config_files in - match%map - Client.dispatch ~compile_config Get_trustlist.rpc () port - with + (Cli_lib.Background_daemon.rpc_init (return ()) ~f:(fun port () -> + match%map Client.dispatch Get_trustlist.rpc () port with | Ok ips -> printf "The following IPs are permitted to connect to the daemon \ @@ -1858,7 +1800,7 @@ let compile_time_constants = let open Command.Let_syntax in Command.async ~summary:"Print a JSON map of the compile-time consensus parameters" - (let%map_open config_files = Cli_lib.Flag.config_files in + (let%map_open config_file = Cli_lib.Flag.config_files in fun () -> let home = Core.Sys.home_directory () in let conf_dir = home ^/ Cli_lib.Default.conf_dir_name in @@ -1873,7 +1815,7 @@ let compile_time_constants = let logger = Logger.create () in let%bind m_conf = Runtime_config.Json_loader.load_config_files ~conf_dir ~logger - config_files + config_file >>| Or_error.ok in let default = @@ -1948,13 +1890,10 @@ let node_status = flag "--show-errors" ~aliases:[ "show-errors" ] no_arg ~doc:"Include error responses in output" in - let flags = - Args.zip4 Cli_lib.Flag.config_files daemon_peers_flag peers_flag - show_errors_flag - in + let flags = Args.zip3 daemon_peers_flag peers_flag show_errors_flag in Command.async ~summary:"Get node statuses for a set of peers" (Cli_lib.Background_daemon.rpc_init flags - ~f:(fun port (config_files, daemon_peers, peers, show_errors) -> + ~f:(fun port (daemon_peers, peers, show_errors) -> if (Option.is_none peers && not daemon_peers) || (Option.is_some peers && daemon_peers) @@ -1966,10 +1905,9 @@ let node_status = Option.map peers ~f:(fun peers -> List.map peers ~f:Mina_net2.Multiaddr.of_string ) in - let%bind compile_config = load_compile_config config_files in match%map - Daemon_rpcs.Client.dispatch ~compile_config - Daemon_rpcs.Get_node_status.rpc peer_ids_opt port + Daemon_rpcs.Client.dispatch Daemon_rpcs.Get_node_status.rpc + peer_ids_opt port with | Ok all_status_data -> let all_status_data = @@ -1989,13 +1927,11 @@ let node_status = let object_lifetime_statistics = let open Daemon_rpcs in + let open Command.Param in Command.async ~summary:"Dump internal object lifetime statistics to JSON" - (Cli_lib.Background_daemon.rpc_init Cli_lib.Flag.config_files - ~f:(fun port config_files -> - let%bind compile_config = load_compile_config config_files in + (Cli_lib.Background_daemon.rpc_init (return ()) ~f:(fun port () -> match%map - Client.dispatch ~compile_config Get_object_lifetime_statistics.rpc () - port + Client.dispatch Get_object_lifetime_statistics.rpc () port with | Ok stats -> print_endline stats @@ -2030,15 +1966,14 @@ let archive_blocks = and extensional_flag = Command.Param.flag "--extensional" ~aliases:[ "extensional" ] no_arg ~doc:"Blocks are in extensional JSON format" - and config_files = Cli_lib.Flag.config_files in + in ( files , success_file , failure_file , log_successes , archive_process_location , precomputed_flag - , extensional_flag - , config_files ) + , extensional_flag ) in Command.async ~summary: @@ -2055,8 +1990,7 @@ let archive_blocks = , log_successes , archive_process_location , precomputed_flag - , extensional_flag - , config_files ) + , extensional_flag ) -> if Bool.equal precomputed_flag extensional_flag then failwith @@ -2104,15 +2038,13 @@ let archive_blocks = in let add_to_success_file = output_file_line success_file in let add_to_failure_file = output_file_line failure_file in - let%bind compile_config = load_compile_config config_files in let send_precomputed_block = make_send_block ~graphql_make:(fun block -> Graphql_queries.Archive_precomputed_block.( make @@ makeVariables ~block ()) ) ~archive_dispatch: - (Mina_lib.Archive_client.dispatch_precomputed_block - ~compile_config ) + Mina_lib.Archive_client.dispatch_precomputed_block in let send_extensional_block = make_send_block @@ -2120,8 +2052,7 @@ let archive_blocks = Graphql_queries.Archive_extensional_block.( make @@ makeVariables ~block ()) ) ~archive_dispatch: - (Mina_lib.Archive_client.dispatch_extensional_block - ~compile_config ) + Mina_lib.Archive_client.dispatch_extensional_block in Deferred.List.iter files ~f:(fun path -> match%map @@ -2225,13 +2156,10 @@ let receipt_chain_hash = let chain_id_inputs = let open Deferred.Let_syntax in Command.async ~summary:"Print the inputs that yield the current chain id" - (Cli_lib.Background_daemon.rpc_init Cli_lib.Flag.config_files - ~f:(fun port config_files -> + (Cli_lib.Background_daemon.rpc_init (Command.Param.all_unit []) + ~f:(fun port () -> let open Daemon_rpcs in - let%bind compile_config = load_compile_config config_files in - match%map - Client.dispatch ~compile_config Chain_id_inputs.rpc () port - with + match%map Client.dispatch Chain_id_inputs.rpc () port with | Ok ( genesis_state_hash , genesis_constants @@ -2388,7 +2316,7 @@ 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_files = Cli_lib.Flag.config_files + and config_file = Cli_lib.Flag.config_files and no_masks = flag "--no-masks" ~doc:"Do not create masks" no_arg in Cli_lib.Exceptions.handle_nicely @@ fun () -> @@ -2396,7 +2324,7 @@ let test_ledger_application = let%bind genesis_constants, constraint_constants = let logger = Logger.create () in let%map conf = - Runtime_config.Constants.load_constants ~logger config_files + Runtime_config.Constants.load_constants ~logger config_file in Runtime_config.Constants. (genesis_constants conf, constraint_constants conf) @@ -2431,31 +2359,28 @@ let itn_create_accounts = ~doc:"NN Amount in nanomina to be divided among new accounts" (required int) in - let config_files = Cli_lib.Flag.config_files in + let config_file = Cli_lib.Flag.config_files in let args = - Args.zip6 privkey_path key_prefix num_accounts fee amount config_files + Args.zip6 privkey_path key_prefix num_accounts fee amount config_file in Cli_lib.Background_daemon.rpc_init args ~f:(fun port - (privkey_path, key_prefix, num_accounts, fee, amount, config_files) + (privkey_path, key_prefix, num_accounts, fee, amount, config_file) -> let open Deferred.Let_syntax in - let%bind genesis_constants, constraint_constants, compile_config = + let%bind genesis_constants, constraint_constants = let logger = Logger.create () in let%map conf = - Runtime_config.Constants.load_constants ~logger config_files + Runtime_config.Constants.load_constants ~logger config_file in Runtime_config.Constants. - ( genesis_constants conf - , constraint_constants conf - , compile_config conf ) + (genesis_constants conf, constraint_constants conf) in let args' = (privkey_path, key_prefix, num_accounts, fee, amount) in let genesis_constants = genesis_constants in let constraint_constants = constraint_constants in - Itn.create_accounts ~genesis_constants ~constraint_constants - ~compile_config port args' )) + Itn.create_accounts ~genesis_constants ~constraint_constants port args' )) module Visualization = struct let create_command (type rpc_response) ~name ~f @@ -2464,14 +2389,10 @@ module Visualization = struct Command.async ~summary:(sprintf !"Produce a visualization of the %s" name) (Cli_lib.Background_daemon.rpc_init - (Args.zip2 Cli_lib.Flag.config_files - Command.Param.(anon @@ ("output-filepath" %: string)) ) - ~f:(fun port (config_files, filename) -> - let%bind compile_config = load_compile_config config_files in + Command.Param.(anon @@ ("output-filepath" %: string)) + ~f:(fun port filename -> let%map message = - match%map - Daemon_rpcs.Client.dispatch ~compile_config rpc filename port - with + match%map Daemon_rpcs.Client.dispatch rpc filename port with | Ok response -> f filename response | Error e -> diff --git a/src/app/cli/src/init/itn.ml b/src/app/cli/src/init/itn.ml index 2b689266e19..d02c987f0b0 100644 --- a/src/app/cli/src/init/itn.ml +++ b/src/app/cli/src/init/itn.ml @@ -7,8 +7,7 @@ open Mina_base open Mina_transaction let create_accounts ~(genesis_constants : Genesis_constants.t) - ~(constraint_constants : Genesis_constants.Constraint_constants.t) - ~(compile_config : Mina_compile_config.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 @@ -38,7 +37,7 @@ let create_accounts ~(genesis_constants : Genesis_constants.t) in let%bind fee_payer_balance = match%bind - Daemon_rpcs.Client.dispatch ~compile_config Daemon_rpcs.Get_balance.rpc + Daemon_rpcs.Client.dispatch Daemon_rpcs.Get_balance.rpc fee_payer_account_id port with | Ok (Ok (Some balance)) -> @@ -61,8 +60,8 @@ let create_accounts ~(genesis_constants : Genesis_constants.t) let%bind fee_payer_initial_nonce = (* inferred nonce considers txns in pool, in addition to ledger *) match%map - Daemon_rpcs.Client.dispatch ~compile_config - Daemon_rpcs.Get_inferred_nonce.rpc fee_payer_account_id port + Daemon_rpcs.Client.dispatch Daemon_rpcs.Get_inferred_nonce.rpc + fee_payer_account_id port with | Ok (Ok (Some nonce)) -> Account.Nonce.of_uint32 nonce @@ -219,8 +218,8 @@ let create_accounts ~(genesis_constants : Genesis_constants.t) Format.printf " Public key: %s Balance change: %s%s@." pk sgn balance_change_str ) ) ; let%bind res = - Daemon_rpcs.Client.dispatch ~compile_config - Daemon_rpcs.Send_zkapp_commands.rpc zkapps_batch port + Daemon_rpcs.Client.dispatch Daemon_rpcs.Send_zkapp_commands.rpc + zkapps_batch port in ( match res with | Ok res_inner -> ( @@ -254,8 +253,8 @@ let create_accounts ~(genesis_constants : Genesis_constants.t) Deferred.List.for_all batch_pks ~f:(fun pk -> let account_id = Account_id.create pk Token_id.default in let%map res = - Daemon_rpcs.Client.dispatch ~compile_config - Daemon_rpcs.Get_balance.rpc account_id port + Daemon_rpcs.Client.dispatch Daemon_rpcs.Get_balance.rpc account_id + port in match res with | Ok (Ok (Some balance)) when Currency.Balance.(balance > zero) -> diff --git a/src/app/cli/src/init/mina_run.ml b/src/app/cli/src/init/mina_run.ml index 94851641819..62063088c4a 100644 --- a/src/app/cli/src/init/mina_run.ml +++ b/src/app/cli/src/init/mina_run.ml @@ -364,15 +364,7 @@ let setup_local_server ?(client_trustlist = []) ?rest_server_port List.map metadata ~f:(fun (s, value) -> (s, Yojson.Safe.from_string value) ) in - let config = - { Itn_logger.rpc_handshake_timeout = - compile_config.rpc_handshake_timeout - ; rpc_heartbeat_timeout = compile_config.rpc_heartbeat_timeout - ; rpc_heartbeat_send_every = compile_config.rpc_heartbeat_send_every - } - in - return - @@ Itn_logger.log ~process ~timestamp ~message ~metadata ~config () ) + return @@ Itn_logger.log ~process ~timestamp ~message ~metadata () ) ] in let log_snark_work_metrics (work : Snark_worker.Work.Result.t) = @@ -608,8 +600,15 @@ let setup_local_server ?(client_trustlist = []) ?rest_server_port ~handshake_timeout:compile_config.rpc_handshake_timeout ~heartbeat_config: (Rpc.Connection.Heartbeat_config.create - ~timeout:compile_config.rpc_heartbeat_timeout - ~send_every:compile_config.rpc_heartbeat_send_every () ) + ~timeout: + (Time_ns.Span.of_sec + (Time.Span.to_sec + compile_config.rpc_heartbeat_timeout ) ) + ~send_every: + (Time_ns.Span.of_sec + (Time.Span.to_sec + compile_config.rpc_heartbeat_send_every ) ) + () ) reader writer ~implementations: (Rpc.Implementations.create_exn diff --git a/src/lib/daemon_rpcs/client.ml b/src/lib/daemon_rpcs/client.ml index cb84061f574..1c95b95a6bc 100644 --- a/src/lib/daemon_rpcs/client.ml +++ b/src/lib/daemon_rpcs/client.ml @@ -6,19 +6,29 @@ open Async let print_rpc_error error = eprintf "RPC connection error: %s\n" (Error.to_string_hum error) -let dispatch ~(compile_config : Mina_compile_config.t) rpc query - (host_and_port : Host_and_port.t) = +let dispatch rpc query (host_and_port : Host_and_port.t) = Deferred.Or_error.try_with_join ~here:[%here] (fun () -> Tcp.with_connection (Tcp.Where_to_connect.of_host_and_port host_and_port) ~timeout:(Time.Span.of_sec 1.) (fun _ r w -> let open Deferred.Let_syntax in match%bind Rpc.Connection.create - ~handshake_timeout:compile_config.rpc_handshake_timeout + ~handshake_timeout: + (Time.Span.of_sec + Node_config_unconfigurable_constants + .rpc_handshake_timeout_sec ) ~heartbeat_config: (Rpc.Connection.Heartbeat_config.create - ~timeout:compile_config.rpc_heartbeat_timeout - ~send_every:compile_config.rpc_heartbeat_send_every () ) r w + ~timeout: + (Time_ns.Span.of_sec + Node_config_unconfigurable_constants + .rpc_heartbeat_timeout_sec ) + ~send_every: + (Time_ns.Span.of_sec + Node_config_unconfigurable_constants + .rpc_heartbeat_send_every_sec ) + () ) + r w ~connection_state:(fun _ -> ()) with | Error exn -> @@ -30,19 +40,19 @@ let dispatch ~(compile_config : Mina_compile_config.t) rpc query | Ok conn -> Rpc.Rpc.dispatch rpc conn query ) ) -let dispatch_join_errors ~compile_config rpc query port = +let dispatch_join_errors rpc query port = let open Deferred.Let_syntax in - let%map res = dispatch ~compile_config rpc query port in + let%map res = dispatch rpc query port in Or_error.join res (** Call an RPC, passing handlers for a successful call and a failing one. Note that a successful *call* may have failed on the server side and returned a failing result. To deal with that, the success handler returns an Or_error. *) -let dispatch_with_message ~compile_config rpc query port ~success ~error +let dispatch_with_message rpc query port ~success ~error ~(join_error : 'a Or_error.t -> 'b Or_error.t) = let fail err = eprintf "%s\n%!" err ; exit 18 in - let%bind res = dispatch ~compile_config rpc query port in + let%bind res = dispatch rpc query port in match join_error res with | Ok x -> printf "%s\n" (success x) ; @@ -52,8 +62,8 @@ let dispatch_with_message ~compile_config rpc query port ~success ~error let dispatch_pretty_message (type t) (module Print : Cli_lib.Render.Printable_intf with type t = t) - ?(json = true) ~compile_config ~(join_error : 'a Or_error.t -> t Or_error.t) - ~error_ctx rpc query port = - let%bind res = dispatch ~compile_config rpc query port in + ?(json = true) ~(join_error : 'a Or_error.t -> t Or_error.t) ~error_ctx rpc + query port = + let%bind res = dispatch rpc query port in Cli_lib.Render.print (module Print) json (join_error res) ~error_ctx |> Deferred.return diff --git a/src/lib/daemon_rpcs/dune b/src/lib/daemon_rpcs/dune index a9abbb47f89..86876a493e8 100644 --- a/src/lib/daemon_rpcs/dune +++ b/src/lib/daemon_rpcs/dune @@ -36,6 +36,7 @@ perf_histograms sync_status node_addrs_and_ports + mina_node_config.unconfigurable_constants logger network_pool data_hash_lib diff --git a/src/lib/genesis_constants/genesis_constants.ml b/src/lib/genesis_constants/genesis_constants.ml index c02e60fc7a5..1f96fda1902 100644 --- a/src/lib/genesis_constants/genesis_constants.ml +++ b/src/lib/genesis_constants/genesis_constants.ml @@ -425,13 +425,14 @@ module Make (Node_config : Node_config_intf.S) : S = struct } ; txpool_max_size = pool_max_size ; num_accounts = None - ; zkapp_proof_update_cost = 10.26 - ; zkapp_signed_pair_update_cost = 10.08 - ; zkapp_signed_single_update_cost = 9.14 - ; zkapp_transaction_cost_limit = 69.45 - ; max_event_elements = 100 - ; max_action_elements = 100 - ; zkapp_cmd_limit_hardcap = 128 + ; 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 } diff --git a/src/lib/itn_logger/dune b/src/lib/itn_logger/dune index 6f9c8936a26..bf9a03dbc9d 100644 --- a/src/lib/itn_logger/dune +++ b/src/lib/itn_logger/dune @@ -14,6 +14,8 @@ core core_kernel yojson + ;; local libraries + mina_node_config.unconfigurable_constants ) (instrumentation (backend bisect_ppx)) (preprocess (pps ppx_version ppx_mina ppx_jane))) diff --git a/src/lib/itn_logger/itn_logger.ml b/src/lib/itn_logger/itn_logger.ml index ad5a5d73f18..11e5f50c997 100644 --- a/src/lib/itn_logger/itn_logger.ml +++ b/src/lib/itn_logger/itn_logger.ml @@ -67,16 +67,7 @@ module Submit_internal_log = struct ~bin_response end -type config = - { rpc_handshake_timeout : Time.Span.t - ; rpc_heartbeat_timeout : Time_ns.Span.t - ; rpc_heartbeat_send_every : Time_ns.Span.t - } -[@@deriving bin_io_unversioned] - -(* dispatch log to daemon *) - -let dispatch_remote_log config log = +let dispatch_remote_log log = let open Async.Deferred.Let_syntax in let rpc = Submit_internal_log.rpc in match daemon_where_to_connect () with @@ -89,11 +80,21 @@ let dispatch_remote_log config log = | Some where_to_connect -> ( let%map res = Async.Rpc.Connection.with_client - ~handshake_timeout:config.rpc_handshake_timeout + ~handshake_timeout: + (Time.Span.of_sec + Node_config_unconfigurable_constants.rpc_handshake_timeout_sec ) ~heartbeat_config: (Async.Rpc.Connection.Heartbeat_config.create - ~timeout:config.rpc_heartbeat_timeout - ~send_every:config.rpc_heartbeat_send_every () ) where_to_connect + ~timeout: + (Time_ns.Span.of_sec + Node_config_unconfigurable_constants + .rpc_heartbeat_timeout_sec ) + ~send_every: + (Time_ns.Span.of_sec + Node_config_unconfigurable_constants + .rpc_heartbeat_send_every_sec ) + () ) + where_to_connect (fun conn -> Async.Rpc.Rpc.dispatch rpc conn log) in (* not ideal that errors are not themselves logged *) @@ -109,13 +110,13 @@ let dispatch_remote_log config log = (* Used to ensure that no more than one log message is in-flight at a time to guarantee sequential processing. *) -let sequential_dispatcher_loop config () = +let sequential_dispatcher_loop () = let open Async in let pipe_r, pipe_w = Pipe.create () in - don't_wait_for (Pipe.iter pipe_r ~f:(dispatch_remote_log config)) ; + don't_wait_for (Pipe.iter pipe_r ~f:dispatch_remote_log) ; pipe_w -let sequential_log_writer_pipe config = sequential_dispatcher_loop config () +let sequential_log_writer_pipe = sequential_dispatcher_loop () (* this function can be called: (1) by the logging process (daemon, verifier, or prover) from the logger in Logger, or @@ -124,7 +125,7 @@ let sequential_log_writer_pipe config = sequential_dispatcher_loop config () for (1), if the process is the verifier or prover, the log is forwarded by RPC to the daemon, resulting in a recursive call of type (2) *) -let log ?process ~timestamp ~message ~metadata ~config () = +let log ?process ~timestamp ~message ~metadata () = match get_process_kind () with | Some process -> (* prover or verifier, send log to daemon @@ -135,9 +136,7 @@ let log ?process ~timestamp ~message ~metadata ~config () = List.map metadata ~f:(fun (s, json) -> (s, Yojson.Safe.to_string json)) in let remote_log = { timestamp; message; metadata; process } in - Async.Pipe.write_without_pushback - (sequential_log_writer_pipe config) - remote_log + Async.Pipe.write_without_pushback sequential_log_writer_pipe remote_log | None -> (* daemon *) (* convert JSON to Basic.t in queue, so we don't have to in GraphQL response *) diff --git a/src/lib/logger/fake/logger.ml b/src/lib/logger/fake/logger.ml index 5f74dc578c6..959a7a6c567 100644 --- a/src/lib/logger/fake/logger.ml +++ b/src/lib/logger/fake/logger.ml @@ -134,15 +134,7 @@ type t = Metadata.Stable.Latest.t [@@deriving bin_io_unversioned] let metadata = Fn.id -type itn_logger_config = unit - -let make_itn_logger_config ~rpc_handshake_timeout:_ ~rpc_heartbeat_timeout:_ - ~rpc_heartbeat_send_every:_ = - () - -let create ?metadata:_ ?id:_ ?itn_config:_ () = Metadata.empty - -let with_itn _ = Fn.id +let create ?metadata:_ ?id:_ ?itn_features:_ () = Metadata.empty let null () = Metadata.empty diff --git a/src/lib/logger/logger.mli b/src/lib/logger/logger.mli index c6eff3bb4a7..c2cb406e29e 100644 --- a/src/lib/logger/logger.mli +++ b/src/lib/logger/logger.mli @@ -135,20 +135,10 @@ type 'a log_function = -> ('a, unit, string, unit) format4 -> 'a -type itn_logger_config - -val make_itn_logger_config : - rpc_handshake_timeout:Time.Span.t - -> rpc_heartbeat_timeout:Time_ns.Span.t - -> rpc_heartbeat_send_every:Time_ns.Span.t - -> itn_logger_config - -val with_itn : itn_logger_config -> t -> t - val create : ?metadata:(string, Yojson.Safe.t) List.Assoc.t -> ?id:string - -> ?itn_config:itn_logger_config + -> ?itn_features:bool -> unit -> t diff --git a/src/lib/logger/native/logger.ml b/src/lib/logger/native/logger.ml index dcbc3c90b93..da36f253cda 100644 --- a/src/lib/logger/native/logger.ml +++ b/src/lib/logger/native/logger.ml @@ -333,33 +333,25 @@ type t = { null : bool ; metadata : Metadata.Stable.Latest.t ; id : Bounded_types.String.Stable.V1.t - ; itn_config : Itn_logger.config option + ; itn_features : bool } [@@deriving bin_io_unversioned] let metadata t = t.metadata -type itn_logger_config = Itn_logger.config - -let make_itn_logger_config ~rpc_handshake_timeout ~rpc_heartbeat_timeout - ~rpc_heartbeat_send_every = - { Itn_logger.rpc_handshake_timeout - ; rpc_heartbeat_timeout - ; rpc_heartbeat_send_every - } - -let create ?(metadata = []) ?(id = "default") ?itn_config () = +let create ?(metadata = []) ?(id = "default") ?(itn_features = false) () = { null = false ; metadata = Metadata.extend Metadata.empty metadata ; id - ; itn_config + ; itn_features } -let with_itn itn_logger_config t = - { t with itn_config = Some itn_logger_config } - let null () = - { null = true; metadata = Metadata.empty; id = "default"; itn_config = None } + { null = true + ; metadata = Metadata.empty + ; id = "default" + ; itn_features = false + } let extend t metadata = { t with metadata = Metadata.extend t.metadata metadata } @@ -421,17 +413,14 @@ let log t ~level ~module_ ~location ?(metadata = []) ?event_id fmt = in raw t message' ; match level with - | Internal -> ( - match t.itn_config with - | Some config -> - let timestamp = message'.timestamp in - let entries = - Itn_logger.postprocess_message ~timestamp ~message ~metadata - in - List.iter entries ~f:(fun (timestamp, message, metadata) -> - Itn_logger.log ~timestamp ~message ~metadata ~config () ) - | None -> - () ) + | Internal -> + if t.itn_features then + let timestamp = message'.timestamp in + let entries = + Itn_logger.postprocess_message ~timestamp ~message ~metadata + in + List.iter entries ~f:(fun (timestamp, message, metadata) -> + Itn_logger.log ~timestamp ~message ~metadata () ) | _ -> () in diff --git a/src/lib/mina_base/dune b/src/lib/mina_base/dune index 5324ac38daf..e362e42f2bb 100644 --- a/src/lib/mina_base/dune +++ b/src/lib/mina_base/dune @@ -73,7 +73,6 @@ snark_bits error_json ppx_version.runtime - mina_compile_config ) (preprocess (pps ppx_annot ppx_snarky ppx_here ppx_mina ppx_version ppx_compare ppx_deriving.enum ppx_deriving.ord ppx_deriving.make diff --git a/src/lib/mina_base/test/verification_key_permission_test.ml b/src/lib/mina_base/test/verification_key_permission_test.ml index ba624fb295e..e7c8559722c 100644 --- a/src/lib/mina_base/test/verification_key_permission_test.ml +++ b/src/lib/mina_base/test/verification_key_permission_test.ml @@ -39,7 +39,6 @@ let update_vk_perm_with_different_version () = match User_command.check_well_formedness ~genesis_constants:Genesis_constants.For_unit_tests.t - ~compile_config:Mina_compile_config.For_unit_tests.t (Zkapp_command (update_vk_perm_to_be ~auth:(auth, different_version))) with | Ok _ -> @@ -53,7 +52,6 @@ let update_vk_perm_with_current_version () = Quickcheck.test ~trials:10 auth_gen ~f:(fun auth -> match User_command.check_well_formedness - ~compile_config:Mina_compile_config.For_unit_tests.t ~genesis_constants:Genesis_constants.For_unit_tests.t (Zkapp_command (update_vk_perm_to_be diff --git a/src/lib/mina_base/test/zero_vesting_period.ml b/src/lib/mina_base/test/zero_vesting_period.ml index 41aee5aca98..bc717be8fc6 100644 --- a/src/lib/mina_base/test/zero_vesting_period.ml +++ b/src/lib/mina_base/test/zero_vesting_period.ml @@ -282,7 +282,6 @@ let zero_vesting_period_is_error () = match User_command.check_well_formedness ~genesis_constants:Genesis_constants.For_unit_tests.t - ~compile_config:Mina_compile_config.For_unit_tests.t (Zkapp_command zkapp_zero_vesting_period) with | Error [ Zero_vesting_period ] -> @@ -295,7 +294,6 @@ let zkapp_nonzero_vesting_period = mk_zkapp_with_vesting_period 1 let nonzero_vesting_period_ok () = match User_command.check_well_formedness - ~compile_config:Mina_compile_config.For_unit_tests.t ~genesis_constants:Genesis_constants.For_unit_tests.t (Zkapp_command zkapp_nonzero_vesting_period) with diff --git a/src/lib/mina_base/user_command.ml b/src/lib/mina_base/user_command.ml index 952d290ee74..909fb53deb6 100644 --- a/src/lib/mina_base/user_command.ml +++ b/src/lib/mina_base/user_command.ml @@ -230,9 +230,9 @@ let fee : t -> Currency.Fee.t = function let has_insufficient_fee ~minimum_fee t = Currency.Fee.(fee t < minimum_fee) -let is_disabled ~(compile_config : Mina_compile_config.t) = function +let is_disabled = function | Zkapp_command _ -> - compile_config.zkapps_disabled + Node_config_unconfigurable_constants.zkapps_disabled | _ -> false @@ -430,8 +430,7 @@ module Well_formedness_error = struct "Transaction type disabled" end -let check_well_formedness ~(genesis_constants : Genesis_constants.t) - ~(compile_config : Mina_compile_config.t) t : +let check_well_formedness ~(genesis_constants : Genesis_constants.t) t : (unit, Well_formedness_error.t list) result = let preds = let open Well_formedness_error in @@ -440,7 +439,7 @@ let check_well_formedness ~(genesis_constants : Genesis_constants.t) , Insufficient_fee ) ; (has_zero_vesting_period, Zero_vesting_period) ; (is_incompatible_version, Incompatible_version) - ; (is_disabled ~compile_config, Transaction_type_disabled) + ; (is_disabled, Transaction_type_disabled) ; (has_invalid_call_forest, Zkapp_invalid_call_forest) ] in diff --git a/src/lib/mina_compile_config/mina_compile_config.ml b/src/lib/mina_compile_config/mina_compile_config.ml index fd47b4f12b2..e05cd77ce2b 100644 --- a/src/lib/mina_compile_config/mina_compile_config.ml +++ b/src/lib/mina_compile_config/mina_compile_config.ml @@ -20,6 +20,13 @@ module Inputs = struct ; rpc_handshake_timeout_sec : float ; rpc_heartbeat_timeout_sec : float ; rpc_heartbeat_send_every_sec : float + ; zkapp_proof_update_cost : float + ; zkapp_signed_pair_update_cost : float + ; zkapp_signed_single_update_cost : float + ; zkapp_transaction_cost_limit : float + ; max_event_elements : int + ; max_action_elements : int + ; zkapp_cmd_limit_hardcap : int ; zkapps_disabled : bool ; sync_ledger_max_subtree_depth : int ; sync_ledger_default_subtree_depth : int @@ -38,8 +45,15 @@ type t = ; network_id : string ; zkapp_cmd_limit : int option ; rpc_handshake_timeout : Time.Span.t - ; rpc_heartbeat_timeout : Time_ns.Span.t - ; rpc_heartbeat_send_every : Time_ns.Span.t + ; rpc_heartbeat_timeout : Time.Span.t + ; rpc_heartbeat_send_every : Time.Span.t + ; zkapp_proof_update_cost : float + ; zkapp_signed_pair_update_cost : float + ; zkapp_signed_single_update_cost : float + ; zkapp_transaction_cost_limit : float + ; max_event_elements : int + ; max_action_elements : int + ; zkapp_cmd_limit_hardcap : int ; zkapps_disabled : bool ; sync_ledger_max_subtree_depth : int ; sync_ledger_default_subtree_depth : int @@ -62,11 +76,18 @@ let make (inputs : Inputs.t) = ; vrf_poll_interval = Float.of_int inputs.vrf_poll_interval_ms |> Time.Span.of_ms ; rpc_handshake_timeout = Time.Span.of_sec inputs.rpc_handshake_timeout_sec - ; rpc_heartbeat_timeout = Time_ns.Span.of_sec inputs.rpc_heartbeat_timeout_sec + ; rpc_heartbeat_timeout = Time.Span.of_sec inputs.rpc_heartbeat_timeout_sec ; rpc_heartbeat_send_every = - Time_ns.Span.of_sec inputs.rpc_heartbeat_send_every_sec + Time.Span.of_sec inputs.rpc_heartbeat_send_every_sec + ; zkapp_proof_update_cost = inputs.zkapp_proof_update_cost + ; zkapp_signed_pair_update_cost = inputs.zkapp_signed_pair_update_cost + ; zkapp_signed_single_update_cost = inputs.zkapp_signed_single_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 ; network_id = inputs.network_id ; zkapp_cmd_limit = inputs.zkapp_cmd_limit + ; zkapp_cmd_limit_hardcap = inputs.zkapp_cmd_limit_hardcap ; zkapps_disabled = inputs.zkapps_disabled ; sync_ledger_max_subtree_depth = inputs.sync_ledger_max_subtree_depth ; sync_ledger_default_subtree_depth = inputs.sync_ledger_default_subtree_depth @@ -89,13 +110,21 @@ let to_yojson t = ; ( "rpc_handshake_timeout" , `Float (Time.Span.to_sec t.rpc_handshake_timeout) ) ; ( "rpc_heartbeat_timeout" - , `Float (Time_ns.Span.to_sec t.rpc_heartbeat_timeout) ) + , `Float (Time.Span.to_sec t.rpc_heartbeat_timeout) ) ; ( "rpc_heartbeat_send_every" - , `Float (Time_ns.Span.to_sec t.rpc_heartbeat_send_every) ) + , `Float (Time.Span.to_sec t.rpc_heartbeat_send_every) ) + ; ("zkapp_proof_update_cost", `Float t.zkapp_proof_update_cost) + ; ("zkapp_signed_pair_update_cost", `Float t.zkapp_signed_pair_update_cost) + ; ( "zkapp_signed_single_update_cost" + , `Float t.zkapp_signed_single_update_cost ) + ; ("zkapp_transaction_cost_limit", `Float t.zkapp_transaction_cost_limit) + ; ("max_event_elements", `Int t.max_event_elements) + ; ("max_action_elements", `Int t.max_action_elements) ; ("network_id", `String t.network_id) ; ( "zkapp_cmd_limit" , Option.value_map ~default:`Null ~f:(fun x -> `Int x) t.zkapp_cmd_limit ) + ; ("zkapp_cmd_limit_hardcap", `Int t.zkapp_cmd_limit_hardcap) ; ("zkapps_disabled", `Bool t.zkapps_disabled) ; ("sync_ledger_max_subtree_depth", `Int t.sync_ledger_max_subtree_depth) ; ( "sync_ledger_default_subtree_depth" @@ -113,12 +142,21 @@ module Compiled = struct ; 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 - ; rpc_handshake_timeout_sec = 60.0 - ; rpc_heartbeat_timeout_sec = 60.0 - ; rpc_heartbeat_send_every_sec = 10.0 - ; zkapps_disabled = false + ; zkapp_cmd_limit_hardcap = Node_config.zkapp_cmd_limit_hardcap + ; zkapps_disabled = Node_config.zkapps_disabled ; sync_ledger_max_subtree_depth = Node_config.sync_ledger_max_subtree_depth ; sync_ledger_default_subtree_depth = @@ -147,8 +185,20 @@ module For_unit_tests = struct 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 ; sync_ledger_max_subtree_depth = Node_config_for_unit_tests.sync_ledger_max_subtree_depth diff --git a/src/lib/mina_graphql/mina_graphql.ml b/src/lib/mina_graphql/mina_graphql.ml index 012734f3ecf..7a05816187c 100644 --- a/src/lib/mina_graphql/mina_graphql.ml +++ b/src/lib/mina_graphql/mina_graphql.ml @@ -971,10 +971,8 @@ module Mutations = struct "Could not find an archive process to connect to" in let%map () = - Mina_lib.Archive_client.dispatch_precomputed_block - ~compile_config: - (Mina_lib.config mina).precomputed_values.compile_config - archive_location block + Mina_lib.Archive_client.dispatch_precomputed_block archive_location + block |> Deferred.Result.map_error ~f:Error.to_string_hum in () ) @@ -1004,10 +1002,8 @@ module Mutations = struct "Could not find an archive process to connect to" in let%map () = - Mina_lib.Archive_client.dispatch_extensional_block - ~compile_config: - (Mina_lib.config mina).precomputed_values.compile_config - archive_location block + Mina_lib.Archive_client.dispatch_extensional_block archive_location + block |> Deferred.Result.map_error ~f:Error.to_string_hum in () ) diff --git a/src/lib/mina_lib/archive_client.ml b/src/lib/mina_lib/archive_client.ml index 396f878ddfe..7f7e49790e8 100644 --- a/src/lib/mina_lib/archive_client.ml +++ b/src/lib/mina_lib/archive_client.ml @@ -2,7 +2,7 @@ open Core_kernel open Async_kernel open Pipe_lib -let dispatch ?(max_tries = 5) ~logger ~compile_config +let dispatch ?(max_tries = 5) ~logger (archive_location : Host_and_port.t Cli_lib.Flag.Types.with_name) diff = let rec go tries_left errs = if Int.( <= ) tries_left 0 then @@ -20,7 +20,7 @@ let dispatch ?(max_tries = 5) ~logger ~compile_config [%sexp_of: (string * Host_and_port.t) * (string * string)] ) ) else match%bind - Daemon_rpcs.Client.dispatch ~compile_config Archive_lib.Rpc.t diff + Daemon_rpcs.Client.dispatch Archive_lib.Rpc.t diff archive_location.value with | Ok () -> @@ -33,7 +33,7 @@ let dispatch ?(max_tries = 5) ~logger ~compile_config in go max_tries [] -let make_dispatch_block ~compile_config rpc ?(max_tries = 5) +let make_dispatch_block rpc ?(max_tries = 5) (archive_location : Host_and_port.t Cli_lib.Flag.Types.with_name) block = let rec go tries_left errs = if Int.( <= ) tries_left 0 then @@ -51,8 +51,7 @@ let make_dispatch_block ~compile_config rpc ?(max_tries = 5) [%sexp_of: (string * Host_and_port.t) * (string * string)] ) ) else match%bind - Daemon_rpcs.Client.dispatch ~compile_config rpc block - archive_location.value + Daemon_rpcs.Client.dispatch rpc block archive_location.value with | Ok () -> return (Ok ()) @@ -112,8 +111,7 @@ let run ~logger ~precomputed_values , `Float (Time.Span.to_ms (Time.diff diff_time start)) ) ] ; match%map - dispatch ~compile_config:precomputed_values.compile_config - archive_location ~logger (Transition_frontier diff) + dispatch archive_location ~logger (Transition_frontier diff) with | Ok () -> [%log debug] diff --git a/src/lib/mina_lib/archive_client.mli b/src/lib/mina_lib/archive_client.mli index 0cebd18f41b..612e04859be 100644 --- a/src/lib/mina_lib/archive_client.mli +++ b/src/lib/mina_lib/archive_client.mli @@ -2,15 +2,13 @@ open Core open Pipe_lib val dispatch_precomputed_block : - compile_config:Mina_compile_config.t - -> ?max_tries:int + ?max_tries:int -> Host_and_port.t Cli_lib.Flag.Types.with_name -> Mina_block.Precomputed.t -> unit Async.Deferred.Or_error.t val dispatch_extensional_block : - compile_config:Mina_compile_config.t - -> ?max_tries:int + ?max_tries:int -> Host_and_port.t Cli_lib.Flag.Types.with_name -> Archive_lib.Extensional.Block.t -> unit Async.Deferred.Or_error.t diff --git a/src/lib/mina_lib/mina_lib.ml b/src/lib/mina_lib/mina_lib.ml index a63781e02dc..0c960afdda4 100644 --- a/src/lib/mina_lib/mina_lib.ml +++ b/src/lib/mina_lib/mina_lib.ml @@ -950,8 +950,7 @@ let add_full_transactions t user_commands = List.find_map user_commands ~f:(fun cmd -> match User_command.check_well_formedness - ~genesis_constants:t.config.precomputed_values.genesis_constants - ~compile_config:t.config.precomputed_values.compile_config cmd + ~genesis_constants:t.config.precomputed_values.genesis_constants cmd with | Ok () -> None @@ -983,7 +982,6 @@ let add_zkapp_transactions t (zkapp_commands : Zkapp_command.t list) = match User_command.check_well_formedness ~genesis_constants:t.config.precomputed_values.genesis_constants - ~compile_config:t.config.precomputed_values.compile_config (Zkapp_command cmd) with | Ok () -> @@ -1638,7 +1636,6 @@ let create ~commit_id ?wallets (config : Config.t) = let catchup_mode = if config.super_catchup then `Super else `Normal in let constraint_constants = config.precomputed_values.constraint_constants in let consensus_constants = config.precomputed_values.consensus_constants in - let compile_config = config.precomputed_values.compile_config in let block_window_duration = config.compile_config.block_window_duration in let monitor = Option.value ~default:(Monitor.create ()) config.monitor in Async.Scheduler.within' ~monitor (fun () -> @@ -1962,7 +1959,7 @@ let create ~commit_id ?wallets (config : Config.t) = ~pool_max_size: config.precomputed_values.genesis_constants.txpool_max_size ~genesis_constants:config.precomputed_values.genesis_constants - ~slot_tx_end ~compile_config + ~slot_tx_end in let first_received_message_signal = Ivar.create () in let online_status, notify_online_impl = @@ -2018,7 +2015,6 @@ let create ~commit_id ?wallets (config : Config.t) = ; consensus_constants ; genesis_constants = config.precomputed_values.genesis_constants ; constraint_constants - ; compile_config } in let snark_jobs_state = diff --git a/src/lib/mina_lib/tests/tests.ml b/src/lib/mina_lib/tests/tests.ml index 5bb967fb048..20afe1d94b3 100644 --- a/src/lib/mina_lib/tests/tests.ml +++ b/src/lib/mina_lib/tests/tests.ml @@ -195,7 +195,6 @@ let%test_module "Epoch ledger sync tests" = ; consensus_constants ; genesis_constants = precomputed_values.genesis_constants ; constraint_constants - ; compile_config } in let _transaction_pool, tx_remote_sink, _tx_local_sink = @@ -204,7 +203,7 @@ let%test_module "Epoch ledger sync tests" = ~trust_system ~pool_max_size:precomputed_values.genesis_constants.txpool_max_size ~genesis_constants:precomputed_values.genesis_constants - ~slot_tx_end:None ~compile_config + ~slot_tx_end:None in Network_pool.Transaction_pool.create ~config ~constraint_constants ~consensus_constants ~time_controller ~logger diff --git a/src/lib/mina_metrics/prometheus_metrics/dune b/src/lib/mina_metrics/prometheus_metrics/dune index 97833ca2ae2..6ce3904ca3d 100644 --- a/src/lib/mina_metrics/prometheus_metrics/dune +++ b/src/lib/mina_metrics/prometheus_metrics/dune @@ -22,6 +22,7 @@ ;; local libraries logger o1trace + mina_node_config ) (instrumentation (backend bisect_ppx)) (preprocess (pps ppx_mina ppx_let ppx_version ppx_pipebang ppx_custom_printf ppx_here)) diff --git a/src/lib/network_pool/intf.ml b/src/lib/network_pool/intf.ml index 507aa01db71..8bb802069ff 100644 --- a/src/lib/network_pool/intf.ml +++ b/src/lib/network_pool/intf.ml @@ -387,7 +387,6 @@ module type Transaction_resource_pool_intf = sig -> verifier:Verifier.t -> genesis_constants:Genesis_constants.t -> slot_tx_end:Mina_numbers.Global_slot_since_hard_fork.t option - -> compile_config:Mina_compile_config.t -> Config.t val member : t -> Transaction_hash.User_command_with_valid_signature.t -> bool diff --git a/src/lib/network_pool/transaction_pool.ml b/src/lib/network_pool/transaction_pool.ml index b4eb6ea92a1..f11fc1f719f 100644 --- a/src/lib/network_pool/transaction_pool.ml +++ b/src/lib/network_pool/transaction_pool.ml @@ -287,20 +287,18 @@ struct ; verifier : (Verifier.t[@sexp.opaque]) ; genesis_constants : Genesis_constants.t ; slot_tx_end : Mina_numbers.Global_slot_since_hard_fork.t option - ; compile_config : Mina_compile_config.t } [@@deriving sexp_of] (* remove next line if there's a way to force [@@deriving make] write a named parameter instead of an optional parameter *) let make ~trust_system ~pool_max_size ~verifier ~genesis_constants - ~slot_tx_end ~compile_config = + ~slot_tx_end = { trust_system ; pool_max_size ; verifier ; genesis_constants ; slot_tx_end - ; compile_config } end @@ -1095,8 +1093,7 @@ struct ~f:(fun acc user_cmd -> match User_command.check_well_formedness - ~genesis_constants:t.config.genesis_constants - ~compile_config:t.config.compile_config user_cmd + ~genesis_constants:t.config.genesis_constants user_cmd with | Ok () -> acc @@ -1664,8 +1661,6 @@ let%test_module _ = let genesis_constants = precomputed_values.genesis_constants - let compile_config = precomputed_values.compile_config - let minimum_fee = Currency.Fee.to_nanomina_int genesis_constants.minimum_user_command_fee @@ -1934,7 +1929,7 @@ let%test_module _ = let trust_system = Trust_system.null () in let config = Test.Resource_pool.make_config ~trust_system ~pool_max_size ~verifier - ~genesis_constants ~slot_tx_end ~compile_config + ~genesis_constants ~slot_tx_end in let pool_, _, _ = Test.create ~config ~logger ~constraint_constants ~consensus_constants diff --git a/src/lib/node_config/dune b/src/lib/node_config/dune index 019dba43c42..3d3eebb8b77 100644 --- a/src/lib/node_config/dune +++ b/src/lib/node_config/dune @@ -4,7 +4,7 @@ (libraries node_config_intf node_config_version - ) + node_config_unconfigurable_constants) (preprocessor_deps ../../config.mlh) (instrumentation (backend bisect_ppx)) (preprocess (pps ppx_version ppx_base ppx_optcomp)) diff --git a/src/lib/node_config/for_unit_tests/dune b/src/lib/node_config/for_unit_tests/dune index 003ed5d630e..460efc1f009 100644 --- a/src/lib/node_config/for_unit_tests/dune +++ b/src/lib/node_config/for_unit_tests/dune @@ -4,7 +4,7 @@ (libraries node_config_intf node_config_version - ) + node_config_unconfigurable_constants) (instrumentation (backend bisect_ppx)) (preprocess (pps ppx_version ppx_base ppx_optcomp)) ) diff --git a/src/lib/node_config/for_unit_tests/node_config_for_unit_tests.ml b/src/lib/node_config/for_unit_tests/node_config_for_unit_tests.ml index 5b35e3b0529..edd73b7fbdc 100644 --- a/src/lib/node_config/for_unit_tests/node_config_for_unit_tests.ml +++ b/src/lib/node_config/for_unit_tests/node_config_for_unit_tests.ml @@ -4,6 +4,7 @@ *) include Node_config_version +include Node_config_unconfigurable_constants let (ledger_depth : int) = (10 : int) @@ -62,41 +63,6 @@ let zkapp_cmd_limit = None let scan_state_tps_goal_x10 : int option = None -(** limits on Zkapp_command.t size - 10.26*np + 10.08*n2 + 9.14*n1 < 69.45 - where np: number of single proof updates - n2: number of pairs of signed/no-auth update - n1: number of single signed/no-auth update - and their coefficients representing the cost - The formula was generated based on benchmarking data conducted on bare - metal i9 processor with room to include lower spec. - 69.45 was the total time for a combination of updates that was considered - acceptable. - The method used to estimate the cost was linear least squares. -*) - -let zkapp_proof_update_cost = 10.26 - -let zkapp_signed_pair_update_cost = 10.08 - -let zkapp_signed_single_update_cost = 9.14 - -let zkapp_transaction_cost_limit = 69.45 - -let max_event_elements = 100 - -let max_action_elements = 100 - -let zkapp_cmd_limit_hardcap = 128 - -let zkapps_disabled = false - -let rpc_handshake_timeout_sec = 60.0 - -let rpc_heartbeat_timeout_sec = 60.0 - -let rpc_heartbeat_send_every_sec = 10.0 (*same as the default*) - let sync_ledger_max_subtree_depth = 4 let sync_ledger_default_subtree_depth = 3 diff --git a/src/lib/node_config/for_unit_tests/node_config_for_unit_tests.mli b/src/lib/node_config/for_unit_tests/node_config_for_unit_tests.mli index 1037949c11e..eb996f25855 100644 --- a/src/lib/node_config/for_unit_tests/node_config_for_unit_tests.mli +++ b/src/lib/node_config/for_unit_tests/node_config_for_unit_tests.mli @@ -1,27 +1 @@ include Node_config_intf.S - -val zkapp_proof_update_cost : float - -val zkapp_signed_pair_update_cost : float - -val zkapp_signed_single_update_cost : float - -val zkapp_transaction_cost_limit : float - -val max_event_elements : int - -val max_action_elements : int - -val zkapp_cmd_limit_hardcap : int - -val zkapps_disabled : bool - -val rpc_handshake_timeout_sec : float - -val rpc_heartbeat_timeout_sec : float - -val rpc_heartbeat_send_every_sec : float - -val sync_ledger_max_subtree_depth : int - -val sync_ledger_default_subtree_depth : int diff --git a/src/lib/node_config/intf/node_config_intf.mli b/src/lib/node_config/intf/node_config_intf.mli index 55d3e444ad6..3892b7b53df 100644 --- a/src/lib/node_config/intf/node_config_intf.mli +++ b/src/lib/node_config/intf/node_config_intf.mli @@ -6,9 +6,36 @@ module type Version = sig val protocol_version_patch : int end +(* It's stupid that this exists. TODO: Remove and make configurable. *) +module type Unconfigurable_constants = sig + val zkapp_proof_update_cost : float + + val zkapp_signed_pair_update_cost : float + + val zkapp_signed_single_update_cost : float + + val zkapp_transaction_cost_limit : float + + val max_event_elements : int + + val max_action_elements : int + + val zkapp_cmd_limit_hardcap : int + + val zkapps_disabled : bool + + val rpc_handshake_timeout_sec : float + + val rpc_heartbeat_timeout_sec : float + + val rpc_heartbeat_send_every_sec : float +end + module type S = sig include Version + include Unconfigurable_constants + val ledger_depth : int val curve_size : int diff --git a/src/lib/node_config/node_config.ml b/src/lib/node_config/node_config.ml index 7b411144ee9..fbcf2753978 100644 --- a/src/lib/node_config/node_config.ml +++ b/src/lib/node_config/node_config.ml @@ -7,6 +7,7 @@ *) include Node_config_version +include Node_config_unconfigurable_constants [%%inject "ledger_depth", ledger_depth] diff --git a/src/lib/node_config/unconfigurable_constants/dune b/src/lib/node_config/unconfigurable_constants/dune new file mode 100644 index 00000000000..6bcb95d8668 --- /dev/null +++ b/src/lib/node_config/unconfigurable_constants/dune @@ -0,0 +1,7 @@ +(library + (name node_config_unconfigurable_constants) + (public_name mina_node_config.unconfigurable_constants) + (libraries node_config_intf) + (instrumentation (backend bisect_ppx)) + (preprocess (pps ppx_version ppx_base ppx_optcomp)) +) diff --git a/src/lib/node_config/unconfigurable_constants/node_config_unconfigurable_constants.ml b/src/lib/node_config/unconfigurable_constants/node_config_unconfigurable_constants.ml new file mode 100644 index 00000000000..1097f348655 --- /dev/null +++ b/src/lib/node_config/unconfigurable_constants/node_config_unconfigurable_constants.ml @@ -0,0 +1,38 @@ +(* FIXME: These should be configurable. *) + +(** limits on Zkapp_command.t size + 10.26*np + 10.08*n2 + 9.14*n1 < 69.45 + where np: number of single proof updates + n2: number of pairs of signed/no-auth update + n1: number of single signed/no-auth update + and their coefficients representing the cost + The formula was generated based on benchmarking data conducted on bare + metal i9 processor with room to include lower spec. + 69.45 was the total time for a combination of updates that was considered + acceptable. + The method used to estimate the cost was linear least squares. +*) + +let zkapp_proof_update_cost = 10.26 + +let zkapp_signed_pair_update_cost = 10.08 + +let zkapp_signed_single_update_cost = 9.14 + +let zkapp_transaction_cost_limit = 69.45 + +let max_event_elements = 100 + +let max_action_elements = 100 + +let zkapp_cmd_limit_hardcap = 128 + +(* These are fine to be non-configurable *) + +let zkapps_disabled = false + +let rpc_handshake_timeout_sec = 60.0 + +let rpc_heartbeat_timeout_sec = 60.0 + +let rpc_heartbeat_send_every_sec = 10.0 (*same as the default*) diff --git a/src/lib/node_config/unconfigurable_constants/node_config_unconfigurable_constants.mli b/src/lib/node_config/unconfigurable_constants/node_config_unconfigurable_constants.mli new file mode 100644 index 00000000000..51efc504085 --- /dev/null +++ b/src/lib/node_config/unconfigurable_constants/node_config_unconfigurable_constants.mli @@ -0,0 +1 @@ +include Node_config_intf.Unconfigurable_constants diff --git a/src/lib/runtime_config/runtime_config.ml b/src/lib/runtime_config/runtime_config.ml index 3daae5df956..fe547e87994 100644 --- a/src/lib/runtime_config/runtime_config.ml +++ b/src/lib/runtime_config/runtime_config.ml @@ -1964,6 +1964,17 @@ module Constants : Constants_intf = struct block_window_duration = constraint_constants.block_window_duration_ms |> Float.of_int |> Time.Span.of_ms + ; zkapp_proof_update_cost = genesis_constants.zkapp_proof_update_cost + ; zkapp_signed_single_update_cost = + genesis_constants.zkapp_signed_single_update_cost + ; zkapp_signed_pair_update_cost = + genesis_constants.zkapp_signed_pair_update_cost + ; zkapp_transaction_cost_limit = + genesis_constants.zkapp_transaction_cost_limit + ; max_event_elements = genesis_constants.max_event_elements + ; max_action_elements = genesis_constants.max_action_elements + ; zkapp_cmd_limit_hardcap = genesis_constants.zkapp_cmd_limit_hardcap + ; minimum_user_command_fee = genesis_constants.minimum_user_command_fee ; network_id = Option.value ~default:a.compile_config.network_id Option.(b.daemon >>= fun d -> d.network_id) diff --git a/src/lib/snark_worker/dune b/src/lib/snark_worker/dune index db1f2151555..35f564ad95a 100644 --- a/src/lib/snark_worker/dune +++ b/src/lib/snark_worker/dune @@ -42,6 +42,7 @@ mina_ledger transaction_snark_work error_json + mina_node_config.unconfigurable_constants mina_state transaction_protocol_state ppx_version.runtime diff --git a/src/lib/snark_worker/functor.ml b/src/lib/snark_worker/functor.ml index 05c79a0e528..1dfa6f06dc6 100644 --- a/src/lib/snark_worker/functor.ml +++ b/src/lib/snark_worker/functor.ml @@ -118,17 +118,24 @@ module Make (Inputs : Intf.Inputs_intf) : ; prover = public_key } ) - let dispatch ~(compile_config : Mina_compile_config.t) rpc - shutdown_on_disconnect query address = + let dispatch rpc shutdown_on_disconnect query address = let%map res = Rpc.Connection.with_client - ~handshake_timeout:compile_config.rpc_handshake_timeout + ~handshake_timeout: + (Time.Span.of_sec + Node_config_unconfigurable_constants.rpc_handshake_timeout_sec ) ~heartbeat_config: (Rpc.Connection.Heartbeat_config.create - ~timeout:compile_config.rpc_heartbeat_timeout - ~send_every:compile_config.rpc_heartbeat_send_every () ) - (Tcp.Where_to_connect.of_host_and_port address) (fun conn -> - Rpc.Rpc.dispatch rpc conn query ) + ~timeout: + (Time_ns.Span.of_sec + Node_config_unconfigurable_constants.rpc_heartbeat_timeout_sec ) + ~send_every: + (Time_ns.Span.of_sec + Node_config_unconfigurable_constants + .rpc_heartbeat_send_every_sec ) + () ) + (Tcp.Where_to_connect.of_host_and_port address) + (fun conn -> Rpc.Rpc.dispatch rpc conn query) in match res with | Error exn -> @@ -221,8 +228,7 @@ 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 ~compile_config daemon_address - shutdown_on_disconnect = + ~proof_level ~constraint_constants daemon_address shutdown_on_disconnect = let%bind state = Worker_state.create ~constraint_constants ~proof_level () in @@ -264,8 +270,8 @@ module Make (Inputs : Intf.Inputs_intf) : !"Snark worker using daemon $addr" ~metadata:[ ("addr", `String (Host_and_port.to_string daemon_address)) ] ; match%bind - dispatch Rpcs_versioned.Get_work.Latest.rpc shutdown_on_disconnect - ~compile_config () daemon_address + dispatch Rpcs_versioned.Get_work.Latest.rpc shutdown_on_disconnect () + daemon_address with | Error e -> log_and_retry "getting work" e (retry_pause 10.) go @@ -297,8 +303,7 @@ module Make (Inputs : Intf.Inputs_intf) : let%bind () = match%map dispatch Rpcs_versioned.Failed_to_generate_snark.Latest.rpc - ~compile_config shutdown_on_disconnect (e, work, public_key) - daemon_address + shutdown_on_disconnect (e, work, public_key) daemon_address with | Error e -> [%log error] @@ -322,7 +327,7 @@ module Make (Inputs : Intf.Inputs_intf) : ] ; let rec submit_work () = match%bind - dispatch ~compile_config Rpcs_versioned.Submit_work.Latest.rpc + dispatch Rpcs_versioned.Submit_work.Latest.rpc shutdown_on_disconnect result daemon_address with | Error e -> @@ -360,15 +365,13 @@ module Make (Inputs : Intf.Inputs_intf) : let logger = Logger.create () ~metadata:[ ("process", `String "Snark Worker") ] in - let%bind.Deferred constraint_constants, proof_level, compile_config = + let%bind.Deferred constraint_constants, proof_level = let%map.Deferred config = Runtime_config.Constants.load_constants ?conf_dir ?cli_proof_level ~logger config_file in Runtime_config.Constants. - ( constraint_constants config - , proof_level config - , compile_config config ) + (constraint_constants config, proof_level config) in Option.value_map ~default:() conf_dir ~f:(fun conf_dir -> let logrotate_max_size = 1024 * 10 in @@ -387,7 +390,7 @@ module Make (Inputs : Intf.Inputs_intf) : Core.exit 0 ) ; main (module Rpcs_versioned) - ~logger ~proof_level ~constraint_constants ~compile_config daemon_port + ~logger ~proof_level ~constraint_constants daemon_port (Option.value ~default:true shutdown_on_disconnect)) let arguments ~proof_level ~daemon_address ~shutdown_on_disconnect = diff --git a/src/lib/transaction/transaction.ml b/src/lib/transaction/transaction.ml index b45b0361c3e..5fa84bc6181 100644 --- a/src/lib/transaction/transaction.ml +++ b/src/lib/transaction/transaction.ml @@ -144,10 +144,10 @@ let valid_size ~genesis_constants (t : t) = | Fee_transfer _ | Coinbase _ -> Ok () -let check_well_formedness ~genesis_constants ~compile_config (t : t) = +let check_well_formedness ~genesis_constants (t : t) = match t with | Command cmd -> - User_command.check_well_formedness ~genesis_constants ~compile_config cmd + User_command.check_well_formedness ~genesis_constants cmd | Fee_transfer _ | Coinbase _ -> Ok () diff --git a/src/lib/transaction_inclusion_status/transaction_inclusion_status.ml b/src/lib/transaction_inclusion_status/transaction_inclusion_status.ml index 65e22b95254..8fd93e7ba06 100644 --- a/src/lib/transaction_inclusion_status/transaction_inclusion_status.ml +++ b/src/lib/transaction_inclusion_status/transaction_inclusion_status.ml @@ -130,7 +130,7 @@ let%test_module "transaction_status" = let config = Transaction_pool.Resource_pool.make_config ~trust_system ~pool_max_size ~verifier ~genesis_constants:precomputed_values.genesis_constants - ~slot_tx_end:None ~compile_config:precomputed_values.compile_config + ~slot_tx_end:None in let transaction_pool, _, local_sink = Transaction_pool.create ~config diff --git a/src/lib/transition_handler/block_sink.ml b/src/lib/transition_handler/block_sink.ml index 7d5515c0d49..ecad7d1d2d7 100644 --- a/src/lib/transition_handler/block_sink.ml +++ b/src/lib/transition_handler/block_sink.ml @@ -23,7 +23,6 @@ type block_sink_config = ; consensus_constants : Consensus.Constants.t ; genesis_constants : Genesis_constants.t ; constraint_constants : Genesis_constants.Constraint_constants.t - ; compile_config : Mina_compile_config.t } type t = @@ -37,7 +36,6 @@ type t = ; consensus_constants : Consensus.Constants.t ; genesis_constants : Genesis_constants.t ; constraint_constants : Genesis_constants.Constraint_constants.t - ; compile_config : Mina_compile_config.t } | Void @@ -59,7 +57,6 @@ let push sink (b_or_h, `Time_received tm, `Valid_cb cb) = ; consensus_constants ; genesis_constants ; constraint_constants - ; compile_config } -> O1trace.sync_thread "handle_block_gossip" @@ fun () -> @@ -173,7 +170,7 @@ let push sink (b_or_h, `Time_received tm, `Valid_cb cb) = List.exists transactions ~f:(fun txn -> match Mina_transaction.Transaction.check_well_formedness - ~genesis_constants ~compile_config txn.data + ~genesis_constants txn.data with | Ok () -> false @@ -236,7 +233,6 @@ let create ; consensus_constants ; genesis_constants ; constraint_constants - ; compile_config } = let rate_limiter = Network_pool.Rate_limiter.create @@ -258,7 +254,6 @@ let create ; consensus_constants ; genesis_constants ; constraint_constants - ; compile_config } ) let void = Void diff --git a/src/lib/transition_handler/block_sink.mli b/src/lib/transition_handler/block_sink.mli index f77f48d0b73..7757d381dd4 100644 --- a/src/lib/transition_handler/block_sink.mli +++ b/src/lib/transition_handler/block_sink.mli @@ -25,7 +25,6 @@ type block_sink_config = ; consensus_constants : Consensus.Constants.t ; genesis_constants : Genesis_constants.t ; constraint_constants : Genesis_constants.Constraint_constants.t - ; compile_config : Mina_compile_config.t } val create : From ec5a56d8f64e88484d650793eb5b76ca35f5b897 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 28 Jan 2025 23:49:15 +0000 Subject: [PATCH 08/16] Revert "Merge pull request #16186 from MinaProtocol/martin/create-constants-loader-part-1" This reverts commit e130ac77a50149ebb0ff3840e4ac5dae32afe201, reversing changes made to b7f2e3de4b6a446faa2a6336218b8d7da9428d9a. --- src/app/archive/cli/archive_cli.ml | 32 +- src/app/archive/lib/processor.ml | 32 +- src/app/batch_txn_tool/batch_txn_tool.ml | 36 +-- .../src/cli_entrypoint/mina_cli_entrypoint.ml | 189 ++++++++---- src/app/cli/src/init/client.ml | 263 ++++++++-------- .../delegation_verify/delegation_verify.ml | 84 ++++-- src/config/dev.mlh | 1 + src/config/devnet.mlh | 1 + src/config/lightnet.mlh | 1 + src/config/mainnet.mlh | 1 + src/lib/cli_lib/commands.ml | 41 +-- src/lib/cli_lib/flag.ml | 40 +-- src/lib/cli_lib/flag.mli | 19 +- .../genesis_ledger_helper.ml | 237 +++++++-------- .../lib/genesis_ledger_helper_lib.ml | 23 +- src/lib/genesis_proof/genesis_proof.ml | 4 - .../mina_compile_config.ml | 9 + src/lib/mina_lib/tests/tests.ml | 16 +- .../node_config_for_unit_tests.ml | 2 + src/lib/node_config/intf/node_config_intf.mli | 2 + src/lib/node_config/node_config.ml | 2 + src/lib/pickles/snarky_tests/dune | 1 - src/lib/pickles/snarky_tests/snarky_tests.ml | 23 +- .../precomputed_values/precomputed_values.ml | 1 - src/lib/runtime_config/runtime_config.ml | 285 ------------------ src/lib/snark_worker/functor.ml | 15 +- src/lib/snark_worker/intf.ml | 8 +- .../standalone/run_snark_worker.ml | 13 +- 28 files changed, 579 insertions(+), 802 deletions(-) diff --git a/src/app/archive/cli/archive_cli.ml b/src/app/archive/cli/archive_cli.ml index 5ff9c6fa9f3..d9835087e91 100644 --- a/src/app/archive/cli/archive_cli.ml +++ b/src/app/archive/cli/archive_cli.ml @@ -38,38 +38,26 @@ let command_run = "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 ) + in fun () -> let logger = Logger.create () in - let open Deferred.Let_syntax in - let%bind config = - Runtime_config.Json_loader.load_config_files ~logger - (Option.to_list runtime_config_file) - |> Deferred.Or_error.ok_exn - in - let constants = Runtime_config.Constants.load_constants' config in - let%bind precomputed_values_opt = - match runtime_config_file with - | None -> - return None - | Some _ -> - Deferred.Or_error.( - Genesis_ledger_helper.Config_loader.init_from_config_file ~logger - ~constants config - >>| fun (a, _) -> Option.some a) - |> Deferred.Or_error.ok_exn + let genesis_constants = Genesis_constants.Compiled.genesis_constants in + let constraint_constants = + Genesis_constants.Compiled.constraint_constants 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: - (Runtime_config.Constants.genesis_constants constants) - ~constraint_constants: - (Runtime_config.Constants.constraint_constants constants) + ~genesis_constants ~constraint_constants ~postgres_address:postgres.value ~server_port: (Option.value server_port.value ~default:server_port.default) - ~delete_older_than ~precomputed_values_opt ~missing_blocks_width ) + ~delete_older_than ~runtime_config_opt ~missing_blocks_width ) 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 9396084b92b..e8452d413da 100644 --- a/src/app/archive/lib/processor.ml +++ b/src/app/archive/lib/processor.ml @@ -4728,12 +4728,26 @@ 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 - ~(precomputed_values_opt : Precomputed_values.t option) pool = - match precomputed_values_opt with +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 precomputed_values -> ( + | Some runtime_config -> ( + let%bind precomputed_values = + match%map + Genesis_ledger_helper.init_from_config_file ~logger + ~proof_level:Genesis_constants.Compiled.proof_level + ~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 @@ -4753,8 +4767,7 @@ let add_genesis_accounts ~logger let%bind.Deferred.Result genesis_block_id = Block.add_if_doesn't_exist (module Conn) - ~constraint_constants:precomputed_values.constraint_constants - genesis_block + ~constraint_constants genesis_block in let%bind.Deferred.Result { ledger_hash; _ } = Block.load (module Conn) ~id:genesis_block_id @@ -4861,7 +4874,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 ~precomputed_values_opt ~missing_blocks_width = + ~delete_older_than ~runtime_config_opt ~missing_blocks_width = let where_to_listen = Async.Tcp.Where_to_listen.bind_to All_addresses (On_port server_port) in @@ -4890,7 +4903,10 @@ let setup_server ~(genesis_constants : Genesis_constants.t) ~metadata:[ ("error", `String (Caqti_error.show e)) ] ; Deferred.unit | Ok pool -> - let%bind () = add_genesis_accounts pool ~logger ~precomputed_values_opt in + let%bind () = + add_genesis_accounts pool ~logger ~genesis_constants + ~constraint_constants ~runtime_config_opt + in run ~constraint_constants ~genesis_constants pool reader ~logger ~delete_older_than |> don't_wait_for ; diff --git a/src/app/batch_txn_tool/batch_txn_tool.ml b/src/app/batch_txn_tool/batch_txn_tool.ml index 9331c5a4207..79741438d56 100644 --- a/src/app/batch_txn_tool/batch_txn_tool.ml +++ b/src/app/batch_txn_tool/batch_txn_tool.ml @@ -154,10 +154,11 @@ 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 ~logger () = + ~graphql_target_node_option ~minimum_user_command_fee () = let open Deferred.Let_syntax in (* define the rate limiting function *) let open Logger in + let logger = Logger.create () in let limit_level = let slot_limit = Float.( @@ -309,6 +310,8 @@ 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: @@ -387,32 +390,23 @@ 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.config_files 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_opt = Cli_lib.Flag.fee_common in - fun () -> - let open Deferred.Let_syntax in - let logger = Logger.create () in - let%bind minimum_user_command_fee = - let%map conf = - Runtime_config.Constants.load_constants ~logger config_file - in - Option.value - ~default: - (Runtime_config.Constants.genesis_constants conf) - .minimum_user_command_fee minimum_user_command_fee_opt - 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 ~logger () ) + 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 + 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 ) let () = Command.run 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 a9e49283fa2..79f00cd6dbb 100644 --- a/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml +++ b/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml @@ -49,7 +49,51 @@ let plugin_flag = times" else Command.Param.return [] -let setup_daemon logger ~itn_features = +let load_config_files ~logger ~genesis_constants ~constraint_constants ~conf_dir + ~genesis_dir ~cli_proof_level ~proof_level (config_files : string list) = + let open Deferred.Or_error.Let_syntax in + let genesis_dir = Option.value ~default:(conf_dir ^/ "genesis") genesis_dir in + let%bind config = + Runtime_config.Json_loader.load_config_files ~conf_dir ~logger config_files + in + match%bind.Deferred + Genesis_ledger_helper.init_from_config_file ~cli_proof_level ~genesis_dir + ~logger ~genesis_constants ~constraint_constants ~proof_level config + with + | Ok a -> + return a + | 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 + +let setup_daemon logger ~itn_features ~default_snark_worker_fee = let open Command.Let_syntax in let open Cli_lib.Arg_type in let receiver_key_warning = Cli_lib.Default.receiver_key_warning in @@ -218,7 +262,8 @@ let setup_daemon logger ~itn_features = ~doc: (sprintf "FEE Amount a worker wants to get compensated for generating a \ - snark proof" ) + snark proof (default: %d)" + (Currency.Fee.to_nanomina_int default_snark_worker_fee) ) (optional txn_fee) and work_reassignment_wait = flag "--work-reassignment-wait" @@ -641,15 +686,22 @@ let setup_daemon logger ~itn_features = in let pids = Child_processes.Termination.create_pid_table () in let mina_initialization_deferred () = + 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 = - Genesis_ledger_helper.Config_loader.load_config_files ~logger - ~conf_dir ?genesis_dir ?cli_proof_level ~itn_features config_files + load_config_files ~logger ~conf_dir ~genesis_dir + ~proof_level:Genesis_constants.Compiled.proof_level config_files + ~genesis_constants ~constraint_constants ~cli_proof_level |> Deferred.Or_error.ok_exn in - let constraint_constants = precomputed_values.consensus_constants in - let compile_config = precomputed_values.compile_config in - constraint_constants.block_window_duration_ms |> Block_time.Span.to_ms - |> Float.of_int64 |> Time.Span.of_ms |> Mina_metrics.initialize_all ; + + constraint_constants.block_window_duration_ms |> Float.of_int + |> Time.Span.of_ms |> Mina_metrics.initialize_all ; let module DC = Runtime_config.Daemon in (* The explicit typing here is necessary to prevent type inference from specializing according @@ -1325,9 +1377,12 @@ 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 ~itn_features = +let daemon logger = + let compile_config = Mina_compile_config.Compiled.t in Command.async ~summary:"Mina daemon" - (Command.Param.map (setup_daemon logger ~itn_features) + (Command.Param.map + (setup_daemon logger ~itn_features:compile_config.itn_features + ~default_snark_worker_fee:compile_config.default_snark_worker_fee ) ~f:(fun setup_daemon () -> (* Immediately disable updating the time offset. *) Block_time.Controller.disable_setting_offset () ; @@ -1336,7 +1391,7 @@ let daemon logger ~itn_features = [%log info] "Daemon ready. Clients can now connect" ; Async.never () ) ) -let replay_blocks ~itn_features logger = +let replay_blocks logger = let replay_flag = let open Command.Param in flag "--blocks-filename" ~aliases:[ "-blocks-filename" ] (required string) @@ -1347,9 +1402,11 @@ let replay_blocks ~itn_features 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) + (setup_daemon logger ~itn_features:compile_config.itn_features + ~default_snark_worker_fee:compile_config.default_snark_worker_fee ) ~f:(fun blocks_filename read_kind setup_daemon () -> (* Enable updating the time offset. *) Block_time.Controller.enable_setting_offset () ; @@ -1541,38 +1598,34 @@ let snark_hashes = let json = Cli_lib.Flag.json in fun () -> if json then Core.printf "[]\n%!"] -let internal_commands ~itn_features logger = +let internal_commands logger = [ ( Snark_worker.Intf.command_name - , Snark_worker.command ~commit_id:Mina_version.commit_id ) + , Snark_worker.command ~proof_level:Genesis_constants.Compiled.proof_level + ~constraint_constants:Genesis_constants.Compiled.constraint_constants + ~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" - (let open Command.Let_syntax in - let%map_open config_file = Cli_lib.Flag.config_files in - fun () -> - let logger = Logger.create () in - let open Deferred.Let_syntax in - let%bind constraint_constants, proof_level = - let%map conf = - Runtime_config.Constants.load_constants ~logger config_file - in - Runtime_config.Constants. - (constraint_constants conf, proof_level conf) - 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") ) + (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" ) ) ) ; ( "run-snark-worker-single" , Command.async ~summary:"Run snark-worker on a sexp provided on a single line of stdin" @@ -1580,18 +1633,14 @@ let internal_commands ~itn_features logger = let%map_open filename = flag "--file" (required string) ~doc:"File containing the s-expression of the snark work to execute" - and config_file = Cli_lib.Flag.config_files in - + in fun () -> let open Deferred.Let_syntax in let logger = Logger.create () in - let%bind constraint_constants, proof_level = - let%map conf = - Runtime_config.Constants.load_constants ~logger config_file - in - Runtime_config.Constants. - (constraint_constants conf, proof_level conf) + let constraint_constants = + Genesis_constants.Compiled.constraint_constants in + let proof_level = Genesis_constants.Compiled.proof_level in Parallel.init_master () ; match%bind Reader.with_file filename ~f:(fun reader -> @@ -1638,17 +1687,14 @@ let internal_commands ~itn_features logger = and limit = flag "--limit" ~aliases:[ "-limit" ] (optional int) ~doc:"limit the number of proofs taken from the file" - and config_file = Cli_lib.Flag.config_files in + in fun () -> let open Async in let logger = Logger.create () in - let%bind constraint_constants, proof_level = - let%map conf = - Runtime_config.Constants.load_constants ~logger config_file - in - Runtime_config.Constants. - (constraint_constants conf, proof_level conf) + let constraint_constants = + Genesis_constants.Compiled.constraint_constants 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 = @@ -1785,12 +1831,18 @@ let internal_commands ~itn_features logger = () ) ; Deferred.return ()) ) ; ("dump-type-shapes", dump_type_shapes) - ; ("replay-blocks", replay_blocks ~itn_features logger) + ; ("replay-blocks", replay_blocks logger) ; ("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_file = Cli_lib.Flag.config_files + 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 and genesis_dir = flag "--genesis-ledger-dir" ~aliases:[ "genesis-ledger-dir" ] @@ -1804,10 +1856,17 @@ let internal_commands ~itn_features logger = 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%bind precomputed_values, _ = - Genesis_ledger_helper.Config_loader.load_config_files ~logger - ~conf_dir ?genesis_dir ~cli_proof_level:Full ~itn_features - config_file + load_config_files ~logger ~conf_dir ~genesis_dir ~genesis_constants + ~constraint_constants ~proof_level config_files + ~cli_proof_level:None |> Deferred.Or_error.ok_exn in let pids = Child_processes.Termination.create_pid_table () in @@ -1816,7 +1875,7 @@ let internal_commands ~itn_features logger = realistic test. *) Prover.create ~commit_id:Mina_version.commit_id ~logger ~pids - ~conf_dir ~proof_level:precomputed_values.proof_level + ~conf_dir ~proof_level ~constraint_constants:precomputed_values.constraint_constants () in match%bind @@ -1836,14 +1895,13 @@ let internal_commands ~itn_features logger = let mina_commands logger ~itn_features = [ ("accounts", Client.accounts) - ; ("daemon", daemon ~itn_features logger) + ; ("daemon", daemon logger) ; ("client", Client.client) ; ("advanced", Client.advanced ~itn_features) ; ("ledger", Client.ledger) ; ("libp2p", Client.libp2p) ; ( "internal" - , Command.group ~summary:"Internal commands" - (internal_commands ~itn_features logger) ) + , Command.group ~summary:"Internal commands" (internal_commands logger) ) ; (Parallel.worker_command_name, Parallel.worker_command) ; ("transaction-snark-profiler", Transaction_snark_profiler.command) ] @@ -1881,10 +1939,11 @@ let () = | [| _mina_exe; version |] when is_version_cmd version -> Mina_version.print_version () | _ -> - let itn_features = Mina_compile_config.Compiled.t.itn_features in + let compile_config = Mina_compile_config.Compiled.t in Command.run (Command.group ~summary:"Mina" ~preserve_subcommand_order:() - (mina_commands logger ~itn_features) ) ) ; + (mina_commands logger ~itn_features:compile_config.itn_features) ) + ) ; Core.exit 0 let linkme = () diff --git a/src/app/cli/src/init/client.ml b/src/app/cli/src/init/client.ml index 1c426b8a7dc..409413d0f00 100644 --- a/src/app/cli/src/init/client.ml +++ b/src/app/cli/src/init/client.ml @@ -4,10 +4,6 @@ open Signature_lib open Mina_base open Mina_transaction -(* TODO consider a better way of setting a default transaction fee than - a fixed compile-time value *) -let default_transaction_fee = Currency.Fee.of_nanomina_int_exn 250000000 - module Client = Graphql_lib.Client.Make (struct let preprocess_variables_string = Fn.id @@ -517,8 +513,14 @@ 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 args = - Args.zip3 Cli_lib.Flag.signed_command_common receiver_flag amount_flag + 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 in Command.async ~summary:"Send payment to an address" (Cli_lib.Background_daemon.graphql_init args @@ -526,8 +528,6 @@ let send_payment_graphql = graphql_endpoint ({ Cli_lib.Flag.sender; fee; nonce; memo }, receiver, amount) -> - let open Deferred.Let_syntax in - let fee = Option.value ~default:default_transaction_fee fee in let%map response = let input = Mina_graphql.Types.Input.SendPaymentInput.make_input ~to_:receiver @@ -548,15 +548,21 @@ let delegate_stake_graphql = ~doc:"PUBLICKEY Public key to which you want to delegate your stake" (required public_key_compressed) in - let args = Args.zip2 Cli_lib.Flag.signed_command_common receiver_flag in + let genesis_constants = Genesis_constants.Compiled.genesis_constants in + let compile_config = Mina_compile_config.Compiled.t 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 + 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) -> - let open Deferred.Let_syntax in - let fee = Option.value ~default:default_transaction_fee fee in let%map response = Graphql_client.query_exn Graphql_queries.Send_delegation.( @@ -812,16 +818,10 @@ let hash_ledger = flag "--ledger-file" ~doc:"LEDGER-FILE File containing an exported ledger" (required string)) - and config_file = Cli_lib.Flag.config_files and plaintext = Cli_lib.Flag.plaintext in fun () -> - let open Deferred.Let_syntax in - let%bind constraint_constants = - let logger = Logger.create () in - let%map conf = - Runtime_config.Constants.load_constants ~logger config_file - in - Runtime_config.Constants.constraint_constants conf + let constraint_constants = + Genesis_constants.Compiled.constraint_constants in let process_accounts accounts = let packed_ledger = @@ -922,28 +922,22 @@ 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" - (let%map_open config_file = Cli_lib.Flag.config_files in - fun () -> - let open Deferred.Let_syntax in - let%bind constraint_constants, proof_level = - let logger = Logger.create () in - let%map conf = - Runtime_config.Constants.load_constants ~logger config_file + (Command.Param.return (fun () -> + let constraint_constants = + Genesis_constants.Compiled.constraint_constants in - Runtime_config.Constants.(constraint_constants conf, proof_level conf) - 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 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 snark_job_list = let open Deferred.Let_syntax in @@ -1797,82 +1791,90 @@ let add_peers_graphql = } ) ) ) ) let compile_time_constants = - let open Command.Let_syntax 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 Command.async ~summary:"Print a JSON map of the compile-time consensus parameters" - (let%map_open config_file = Cli_lib.Flag.config_files in - fun () -> - let home = Core.Sys.home_directory () in - let conf_dir = home ^/ Cli_lib.Default.conf_dir_name in - let genesis_dir = + (Command.Param.return (fun () -> let home = Core.Sys.home_directory () in - home ^/ Cli_lib.Default.conf_dir_name - in - let open Deferred.Let_syntax in - let%map ({ consensus_constants; _ } as precomputed_values), _ = - (* This is kind of ugly because we are allowing for supplying a runtime_config value directly, rather than force what is read from the environment *) - (* TODO: See if we can initialize consensus_constants without also initializing the ledger *) - let logger = Logger.create () in - let%bind m_conf = - Runtime_config.Json_loader.load_config_files ~conf_dir ~logger - config_file - >>| Or_error.ok + 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 default = - Runtime_config.of_json_layout - { Runtime_config.Json_layout.default with - ledger = - Some - { Runtime_config.Json_layout.Ledger.default with - accounts = Some [] - } - } - |> Result.ok_or_failwith + 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 logger = Logger.create () in + let%map ({ consensus_constants; _ } as precomputed_values), _ = + let%bind runtime_config = + let%map config_file = + Runtime_config.Json_loader.load_config_files ~conf_dir ~logger + [ config_file ] + >>| Or_error.ok + in + let default = + Runtime_config.of_json_layout + { Runtime_config.Json_layout.default with + ledger = + Some + { Runtime_config.Json_layout.Ledger.default with + accounts = Some [] + } + } + |> Result.ok_or_failwith + in + Option.value ~default config_file + in + Genesis_ledger_helper.init_from_config_file ~genesis_constants + ~constraint_constants ~logger:(Logger.null ()) ~proof_level + ~cli_proof_level:None ~genesis_dir runtime_config + >>| Or_error.ok_exn in - let runtime_config = Option.value ~default m_conf in - let constants = - Runtime_config.Constants.load_constants' runtime_config + 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 - Genesis_ledger_helper.Config_loader.init_from_config_file ~genesis_dir - ~logger ~constants runtime_config - |> Deferred.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) ) + Core_kernel.printf "%s\n%!" (Yojson.Safe.to_string all_constants) ) ) let node_status = let open Command.Param in @@ -2316,31 +2318,26 @@ 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.config_files 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 genesis_constants, constraint_constants = - let logger = Logger.create () in - let%map conf = - Runtime_config.Constants.load_constants ~logger config_file - in - Runtime_config.Constants. - (genesis_constants conf, constraint_constants conf) - 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 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 @@ -2351,7 +2348,10 @@ let itn_create_accounts = flag "--num-accounts" ~doc:"NN Number of new accounts" (required int) in let fee = - flag "--fee" ~doc:"NN Fee in nanomina paid to create an account" + 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) ) (required int) in let amount = @@ -2359,28 +2359,13 @@ let itn_create_accounts = ~doc:"NN Amount in nanomina to be divided among new accounts" (required int) in - let config_file = Cli_lib.Flag.config_files in - let args = - Args.zip6 privkey_path key_prefix num_accounts fee amount config_file + 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 in Cli_lib.Background_daemon.rpc_init args - ~f:(fun - port - (privkey_path, key_prefix, num_accounts, fee, amount, config_file) - -> - let open Deferred.Let_syntax in - let%bind genesis_constants, constraint_constants = - let logger = Logger.create () in - let%map conf = - Runtime_config.Constants.load_constants ~logger config_file - in - Runtime_config.Constants. - (genesis_constants conf, constraint_constants conf) - in - let args' = (privkey_path, key_prefix, num_accounts, fee, amount) in - let genesis_constants = genesis_constants in - let constraint_constants = constraint_constants in - Itn.create_accounts ~genesis_constants ~constraint_constants port args' )) + ~f:(Itn.create_accounts ~genesis_constants ~constraint_constants)) module Visualization = struct let create_command (type rpc_response) ~name ~f diff --git a/src/app/delegation_verify/delegation_verify.ml b/src/app/delegation_verify/delegation_verify.ml index ac643b1db67..f160d4c1234 100644 --- a/src/app/delegation_verify/delegation_verify.ml +++ b/src/app/delegation_verify/delegation_verify.ml @@ -13,7 +13,9 @@ let get_filenames = let verify_snark_work ~verify_transaction_snarks ~proof ~message = verify_transaction_snarks [ (proof, message) ] -let config_flag = Cli_lib.Flag.config_files +let config_flag = + let open Command.Param in + flag "--config-file" ~doc:"FILE config file" (optional string) let keyspace_flag = let open Command.Param in @@ -42,15 +44,31 @@ let timestamp = let open Command.Param in anon ("timestamp" %: string) -let instantiate_verify_functions ~logger config_file = - let open Deferred.Let_syntax in - let%map constants = - Runtime_config.Constants.load_constants ~logger config_file - in - let constraint_constants = - Runtime_config.Constants.constraint_constants constants - in - Verifier.verify_functions ~constraint_constants ~proof_level:Full () +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 = + Runtime_config.Json_loader.load_config_files ~logger [ config_file ] + 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 () module Make_verifier (Source : Submission.Data_source) = struct let verify_transaction_snarks = Source.verify_transaction_snarks @@ -121,7 +139,7 @@ module Make_verifier (Source : Submission.Data_source) = struct |> Deferred.Or_error.all_unit end -let filesystem_command ~logger = +let filesystem_command = Command.async ~summary:"Verify submissions and block read from the filesystem" Command.Let_syntax.( let%map_open block_dir = block_dir_flag @@ -129,10 +147,16 @@ let filesystem_command ~logger = and no_checks = no_checks_flag 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 + instantiate_verify_functions ~logger config_file ~genesis_constants + ~constraint_constants ~proof_level ~cli_proof_level:None in - let submission_paths = get_filenames inputs in let module V = Make_verifier (struct include Submission.Filesystem @@ -151,7 +175,7 @@ let filesystem_command ~logger = Output.display_error @@ Error.to_string_hum e ; exit 1) -let cassandra_command ~logger = +let cassandra_command = Command.async ~summary:"Verify submissions and block read from Cassandra" Command.Let_syntax.( let%map_open cqlsh = cassandra_executable_flag @@ -162,8 +186,15 @@ let cassandra_command ~logger = and period_end = timestamp in 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 + instantiate_verify_functions ~logger config_file ~genesis_constants + ~constraint_constants ~proof_level ~cli_proof_level:None in let module V = Make_verifier (struct include Submission.Cassandra @@ -186,15 +217,22 @@ let cassandra_command ~logger = Output.display_error @@ Error.to_string_hum e ; exit 1) -let stdin_command ~logger = +let stdin_command = Command.async ~summary:"Verify submissions and blocks read from standard input" Command.Let_syntax.( 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 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 + instantiate_verify_functions ~logger config_file ~genesis_constants + ~constraint_constants ~proof_level ~cli_proof_level:None in let module V = Make_verifier (struct include Submission.Stdin @@ -210,14 +248,12 @@ let stdin_command ~logger = Output.display_error @@ Error.to_string_hum e ; exit 1) -let command ~logger = +let command = Command.group ~summary:"A tool for verifying JSON payload submitted by the uptime service" - [ ("fs", filesystem_command ~logger) - ; ("cassandra", cassandra_command ~logger) - ; ("stdin", stdin_command ~logger) + [ ("fs", filesystem_command) + ; ("cassandra", cassandra_command) + ; ("stdin", stdin_command) ] -let () = - let logger = Logger.create () in - Async.Command.run @@ command ~logger +let () = Async.Command.run command diff --git a/src/config/dev.mlh b/src/config/dev.mlh index a2bea1045b3..c47c5a0223b 100644 --- a/src/config/dev.mlh +++ b/src/config/dev.mlh @@ -51,6 +51,7 @@ (*BEGIN src/config/amount_defaults/standard.mlh*) +[%%define default_transaction_fee "5"] [%%define default_snark_worker_fee "1"] [%%define minimum_user_command_fee "2"] (*END src/config/amount_defaults/standard.mlh*) diff --git a/src/config/devnet.mlh b/src/config/devnet.mlh index 0b27ffe230b..f9b442f66fa 100644 --- a/src/config/devnet.mlh +++ b/src/config/devnet.mlh @@ -37,6 +37,7 @@ (*BEGIN src/config/amount_defaults/realistic.mlh*) +[%%define default_transaction_fee "0.25"] [%%define default_snark_worker_fee "0.1"] [%%define minimum_user_command_fee "0.001"] (*END src/config/amount_defaults/realistic.mlh*) diff --git a/src/config/lightnet.mlh b/src/config/lightnet.mlh index d59207c06cf..4a3cdcebd26 100644 --- a/src/config/lightnet.mlh +++ b/src/config/lightnet.mlh @@ -37,6 +37,7 @@ (*BEGIN src/config/amount_defaults/realistic.mlh*) +[%%define default_transaction_fee "0.25"] [%%define default_snark_worker_fee "0.1"] [%%define minimum_user_command_fee "0.001"] (*END src/config/amount_defaults/realistic.mlh*) diff --git a/src/config/mainnet.mlh b/src/config/mainnet.mlh index 1af34773c8a..2ed4e16c950 100644 --- a/src/config/mainnet.mlh +++ b/src/config/mainnet.mlh @@ -37,6 +37,7 @@ (*BEGIN src/config/amount_defaults/realistic.mlh*) +[%%define default_transaction_fee "0.25"] [%%define default_snark_worker_fee "0.1"] [%%define minimum_user_command_fee "0.001"] (*END src/config/amount_defaults/realistic.mlh*) diff --git a/src/lib/cli_lib/commands.ml b/src/lib/cli_lib/commands.ml index 4467e4cb915..375a130d6e7 100644 --- a/src/lib/cli_lib/commands.ml +++ b/src/lib/cli_lib/commands.ml @@ -230,20 +230,16 @@ module Vrf = struct flag "--total-stake" ~doc:"AMOUNT The total balance of all accounts in the epoch ledger" (optional int) - and config_file = Flag.config_files in + in Exceptions.handle_nicely @@ fun () -> let env = Secrets.Keypair.env in - let open Deferred.Let_syntax in - let%bind constraint_constants = - let logger = Logger.create () in - let%map conf = - Runtime_config.Constants.load_constants ~logger config_file - in - Runtime_config.Constants.constraint_constants conf + let constraint_constants = + Genesis_constants.Compiled.constraint_constants 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 = @@ -301,21 +297,17 @@ 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 - and config_file = Flag.config_files in + let%map_open privkey_path = Flag.privkey_read_path 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 open Deferred.Let_syntax in - let%bind constraint_constants = - let logger = Logger.create () in - let%map conf = - Runtime_config.Constants.load_constants ~logger config_file - in - Runtime_config.Constants.constraint_constants conf - in + (* TODO-someday: constraint constants from config file. *) let%bind () = let password = lazy @@ -370,18 +362,13 @@ 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." - (let open Command.Let_syntax in - let%map_open config_file = Flag.config_files in - Exceptions.handle_nicely + ( Command.Param.return @@ Exceptions.handle_nicely @@ fun () -> let open Deferred.Let_syntax in - let%bind constraint_constants = - let logger = Logger.create () in - let%map conf = - Runtime_config.Constants.load_constants ~logger config_file - in - Runtime_config.Constants.constraint_constants conf + let constraint_constants = + Genesis_constants.Compiled.constraint_constants in + (* TODO-someday: constraint constants from config file. *) let lexbuf = Lexing.from_channel In_channel.stdin in let lexer = Yojson.init_lexer () in let%bind () = @@ -412,7 +399,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/flag.ml b/src/lib/cli_lib/flag.ml index 64b279757d6..c96200feb9e 100644 --- a/src/lib/cli_lib/flag.ml +++ b/src/lib/cli_lib/flag.ml @@ -33,15 +33,6 @@ let conf_dir = flag "--config-directory" ~aliases:[ "config-directory" ] ~doc:"DIR Configuration directory" (optional string) -let config_files = - let open Command.Param in - 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) - module Doc_builder = struct type 'value t = { type_name : string @@ -352,24 +343,32 @@ end type signed_command_common = { sender : Signature_lib.Public_key.Compressed.t - ; fee : Currency.Fee.t option + ; fee : Currency.Fee.t ; nonce : Mina_base.Account.Nonce.t option ; memo : string option } -let fee_common : Currency.Fee.t option Command.Param.t = +let fee_common ~default_transaction_fee ~minimum_user_command_fee : + Currency.Fee.t Command.Param.t = Command.Param.flag "--fee" ~aliases:[ "fee" ] - ~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 = + ~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 = 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 + and fee = fee_common ~default_transaction_fee ~minimum_user_command_fee and nonce = flag "--nonce" ~aliases:[ "nonce" ] ~doc: @@ -402,10 +401,15 @@ module Signed_command = struct flag "--amount" ~aliases:[ "amount" ] ~doc:"VALUE Payment amount you want to send" (required txn_amount) - let fee = + let fee ~default_transaction_fee ~minimum_user_command_fee = let open Command.Param in flag "--fee" ~aliases:[ "fee" ] - ~doc:"FEE Amount you are willing to pay to process the transaction" + ~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) ) (optional txn_fee) let valid_until = diff --git a/src/lib/cli_lib/flag.mli b/src/lib/cli_lib/flag.mli index dda9c630ce5..69ff38f86f3 100644 --- a/src/lib/cli_lib/flag.mli +++ b/src/lib/cli_lib/flag.mli @@ -12,8 +12,6 @@ val privkey_read_path : string Command.Param.t val conf_dir : string option Command.Param.t -val config_files : string list Command.Param.t - module Types : sig type 'a with_name = { name : string; value : 'a } @@ -83,14 +81,20 @@ end type signed_command_common = { sender : Signature_lib.Public_key.Compressed.t - ; fee : Currency.Fee.t option + ; fee : Currency.Fee.t ; nonce : Mina_base.Account.Nonce.t option ; memo : string option } -val fee_common : Currency.Fee.t option Command.Param.t +val fee_common : + default_transaction_fee:Currency.Fee.t + -> minimum_user_command_fee:Currency.Fee.t + -> Currency.Fee.t Command.Param.t -val signed_command_common : signed_command_common 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 module Signed_command : sig val hd_index : Mina_numbers.Hd_index.t Command.Param.t @@ -99,7 +103,10 @@ module Signed_command : sig val amount : Currency.Amount.t Command.Param.t - val fee : Currency.Fee.t option 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 valid_until : Mina_numbers.Global_slot_since_genesis.t option Command.Param.t diff --git a/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml b/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml index e3c4b62cbb3..b669fd3bc65 100644 --- a/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml +++ b/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml @@ -666,7 +666,7 @@ module Genesis_proof = struct return None let generate_inputs ~runtime_config ~proof_level ~ledger ~genesis_epoch_data - ~constraint_constants ~blockchain_proof_system_id ~compile_config + ~constraint_constants ~blockchain_proof_system_id ~(genesis_constants : Genesis_constants.t) = let consensus_constants = Consensus.Constants.create ~constraint_constants @@ -682,7 +682,6 @@ module Genesis_proof = struct { Genesis_proof.Inputs.runtime_config ; constraint_constants ; proof_level - ; compile_config ; blockchain_proof_system_id ; genesis_ledger = ledger ; genesis_epoch_data @@ -709,7 +708,6 @@ module Genesis_proof = struct ; consensus_constants = inputs.consensus_constants ; constraint_constants = inputs.constraint_constants ; genesis_body_reference = inputs.genesis_body_reference - ; compile_config = inputs.compile_config } | _ -> Deferred.return (Genesis_proof.create_values_no_proof inputs) @@ -761,138 +759,109 @@ let print_config ~logger (config : Runtime_config.t) = [%log info] "Initializing with runtime configuration. Ledger name: $name" ~metadata -module type Config_loader_intf = sig - val load_config_files : - ?overwrite_version:Mina_numbers.Txn_version.t - -> ?genesis_dir:string - -> ?itn_features:bool - -> ?cli_proof_level:Genesis_constants.Proof_level.t - -> ?conf_dir:string - -> logger:Logger.t - -> string list - -> (Precomputed_values.t * Runtime_config.t) Deferred.Or_error.t - - (* Mostly loads genesis ledger and epoch data *) - val init_from_config_file : - ?overwrite_version:Mina_numbers.Txn_version.t - -> ?genesis_dir:string - -> logger:Logger.t - -> constants:Runtime_config.Constants.constants - -> Runtime_config.t - -> (Precomputed_values.t * Runtime_config.t) Deferred.Or_error.t -end - -module Config_loader : Config_loader_intf = struct - let inputs_from_config_file ?(genesis_dir = Cache_dir.autogen_path) ~logger - ~(constants : Runtime_config.Constants.constants) ?overwrite_version - (config : Runtime_config.t) = - print_config ~logger config ; - let open Deferred.Or_error.Let_syntax in - let constraint_constants = - Runtime_config.Constants.constraint_constants constants - in - let proof_level = Runtime_config.Constants.proof_level constants in - let compile_config = Runtime_config.Constants.compile_config constants in - let genesis_constants = - Runtime_config.Constants.genesis_constants constants - 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 - ~compile_config ~blockchain_proof_system_id:None ~genesis_epoch_data - in - (proof_inputs, config) - - let init_from_config_file ?overwrite_version ?genesis_dir ~logger - ~(constants : Runtime_config.Constants.constants) - (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 ~constants ~logger ?overwrite_version - config - in - let values = Genesis_proof.create_values_no_proof inputs in - (values, config) - - let load_config_files ?overwrite_version ?genesis_dir ?(itn_features = false) - ?cli_proof_level ?conf_dir ~logger (config_files : string list) = - let open Deferred.Or_error.Let_syntax in - let genesis_dir = - let%map.Option conf_dir = conf_dir in - Option.value ~default:(conf_dir ^/ "genesis") genesis_dir - in - let%bind.Deferred constants = - Runtime_config.Constants.load_constants ?conf_dir ?cli_proof_level - ~itn_features ~logger config_files - in - let%bind config = - Runtime_config.Json_loader.load_config_files ?conf_dir ~logger - config_files - in - match%bind.Deferred - init_from_config_file ?overwrite_version ?genesis_dir ~logger ~constants - config - with - | Ok a -> - return a - | 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) - ] +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 + | No_check -> + No_check) + ; 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 - [%log info] - "Initializing with runtime configuration. Ledger source: $name" - ~metadata ; - Error.raise err -end + ( make_constraint_constants ~default:constraint_constants config + , blockchain_proof_system_id ) + in + let%bind () = + match (proof_level, compiled_proof_level) with + | _, Full | (Check | No_check), _ -> + return () + | Full, ((Check | No_check) 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%test_module "Account config test" = ( module struct 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 6b324d0cdb8..ce385ad3acc 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 @@ -424,10 +424,25 @@ let make_constraint_constants in let transaction_capacity_log_2 = match config.transaction_capacity with - | Some transaction_capacity -> - Runtime_config.Proof_keys.Transaction_capacity - .to_transaction_capacity_log_2 ~block_window_duration_ms - ~transaction_capacity + | 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 diff --git a/src/lib/genesis_proof/genesis_proof.ml b/src/lib/genesis_proof/genesis_proof.ml index db2aabbeccb..9d3c74d6a18 100644 --- a/src/lib/genesis_proof/genesis_proof.ml +++ b/src/lib/genesis_proof/genesis_proof.ml @@ -8,7 +8,6 @@ module Inputs = struct ; 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 @@ -86,7 +85,6 @@ module T = struct ; constraint_constants : Genesis_constants.Constraint_constants.t ; genesis_constants : Genesis_constants.t ; proof_level : Genesis_constants.Proof_level.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 @@ -225,7 +223,6 @@ let create_values_no_proof (t : Inputs.t) = ; 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 @@ -243,7 +240,6 @@ let to_inputs (t : t) : Inputs.t = ; 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_compile_config/mina_compile_config.ml b/src/lib/mina_compile_config/mina_compile_config.ml index e05cd77ce2b..ddee9ab841c 100644 --- a/src/lib/mina_compile_config/mina_compile_config.ml +++ b/src/lib/mina_compile_config/mina_compile_config.ml @@ -9,6 +9,7 @@ open Core_kernel module Inputs = struct type t = { curve_size : int + ; default_transaction_fee_string : string ; default_snark_worker_fee_string : string ; minimum_user_command_fee_string : string ; itn_features : bool @@ -36,6 +37,7 @@ end type t = { curve_size : int + ; default_transaction_fee : Currency.Fee.Stable.Latest.t ; default_snark_worker_fee : Currency.Fee.Stable.Latest.t ; minimum_user_command_fee : Currency.Fee.Stable.Latest.t ; itn_features : bool @@ -62,6 +64,8 @@ type t = let make (inputs : Inputs.t) = { curve_size = inputs.curve_size + ; default_transaction_fee = + Currency.Fee.of_mina_string_exn inputs.default_transaction_fee_string ; default_snark_worker_fee = Currency.Fee.of_mina_string_exn inputs.default_snark_worker_fee_string ; minimum_user_command_fee = @@ -96,6 +100,8 @@ let make (inputs : Inputs.t) = let to_yojson t = `Assoc [ ("curve_size", `Int t.curve_size) + ; ( "default_transaction_fee" + , Currency.Fee.to_yojson t.default_transaction_fee ) ; ( "default_snark_worker_fee" , Currency.Fee.to_yojson t.default_snark_worker_fee ) ; ( "minimum_user_command_fee" @@ -136,6 +142,7 @@ 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 @@ -170,6 +177,8 @@ 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 = diff --git a/src/lib/mina_lib/tests/tests.ml b/src/lib/mina_lib/tests/tests.ml index 20afe1d94b3..61a05b1572e 100644 --- a/src/lib/mina_lib/tests/tests.ml +++ b/src/lib/mina_lib/tests/tests.ml @@ -48,6 +48,11 @@ 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 @@ -58,9 +63,7 @@ let%test_module "Epoch ledger sync tests" = let runtime_config : Runtime_config.t = { daemon = None ; genesis = None - ; proof = - Some - { Runtime_config.Proof_keys.default with level = Some No_check } + ; proof = None ; ledger = Some { base = Named "test" @@ -75,11 +78,10 @@ let%test_module "Epoch ledger sync tests" = } in match%map - Genesis_ledger_helper.Config_loader.init_from_config_file + Genesis_ledger_helper.init_from_config_file ~genesis_dir:(make_dirname "genesis_dir") - ~constants: - (Runtime_config.Constants.magic_for_unit_tests runtime_config) - ~logger runtime_config + ~constraint_constants ~genesis_constants ~logger + ~proof_level:No_check runtime_config ~cli_proof_level:None with | Ok (precomputed_values, _) -> precomputed_values diff --git a/src/lib/node_config/for_unit_tests/node_config_for_unit_tests.ml b/src/lib/node_config/for_unit_tests/node_config_for_unit_tests.ml index edd73b7fbdc..7629ba98f1d 100644 --- a/src/lib/node_config/for_unit_tests/node_config_for_unit_tests.ml +++ b/src/lib/node_config/for_unit_tests/node_config_for_unit_tests.ml @@ -39,6 +39,8 @@ let (pool_max_size : int) = (3000 : int) let (account_creation_fee_int : string) = ("0.001" : string) +let (default_transaction_fee : string) = ("5" : string) + let (default_snark_worker_fee : string) = ("1" : string) let (minimum_user_command_fee : string) = ("2" : string) diff --git a/src/lib/node_config/intf/node_config_intf.mli b/src/lib/node_config/intf/node_config_intf.mli index 3892b7b53df..7cb48a7a29f 100644 --- a/src/lib/node_config/intf/node_config_intf.mli +++ b/src/lib/node_config/intf/node_config_intf.mli @@ -66,6 +66,8 @@ module type S = sig val account_creation_fee_int : string + val default_transaction_fee : string + val default_snark_worker_fee : string val minimum_user_command_fee : string diff --git a/src/lib/node_config/node_config.ml b/src/lib/node_config/node_config.ml index fbcf2753978..d791ea413a4 100644 --- a/src/lib/node_config/node_config.ml +++ b/src/lib/node_config/node_config.ml @@ -56,6 +56,8 @@ let scan_state_transaction_capacity_log_2 = [%%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] diff --git a/src/lib/pickles/snarky_tests/dune b/src/lib/pickles/snarky_tests/dune index 5fbfe8499c7..a9710cf679b 100644 --- a/src/lib/pickles/snarky_tests/dune +++ b/src/lib/pickles/snarky_tests/dune @@ -68,5 +68,4 @@ blockchain_snark transaction_snark genesis_constants - mina_runtime_config core)) diff --git a/src/lib/pickles/snarky_tests/snarky_tests.ml b/src/lib/pickles/snarky_tests/snarky_tests.ml index 82aad430d4b..c9c15ca285e 100644 --- a/src/lib/pickles/snarky_tests/snarky_tests.ml +++ b/src/lib/pickles/snarky_tests/snarky_tests.ml @@ -585,12 +585,14 @@ 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 print_hash print expected digest : unit = if print then ( Format.printf "expected:\n%s\n" expected ; Format.printf "obtained:\n%s\n" digest ) - let blockchain ~constraint_constants () : unit = + let blockchain () : unit = let expected = "36786c300e37c2a2f1341ad6374aa113" in let digest = Blockchain_snark.Blockchain_snark_state.constraint_system_digests @@ -605,7 +607,7 @@ module Protocol_circuits = struct assert digests_match ; () - let transaction ~constraint_constants () : unit = + let transaction () : unit = let expected1 = "b8879f677f622a1d86648030701f43e1" in let expected2 = "740db2397b0b01806a48f061a2e2b063" in let digest = @@ -630,9 +632,9 @@ module Protocol_circuits = struct assert check ; () - let tests ~constraint_constants = - [ ("test blockchain circuit", `Quick, blockchain ~constraint_constants) - ; ("test transaction circuit", `Quick, transaction ~constraint_constants) + let tests = + [ ("test blockchain circuit", `Quick, blockchain) + ; ("test transaction circuit", `Quick, transaction) ] end @@ -645,25 +647,16 @@ let api_tests = ] let () = - Async.Thread_safe.block_on_async_exn - @@ fun () -> let range_checks = List.map ~f:QCheck_alcotest.to_alcotest [ RangeCircuits.test_range_gates ] in - let logger = Logger.create () in - let%map.Async.Deferred constraint_constants = - let%map.Async.Deferred config = - Runtime_config.Constants.load_constants ~logger [] - in - Runtime_config.Constants.constraint_constants config - in Alcotest.run "Simple snarky tests" [ ("outside of circuit tests before", outside_circuit_tests) ; ("API tests", api_tests) ; ("circuit tests", circuit_tests) ; ("As_prover tests", As_prover_circuits.as_prover_tests) ; ("range checks", range_checks) - ; ("protocol circuits", Protocol_circuits.tests ~constraint_constants) + ; ("protocol circuits", Protocol_circuits.tests) ; ("improper calls", Improper_calls.tests) (* We run the pure functions before and after other tests, because we've had bugs in the past where it would only work after the global state was initialized by an API function diff --git a/src/lib/precomputed_values/precomputed_values.ml b/src/lib/precomputed_values/precomputed_values.ml index c5d03d0020e..fd97c4ec317 100644 --- a/src/lib/precomputed_values/precomputed_values.ml +++ b/src/lib/precomputed_values/precomputed_values.ml @@ -43,5 +43,4 @@ let for_unit_tests = ; protocol_state_with_hashes ; constraint_system_digests = hashes ; proof_data = None - ; compile_config = Mina_compile_config.For_unit_tests.t }) diff --git a/src/lib/runtime_config/runtime_config.ml b/src/lib/runtime_config/runtime_config.ml index fe547e87994..7846e46f27e 100644 --- a/src/lib/runtime_config/runtime_config.ml +++ b/src/lib/runtime_config/runtime_config.ml @@ -1033,30 +1033,6 @@ module Proof_keys = struct let small : t = Log_2 2 let medium : t = Log_2 3 - - let to_transaction_capacity_log_2 ~block_window_duration_ms - ~transaction_capacity = - match transaction_capacity with - | Log_2 i -> - i - | 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) end type t = @@ -1088,19 +1064,6 @@ module Proof_keys = struct ; fork } - let default = - { 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 = None - } - let to_json_layout { level ; sub_windows_per_window @@ -1782,251 +1745,3 @@ module Json_loader : Json_loader_intf = struct ] ; failwithf "Could not parse configuration file: %s" err () ) end - -module type Constants_intf = sig - type constants - - val load_constants : - ?conf_dir:string - -> ?commit_id_short:string - -> ?itn_features:bool - -> ?cli_proof_level:Genesis_constants.Proof_level.t - -> logger:Logger.t - -> string list - -> constants Deferred.t - - val load_constants' : - ?itn_features:bool - -> ?cli_proof_level:Genesis_constants.Proof_level.t - -> t - -> constants - - val genesis_constants : constants -> Genesis_constants.t - - val constraint_constants : - constants -> Genesis_constants.Constraint_constants.t - - val proof_level : constants -> Genesis_constants.Proof_level.t - - val compile_config : constants -> Mina_compile_config.t - - val magic_for_unit_tests : t -> constants -end - -module Constants : Constants_intf = struct - type constants = - { 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 genesis_constants t = t.genesis_constants - - let constraint_constants t = t.constraint_constants - - let proof_level t = t.proof_level - - let compile_config t = t.compile_config - - let combine (a : constants) (b : t) : constants = - let genesis_constants = - { Genesis_constants.protocol = - { k = - Option.value ~default:a.genesis_constants.protocol.k - Option.(b.genesis >>= fun g -> g.k) - ; delta = - Option.value ~default:a.genesis_constants.protocol.delta - Option.(b.genesis >>= fun g -> g.delta) - ; slots_per_epoch = - Option.value ~default:a.genesis_constants.protocol.slots_per_epoch - Option.(b.genesis >>= fun g -> g.slots_per_epoch) - ; slots_per_sub_window = - Option.value - ~default:a.genesis_constants.protocol.slots_per_sub_window - Option.(b.genesis >>= fun g -> g.slots_per_sub_window) - ; grace_period_slots = - Option.value - ~default:a.genesis_constants.protocol.grace_period_slots - Option.(b.genesis >>= fun g -> g.grace_period_slots) - ; genesis_state_timestamp = - Option.value - ~default:a.genesis_constants.protocol.genesis_state_timestamp - Option.( - b.genesis - >>= fun g -> - g.genesis_state_timestamp - >>| Genesis_constants.genesis_timestamp_of_string - >>| Genesis_constants.of_time) - } - ; txpool_max_size = - Option.value ~default:a.genesis_constants.txpool_max_size - Option.(b.daemon >>= fun d -> d.txpool_max_size) - ; num_accounts = - Option.first_some - Option.(b.ledger >>= fun l -> l.num_accounts) - a.genesis_constants.num_accounts - ; zkapp_proof_update_cost = - Option.value ~default:a.genesis_constants.zkapp_proof_update_cost - Option.(b.daemon >>= fun d -> d.zkapp_proof_update_cost) - ; zkapp_signed_single_update_cost = - Option.value - ~default:a.genesis_constants.zkapp_signed_single_update_cost - Option.(b.daemon >>= fun d -> d.zkapp_signed_single_update_cost) - ; zkapp_signed_pair_update_cost = - Option.value - ~default:a.genesis_constants.zkapp_signed_pair_update_cost - Option.(b.daemon >>= fun d -> d.zkapp_signed_pair_update_cost) - ; zkapp_transaction_cost_limit = - Option.value ~default:a.genesis_constants.zkapp_transaction_cost_limit - Option.(b.daemon >>= fun d -> d.zkapp_transaction_cost_limit) - ; max_event_elements = - Option.value ~default:a.genesis_constants.max_event_elements - Option.(b.daemon >>= fun d -> d.max_event_elements) - ; max_action_elements = - Option.value ~default:a.genesis_constants.max_action_elements - Option.(b.daemon >>= fun d -> d.max_action_elements) - ; zkapp_cmd_limit_hardcap = - Option.value ~default:a.genesis_constants.zkapp_cmd_limit_hardcap - Option.(b.daemon >>= fun d -> d.zkapp_cmd_limit_hardcap) - ; minimum_user_command_fee = - Option.value ~default:a.genesis_constants.minimum_user_command_fee - Option.(b.daemon >>= fun d -> d.minimum_user_command_fee) - } - in - let constraint_constants = - let fork = - let a = a.constraint_constants.fork in - let b = - let%map.Option f = Option.(b.proof >>= fun x -> x.fork) in - { Genesis_constants.Fork_constants.state_hash = - Mina_base.State_hash.of_base58_check_exn f.state_hash - ; blockchain_length = Mina_numbers.Length.of_int f.blockchain_length - ; global_slot_since_genesis = - Mina_numbers.Global_slot_since_genesis.of_int - f.global_slot_since_genesis - } - in - Option.first_some b a - in - let block_window_duration_ms = - Option.value ~default:a.constraint_constants.block_window_duration_ms - Option.(b.proof >>= fun p -> p.block_window_duration_ms) - in - { a.constraint_constants with - sub_windows_per_window = - Option.value ~default:a.constraint_constants.sub_windows_per_window - Option.(b.proof >>= fun p -> p.sub_windows_per_window) - ; ledger_depth = - Option.value ~default:a.constraint_constants.ledger_depth - Option.(b.proof >>= fun p -> p.ledger_depth) - ; work_delay = - Option.value ~default:a.constraint_constants.work_delay - Option.(b.proof >>= fun p -> p.work_delay) - ; block_window_duration_ms - ; transaction_capacity_log_2 = - Option.value - ~default:a.constraint_constants.transaction_capacity_log_2 - Option.( - b.proof - >>= fun p -> - p.transaction_capacity - >>| fun transaction_capacity -> - Proof_keys.Transaction_capacity.to_transaction_capacity_log_2 - ~block_window_duration_ms ~transaction_capacity) - ; coinbase_amount = - Option.value ~default:a.constraint_constants.coinbase_amount - Option.(b.proof >>= fun p -> p.coinbase_amount) - ; supercharged_coinbase_factor = - Option.value - ~default:a.constraint_constants.supercharged_coinbase_factor - Option.(b.proof >>= fun p -> p.supercharged_coinbase_factor) - ; account_creation_fee = - Option.value ~default:a.constraint_constants.account_creation_fee - Option.(b.proof >>= fun p -> p.account_creation_fee) - ; fork - } - in - let proof_level = - let coerce_proof_level = function - | Proof_keys.Level.Full -> - Genesis_constants.Proof_level.Full - | Check -> - Genesis_constants.Proof_level.Check - | No_check -> - Genesis_constants.Proof_level.No_check - in - Option.value ~default:a.proof_level - Option.(b.proof >>= fun p -> p.level >>| coerce_proof_level) - in - let compile_config = - { a.compile_config with - block_window_duration = - constraint_constants.block_window_duration_ms |> Float.of_int - |> Time.Span.of_ms - ; zkapp_proof_update_cost = genesis_constants.zkapp_proof_update_cost - ; zkapp_signed_single_update_cost = - genesis_constants.zkapp_signed_single_update_cost - ; zkapp_signed_pair_update_cost = - genesis_constants.zkapp_signed_pair_update_cost - ; zkapp_transaction_cost_limit = - genesis_constants.zkapp_transaction_cost_limit - ; max_event_elements = genesis_constants.max_event_elements - ; max_action_elements = genesis_constants.max_action_elements - ; zkapp_cmd_limit_hardcap = genesis_constants.zkapp_cmd_limit_hardcap - ; minimum_user_command_fee = genesis_constants.minimum_user_command_fee - ; network_id = - Option.value ~default:a.compile_config.network_id - Option.(b.daemon >>= fun d -> d.network_id) - ; sync_ledger_max_subtree_depth = - Option.value ~default:a.compile_config.sync_ledger_max_subtree_depth - Option.(b.daemon >>= fun d -> d.sync_ledger_max_subtree_depth) - ; sync_ledger_default_subtree_depth = - Option.value - ~default:a.compile_config.sync_ledger_default_subtree_depth - Option.(b.daemon >>= fun d -> d.sync_ledger_default_subtree_depth) - } - in - { genesis_constants; constraint_constants; proof_level; compile_config } - - let load_constants' ?itn_features ?cli_proof_level runtime_config = - let compile_constants = - { genesis_constants = Genesis_constants.Compiled.genesis_constants - ; constraint_constants = Genesis_constants.Compiled.constraint_constants - ; proof_level = Genesis_constants.Compiled.proof_level - ; compile_config = Mina_compile_config.Compiled.t - } - in - let cs = combine compile_constants runtime_config in - { cs with - proof_level = Option.value ~default:cs.proof_level cli_proof_level - ; compile_config = - { cs.compile_config with - itn_features = - Option.value ~default:cs.compile_config.itn_features itn_features - } - } - - (* Use this function if you don't need/want the ledger configuration *) - let load_constants ?conf_dir ?commit_id_short ?itn_features ?cli_proof_level - ~logger config_files = - Deferred.Or_error.ok_exn - @@ - let open Deferred.Or_error.Let_syntax in - let%map runtime_config = - Json_loader.load_config_files ?conf_dir ?commit_id_short ~logger - config_files - in - load_constants' ?itn_features ?cli_proof_level runtime_config - - let magic_for_unit_tests t = - let compile_constants = - { genesis_constants = Genesis_constants.For_unit_tests.t - ; constraint_constants = - Genesis_constants.For_unit_tests.Constraint_constants.t - ; proof_level = Genesis_constants.For_unit_tests.Proof_level.t - ; compile_config = Mina_compile_config.For_unit_tests.t - } - in - combine compile_constants t -end diff --git a/src/lib/snark_worker/functor.ml b/src/lib/snark_worker/functor.ml index 1dfa6f06dc6..a62453e2877 100644 --- a/src/lib/snark_worker/functor.ml +++ b/src/lib/snark_worker/functor.ml @@ -340,7 +340,8 @@ module Make (Inputs : Intf.Inputs_intf) : in go () - let command_from_rpcs ~commit_id + let command_from_rpcs ~commit_id ~proof_level:default_proof_level + ~constraint_constants (module Rpcs_versioned : Intf.Rpcs_versioned_S with type Work.ledger_proof = Inputs.Ledger_proof.t ) = Command.async ~summary:"Snark worker" @@ -349,7 +350,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 cli_proof_level = + and proof_level = flag "--proof-level" ~aliases:[ "proof-level" ] (optional (Arg_type.create Genesis_constants.Proof_level.of_string)) ~doc:"full|check|none" @@ -359,19 +360,13 @@ module Make (Inputs : Intf.Inputs_intf) : (optional bool) ~doc: "true|false Shutdown when disconnected from daemon (default:true)" - and config_file = Cli_lib.Flag.config_files and conf_dir = Cli_lib.Flag.conf_dir in fun () -> let logger = Logger.create () ~metadata:[ ("process", `String "Snark Worker") ] in - let%bind.Deferred constraint_constants, proof_level = - let%map.Deferred config = - Runtime_config.Constants.load_constants ?conf_dir ?cli_proof_level - ~logger config_file - in - Runtime_config.Constants. - (constraint_constants config, proof_level config) + 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 diff --git a/src/lib/snark_worker/intf.ml b/src/lib/snark_worker/intf.ml index 2a9d93bb03c..9173d066d9c 100644 --- a/src/lib/snark_worker/intf.ml +++ b/src/lib/snark_worker/intf.ml @@ -154,6 +154,8 @@ 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 @@ -171,5 +173,9 @@ module type S = sig module Rpcs_versioned : Rpcs_versioned_S with type Work.ledger_proof = ledger_proof - val command : commit_id:string -> Command.t + val command : + commit_id:string + -> proof_level:Genesis_constants.Proof_level.t + -> constraint_constants:Genesis_constants.Constraint_constants.t + -> Command.t end diff --git a/src/lib/snark_worker/standalone/run_snark_worker.ml b/src/lib/snark_worker/standalone/run_snark_worker.ml index 9421ccde2b1..3f8b55c1295 100644 --- a/src/lib/snark_worker/standalone/run_snark_worker.ml +++ b/src/lib/snark_worker/standalone/run_snark_worker.ml @@ -76,8 +76,7 @@ let command = "Snark work spec in sexp format (json formats are preferred over \ sexp if both are passed)" (optional string) - and config_file = Cli_lib.Flag.config_files - and cli_proof_level = + and proof_level = flag "--proof-level" ~doc:"" (optional_with_default Genesis_constants.Proof_level.Full (Command.Arg_type.of_alist_exn @@ -105,14 +104,8 @@ let command = in fun () -> let open Async in - let open Deferred.Let_syntax in - let%bind constraint_constants, proof_level = - let logger = Logger.create () in - let%map conf = - Runtime_config.Constants.load_constants ~cli_proof_level ~logger - config_file - in - Runtime_config.Constants.(constraint_constants conf, proof_level conf) + let constraint_constants = + Genesis_constants.Compiled.constraint_constants in let%bind worker_state = Prod.Worker_state.create ~constraint_constants ~proof_level () From a40b65a29b993c7b5269df31eb6a0a63dbc637b0 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 28 Jan 2025 23:49:21 +0000 Subject: [PATCH 09/16] Revert "Merge pull request #16167 from MinaProtocol/martin/unify-json-config-loading" This reverts commit 0b1293261ae9d170244a57eb0d3656e0add8dfef, reversing changes made to 6df5977c39b37653eb8360f63448fcb033a485f3. --- .../src/cli_entrypoint/mina_cli_entrypoint.ml | 270 +++++++++++++----- src/app/cli/src/init/client.ml | 32 +-- .../delegation_verify/delegation_verify.ml | 7 +- .../runtime_genesis_ledger.ml | 14 +- .../zkapp_test_transaction/lib/commands.ml | 8 +- .../genesis_ledger_helper.ml | 82 +++++- src/lib/runtime_config/dune | 4 +- src/lib/runtime_config/runtime_config.ml | 152 +++------- 8 files changed, 336 insertions(+), 233 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 79f00cd6dbb..5ef8f69c6f9 100644 --- a/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml +++ b/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml @@ -50,48 +50,92 @@ let plugin_flag = else Command.Param.return [] let load_config_files ~logger ~genesis_constants ~constraint_constants ~conf_dir - ~genesis_dir ~cli_proof_level ~proof_level (config_files : string list) = - let open Deferred.Or_error.Let_syntax in + ~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 config = - Runtime_config.Json_loader.load_config_files ~conf_dir ~logger config_files + 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 - match%bind.Deferred - Genesis_ledger_helper.init_from_config_file ~cli_proof_level ~genesis_dir - ~logger ~genesis_constants ~constraint_constants ~proof_level config - with - | Ok a -> - return a - | 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 + return (precomputed_values, config_jsons, config) let setup_daemon logger ~itn_features ~default_snark_worker_fee = let open Command.Let_syntax in @@ -686,6 +730,45 @@ 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 @@ -693,55 +776,74 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = Genesis_constants.Compiled.constraint_constants in let compile_config = Mina_compile_config.Compiled.t in - let%bind precomputed_values, config = + 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 - |> Deferred.Or_error.ok_exn in constraint_constants.block_window_duration_ms |> Float.of_int |> Time.Span.of_ms |> Mina_metrics.initialize_all ; + (* We reverse the list because we want to find the "most relevant" value, i.e. the + last time it was declared in the list of supplied config files + *) + let rev_daemon_configs = + List.rev_filter_map config_jsons + ~f:(fun (config_file, config_json) -> + Yojson.Safe.Util.member "daemon" config_json + |> fun x -> + Runtime_config.Daemon.of_yojson x + |> Result.ok + |> Option.map ~f:(fun daemon_config -> + (config_file, daemon_config) ) ) + in + let module DC = Runtime_config.Daemon in (* The explicit typing here is necessary to prevent type inference from specializing according to the first usage. *) let maybe_from_config (type a) : - getter:(DC.t -> a option) -> preferred_value:a option -> a option - = - fun ~getter ~preferred_value -> - Option.first_some preferred_value Option.(config.daemon >>= getter) + getter:(DC.t -> a option) + -> keyname:string + -> preferred_value:a option + -> a option = + fun ~getter ~keyname ~preferred_value -> + Runtime_config.Config_loader.maybe_from_config ~logger + ~configs:rev_daemon_configs ~getter ~keyname ~preferred_value in let or_from_config (type a) : getter:(DC.t -> a option) + -> keyname:string -> preferred_value:a option -> default:a -> a = - fun ~getter ~preferred_value ~default -> - Option.first_some preferred_value Option.(config.daemon >>= getter) - |> Option.value ~default + fun ~getter ~keyname ~preferred_value ~default -> + Runtime_config.Config_loader.or_from_config ~logger + ~configs:rev_daemon_configs ~getter ~keyname ~preferred_value + ~default in let libp2p_port = - or_from_config ~getter:DC.libp2p_port + or_from_config ~keyname:"libp2p-port" ~getter:DC.libp2p_port ~preferred_value:libp2p_port.value ~default:libp2p_port.default in let rest_server_port = - or_from_config ~getter:DC.rest_port + or_from_config ~keyname:"rest-port" ~getter:DC.rest_port ~preferred_value:rest_server_port.value ~default:rest_server_port.default in let limited_graphql_port = - maybe_from_config ~getter:DC.graphql_port + maybe_from_config ~keyname:"limited-graphql-port" + ~getter:DC.graphql_port ~preferred_value:limited_graphql_port.value in let client_port = - or_from_config ~getter:DC.client_port + or_from_config ~keyname:"client-port" ~getter:DC.client_port ~preferred_value:client_port.value ~default:client_port.default in let snark_work_fee = - or_from_config + or_from_config ~keyname:"snark-worker-fee" ~getter:(fun x -> DC.snark_worker_fee x |> Option.map ~f:Currency.Fee.of_nanomina_int_exn ) @@ -749,8 +851,8 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = ~default:compile_config.default_snark_worker_fee in let node_status_url = - maybe_from_config ~getter:DC.node_status_url - ~preferred_value:node_status_url + maybe_from_config ~keyname:"node-status-url" + ~getter:DC.node_status_url ~preferred_value:node_status_url in (* FIXME #4095: pass this through to Gossip_net.Libp2p *) let _max_concurrent_connections = @@ -762,7 +864,7 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = None in let work_selection_method = - or_from_config + or_from_config ~keyname:"work-selection" ~getter:(fun x -> DC.work_selection x |> Option.map ~f:Cli_lib.Arg_type.work_selection_method_val ) @@ -770,21 +872,25 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = ~default:Cli_lib.Arg_type.Work_selection_method.Random in let work_reassignment_wait = - or_from_config ~getter:DC.work_reassignment_wait + or_from_config ~keyname:"work-reassignment-wait" + ~getter:DC.work_reassignment_wait ~preferred_value:work_reassignment_wait ~default:Cli_lib.Default.work_reassignment_wait in let log_received_snark_pool_diff = - or_from_config ~getter:DC.log_snark_work_gossip + or_from_config ~keyname:"log-snark-work-gossip" + ~getter:DC.log_snark_work_gossip ~preferred_value:log_received_snark_pool_diff ~default:false in let log_transaction_pool_diff = - or_from_config ~getter:DC.log_txn_pool_gossip + or_from_config ~keyname:"log-txn-pool-gossip" + ~getter:DC.log_txn_pool_gossip ~preferred_value:log_transaction_pool_diff ~default:false in let log_block_creation = - or_from_config ~getter:DC.log_block_creation - ~preferred_value:log_block_creation ~default:true + or_from_config ~keyname:"log-block-creation" + ~getter:DC.log_block_creation ~preferred_value:log_block_creation + ~default:true in let log_gossip_heard = { Mina_networking.Config.snark_pool_diff = @@ -808,7 +914,7 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = "The %s public key %s could not be decoded." which pk_str in let run_snark_worker_flag = - maybe_from_config + maybe_from_config ~keyname:"run-snark-worker" ~getter: Option.( fun x -> @@ -817,7 +923,7 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = ~preferred_value:run_snark_worker_flag in let run_snark_coordinator_flag = - maybe_from_config + maybe_from_config ~keyname:"run-snark-coordinator" ~getter: Option.( fun x -> @@ -826,11 +932,12 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = ~preferred_value:run_snark_coordinator_flag in let snark_worker_parallelism_flag = - maybe_from_config ~getter:DC.snark_worker_parallelism + maybe_from_config ~keyname:"snark-worker-parallelism" + ~getter:DC.snark_worker_parallelism ~preferred_value:snark_worker_parallelism_flag in let coinbase_receiver_flag = - maybe_from_config + maybe_from_config ~keyname:"coinbase-receiver" ~getter: Option.( fun x -> @@ -853,11 +960,12 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = { external_ip; bind_ip; peer = None; client_port; libp2p_port } in let block_production_key = - maybe_from_config ~getter:DC.block_producer_key + maybe_from_config ~keyname:"block-producer-key" + ~getter:DC.block_producer_key ~preferred_value:block_production_key in let block_production_pubkey = - maybe_from_config + maybe_from_config ~keyname:"block-producer-pubkey" ~getter: Option.( fun x -> @@ -866,7 +974,8 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = ~preferred_value:block_production_pubkey in let block_production_password = - maybe_from_config ~getter:DC.block_producer_password + maybe_from_config ~keyname:"block-producer-password" + ~getter:DC.block_producer_password ~preferred_value:block_production_password in Option.iter @@ -1095,7 +1204,8 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = raw_peer ) ; let initial_peers = let peers = - or_from_config ~getter:DC.peers ~preferred_value:None ~default:[] + or_from_config ~keyname:"peers" ~getter:DC.peers + ~preferred_value:None ~default:[] in List.concat [ List.map ~f:Mina_net2.Multiaddr.of_string libp2p_peers_raw @@ -1107,12 +1217,12 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = List.map ~f:Mina_net2.Multiaddr.of_string direct_peers_raw in let min_connections = - or_from_config ~getter:DC.min_connections + or_from_config ~keyname:"min-connections" ~getter:DC.min_connections ~preferred_value:min_connections ~default:Cli_lib.Default.min_connections in let max_connections = - or_from_config ~getter:DC.max_connections + or_from_config ~keyname:"max-connections" ~getter:DC.max_connections ~preferred_value:max_connections ~default:Cli_lib.Default.max_connections in @@ -1123,20 +1233,21 @@ 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 + or_from_config ~keyname:"pubsub-v0" ~getter: Option.(fun x -> DC.pubsub_v0 x >>= to_pubsub_topic_mode_option) ~preferred_value:None ~default:Cli_lib.Default.pubsub_v0 in let validation_queue_size = - or_from_config ~getter:DC.validation_queue_size + or_from_config ~keyname:"validation-queue-size" + ~getter:DC.validation_queue_size ~preferred_value:validation_queue_size ~default:Cli_lib.Default.validation_queue_size in let stop_time = - or_from_config ~getter:DC.stop_time ~preferred_value:stop_time - ~default:Cli_lib.Default.stop_time + or_from_config ~keyname:"stop-time" ~getter:DC.stop_time + ~preferred_value:stop_time ~default:Cli_lib.Default.stop_time in if enable_tracing then Mina_tracing.start conf_dir |> don't_wait_for ; let%bind () = @@ -1863,11 +1974,14 @@ let internal_commands logger = Genesis_constants.Compiled.constraint_constants in let proof_level = Genesis_constants.Proof_level.Full in - let%bind precomputed_values, _ = + 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 - |> Deferred.Or_error.ok_exn in let pids = Child_processes.Termination.create_pid_table () in let%bind prover = diff --git a/src/app/cli/src/init/client.ml b/src/app/cli/src/init/client.ml index 409413d0f00..dc046388752 100644 --- a/src/app/cli/src/init/client.ml +++ b/src/app/cli/src/init/client.ml @@ -1811,30 +1811,16 @@ let compile_time_constants = conf_dir ^/ "daemon.json" in let open Async in - let logger = Logger.create () in let%map ({ consensus_constants; _ } as precomputed_values), _ = - let%bind runtime_config = - let%map config_file = - Runtime_config.Json_loader.load_config_files ~conf_dir ~logger - [ config_file ] - >>| Or_error.ok - in - let default = - Runtime_config.of_json_layout - { Runtime_config.Json_layout.default with - ledger = - Some - { Runtime_config.Json_layout.Ledger.default with - accounts = Some [] - } - } - |> Result.ok_or_failwith - in - Option.value ~default config_file - in - Genesis_ledger_helper.init_from_config_file ~genesis_constants - ~constraint_constants ~logger:(Logger.null ()) ~proof_level - ~cli_proof_level:None ~genesis_dir runtime_config + 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 = diff --git a/src/app/delegation_verify/delegation_verify.ml b/src/app/delegation_verify/delegation_verify.ml index f160d4c1234..883494c5a28 100644 --- a/src/app/delegation_verify/delegation_verify.ml +++ b/src/app/delegation_verify/delegation_verify.ml @@ -51,8 +51,13 @@ let instantiate_verify_functions ~logger ~genesis_constants (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 = - Runtime_config.Json_loader.load_config_files ~logger [ config_file ] + 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 diff --git a/src/app/runtime_genesis_ledger/runtime_genesis_ledger.ml b/src/app/runtime_genesis_ledger/runtime_genesis_ledger.ml index 298f50ef14e..161da1e4a5b 100644 --- a/src/app/runtime_genesis_ledger/runtime_genesis_ledger.ml +++ b/src/app/runtime_genesis_ledger/runtime_genesis_ledger.ml @@ -90,10 +90,16 @@ let extract_accounts_exn = function | _ -> failwith "Wrong ledger supplied" -let load_config_exn ~logger config_file = - let%map config = +let load_config_exn config_file = + let%map config_json = Deferred.Or_error.ok_exn - @@ Runtime_config.Json_loader.load_config_files ~logger [ config_file ] + @@ 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.( @@ -117,7 +123,7 @@ let load_config_exn ~logger config_file = let main ~(constraint_constants : Genesis_constants.Constraint_constants.t) ~config_file ~genesis_dir ~hash_output_file ~ignore_missing_fields () = let%bind accounts, staking_accounts_opt, next_accounts_opt = - load_config_exn ~logger config_file + load_config_exn config_file in let ledger = load_ledger ~ignore_missing_fields ~constraint_constants accounts diff --git a/src/app/zkapp_test_transaction/lib/commands.ml b/src/app/zkapp_test_transaction/lib/commands.ml index 11670e5602e..2124929f95b 100644 --- a/src/app/zkapp_test_transaction/lib/commands.ml +++ b/src/app/zkapp_test_transaction/lib/commands.ml @@ -326,12 +326,12 @@ 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 logger = Logger.create () in let%bind ledger = - let%map config_json = - Runtime_config.Json_loader.load_config_files ~logger [ config_file ] + 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 runtime_config = Or_error.ok_exn config_json in let accounts = let config = Option.value_exn runtime_config.Runtime_config.ledger in match config.base with diff --git a/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml b/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml index b669fd3bc65..c2ad4537a8a 100644 --- a/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml +++ b/src/lib/genesis_ledger_helper/genesis_ledger_helper.ml @@ -731,7 +731,22 @@ module Genesis_proof = struct let create_values_no_proof = Genesis_proof.create_values_no_proof end -let print_config ~logger (config : Runtime_config.t) = +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 ) + +let print_config ~logger config = let ledger_name_json = Option.value ~default:`Null @@ let%bind.Option ledger = config.Runtime_config.ledger in @@ -863,6 +878,71 @@ let init_from_config_file ?genesis_dir ~cli_proof_level ~genesis_constants let values = Genesis_proof.create_values_no_proof inputs in (values, config) +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/dune b/src/lib/runtime_config/dune index 268a52776e2..41e498ec504 100644 --- a/src/lib/runtime_config/dune +++ b/src/lib/runtime_config/dune @@ -40,9 +40,7 @@ staged_ledger bounded_types mina_compile_config - mina_version - mina_user_error ) (instrumentation (backend bisect_ppx)) (preprocess (pps ppx_custom_printf ppx_sexp_conv ppx_let ppx_deriving_yojson - ppx_fields_conv ppx_version ppx_compare ppx_jane ppx_mina))) + ppx_fields_conv ppx_version ppx_compare ppx_here ppx_mina))) diff --git a/src/lib/runtime_config/runtime_config.ml b/src/lib/runtime_config/runtime_config.ml index 7846e46f27e..259b5ca0804 100644 --- a/src/lib/runtime_config/runtime_config.ml +++ b/src/lib/runtime_config/runtime_config.ml @@ -1,5 +1,4 @@ open Core_kernel -open Async module Fork_config = struct (* Note that length might be smaller than the gernesis_slot @@ -394,16 +393,6 @@ module Json_layout = struct let fields = Fields.names |> Array.of_list let of_yojson json = of_yojson_generic ~fields of_yojson json - - let default : t = - { accounts = None - ; num_accounts = None - ; balances = [] - ; hash = None - ; s3_data_hash = None - ; name = None - ; add_genesis_winner = None - } end module Proof_keys = struct @@ -562,14 +551,6 @@ module Json_layout = struct let fields = Fields.names |> Array.of_list let of_yojson json = of_yojson_generic ~fields of_yojson json - - let default : t = - { daemon = None - ; genesis = None - ; proof = None - ; ledger = None - ; epoch_data = None - } end (** JSON representation: @@ -1644,104 +1625,37 @@ let slot_tx_end, slot_chain_end = in (f (fun d -> d.slot_tx_end), f (fun d -> d.slot_chain_end)) -module type Json_loader_intf = sig - val load_config_files : - ?conf_dir:string - -> ?commit_id_short:string - -> logger:Logger.t - -> string list - -> t Deferred.Or_error.t -end - -module Json_loader : Json_loader_intf = struct - let load_config_file filename = - Monitor.try_with_or_error ~here:[%here] (fun () -> - let%map json = Reader.file_contents filename in - Yojson.Safe.from_string json ) - - let get_magic_config_files ?conf_dir - ?(commit_id_short = Mina_version.commit_id_short) () = - 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_" ^ 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 = - Option.map conf_dir ~f:(fun dir -> - (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 - List.filter_opt - [ config_file_installed; config_file_configdir; config_file_envvar ] - - let load_config_files ?conf_dir ?commit_id_short ~logger config_files = - let open Deferred.Or_error.Let_syntax in - let config_files = List.map ~f:(fun a -> (a, `Must_exist)) config_files in - let config_files = - get_magic_config_files ?conf_dir ?commit_id_short () @ config_files - in - let%map 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.Or_error.List.filter_map config_files - ~f:(fun (config_file, handle_missing) -> - match%bind.Deferred load_config_file config_file with - | Ok config_json -> - Deferred.Or_error.return @@ 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 - List.fold ~init:default config_jsons - ~f:(fun config (config_file, config_json) -> - match of_yojson config_json with - | Ok loaded_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 () ) +module Config_loader = struct + (* Use the prefered value if available. Otherwise, given a list of confs + find the first conf such that the getter returns a Some. + *) + let maybe_from_config (type conf a) ~(logger : Logger.t) + ~(configs : (string * conf) list) ~(getter : conf -> a option) + ~(keyname : string) ~(preferred_value : a option) : a option = + match preferred_value with + | Some v -> + Some v + | None -> + let open Option.Let_syntax in + let%map config_file, data = + List.find_map configs ~f:(fun (config_file, daemon_config) -> + let%map a = getter daemon_config in + (config_file, a) ) + in + [%log debug] "Key $key being used from config file $config_file" + ~metadata: + [ ("key", `String keyname); ("config_file", `String config_file) ] ; + data + + let or_from_config ~logger ~configs ~getter ~keyname ~preferred_value ~default + = + match + maybe_from_config ~logger ~configs ~getter ~keyname ~preferred_value + with + | Some x -> + x + | None -> + [%log trace] "Key '$key' not found in any config files, using default" + ~metadata:[ ("key", `String keyname) ] ; + default end From 2ceea4d98b544a8fe23820fbc2e296da36249e26 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 28 Jan 2025 23:51:48 +0000 Subject: [PATCH 10/16] Revert "Merge pull request #16163 from MinaProtocol/martin/remove-phantom-config" This reverts commit 6df5977c39b37653eb8360f63448fcb033a485f3, reversing changes made to ea896ccdbbc1ceca73cba61b6d535dacf2045590. --- .../src/cli_entrypoint/mina_cli_entrypoint.ml | 298 +++++++-------- .../mina_docker.ml | 12 +- src/lib/runtime_config/dune | 2 +- src/lib/runtime_config/runtime_config.ml | 348 ++++++++---------- 4 files changed, 310 insertions(+), 350 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 5ef8f69c6f9..4711a57ba7d 100644 --- a/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml +++ b/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml @@ -572,12 +572,14 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = let to_pubsub_topic_mode_option = let open Gossip_net.Libp2p in function - | "ro" -> + | `String "ro" -> Some RO - | "rw" -> + | `String "rw" -> Some RW - | "none" -> + | `String "none" -> Some N + | `Null -> + None | _ -> raise (Error.to_exn (Error.of_string "Invalid pubsub topic mode")) in @@ -785,74 +787,75 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = constraint_constants.block_window_duration_ms |> Float.of_int |> Time.Span.of_ms |> Mina_metrics.initialize_all ; - (* We reverse the list because we want to find the "most relevant" value, i.e. the - last time it was declared in the list of supplied config files - *) let rev_daemon_configs = List.rev_filter_map config_jsons ~f:(fun (config_file, config_json) -> - Yojson.Safe.Util.member "daemon" config_json - |> fun x -> - Runtime_config.Daemon.of_yojson x - |> Result.ok - |> Option.map ~f:(fun daemon_config -> - (config_file, daemon_config) ) ) - in - - let module DC = Runtime_config.Daemon in - (* The explicit typing here is necessary to prevent type inference from specializing according - to the first usage. - *) - let maybe_from_config (type a) : - getter:(DC.t -> a option) - -> keyname:string - -> preferred_value:a option - -> a option = - fun ~getter ~keyname ~preferred_value -> - Runtime_config.Config_loader.maybe_from_config ~logger - ~configs:rev_daemon_configs ~getter ~keyname ~preferred_value - in - let or_from_config (type a) : - getter:(DC.t -> a option) - -> keyname:string - -> preferred_value:a option - -> default:a - -> a = - fun ~getter ~keyname ~preferred_value ~default -> - Runtime_config.Config_loader.or_from_config ~logger - ~configs:rev_daemon_configs ~getter ~keyname ~preferred_value - ~default + 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 libp2p_port = - or_from_config ~keyname:"libp2p-port" ~getter:DC.libp2p_port - ~preferred_value:libp2p_port.value ~default:libp2p_port.default + 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 rest_server_port = - or_from_config ~keyname:"rest-port" ~getter:DC.rest_port - ~preferred_value:rest_server_port.value - ~default:rest_server_port.default + 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 = - maybe_from_config ~keyname:"limited-graphql-port" - ~getter:DC.graphql_port - ~preferred_value:limited_graphql_port.value - in - let client_port = - or_from_config ~keyname:"client-port" ~getter:DC.client_port - ~preferred_value:client_port.value ~default:client_port.default - in - let snark_work_fee = - or_from_config ~keyname:"snark-worker-fee" - ~getter:(fun x -> - DC.snark_worker_fee x - |> Option.map ~f:Currency.Fee.of_nanomina_int_exn ) - ~preferred_value:snark_work_fee - ~default:compile_config.default_snark_worker_fee + 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 + 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 ~keyname:"node-status-url" - ~getter:DC.node_status_url ~preferred_value:node_status_url + maybe_from_config YJ.Util.to_string_option "node-status-url" + node_status_url in (* FIXME #4095: pass this through to Gossip_net.Libp2p *) let _max_concurrent_connections = @@ -864,33 +867,29 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = None in let work_selection_method = - or_from_config ~keyname:"work-selection" - ~getter:(fun x -> - DC.work_selection x - |> Option.map ~f:Cli_lib.Arg_type.work_selection_method_val ) - ~preferred_value:work_selection_method_flag + 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 in let work_reassignment_wait = - or_from_config ~keyname:"work-reassignment-wait" - ~getter:DC.work_reassignment_wait - ~preferred_value:work_reassignment_wait + or_from_config YJ.Util.to_int_option "work-reassignment-wait" ~default:Cli_lib.Default.work_reassignment_wait + work_reassignment_wait in let log_received_snark_pool_diff = - or_from_config ~keyname:"log-snark-work-gossip" - ~getter:DC.log_snark_work_gossip - ~preferred_value:log_received_snark_pool_diff ~default:false + 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 ~keyname:"log-txn-pool-gossip" - ~getter:DC.log_txn_pool_gossip - ~preferred_value:log_transaction_pool_diff ~default:false + 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 ~keyname:"log-block-creation" - ~getter:DC.log_block_creation ~preferred_value:log_block_creation - ~default:true + 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 = @@ -899,51 +898,42 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = ; new_state = true } in - let to_publickey_compressed_option which 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 + 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 ~keyname:"run-snark-worker" - ~getter: - Option.( - fun x -> - DC.run_snark_worker x - >>= to_publickey_compressed_option "snark_worker") - ~preferred_value: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 ~keyname:"run-snark-coordinator" - ~getter: - Option.( - fun x -> - DC.run_snark_coordinator x - >>= to_publickey_compressed_option "snark_coordinator") - ~preferred_value: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 ~keyname:"snark-worker-parallelism" - ~getter:DC.snark_worker_parallelism - ~preferred_value: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 ~keyname:"coinbase-receiver" - ~getter: - Option.( - fun x -> - DC.coinbase_receiver x - >>= to_publickey_compressed_option "coinbase_receiver") - ~preferred_value: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 @@ -960,23 +950,17 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = { external_ip; bind_ip; peer = None; client_port; libp2p_port } in let block_production_key = - maybe_from_config ~keyname:"block-producer-key" - ~getter:DC.block_producer_key - ~preferred_value: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 ~keyname:"block-producer-pubkey" - ~getter: - Option.( - fun x -> - DC.block_producer_pubkey x - >>= to_publickey_compressed_option "block_producer") - ~preferred_value: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 ~keyname:"block-producer-password" - ~getter:DC.block_producer_password - ~preferred_value:block_production_password + maybe_from_config YJ.Util.to_string_option "block-producer-password" + block_production_password in Option.iter ~f:(fun password -> @@ -1203,28 +1187,26 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = /ip4/IPADDR/tcp/PORT/p2p/PEERID)" raw_peer ) ; let initial_peers = - let peers = - or_from_config ~keyname:"peers" ~getter:DC.peers - ~preferred_value:None ~default:[] - in 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 @@ peers + ; 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 ~keyname:"min-connections" ~getter:DC.min_connections - ~preferred_value:min_connections - ~default:Cli_lib.Default.min_connections + or_from_config YJ.Util.to_int_option "min-connections" + ~default:Cli_lib.Default.min_connections min_connections in let max_connections = - or_from_config ~keyname:"max-connections" ~getter:DC.max_connections - ~preferred_value:max_connections - ~default:Cli_lib.Default.max_connections + or_from_config YJ.Util.to_int_option "max-connections" + ~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 *) @@ -1233,21 +1215,17 @@ 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 ~keyname:"pubsub-v0" - ~getter: - Option.(fun x -> DC.pubsub_v0 x >>= to_pubsub_topic_mode_option) - ~preferred_value:None ~default:Cli_lib.Default.pubsub_v0 + or_from_config to_pubsub_topic_mode_option "pubsub-v0" + ~default:Cli_lib.Default.pubsub_v0 None in - let validation_queue_size = - or_from_config ~keyname:"validation-queue-size" - ~getter:DC.validation_queue_size - ~preferred_value:validation_queue_size + or_from_config YJ.Util.to_int_option "validation-queue-size" ~default:Cli_lib.Default.validation_queue_size + validation_queue_size in let stop_time = - or_from_config ~keyname:"stop-time" ~getter:DC.stop_time - ~preferred_value:stop_time ~default:Cli_lib.Default.stop_time + or_from_config YJ.Util.to_int_option "stop-time" + ~default:Cli_lib.Default.stop_time stop_time in if enable_tracing then Mina_tracing.start conf_dir |> don't_wait_for ; let%bind () = @@ -1418,16 +1396,16 @@ 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 ~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: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 ~zkapp_cmd_limit:(ref compile_config.zkapp_cmd_limit) ~compile_config () ) in diff --git a/src/lib/integration_test_local_engine/mina_docker.ml b/src/lib/integration_test_local_engine/mina_docker.ml index 2a29814bb5c..9a92fe18304 100644 --- a/src/lib/integration_test_local_engine/mina_docker.ml +++ b/src/lib/integration_test_local_engine/mina_docker.ml @@ -156,10 +156,18 @@ module Network_config = struct let runtime_config = { Runtime_config.daemon = Some - { Runtime_config.Daemon.default with - txpool_max_size = Some txpool_max_size + { 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 = diff --git a/src/lib/runtime_config/dune b/src/lib/runtime_config/dune index 41e498ec504..f7f5ff7d3ce 100644 --- a/src/lib/runtime_config/dune +++ b/src/lib/runtime_config/dune @@ -43,4 +43,4 @@ ) (instrumentation (backend bisect_ppx)) (preprocess (pps ppx_custom_printf ppx_sexp_conv ppx_let ppx_deriving_yojson - ppx_fields_conv ppx_version ppx_compare ppx_here ppx_mina))) + ppx_fields_conv ppx_version ppx_compare ppx_here))) diff --git a/src/lib/runtime_config/runtime_config.ml b/src/lib/runtime_config/runtime_config.ml index 259b5ca0804..eedc5ae89c5 100644 --- a/src/lib/runtime_config/runtime_config.ml +++ b/src/lib/runtime_config/runtime_config.ml @@ -9,6 +9,14 @@ module Fork_config = struct ; 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 @@ -467,42 +475,6 @@ module Json_layout = struct ; slot_chain_end : int option [@default None] ; minimum_user_command_fee : Currency.Fee.t option [@default None] ; network_id : string option [@default None] - ; client_port : int option [@default None] [@key "client-port"] - ; libp2p_port : int option [@default None] [@key "libp2p-port"] - ; rest_port : int option [@default None] [@key "rest-port"] - ; graphql_port : int option [@default None] [@key "limited-graphql-port"] - ; node_status_url : string option [@default None] [@key "node-status-url"] - ; block_producer_key : string option - [@default None] [@key "block-producer-key"] - ; block_producer_pubkey : string option - [@default None] [@key "block-producer-pubkey"] - ; block_producer_password : string option - [@default None] [@key "block-producer-password"] - ; coinbase_receiver : string option - [@default None] [@key "coinbase-receiver"] - ; run_snark_worker : string option - [@default None] [@key "run-snark-worker"] - ; run_snark_coordinator : string option - [@default None] [@key "run-snark-coordinator"] - ; snark_worker_fee : int option [@default None] [@key "snark-worker-fee"] - ; snark_worker_parallelism : int option - [@default None] [@key "snark-worker-parallelism"] - ; work_selection : string option [@default None] [@key "work-selection"] - ; work_reassignment_wait : int option - [@default None] [@key "work-reassignment-wait"] - ; log_txn_pool_gossip : bool option - [@default None] [@key "log-txn-pool-gossip"] - ; log_snark_work_gossip : bool option - [@default None] [@key "log-snark-work-gossip"] - ; log_block_creation : bool option - [@default None] [@key "log-block-creation"] - ; min_connections : int option [@default None] [@key "min-connections"] - ; max_connections : int option [@default None] [@key "max-connections"] - ; pubsub_v0 : string option [@default None] [@key "pubsub-v0"] - ; validation_queue_size : int option - [@default None] [@key "validation-queue-size"] - ; stop_time : int option [@default None] [@key "stop-time"] - ; peers : string list option [@default None] [@key "peers"] ; sync_ledger_max_subtree_depth : int option [@default None] ; sync_ledger_default_subtree_depth : int option [@default None] } @@ -800,6 +772,11 @@ 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 = @@ -937,6 +914,29 @@ module Ledger = struct 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 @@ -978,6 +978,8 @@ module Proof_keys = struct 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; No_check ] end module Transaction_capacity = struct @@ -1011,6 +1013,16 @@ module Proof_keys = struct 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 @@ -1125,6 +1137,37 @@ module Proof_keys = struct 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 @@ -1161,6 +1204,30 @@ module Genesis = struct 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 @@ -1182,76 +1249,10 @@ module Daemon = struct ; minimum_user_command_fee : Currency.Fee.Stable.Latest.t option [@default None] ; network_id : string option [@default None] - ; client_port : int option [@default None] - ; libp2p_port : int option [@default None] - ; rest_port : int option [@default None] - ; graphql_port : int option [@default None] - ; node_status_url : string option [@default None] - ; block_producer_key : string option [@default None] - ; block_producer_pubkey : string option [@default None] - ; block_producer_password : string option [@default None] - ; coinbase_receiver : string option [@default None] - ; run_snark_worker : string option [@default None] - ; run_snark_coordinator : string option [@default None] - ; snark_worker_fee : int option [@default None] - ; snark_worker_parallelism : int option [@default None] - ; work_selection : string option [@default None] - ; work_reassignment_wait : int option [@default None] - ; log_txn_pool_gossip : bool option [@default None] - ; log_snark_work_gossip : bool option [@default None] - ; log_block_creation : bool option [@default None] - ; min_connections : int option [@default None] - ; max_connections : int option [@default None] - ; pubsub_v0 : string option [@default None] - ; validation_queue_size : int option [@default None] - ; stop_time : int option [@default None] - ; peers : string list option [@default None] ; sync_ledger_max_subtree_depth : int option [@default None] ; sync_ledger_default_subtree_depth : int option [@default None] } - [@@deriving bin_io_unversioned, fields] - - let default : t = - { txpool_max_size = None - ; 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 = None - ; slot_chain_end = None - ; minimum_user_command_fee = None - ; network_id = None - ; client_port = None - ; libp2p_port = None - ; rest_port = None - ; graphql_port = None - ; node_status_url = None - ; block_producer_key = None - ; block_producer_pubkey = None - ; block_producer_password = None - ; coinbase_receiver = None - ; run_snark_worker = None - ; run_snark_coordinator = None - ; snark_worker_fee = None - ; snark_worker_parallelism = None - ; work_selection = None - ; work_reassignment_wait = None - ; log_txn_pool_gossip = None - ; log_snark_work_gossip = None - ; log_block_creation = None - ; min_connections = None - ; max_connections = None - ; pubsub_v0 = None - ; validation_queue_size = None - ; stop_time = None - ; peers = None - ; sync_ledger_max_subtree_depth = None - ; sync_ledger_default_subtree_depth = None - } + [@@deriving bin_io_unversioned] let to_json_layout : t -> Json_layout.Daemon.t = Fn.id @@ -1293,54 +1294,6 @@ module Daemon = struct opt_fallthrough ~default:t1.minimum_user_command_fee t2.minimum_user_command_fee ; network_id = opt_fallthrough ~default:t1.network_id t2.network_id - ; client_port = opt_fallthrough ~default:t1.client_port t2.client_port - ; libp2p_port = opt_fallthrough ~default:t1.libp2p_port t2.libp2p_port - ; rest_port = opt_fallthrough ~default:t1.rest_port t2.rest_port - ; graphql_port = opt_fallthrough ~default:t1.graphql_port t2.graphql_port - ; node_status_url = - opt_fallthrough ~default:t1.node_status_url t2.node_status_url - ; block_producer_key = - opt_fallthrough ~default:t1.block_producer_key t2.block_producer_key - ; block_producer_pubkey = - opt_fallthrough ~default:t1.block_producer_pubkey - t2.block_producer_pubkey - ; block_producer_password = - opt_fallthrough ~default:t1.block_producer_password - t2.block_producer_password - ; coinbase_receiver = - opt_fallthrough ~default:t1.coinbase_receiver t2.coinbase_receiver - ; run_snark_worker = - opt_fallthrough ~default:t1.run_snark_worker t2.run_snark_worker - ; run_snark_coordinator = - opt_fallthrough ~default:t1.run_snark_coordinator - t2.run_snark_coordinator - ; snark_worker_fee = - opt_fallthrough ~default:t1.snark_worker_fee t2.snark_worker_fee - ; snark_worker_parallelism = - opt_fallthrough ~default:t1.snark_worker_parallelism - t2.snark_worker_parallelism - ; work_selection = - opt_fallthrough ~default:t1.work_selection t2.work_selection - ; work_reassignment_wait = - opt_fallthrough ~default:t1.work_reassignment_wait - t2.work_reassignment_wait - ; log_txn_pool_gossip = - opt_fallthrough ~default:t1.log_txn_pool_gossip t2.log_txn_pool_gossip - ; log_snark_work_gossip = - opt_fallthrough ~default:t1.log_snark_work_gossip - t2.log_snark_work_gossip - ; log_block_creation = - opt_fallthrough ~default:t1.log_block_creation t2.log_block_creation - ; min_connections = - opt_fallthrough ~default:t1.min_connections t2.min_connections - ; max_connections = - opt_fallthrough ~default:t1.max_connections t2.max_connections - ; pubsub_v0 = opt_fallthrough ~default:t1.pubsub_v0 t2.pubsub_v0 - ; validation_queue_size = - opt_fallthrough ~default:t1.validation_queue_size - t2.validation_queue_size - ; stop_time = opt_fallthrough ~default:t1.stop_time t2.stop_time - ; peers = opt_fallthrough ~default:t1.peers t2.peers ; sync_ledger_max_subtree_depth = opt_fallthrough ~default:t1.sync_ledger_max_subtree_depth t2.sync_ledger_max_subtree_depth @@ -1348,12 +1301,48 @@ module Daemon = struct opt_fallthrough ~default:t1.sync_ledger_default_subtree_depth t2.sync_ledger_default_subtree_depth } + + 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 + ; sync_ledger_max_subtree_depth = None + ; sync_ledger_default_subtree_depth = 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 } end type t = @@ -1428,6 +1417,12 @@ module Epoch_data = struct let of_yojson json = Result.bind ~f:of_json_layout (Json_layout.Epoch_data.of_yojson json) + + 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 } end type t = @@ -1437,7 +1432,7 @@ type t = ; ledger : Ledger.t option ; epoch_data : Epoch_data.t option } -[@@deriving bin_io_unversioned, fields] +[@@deriving bin_io_unversioned] let make ?daemon ?genesis ?proof ?ledger ?epoch_data () = { daemon; genesis; proof; ledger; epoch_data } @@ -1519,6 +1514,20 @@ let combine t1 t2 = ; 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 let yield = Async_unix.Scheduler.yield_every ~n:100 |> Staged.unstage in @@ -1624,38 +1633,3 @@ let slot_tx_end, slot_chain_end = 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)) - -module Config_loader = struct - (* Use the prefered value if available. Otherwise, given a list of confs - find the first conf such that the getter returns a Some. - *) - let maybe_from_config (type conf a) ~(logger : Logger.t) - ~(configs : (string * conf) list) ~(getter : conf -> a option) - ~(keyname : string) ~(preferred_value : a option) : a option = - match preferred_value with - | Some v -> - Some v - | None -> - let open Option.Let_syntax in - let%map config_file, data = - List.find_map configs ~f:(fun (config_file, daemon_config) -> - let%map a = getter daemon_config in - (config_file, a) ) - in - [%log debug] "Key $key being used from config file $config_file" - ~metadata: - [ ("key", `String keyname); ("config_file", `String config_file) ] ; - data - - let or_from_config ~logger ~configs ~getter ~keyname ~preferred_value ~default - = - match - maybe_from_config ~logger ~configs ~getter ~keyname ~preferred_value - with - | Some x -> - x - | None -> - [%log trace] "Key '$key' not found in any config files, using default" - ~metadata:[ ("key", `String keyname) ] ; - default -end From 1bb57d6fd5e1e991295249f527c60dc58661ca29 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 28 Jan 2025 21:18:52 +0000 Subject: [PATCH 11/16] Fixup compilation errors --- .../src/cli_entrypoint/mina_cli_entrypoint.ml | 2 - src/lib/block_producer/block_producer.ml | 22 +++------ .../bootstrap_controller.ml | 48 ++++++++----------- .../bootstrap_controller.mli | 2 + src/lib/consensus/intf.ml | 8 +++- src/lib/consensus/proof_of_stake.ml | 14 +++--- src/lib/fake_network/fake_network.ml | 22 +++------ src/lib/fake_network/fake_network.mli | 3 ++ src/lib/ledger_catchup/normal_catchup.ml | 11 +++-- src/lib/ledger_catchup/super_catchup.ml | 20 ++++---- src/lib/mina_block/validation.ml | 2 - src/lib/mina_block/validation.mli | 2 - .../transition_frontier_components_intf.ml | 2 + src/lib/mina_lib/mina_lib.ml | 21 +++++--- src/lib/mina_lib/mina_lib.mli | 2 +- src/lib/mina_lib/tests/tests.ml | 15 ++++-- src/lib/mina_networking/mina_networking.ml | 2 +- src/lib/mina_networking/mina_networking.mli | 2 +- src/lib/mina_networking/rpcs.ml | 2 +- src/lib/sync_handler/sync_handler.ml | 15 ++---- src/lib/syncable_ledger/syncable_ledger.ml | 23 ++++++--- src/lib/syncable_ledger/test/test.ml | 9 ++-- .../full_frontier/full_frontier.ml | 9 +--- .../transition_frontier.ml | 2 - src/lib/transition_handler/processor.ml | 11 ++--- src/lib/transition_handler/validator.ml | 2 - .../transition_router/transition_router.ml | 27 +++-------- src/lib/vrf_evaluator/vrf_evaluator.ml | 16 +------ 28 files changed, 136 insertions(+), 180 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 4711a57ba7d..8bc3d48b2d8 100644 --- a/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml +++ b/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml @@ -1138,8 +1138,6 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee = let module Context = struct let logger = logger - let compile_config = precomputed_values.compile_config - let constraint_constants = precomputed_values.constraint_constants let consensus_constants = precomputed_values.consensus_constants diff --git a/src/lib/block_producer/block_producer.ml b/src/lib/block_producer/block_producer.ml index e092d41e18c..af74fca3fb4 100644 --- a/src/lib/block_producer/block_producer.ml +++ b/src/lib/block_producer/block_producer.ml @@ -819,17 +819,12 @@ let produce ~genesis_breadcrumb ~context:(module Context : CONTEXT) ~prover (Mina_base.State_hash.to_base58_check protocol_state_hashes.state_hash ) ) ] ; - let module Consensus_context = struct - include Context - - let compile_config = precomputed_values.compile_config - end in Internal_tracing.with_state_hash protocol_state_hashes.state_hash @@ fun () -> Debug_assert.debug_assert (fun () -> [%test_result: [ `Take | `Keep ]] (Consensus.Hooks.select - ~context:(module Consensus_context) + ~context:(module Context) ~existing: (With_hash.map ~f:Mina_block.consensus_state previous_transition ) @@ -844,7 +839,7 @@ let produce ~genesis_breadcrumb ~context:(module Context : CONTEXT) ~prover in [%test_result: [ `Take | `Keep ]] (Consensus.Hooks.select - ~context:(module Consensus_context) + ~context:(module Context) ~existing:root_consensus_state_with_hashes ~candidate:consensus_state_with_hashes ) ~expect:`Take @@ -913,7 +908,7 @@ let produce ~genesis_breadcrumb ~context:(module Context : CONTEXT) ~prover `This_block_was_not_received_via_gossip >>= Validation.validate_frontier_dependencies ~to_header:Mina_block.header - ~context:(module Consensus_context) + ~context:(module Context) ~root_block: ( Transition_frontier.root frontier |> Breadcrumb.block_with_hash ) @@ -1417,15 +1412,10 @@ let run_precomputed ~context:(module Context : CONTEXT) ~verifier ~trust_system Header.protocol_state @@ Mina_block.header (With_hash.data previous_transition) in - let module Consensus_context = struct - include Context - - let compile_config = precomputed_values.compile_config - end in Debug_assert.debug_assert (fun () -> [%test_result: [ `Take | `Keep ]] (Consensus.Hooks.select - ~context:(module Consensus_context) + ~context:(module Context) ~existing: (With_hash.map ~f:Mina_block.consensus_state previous_transition ) @@ -1440,7 +1430,7 @@ let run_precomputed ~context:(module Context : CONTEXT) ~verifier ~trust_system in [%test_result: [ `Take | `Keep ]] (Consensus.Hooks.select - ~context:(module Consensus_context) + ~context:(module Context) ~existing:root_consensus_state_with_hashes ~candidate:consensus_state_with_hashes ) ~expect:`Take @@ -1478,7 +1468,7 @@ let run_precomputed ~context:(module Context : CONTEXT) ~verifier ~trust_system previous_protocol_state ) >>= Validation.validate_frontier_dependencies ~to_header:Mina_block.header - ~context:(module Consensus_context) + ~context:(module Context) ~root_block: ( Transition_frontier.root frontier |> Breadcrumb.block_with_hash ) diff --git a/src/lib/bootstrap_controller/bootstrap_controller.ml b/src/lib/bootstrap_controller/bootstrap_controller.ml index 07ff47f8b9c..e25bc487dea 100644 --- a/src/lib/bootstrap_controller/bootstrap_controller.ml +++ b/src/lib/bootstrap_controller/bootstrap_controller.ml @@ -17,6 +17,8 @@ module type CONTEXT = sig val constraint_constants : Genesis_constants.Constraint_constants.t val consensus_constants : Consensus.Constants.t + + val ledger_sync_config : Syncable_ledger.daemon_config end type Structured_log_events.t += Bootstrap_complete @@ -66,8 +68,6 @@ let worth_getting_root ({ context = (module Context); _ } as t) candidate = let module Consensus_context = struct include Context - let compile_config = precomputed_values.compile_config - let logger = Logger.extend logger [ ( "selection_context" @@ -236,11 +236,6 @@ let sync_ledger ({ context = (module Context); _ } as t) ~preferred else Deferred.unit ) let external_transition_compare ~context:(module Context : CONTEXT) = - let module Consensus_context = struct - include Context - - let compile_config = precomputed_values.compile_config - end in let get_consensus_state = Fn.compose Protocol_state.consensus_state Mina_block.Header.protocol_state in @@ -254,9 +249,7 @@ let external_transition_compare ~context:(module Context : CONTEXT) = then 0 else if Consensus.Hooks.equal_select_status `Keep - @@ Consensus.Hooks.select - ~context:(module Consensus_context) - ~existing ~candidate + @@ Consensus.Hooks.select ~context:(module Context) ~existing ~candidate then -1 else 1 ) ~f:(With_hash.map ~f:get_consensus_state) @@ -333,16 +326,11 @@ let run ~context:(module Context : CONTEXT) ~trust_system ~verifier ~network temp_persistent_root_instance in (* step 1. download snarked_ledger *) - let module Consensus_context = struct - include Context - - let compile_config = precomputed_values.compile_config - end in let%bind sync_ledger_time, (hash, sender, expected_staged_ledger_hash) = time_deferred (let root_sync_ledger = Sync_ledger.Db.create temp_snarked_ledger - ~context:(module Consensus_context) + ~context:(module Context) ~trust_system in don't_wait_for @@ -574,7 +562,7 @@ let run ~context:(module Context : CONTEXT) ~trust_system ~verifier ~network [%log info] "Synchronizing consensus local state" ; let%map result = Consensus.Hooks.sync_local_state - ~context:(module Consensus_context) + ~context:(module Context) ~local_state:consensus_local_state ~trust_system ~glue_sync_ledger: (Mina_networking.glue_sync_ledger t.network) @@ -625,7 +613,7 @@ let run ~context:(module Context : CONTEXT) ~trust_system ~verifier ~network bootstrapping: " ^ msg ) in Transition_frontier.load - ~context:(module Consensus_context) + ~context:(module Context) ~retry_with_fresh_db:false ~verifier ~consensus_local_state ~persistent_root ~persistent_frontier ~catchup_mode () >>| function @@ -667,7 +655,7 @@ let run ~context:(module Context : CONTEXT) ~trust_system ~verifier ~network in Consensus.Hooks.equal_select_status `Take @@ Consensus.Hooks.select - ~context:(module Consensus_context) + ~context:(module Context) ~existing:root_consensus_state ~candidate: (With_hash.map @@ -750,6 +738,11 @@ let%test_module "Bootstrap_controller tests" = let constraint_constants = precomputed_values.constraint_constants + let ledger_sync_config = + Syncable_ledger.create_config + ~compile_config:Mina_compile_config.For_unit_tests.t + ~max_subtree_depth:None ~default_subtree_depth:None () + module Context = struct let logger = logger @@ -759,6 +752,11 @@ let%test_module "Bootstrap_controller tests" = Genesis_constants.For_unit_tests.Constraint_constants.t let consensus_constants = precomputed_values.consensus_constants + + let ledger_sync_config = + Syncable_ledger.create_config + ~compile_config:Mina_compile_config.For_unit_tests.t + ~max_subtree_depth:None ~default_subtree_depth:None () end let verifier = @@ -805,7 +803,8 @@ let%test_module "Bootstrap_controller tests" = let%bind fake_network = Fake_network.Generator.( gen ~precomputed_values ~verifier ~max_frontier_length - [ fresh_peer; fresh_peer ] ~use_super_catchup:false) + ~ledger_sync_config [ fresh_peer; fresh_peer ] + ~use_super_catchup:false) in let%map make_branch = Transition_frontier.Breadcrumb.For_tests.gen_seq ~precomputed_values @@ -833,15 +832,10 @@ let%test_module "Bootstrap_controller tests" = let bootstrap = make_non_running_bootstrap ~genesis_root ~network:me.network in - let module Consensus_context = struct - include Context - - let compile_config = precomputed_values.compile_config - end in let root_sync_ledger = Sync_ledger.Db.create (Transition_frontier.root_snarked_ledger me.state.frontier) - ~context:(module Consensus_context) + ~context:(module Context) ~trust_system in Async.Thread_safe.block_on_async_exn (fun () -> @@ -944,7 +938,7 @@ let%test_module "Bootstrap_controller tests" = Quickcheck.test ~trials:1 Fake_network.Generator.( gen ~precomputed_values ~verifier ~max_frontier_length - ~use_super_catchup:false + ~use_super_catchup:false ~ledger_sync_config [ fresh_peer ; peer_with_branch ~frontier_branch_size:((max_frontier_length * 2) + 2) diff --git a/src/lib/bootstrap_controller/bootstrap_controller.mli b/src/lib/bootstrap_controller/bootstrap_controller.mli index d9730576a92..c4d87edd215 100644 --- a/src/lib/bootstrap_controller/bootstrap_controller.mli +++ b/src/lib/bootstrap_controller/bootstrap_controller.mli @@ -11,6 +11,8 @@ module type CONTEXT = sig val constraint_constants : Genesis_constants.Constraint_constants.t val consensus_constants : Consensus.Constants.t + + val ledger_sync_config : Syncable_ledger.daemon_config end type Structured_log_events.t += Bootstrap_complete [@@deriving register_event] diff --git a/src/lib/consensus/intf.ml b/src/lib/consensus/intf.ml index df4e178cac4..0158d120854 100644 --- a/src/lib/consensus/intf.ml +++ b/src/lib/consensus/intf.ml @@ -11,8 +11,12 @@ module type CONTEXT = sig val constraint_constants : Genesis_constants.Constraint_constants.t val consensus_constants : Constants.t +end + +module type CONTEXT_WITH_LEDGER_SYNC = sig + include CONTEXT - val compile_config : Mina_compile_config.t + val ledger_sync_config : Syncable_ledger.daemon_config end module type Constants = sig @@ -768,7 +772,7 @@ module type S = sig already supplied *) val sync_local_state : - context:(module CONTEXT) + context:(module CONTEXT_WITH_LEDGER_SYNC) -> trust_system:Trust_system.t -> local_state:Local_state.t -> glue_sync_ledger: diff --git a/src/lib/consensus/proof_of_stake.ml b/src/lib/consensus/proof_of_stake.ml index 32abc3dd2e5..89b6ff8402d 100644 --- a/src/lib/consensus/proof_of_stake.ml +++ b/src/lib/consensus/proof_of_stake.ml @@ -30,8 +30,12 @@ module Make_str (A : Wire_types.Concrete) = struct val constraint_constants : Genesis_constants.Constraint_constants.t val consensus_constants : Constants.t + end + + module type CONTEXT_WITH_LEDGER_SYNC = sig + include CONTEXT - val compile_config : Mina_compile_config.t + val ledger_sync_config : Syncable_ledger.daemon_config end let make_checked t = Snark_params.Tick.Run.make_checked t @@ -2591,8 +2595,8 @@ module Make_str (A : Wire_types.Concrete) = struct ; staking = staking.expected_root } ) ) - let sync_local_state ~context:(module Context : CONTEXT) ~trust_system - ~local_state ~glue_sync_ledger requested_syncs = + let sync_local_state ~context:(module Context : CONTEXT_WITH_LEDGER_SYNC) + ~trust_system ~local_state ~glue_sync_ledger requested_syncs = let open Context in let open Local_state in let open Snapshot in @@ -3110,8 +3114,6 @@ module Make_str (A : Wire_types.Concrete) = struct Genesis_constants.For_unit_tests.Constraint_constants.t let consensus_constants = Lazy.force Constants.for_unit_tests - - let compile_config = Mina_compile_config.For_unit_tests.t end in (* Even when consensus constants are of prod sizes, candidate should still trigger a bootstrap *) should_bootstrap_len @@ -3438,8 +3440,6 @@ module Make_str (A : Wire_types.Concrete) = struct let constraint_constants = constraint_constants let consensus_constants = constants - - let compile_config = Mina_compile_config.For_unit_tests.t end let test_update constraint_constants = diff --git a/src/lib/fake_network/fake_network.ml b/src/lib/fake_network/fake_network.ml index 1ccecfa4428..ebebba59888 100644 --- a/src/lib/fake_network/fake_network.ml +++ b/src/lib/fake_network/fake_network.ml @@ -14,6 +14,8 @@ module type CONTEXT = sig val constraint_constants : Genesis_constants.Constraint_constants.t val consensus_constants : Consensus.Constants.t + + val ledger_sync_config : Syncable_ledger.daemon_config end (* There must be at least 2 peers to create a network *) @@ -77,8 +79,6 @@ let setup (type n) ~context:(module Context : CONTEXT) let time_controller = time_controller let consensus_local_state = consensus_local_state - - let compile_config = precomputed_values.compile_config end ) in let config rpc_mocks peer = @@ -224,11 +224,6 @@ module Generator = struct ?get_transition_chain_proof ?get_ancestry ?get_best_tip ?get_completed_snarks ~context:(module Context : CONTEXT) ~verifier ~max_frontier_length ~use_super_catchup = - let module Consensus_context = struct - include Context - - let compile_config = precomputed_values.compile_config - end in let open Context in let epoch_ledger_location = Filename.temp_dir_name ^/ "epoch_ledger" @@ -237,7 +232,7 @@ module Generator = struct let genesis_ledger = Precomputed_values.genesis_ledger precomputed_values in let consensus_local_state = Consensus.Data.Local_state.create Public_key.Compressed.Set.empty - ~context:(module Consensus_context) + ~context:(module Context) ~genesis_ledger ~genesis_epoch_data:precomputed_values.genesis_epoch_data ~epoch_ledger_location @@ -273,11 +268,6 @@ module Generator = struct ?get_transition_chain_proof ?get_ancestry ?get_best_tip ?get_completed_snarks ~context:(module Context : CONTEXT) ~verifier ~max_frontier_length ~use_super_catchup = - let module Consensus_context = struct - include Context - - let compile_config = precomputed_values.compile_config - end in let open Context in let epoch_ledger_location = Filename.temp_dir_name ^/ "epoch_ledger" @@ -286,7 +276,7 @@ module Generator = struct let genesis_ledger = Precomputed_values.genesis_ledger precomputed_values in let consensus_local_state = Consensus.Data.Local_state.create Public_key.Compressed.Set.empty - ~context:(module Consensus_context) + ~context:(module Context) ~genesis_ledger ~genesis_epoch_data:precomputed_values.genesis_epoch_data ~epoch_ledger_location @@ -321,7 +311,7 @@ module Generator = struct ~verifier ~max_frontier_length ~use_super_catchup let gen ?(logger = Logger.null ()) ~precomputed_values ~verifier - ~max_frontier_length ~use_super_catchup + ~max_frontier_length ~use_super_catchup ~ledger_sync_config (configs : (peer_config, 'n num_peers) Gadt_lib.Vect.t) = (* TODO: Pass in *) let module Context = struct @@ -334,6 +324,8 @@ module Generator = struct let consensus_constants = precomputed_values.Precomputed_values.consensus_constants + + let ledger_sync_config = ledger_sync_config end in let open Quickcheck.Generator.Let_syntax in let%map states = diff --git a/src/lib/fake_network/fake_network.mli b/src/lib/fake_network/fake_network.mli index 5cc160b6b07..cb686a2408c 100644 --- a/src/lib/fake_network/fake_network.mli +++ b/src/lib/fake_network/fake_network.mli @@ -10,6 +10,8 @@ module type CONTEXT = sig val constraint_constants : Genesis_constants.Constraint_constants.t val consensus_constants : Consensus.Constants.t + + val ledger_sync_config : Syncable_ledger.daemon_config end (* There must be at least 2 peers to create a network *) @@ -102,6 +104,7 @@ module Generator : sig -> verifier:Verifier.t -> max_frontier_length:int -> use_super_catchup:bool + -> ledger_sync_config:Syncable_ledger.daemon_config -> (peer_config, 'n num_peers) Vect.t -> 'n num_peers t Generator.t end diff --git a/src/lib/ledger_catchup/normal_catchup.ml b/src/lib/ledger_catchup/normal_catchup.ml index 15f6be8dec7..520a4e0fdb1 100644 --- a/src/lib/ledger_catchup/normal_catchup.ml +++ b/src/lib/ledger_catchup/normal_catchup.ml @@ -920,6 +920,11 @@ let%test_module "Ledger_catchup tests" = Verifier.For_tests.default ~constraint_constants ~logger ~proof_level () ) + let ledger_sync_config = + Syncable_ledger.create_config + ~compile_config:Mina_compile_config.For_unit_tests.t + ~max_subtree_depth:None ~default_subtree_depth:None () + module Context = struct let logger = logger @@ -1051,7 +1056,7 @@ let%test_module "Ledger_catchup tests" = Int.gen_incl (max_frontier_length / 2) (max_frontier_length - 1) in gen ~precomputed_values ~verifier ~max_frontier_length - ~use_super_catchup + ~use_super_catchup ~ledger_sync_config [ fresh_peer ; peer_with_branch ~frontier_branch_size:peer_branch_size ]) @@ -1072,7 +1077,7 @@ let%test_module "Ledger_catchup tests" = Quickcheck.test ~trials:1 Fake_network.Generator.( gen ~precomputed_values ~verifier ~max_frontier_length - ~use_super_catchup + ~use_super_catchup ~ledger_sync_config [ fresh_peer; peer_with_branch ~frontier_branch_size:1 ]) ~f:(fun network -> let open Fake_network in @@ -1087,7 +1092,7 @@ let%test_module "Ledger_catchup tests" = Quickcheck.test ~trials:1 Fake_network.Generator.( gen ~precomputed_values ~verifier ~max_frontier_length - ~use_super_catchup + ~use_super_catchup ~ledger_sync_config [ fresh_peer ; peer_with_branch ~frontier_branch_size:(max_frontier_length * 2) ]) diff --git a/src/lib/ledger_catchup/super_catchup.ml b/src/lib/ledger_catchup/super_catchup.ml index 1f130cd5286..07f66561323 100644 --- a/src/lib/ledger_catchup/super_catchup.ml +++ b/src/lib/ledger_catchup/super_catchup.ml @@ -761,11 +761,6 @@ let pick ~context:(module Context : CONTEXT) (x : Mina_state.Protocol_state.Value.t State_hash.With_state_hashes.t) (y : Mina_state.Protocol_state.Value.t State_hash.With_state_hashes.t) = let f = With_hash.map ~f:Mina_state.Protocol_state.consensus_state in - let module Context = struct - include Context - - let compile_config = precomputed_values.compile_config - end in match Consensus.Hooks.select ~context:(module Context) @@ -1466,6 +1461,11 @@ let%test_module "Ledger_catchup tests" = Verifier.For_tests.default ~constraint_constants ~logger ~proof_level () ) + let ledger_sync_config = + Syncable_ledger.create_config + ~compile_config:Mina_compile_config.For_unit_tests.t + ~max_subtree_depth:None ~default_subtree_depth:None () + module Context = struct let logger = logger @@ -1652,7 +1652,7 @@ let%test_module "Ledger_catchup tests" = Int.gen_incl (max_frontier_length / 2) (max_frontier_length - 1) in gen ~precomputed_values ~verifier ~max_frontier_length - ~use_super_catchup + ~use_super_catchup ~ledger_sync_config [ fresh_peer ; peer_with_branch ~frontier_branch_size:peer_branch_size ]) @@ -1672,7 +1672,7 @@ let%test_module "Ledger_catchup tests" = Quickcheck.test ~trials:1 Fake_network.Generator.( gen ~precomputed_values ~verifier ~max_frontier_length - ~use_super_catchup + ~use_super_catchup ~ledger_sync_config [ fresh_peer; peer_with_branch ~frontier_branch_size:1 ]) ~f:(fun network -> let open Fake_network in @@ -1688,7 +1688,7 @@ let%test_module "Ledger_catchup tests" = Quickcheck.test ~trials:1 Fake_network.Generator.( gen ~precomputed_values ~verifier ~max_frontier_length - ~use_super_catchup + ~use_super_catchup ~ledger_sync_config [ fresh_peer; peer_with_branch ~frontier_branch_size:1 ]) ~f:(fun network -> let open Fake_network in @@ -1705,7 +1705,7 @@ let%test_module "Ledger_catchup tests" = Quickcheck.test ~trials:1 Fake_network.Generator.( gen ~precomputed_values ~verifier ~max_frontier_length - ~use_super_catchup + ~use_super_catchup ~ledger_sync_config [ fresh_peer ; peer_with_branch ~frontier_branch_size:((max_frontier_length * 3) + 1) @@ -1783,7 +1783,7 @@ let%test_module "Ledger_catchup tests" = Quickcheck.test ~trials:1 Fake_network.Generator.( gen ~precomputed_values ~verifier ~max_frontier_length - ~use_super_catchup + ~use_super_catchup ~ledger_sync_config [ fresh_peer (* ; peer_with_branch ~frontier_branch_size:(max_frontier_length / 2) *) ; peer_with_branch_custom_rpc diff --git a/src/lib/mina_block/validation.ml b/src/lib/mina_block/validation.ml index 7ef73524feb..8ff4a9c7d3a 100644 --- a/src/lib/mina_block/validation.ml +++ b/src/lib/mina_block/validation.ml @@ -18,8 +18,6 @@ module type CONTEXT = sig val constraint_constants : Genesis_constants.Constraint_constants.t val consensus_constants : Consensus.Constants.t - - val compile_config : Mina_compile_config.t end let validation (_, v) = v diff --git a/src/lib/mina_block/validation.mli b/src/lib/mina_block/validation.mli index 71881258304..edb63b48893 100644 --- a/src/lib/mina_block/validation.mli +++ b/src/lib/mina_block/validation.mli @@ -19,8 +19,6 @@ module type CONTEXT = sig val constraint_constants : Genesis_constants.Constraint_constants.t val consensus_constants : Consensus.Constants.t - - val compile_config : Mina_compile_config.t end val validation : diff --git a/src/lib/mina_intf/transition_frontier_components_intf.ml b/src/lib/mina_intf/transition_frontier_components_intf.ml index 4521e31c0f8..f0dfc12bf18 100644 --- a/src/lib/mina_intf/transition_frontier_components_intf.ml +++ b/src/lib/mina_intf/transition_frontier_components_intf.ml @@ -13,6 +13,8 @@ module type CONTEXT = sig val constraint_constants : Genesis_constants.Constraint_constants.t val consensus_constants : Consensus.Constants.t + + val ledger_sync_config : Syncable_ledger.daemon_config end module type Transition_handler_validator_intf = sig diff --git a/src/lib/mina_lib/mina_lib.ml b/src/lib/mina_lib/mina_lib.ml index 0c960afdda4..be23d1c8214 100644 --- a/src/lib/mina_lib/mina_lib.ml +++ b/src/lib/mina_lib/mina_lib.ml @@ -1247,7 +1247,7 @@ module type CONTEXT = sig val compaction_interval : Time.Span.t option - val compile_config : Mina_compile_config.t + val ledger_sync_config : Syncable_ledger.daemon_config end let context ~commit_id (config : Config.t) : (module CONTEXT) = @@ -1274,9 +1274,18 @@ let context ~commit_id (config : Config.t) : (module CONTEXT) = let compaction_interval = config.compile_config.compaction_interval - (*Same as config.precomputed_values.compile_config. - TODO: Remove redundant fields *) - let compile_config = config.compile_config + let ledger_sync_config = + let open Option.Let_syntax in + let max_subtree_depth = + let%bind daemon = precomputed_values.runtime_config.daemon in + daemon.sync_ledger_max_subtree_depth + in + let default_subtree_depth = + let%bind daemon = precomputed_values.runtime_config.daemon in + daemon.sync_ledger_default_subtree_depth + in + Syncable_ledger.create_config ~compile_config:config.compile_config + ~max_subtree_depth ~default_subtree_depth () end ) let start t = @@ -1753,9 +1762,7 @@ let create ~commit_id ?wallets (config : Config.t) = Vrf_evaluator.create ~commit_id ~constraint_constants ~pids:config.pids ~logger:config.logger ~conf_dir:config.conf_dir ~consensus_constants - ~keypairs:config.block_production_keypairs - ~compile_config:config.precomputed_values.compile_config ) - ) + ~keypairs:config.block_production_keypairs ) ) >>| Result.ok_exn in let snark_worker = diff --git a/src/lib/mina_lib/mina_lib.mli b/src/lib/mina_lib/mina_lib.mli index 3fddaa8bcf3..f0ef50b452a 100644 --- a/src/lib/mina_lib/mina_lib.mli +++ b/src/lib/mina_lib/mina_lib.mli @@ -43,7 +43,7 @@ module type CONTEXT = sig val compaction_interval : Time.Span.t option - val compile_config : Mina_compile_config.t + val ledger_sync_config : Syncable_ledger.daemon_config end exception Snark_worker_error of int diff --git a/src/lib/mina_lib/tests/tests.ml b/src/lib/mina_lib/tests/tests.ml index 61a05b1572e..06e89f2efba 100644 --- a/src/lib/mina_lib/tests/tests.ml +++ b/src/lib/mina_lib/tests/tests.ml @@ -112,8 +112,6 @@ let%test_module "Epoch ledger sync tests" = let time_controller = time_controller - let compile_config = Mina_compile_config.For_unit_tests.t - let commit_id = "not specified for unit test" let vrf_poll_interval = @@ -124,6 +122,11 @@ let%test_module "Epoch ledger sync tests" = let compaction_interval = Mina_compile_config.For_unit_tests.t.compaction_interval + + let ledger_sync_config = + Syncable_ledger.create_config + ~compile_config:Mina_compile_config.For_unit_tests.t + ~max_subtree_depth:None ~default_subtree_depth:None () end in let genesis_ledger = lazy @@ -211,7 +214,9 @@ let%test_module "Epoch ledger sync tests" = ~consensus_constants ~time_controller ~logger ~frontier_broadcast_pipe:frontier_broadcast_pipe_r ~on_remote_push ~log_gossip_heard:false - ~block_window_duration:compile_config.block_window_duration + ~block_window_duration: + ( Time.Span.of_ms + @@ Float.of_int constraint_constants.block_window_duration_ms ) in let snark_remote_sink, snark_pool = let config = @@ -224,7 +229,9 @@ let%test_module "Epoch ledger sync tests" = ~consensus_constants ~time_controller ~logger ~frontier_broadcast_pipe:frontier_broadcast_pipe_r ~on_remote_push ~log_gossip_heard:false - ~block_window_duration:compile_config.block_window_duration + ~block_window_duration: + ( Time.Span.of_ms + @@ Float.of_int constraint_constants.block_window_duration_ms ) in (snark_remote_sink, snark_pool) in diff --git a/src/lib/mina_networking/mina_networking.ml b/src/lib/mina_networking/mina_networking.ml index 6e5687ff2d8..3176a965d12 100644 --- a/src/lib/mina_networking/mina_networking.ml +++ b/src/lib/mina_networking/mina_networking.ml @@ -43,7 +43,7 @@ module type CONTEXT = sig val consensus_constants : Consensus.Constants.t - val compile_config : Mina_compile_config.t + val ledger_sync_config : Syncable_ledger.daemon_config end module Node_status = Node_status diff --git a/src/lib/mina_networking/mina_networking.mli b/src/lib/mina_networking/mina_networking.mli index 48301c7585c..b931227726b 100644 --- a/src/lib/mina_networking/mina_networking.mli +++ b/src/lib/mina_networking/mina_networking.mli @@ -30,7 +30,7 @@ module type CONTEXT = sig val consensus_constants : Consensus.Constants.t - val compile_config : Mina_compile_config.t + val ledger_sync_config : Syncable_ledger.daemon_config end module Node_status = Node_status diff --git a/src/lib/mina_networking/rpcs.ml b/src/lib/mina_networking/rpcs.ml index dc91c8f538b..1415baf5c08 100644 --- a/src/lib/mina_networking/rpcs.ml +++ b/src/lib/mina_networking/rpcs.ml @@ -38,7 +38,7 @@ module type CONTEXT = sig val snark_job_state : unit -> Work_selector.State.t option - val compile_config : Mina_compile_config.t + val ledger_sync_config : Syncable_ledger.daemon_config end type ctx = (module CONTEXT) diff --git a/src/lib/sync_handler/sync_handler.ml b/src/lib/sync_handler/sync_handler.ml index 13bec079662..472f4be61dd 100644 --- a/src/lib/sync_handler/sync_handler.ml +++ b/src/lib/sync_handler/sync_handler.ml @@ -14,6 +14,8 @@ module type CONTEXT = sig val constraint_constants : Genesis_constants.Constraint_constants.t val consensus_constants : Consensus.Constants.t + + val ledger_sync_config : Syncable_ledger.daemon_config end module type Inputs_intf = sig @@ -92,13 +94,6 @@ module Make (Inputs : Inputs_intf) : -> trust_system:Trust_system.t -> Sync_ledger.Answer.t Or_error.t Deferred.t = fun ~frontier hash query ~context:(module Context) ~trust_system -> - let (module C : Syncable_ledger.CONTEXT) = - ( module struct - let logger = Context.logger - - let compile_config = Context.precomputed_values.compile_config - end ) - in match get_ledger_by_hash ~frontier hash with | None -> return @@ -109,7 +104,7 @@ module Make (Inputs : Inputs_intf) : | Some ledger -> let responder = Sync_ledger.Any_ledger.Responder.create ledger ignore - ~context:(module C) + ~context:(module Context) ~trust_system in Sync_ledger.Any_ledger.Responder.answer_query responder query @@ -208,8 +203,6 @@ module Make (Inputs : Inputs_intf) : let module Context = struct include Context - let compile_config = precomputed_values.compile_config - let logger = Logger.extend logger [ ("selection_context", `String "Root.prove") ] end in @@ -237,8 +230,6 @@ module Make (Inputs : Inputs_intf) : let module Context = struct include Context - let compile_config = precomputed_values.compile_config - let logger = Logger.extend logger [ ("selection_context", `String "Root.verify") ] end in diff --git a/src/lib/syncable_ledger/syncable_ledger.ml b/src/lib/syncable_ledger/syncable_ledger.ml index 15f97bf9876..fe2cd37d598 100644 --- a/src/lib/syncable_ledger/syncable_ledger.ml +++ b/src/lib/syncable_ledger/syncable_ledger.ml @@ -105,10 +105,22 @@ module Answer = struct end] end +type daemon_config = { max_subtree_depth : int; default_subtree_depth : int } + +let create_config ~(compile_config : Mina_compile_config.t) ~max_subtree_depth + ~default_subtree_depth () = + { max_subtree_depth = + Option.value ~default:compile_config.sync_ledger_max_subtree_depth + max_subtree_depth + ; default_subtree_depth = + Option.value ~default:compile_config.sync_ledger_default_subtree_depth + default_subtree_depth + } + module type CONTEXT = sig val logger : Logger.t - val compile_config : Mina_compile_config.t + val ledger_sync_config : daemon_config end module type Inputs_intf = sig @@ -388,7 +400,7 @@ end = struct match subtree_depth with | n when n >= 1 -> ( let subtree_depth = - min n compile_config.sync_ledger_max_subtree_depth + min n ledger_sync_config.max_subtree_depth in let ledger_depth = MT.depth mt in let addresses = @@ -627,8 +639,7 @@ end = struct expect_children t addr exp_hash ; Linear_pipe.write_without_pushback_if_open t.queries ( desired_root_exn t - , What_child_hashes - (addr, compile_config.sync_ledger_default_subtree_depth) ) ) + , What_child_hashes (addr, ledger_sync_config.default_subtree_depth) ) ) (** Handle the initial Num_accounts message, starting the main syncing process. *) @@ -761,9 +772,7 @@ end = struct ( "hashes sent for subtree on address $address must \ be a power of 2 in the range 2-2^$depth" , [ ( "depth" - , `Int - compile_config.sync_ledger_max_subtree_depth - ) + , `Int ledger_sync_config.max_subtree_depth ) ] ) ) in requeue_query () diff --git a/src/lib/syncable_ledger/test/test.ml b/src/lib/syncable_ledger/test/test.ml index 5cc21424ba8..4cb41823981 100644 --- a/src/lib/syncable_ledger/test/test.ml +++ b/src/lib/syncable_ledger/test/test.ml @@ -44,12 +44,9 @@ module Make_context (Subtree_depth : sig end) : Syncable_ledger.CONTEXT = struct let logger = Logger.null () - let compile_config = - { Mina_compile_config.For_unit_tests.t with - sync_ledger_max_subtree_depth = - Subtree_depth.sync_ledger_max_subtree_depth - ; sync_ledger_default_subtree_depth = - Subtree_depth.sync_ledger_default_subtree_depth + let ledger_sync_config : Syncable_ledger.daemon_config = + { max_subtree_depth = Subtree_depth.sync_ledger_max_subtree_depth + ; default_subtree_depth = Subtree_depth.sync_ledger_default_subtree_depth } end diff --git a/src/lib/transition_frontier/full_frontier/full_frontier.ml b/src/lib/transition_frontier/full_frontier/full_frontier.ml index 73d1079b544..33b5bc4ffc6 100644 --- a/src/lib/transition_frontier/full_frontier/full_frontier.ml +++ b/src/lib/transition_frontier/full_frontier/full_frontier.ml @@ -563,11 +563,6 @@ let calculate_diffs ({ context = (module Context); _ } as t) breadcrumb = ] end in let open Diff in - let module Consensus_context = struct - include Context - - let compile_config = precomputed_values.compile_config - end in O1trace.sync_thread "calculate_diff_frontier_diffs" (fun () -> let breadcrumb_hash = Breadcrumb.state_hash breadcrumb in let parent_node = @@ -588,7 +583,7 @@ let calculate_diffs ({ context = (module Context); _ } as t) breadcrumb = if Consensus.Hooks.equal_select_status (Consensus.Hooks.select - ~context:(module Consensus_context) + ~context:(module Context) ~existing: (Breadcrumb.consensus_state_with_hashes current_best_tip) ~candidate:(Breadcrumb.consensus_state_with_hashes breadcrumb) ) @@ -963,8 +958,6 @@ module For_tests = struct let precomputed_values = precomputed_values let consensus_constants = precomputed_values.consensus_constants - - let compile_config = precomputed_values.compile_config end let verifier () = diff --git a/src/lib/transition_frontier/transition_frontier.ml b/src/lib/transition_frontier/transition_frontier.ml index fdbf67b52e6..2e0fa241b43 100644 --- a/src/lib/transition_frontier/transition_frontier.ml +++ b/src/lib/transition_frontier/transition_frontier.ml @@ -720,8 +720,6 @@ module For_tests = struct let constraint_constants = precomputed_values.constraint_constants let consensus_constants = precomputed_values.consensus_constants - - let compile_config = precomputed_values.compile_config end in let open Context in let open Quickcheck.Generator.Let_syntax in diff --git a/src/lib/transition_handler/processor.ml b/src/lib/transition_handler/processor.ml index c10457491c9..ab2242ac0d2 100644 --- a/src/lib/transition_handler/processor.ml +++ b/src/lib/transition_handler/processor.ml @@ -110,12 +110,7 @@ let process_transition ~context:(module Context : CONTEXT) ~trust_system let is_block_in_frontier = Fn.compose Option.is_some @@ Transition_frontier.find frontier in - let module Consensus_context = struct - include Context - - let compile_config = precomputed_values.compile_config - end in - let open Consensus_context in + let open Context in let header, transition_hash, transition_receipt_time, sender, validation = match block_or_header with | `Block cached_env -> @@ -166,7 +161,7 @@ let process_transition ~context:(module Context : CONTEXT) ~trust_system [%log internal] "Validate_frontier_dependencies" ; match Mina_block.Validation.validate_frontier_dependencies - ~context:(module Consensus_context) + ~context:(module Context) ~root_block ~is_block_in_frontier ~to_header:ident (Envelope.Incoming.data env) with @@ -197,7 +192,7 @@ let process_transition ~context:(module Context : CONTEXT) ~trust_system [%log internal] "Validate_frontier_dependencies" ; match Mina_block.Validation.validate_frontier_dependencies - ~context:(module Consensus_context) + ~context:(module Context) ~root_block ~is_block_in_frontier ~to_header:Mina_block.header initially_validated_transition with diff --git a/src/lib/transition_handler/validator.ml b/src/lib/transition_handler/validator.ml index cb1e39b4df2..dc8862b85fa 100644 --- a/src/lib/transition_handler/validator.ml +++ b/src/lib/transition_handler/validator.ml @@ -22,8 +22,6 @@ let validate_header_is_relevant ~context:(module Context : CONTEXT) ~frontier let module Context = struct include Context - let compile_config = precomputed_values.compile_config - let logger = Logger.extend logger [ ("selection_context", `String "Transition_handler.Validator") ] diff --git a/src/lib/transition_router/transition_router.ml b/src/lib/transition_router/transition_router.ml index 677f4a2352c..b52e51ef8b6 100644 --- a/src/lib/transition_router/transition_router.ml +++ b/src/lib/transition_router/transition_router.ml @@ -12,6 +12,8 @@ module type CONTEXT = sig val constraint_constants : Genesis_constants.Constraint_constants.t val consensus_constants : Consensus.Constants.t + + val ledger_sync_config : Syncable_ledger.daemon_config end type Structured_log_events.t += Starting_transition_frontier_controller @@ -284,11 +286,6 @@ let download_best_tip ~context:(module Context : CONTEXT) ~notify_online [ ("actual", `Int (List.length tips)); ("expected", `Int num_peers) ] "Finished requesting tips. Got $actual / $expected" ; let%map () = notify_online () in - let module Consensus_context = struct - include Context - - let compile_config = precomputed_values.compile_config - end in let res = List.fold tips ~init:None ~f:(fun acc enveloped_candidate_best_tip -> Option.merge acc (Option.return enveloped_candidate_best_tip) @@ -299,7 +296,7 @@ let download_best_tip ~context:(module Context : CONTEXT) ~notify_online in match Consensus.Hooks.select - ~context:(module Consensus_context) + ~context:(module Context) ~existing:(f enveloped_existing_best_tip.data.data) ~candidate:(f enveloped_candidate_best_tip.data.data) with @@ -414,11 +411,6 @@ let initialize ~context:(module Context : CONTEXT) ~sync_local_state ~network let genesis_constants = Precomputed_values.genesis_constants precomputed_values in - let module Consensus_context = struct - include Context - - let compile_config = precomputed_values.compile_config - end in match%bind Deferred.both (download_best_tip @@ -448,7 +440,7 @@ let initialize ~context:(module Context : CONTEXT) ~sync_local_state ~network (Option.map ~f:(fun x -> `Block x) best_seen_transition) | Some best_tip, Some frontier when is_transition_for_bootstrap - ~context:(module Consensus_context) + ~context:(module Context) frontier ( best_tip |> Envelope.Incoming.data |> Mina_block.Validation.to_header ) -> @@ -518,7 +510,7 @@ let initialize ~context:(module Context : CONTEXT) ~sync_local_state ~network Consensus.Hooks.sync_local_state ~local_state:consensus_local_state ~glue_sync_ledger:(Mina_networking.glue_sync_ledger network) - ~context:(module Consensus_context) + ~context:(module Context) ~trust_system sync_jobs with | Error e -> @@ -584,11 +576,6 @@ let run ?(sync_local_state = true) ?(cache_exceptions = false) ~get_most_recent_valid_block ~most_recent_valid_block_writer ~get_completed_work ~catchup_mode ~notify_online () = let open Context in - let module Consensus_context = struct - include Context - - let compile_config = precomputed_values.compile_config - end in [%log info] "Starting transition router" ; let initialization_finish_signal = Ivar.create () in let clear_reader, clear_writer = @@ -683,7 +670,7 @@ let run ?(sync_local_state = true) ?(cache_exceptions = false) if Consensus.Hooks.equal_select_status `Take (Consensus.Hooks.select - ~context:(module Consensus_context) + ~context:(module Context) ~existing:(to_consensus_state current_header_with_hash) ~candidate:(to_consensus_state header_with_hash) ) then @@ -703,7 +690,7 @@ let run ?(sync_local_state = true) ?(cache_exceptions = false) | Some frontier -> if is_transition_for_bootstrap - ~context:(module Consensus_context) + ~context:(module Context) frontier header_with_hash then ( Strict_pipe.Writer.kill !transition_writer_ref ; diff --git a/src/lib/vrf_evaluator/vrf_evaluator.ml b/src/lib/vrf_evaluator/vrf_evaluator.ml index 561f9292f0a..ff5b71ee4ed 100644 --- a/src/lib/vrf_evaluator/vrf_evaluator.ml +++ b/src/lib/vrf_evaluator/vrf_evaluator.ml @@ -10,8 +10,6 @@ module type CONTEXT = sig val constraint_constants : Genesis_constants.Constraint_constants.t val consensus_constants : Consensus.Constants.t - - val compile_config : Mina_compile_config.t end (*Slot number within an epoch*) @@ -77,7 +75,6 @@ module Worker_state = struct type init_arg = { constraint_constants : Genesis_constants.Constraint_constants.t ; consensus_constants : Consensus.Constants.Stable.Latest.t - ; compile_config : Mina_compile_config.t ; conf_dir : string ; logger : Logger.t ; commit_id : string @@ -87,7 +84,6 @@ module Worker_state = struct let context_of_config ({ constraint_constants ; consensus_constants - ; compile_config ; logger ; conf_dir = _ ; commit_id = _ @@ -99,8 +95,6 @@ module Worker_state = struct let consensus_constants = consensus_constants let logger = logger - - let compile_config = compile_config end ) type t = @@ -420,7 +414,7 @@ let update_block_producer_keys { connection; process = _ } ~keypairs = ~arg:(Keypair.And_compressed_pk.Set.to_list keypairs) let create ~constraint_constants ~pids ~consensus_constants ~conf_dir ~logger - ~keypairs ~commit_id ~compile_config = + ~keypairs ~commit_id = let on_failure err = [%log error] "VRF evaluator process failed with error $err" ~metadata:[ ("err", Error_json.error_to_yojson err) ] ; @@ -430,13 +424,7 @@ let create ~constraint_constants ~pids ~consensus_constants ~conf_dir ~logger let%bind connection, process = Worker.spawn_in_foreground_exn ~connection_timeout:(Time.Span.of_min 1.) ~on_failure ~shutdown_on:Connection_closed ~connection_state_init_arg:() - { constraint_constants - ; consensus_constants - ; compile_config - ; conf_dir - ; logger - ; commit_id - } + { constraint_constants; consensus_constants; conf_dir; logger; commit_id } in [%log info] "Daemon started process of kind $process_kind with pid $vrf_evaluator_pid" From 734b6b497faaa632efb02ace809a48a2bd28ba87 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 28 Jan 2025 23:57:01 +0000 Subject: [PATCH 12/16] Stop using commit_id --- src/lib/bootstrap_controller/bootstrap_controller.ml | 2 +- src/lib/ledger_catchup/normal_catchup.ml | 2 +- src/lib/ledger_catchup/super_catchup.ml | 2 +- src/lib/mina_lib/tests/tests.ml | 2 +- .../transaction_inclusion_status.ml | 2 +- src/lib/transition_handler/catchup_scheduler.ml | 2 +- src/lib/transition_handler/processor.ml | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lib/bootstrap_controller/bootstrap_controller.ml b/src/lib/bootstrap_controller/bootstrap_controller.ml index e25bc487dea..feb54682506 100644 --- a/src/lib/bootstrap_controller/bootstrap_controller.ml +++ b/src/lib/bootstrap_controller/bootstrap_controller.ml @@ -712,7 +712,7 @@ let%test_module "Bootstrap_controller tests" = let () = (* Disable log messages from best_tip_diff logger. *) - Logger.Consumer_registry.register ~commit_id:Mina_version.commit_id + Logger.Consumer_registry.register ~commit_id:"" ~id:Logger.Logger_id.best_tip_diff ~processor:(Logger.Processor.raw ()) ~transport: (Logger.Transport.create diff --git a/src/lib/ledger_catchup/normal_catchup.ml b/src/lib/ledger_catchup/normal_catchup.ml index 520a4e0fdb1..93a7c098ce4 100644 --- a/src/lib/ledger_catchup/normal_catchup.ml +++ b/src/lib/ledger_catchup/normal_catchup.ml @@ -891,7 +891,7 @@ let%test_module "Ledger_catchup tests" = let () = (* Disable log messages from best_tip_diff logger. *) - Logger.Consumer_registry.register ~commit_id:Mina_version.commit_id + Logger.Consumer_registry.register ~commit_id:"" ~id:Logger.Logger_id.best_tip_diff ~processor:(Logger.Processor.raw ()) ~transport: (Logger.Transport.create diff --git a/src/lib/ledger_catchup/super_catchup.ml b/src/lib/ledger_catchup/super_catchup.ml index 07f66561323..4dc4fe796ff 100644 --- a/src/lib/ledger_catchup/super_catchup.ml +++ b/src/lib/ledger_catchup/super_catchup.ml @@ -1432,7 +1432,7 @@ let%test_module "Ledger_catchup tests" = let () = (* Disable log messages from best_tip_diff logger. *) - Logger.Consumer_registry.register ~commit_id:Mina_version.commit_id + Logger.Consumer_registry.register ~commit_id:"" ~id:Logger.Logger_id.best_tip_diff ~processor:(Logger.Processor.raw ()) ~transport: (Logger.Transport.create diff --git a/src/lib/mina_lib/tests/tests.ml b/src/lib/mina_lib/tests/tests.ml index 06e89f2efba..89cac363d5c 100644 --- a/src/lib/mina_lib/tests/tests.ml +++ b/src/lib/mina_lib/tests/tests.ml @@ -32,7 +32,7 @@ let%test_module "Epoch ledger sync tests" = let () = (* Disable log messages from best_tip_diff logger. *) - Logger.Consumer_registry.register ~commit_id:Mina_version.commit_id + Logger.Consumer_registry.register ~commit_id:"" ~id:Logger.Logger_id.best_tip_diff ~processor:(Logger.Processor.raw ()) ~transport: (Logger.Transport.create diff --git a/src/lib/transaction_inclusion_status/transaction_inclusion_status.ml b/src/lib/transaction_inclusion_status/transaction_inclusion_status.ml index 8fd93e7ba06..6077f9f767d 100644 --- a/src/lib/transaction_inclusion_status/transaction_inclusion_status.ml +++ b/src/lib/transaction_inclusion_status/transaction_inclusion_status.ml @@ -74,7 +74,7 @@ let%test_module "transaction_status" = let () = (* Disable log messages from best_tip_diff logger. *) - Logger.Consumer_registry.register ~commit_id:Mina_version.commit_id + Logger.Consumer_registry.register ~commit_id:"" ~id:Logger.Logger_id.best_tip_diff ~processor:(Logger.Processor.raw ()) ~transport: (Logger.Transport.create diff --git a/src/lib/transition_handler/catchup_scheduler.ml b/src/lib/transition_handler/catchup_scheduler.ml index 4e2ec85f7e5..aaff09d37c1 100644 --- a/src/lib/transition_handler/catchup_scheduler.ml +++ b/src/lib/transition_handler/catchup_scheduler.ml @@ -349,7 +349,7 @@ let%test_module "Transition_handler.Catchup_scheduler tests" = let () = (* Disable log messages from best_tip_diff logger. *) - Logger.Consumer_registry.register ~commit_id:Mina_version.commit_id + Logger.Consumer_registry.register ~commit_id:"" ~id:Logger.Logger_id.best_tip_diff ~processor:(Logger.Processor.raw ()) ~transport: (Logger.Transport.create diff --git a/src/lib/transition_handler/processor.ml b/src/lib/transition_handler/processor.ml index ab2242ac0d2..32f173614d6 100644 --- a/src/lib/transition_handler/processor.ml +++ b/src/lib/transition_handler/processor.ml @@ -480,7 +480,7 @@ let%test_module "Transition_handler.Processor tests" = let () = (* Disable log messages from best_tip_diff logger. *) - Logger.Consumer_registry.register ~commit_id:Mina_version.commit_id + Logger.Consumer_registry.register ~commit_id:"" ~id:Logger.Logger_id.best_tip_diff ~processor:(Logger.Processor.raw ()) ~transport: (Logger.Transport.create From b5306635bf9ce3758e32025a68a0389f304a8842 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Wed, 29 Jan 2025 00:00:20 +0000 Subject: [PATCH 13/16] Remove unused parameter --- src/lib/transition_handler/processor.ml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/lib/transition_handler/processor.ml b/src/lib/transition_handler/processor.ml index 32f173614d6..bd11a64ff8c 100644 --- a/src/lib/transition_handler/processor.ml +++ b/src/lib/transition_handler/processor.ml @@ -42,8 +42,7 @@ let cached_transform_deferred_result ~transform_cached ~transform_result cached (* add a breadcrumb and perform post processing *) let add_and_finalize ~logger ~frontier ~catchup_scheduler ~processed_transition_writer ~only_if_present ~time_controller ~source - ~valid_cb cached_breadcrumb ~(precomputed_values : Precomputed_values.t) - ~block_window_duration:_ (*TODO remove unused var*) = + ~valid_cb cached_breadcrumb ~(precomputed_values : Precomputed_values.t) = let module Inclusion_time = Mina_metrics.Block_latency.Inclusion_time in let breadcrumb = if Cached.is_pure cached_breadcrumb then Cached.peek cached_breadcrumb @@ -280,7 +279,6 @@ let process_transition ~context:(module Context : CONTEXT) ~trust_system add_and_finalize ~logger ~frontier ~catchup_scheduler ~processed_transition_writer ~only_if_present:false ~time_controller ~source:`Gossip breadcrumb ~precomputed_values ~valid_cb - ~block_window_duration:compile_config.block_window_duration in ( match result with | Ok () -> @@ -374,8 +372,6 @@ let run ~context:(module Context : CONTEXT) ~verifier ~trust_system let%map result = add_and_finalize ~logger ~only_if_present:true ~source:`Catchup ~valid_cb b - ~block_window_duration: - compile_config.block_window_duration in Internal_tracing.with_state_hash state_hash @@ fun () -> @@ -439,8 +435,6 @@ let run ~context:(module Context : CONTEXT) ~verifier ~trust_system match%map add_and_finalize ~logger ~only_if_present:false ~source:`Internal breadcrumb ~valid_cb:None - ~block_window_duration: - compile_config.block_window_duration with | Ok () -> [%log internal] "Breadcrumb_integrated" ; From f1bf8fa21a95936d4339f06ef34dfb999f5c50ae Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Wed, 29 Jan 2025 00:00:33 +0000 Subject: [PATCH 14/16] Add missing fields to integration test local engine config --- src/lib/integration_test_local_engine/mina_docker.ml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/integration_test_local_engine/mina_docker.ml b/src/lib/integration_test_local_engine/mina_docker.ml index 9a92fe18304..c65eda8f716 100644 --- a/src/lib/integration_test_local_engine/mina_docker.ml +++ b/src/lib/integration_test_local_engine/mina_docker.ml @@ -169,6 +169,8 @@ module Network_config = struct ; slot_chain_end ; minimum_user_command_fee = None ; network_id + ; sync_ledger_max_subtree_depth = None + ; sync_ledger_default_subtree_depth = None } ; genesis = Some From 8bf6be26ea9c572793843d6495f56e1fe83edb6e Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Wed, 29 Jan 2025 00:08:07 +0000 Subject: [PATCH 15/16] Reformat conflicting files in preparation for merge --- src/lib/daemon_rpcs/dune | 91 +++++----- src/lib/itn_logger/dune | 35 ++-- src/lib/mina_base/dune | 173 +++++++++++-------- src/lib/mina_metrics/prometheus_metrics/dune | 49 +++--- src/lib/node_config/dune | 13 +- src/lib/node_config/for_unit_tests/dune | 13 +- src/lib/runtime_config/dune | 92 +++++----- src/lib/snark_worker/dune | 111 ++++++------ 8 files changed, 308 insertions(+), 269 deletions(-) diff --git a/src/lib/daemon_rpcs/dune b/src/lib/daemon_rpcs/dune index 86876a493e8..1618cf49e07 100644 --- a/src/lib/daemon_rpcs/dune +++ b/src/lib/daemon_rpcs/dune @@ -2,49 +2,54 @@ (name daemon_rpcs) (public_name daemon_rpcs) (library_flags -linkall) - (inline_tests (flags -verbose -show-counts)) + (inline_tests + (flags -verbose -show-counts)) (libraries - ;; opam libraries - base.caml - sexplib0 - bin_prot.shape - yojson - core - async - ppx_deriving_yojson.runtime - core_kernel - async_unix - async.async_rpc - async_rpc_kernel - async_kernel - ;; local libraries - network_peer - genesis_constants - bounded_types - currency - mina_net2 - transition_frontier - block_time - mina_numbers - itn_logger - cli_lib - transaction_inclusion_status - consensus - mina_networking - mina_base - user_command_input - perf_histograms - sync_status - node_addrs_and_ports - mina_node_config.unconfigurable_constants - logger - network_pool - data_hash_lib - trust_system - ppx_version.runtime - ) + ;; opam libraries + base.caml + sexplib0 + bin_prot.shape + yojson + core + async + ppx_deriving_yojson.runtime + core_kernel + async_unix + async.async_rpc + async_rpc_kernel + async_kernel + ;; local libraries + network_peer + genesis_constants + bounded_types + currency + mina_net2 + transition_frontier + block_time + mina_numbers + itn_logger + cli_lib + transaction_inclusion_status + consensus + mina_networking + mina_base + user_command_input + perf_histograms + sync_status + node_addrs_and_ports + mina_node_config.unconfigurable_constants + logger + network_pool + data_hash_lib + trust_system + ppx_version.runtime) (preprocess - (pps ppx_version ppx_jane ppx_deriving_yojson ppx_compare ppx_deriving.make - )) - (instrumentation (backend bisect_ppx)) + (pps + ppx_version + ppx_jane + ppx_deriving_yojson + ppx_compare + ppx_deriving.make)) + (instrumentation + (backend bisect_ppx)) (synopsis "Lib powering the client interactions with the daemon")) diff --git a/src/lib/itn_logger/dune b/src/lib/itn_logger/dune index bf9a03dbc9d..989efb7d189 100644 --- a/src/lib/itn_logger/dune +++ b/src/lib/itn_logger/dune @@ -2,20 +2,21 @@ (name itn_logger) (public_name itn_logger) (libraries - ;; opam libraries - base - base.caml - bin_prot.shape - async - async.async_rpc - async_kernel - async_rpc_kernel - async_unix - core - core_kernel - yojson - ;; local libraries - mina_node_config.unconfigurable_constants - ) - (instrumentation (backend bisect_ppx)) - (preprocess (pps ppx_version ppx_mina ppx_jane))) + ;; opam libraries + base + base.caml + bin_prot.shape + async + async.async_rpc + async_kernel + async_rpc_kernel + async_unix + core + core_kernel + yojson + ;; local libraries + mina_node_config.unconfigurable_constants) + (instrumentation + (backend bisect_ppx)) + (preprocess + (pps ppx_version ppx_mina ppx_jane))) diff --git a/src/lib/mina_base/dune b/src/lib/mina_base/dune index e362e42f2bb..0d03f4eb549 100644 --- a/src/lib/mina_base/dune +++ b/src/lib/mina_base/dune @@ -1,83 +1,104 @@ (library (name mina_base) (public_name mina_base) - (inline_tests (flags -verbose -show-counts)) + (inline_tests + (flags -verbose -show-counts)) (library_flags -linkall) (libraries - ;; opam libraries - async_kernel - result - bin_prot.shape - ppx_inline_test.config - sexplib0 - yojson - digestif - sexp_diff_kernel - core_kernel - base.caml - base - base.base_internalhash_types - integers - base_quickcheck - base_quickcheck.ppx_quickcheck - core_kernel.uuid - ;; local libraries - protocol_version - mina_wire_types - run_in_thread - kimchi_backend_common - kimchi_pasta - kimchi_pasta.basic - mina_base.import - sgn - sgn_type - pickles_types - blake2 - pickles - sparse_ledger_lib - snark_params - signature_lib - bounded_types - rosetta_coding - random_oracle - hash_prefix_states - hash_prefix_create - dummy_values - currency - mina_numbers - genesis_constants - block_time - base58_check - bignum_bigint - codable - crypto_params - debug_assert - fold_lib - fields_derivers.zkapps - fields_derivers.json - fields_derivers.graphql - one_or_two - outside_hash_image - quickcheck_lib - snarky.backendless - test_util - unsigned_extended - with_hash - random_oracle_input - data_hash_lib - pickles.backend - mina_signature_kind - mina_base.util - kimchi_backend - hex - snark_bits - error_json - ppx_version.runtime - ) + ;; opam libraries + async_kernel + result + bin_prot.shape + ppx_inline_test.config + sexplib0 + yojson + digestif + sexp_diff_kernel + core_kernel + base.caml + base + base.base_internalhash_types + integers + base_quickcheck + base_quickcheck.ppx_quickcheck + core_kernel.uuid + ;; local libraries + protocol_version + mina_wire_types + run_in_thread + kimchi_backend_common + kimchi_pasta + kimchi_pasta.basic + mina_base.import + sgn + sgn_type + pickles_types + blake2 + pickles + sparse_ledger_lib + snark_params + signature_lib + bounded_types + rosetta_coding + random_oracle + hash_prefix_states + hash_prefix_create + dummy_values + currency + mina_numbers + genesis_constants + block_time + base58_check + bignum_bigint + codable + crypto_params + debug_assert + fold_lib + fields_derivers.zkapps + fields_derivers.json + fields_derivers.graphql + one_or_two + outside_hash_image + quickcheck_lib + snarky.backendless + test_util + unsigned_extended + with_hash + random_oracle_input + data_hash_lib + pickles.backend + mina_signature_kind + mina_base.util + kimchi_backend + hex + snark_bits + error_json + ppx_version.runtime) (preprocess - (pps ppx_annot ppx_snarky ppx_here ppx_mina ppx_version ppx_compare ppx_deriving.enum ppx_deriving.ord ppx_deriving.make - ppx_base base_quickcheck.ppx_quickcheck ppx_bench ppx_let ppx_sexp_conv ppx_bin_prot ppx_fields_conv ppx_custom_printf ppx_assert ppx_deriving_yojson ppx_inline_test h_list.ppx - ppx_variants_conv ppx_pipebang - )) - (instrumentation (backend bisect_ppx)) + (pps + ppx_annot + ppx_snarky + ppx_here + ppx_mina + ppx_version + ppx_compare + ppx_deriving.enum + ppx_deriving.ord + ppx_deriving.make + ppx_base + base_quickcheck.ppx_quickcheck + ppx_bench + ppx_let + ppx_sexp_conv + ppx_bin_prot + ppx_fields_conv + ppx_custom_printf + ppx_assert + ppx_deriving_yojson + ppx_inline_test + h_list.ppx + ppx_variants_conv + ppx_pipebang)) + (instrumentation + (backend bisect_ppx)) (synopsis "Snarks and friends necessary for keypair generation")) diff --git a/src/lib/mina_metrics/prometheus_metrics/dune b/src/lib/mina_metrics/prometheus_metrics/dune index 6ce3904ca3d..3cd172f3a46 100644 --- a/src/lib/mina_metrics/prometheus_metrics/dune +++ b/src/lib/mina_metrics/prometheus_metrics/dune @@ -2,28 +2,29 @@ (public_name mina_metrics.prometheus) (name mina_metrics_prometheus) (libraries - ;; opam libraries - conduit-async - ppx_hash.runtime-lib - fmt - re - base - core - async_kernel - core_kernel - prometheus - cohttp-async - cohttp - async - base.base_internalhash_types - uri - async_unix - base.caml - ;; local libraries - logger - o1trace - mina_node_config - ) - (instrumentation (backend bisect_ppx)) - (preprocess (pps ppx_mina ppx_let ppx_version ppx_pipebang ppx_custom_printf ppx_here)) + ;; opam libraries + conduit-async + ppx_hash.runtime-lib + fmt + re + base + core + async_kernel + core_kernel + prometheus + cohttp-async + cohttp + async + base.base_internalhash_types + uri + async_unix + base.caml + ;; local libraries + logger + o1trace + mina_node_config) + (instrumentation + (backend bisect_ppx)) + (preprocess + (pps ppx_mina ppx_let ppx_version ppx_pipebang ppx_custom_printf ppx_here)) (implements mina_metrics)) diff --git a/src/lib/node_config/dune b/src/lib/node_config/dune index 3d3eebb8b77..43d94d24aad 100644 --- a/src/lib/node_config/dune +++ b/src/lib/node_config/dune @@ -2,10 +2,11 @@ (name node_config) (public_name mina_node_config) (libraries - node_config_intf - node_config_version - node_config_unconfigurable_constants) + node_config_intf + node_config_version + node_config_unconfigurable_constants) (preprocessor_deps ../../config.mlh) - (instrumentation (backend bisect_ppx)) - (preprocess (pps ppx_version ppx_base ppx_optcomp)) -) + (instrumentation + (backend bisect_ppx)) + (preprocess + (pps ppx_version ppx_base ppx_optcomp))) diff --git a/src/lib/node_config/for_unit_tests/dune b/src/lib/node_config/for_unit_tests/dune index 460efc1f009..f51b912908d 100644 --- a/src/lib/node_config/for_unit_tests/dune +++ b/src/lib/node_config/for_unit_tests/dune @@ -2,9 +2,10 @@ (name node_config_for_unit_tests) (public_name mina_node_config.for_unit_tests) (libraries - node_config_intf - node_config_version - node_config_unconfigurable_constants) - (instrumentation (backend bisect_ppx)) - (preprocess (pps ppx_version ppx_base ppx_optcomp)) -) + node_config_intf + node_config_version + node_config_unconfigurable_constants) + (instrumentation + (backend bisect_ppx)) + (preprocess + (pps ppx_version ppx_base ppx_optcomp))) diff --git a/src/lib/runtime_config/dune b/src/lib/runtime_config/dune index f7f5ff7d3ce..fa551a18185 100644 --- a/src/lib/runtime_config/dune +++ b/src/lib/runtime_config/dune @@ -2,45 +2,53 @@ (name runtime_config) (public_name mina_runtime_config) (libraries - ;; opam libraries - async - async_kernel - async_unix - core_kernel - bin_prot.shape - base.caml - base - base64 - integers - result - sexplib0 - ;; local libraries - block_time - currency - genesis_constants - data_hash_lib - kimchi_backend - kimchi_pasta - kimchi_pasta.basic - mina_ledger - merkle_ledger - mina_base - mina_base.import - mina_numbers - mina_wire_types - mina_state - snark_params - unsigned_extended - pickles - pickles.backend - pickles_types - random_oracle - with_hash - signature_lib - staged_ledger - bounded_types - mina_compile_config - ) - (instrumentation (backend bisect_ppx)) - (preprocess (pps ppx_custom_printf ppx_sexp_conv ppx_let ppx_deriving_yojson - ppx_fields_conv ppx_version ppx_compare ppx_here))) + ;; opam libraries + async + async_kernel + async_unix + core_kernel + bin_prot.shape + base.caml + base + base64 + integers + result + sexplib0 + ;; local libraries + block_time + currency + genesis_constants + data_hash_lib + kimchi_backend + kimchi_pasta + kimchi_pasta.basic + mina_ledger + merkle_ledger + mina_base + mina_base.import + mina_numbers + mina_wire_types + mina_state + snark_params + unsigned_extended + pickles + pickles.backend + pickles_types + random_oracle + with_hash + signature_lib + staged_ledger + bounded_types + mina_compile_config) + (instrumentation + (backend bisect_ppx)) + (preprocess + (pps + ppx_custom_printf + ppx_sexp_conv + ppx_let + ppx_deriving_yojson + ppx_fields_conv + ppx_version + ppx_compare + ppx_here))) diff --git a/src/lib/snark_worker/dune b/src/lib/snark_worker/dune index 35f564ad95a..9e90dd79b68 100644 --- a/src/lib/snark_worker/dune +++ b/src/lib/snark_worker/dune @@ -2,62 +2,63 @@ (name snark_worker) (public_name snark_worker) (library_flags -linkall) - (inline_tests (flags -verbose -show-counts)) + (inline_tests + (flags -verbose -show-counts)) (libraries - ;; opam libraries - async_rpc_kernel - sexplib0 - async_kernel - base - base.caml - async - core - core_kernel.hash_heap - core_kernel - async.async_rpc - async.async_command - base.base_internalhash_types - ppx_hash.runtime-lib - result - async_unix - bin_prot.shape - ;; local libraries - bounded_types - one_or_two - mina_metrics - logger - signature_lib - logger.file_system - mina_base.import - cli_lib - genesis_constants - transaction_witness - perf_histograms - snark_work_lib - currency - mina_base - mina_transaction - transaction_snark - ledger_proof - mina_ledger - transaction_snark_work - error_json - mina_node_config.unconfigurable_constants - mina_state - transaction_protocol_state - ppx_version.runtime - ) + ;; opam libraries + async_rpc_kernel + sexplib0 + async_kernel + base + base.caml + async + core + core_kernel.hash_heap + core_kernel + async.async_rpc + async.async_command + base.base_internalhash_types + ppx_hash.runtime-lib + result + async_unix + bin_prot.shape + ;; local libraries + bounded_types + one_or_two + mina_metrics + logger + signature_lib + logger.file_system + mina_base.import + cli_lib + genesis_constants + transaction_witness + perf_histograms + snark_work_lib + currency + mina_base + mina_transaction + transaction_snark + ledger_proof + mina_ledger + transaction_snark_work + error_json + mina_node_config.unconfigurable_constants + mina_state + transaction_protocol_state + ppx_version.runtime) (preprocess (pps - ppx_bin_prot - ppx_mina - ppx_here - ppx_custom_printf - ppx_deriving_yojson - ppx_inline_test - ppx_let - ppx_register_event - ppx_sexp_conv - ppx_version)) - (instrumentation (backend bisect_ppx)) + ppx_bin_prot + ppx_mina + ppx_here + ppx_custom_printf + ppx_deriving_yojson + ppx_inline_test + ppx_let + ppx_register_event + ppx_sexp_conv + ppx_version)) + (instrumentation + (backend bisect_ppx)) (synopsis "Lib powering the snark_worker interactions with the daemon")) From f45cb7ffdaebc138905c75124b672f58eeac7f21 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Wed, 29 Jan 2025 01:27:09 +0000 Subject: [PATCH 16/16] Use MINA_CONFIG_FILE env var to pass config file --- src/test/command_line_tests/mina_cli.ml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/command_line_tests/mina_cli.ml b/src/test/command_line_tests/mina_cli.ml index d0f1a1590ab..5e28d5f3d8c 100644 --- a/src/test/command_line_tests/mina_cli.ml +++ b/src/test/command_line_tests/mina_cli.ml @@ -34,9 +34,10 @@ module MinaCli = struct Process.run ~prog:t.mina_exe ~args:[ "advanced"; "print-signature-kind" ] () let advanced_compile_time_constants t ~config_file = - Process.run ~prog:t.mina_exe - ~args: - [ "advanced"; "compile-time-constants"; "--config-file"; config_file ] + Process.run + ~env:(`Extend [ ("MINA_CONFIG_FILE", config_file) ]) + ~prog:t.mina_exe + ~args:[ "advanced"; "compile-time-constants" ] () let advanced_constraint_system_digests t =