From 94b7b9de058eee399326b9c248f898239cf2dec3 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Fri, 22 Sep 2023 15:32:07 +0100 Subject: [PATCH] Testnet experiments: generate protocol activation parameters --- .../proto_017_PtNairob_mainnet.json | 57 ++++++++++++ .../testnet_experiment_tools.ml | 87 +++++++++++++++++-- tezt/lib_tezos/protocol.ml | 7 +- tezt/lib_tezos/protocol.mli | 3 + 4 files changed, 146 insertions(+), 8 deletions(-) create mode 100644 devtools/testnet_experiment_tools/activation_parameters_templates/proto_017_PtNairob_mainnet.json diff --git a/devtools/testnet_experiment_tools/activation_parameters_templates/proto_017_PtNairob_mainnet.json b/devtools/testnet_experiment_tools/activation_parameters_templates/proto_017_PtNairob_mainnet.json new file mode 100644 index 000000000000..18da8948bc8b --- /dev/null +++ b/devtools/testnet_experiment_tools/activation_parameters_templates/proto_017_PtNairob_mainnet.json @@ -0,0 +1,57 @@ +{ "bootstrap_accounts": [], + "preserved_cycles": 5, + "blocks_per_cycle": 16384, "blocks_per_commitment": 128, + "nonce_revelation_threshold": 512, "blocks_per_stake_snapshot": 1024, + "cycles_per_voting_period": 5, "hard_gas_limit_per_operation": "1040000", + "hard_gas_limit_per_block": "2600000", + "proof_of_work_threshold": "281474976710655", + "minimal_stake": "6000000000", "vdf_difficulty": "8000000000", + "seed_nonce_revelation_tip": "125000", "origination_size": 257, + "baking_reward_fixed_portion": "5000000", + "baking_reward_bonus_per_slot": "2143", + "endorsing_reward_per_slot": "1428", "cost_per_byte": "250", + "hard_storage_limit_per_operation": "60000", "quorum_min": 2000, + "quorum_max": 7000, "min_proposal_quorum": 500, + "liquidity_baking_subsidy": "1250000", + "liquidity_baking_toggle_ema_threshold": 1000000000, + "max_operations_time_to_live": 240, "minimal_block_delay": "15", + "delay_increment_per_round": "8", "consensus_committee_size": 7000, + "consensus_threshold": 4667, + "minimal_participation_ratio": { "numerator": 2, "denominator": 3 }, + "max_slashing_period": 2, "frozen_deposits_percentage": 10, + "double_baking_punishment": "640000000", + "ratio_of_frozen_deposits_slashed_per_double_endorsement": + { "numerator": 1, "denominator": 2 }, "cache_script_size": 100000000, + "cache_stake_distribution_cycles": 8, "cache_sampler_state_cycles": 8, + "tx_rollup_enable": false, "tx_rollup_origination_size": 4000, + "tx_rollup_hard_size_limit_per_inbox": 500000, + "tx_rollup_hard_size_limit_per_message": 5000, + "tx_rollup_max_withdrawals_per_batch": 15, + "tx_rollup_commitment_bond": "10000000000", + "tx_rollup_finality_period": 40000, "tx_rollup_withdraw_period": 40000, + "tx_rollup_max_inboxes_count": 40100, + "tx_rollup_max_messages_per_inbox": 1010, + "tx_rollup_max_commitments_count": 80100, + "tx_rollup_cost_per_byte_ema_factor": 120, + "tx_rollup_max_ticket_payload_size": 2048, + "tx_rollup_rejection_max_proof_size": 30000, + "tx_rollup_sunset_level": 3473409, + "dal_parametric": + { "feature_enable": false, "number_of_slots": 256, "attestation_lag": 1, + "attestation_threshold": 50, "blocks_per_epoch": 32, + "redundancy_factor": 16, "page_size": 4096, "slot_size": 1048576, + "number_of_shards": 2048 }, "smart_rollup_enable": true, + "smart_rollup_arith_pvm_enable": false, + "smart_rollup_origination_size": 6314, + "smart_rollup_challenge_window_in_blocks": 80640, + "smart_rollup_stake_amount": "10000000000", + "smart_rollup_commitment_period_in_blocks": 60, + "smart_rollup_max_lookahead_in_blocks": 172800, + "smart_rollup_max_active_outbox_levels": 80640, + "smart_rollup_max_outbox_messages_per_level": 100, + "smart_rollup_number_of_sections_in_dissection": 32, + "smart_rollup_timeout_period_in_blocks": 40320, + "smart_rollup_max_number_of_cemented_commitments": 5, + "smart_rollup_max_number_of_parallel_games": 32, "zk_rollup_enable": false, + "zk_rollup_origination_size": 4000, + "zk_rollup_min_pending_to_process": 10 } diff --git a/devtools/testnet_experiment_tools/testnet_experiment_tools.ml b/devtools/testnet_experiment_tools/testnet_experiment_tools.ml index c70ac18f7aaa..95f51866294d 100644 --- a/devtools/testnet_experiment_tools/testnet_experiment_tools.ml +++ b/devtools/testnet_experiment_tools/testnet_experiment_tools.ml @@ -56,7 +56,9 @@ let default_number_of_bakers = 10 let bakers = "BAKERS" -let baker_alias n = Printf.sprintf "baker_%d" n +let baker_prefix = "baker_" + +let baker_alias n = Printf.sprintf "%s%d" baker_prefix n let number_of_bakers = Sys.getenv_opt bakers |> Option.map int_of_string @@ -78,6 +80,32 @@ let network_name_default = "TEZOS_EXPERIMENT_NET" let network_name = Sys.getenv_opt "NETWORK" |> Option.value ~default:network_name_default +let output_parameters_filename = + Sys.getenv_opt "NETWORK_PARAMETERS_OUTPUT" + |> Option.value + ~default:Filename.(concat output_dir "network_parameters.json") + +let network_parameters_templates_dir = + Filename.current_dir_name // "devtools" // "testnet_experiment_tools" + // "activation_parameters_templates" + +let protocol_alpha_parameters_template = + Filename.current_dir_name // "src" // "proto_alpha" // "parameters" + // "mainnet_parameters.json" + +let network_activation_parameters_templates protocol_hash = + match protocol_hash with + | Tezt_tezos.Protocol.Nairobi -> + Some + (Filename.concat + network_parameters_templates_dir + "proto_017_PtNairob_mainnet.json") + | Tezt_tezos.Protocol.Alpha -> + (* Fetching the network parameters from the src/proto_alpha directory, + to be sure that we are in synch with current protocl parameters. *) + Some protocol_alpha_parameters_template + | _ -> None + let genesis_prefix = "BLockGenesisGenesisGenesisGenesisGenesis" let generate_baker_accounts n client = @@ -90,7 +118,7 @@ let generate_baker_accounts n client = in let* () = Lwt_io.printf "Generating accounts" in let* () = generate_baker_account (n - 1) in - Lwt_io.printf "\n\n" + Lwt_io.printf "\n" let rec genesis () = let* time = Lwt_process.pread_line (Lwt_process.shell "date -u +%FT%TZ") in @@ -109,7 +137,7 @@ let save_config (Node_config.{data_dir; _} as configuration) = let file = Filename.concat data_dir "config.json" in let* () = Lwt_io.printf - "Configuration for %s will be written in %s\n\n." + "Configuration for %s will be written in %s\n." network_name file in @@ -136,13 +164,13 @@ module Local = struct let* () = Lwt_io.printf "Keys will be saved in %s. You can change this by setting the \ - OUTPUT_DIR environment variable\n\n" + OUTPUT_DIR environment variable\n" output_dir in let* () = Lwt_io.printf "%d baker accounts will be generated. You can change this by setting \ - the BAKERS environment variable.\n\n" + the BAKERS environment variable.\n" number_of_bakers in let client = Client.create ~base_dir:output_dir () in @@ -201,6 +229,50 @@ module Local = struct let* () = save_config node_configuration in Lwt.return_unit + let generate_network_activation_parameters protocol_hash () = + let* () = + Lwt_io.printf + "All relative paths in commands will use %s as the current working \ + directory\n" + Filename.current_dir_name + in + let activation_parameters_filename = + match network_activation_parameters_templates protocol_hash with + | None -> + Test.fail "Protocol %s not supported" (Protocol.name protocol_hash) + | Some activation_parameters_filename -> activation_parameters_filename + in + let client = Client.create ~base_dir:output_dir () in + let* () = Lwt_io.printf "Fetching client accounts\n" in + let* client_accounts_with_pkhs = Client.list_known_addresses client in + let baker_accounts = + client_accounts_with_pkhs |> List.map fst + |> List.filter (String.starts_with ~prefix:baker_prefix) + in + let* () = Lwt_io.printf "Fetching client accounts from %s\n" output_dir in + let bootstrap_amount_mutez = Some 4_000_000_000_000 in + let* bootstrap_accounts = + baker_accounts + |> Lwt_list.map_s (fun alias -> + let* () = Lwt_io.printf "." in + let* account_key = Client.show_address ~alias client in + return (account_key, bootstrap_amount_mutez)) + in + let* () = Lwt_io.printf "\n" in + let* () = + Lwt_io.printf + "Retrieving activation parameters template from %s\n" + activation_parameters_filename + in + let* _filename = + Tezt_tezos.Protocol.write_parameter_file + ~bootstrap_accounts + ~base:(Either.Left activation_parameters_filename) + ~output_file:output_parameters_filename + [] + in + Lwt.return_unit + let generate_manager_operations () = Test.fail "Not implemented" end @@ -227,6 +299,11 @@ let () = ~title:"Generate Network Configuration" ~tags:["generate_network_configuration"] (Local.generate_network_configuration network_name output_dir) ; + register + ~__FILE__ + ~title:"Generate Network Activation Parameters" + ~tags:["generate_activation_parameters"] + (Local.generate_network_activation_parameters Protocol.Nairobi) ; register ~__FILE__ ~title:"Generate manager operations" diff --git a/tezt/lib_tezos/protocol.ml b/tezt/lib_tezos/protocol.ml index 2a077e7e827f..b3c85003f55f 100644 --- a/tezt/lib_tezos/protocol.ml +++ b/tezt/lib_tezos/protocol.ml @@ -117,6 +117,7 @@ let write_parameter_file : ?additional_bootstrap_accounts:(Account.key * int option * bool) list -> ?bootstrap_smart_rollups:bootstrap_smart_rollup list -> ?bootstrap_contracts:bootstrap_contract list -> + ?output_file:string -> base:(string, t * constants option) Either.t -> parameter_overrides -> string Lwt.t = @@ -124,10 +125,10 @@ let write_parameter_file : ?(additional_bootstrap_accounts = []) ?(bootstrap_smart_rollups = []) ?(bootstrap_contracts = []) + ?(output_file = Temp.file "parameters.json") ~base parameter_overrides -> (* make a copy of the parameters file and update the given constants *) - let overriden_parameters = Temp.file "parameters.json" in let original_parameters = let file = Either.fold @@ -256,8 +257,8 @@ let write_parameter_file : path (Some (`A (existing_accounts @ additional_bootstrap_accounts))) in - JSON.encode_to_file_u overriden_parameters parameters ; - Lwt.return overriden_parameters + JSON.encode_to_file_u output_file parameters ; + Lwt.return output_file let next_protocol = function | Nairobi -> Some Oxford diff --git a/tezt/lib_tezos/protocol.mli b/tezt/lib_tezos/protocol.mli index 99ac42909120..3936bac553e0 100644 --- a/tezt/lib_tezos/protocol.mli +++ b/tezt/lib_tezos/protocol.mli @@ -148,12 +148,15 @@ val default_bootstrap_balance : int from the start. Default [balance] is 4000000 tez. - [bootstrap_smart_rollups] when given. - [bootstrap_contracts] when given. + - [output_file] the path where to write the protocol parameter file, + a [Temp.file] temporary file "parameters.json" by default. *) val write_parameter_file : ?bootstrap_accounts:(Account.key * int option) list -> ?additional_bootstrap_accounts:(Account.key * int option * bool) list -> ?bootstrap_smart_rollups:bootstrap_smart_rollup list -> ?bootstrap_contracts:bootstrap_contract list -> + ?output_file:string -> base:(string, t * constants option) Either.t -> parameter_overrides -> string Lwt.t -- GitLab