From 2531f8d9a8f5026e8bb8862ad8d405ff8f38a96a Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Wed, 20 Dec 2023 11:51:13 +0100 Subject: [PATCH 01/12] tezt/tests: add baker rewards test --- tezt/tests/baker_test.ml | 33 +++++ .../baker_test.ml/Alpha- Baker rewards.out | 126 ++++++++++++++++++ .../baker_test.ml/Nairobi- Baker rewards.out | 121 +++++++++++++++++ .../baker_test.ml/Oxford- Baker rewards.out | 126 ++++++++++++++++++ 4 files changed, 406 insertions(+) create mode 100644 tezt/tests/expected/baker_test.ml/Alpha- Baker rewards.out create mode 100644 tezt/tests/expected/baker_test.ml/Nairobi- Baker rewards.out create mode 100644 tezt/tests/expected/baker_test.ml/Oxford- Baker rewards.out diff --git a/tezt/tests/baker_test.ml b/tezt/tests/baker_test.ml index cb5d66b23d40..096a95485ecd 100644 --- a/tezt/tests/baker_test.ml +++ b/tezt/tests/baker_test.ml @@ -30,6 +30,38 @@ Subject: Run the baker while performing a lot of transfers *) +let hooks = Tezos_regression.hooks + +let baker_reward_test = + Protocol.register_regression_test + ~__FILE__ + ~title:"Baker rewards" + ~tags:["baker"; "rewards"] + ~uses:(fun protocol -> [Protocol.baker protocol]) + (fun protocol -> + let* parameter_file = + Protocol.write_parameter_file + ~base:(Either.Right (protocol, Some Constants_mainnet)) + [] + in + let* node, client = + Client.init_with_protocol + `Client + ~protocol + ~timestamp:Now + ~parameter_file + () + in + let level_2_promise = Node.wait_for_level node 2 in + let* baker = Baker.init ~protocol node client in + Log.info "Wait for new head." ; + Baker.log_events baker ; + let* _ = level_2_promise in + let* _ = + Client.RPC.call ~hooks client @@ RPC.get_chain_block_metadata () + in + unit) + let baker_test ?force_apply protocol ~keys = let* parameter_file = Protocol.write_parameter_file @@ -156,6 +188,7 @@ let baker_remote_test = let register ~protocols = baker_simple_test protocols ; + baker_reward_test protocols ; baker_stresstest protocols ; baker_stresstest_apply protocols ; baker_bls_test protocols ; diff --git a/tezt/tests/expected/baker_test.ml/Alpha- Baker rewards.out b/tezt/tests/expected/baker_test.ml/Alpha- Baker rewards.out new file mode 100644 index 000000000000..4338b6ec03ec --- /dev/null +++ b/tezt/tests/expected/baker_test.ml/Alpha- Baker rewards.out @@ -0,0 +1,126 @@ + +./octez-client rpc get /chains/main/blocks/head/metadata +{ "protocol": "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK", + "next_protocol": "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK", + "test_chain_status": { "status": "not_running" }, "max_operations_ttl": 2, + "max_operation_data_length": 32768, "max_block_header_length": 289, + "max_operation_list_length": + [ { "max_size": 4194304, "max_op": 2048 }, { "max_size": 32768 }, + { "max_size": 135168, "max_op": 132 }, { "max_size": 524288 } ], + "proposer": "[PUBLIC_KEY_HASH]", + "baker": "[PUBLIC_KEY_HASH]", + "level_info": + { "level": 2, "level_position": 1, "cycle": 0, "cycle_position": 1, + "expected_commitment": false }, + "voting_period_info": + { "voting_period": + { "index": 0, "kind": "proposal", "start_position": 0 }, + "position": 1, "remaining": 81918 }, "nonce_hash": null, + "deactivated": [], + "balance_updates": + [ { "kind": "minted", "category": "bootstrap", + "change": "-20000000000000", "origin": "migration" }, + { "kind": "freezer", "category": "deposits", + "staker": { "baker": "[PUBLIC_KEY_HASH]" }, + "change": "400000000000", "origin": "migration" }, + { "kind": "freezer", "category": "deposits", + "staker": { "baker": "[PUBLIC_KEY_HASH]" }, + "change": "400000000000", "origin": "migration" }, + { "kind": "freezer", "category": "deposits", + "staker": { "baker": "[PUBLIC_KEY_HASH]" }, + "change": "400000000000", "origin": "migration" }, + { "kind": "freezer", "category": "deposits", + "staker": { "baker": "[PUBLIC_KEY_HASH]" }, + "change": "400000000000", "origin": "migration" }, + { "kind": "freezer", "category": "deposits", + "staker": { "baker": "[PUBLIC_KEY_HASH]" }, + "change": "400000000000", "origin": "migration" }, + { "kind": "contract", + "contract": "[PUBLIC_KEY_HASH]", + "change": "3600000000000", "origin": "migration" }, + { "kind": "contract", + "contract": "[PUBLIC_KEY_HASH]", + "change": "3600000000000", "origin": "migration" }, + { "kind": "contract", + "contract": "[PUBLIC_KEY_HASH]", + "change": "3600000000000", "origin": "migration" }, + { "kind": "contract", + "contract": "[PUBLIC_KEY_HASH]", + "change": "3600000000000", "origin": "migration" }, + { "kind": "contract", + "contract": "[PUBLIC_KEY_HASH]", + "change": "3600000000000", "origin": "migration" }, + { "kind": "minted", "category": "baking rewards", "change": "-500000", + "origin": "block" }, + { "kind": "freezer", "category": "deposits", + "staker": { "baker": "[PUBLIC_KEY_HASH]" }, + "change": "500000", "origin": "block" }, + { "kind": "minted", "category": "baking rewards", "change": "-4499999", + "origin": "block" }, + { "kind": "contract", + "contract": "[PUBLIC_KEY_HASH]", + "change": "4499999", "origin": "block" } ], + "liquidity_baking_toggle_ema": 0, "adaptive_issuance_vote_ema": 0, + "implicit_operations_results": + [ { "kind": "origination", + "balance_updates": + [ { "kind": "minted", "category": "subsidy", "change": "-64250", + "origin": "migration" }, + { "kind": "burned", "category": "storage fees", + "change": "64250", "origin": "migration" }, + { "kind": "minted", "category": "subsidy", "change": "-1157000", + "origin": "migration" }, + { "kind": "burned", "category": "storage fees", + "change": "1157000", "origin": "migration" }, + { "kind": "minted", "category": "subsidy", "change": "-100", + "origin": "migration" }, + { "kind": "contract", + "contract": "[CONTRACT_HASH]", + "change": "100", "origin": "migration" } ], + "originated_contracts": [ "[CONTRACT_HASH]" ], + "storage_size": "4628", "paid_storage_size_diff": "4628" }, + { "kind": "origination", + "balance_updates": + [ { "kind": "minted", "category": "subsidy", "change": "-64250", + "origin": "migration" }, + { "kind": "burned", "category": "storage fees", + "change": "64250", "origin": "migration" }, + { "kind": "minted", "category": "subsidy", "change": "-494500", + "origin": "migration" }, + { "kind": "burned", "category": "storage fees", + "change": "494500", "origin": "migration" } ], + "originated_contracts": [ "[CONTRACT_HASH]" ], + "storage_size": "1978", "paid_storage_size_diff": "1978" }, + { "kind": "origination", + "balance_updates": + [ { "kind": "minted", "category": "subsidy", "change": "-64250", + "origin": "migration" }, + { "kind": "burned", "category": "storage fees", + "change": "64250", "origin": "migration" }, + { "kind": "minted", "category": "subsidy", "change": "-477750", + "origin": "migration" }, + { "kind": "burned", "category": "storage fees", + "change": "477750", "origin": "migration" }, + { "kind": "minted", "category": "subsidy", "change": "-1000000", + "origin": "migration" }, + { "kind": "contract", + "contract": "[CONTRACT_HASH]", + "change": "1000000", "origin": "migration" } ], + "originated_contracts": [ "[CONTRACT_HASH]" ], + "storage_size": "1911", "paid_storage_size_diff": "1911" }, + { "kind": "transaction", + "storage": + [ { "int": "1" }, { "int": "1250099" }, { "int": "100" }, + { "bytes": "01e927f00ef734dfc85919635e9afc9166c83ef9fc00" }, + { "bytes": "0115eb0104481a6d7921160bc982c5e0a561cd8a3a00" } ], + "balance_updates": + [ { "kind": "minted", "category": "subsidy", "change": "-1249999", + "origin": "subsidy" }, + { "kind": "contract", + "contract": "[CONTRACT_HASH]", + "change": "1249999", "origin": "subsidy" } ], + "consumed_milligas": "2261931", "storage_size": "4630", + "paid_storage_size_diff": "2" } ], + "proposer_consensus_key": "[PUBLIC_KEY_HASH]", + "baker_consensus_key": "[PUBLIC_KEY_HASH]", + "consumed_milligas": "0" } diff --git a/tezt/tests/expected/baker_test.ml/Nairobi- Baker rewards.out b/tezt/tests/expected/baker_test.ml/Nairobi- Baker rewards.out new file mode 100644 index 000000000000..c47486ab5c03 --- /dev/null +++ b/tezt/tests/expected/baker_test.ml/Nairobi- Baker rewards.out @@ -0,0 +1,121 @@ + +./octez-client rpc get /chains/main/blocks/head/metadata +{ "protocol": "PtNairobiyssHuh87hEhfVBGCVrK3WnS8Z2FT4ymB5tAa4r1nQf", + "next_protocol": "PtNairobiyssHuh87hEhfVBGCVrK3WnS8Z2FT4ymB5tAa4r1nQf", + "test_chain_status": { "status": "not_running" }, "max_operations_ttl": 2, + "max_operation_data_length": 32768, "max_block_header_length": 289, + "max_operation_list_length": + [ { "max_size": 4194304, "max_op": 2048 }, { "max_size": 32768 }, + { "max_size": 135168, "max_op": 132 }, { "max_size": 524288 } ], + "proposer": "[PUBLIC_KEY_HASH]", + "baker": "[PUBLIC_KEY_HASH]", + "level_info": + { "level": 2, "level_position": 1, "cycle": 0, "cycle_position": 1, + "expected_commitment": false }, + "voting_period_info": + { "voting_period": + { "index": 0, "kind": "proposal", "start_position": 0 }, + "position": 1, "remaining": 81918 }, "nonce_hash": null, + "deactivated": [], + "balance_updates": + [ { "kind": "minted", "category": "bootstrap", + "change": "-20000000000000", "origin": "migration" }, + { "kind": "freezer", "category": "deposits", + "delegate": "[PUBLIC_KEY_HASH]", + "change": "400000000000", "origin": "migration" }, + { "kind": "freezer", "category": "deposits", + "delegate": "[PUBLIC_KEY_HASH]", + "change": "400000000000", "origin": "migration" }, + { "kind": "freezer", "category": "deposits", + "delegate": "[PUBLIC_KEY_HASH]", + "change": "400000000000", "origin": "migration" }, + { "kind": "freezer", "category": "deposits", + "delegate": "[PUBLIC_KEY_HASH]", + "change": "400000000000", "origin": "migration" }, + { "kind": "freezer", "category": "deposits", + "delegate": "[PUBLIC_KEY_HASH]", + "change": "400000000000", "origin": "migration" }, + { "kind": "contract", + "contract": "[PUBLIC_KEY_HASH]", + "change": "3600000000000", "origin": "migration" }, + { "kind": "contract", + "contract": "[PUBLIC_KEY_HASH]", + "change": "3600000000000", "origin": "migration" }, + { "kind": "contract", + "contract": "[PUBLIC_KEY_HASH]", + "change": "3600000000000", "origin": "migration" }, + { "kind": "contract", + "contract": "[PUBLIC_KEY_HASH]", + "change": "3600000000000", "origin": "migration" }, + { "kind": "contract", + "contract": "[PUBLIC_KEY_HASH]", + "change": "3600000000000", "origin": "migration" }, + { "kind": "minted", "category": "baking rewards", "change": "-5000000", + "origin": "block" }, + { "kind": "contract", + "contract": "[PUBLIC_KEY_HASH]", + "change": "5000000", "origin": "block" } ], + "liquidity_baking_toggle_ema": 0, + "implicit_operations_results": + [ { "kind": "origination", + "balance_updates": + [ { "kind": "minted", "category": "subsidy", "change": "-64250", + "origin": "migration" }, + { "kind": "burned", "category": "storage fees", + "change": "64250", "origin": "migration" }, + { "kind": "minted", "category": "subsidy", "change": "-1157000", + "origin": "migration" }, + { "kind": "burned", "category": "storage fees", + "change": "1157000", "origin": "migration" }, + { "kind": "minted", "category": "subsidy", "change": "-100", + "origin": "migration" }, + { "kind": "contract", + "contract": "[CONTRACT_HASH]", + "change": "100", "origin": "migration" } ], + "originated_contracts": [ "[CONTRACT_HASH]" ], + "storage_size": "4628", "paid_storage_size_diff": "4628" }, + { "kind": "origination", + "balance_updates": + [ { "kind": "minted", "category": "subsidy", "change": "-64250", + "origin": "migration" }, + { "kind": "burned", "category": "storage fees", + "change": "64250", "origin": "migration" }, + { "kind": "minted", "category": "subsidy", "change": "-494500", + "origin": "migration" }, + { "kind": "burned", "category": "storage fees", + "change": "494500", "origin": "migration" } ], + "originated_contracts": [ "[CONTRACT_HASH]" ], + "storage_size": "1978", "paid_storage_size_diff": "1978" }, + { "kind": "origination", + "balance_updates": + [ { "kind": "minted", "category": "subsidy", "change": "-64250", + "origin": "migration" }, + { "kind": "burned", "category": "storage fees", + "change": "64250", "origin": "migration" }, + { "kind": "minted", "category": "subsidy", "change": "-477750", + "origin": "migration" }, + { "kind": "burned", "category": "storage fees", + "change": "477750", "origin": "migration" }, + { "kind": "minted", "category": "subsidy", "change": "-1000000", + "origin": "migration" }, + { "kind": "contract", + "contract": "[CONTRACT_HASH]", + "change": "1000000", "origin": "migration" } ], + "originated_contracts": [ "[CONTRACT_HASH]" ], + "storage_size": "1911", "paid_storage_size_diff": "1911" }, + { "kind": "transaction", + "storage": + [ { "int": "1" }, { "int": "1250100" }, { "int": "100" }, + { "bytes": "01e927f00ef734dfc85919635e9afc9166c83ef9fc00" }, + { "bytes": "0115eb0104481a6d7921160bc982c5e0a561cd8a3a00" } ], + "balance_updates": + [ { "kind": "minted", "category": "subsidy", "change": "-1250000", + "origin": "subsidy" }, + { "kind": "contract", + "contract": "[CONTRACT_HASH]", + "change": "1250000", "origin": "subsidy" } ], + "consumed_milligas": "2263472", "storage_size": "4630", + "paid_storage_size_diff": "2" } ], + "proposer_consensus_key": "[PUBLIC_KEY_HASH]", + "baker_consensus_key": "[PUBLIC_KEY_HASH]", + "consumed_milligas": "0" } diff --git a/tezt/tests/expected/baker_test.ml/Oxford- Baker rewards.out b/tezt/tests/expected/baker_test.ml/Oxford- Baker rewards.out new file mode 100644 index 000000000000..3f370137bdeb --- /dev/null +++ b/tezt/tests/expected/baker_test.ml/Oxford- Baker rewards.out @@ -0,0 +1,126 @@ + +./octez-client rpc get /chains/main/blocks/head/metadata +{ "protocol": "ProxfordYmVfjWnRcgjWH36fW6PArwqykTFzotUxRs6gmTcZDuH", + "next_protocol": "ProxfordYmVfjWnRcgjWH36fW6PArwqykTFzotUxRs6gmTcZDuH", + "test_chain_status": { "status": "not_running" }, "max_operations_ttl": 2, + "max_operation_data_length": 32768, "max_block_header_length": 289, + "max_operation_list_length": + [ { "max_size": 4194304, "max_op": 2048 }, { "max_size": 32768 }, + { "max_size": 135168, "max_op": 132 }, { "max_size": 524288 } ], + "proposer": "[PUBLIC_KEY_HASH]", + "baker": "[PUBLIC_KEY_HASH]", + "level_info": + { "level": 2, "level_position": 1, "cycle": 0, "cycle_position": 1, + "expected_commitment": false }, + "voting_period_info": + { "voting_period": + { "index": 0, "kind": "proposal", "start_position": 0 }, + "position": 1, "remaining": 81918 }, "nonce_hash": null, + "deactivated": [], + "balance_updates": + [ { "kind": "minted", "category": "bootstrap", + "change": "-20000000000000", "origin": "migration" }, + { "kind": "freezer", "category": "deposits", + "staker": { "baker": "[PUBLIC_KEY_HASH]" }, + "change": "400000000000", "origin": "migration" }, + { "kind": "freezer", "category": "deposits", + "staker": { "baker": "[PUBLIC_KEY_HASH]" }, + "change": "400000000000", "origin": "migration" }, + { "kind": "freezer", "category": "deposits", + "staker": { "baker": "[PUBLIC_KEY_HASH]" }, + "change": "400000000000", "origin": "migration" }, + { "kind": "freezer", "category": "deposits", + "staker": { "baker": "[PUBLIC_KEY_HASH]" }, + "change": "400000000000", "origin": "migration" }, + { "kind": "freezer", "category": "deposits", + "staker": { "baker": "[PUBLIC_KEY_HASH]" }, + "change": "400000000000", "origin": "migration" }, + { "kind": "contract", + "contract": "[PUBLIC_KEY_HASH]", + "change": "3600000000000", "origin": "migration" }, + { "kind": "contract", + "contract": "[PUBLIC_KEY_HASH]", + "change": "3600000000000", "origin": "migration" }, + { "kind": "contract", + "contract": "[PUBLIC_KEY_HASH]", + "change": "3600000000000", "origin": "migration" }, + { "kind": "contract", + "contract": "[PUBLIC_KEY_HASH]", + "change": "3600000000000", "origin": "migration" }, + { "kind": "contract", + "contract": "[PUBLIC_KEY_HASH]", + "change": "3600000000000", "origin": "migration" }, + { "kind": "minted", "category": "baking rewards", "change": "-500000", + "origin": "block" }, + { "kind": "freezer", "category": "deposits", + "staker": { "baker": "[PUBLIC_KEY_HASH]" }, + "change": "500000", "origin": "block" }, + { "kind": "minted", "category": "baking rewards", "change": "-4499999", + "origin": "block" }, + { "kind": "contract", + "contract": "[PUBLIC_KEY_HASH]", + "change": "4499999", "origin": "block" } ], + "liquidity_baking_toggle_ema": 0, "adaptive_issuance_vote_ema": 0, + "implicit_operations_results": + [ { "kind": "origination", + "balance_updates": + [ { "kind": "minted", "category": "subsidy", "change": "-64250", + "origin": "migration" }, + { "kind": "burned", "category": "storage fees", + "change": "64250", "origin": "migration" }, + { "kind": "minted", "category": "subsidy", "change": "-1157000", + "origin": "migration" }, + { "kind": "burned", "category": "storage fees", + "change": "1157000", "origin": "migration" }, + { "kind": "minted", "category": "subsidy", "change": "-100", + "origin": "migration" }, + { "kind": "contract", + "contract": "[CONTRACT_HASH]", + "change": "100", "origin": "migration" } ], + "originated_contracts": [ "[CONTRACT_HASH]" ], + "storage_size": "4628", "paid_storage_size_diff": "4628" }, + { "kind": "origination", + "balance_updates": + [ { "kind": "minted", "category": "subsidy", "change": "-64250", + "origin": "migration" }, + { "kind": "burned", "category": "storage fees", + "change": "64250", "origin": "migration" }, + { "kind": "minted", "category": "subsidy", "change": "-494500", + "origin": "migration" }, + { "kind": "burned", "category": "storage fees", + "change": "494500", "origin": "migration" } ], + "originated_contracts": [ "[CONTRACT_HASH]" ], + "storage_size": "1978", "paid_storage_size_diff": "1978" }, + { "kind": "origination", + "balance_updates": + [ { "kind": "minted", "category": "subsidy", "change": "-64250", + "origin": "migration" }, + { "kind": "burned", "category": "storage fees", + "change": "64250", "origin": "migration" }, + { "kind": "minted", "category": "subsidy", "change": "-477750", + "origin": "migration" }, + { "kind": "burned", "category": "storage fees", + "change": "477750", "origin": "migration" }, + { "kind": "minted", "category": "subsidy", "change": "-1000000", + "origin": "migration" }, + { "kind": "contract", + "contract": "[CONTRACT_HASH]", + "change": "1000000", "origin": "migration" } ], + "originated_contracts": [ "[CONTRACT_HASH]" ], + "storage_size": "1911", "paid_storage_size_diff": "1911" }, + { "kind": "transaction", + "storage": + [ { "int": "1" }, { "int": "1250099" }, { "int": "100" }, + { "bytes": "01e927f00ef734dfc85919635e9afc9166c83ef9fc00" }, + { "bytes": "0115eb0104481a6d7921160bc982c5e0a561cd8a3a00" } ], + "balance_updates": + [ { "kind": "minted", "category": "subsidy", "change": "-1249999", + "origin": "subsidy" }, + { "kind": "contract", + "contract": "[CONTRACT_HASH]", + "change": "1249999", "origin": "subsidy" } ], + "consumed_milligas": "2261931", "storage_size": "4630", + "paid_storage_size_diff": "2" } ], + "proposer_consensus_key": "[PUBLIC_KEY_HASH]", + "baker_consensus_key": "[PUBLIC_KEY_HASH]", + "consumed_milligas": "0" } -- GitLab From 9e3972a343946e97146e780293001bb64587b989 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Wed, 13 Dec 2023 11:20:01 +0100 Subject: [PATCH 02/12] Proto: set block times to 10s and update related constants --- .../lib_parameters/default_parameters.ml | 20 ++--- .../lib_protocol/delegate_rewards.ml | 4 +- src/proto_alpha/lib_protocol/raw_context.ml | 79 +++++++++++++++++++ src/proto_alpha/lib_protocol/storage.ml | 2 +- 4 files changed, 92 insertions(+), 13 deletions(-) diff --git a/src/proto_alpha/lib_parameters/default_parameters.ml b/src/proto_alpha/lib_parameters/default_parameters.ml index 5e51b8c3ab00..97e6a172dcce 100644 --- a/src/proto_alpha/lib_parameters/default_parameters.ml +++ b/src/proto_alpha/lib_parameters/default_parameters.ml @@ -98,7 +98,7 @@ let default_dal = let constants_mainnet = let consensus_committee_size = 7000 in - let block_time = 15 in + let block_time = 10 in let Constants.Generated. { consensus_threshold; @@ -132,21 +132,21 @@ let constants_mainnet = consensus_rights_delay = 5; blocks_preservation_cycles = 1; delegate_parameters_activation_delay = 5; - blocks_per_cycle = 16384l; - blocks_per_commitment = 128l; - nonce_revelation_threshold = 512l; - blocks_per_stake_snapshot = 1024l; + blocks_per_cycle = 24576l; + blocks_per_commitment = 192l; + nonce_revelation_threshold = 768l; + blocks_per_stake_snapshot = 1536l; cycles_per_voting_period = 5l; hard_gas_limit_per_operation = Gas.Arith.(integral_of_int_exn 1_040_000); - hard_gas_limit_per_block = Gas.Arith.(integral_of_int_exn 2_600_000); - (* When reducing block times, consider adapting this constant so + hard_gas_limit_per_block = Gas.Arith.(integral_of_int_exn 1_733_333); + (* When reducing blocks time, consider adapting this constant so the block production's overhead is not too important. *) proof_of_work_threshold = Int64.(sub (shift_left 1L 48) 1L); minimal_stake = Tez.(mul_exn one 6_000); minimal_frozen_stake = Tez.(mul_exn one 600); (* VDF's difficulty must be a multiple of `nonce_revelation_threshold` times the block time. At the moment it is equal to 8B = 8000 * 5 * .2M with - - 8000 ~= 512 * 15 that is nonce_revelation_threshold * block time + - 8000 ~= 768 * 10 that is nonce_revelation_threshold * block time - .2M ~= number of modular squaring per second on benchmark machine with 2.8GHz CPU - 5: security factor (strictly higher than the ratio between highest CPU @@ -185,9 +185,9 @@ let constants_mainnet = The unit for this value is a block. *) - max_operations_time_to_live = 240; + max_operations_time_to_live = 360; minimal_block_delay = Period.of_seconds_exn (Int64.of_int block_time); - delay_increment_per_round = Period.of_seconds_exn 8L; + delay_increment_per_round = Period.of_seconds_exn 5L; consensus_committee_size; consensus_threshold; (* 4667 slots *) diff --git a/src/proto_alpha/lib_protocol/delegate_rewards.ml b/src/proto_alpha/lib_protocol/delegate_rewards.ml index 419300489035..0b61dae93a05 100644 --- a/src/proto_alpha/lib_protocol/delegate_rewards.ml +++ b/src/proto_alpha/lib_protocol/delegate_rewards.ml @@ -93,12 +93,12 @@ module M = struct | Liquidity_baking_subsidy -> issuance_weights.liquidity_baking_subsidy_weight | Seed_nonce_revelation_tip -> - (* Seed nonce revelation rewards are given every [blocks_per_commitment](=128)th block *) + (* Seed nonce revelation rewards are given every [blocks_per_commitment](=192)th block *) let blocks_per_commitment = Int32.to_int csts.blocks_per_commitment in issuance_weights.seed_nonce_revelation_tip_weight * blocks_per_commitment | Vdf_revelation_tip -> - (* Vdf revelation rewards are given every [blocks_per_commitment](=128)th block *) + (* Vdf revelation rewards are given every [blocks_per_commitment](=192)th block *) let blocks_per_commitment = Int32.to_int csts.blocks_per_commitment in issuance_weights.vdf_revelation_tip_weight * blocks_per_commitment in diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 1400af066c7a..8d1ad90eadb2 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -935,6 +935,63 @@ let[@warning "-32"] get_previous_protocol_constants ctxt = context." | Some constants -> return constants) +let update_block_time_related_constants (c : Constants_parametric_repr.t) = + let divide_period p = + Period_repr.of_seconds_exn + Int64.(div (mul (Period_repr.to_seconds p) 2L) 3L) + in + let minimal_block_delay = divide_period c.minimal_block_delay in + let delay_increment_per_round = divide_period c.delay_increment_per_round in + let hard_gas_limit_per_block = + let two = Z.(succ one) in + let three = Z.(succ two) in + Gas_limit_repr.Arith.( + integral_exn + (Z.div (Z.mul (integral_to_z c.hard_gas_limit_per_block) two) three)) + in + let half_more x = Int32.(div (mul 3l x) 2l) in + let blocks_per_cycle = half_more c.blocks_per_cycle in + let blocks_per_commitment = half_more c.blocks_per_commitment in + let nonce_revelation_threshold = half_more c.nonce_revelation_threshold in + let blocks_per_stake_snapshot = half_more c.blocks_per_stake_snapshot in + let max_operations_time_to_live = 3 * c.max_operations_time_to_live / 2 in + { + c with + blocks_per_cycle; + blocks_per_commitment; + nonce_revelation_threshold; + blocks_per_stake_snapshot; + max_operations_time_to_live; + minimal_block_delay; + delay_increment_per_round; + hard_gas_limit_per_block; + } + +let update_cycle_eras ctxt level ~prev_blocks_per_cycle ~blocks_per_cycle + ~blocks_per_commitment = + let open Lwt_result_syntax in + let* cycle_eras = get_cycle_eras ctxt in + let current_era = Level_repr.current_era cycle_eras in + let current_cycle = + let level_position = + Int32.sub level (Raw_level_repr.to_int32 current_era.first_level) + in + Cycle_repr.add + current_era.first_cycle + (Int32.to_int (Int32.div level_position prev_blocks_per_cycle)) + in + let new_cycle_era = + Level_repr. + { + first_level = Raw_level_repr.of_int32_exn (Int32.succ level); + first_cycle = Cycle_repr.succ current_cycle; + blocks_per_cycle; + blocks_per_commitment; + } + in + let*? new_cycle_eras = Level_repr.add_cycle_era new_cycle_era cycle_eras in + set_cycle_eras ctxt new_cycle_eras + (* You should ensure that if the type `Constants_parametric_repr.t` is different from `Constants_parametric_previous_repr.t` or the value of these constants is modified, is changed from the previous protocol, then @@ -1173,6 +1230,28 @@ let prepare_first_block ~level ~timestamp _chain_id ctxt = direct_ticket_spending_enable; } in + let block_time_is_at_least_8s = + (* This check is used to trigger the constants changes at migration on + this protocol for network that have block time strictly greater + than 7s such as mainnet and ghostnet *) + Compare.Int64.(Period_repr.to_seconds c.minimal_block_delay >= 8L) + in + let* ctxt, constants = + if block_time_is_at_least_8s then + let new_constants : Constants_parametric_repr.t = + update_block_time_related_constants constants + in + let* ctxt = + update_cycle_eras + ctxt + level + ~prev_blocks_per_cycle:constants.blocks_per_cycle + ~blocks_per_cycle:new_constants.blocks_per_cycle + ~blocks_per_commitment:new_constants.blocks_per_commitment + in + return (ctxt, new_constants) + else return (ctxt, constants) + in let*! ctxt = add_constants ctxt constants in return ctxt in diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index 0c9b54d0e464..7114052632f2 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -1371,7 +1371,7 @@ module Stake = struct That is, the increment is done every [blocks_per_stake_snaphot] blocks and reset at the end of cycles. So, it goes up to [blocks_per_cycle / blocks_per_stake_snaphot], which is currently - 16 (= 8192/512 -- the concrete values can be found in + 16 (= 24576/1536 -- the concrete values can be found in {!val:Default_parameters.constants_mainnet}), then comes back to 0, so that a UInt16 is big enough. -- GitLab From 0d0d16863e61313ece55dbe8e73e2c13b9614c18 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Tue, 19 Dec 2023 16:04:59 +0100 Subject: [PATCH 03/12] proto: adapt AI EMA parameters --- .../lib_protocol/per_block_votes_repr.ml | 4 ++-- .../integration/test_adaptive_issuance_launch.ml | 8 ++++---- .../test/unit/test_adaptive_issuance_ema.ml | 16 ++++++++-------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/proto_alpha/lib_protocol/per_block_votes_repr.ml b/src/proto_alpha/lib_protocol/per_block_votes_repr.ml index dc10200105d6..a30dd1bc9481 100644 --- a/src/proto_alpha/lib_protocol/per_block_votes_repr.ml +++ b/src/proto_alpha/lib_protocol/per_block_votes_repr.ml @@ -105,11 +105,11 @@ module Adaptive_issuance_launch_EMA = Votes_EMA_repr.Make (struct baker_contrib = (1/2) * ema_max * (1 - 2^(-1/k)) - where k is the number of blocks in 2 weeks (which is 80640). + where k is the number of blocks in 2 weeks (which is 120960). Because of a small accumulation of rounding errors, two more blocks are actually needed. *) - let baker_contribution = Z.of_int 8595 + let baker_contribution = Z.of_int 5730 let ema_max = 2_000_000_000l end) diff --git a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_launch.ml b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_launch.ml index 080c686e4deb..cbb75e645266 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_launch.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_launch.ml @@ -469,7 +469,7 @@ let tests = `Quick (test_launch 1000000l (* This means that the threshold is set at 0.05% *) - 59l); + 88l); Tztest.tztest "the EMA reaches the vote threshold at the expected level and adaptive \ issuance launches (realistic threshold, vote enabled)" @@ -477,7 +477,7 @@ let tests = (test_launch Default_parameters.constants_test.adaptive_issuance .launch_ema_threshold - 187259l + 280894l (* This vote duration is consistent with the result of the unit test for this EMA in ../unit/test_adaptive_issuance_ema.ml*)); @@ -487,7 +487,7 @@ let tests = `Quick (test_does_not_launch_without_feature_flag 1000000l (* This means that the threshold is set at 0.05% *) - 59l); + 88l); Tztest.tztest "the EMA reaches the vote threshold at the expected level and adaptive \ issuance does not launch (realistic threshold, vote disabled)" @@ -495,7 +495,7 @@ let tests = (test_does_not_launch_without_feature_flag Default_parameters.constants_test.adaptive_issuance .launch_ema_threshold - 187259l + 280894l (* This vote duration is consistent with the result of the unit test for this EMA in ../unit/test_adaptive_issuance_ema.ml*)); diff --git a/src/proto_alpha/lib_protocol/test/unit/test_adaptive_issuance_ema.ml b/src/proto_alpha/lib_protocol/test/unit/test_adaptive_issuance_ema.ml index f1ba74b51b3a..b5475afab6f4 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_adaptive_issuance_ema.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_adaptive_issuance_ema.ml @@ -184,7 +184,7 @@ let test_ema_decreases_off_bound () = 1_000_000l) ema_range -(* Test that 80642 On votes are needed to move from 0% to 50%. *) +(* Test that 120961 On votes are needed to move from 0% to 50%. *) let test_ema_many_on () = let open Lwt_result_syntax in let open Per_block_votes_repr in @@ -201,10 +201,10 @@ let test_ema_many_on () = ~loc:__LOC__ 1_000_000_000l (compute_new_ema_n - (Stdlib.List.init 80642 (fun _ -> Per_block_vote_on)) + (Stdlib.List.init 120961 (fun _ -> Per_block_vote_on)) initial_ema) -(* Test that 80642 Off votes are needed to move from 100% to 50%. *) +(* Test that 120961 Off votes are needed to move from 100% to 50%. *) let test_ema_many_off () = let open Lwt_result_syntax in let open Per_block_votes_repr in @@ -220,7 +220,7 @@ let test_ema_many_off () = Assert.leq_int32 ~loc:__LOC__ (compute_new_ema_n - (Stdlib.List.init 80642 (fun _ -> Per_block_vote_off)) + (Stdlib.List.init 120961 (fun _ -> Per_block_vote_off)) initial_ema) 1_000_000_000l @@ -241,7 +241,7 @@ let test_ema_many_many_on () = ~loc:__LOC__ 1_600_000_000l (compute_new_ema_n - (Stdlib.List.init 187259 (fun _ -> Per_block_vote_on)) + (Stdlib.List.init 280894 (fun _ -> Per_block_vote_on)) initial_ema) (* Test that the EMA update function is symmetric: @@ -288,15 +288,15 @@ let tests = `Quick test_ema_decreases_off_bound; Tztest.tztest - "EMA goes from 0% to 50% in 80642 On votes" + "EMA goes from 0% to 50% in 120961 On votes" `Quick test_ema_many_on; Tztest.tztest - "EMA goes from 100% to 50% in 80642 Off votes" + "EMA goes from 100% to 50% in 120961 Off votes" `Quick test_ema_many_off; Tztest.tztest - "EMA goes from 0% to 80% in 187259 On votes" + "EMA goes from 0% to 80% in 280894 On votes" `Quick test_ema_many_many_on; Tztest.tztest -- GitLab From 46a6ca26fd15de607cd9a7fed5e5e4055adcb234 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Tue, 19 Dec 2023 16:44:44 +0100 Subject: [PATCH 04/12] proto/tests: fix sapling gas operations --- .../lib_protocol/test/integration/michelson/test_sapling.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_sapling.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_sapling.ml index cbc00cf51319..214910e074ea 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_sapling.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_sapling.ml @@ -997,7 +997,7 @@ module Interpreter_tests = struct let*? amount_tez = Tez.one_mutez *? Int64.of_int 15 in let* operation1 = Op.transaction - ~gas_limit:Max + ~gas_limit:High ~fee (B block_start) src @@ -1012,7 +1012,7 @@ module Interpreter_tests = struct let*@ counter = Alpha_context.Contract.get_counter ctx pkh in let* operation2 = Op.transaction - ~gas_limit:Max + ~gas_limit:High ~counter ~fee (B block_start) -- GitLab From 2bde16b655f2bd3cda17c93d0acffa31ecc72d13 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Tue, 19 Dec 2023 17:00:03 +0100 Subject: [PATCH 05/12] proto/tests: fix gas_levels tests --- .../test/integration/gas/test_gas_levels.ml | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/integration/gas/test_gas_levels.ml b/src/proto_alpha/lib_protocol/test/integration/gas/test_gas_levels.ml index fa7d0362f193..54ee6f5d98dd 100644 --- a/src/proto_alpha/lib_protocol/test/integration/gas/test_gas_levels.ml +++ b/src/proto_alpha/lib_protocol/test/integration/gas/test_gas_levels.ml @@ -444,6 +444,10 @@ let make_batch_test_block_one_origination name contract gas_sampler = ("both lists and single operations", test_mixed_operations); ] +let hard_gas_limit_per_operation = 1_040_000 + +let hard_gas_limit_per_block = 1_733_333 + (** Tests the consumption of all gas in a block, should pass *) let test_consume_exactly_all_block_gas () = let open Lwt_result_syntax in @@ -451,14 +455,17 @@ let test_consume_exactly_all_block_gas () = let* block, src_list, dst = block_with_one_origination number_of_ops nil_contract in - (* assumptions: - hard gas limit per operation = 1_040_000 - hard gas limit per block = 2_600_000 - *) let lld = - List.map - (fun src -> - [(src, dst, Alpha_context.Gas.Arith.integral_of_int_exn 1040000)]) + List.mapi + (fun i src -> + [ + ( src, + dst, + Alpha_context.Gas.Arith.integral_of_int_exn + (if i = number_of_ops - 1 then + hard_gas_limit_per_block - hard_gas_limit_per_operation + else hard_gas_limit_per_operation) ); + ]) src_list in let* _, _, _ = bake_operations_with_gas block lld in @@ -468,14 +475,10 @@ let test_consume_exactly_all_block_gas () = operations, should fail *) let test_malformed_block_max_limit_reached () = let open Lwt_result_syntax in - let number_of_ops = 6 in + let number_of_ops = 2 in let* block, src_list, dst = block_with_one_origination number_of_ops nil_contract in - (* assumptions: - hard gas limit per operation = 1040000 - hard gas limit per block = 5200000 - *) let lld = List.mapi (fun i src -> @@ -483,7 +486,9 @@ let test_malformed_block_max_limit_reached () = ( src, dst, Alpha_context.Gas.Arith.integral_of_int_exn - (if i = number_of_ops - 1 then 1 else 1040000) ); + (if i = number_of_ops - 1 then + hard_gas_limit_per_block - hard_gas_limit_per_operation + 1 + else hard_gas_limit_per_operation) ); ]) src_list in @@ -500,14 +505,10 @@ let test_malformed_block_max_limit_reached () = operation list, should fail *) let test_malformed_block_max_limit_reached' () = let open Lwt_result_syntax in - let number_of_ops = 6 in + let number_of_ops = 2 in let* block, src_list, dst = block_with_one_origination number_of_ops nil_contract in - (* assumptions: - hard gas limit per operation = 1040000 - hard gas limit per block = 5200000 - *) let lld = List.mapi (fun i src -> @@ -515,7 +516,9 @@ let test_malformed_block_max_limit_reached' () = ( src, dst, Alpha_context.Gas.Arith.integral_of_int_exn - (if i = number_of_ops - 1 then 1 else 1040000) ); + (if i = number_of_ops - 1 then + hard_gas_limit_per_block - hard_gas_limit_per_operation + 1 + else hard_gas_limit_per_operation) ); ]) src_list in -- GitLab From 0b1099a4ae81937f4f77eef51c07d6fd7b937af8 Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Wed, 20 Dec 2023 11:35:01 +0100 Subject: [PATCH 06/12] proto/test: fix rounding error in test_seed --- .../test/integration/consensus/test_seed.ml | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_seed.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_seed.ml index a0353eae4a61..a3e31178aecd 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_seed.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_seed.ml @@ -212,14 +212,24 @@ let test_revelation_early_wrong_right_twice () = let cycle_for_rewards = Block.current_cycle b in let* b = Block.bake ~policy:(Block.By_account baker_pkh) ~operation b in (* test that the baker gets the tip reward plus the baking reward*) - let* reward_to_liquid = + let* tip_to_liquid = + Adaptive_issuance_helpers.portion_of_rewards_to_liquid_for_cycle + ~policy + (B b) + cycle_for_rewards + pkh + tip + in + let* baking_reward_to_liquid = Adaptive_issuance_helpers.portion_of_rewards_to_liquid_for_cycle ~policy (B b) cycle_for_rewards pkh - Test_tez.(tip +! baking_reward_fixed_portion) + baking_reward_fixed_portion in + let reward_to_liquid = Test_tez.(baking_reward_to_liquid +! tip_to_liquid) in + let* () = balance_was_credited ~loc:__LOC__ (B b) baker baker_bal reward_to_liquid in @@ -432,14 +442,23 @@ let test_early_incorrect_unverified_correct_already_vdf () = let cycle_for_rewards = Block.current_cycle b in let* b = Block.bake ~policy:(Block.By_account baker_pkh) ~operation b in (* test that the baker gets the tip reward plus the baking reward*) - let* reward_to_liquid = + let* tip_to_liquid = + Adaptive_issuance_helpers.portion_of_rewards_to_liquid_for_cycle + ~policy + (B b) + cycle_for_rewards + pkh + seed_nonce_revelation_tip + in + let* baking_reward_to_liquid = Adaptive_issuance_helpers.portion_of_rewards_to_liquid_for_cycle ~policy (B b) cycle_for_rewards pkh - Test_tez.(seed_nonce_revelation_tip +! baking_reward_fixed_portion) + baking_reward_fixed_portion in + let reward_to_liquid = Test_tez.(tip_to_liquid +! baking_reward_to_liquid) in let* () = balance_was_credited ~loc:__LOC__ (B b) baker baker_bal reward_to_liquid in @@ -519,13 +538,24 @@ let test_early_incorrect_unverified_correct_already_vdf () = (* verify the balance was credited following operation inclusion *) let cycle_for_rewards = Block.current_cycle b in let* b = Block.bake ~policy:(Block.By_account baker_pkh) ~operation b in - let* reward_to_liquid = + let* tip_to_liquid = + Adaptive_issuance_helpers.portion_of_rewards_to_liquid_for_cycle + ~policy + (B b) + cycle_for_rewards + pkh + vdf_nonce_revelation_tip + in + let* baking_reward_to_liquid = Adaptive_issuance_helpers.portion_of_rewards_to_liquid_for_cycle ~policy (B b) cycle_for_rewards pkh - Test_tez.(vdf_nonce_revelation_tip +! baking_reward_fixed_portion) + baking_reward_fixed_portion + in + let reward_to_liquid = + Test_tez.(tip_to_liquid +! baking_reward_to_liquid) in let* () = balance_was_credited ~loc:__LOC__ (B b) baker baker_bal reward_to_liquid -- GitLab From 48f964aa2fb70bceb119c73468c41af73d5ae7e8 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Wed, 20 Dec 2023 16:55:07 +0100 Subject: [PATCH 07/12] proto/tests: fix hard_gas_limit_per_block consant in validate tests --- manifest/main.ml | 1 + src/proto_alpha/lib_protocol/test/integration/validate/dune | 2 ++ .../test/integration/validate/manager_operation_helpers.ml | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/manifest/main.ml b/manifest/main.ml index 736d723b7549..7786f2b517b9 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -5392,6 +5392,7 @@ end = struct octez_test_helpers |> open_; test_helpers |> if_some |> open_; octez_base_test_helpers |> open_; + parameters |> if_some |> if_ N.(number >= 019) |> open_; plugin |> if_some |> open_; ] in diff --git a/src/proto_alpha/lib_protocol/test/integration/validate/dune b/src/proto_alpha/lib_protocol/test/integration/validate/dune index 9811a7ed5512..1542ee049ac9 100644 --- a/src/proto_alpha/lib_protocol/test/integration/validate/dune +++ b/src/proto_alpha/lib_protocol/test/integration/validate/dune @@ -14,6 +14,7 @@ octez-libs.test-helpers octez-protocol-alpha-libs.test-helpers octez-libs.base-test-helpers + tezos-protocol-alpha.parameters octez-protocol-alpha-libs.plugin) (library_flags (:standard -linkall)) (flags @@ -28,6 +29,7 @@ -open Tezos_test_helpers -open Tezos_alpha_test_helpers -open Tezos_base_test_helpers + -open Tezos_protocol_alpha_parameters -open Tezos_protocol_plugin_alpha) (modules generator_descriptors diff --git a/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml b/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml index 558fbfa793b5..d9d4f2f9bb3a 100644 --- a/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml @@ -402,7 +402,7 @@ let manager_parameters : Parameters.t -> ctxt_req -> Parameters.t = let hard_gas_limit_per_block = match hard_gas_limit_per_block with | Some gb -> gb - | None -> Gas.Arith.(integral_of_int_exn 5_200_000) + | None -> Default_parameters.constants_mainnet.hard_gas_limit_per_block in let dal = {params.constants.dal with feature_enable = flags.dal} in let sc_rollup = -- GitLab From 6c2b08813f9cbff774ded70df640276077caf0b9 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Tue, 19 Dec 2023 14:07:52 +0100 Subject: [PATCH 08/12] tezt/tests: adapt manager_operations batch test with new gas_limit --- tezt/tests/manager_operations.ml | 50 ++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/tezt/tests/manager_operations.ml b/tezt/tests/manager_operations.ml index 66fa752b7a32..0c81c69d7bbc 100644 --- a/tezt/tests/manager_operations.ml +++ b/tezt/tests/manager_operations.ml @@ -978,15 +978,27 @@ module Deserialisation = struct end module Gas_limits = struct - (** Build a batch of transfers with the same given gas limit for every one of - them. *) - let mk_batch ?(source = Constant.bootstrap2) ?(dest = Constant.bootstrap3) ~nb - ~gas_limit client = + (** Build a batch of transfers with specific gas limit for every one of + them. *) + let mk_batch ?(source = Constant.bootstrap2) ?(dest = Constant.bootstrap3) + ~operations_gas_limit client = let open Operation.Manager in let fee = 1_000_000 in let* counter = get_next_counter client ~source:Constant.bootstrap1 in - let transfers = List.map (fun _ -> transfer ~dest ()) (range 1 nb) in - make_batch ~source ~gas_limit ~fee ~counter transfers |> return + List.mapi + (fun i gas_limit -> + let counter = counter + i in + let payload = transfer ~dest () in + make ~source ~fee ~gas_limit ~counter payload) + operations_gas_limit + |> return + + let remaining_gas_after_big_operation ~(protocol : Protocol.t) + (limits : Helpers.hard_gas_limits) = + match protocol with + | Alpha -> + limits.hard_gas_limit_per_block - limits.hard_gas_limit_per_operation + | Nairobi | Oxford -> limits.hard_gas_limit_per_operation let block_below_ops_below = Protocol.register_test @@ -996,13 +1008,12 @@ module Gas_limits = struct @@ fun protocol -> let* nodes = Helpers.init ~protocol () in let* limits = Helpers.gas_limits nodes.main.client in + let gas_limit = remaining_gas_after_big_operation ~protocol limits in (* Gas limit per op is ok *) - let* batch = - mk_batch - ~nb:2 - ~gas_limit:limits.hard_gas_limit_per_operation - nodes.main.client + let operations_gas_limit = + [limits.hard_gas_limit_per_operation; gas_limit] in + let* batch = mk_batch ~operations_gas_limit nodes.main.client in let* _oph = Memchecks.with_validated_checks ~__LOC__ @@ -1020,12 +1031,11 @@ module Gas_limits = struct @@ fun protocol -> let* nodes = Helpers.init ~protocol () in let* limits = Helpers.gas_limits nodes.main.client in - let* batch = - mk_batch - ~nb:2 - ~gas_limit:(limits.hard_gas_limit_per_operation + 1) - nodes.main.client + let gas_limit = remaining_gas_after_big_operation ~protocol limits in + let operations_gas_limit = + [limits.hard_gas_limit_per_operation + 1; gas_limit - 2] in + let* batch = mk_batch ~operations_gas_limit nodes.main.client in let* _oph = Memchecks.with_refused_checks ~__LOC__ nodes @@ fun () -> (* Gas limit per op is too high *) @@ -1046,12 +1056,10 @@ module Gas_limits = struct (limits.hard_gas_limit_per_block / limits.hard_gas_limit_per_operation) + 1 in - let* batch = - mk_batch - ~nb:too_many_ops - ~gas_limit:limits.hard_gas_limit_per_operation - nodes.main.client + let operations_gas_limit = + List.init too_many_ops (fun _i -> limits.hard_gas_limit_per_operation) in + let* batch = mk_batch ~operations_gas_limit nodes.main.client in let* _oph = Memchecks.with_refused_checks ~__LOC__ nodes @@ fun () -> Operation.Manager.inject ~force:true batch nodes.main.client -- GitLab From e56d9ebb13f390ba5d8d643c47948da76eb92f42 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Tue, 19 Dec 2023 15:38:07 +0100 Subject: [PATCH 09/12] tezt/tests: adapt rpc regression files --- ...pha- (mode client) RPC regression tests- misc_protocol.out | 4 ++-- ...lpha- (mode light) RPC regression tests- misc_protocol.out | 4 ++-- ...lpha- (mode proxy) RPC regression tests- misc_protocol.out | 4 ++-- ...y_server_data_dir) RPC regression tests- misc_protocol.out | 4 ++-- ... proxy_server_rpc) RPC regression tests- misc_protocol.out | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out index 748ea5751a32..1bdf69cf6f60 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out @@ -14,7 +14,7 @@ "blocks_per_cycle": 8, "blocks_per_commitment": 4, "nonce_revelation_threshold": 4, "blocks_per_stake_snapshot": 4, "cycles_per_voting_period": 8, "hard_gas_limit_per_operation": "1040000", - "hard_gas_limit_per_block": "2600000", + "hard_gas_limit_per_block": "1733333", "proof_of_work_threshold": "4611686018427387903", "minimal_stake": "6000000000", "minimal_frozen_stake": "600000000", "vdf_difficulty": "50000", "origination_size": 257, @@ -27,7 +27,7 @@ "cost_per_byte": "250", "hard_storage_limit_per_operation": "60000", "quorum_min": 2000, "quorum_max": 7000, "min_proposal_quorum": 500, "liquidity_baking_toggle_ema_threshold": 1000000000, - "max_operations_time_to_live": 240, "minimal_block_delay": "1", + "max_operations_time_to_live": 360, "minimal_block_delay": "1", "delay_increment_per_round": "1", "consensus_committee_size": 256, "consensus_threshold": 0, "minimal_participation_ratio": { "numerator": 2, "denominator": 3 }, diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out index 8c04ab06a856..296dd6f32fc8 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out @@ -14,7 +14,7 @@ "blocks_per_cycle": 8, "blocks_per_commitment": 4, "nonce_revelation_threshold": 4, "blocks_per_stake_snapshot": 4, "cycles_per_voting_period": 8, "hard_gas_limit_per_operation": "1040000", - "hard_gas_limit_per_block": "2600000", + "hard_gas_limit_per_block": "1733333", "proof_of_work_threshold": "4611686018427387903", "minimal_stake": "6000000000", "minimal_frozen_stake": "600000000", "vdf_difficulty": "50000", "origination_size": 257, @@ -27,7 +27,7 @@ "cost_per_byte": "250", "hard_storage_limit_per_operation": "60000", "quorum_min": 2000, "quorum_max": 7000, "min_proposal_quorum": 500, "liquidity_baking_toggle_ema_threshold": 1000000000, - "max_operations_time_to_live": 240, "minimal_block_delay": "1", + "max_operations_time_to_live": 360, "minimal_block_delay": "1", "delay_increment_per_round": "1", "consensus_committee_size": 256, "consensus_threshold": 0, "minimal_participation_ratio": { "numerator": 2, "denominator": 3 }, diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out index 152594ea4155..3c4fd283f2c3 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out @@ -14,7 +14,7 @@ "blocks_per_cycle": 8, "blocks_per_commitment": 4, "nonce_revelation_threshold": 4, "blocks_per_stake_snapshot": 4, "cycles_per_voting_period": 8, "hard_gas_limit_per_operation": "1040000", - "hard_gas_limit_per_block": "2600000", + "hard_gas_limit_per_block": "1733333", "proof_of_work_threshold": "4611686018427387903", "minimal_stake": "6000000000", "minimal_frozen_stake": "600000000", "vdf_difficulty": "50000", "origination_size": 257, @@ -27,7 +27,7 @@ "cost_per_byte": "250", "hard_storage_limit_per_operation": "60000", "quorum_min": 2000, "quorum_max": 7000, "min_proposal_quorum": 500, "liquidity_baking_toggle_ema_threshold": 1000000000, - "max_operations_time_to_live": 240, "minimal_block_delay": "1", + "max_operations_time_to_live": 360, "minimal_block_delay": "1", "delay_increment_per_round": "1", "consensus_committee_size": 256, "consensus_threshold": 0, "minimal_participation_ratio": { "numerator": 2, "denominator": 3 }, diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out index f8368c908b0e..57e26d9e7df7 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out @@ -14,7 +14,7 @@ "blocks_per_cycle": 8, "blocks_per_commitment": 4, "nonce_revelation_threshold": 4, "blocks_per_stake_snapshot": 4, "cycles_per_voting_period": 8, "hard_gas_limit_per_operation": "1040000", - "hard_gas_limit_per_block": "2600000", + "hard_gas_limit_per_block": "1733333", "proof_of_work_threshold": "4611686018427387903", "minimal_stake": "6000000000", "minimal_frozen_stake": "600000000", "vdf_difficulty": "50000", "origination_size": 257, @@ -27,7 +27,7 @@ "cost_per_byte": "250", "hard_storage_limit_per_operation": "60000", "quorum_min": 2000, "quorum_max": 7000, "min_proposal_quorum": 500, "liquidity_baking_toggle_ema_threshold": 1000000000, - "max_operations_time_to_live": 240, "minimal_block_delay": "1", + "max_operations_time_to_live": 360, "minimal_block_delay": "1", "delay_increment_per_round": "1", "consensus_committee_size": 256, "consensus_threshold": 0, "minimal_participation_ratio": { "numerator": 2, "denominator": 3 }, diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out index f8368c908b0e..57e26d9e7df7 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out @@ -14,7 +14,7 @@ "blocks_per_cycle": 8, "blocks_per_commitment": 4, "nonce_revelation_threshold": 4, "blocks_per_stake_snapshot": 4, "cycles_per_voting_period": 8, "hard_gas_limit_per_operation": "1040000", - "hard_gas_limit_per_block": "2600000", + "hard_gas_limit_per_block": "1733333", "proof_of_work_threshold": "4611686018427387903", "minimal_stake": "6000000000", "minimal_frozen_stake": "600000000", "vdf_difficulty": "50000", "origination_size": 257, @@ -27,7 +27,7 @@ "cost_per_byte": "250", "hard_storage_limit_per_operation": "60000", "quorum_min": 2000, "quorum_max": 7000, "min_proposal_quorum": 500, "liquidity_baking_toggle_ema_threshold": 1000000000, - "max_operations_time_to_live": 240, "minimal_block_delay": "1", + "max_operations_time_to_live": 360, "minimal_block_delay": "1", "delay_increment_per_round": "1", "consensus_committee_size": 256, "consensus_threshold": 0, "minimal_participation_ratio": { "numerator": 2, "denominator": 3 }, -- GitLab From 1f68286806dd1fb58b622a0528c90ff70f446a1d Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Wed, 20 Dec 2023 12:02:58 +0100 Subject: [PATCH 10/12] tezt/tests: adapt baker reward regression tests --- .../baker_test.ml/Alpha- Baker rewards.out | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tezt/tests/expected/baker_test.ml/Alpha- Baker rewards.out b/tezt/tests/expected/baker_test.ml/Alpha- Baker rewards.out index 4338b6ec03ec..4188051db3be 100644 --- a/tezt/tests/expected/baker_test.ml/Alpha- Baker rewards.out +++ b/tezt/tests/expected/baker_test.ml/Alpha- Baker rewards.out @@ -15,7 +15,7 @@ "voting_period_info": { "voting_period": { "index": 0, "kind": "proposal", "start_position": 0 }, - "position": 1, "remaining": 81918 }, "nonce_hash": null, + "position": 1, "remaining": 122878 }, "nonce_hash": null, "deactivated": [], "balance_updates": [ { "kind": "minted", "category": "bootstrap", @@ -50,16 +50,16 @@ { "kind": "contract", "contract": "[PUBLIC_KEY_HASH]", "change": "3600000000000", "origin": "migration" }, - { "kind": "minted", "category": "baking rewards", "change": "-500000", + { "kind": "minted", "category": "baking rewards", "change": "-333334", "origin": "block" }, { "kind": "freezer", "category": "deposits", "staker": { "baker": "[PUBLIC_KEY_HASH]" }, - "change": "500000", "origin": "block" }, - { "kind": "minted", "category": "baking rewards", "change": "-4499999", + "change": "333334", "origin": "block" }, + { "kind": "minted", "category": "baking rewards", "change": "-2999999", "origin": "block" }, { "kind": "contract", "contract": "[PUBLIC_KEY_HASH]", - "change": "4499999", "origin": "block" } ], + "change": "2999999", "origin": "block" } ], "liquidity_baking_toggle_ema": 0, "adaptive_issuance_vote_ema": 0, "implicit_operations_results": [ { "kind": "origination", @@ -110,17 +110,17 @@ "storage_size": "1911", "paid_storage_size_diff": "1911" }, { "kind": "transaction", "storage": - [ { "int": "1" }, { "int": "1250099" }, { "int": "100" }, + [ { "int": "1" }, { "int": "833433" }, { "int": "100" }, { "bytes": "01e927f00ef734dfc85919635e9afc9166c83ef9fc00" }, { "bytes": "0115eb0104481a6d7921160bc982c5e0a561cd8a3a00" } ], "balance_updates": - [ { "kind": "minted", "category": "subsidy", "change": "-1249999", + [ { "kind": "minted", "category": "subsidy", "change": "-833333", "origin": "subsidy" }, { "kind": "contract", "contract": "[CONTRACT_HASH]", - "change": "1249999", "origin": "subsidy" } ], - "consumed_milligas": "2261931", "storage_size": "4630", - "paid_storage_size_diff": "2" } ], + "change": "833333", "origin": "subsidy" } ], + "consumed_milligas": "2261927", "storage_size": "4629", + "paid_storage_size_diff": "1" } ], "proposer_consensus_key": "[PUBLIC_KEY_HASH]", "baker_consensus_key": "[PUBLIC_KEY_HASH]", "consumed_milligas": "0" } -- GitLab From bab7629185a9f173c16b9af921924b9c7f8e73f6 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Wed, 20 Dec 2023 11:23:00 +0100 Subject: [PATCH 11/12] tezt/tests: fix dal tests --- tezt/tests/dal.ml | 2 +- ... and node with L1 (mainnet_lag-2_time-10_preinject-1_sl.out} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename tezt/tests/expected/dal.ml/{Alpha- Testing DAL rollup and node with L1 (mainnet_lag-2_time-15_preinject-1_sl.out => Alpha- Testing DAL rollup and node with L1 (mainnet_lag-2_time-10_preinject-1_sl.out} (100%) diff --git a/tezt/tests/dal.ml b/tezt/tests/dal.ml index 3a718c8bb01f..34c66cc1ea66 100644 --- a/tezt/tests/dal.ml +++ b/tezt/tests/dal.ml @@ -2782,7 +2782,7 @@ let e2e_tests = { constants = Protocol.Constants_mainnet; attestation_lag = 2; - block_delay = 15; + block_delay = 10; number_of_dal_slots = 1; beforehand_slot_injection = 1; num_extra_nodes = 1; diff --git a/tezt/tests/expected/dal.ml/Alpha- Testing DAL rollup and node with L1 (mainnet_lag-2_time-15_preinject-1_sl.out b/tezt/tests/expected/dal.ml/Alpha- Testing DAL rollup and node with L1 (mainnet_lag-2_time-10_preinject-1_sl.out similarity index 100% rename from tezt/tests/expected/dal.ml/Alpha- Testing DAL rollup and node with L1 (mainnet_lag-2_time-15_preinject-1_sl.out rename to tezt/tests/expected/dal.ml/Alpha- Testing DAL rollup and node with L1 (mainnet_lag-2_time-10_preinject-1_sl.out -- GitLab From c1c2455e25266e922156880c82a614e6fc96332f Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Wed, 20 Dec 2023 12:11:40 +0100 Subject: [PATCH 12/12] Docs/Protocols: update changelog for Alpha --- docs/protocols/alpha.rst | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/docs/protocols/alpha.rst b/docs/protocols/alpha.rst index e2195f8c9328..b0f8f76914d6 100644 --- a/docs/protocols/alpha.rst +++ b/docs/protocols/alpha.rst @@ -54,6 +54,57 @@ Protocol parameters Bug Fixes --------- +10s Blocks Time (MR :gl:`!11288`) +--------------------------------- + +Blocks time have been reduced from 15 seconds to 10 seconds. That is, a block +can be produced with a delay of 10 seconds with respect to the previous block, +if both blocks have round 0. This change comes with updating many related +protocol parameters in order to match the reduced blocks time. In particular, +the following quantities are kept the same: + +- the minimal time period of a cycle (namely, 2 days, 20 hours, and 16 minutes), +- the length of the nonce revelation period (namely, around 2 hours and 8 minutes) +- the number of nonce commitments per cycle (namely, 128), +- the number of stake snapshots per cycle (namely, 16), +- the maximum rewards per minute (namely 80 tez), and therefore roughly the same inflation, +- the minimal "time to live" of an operation (namely, 1 hour), +- the block gas limit per minute (namely 10400000 gas), +- the ratio between the liquidity baking subsidy and the maximum rewards per block (namely, 1/16). + +.. list-table:: Changes to protocol parameters + :widths: 50 25 25 + :header-rows: 1 + + * - Parameter (unit) + - Old (oxford) value + - New value + * - ``minimal_block_delay`` (seconds) + - ``15`` + - ``10`` + * - ``delay_increment_per_round`` (seconds) + - ``8`` + - ``5`` + * - ``blocks_per_cycle`` (blocks) + - ``16384`` + - ``24576`` + * - ``blocks_per_commitment`` (blocks) + - ``128`` + - ``192`` + * - ``nonce_revelation_threshold`` (blocks) + - ``512`` + - ``768`` + * - ``blocks_per_stake_snapshot`` (blocks) + - ``1024`` + - ``1536`` + * - ``max_operations_time_to_live`` (blocks) + - ``240`` + - ``360`` + * - ``hard_gas_limit_per_block`` (gas unit) + - ``2600000`` + - ``1733333`` + + Minor Changes ------------- -- GitLab