From 94e9360323f529377db6fe8a2b6607b0eb1ac4f8 Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Thu, 1 Aug 2024 13:22:43 +0200 Subject: [PATCH 1/3] Proto/Alpha: update number of cycles stored in the cache --- .../lib_parameters/default_parameters.ml | 9 ++++--- .../lib_protocol/constants_repr.ml | 25 +++++++++++++++++++ src/proto_alpha/lib_protocol/raw_context.ml | 10 +++++--- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/proto_alpha/lib_parameters/default_parameters.ml b/src/proto_alpha/lib_parameters/default_parameters.ml index 0bfaa4e27d8e..4f72be46a744 100644 --- a/src/proto_alpha/lib_parameters/default_parameters.ml +++ b/src/proto_alpha/lib_parameters/default_parameters.ml @@ -266,11 +266,12 @@ let constants_mainnet : Constants.Parametric.t = (* A cache for contract source code and storage. Its size has been chosen not too exceed 100 000 000 bytes. *) cache_script_size = 100_000_000; - (* A cache for the stake distribution for all cycles stored at any - moment: consensus_rights_delay + max_slashing_period + 1 = 8 currently. *) - cache_stake_distribution_cycles = 8; + (* A cache for the stake distribution for all cycles stored at any moment: + consensus_rights_delay + max_slashing_period + 1 = 2 + 2 + 1 = 5 + currently. *) + cache_stake_distribution_cycles = 5; (* One for the sampler state for all cycles stored at any moment (as above). *) - cache_sampler_state_cycles = 8; + cache_sampler_state_cycles = 5; dal = default_dal; sc_rollup; zk_rollup = diff --git a/src/proto_alpha/lib_protocol/constants_repr.ml b/src/proto_alpha/lib_protocol/constants_repr.ml index 5a1cb8ef3f39..ac692c1d79ff 100644 --- a/src/proto_alpha/lib_protocol/constants_repr.ml +++ b/src/proto_alpha/lib_protocol/constants_repr.ml @@ -340,6 +340,31 @@ let check_constants constants = "The number of maximum stored cemented commitments must be strictly \ positive") in + let* () = + error_unless + Compare.Int.( + constants.cache_stake_distribution_cycles + = constants.consensus_rights_delay + max_slashing_period + 1) + (Invalid_protocol_constants + (Format.sprintf + "We should have cache_stake_distribution_cycles (%d) = \ + consensus_rights_delay (%d) + max_slashing_period (%d) + 1." + constants.cache_stake_distribution_cycles + constants.consensus_rights_delay + max_slashing_period)) + in + let* () = + error_unless + Compare.Int.( + constants.cache_sampler_state_cycles + = constants.cache_stake_distribution_cycles) + (Invalid_protocol_constants + (Format.sprintf + "The number cached cycles for the sampler state (%d) and for the \ + stake distribution (%d) should currently be the same." + constants.cache_sampler_state_cycles + constants.cache_stake_distribution_cycles)) + in Result.return_unit module Generated = struct diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 81e924ca1e67..bc1120c061f9 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -1472,8 +1472,8 @@ let prepare_first_block ~level ~timestamp _chain_id ctxt = testnet_dictator; initial_seed; cache_script_size; - cache_stake_distribution_cycles; - cache_sampler_state_cycles; + cache_stake_distribution_cycles = _; + cache_sampler_state_cycles = _; dal = _; sc_rollup = _; zk_rollup = _; @@ -1521,8 +1521,10 @@ let prepare_first_block ~level ~timestamp _chain_id ctxt = testnet_dictator; initial_seed; cache_script_size; - cache_stake_distribution_cycles; - cache_sampler_state_cycles; + cache_stake_distribution_cycles = + consensus_rights_delay + Constants_repr.max_slashing_period + 1; + cache_sampler_state_cycles = + consensus_rights_delay + Constants_repr.max_slashing_period + 1; dal; sc_rollup; zk_rollup; -- GitLab From efba87f3e79ee8eb56c24ff955d45b5c3238eb2a Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Thu, 1 Aug 2024 13:31:28 +0200 Subject: [PATCH 2/3] Tests: reset some regressions --- ...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 ++-- .../Alpha- weeklynet regression test.out | 4 ++-- 6 files changed, 12 insertions(+), 12 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 c15fdf7a44af..818a39eb62b1 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 @@ -34,8 +34,8 @@ "percentage_of_frozen_deposits_slashed_per_double_baking": 500, "percentage_of_frozen_deposits_slashed_per_double_attestation": 5000, "max_slashing_per_block": 10000, "max_slashing_threshold": 101, - "cache_script_size": 100000000, "cache_stake_distribution_cycles": 8, - "cache_sampler_state_cycles": 8, + "cache_script_size": 100000000, "cache_stake_distribution_cycles": 5, + "cache_sampler_state_cycles": 5, "dal_parametric": { "feature_enable": true, "incentives_enable": false, "number_of_slots": 16, "attestation_lag": 8, 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 c24db87341ca..496c82e4d6fe 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 @@ -34,8 +34,8 @@ "percentage_of_frozen_deposits_slashed_per_double_baking": 500, "percentage_of_frozen_deposits_slashed_per_double_attestation": 5000, "max_slashing_per_block": 10000, "max_slashing_threshold": 101, - "cache_script_size": 100000000, "cache_stake_distribution_cycles": 8, - "cache_sampler_state_cycles": 8, + "cache_script_size": 100000000, "cache_stake_distribution_cycles": 5, + "cache_sampler_state_cycles": 5, "dal_parametric": { "feature_enable": true, "incentives_enable": false, "number_of_slots": 16, "attestation_lag": 8, 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 c40986c91f79..7e92103cc081 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 @@ -34,8 +34,8 @@ "percentage_of_frozen_deposits_slashed_per_double_baking": 500, "percentage_of_frozen_deposits_slashed_per_double_attestation": 5000, "max_slashing_per_block": 10000, "max_slashing_threshold": 101, - "cache_script_size": 100000000, "cache_stake_distribution_cycles": 8, - "cache_sampler_state_cycles": 8, + "cache_script_size": 100000000, "cache_stake_distribution_cycles": 5, + "cache_sampler_state_cycles": 5, "dal_parametric": { "feature_enable": true, "incentives_enable": false, "number_of_slots": 16, "attestation_lag": 8, 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 16599d651348..4cb0c56fe997 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 @@ -34,8 +34,8 @@ "percentage_of_frozen_deposits_slashed_per_double_baking": 500, "percentage_of_frozen_deposits_slashed_per_double_attestation": 5000, "max_slashing_per_block": 10000, "max_slashing_threshold": 101, - "cache_script_size": 100000000, "cache_stake_distribution_cycles": 8, - "cache_sampler_state_cycles": 8, + "cache_script_size": 100000000, "cache_stake_distribution_cycles": 5, + "cache_sampler_state_cycles": 5, "dal_parametric": { "feature_enable": true, "incentives_enable": false, "number_of_slots": 16, "attestation_lag": 8, 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 16599d651348..4cb0c56fe997 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 @@ -34,8 +34,8 @@ "percentage_of_frozen_deposits_slashed_per_double_baking": 500, "percentage_of_frozen_deposits_slashed_per_double_attestation": 5000, "max_slashing_per_block": 10000, "max_slashing_threshold": 101, - "cache_script_size": 100000000, "cache_stake_distribution_cycles": 8, - "cache_sampler_state_cycles": 8, + "cache_script_size": 100000000, "cache_stake_distribution_cycles": 5, + "cache_sampler_state_cycles": 5, "dal_parametric": { "feature_enable": true, "incentives_enable": false, "number_of_slots": 16, "attestation_lag": 8, diff --git a/tezt/tests/expected/protocol_migration.ml/Alpha- weeklynet regression test.out b/tezt/tests/expected/protocol_migration.ml/Alpha- weeklynet regression test.out index e4ffca80e7c9..a47254130606 100644 --- a/tezt/tests/expected/protocol_migration.ml/Alpha- weeklynet regression test.out +++ b/tezt/tests/expected/protocol_migration.ml/Alpha- weeklynet regression test.out @@ -24,8 +24,8 @@ "percentage_of_frozen_deposits_slashed_per_double_baking": 700, "percentage_of_frozen_deposits_slashed_per_double_attestation": 5000, "max_slashing_per_block": 10000, "max_slashing_threshold": 2334, - "cache_script_size": 100000000, "cache_stake_distribution_cycles": 8, - "cache_sampler_state_cycles": 8, + "cache_script_size": 100000000, "cache_stake_distribution_cycles": 5, + "cache_sampler_state_cycles": 5, "dal_parametric": { "feature_enable": true, "incentives_enable": false, "number_of_slots": 32, "attestation_lag": 8, -- GitLab From 5d9b902f54259002f0bba5410ae9b03a05b1d49c Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Mon, 5 Aug 2024 11:50:15 +0200 Subject: [PATCH 3/3] Tests: update values of cache constants when needed --- src/proto_alpha/lib_protocol/test/helpers/block.ml | 8 +++++++- tezt/tests/consensus_key.ml | 4 ++++ tezt/tests/prevalidator.ml | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/test/helpers/block.ml b/src/proto_alpha/lib_protocol/test/helpers/block.ml index 7da1a73c2a8d..ae41330b482d 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/block.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/block.ml @@ -643,7 +643,11 @@ let prepare_initial_context_params ?consensus_committee_size ~default:constants.consensus_rights_delay consensus_rights_delay in - + let cache_sampler_state_cycles = + consensus_rights_delay + Constants_repr.max_slashing_period + 1 + and cache_stake_distribution_cycles = + consensus_rights_delay + Constants_repr.max_slashing_period + 1 + in let constants = { constants with @@ -668,6 +672,8 @@ let prepare_initial_context_params ?consensus_committee_size hard_gas_limit_per_block; nonce_revelation_threshold; consensus_rights_delay; + cache_sampler_state_cycles; + cache_stake_distribution_cycles; } in let* () = check_constants_consistency constants in diff --git a/tezt/tests/consensus_key.ml b/tezt/tests/consensus_key.ml index 76f2b5693bf8..561d59182ce1 100644 --- a/tezt/tests/consensus_key.ml +++ b/tezt/tests/consensus_key.ml @@ -102,6 +102,8 @@ let test_update_consensus_key = (["blocks_per_cycle"], `Int blocks_per_cycle); (["nonce_revelation_threshold"], `Int 2); (["consensus_rights_delay"], `Int consensus_rights_delay); + (["cache_sampler_state_cycles"], `Int (consensus_rights_delay + 3)); + (["cache_stake_distribution_cycles"], `Int (consensus_rights_delay + 3)); ] in let* parameter_file = @@ -639,6 +641,8 @@ let register ?(regression = true) title test = (["blocks_per_cycle"], `Int blocks_per_cycle); (["nonce_revelation_threshold"], `Int 2); (["consensus_rights_delay"], `Int consensus_rights_delay); + (["cache_sampler_state_cycles"], `Int (consensus_rights_delay + 3)); + (["cache_stake_distribution_cycles"], `Int (consensus_rights_delay + 3)); ] in let* parameter_file = diff --git a/tezt/tests/prevalidator.ml b/tezt/tests/prevalidator.ml index 1422b12a3cd3..a14333a78f53 100644 --- a/tezt/tests/prevalidator.ml +++ b/tezt/tests/prevalidator.ml @@ -2613,6 +2613,8 @@ module Revamped = struct (["blocks_per_cycle"], `Int blocks_per_cycle); (["nonce_revelation_threshold"], `Int 2); (["consensus_rights_delay"], `Int consensus_rights_delay); + (["cache_sampler_state_cycles"], `Int (consensus_rights_delay + 3)); + (["cache_stake_distribution_cycles"], `Int (consensus_rights_delay + 3)); ] in let* parameter_file = -- GitLab