From f0c800bcd1b2d80d6790f901d89f25accc267f25 Mon Sep 17 00:00:00 2001 From: Marina Polubelova Date: Mon, 21 Jul 2025 16:06:56 +0200 Subject: [PATCH 01/13] Proto: change consensus_rights_delay to 1 This commit also removes redundant entries in the following tables (when decreasing the consensus_rights_delay value): - Storage.Stake.Total_active_stake - Selected_distribution_for_cycle - Delegate_sampler_state --- .../lib_parameters/default_parameters.ml | 6 ++-- .../lib_protocol/delegate_sampler.ml | 22 ++++++++++++ .../lib_protocol/delegate_sampler.mli | 7 ++++ src/proto_alpha/lib_protocol/init_storage.ml | 36 +++++++++++++++++++ src/proto_alpha/lib_protocol/raw_context.ml | 3 +- src/proto_alpha/lib_protocol/stake_storage.ml | 28 +++++++++++++++ .../lib_protocol/stake_storage.mli | 7 ++++ 7 files changed, 104 insertions(+), 5 deletions(-) diff --git a/src/proto_alpha/lib_parameters/default_parameters.ml b/src/proto_alpha/lib_parameters/default_parameters.ml index c99076c0440e..1dd40aa83282 100644 --- a/src/proto_alpha/lib_parameters/default_parameters.ml +++ b/src/proto_alpha/lib_parameters/default_parameters.ml @@ -235,8 +235,8 @@ let constants_mainnet : Constants.Parametric.t = [n+1+consensus_rights_delay] are sampled based on the current baking power of bakers. - Last updated in protocol P. *) - consensus_rights_delay = 2; + Last updated in protocol T. *) + consensus_rights_delay = 1; blocks_preservation_cycles = 1; (* [delegate_parameters_activation_delay] is the number of full cycles after which submitted delegate parameters are actually @@ -447,7 +447,6 @@ let constants_sandbox = }; issuance_weights; blocks_preservation_cycles = 1; - consensus_rights_delay = 2; delegate_parameters_activation_delay = 2; blocks_per_cycle = 8l; blocks_per_commitment = 4l; @@ -486,7 +485,6 @@ let constants_test = }; }; issuance_weights; - consensus_rights_delay = 2; delegate_parameters_activation_delay = 3; blocks_preservation_cycles = 1; blocks_per_cycle = 12l; diff --git a/src/proto_alpha/lib_protocol/delegate_sampler.ml b/src/proto_alpha/lib_protocol/delegate_sampler.ml index b271dec004aa..39dffc1f2851 100644 --- a/src/proto_alpha/lib_protocol/delegate_sampler.ml +++ b/src/proto_alpha/lib_protocol/delegate_sampler.ml @@ -63,6 +63,13 @@ module Delegate_sampler_state = struct let id = identifier_of_cycle cycle in let*? ctxt = Cache.update ctxt id None in Storage.Delegate_sampler_state.remove_existing ctxt cycle + + let remove ctxt cycle = + let open Lwt_result_syntax in + let id = identifier_of_cycle cycle in + let*? ctxt = Cache.update ctxt id None in + let*! ctxt = Storage.Delegate_sampler_state.remove ctxt cycle in + return ctxt end module Random = struct @@ -303,6 +310,21 @@ let attesting_rights_count ctxt level = (ctxt, Signature.Public_key_hash.Map.empty) slots +let cleanup_values_for_protocol_t ctxt ~previous_consensus_rights_delay + ~consensus_rights_delay ~new_cycle = + let open Lwt_result_syntax in + assert ( + Compare.Int.(consensus_rights_delay <= previous_consensus_rights_delay)) ; + if Compare.Int.(consensus_rights_delay = previous_consensus_rights_delay) then + return ctxt + else + let start_cycle = Cycle_repr.add new_cycle (consensus_rights_delay + 1) in + let end_cycle = Cycle_repr.add new_cycle previous_consensus_rights_delay in + List.fold_left_es + Delegate_sampler_state.remove + ctxt + Cycle_repr.(start_cycle ---> end_cycle) + module For_RPC = struct let delegate_current_baking_power ctxt delegate = let open Lwt_result_syntax in diff --git a/src/proto_alpha/lib_protocol/delegate_sampler.mli b/src/proto_alpha/lib_protocol/delegate_sampler.mli index 6dd5bd5f9adc..3163ad43ba44 100644 --- a/src/proto_alpha/lib_protocol/delegate_sampler.mli +++ b/src/proto_alpha/lib_protocol/delegate_sampler.mli @@ -97,6 +97,13 @@ val attesting_rights_count : level, all bakers were allowed (and expected) to attest. *) val check_all_bakers_attest_at_level : Raw_context.t -> Level_repr.t -> bool +val cleanup_values_for_protocol_t : + Raw_context.t -> + previous_consensus_rights_delay:int -> + consensus_rights_delay:int -> + new_cycle:Cycle_repr.t -> + Raw_context.t tzresult Lwt.t + module For_RPC : sig (** The baking power for a given delegate computed from its current stake. *) diff --git a/src/proto_alpha/lib_protocol/init_storage.ml b/src/proto_alpha/lib_protocol/init_storage.ml index 788d4eec5b99..a143951d0803 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml @@ -126,6 +126,34 @@ let prepare ctxt ~level ~predecessor_timestamp ~timestamp = (* Please add here any code that should be removed at the next automatic protocol snapshot *) +let cleanup_values_for_protocol_t ctxt + (previous_proto_constants : Constants_parametric_previous_repr.t) level = + let open Lwt_result_syntax in + let previous_consensus_rights_delay = + previous_proto_constants.consensus_rights_delay + in + let consensus_rights_delay = Constants_storage.consensus_rights_delay ctxt in + let new_cycle = + let next_level = Raw_level_repr.succ level in + let cycle_eras = Raw_context.cycle_eras ctxt in + (Level_repr.level_from_raw ~cycle_eras next_level).cycle + in + let* ctxt = + Stake_storage.cleanup_values_for_protocol_t + ctxt + ~previous_consensus_rights_delay + ~consensus_rights_delay + ~new_cycle + in + let* ctxt = + Delegate_sampler.cleanup_values_for_protocol_t + ctxt + ~previous_consensus_rights_delay + ~consensus_rights_delay + ~new_cycle + in + return ctxt + (* End of code to remove at next automatic protocol snapshot *) let prepare_first_block chain_id ctxt ~typecheck_smart_contract @@ -235,6 +263,14 @@ let prepare_first_block chain_id ctxt ~typecheck_smart_contract let* ctxt = Sc_rollup_refutation_storage.migrate_clean_refutation_games ctxt in + let* ctxt = + match previous_proto_constants with + | Some previous_proto_constants -> + cleanup_values_for_protocol_t ctxt previous_proto_constants level + | None -> + (* this can happen iff the previous protocol is Genesis *) + return ctxt + in return (ctxt, []) (* End of alpha predecessor stitching. Comment used for automatic snapshot *) in diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index ec2b289a4d2d..124d483d7dbe 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -1574,7 +1574,7 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = } in let ({ - consensus_rights_delay; + consensus_rights_delay = _; blocks_preservation_cycles; delegate_parameters_activation_delay; tolerated_inactivity_period; @@ -1676,6 +1676,7 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = ~new_blocks_per_commitment:blocks_per_commitment else return ctxt in + let consensus_rights_delay = 1 in let constants = { Constants_parametric_repr.consensus_rights_delay; diff --git a/src/proto_alpha/lib_protocol/stake_storage.ml b/src/proto_alpha/lib_protocol/stake_storage.ml index ae0b66580201..3d26864c0a30 100644 --- a/src/proto_alpha/lib_protocol/stake_storage.ml +++ b/src/proto_alpha/lib_protocol/stake_storage.ml @@ -71,6 +71,15 @@ module Selected_distribution_for_cycle = struct let id = identifier_of_cycle cycle in let*? ctxt = Cache.update ctxt id None in Storage.Stake.Selected_distribution_for_cycle.remove_existing ctxt cycle + + let remove ctxt cycle = + let open Lwt_result_syntax in + let id = identifier_of_cycle cycle in + let*? ctxt = Cache.update ctxt id None in + let*! ctxt = + Storage.Stake.Selected_distribution_for_cycle.remove ctxt cycle + in + return ctxt end let get_full_staking_balance = Storage.Stake.Staking_balance.get @@ -277,6 +286,25 @@ let add_contract_delegated_stake ctxt contract amount = | None -> return ctxt | Some delegate -> add_delegated_stake ctxt delegate amount +let cleanup_values_for_protocol_t ctxt ~previous_consensus_rights_delay + ~consensus_rights_delay ~new_cycle = + let open Lwt_result_syntax in + assert ( + Compare.Int.(consensus_rights_delay <= previous_consensus_rights_delay)) ; + if Compare.Int.(consensus_rights_delay = previous_consensus_rights_delay) then + return ctxt + else + let start_cycle = Cycle_repr.add new_cycle (consensus_rights_delay + 1) in + let end_cycle = Cycle_repr.add new_cycle previous_consensus_rights_delay in + List.fold_left_es + (fun ctxt cycle_to_clear -> + let*! ctxt = + Storage.Stake.Total_active_stake.remove ctxt cycle_to_clear + in + Selected_distribution_for_cycle.remove ctxt cycle_to_clear) + ctxt + Cycle_repr.(start_cycle ---> end_cycle) + module For_RPC = struct let get_staking_balance ctxt delegate = let open Lwt_result_syntax in diff --git a/src/proto_alpha/lib_protocol/stake_storage.mli b/src/proto_alpha/lib_protocol/stake_storage.mli index 5dbf028bbc7b..0863b260dc7e 100644 --- a/src/proto_alpha/lib_protocol/stake_storage.mli +++ b/src/proto_alpha/lib_protocol/stake_storage.mli @@ -143,6 +143,13 @@ val add_contract_delegated_stake : val remove_contract_delegated_stake : Raw_context.t -> Contract_repr.t -> Tez_repr.t -> Raw_context.t tzresult Lwt.t +val cleanup_values_for_protocol_t : + Raw_context.t -> + previous_consensus_rights_delay:int -> + consensus_rights_delay:int -> + new_cycle:Cycle_repr.t -> + Raw_context.t tzresult Lwt.t + module For_RPC : sig val get_staking_balance : Raw_context.t -> Signature.Public_key_hash.t -> Tez_repr.t tzresult Lwt.t -- GitLab From 467328da0023ee75853c45caf107515af549f2e1 Mon Sep 17 00:00:00 2001 From: Marina Polubelova Date: Mon, 21 Jul 2025 16:08:41 +0200 Subject: [PATCH 02/13] Proto: update number of cycles stored in cache --- .../lib_parameters/default_parameters.ml | 14 +++++++++----- src/proto_alpha/lib_protocol/raw_context.ml | 10 ++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/proto_alpha/lib_parameters/default_parameters.ml b/src/proto_alpha/lib_parameters/default_parameters.ml index 1dd40aa83282..b8dc5a2ae602 100644 --- a/src/proto_alpha/lib_parameters/default_parameters.ml +++ b/src/proto_alpha/lib_parameters/default_parameters.ml @@ -379,11 +379,15 @@ let constants_mainnet : Constants.Parametric.t = 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 = 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 = 5; + consensus_rights_delay + slashing_delay + 2 = 1 + 1 + 2 = 4 + currently. + + Last updated in protocol T. *) + cache_stake_distribution_cycles = 4; + (* One for the sampler state for all cycles stored at any moment (as above). + + Last updated in protocol T. *) + cache_sampler_state_cycles = 4; dal = default_dal; sc_rollup; zk_rollup = diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 124d483d7dbe..7f5c3f767f27 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -1611,8 +1611,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 = _; @@ -1716,8 +1716,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.slashing_delay + 2; + cache_sampler_state_cycles = + consensus_rights_delay + Constants_repr.slashing_delay + 2; dal; sc_rollup; zk_rollup; -- GitLab From 475aa77250fb20e96ed9199a6f41aa0bed116c1c Mon Sep 17 00:00:00 2001 From: mattiasdrp Date: Tue, 22 Jul 2025 10:46:46 +0200 Subject: [PATCH 03/13] Profiling: Update proto alpha patch --- scripts/profile_alpha.patch | 42 +++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/scripts/profile_alpha.patch b/scripts/profile_alpha.patch index c1c154251162..f657cff9505c 100644 --- a/scripts/profile_alpha.patch +++ b/scripts/profile_alpha.patch @@ -1,22 +1,22 @@ -From 48b33e443cd2a4fed3b16a34ef34e664be1d68a9 Mon Sep 17 00:00:00 2001 +From 3f9052a5dc75bd64a628b7c99d9b8f8f1f8184f8 Mon Sep 17 00:00:00 2001 From: mattiasdrp -Date: Wed, 2 Jul 2025 11:29:00 +0200 -Subject: [PATCH] Patch alpha +Date: Tue, 22 Jul 2025 10:42:38 +0200 +Subject: [PATCH] Apply proto alpha profiling --- src/lib_protocol_environment/sigs/v15.in.ml | 2 + - src/lib_protocol_environment/sigs/v15.ml | 80 ++++++++++++++----- - .../sigs/v15/profiler.mli | 36 +++++++++ + src/lib_protocol_environment/sigs/v15.ml | 82 ++++++++++++++----- + .../sigs/v15/profiler.mli | 36 ++++++++ src/proto_alpha/lib_protocol/apply.ml | 17 ++-- src/proto_alpha/lib_protocol/baking.ml | 4 +- .../lib_protocol/delegate_cycles.ml | 78 ++++++++++++++---- src/proto_alpha/lib_protocol/dune | 2 + - src/proto_alpha/lib_protocol/init_storage.ml | 36 +++++++-- + src/proto_alpha/lib_protocol/init_storage.ml | 36 ++++++-- src/proto_alpha/lib_protocol/raw_context.ml | 13 +-- - src/proto_alpha/lib_protocol/script_cache.ml | 19 ++--- + src/proto_alpha/lib_protocol/script_cache.ml | 19 +++-- .../lib_protocol/script_interpreter.ml | 11 +-- - .../lib_protocol/script_ir_translator.ml | 40 +++++----- - 12 files changed, 253 insertions(+), 85 deletions(-) + .../lib_protocol/script_ir_translator.ml | 40 +++++---- + 12 files changed, 254 insertions(+), 86 deletions(-) create mode 100644 src/lib_protocol_environment/sigs/v15/profiler.mli diff --git a/src/lib_protocol_environment/sigs/v15.in.ml b/src/lib_protocol_environment/sigs/v15.in.ml @@ -33,7 +33,7 @@ index e86731c9cb..05291026e6 100644 module Context_hash : [%sig "v15/context_hash.mli"] diff --git a/src/lib_protocol_environment/sigs/v15.ml b/src/lib_protocol_environment/sigs/v15.ml -index f412c985e9..313466717b 100644 +index f412c985e9..437c499bb4 100644 --- a/src/lib_protocol_environment/sigs/v15.ml +++ b/src/lib_protocol_environment/sigs/v15.ml @@ -10060,6 +10060,48 @@ end @@ -256,6 +256,14 @@ index f412c985e9..313466717b 100644 module Riscv : sig +@@ -12850,6 +12892,6 @@ val bytes_to_output_proof : bytes -> (output_proof, string) result + + val get_current_level : state -> int32 option Lwt.t + end +-# 146 "v15.in.ml" ++# 148 "v15.in.ml" + + end diff --git a/src/lib_protocol_environment/sigs/v15/profiler.mli b/src/lib_protocol_environment/sigs/v15/profiler.mli new file mode 100644 index 0000000000..3dc7a1c702 @@ -480,10 +488,10 @@ index 1a34312188..4cb8b2b008 100644 (flags (:standard) diff --git a/src/proto_alpha/lib_protocol/init_storage.ml b/src/proto_alpha/lib_protocol/init_storage.ml -index 788d4eec5b..13fbcf3ca2 100644 +index 229b019310..b30eadacec 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml -@@ -218,31 +218,55 @@ let prepare_first_block chain_id ctxt ~typecheck_smart_contract +@@ -256,22 +256,38 @@ let prepare_first_block chain_id ctxt ~typecheck_smart_contract (* Start of Alpha stitching. Comment used for automatic snapshot *) | Alpha -> let* ctxt = @@ -524,7 +532,9 @@ index 788d4eec5b..13fbcf3ca2 100644 + {verbosity = Notice} + "Sc_rollup_refutation_storage.migrate_clean_refutation_games"]) in - return (ctxt, []) + let* ctxt = + cleanup_values_for_protocol_t ctxt previous_proto_constants level +@@ -280,10 +296,18 @@ let prepare_first_block chain_id ctxt ~typecheck_smart_contract (* End of alpha predecessor stitching. Comment used for automatic snapshot *) in let* ctxt = @@ -546,10 +556,10 @@ index 788d4eec5b..13fbcf3ca2 100644 in return ctxt diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml -index 919dcfc69a..21e4fdb63f 100644 +index 17391ebd9d..a58a971293 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml -@@ -1608,12 +1608,13 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = +@@ -1723,12 +1723,13 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = (* End of alpha predecessor stitching. Comment used for automatic snapshot *) in let+ ctxt = @@ -696,5 +706,5 @@ index 6f1d8b6bee..43f5715b4a 100644 let parse_view ~elab_conf ctxt ty view = parse_view ~unparse_code_rec ~elab_conf ctxt ty view -- -2.50.0 +2.50.1 -- GitLab From 9c5775fd10474f03fa1143976e304df57bf8bc77 Mon Sep 17 00:00:00 2001 From: Marina Polubelova Date: Wed, 23 Jul 2025 14:43:03 +0200 Subject: [PATCH 04/13] Tezt/Tests: reset regressions --- ...client) RPC regression tests- adaptive_issuance.out | 4 ---- ...- (mode client) RPC regression tests- delegates.out | 4 ++-- ...ode client) RPC regression tests- misc_protocol.out | 10 +++++----- ... light) RPC regression tests- adaptive_issuance.out | 4 ---- ...a- (mode light) RPC regression tests- delegates.out | 4 ++-- ...mode light) RPC regression tests- misc_protocol.out | 10 +++++----- ... proxy) RPC regression tests- adaptive_issuance.out | 4 ---- ...a- (mode proxy) RPC regression tests- delegates.out | 4 ++-- ...mode proxy) RPC regression tests- misc_protocol.out | 10 +++++----- ... Test following dal and baker tutorial commands.out | 2 +- ...esting DAL node (attesters receive DAL rewards).out | 4 ++-- .../weeklynet.ml/Alpha- weeklynet regression test.out | 6 +++--- tezt/tests/weeklynet_configs/alpha.json | 6 +++--- 13 files changed, 30 insertions(+), 42 deletions(-) diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- adaptive_issuance.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- adaptive_issuance.out index 1210015efe52..9fb0b2d56b73 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- adaptive_issuance.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- adaptive_issuance.out @@ -43,10 +43,6 @@ "attesting_reward_per_slot": "2343", "seed_nonce_revelation_tip": "234", "vdf_revelation_tip": "234", "dal_attesting_reward_per_shard": "520" }, { "cycle": 1, "baking_reward_fixed_portion": "300010", - "baking_reward_bonus_per_slot": "1171", - "attesting_reward_per_slot": "2343", "seed_nonce_revelation_tip": "234", - "vdf_revelation_tip": "234", "dal_attesting_reward_per_shard": "520" }, - { "cycle": 2, "baking_reward_fixed_portion": "300010", "baking_reward_bonus_per_slot": "1171", "attesting_reward_per_slot": "2343", "seed_nonce_revelation_tip": "234", "vdf_revelation_tip": "234", "dal_attesting_reward_per_shard": "520" } ] diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- delegates.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- delegates.out index cbaa5f5251f3..99040169f154 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- delegates.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- delegates.out @@ -27,7 +27,7 @@ { "expected_assigned_shards_per_slot": 409, "delegate_attested_dal_slots": 0, "delegate_attestable_dal_slots": 0, "expected_dal_rewards": "212680", "sufficient_dal_participation": true, - "denounced": false }, "grace_period": 4, + "denounced": false }, "grace_period": 3, "active_staking_parameters": { "limit_of_staking_over_baking_millionth": 0, "edge_of_baking_over_staking_billionth": 1000000000 }, @@ -73,7 +73,7 @@ false [ "[PUBLIC_KEY_HASH]" ] ./octez-client rpc get '/chains/main/blocks/head/context/delegates/[PUBLIC_KEY_HASH]/grace_period' -4 +3 ./octez-client rpc get '/chains/main/blocks/head/context/delegates/[PUBLIC_KEY_HASH]/staking_balance' "4000000000000" 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 4871384b903c..9904784dacc8 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 @@ -9,7 +9,7 @@ "slashing_delay": 1, "smart_rollup_max_wrapped_proof_binary_size": 30000, "smart_rollup_message_size_limit": 4096, "smart_rollup_max_number_of_messages_per_level": "1000000", - "consensus_rights_delay": 2, "blocks_preservation_cycles": 1, + "consensus_rights_delay": 1, "blocks_preservation_cycles": 1, "delegate_parameters_activation_delay": 2, "tolerated_inactivity_period": 2, "blocks_per_cycle": 8, "blocks_per_commitment": 4, "nonce_revelation_threshold": 4, @@ -36,8 +36,8 @@ "percentage_of_frozen_deposits_slashed_per_double_baking": 500, "max_slashing_per_block": 10000, "max_slashing_threshold": { "numerator": 1, "denominator": 3 }, - "cache_script_size": 100000000, "cache_stake_distribution_cycles": 5, - "cache_sampler_state_cycles": 5, + "cache_script_size": 100000000, "cache_stake_distribution_cycles": 4, + "cache_sampler_state_cycles": 4, "dal_parametric": { "feature_enable": true, "incentives_enable": true, "number_of_slots": 16, "attestation_lag": 8, @@ -82,8 +82,8 @@ "direct_ticket_spending_enable": false, "aggregate_attestation": true, "allow_tz4_delegate_enable": true, "all_bakers_attest_activation_level": null, - "issuance_modification_delay": 2, "consensus_key_activation_delay": 2, - "unstake_finalization_delay": 3 } + "issuance_modification_delay": 1, "consensus_key_activation_delay": 1, + "unstake_finalization_delay": 2 } ./octez-client rpc get /chains/main/blocks/head/helpers/baking_rights [ { "level": 2, "delegate": "[PUBLIC_KEY_HASH]", diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- adaptive_issuance.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- adaptive_issuance.out index cc06794cf3d6..3415cd6047a4 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- adaptive_issuance.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- adaptive_issuance.out @@ -43,10 +43,6 @@ "attesting_reward_per_slot": "2343", "seed_nonce_revelation_tip": "234", "vdf_revelation_tip": "234", "dal_attesting_reward_per_shard": "520" }, { "cycle": 1, "baking_reward_fixed_portion": "300010", - "baking_reward_bonus_per_slot": "1171", - "attesting_reward_per_slot": "2343", "seed_nonce_revelation_tip": "234", - "vdf_revelation_tip": "234", "dal_attesting_reward_per_shard": "520" }, - { "cycle": 2, "baking_reward_fixed_portion": "300010", "baking_reward_bonus_per_slot": "1171", "attesting_reward_per_slot": "2343", "seed_nonce_revelation_tip": "234", "vdf_revelation_tip": "234", "dal_attesting_reward_per_shard": "520" } ] diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- delegates.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- delegates.out index 8bb3a697b4a0..69f51408067c 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- delegates.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- delegates.out @@ -27,7 +27,7 @@ { "expected_assigned_shards_per_slot": 409, "delegate_attested_dal_slots": 0, "delegate_attestable_dal_slots": 0, "expected_dal_rewards": "212680", "sufficient_dal_participation": true, - "denounced": false }, "grace_period": 4, + "denounced": false }, "grace_period": 3, "active_staking_parameters": { "limit_of_staking_over_baking_millionth": 0, "edge_of_baking_over_staking_billionth": 1000000000 }, @@ -73,7 +73,7 @@ false [ "[PUBLIC_KEY_HASH]" ] ./octez-client --mode light rpc get '/chains/main/blocks/head/context/delegates/[PUBLIC_KEY_HASH]/grace_period' -4 +3 ./octez-client --mode light rpc get '/chains/main/blocks/head/context/delegates/[PUBLIC_KEY_HASH]/staking_balance' "4000000000000" 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 2dafb6179857..a2347b6aa68c 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 @@ -9,7 +9,7 @@ "slashing_delay": 1, "smart_rollup_max_wrapped_proof_binary_size": 30000, "smart_rollup_message_size_limit": 4096, "smart_rollup_max_number_of_messages_per_level": "1000000", - "consensus_rights_delay": 2, "blocks_preservation_cycles": 1, + "consensus_rights_delay": 1, "blocks_preservation_cycles": 1, "delegate_parameters_activation_delay": 2, "tolerated_inactivity_period": 2, "blocks_per_cycle": 8, "blocks_per_commitment": 4, "nonce_revelation_threshold": 4, @@ -36,8 +36,8 @@ "percentage_of_frozen_deposits_slashed_per_double_baking": 500, "max_slashing_per_block": 10000, "max_slashing_threshold": { "numerator": 1, "denominator": 3 }, - "cache_script_size": 100000000, "cache_stake_distribution_cycles": 5, - "cache_sampler_state_cycles": 5, + "cache_script_size": 100000000, "cache_stake_distribution_cycles": 4, + "cache_sampler_state_cycles": 4, "dal_parametric": { "feature_enable": true, "incentives_enable": true, "number_of_slots": 16, "attestation_lag": 8, @@ -82,8 +82,8 @@ "direct_ticket_spending_enable": false, "aggregate_attestation": true, "allow_tz4_delegate_enable": true, "all_bakers_attest_activation_level": null, - "issuance_modification_delay": 2, "consensus_key_activation_delay": 2, - "unstake_finalization_delay": 3 } + "issuance_modification_delay": 1, "consensus_key_activation_delay": 1, + "unstake_finalization_delay": 2 } ./octez-client --mode light rpc get /chains/main/blocks/head/helpers/baking_rights [ { "level": 2, "delegate": "[PUBLIC_KEY_HASH]", diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- adaptive_issuance.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- adaptive_issuance.out index 23e1a11df8b5..72d5fdab114a 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- adaptive_issuance.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- adaptive_issuance.out @@ -43,10 +43,6 @@ "attesting_reward_per_slot": "2343", "seed_nonce_revelation_tip": "234", "vdf_revelation_tip": "234", "dal_attesting_reward_per_shard": "520" }, { "cycle": 1, "baking_reward_fixed_portion": "300010", - "baking_reward_bonus_per_slot": "1171", - "attesting_reward_per_slot": "2343", "seed_nonce_revelation_tip": "234", - "vdf_revelation_tip": "234", "dal_attesting_reward_per_shard": "520" }, - { "cycle": 2, "baking_reward_fixed_portion": "300010", "baking_reward_bonus_per_slot": "1171", "attesting_reward_per_slot": "2343", "seed_nonce_revelation_tip": "234", "vdf_revelation_tip": "234", "dal_attesting_reward_per_shard": "520" } ] diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- delegates.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- delegates.out index 1f9cd7583277..3bf5048ed0f0 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- delegates.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- delegates.out @@ -27,7 +27,7 @@ { "expected_assigned_shards_per_slot": 409, "delegate_attested_dal_slots": 0, "delegate_attestable_dal_slots": 0, "expected_dal_rewards": "212680", "sufficient_dal_participation": true, - "denounced": false }, "grace_period": 4, + "denounced": false }, "grace_period": 3, "active_staking_parameters": { "limit_of_staking_over_baking_millionth": 0, "edge_of_baking_over_staking_billionth": 1000000000 }, @@ -73,7 +73,7 @@ false [ "[PUBLIC_KEY_HASH]" ] ./octez-client --mode proxy rpc get '/chains/main/blocks/head/context/delegates/[PUBLIC_KEY_HASH]/grace_period' -4 +3 ./octez-client --mode proxy rpc get '/chains/main/blocks/head/context/delegates/[PUBLIC_KEY_HASH]/staking_balance' "4000000000000" 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 32577a8b1e51..f476c821cab0 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 @@ -9,7 +9,7 @@ "slashing_delay": 1, "smart_rollup_max_wrapped_proof_binary_size": 30000, "smart_rollup_message_size_limit": 4096, "smart_rollup_max_number_of_messages_per_level": "1000000", - "consensus_rights_delay": 2, "blocks_preservation_cycles": 1, + "consensus_rights_delay": 1, "blocks_preservation_cycles": 1, "delegate_parameters_activation_delay": 2, "tolerated_inactivity_period": 2, "blocks_per_cycle": 8, "blocks_per_commitment": 4, "nonce_revelation_threshold": 4, @@ -36,8 +36,8 @@ "percentage_of_frozen_deposits_slashed_per_double_baking": 500, "max_slashing_per_block": 10000, "max_slashing_threshold": { "numerator": 1, "denominator": 3 }, - "cache_script_size": 100000000, "cache_stake_distribution_cycles": 5, - "cache_sampler_state_cycles": 5, + "cache_script_size": 100000000, "cache_stake_distribution_cycles": 4, + "cache_sampler_state_cycles": 4, "dal_parametric": { "feature_enable": true, "incentives_enable": true, "number_of_slots": 16, "attestation_lag": 8, @@ -82,8 +82,8 @@ "direct_ticket_spending_enable": false, "aggregate_attestation": true, "allow_tz4_delegate_enable": true, "all_bakers_attest_activation_level": null, - "issuance_modification_delay": 2, "consensus_key_activation_delay": 2, - "unstake_finalization_delay": 3 } + "issuance_modification_delay": 1, "consensus_key_activation_delay": 1, + "unstake_finalization_delay": 2 } ./octez-client --mode proxy rpc get /chains/main/blocks/head/helpers/baking_rights [ { "level": 2, "delegate": "[PUBLIC_KEY_HASH]", diff --git a/tezt/tests/expected/dal.ml/Alpha- Test following dal and baker tutorial commands.out b/tezt/tests/expected/dal.ml/Alpha- Test following dal and baker tutorial commands.out index 4db253ad35ec..02e16155dd64 100644 --- a/tezt/tests/expected/dal.ml/Alpha- Test following dal and baker tutorial commands.out +++ b/tezt/tests/expected/dal.ml/Alpha- Test following dal and baker tutorial commands.out @@ -121,7 +121,7 @@ This sequence of operations was run: { "expected_assigned_shards_per_slot": 0, "delegate_attested_dal_slots": 0, "delegate_attestable_dal_slots": 0, "expected_dal_rewards": "0", "sufficient_dal_participation": false, - "denounced": false }, "grace_period": 4, + "denounced": false }, "grace_period": 3, "active_staking_parameters": { "limit_of_staking_over_baking_millionth": 0, "edge_of_baking_over_staking_billionth": 1000000000 }, diff --git a/tezt/tests/expected/dal.ml/Alpha- Testing DAL node (attesters receive DAL rewards).out b/tezt/tests/expected/dal.ml/Alpha- Testing DAL node (attesters receive DAL rewards).out index d12758bb4e67..f9981c3c1459 100644 --- a/tezt/tests/expected/dal.ml/Alpha- Testing DAL node (attesters receive DAL rewards).out +++ b/tezt/tests/expected/dal.ml/Alpha- Testing DAL node (attesters receive DAL rewards).out @@ -75,7 +75,7 @@ } GET http://[HOST]:[PORT]/chains/main/blocks/head/context/issuance/expected_issuance 200 OK -[{"cycle":0,"baking_reward_fixed_portion":"300010","baking_reward_bonus_per_slot":"1171","attesting_reward_per_slot":"2343","seed_nonce_revelation_tip":"234","vdf_revelation_tip":"234","dal_attesting_reward_per_shard":"520"},{"cycle":1,"baking_reward_fixed_portion":"300010","baking_reward_bonus_per_slot":"1171","attesting_reward_per_slot":"2343","seed_nonce_revelation_tip":"234","vdf_revelation_tip":"234","dal_attesting_reward_per_shard":"520"},{"cycle":2,"baking_reward_fixed_portion":"300010","baking_reward_bonus_per_slot":"1171","attesting_reward_per_slot":"2343","seed_nonce_revelation_tip":"234","vdf_revelation_tip":"234","dal_attesting_reward_per_shard":"520"}] +[{"cycle":0,"baking_reward_fixed_portion":"300010","baking_reward_bonus_per_slot":"1171","attesting_reward_per_slot":"2343","seed_nonce_revelation_tip":"234","vdf_revelation_tip":"234","dal_attesting_reward_per_shard":"520"},{"cycle":1,"baking_reward_fixed_portion":"300010","baking_reward_bonus_per_slot":"1171","attesting_reward_per_slot":"2343","seed_nonce_revelation_tip":"234","vdf_revelation_tip":"234","dal_attesting_reward_per_shard":"520"}] GET http://[HOST]:[PORT]/chains/main/blocks/head~1/context/delegates/[PUBLIC_KEY_HASH]/dal_participation 200 OK @@ -134,7 +134,7 @@ GET http://[HOST]:[PORT]/chains/main/blocks/head~1/context/delegates/[PUBLIC_KEY } GET http://[HOST]:[PORT]/chains/main/blocks/head/context/issuance/expected_issuance 200 OK -[{"cycle":1,"baking_reward_fixed_portion":"300010","baking_reward_bonus_per_slot":"1171","attesting_reward_per_slot":"2343","seed_nonce_revelation_tip":"234","vdf_revelation_tip":"234","dal_attesting_reward_per_shard":"520"},{"cycle":2,"baking_reward_fixed_portion":"300010","baking_reward_bonus_per_slot":"1171","attesting_reward_per_slot":"2343","seed_nonce_revelation_tip":"234","vdf_revelation_tip":"234","dal_attesting_reward_per_shard":"520"},{"cycle":3,"baking_reward_fixed_portion":"7847","baking_reward_bonus_per_slot":"30","attesting_reward_per_slot":"61","seed_nonce_revelation_tip":"6","vdf_revelation_tip":"6","dal_attesting_reward_per_shard":"13"}] +[{"cycle":1,"baking_reward_fixed_portion":"300010","baking_reward_bonus_per_slot":"1171","attesting_reward_per_slot":"2343","seed_nonce_revelation_tip":"234","vdf_revelation_tip":"234","dal_attesting_reward_per_shard":"520"},{"cycle":2,"baking_reward_fixed_portion":"7847","baking_reward_bonus_per_slot":"30","attesting_reward_per_slot":"61","seed_nonce_revelation_tip":"6","vdf_revelation_tip":"6","dal_attesting_reward_per_shard":"13"}] GET http://[HOST]:[PORT]/chains/main/blocks/head~1/context/delegates/[PUBLIC_KEY_HASH]/dal_participation 200 OK diff --git a/tezt/tests/expected/weeklynet.ml/Alpha- weeklynet regression test.out b/tezt/tests/expected/weeklynet.ml/Alpha- weeklynet regression test.out index 04c6f5f3518e..acabb8617dab 100644 --- a/tezt/tests/expected/weeklynet.ml/Alpha- weeklynet regression test.out +++ b/tezt/tests/expected/weeklynet.ml/Alpha- weeklynet regression test.out @@ -1,6 +1,6 @@ ./octez-client rpc get /chains/main/blocks/head/context/constants/parametric -{ "consensus_rights_delay": 2, "blocks_preservation_cycles": 1, +{ "consensus_rights_delay": 1, "blocks_preservation_cycles": 1, "delegate_parameters_activation_delay": 3, "tolerated_inactivity_period": 1, "blocks_per_cycle": 200, "blocks_per_commitment": 25, "nonce_revelation_threshold": 50, @@ -26,8 +26,8 @@ "percentage_of_frozen_deposits_slashed_per_double_baking": 700, "max_slashing_per_block": 10000, "max_slashing_threshold": { "numerator": 1, "denominator": 3 }, - "cache_script_size": 100000000, "cache_stake_distribution_cycles": 5, - "cache_sampler_state_cycles": 5, + "cache_script_size": 100000000, "cache_stake_distribution_cycles": 4, + "cache_sampler_state_cycles": 4, "dal_parametric": { "feature_enable": true, "incentives_enable": false, "number_of_slots": 32, "attestation_lag": 8, diff --git a/tezt/tests/weeklynet_configs/alpha.json b/tezt/tests/weeklynet_configs/alpha.json index cb3dc432970a..9307da346edf 100644 --- a/tezt/tests/weeklynet_configs/alpha.json +++ b/tezt/tests/weeklynet_configs/alpha.json @@ -21,7 +21,7 @@ "4000000000000" ] ], - "consensus_rights_delay": 2, + "consensus_rights_delay": 1, "blocks_preservation_cycles": 1, "delegate_parameters_activation_delay": 3, "tolerated_inactivity_period": 1, @@ -69,8 +69,8 @@ "denominator": 3 }, "cache_script_size": 100000000, - "cache_stake_distribution_cycles": 5, - "cache_sampler_state_cycles": 5, + "cache_stake_distribution_cycles": 4, + "cache_sampler_state_cycles": 4, "dal_parametric": { "feature_enable": true, "incentives_enable": false, -- GitLab From 4bcf02366beb9ec7fceba20c7732d639a85dc427 Mon Sep 17 00:00:00 2001 From: Marina Polubelova Date: Wed, 23 Jul 2025 16:08:00 +0200 Subject: [PATCH 05/13] Tezt/Tests: update tests with consensus_rights_delay = 1 --- tezt/tests/adaptive_issuance.ml | 12 ++++++++--- tezt/tests/protocol_migration.ml | 34 ++++++++++++-------------------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/tezt/tests/adaptive_issuance.ml b/tezt/tests/adaptive_issuance.ml index 5a651dc24ab9..aeaea17f10b6 100644 --- a/tezt/tests/adaptive_issuance.ml +++ b/tezt/tests/adaptive_issuance.ml @@ -318,6 +318,12 @@ let test_staking = in let* _proto_hash, endpoint, client_1, node_1 = init ~overrides protocol in + let* constants = + Client.RPC.call client_1 @@ RPC.get_chain_block_context_constants () + in + let consensus_rights_delay = + JSON.(constants |-> "consensus_rights_delay" |> as_int) + in let* eosod = edge_of_staking_over_delegation client_1 in @@ -686,7 +692,7 @@ let test_staking = let* () = bake_n ~endpoint ~protocol client_1 1 in let* () = - repeat 7 (fun () -> + repeat 5 (fun () -> let* () = bake_n ~endpoint ~protocol client_1 1 in let* b0 = check_and_return_balances ~check:!balances0 staker0 in let* b1 = check_and_return_balances ~check:!balances1 staker1 in @@ -804,7 +810,7 @@ let test_staking = Client.spawn_unstake (Tez.of_int 500000) ~staker:staker0.alias client_1 in - let* _ = Helpers.bake_n_cycles bake 2 client_1 in + let* _ = Helpers.bake_n_cycles bake consensus_rights_delay client_1 in let* () = Process.check ~expect_failure:false unstake0 in @@ -1001,7 +1007,7 @@ let test_staking = let amount_slashed_from_baker_deposits = match eosod with | 2 -> 10_049_764_326 - | 3 -> 10_049_764_732 + | 3 -> if consensus_rights_delay = 1 then 10_049_761_010 else 10_049_764_732 | _ -> Test.fail "Unexpected edge_of_staking_over_baking value: %d" eosod in diff --git a/tezt/tests/protocol_migration.ml b/tezt/tests/protocol_migration.ml index e44545d87ec5..968c7740672a 100644 --- a/tezt/tests/protocol_migration.ml +++ b/tezt/tests/protocol_migration.ml @@ -1388,15 +1388,21 @@ let test_unstaked_requests_many_delegates () = let expected_list = (* unstaked_frozen_balance =?= 0 *) match target_cycle with + (* D0 unstakes in C0: D0 unstaked_frozen <> 0 *) | 1 -> List.init 6 (fun i -> if i = 0 then false else true) + (* D1 unstakes in C1: D0, D1 unstaked_frozen <> 0 *) | 2 -> List.init 6 (fun i -> if i <= 1 then false else true) + (* D2 unstakes in C2: D0, D1, D2 unstaked_frozen <> 0 *) | 3 -> List.init 6 (fun i -> if i <= 2 then false else true) + (* D3 unstakes in C3: D1, D2, D3 unstaked_frozen <> 0; D0 unstaked_frozen = 0 *) | 4 -> List.init 6 (fun i -> if 1 <= i && i <= 3 then false else true) - | 5 -> List.init 6 (fun i -> if 2 <= i && i <= 4 then false else true) - | 6 -> List.init 6 (fun i -> if 3 <= i then false else true) - | 7 -> List.init 6 (fun i -> if 4 <= i then false else true) - | 8 -> List.init 6 (fun i -> if i = 5 then false else true) - | 9 -> List.init 6 (fun _i -> true) + (* D4 unstakes in C4: D3, D4 unstaked_frozen <> 0; D0, D1, D2 unstaked_frozen = 0 *) + | 5 -> List.init 6 (fun i -> if 3 <= i && i <= 4 then false else true) + (* D5 unstakes in C5: D4, D5 unstaked_frozen <> 0; D0, D1, D2, D3 unstaked_frozen = 0 *) + | 6 -> List.init 6 (fun i -> if 4 <= i then false else true) + (* D5 unstaked_frozen <> 0; D0, D1, D2, D3, D4 unstaked_frozen = 0 *) + | 7 -> List.init 6 (fun i -> if 5 <= i then false else true) + | 8 -> List.init 6 (fun _i -> true) | _ -> failwith "unexpected input" in let* () = @@ -1418,8 +1424,8 @@ let test_unstaked_requests_many_delegates () = else unit in unit) - (* From cycle 1 to 9 *) - (List.init 9 (fun i -> i + 1)) + (* From cycle 1 to 8 *) + (List.init 8 (fun i -> i + 1)) in unit @@ -1586,20 +1592,6 @@ let test_unstaked_requests_and_min_delegated () = ~target_cycle:5 ~delegate:default_baker ~check_last_block:(fun _ -> unit) - ~check_next_block:(fun _ -> - let* _ = Local_helpers.unstake_requests ~staker:delegate_0 client in - Local_helpers.check_is_finalizable_all_requests - ~staker:delegate_0 - ~expected:false - client) - client - in - let* () = - bake_until_cycle_with_and_check - ~bakers:[default_baker] - ~target_cycle:6 - ~delegate:default_baker - ~check_last_block:(fun _ -> unit) ~check_next_block:(fun _ -> let* _ = Local_helpers.unstake_requests ~staker:delegate_0 client in Local_helpers.check_is_finalizable_all_requests -- GitLab From 29f44d421d53440f7f797d7a2940e4e41df2d1b2 Mon Sep 17 00:00:00 2001 From: Marina Polubelova Date: Wed, 23 Jul 2025 16:22:10 +0200 Subject: [PATCH 06/13] etherlink/tezt/tests: reset regressions --- ...he FA deposit and withdrawal events (with revm).out | 10 +++++----- ...n test for the FA deposit and withdrawal events.out | 10 +++++----- ...st for the claimed FA deposit event (with revm).out | 2 +- ...egression test for the claimed FA deposit event.out | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/etherlink/tezt/tests/expected/evm_sequencer.ml/Alpha- Regression test for the FA deposit and withdrawal events (with revm).out b/etherlink/tezt/tests/expected/evm_sequencer.ml/Alpha- Regression test for the FA deposit and withdrawal events (with revm).out index 858ec1dc643f..de0dbaf70919 100644 --- a/etherlink/tezt/tests/expected/evm_sequencer.ml/Alpha- Regression test for the FA deposit and withdrawal events (with revm).out +++ b/etherlink/tezt/tests/expected/evm_sequencer.ml/Alpha- Regression test for the FA deposit and withdrawal events (with revm).out @@ -3,19 +3,19 @@ Address: 0x0000000000000000000000000000000000000000 Topics: - 0x7ee7a1de9c18ce695c95b8b19fbdf26cce3544e3ca9e08c9f487776783d7599f -- 0xe93ef5b0cbe6d2f5a9e220560f624fc9bad80ba85e0742e65bf17dfebcf4f333 +- 0x1260a8e6705d5b2c0ffcb2f6403873322b8c183a61e390190227eb54836726dd Data: 0x0000000000000000000000006ce4d79d4e77402e1ef3417fdda433aa744c6e1c0000000000000000000000006ce4d79d4e77402e1ef3417fdda433aa744c6e1c000000000000000000000000000000000000000000000000000000000000002a00000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000002 # FA Withdrawal ## Log 0 Address: 0xff00000000000000000000000000000000000002 Topics: - 0xab68450c9e546f6062a861eebf8ec5bbd41b4425e26b20199c91227c7f9038ca -- 0xe93ef5b0cbe6d2f5a9e220560f624fc9bad80ba85e0742e65bf17dfebcf4f333 -Data: 0x0000000000000000000000006ce4d79d4e77402e1ef3417fdda433aa744c6e1c0000000000000000000000006ce4d79d4e77402e1ef3417fdda433aa744c6e1c0000000000000000000000000000000000000000000000000000000000000000011fbd55a114875a8ee4ef81e5f43509ebdafc8ddc000000000000000000000000000000000000000000000000000000000000000000000000000000000000280000000000000000000000000000000000000000000000000000000000000000 +- 0x1260a8e6705d5b2c0ffcb2f6403873322b8c183a61e390190227eb54836726dd +Data: 0x0000000000000000000000006ce4d79d4e77402e1ef3417fdda433aa744c6e1c0000000000000000000000006ce4d79d4e77402e1ef3417fdda433aa744c6e1c00000000000000000000000000000000000000000000000000000000000000000180e5787d88921e91f5cfa294502fc82e8650f893000000000000000000000000000000000000000000000000000000000000000000000000000000000000280000000000000000000000000000000000000000000000000000000000000000 # FA Fast Withdrawal ## Log 0 Address: 0xff00000000000000000000000000000000000002 Topics: - 0x7e40c982e82bccb5e8bbd29f38bcfa3996f341ef9f51e2a9cffe086ec87a11c7 -- 0xe93ef5b0cbe6d2f5a9e220560f624fc9bad80ba85e0742e65bf17dfebcf4f333 -Data: 0x0000000000000000000000006ce4d79d4e77402e1ef3417fdda433aa744c6e1c0000000000000000000000006ce4d79d4e77402e1ef3417fdda433aa744c6e1c0000c55cf02dbeecc978d9c84625dcae72bb77ea4fbd00000000000000000000011fbd55a114875a8ee4ef81e5f43509ebdafc8ddc000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000005e0be103000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001 +- 0x1260a8e6705d5b2c0ffcb2f6403873322b8c183a61e390190227eb54836726dd +Data: 0x0000000000000000000000006ce4d79d4e77402e1ef3417fdda433aa744c6e1c0000000000000000000000006ce4d79d4e77402e1ef3417fdda433aa744c6e1c0000c55cf02dbeecc978d9c84625dcae72bb77ea4fbd000000000000000000000180e5787d88921e91f5cfa294502fc82e8650f893000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000005e0be103000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001 diff --git a/etherlink/tezt/tests/expected/evm_sequencer.ml/Alpha- Regression test for the FA deposit and withdrawal events.out b/etherlink/tezt/tests/expected/evm_sequencer.ml/Alpha- Regression test for the FA deposit and withdrawal events.out index f17331f4f3ac..c8a3097e87e4 100644 --- a/etherlink/tezt/tests/expected/evm_sequencer.ml/Alpha- Regression test for the FA deposit and withdrawal events.out +++ b/etherlink/tezt/tests/expected/evm_sequencer.ml/Alpha- Regression test for the FA deposit and withdrawal events.out @@ -3,19 +3,19 @@ Address: 0x0000000000000000000000000000000000000000 Topics: - 0x7ee7a1de9c18ce695c95b8b19fbdf26cce3544e3ca9e08c9f487776783d7599f -- 0xe93ef5b0cbe6d2f5a9e220560f624fc9bad80ba85e0742e65bf17dfebcf4f333 +- 0x1260a8e6705d5b2c0ffcb2f6403873322b8c183a61e390190227eb54836726dd Data: 0x0000000000000000000000006ce4d79d4e77402e1ef3417fdda433aa744c6e1c0000000000000000000000006ce4d79d4e77402e1ef3417fdda433aa744c6e1c000000000000000000000000000000000000000000000000000000000000002a00000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000002 # FA Withdrawal ## Log 0 Address: 0xff00000000000000000000000000000000000002 Topics: - 0xab68450c9e546f6062a861eebf8ec5bbd41b4425e26b20199c91227c7f9038ca -- 0xe93ef5b0cbe6d2f5a9e220560f624fc9bad80ba85e0742e65bf17dfebcf4f333 -Data: 0x0000000000000000000000006ce4d79d4e77402e1ef3417fdda433aa744c6e1c0000000000000000000000006ce4d79d4e77402e1ef3417fdda433aa744c6e1c0000000000000000000000000000000000000000000000000000000000000000011fbd55a114875a8ee4ef81e5f43509ebdafc8ddc000000000000000000000000000000000000000000000000000000000000000000000000000000000000280000000000000000000000000000000000000000000000000000000000000000 +- 0x1260a8e6705d5b2c0ffcb2f6403873322b8c183a61e390190227eb54836726dd +Data: 0x0000000000000000000000006ce4d79d4e77402e1ef3417fdda433aa744c6e1c0000000000000000000000006ce4d79d4e77402e1ef3417fdda433aa744c6e1c00000000000000000000000000000000000000000000000000000000000000000180e5787d88921e91f5cfa294502fc82e8650f893000000000000000000000000000000000000000000000000000000000000000000000000000000000000280000000000000000000000000000000000000000000000000000000000000000 # FA Fast Withdrawal ## Log 0 Address: 0xff00000000000000000000000000000000000002 Topics: - 0x477f545a1f30cd1fb89c51ee4fa67e3a56a1e37e3d742b84f6ce73ad6e33451f -- 0xe93ef5b0cbe6d2f5a9e220560f624fc9bad80ba85e0742e65bf17dfebcf4f333 -Data: 0x0000000000000000000000006ce4d79d4e77402e1ef3417fdda433aa744c6e1c0000000000000000000000006ce4d79d4e77402e1ef3417fdda433aa744c6e1c0000c55cf02dbeecc978d9c84625dcae72bb77ea4fbd00000000000000000000011fbd55a114875a8ee4ef81e5f43509ebdafc8ddc000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000005e0be103000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001 +- 0x1260a8e6705d5b2c0ffcb2f6403873322b8c183a61e390190227eb54836726dd +Data: 0x0000000000000000000000006ce4d79d4e77402e1ef3417fdda433aa744c6e1c0000000000000000000000006ce4d79d4e77402e1ef3417fdda433aa744c6e1c0000c55cf02dbeecc978d9c84625dcae72bb77ea4fbd000000000000000000000180e5787d88921e91f5cfa294502fc82e8650f893000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000005e0be103000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001 diff --git a/etherlink/tezt/tests/expected/evm_sequencer.ml/Alpha- Regression test for the claimed FA deposit event (with revm).out b/etherlink/tezt/tests/expected/evm_sequencer.ml/Alpha- Regression test for the claimed FA deposit event (with revm).out index 3cb7dc069bea..6644fdcbd0ab 100644 --- a/etherlink/tezt/tests/expected/evm_sequencer.ml/Alpha- Regression test for the claimed FA deposit event (with revm).out +++ b/etherlink/tezt/tests/expected/evm_sequencer.ml/Alpha- Regression test for the claimed FA deposit event (with revm).out @@ -3,5 +3,5 @@ Address: 0xff00000000000000000000000000000000000002 Topics: - 0x7ee7a1de9c18ce695c95b8b19fbdf26cce3544e3ca9e08c9f487776783d7599f -- 0x2aa47038ff901ed93fb2e4f6596a02d55a9d42ad6dae6e09fe4d0f69e7940b53 +- 0xef624bac0d0b6887cc4578f36ebb87d0dc8a9c4e017d6152af09e15403aa1894 Data: 0x00000000000000000000000092e791df3dd5a8704f0e7d9b3003a0627d95d01700000000000000000000000092e791df3dd5a8704f0e7d9b3003a0627d95d017000000000000000000000000000000000000000000000000000000000000003200000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000003 diff --git a/etherlink/tezt/tests/expected/evm_sequencer.ml/Alpha- Regression test for the claimed FA deposit event.out b/etherlink/tezt/tests/expected/evm_sequencer.ml/Alpha- Regression test for the claimed FA deposit event.out index 58e38ea12470..bbcf4847fa44 100644 --- a/etherlink/tezt/tests/expected/evm_sequencer.ml/Alpha- Regression test for the claimed FA deposit event.out +++ b/etherlink/tezt/tests/expected/evm_sequencer.ml/Alpha- Regression test for the claimed FA deposit event.out @@ -3,5 +3,5 @@ Address: 0x0000000000000000000000000000000000000000 Topics: - 0x7ee7a1de9c18ce695c95b8b19fbdf26cce3544e3ca9e08c9f487776783d7599f -- 0x2aa47038ff901ed93fb2e4f6596a02d55a9d42ad6dae6e09fe4d0f69e7940b53 +- 0xef624bac0d0b6887cc4578f36ebb87d0dc8a9c4e017d6152af09e15403aa1894 Data: 0x00000000000000000000000092e791df3dd5a8704f0e7d9b3003a0627d95d01700000000000000000000000092e791df3dd5a8704f0e7d9b3003a0627d95d017000000000000000000000000000000000000000000000000000000000000003200000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000003 -- GitLab From e8e9aed0a85a70b3f7df51e72bad314a227c31e1 Mon Sep 17 00:00:00 2001 From: Marina Polubelova Date: Mon, 28 Jul 2025 11:30:38 +0200 Subject: [PATCH 07/13] Proto/Tests: properly compute minimal requirements to determine frozen_rights Co-authored-by: Diane Gallois-Wong --- .../test/helpers/state_account.ml | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/helpers/state_account.ml b/src/proto_alpha/lib_protocol/test/helpers/state_account.ml index 88e3cf3c382c..82b7bf1a1de0 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/state_account.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/state_account.ml @@ -404,13 +404,6 @@ let compute_future_frozen_rights block account_map = CycleMap.find (Block.current_cycle block) acc.frozen_rights |> Option.value ~default:Tez.zero in - let current_rights_state = - if - Tez.( - current_rights_state < block.constants.minimal_frozen_stake) - then Tez.zero - else current_rights_state - in let* current_rights_rpc = Context.Delegate.initial_frozen_deposits (B block) acc.pkh in @@ -429,13 +422,27 @@ let compute_future_frozen_rights block account_map = current_cycle (block.constants.consensus_rights_delay + 1) in - let frozen_rights = - CycleMap.add - future_cycle - (current_total_frozen_deposits_with_limits acc) - acc.frozen_rights + let total_staked_after_limits = + current_total_frozen_deposits_with_limits acc in - return (String.Map.add key {acc with frozen_rights} acc_map) + let* current_baking_power = + Context.get_current_baking_power (B block) acc.pkh + in + let total_baking_power = Tez.of_mutez current_baking_power in + if + Tez.( + total_staked_after_limits + >= block.constants.minimal_frozen_stake + && total_baking_power >= block.constants.minimal_stake) + then + let frozen_rights = + CycleMap.add + future_cycle + total_staked_after_limits + acc.frozen_rights + in + return (String.Map.add key {acc with frozen_rights} acc_map) + else return acc_map else return acc_map) account_map account_map -- GitLab From 6b60aa1b7a8db81b80b76ce5cecb60d585d88067 Mon Sep 17 00:00:00 2001 From: Marina Polubelova Date: Thu, 24 Jul 2025 11:45:43 +0200 Subject: [PATCH 08/13] Proto/Tests: update tests with consensus_rights_delay = 1 Co-authored-by: Diane Gallois-Wong --- .../test/integration/test_scenario_rewards.ml | 32 +++++++++++-------- .../integration/test_scenario_slashing.ml | 14 ++++---- .../test/integration/test_scenario_stake.ml | 13 +++----- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/integration/test_scenario_rewards.ml b/src/proto_alpha/lib_protocol/test/integration/test_scenario_rewards.ml index 2d12a8ba91b9..d3b93fe20133 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_scenario_rewards.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_scenario_rewards.ml @@ -456,12 +456,12 @@ let test_overstake = begin_test_with_rewards_checks ~init_limit:3. --> next_block_with_check_rewards ~loc:__LOC__ - ~staker_diff:(Q.of_int32 30_516l) - ~delegate_diff:(Q.of_int32 141_452l) + ~staker_diff:(Q.of_int32 30_503l) + ~delegate_diff:(Q.of_int32 141_060l) --> next_block_with_check_rewards ~loc:__LOC__ - ~staker_diff:(Q.of_int32 30_516l) - ~delegate_diff:(Q.of_int32 141_452l) + ~staker_diff:(Q.of_int32 30_503l) + ~delegate_diff:(Q.of_int32 141_060l) --> add_account_with_funds "staker2" ~funder:"faucet" @@ -471,30 +471,34 @@ let test_overstake = --> next_block_with_check_rewards ~loc:__LOC__ ~staker_diff: - (Q.make (Z.of_int64 123_818_187_500_000L) (Z.of_int64 6_937_492_371L)) - (* = 12466.3429088 *) - ~delegate_diff:(Q.of_int32 118_425l) + (Q.make + (Z.of_int64 494_662_250_000_000L) + (Z.of_int64 27_749_969_497L)) + (* = 17825.68626079 *) + ~delegate_diff:(Q.of_int32 118_086l) --> check_overstaked_status ~loc:__LOC__ ~expected:false "delegate" --> stake "staker2" (Amount (Tez.of_mutez 300_000_000_000L)) --> check_overstaked_status ~loc:__LOC__ ~expected:true "delegate" --> next_block_with_check_rewards ~loc:__LOC__ ~staker_diff: - (Q.make (Z.of_int64 89_477_100_000_000L) (Z.of_int64 7_912_488_031L)) - (* = 7898.71925 *) - ~delegate_diff:(Q.of_int32 107_480l) + (Q.make + (Z.of_int64 3_570_648_000_000_000L) + (Z.of_int64 316_499_521_483L)) + (* = 11281.68530325 *) + ~delegate_diff:(Q.of_int32 107_227l) --> set_edge 0.8 --> wait_delegate_parameters_activation --> set_delegate "staker2" (Some "faucet") --> check_overstaked_status ~loc:__LOC__ ~expected:false "delegate" --> next_block_with_check_rewards ~loc:__LOC__ - ~staker_diff:(Q.of_int32 34_603l) - ~delegate_diff:(Q.of_int32 452_898l) + ~staker_diff:(Q.of_int32 34_634l) + ~delegate_diff:(Q.of_int32 452_382l) --> wait_n_cycles_f Test_scenario_stake.unstake_wait --> next_block_with_check_rewards ~loc:__LOC__ - ~staker_diff:(Q.of_int32 17_858l) - ~delegate_diff:(Q.of_int32 233_748l) + ~staker_diff:(Q.of_int32 17_889l) + ~delegate_diff:(Q.of_int32 233_679l) let tests = tests_of_scenarios diff --git a/src/proto_alpha/lib_protocol/test/integration/test_scenario_slashing.ml b/src/proto_alpha/lib_protocol/test/integration/test_scenario_slashing.ml index d112f5179af5..18ebb91e9bb2 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_scenario_slashing.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_scenario_slashing.ml @@ -324,12 +324,14 @@ let test_slash_timing = --> exclude_bakers ["delegate"] --> make_denunciations () |+ Tag "without another slash" --> Empty) + --> next_cycle + (* Stake again to ensure that [delegate] has sufficient current + stake to get unforbidden, see the comment in + Protocol.Forbidden_delegates_storage.should_unforbid. *) --> stake "delegate" Half - --> List.fold_left - (fun acc i -> - acc |+ Tag (string_of_int i ^ " cycles lag") --> wait_n_cycles i) - wait_for_slashing - [3; 4; 5; 6] + --> list_map_branched [0; 1; 2; 3; 4] (fun i -> + let i = Protocol.Constants_repr.slashing_delay + i in + Tag (string_of_int i ^ " cycles lag") --> wait_n_cycles i) --> double_bake "delegate" --> exclude_bakers ["delegate"] --> make_denunciations () --> next_cycle @@ -589,7 +591,7 @@ let test_mega_slash = because of the slash that happens before rights computation, which puts it under the minimal frozen threshold required to bake. *) --> wait_n_cycles_f (fun (_, state) -> - state.State.constants.consensus_rights_delay + 2) + state.State.constants.consensus_rights_delay + 1) --> check_has_no_slots ~loc:__LOC__ "delegate" --> next_cycle --> check_has_slots ~loc:__LOC__ "delegate" diff --git a/src/proto_alpha/lib_protocol/test/integration/test_scenario_stake.ml b/src/proto_alpha/lib_protocol/test/integration/test_scenario_stake.ml index 80fe96ee5ab0..a23da1da42ae 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_scenario_stake.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_scenario_stake.ml @@ -150,7 +150,7 @@ let shorter_roundtrip_for_baker = let unstake_amount = Amount (Tez.of_mutez 222_000_000_000L) in let consensus_rights_delay = Default_parameters.constants_mainnet.consensus_rights_delay - (* mainnet value, = 2 *) + (* mainnet value, = 1 *) in let init_params = {limit_of_staking_over_baking = Q.one; edge_of_baking_over_staking = Q.one} @@ -180,14 +180,11 @@ let shorter_roundtrip_for_baker = (* We unstake to have an amount in the last container for ufd *) --> unstake "delegate" unstake_amount --> next_cycle - (* We unstake either one, two or three cycles later *) - --> (Tag "unstake cycle (current-2)" + (* We unstake either one or two cycles later *) + --> (Tag "unstake cycle (current-1)" --> unstake "delegate" unstake_amount - --> next_cycle --> next_cycle - |+ Tag "unstake cycle (current-1)" --> next_cycle - --> unstake "delegate" unstake_amount - --> next_cycle - |+ Tag "unstake cycle (current)" --> next_cycle --> next_cycle + --> next_cycle + |+ Tag "unstake cycle (current)" --> next_cycle --> unstake "delegate" unstake_amount) (* Nothing is finalizable yet. If nothing else happens, next cycle the first unstake request will become finalizable. *) -- GitLab From ece08857d09d5a568f31a1584774cbd5f18711f7 Mon Sep 17 00:00:00 2001 From: Marina Polubelova Date: Mon, 28 Jul 2025 16:06:17 +0200 Subject: [PATCH 09/13] Tezt/Tests: add protocol migration test for consensus_rights_delay shortening --- tezt/tests/protocol_migration.ml | 129 ++++++++++++++++++++++++++++++- 1 file changed, 128 insertions(+), 1 deletion(-) diff --git a/tezt/tests/protocol_migration.ml b/tezt/tests/protocol_migration.ml index 968c7740672a..c23e10539476 100644 --- a/tezt/tests/protocol_migration.ml +++ b/tezt/tests/protocol_migration.ml @@ -1960,6 +1960,132 @@ let test_tz4_manager_operation ~with_empty_mempool = else Test.fail "Reveal of tz4 account is not included in the block: %s" receipt +let test_consensus_rights_delay_shortening () = + let migrate_from = Option.get Protocol.(previous_protocol Alpha) in + let migrate_to = Protocol.Alpha in + + let check_baking_rights_rpc ~expect_failure ~cycle client = + let*? process = + Client.RPC.spawn client + @@ RPC.get_chain_block_helper_baking_rights ~cycle () + in + let* () = Process.check ~expect_failure process in + Log.info + ~color:Log.Color.FG.green + "Checked the baking rights for cycle = %s (expect_failure = %s)" + (Int.to_string cycle) + (Bool.to_string expect_failure) ; + unit + in + let check_baking_rights nb_cycles_to_check ?nb_cycles_is_valid client = + let* level = + Client.RPC.call client @@ RPC.get_chain_block_helper_current_level () + in + let nb_cycles_is_valid = + Option.value ~default:nb_cycles_to_check nb_cycles_is_valid + in + Lwt_list.iter_s + (fun cycle -> + let expect_failure = cycle > level.cycle + nb_cycles_is_valid in + check_baking_rights_rpc ~expect_failure ~cycle client) + (range level.cycle (level.cycle + nb_cycles_to_check)) + in + + let parameters = JSON.parse_file (Protocol.parameter_file migrate_to) in + let blocks_per_cycle = JSON.(get "blocks_per_cycle" parameters |> as_int) in + for migration_level = blocks_per_cycle to 2 * blocks_per_cycle do + Test.register + ~__FILE__ + ~title: + (Printf.sprintf + "protocol migration for consensus_rights_delay shortening at level \ + %d" + migration_level) + ~tags:["protocol"; "migration"; "consensus_rights_delay"] + @@ fun () -> + let parameter_file = Protocol.parameter_file migrate_from in + let old_parameters = JSON.parse_file parameter_file in + let* client, _node = + Local_helpers.activate_protocol + ~parameter_file + ~migrate_from + ~migrate_to + ~migration_level + in + let consensus_rights_delay = + JSON.(get "consensus_rights_delay" parameters |> as_int) + in + let old_consensus_rights_delay = + JSON.(get "consensus_rights_delay" old_parameters |> as_int) + in + Log.info + ~color:Log.Color.FG.green + "blocks_per_cycle = %d, old_consensus_rights_delay = %d, \ + consensus_rights_delay = %d, migration_level = %d" + blocks_per_cycle + old_consensus_rights_delay + consensus_rights_delay + migration_level ; + + Log.info + ~color:Log.Color.FG.blue + "Checking baking rights before the migration" ; + let* () = + check_baking_rights + old_consensus_rights_delay + ~nb_cycles_is_valid:old_consensus_rights_delay + client + in + let* () = Client.bake_until_level ~target_level:migration_level client in + Log.info ~color:Log.Color.FG.green "Checking migration block consistency" ; + let* () = + block_check + ~expected_block_type:`Migration + client + ~migrate_from + ~migrate_to + in + let* () = Client.bake_for_and_wait client in + Log.info + ~color:Log.Color.FG.green + "Checking post-migration block consistency (first block of new protocol \ + %s)." + (Protocol.name migrate_to) ; + let* () = + block_check + ~expected_block_type:`Non_migration + client + ~migrate_from + ~migrate_to + in + Log.info + ~color:Log.Color.FG.blue + "Checking baking rights just after the migration" ; + let* () = + check_baking_rights + old_consensus_rights_delay + ~nb_cycles_is_valid:consensus_rights_delay + client + in + (* Test that we can still bake after migration *) + let* () = + repeat + ((consensus_rights_delay + 2) * blocks_per_cycle) + (fun () -> Client.bake_for_and_wait client) + in + Log.info + ~color:Log.Color.FG.blue + "Checking baking rights after %d cycles after the migration" + (consensus_rights_delay + 2) ; + let* () = + check_baking_rights + old_consensus_rights_delay + ~nb_cycles_is_valid:consensus_rights_delay + client + in + unit + done + let register ~migrate_from ~migrate_to = test_migration_for_whole_cycle ~migrate_from ~migrate_to ; test_migration_with_bakers ~migrate_from ~migrate_to () ; @@ -1970,4 +2096,5 @@ let register ~migrate_from ~migrate_to = test_unstaked_requests_and_min_delegated () ; test_reveal_migration () ; test_tz4_manager_operation ~with_empty_mempool:true ; - test_tz4_manager_operation ~with_empty_mempool:false + test_tz4_manager_operation ~with_empty_mempool:false ; + test_consensus_rights_delay_shortening () -- GitLab From f62c1f9efe5a93020a5f1a87517ce6003039250c Mon Sep 17 00:00:00 2001 From: Marina Polubelova Date: Mon, 28 Jul 2025 16:07:36 +0200 Subject: [PATCH 10/13] Docs: update changelog --- docs/protocols/alpha.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/protocols/alpha.rst b/docs/protocols/alpha.rst index 00e43065de3a..2dacfb89f203 100644 --- a/docs/protocols/alpha.rst +++ b/docs/protocols/alpha.rst @@ -74,6 +74,15 @@ Protocol parameters from 300 blocks to 150 blocks. Reduced accordingly the VDF difficulty (``vdf_difficulty``) as well. (:gl:`!17583`) +- Lowered the ``consensus_rights_delay`` protocol constant from 2 + cycles to 1 cycle. (MR :gl:`!18783`) + +- Reduced the ``cache_stake_distribution_cycles`` and + ``cache_sampler_state_cycles`` protocol constants from 5 cycles to 4 + cycles, in order to reduce memory consumption. Only + ``consensus_rights_delay + slashing_delay + 2 = 1 + 1 + 2 = 4`` + cycles are needed. (MR :gl:`!18783`) + Bug Fixes --------- -- GitLab From 5787ce002c98871958ca7bacb658f8f3445752ed Mon Sep 17 00:00:00 2001 From: Marina Polubelova Date: Tue, 29 Jul 2025 17:24:20 +0200 Subject: [PATCH 11/13] Docs/Alpha: update docs with consensus_rights_delay = 1 cycle --- docs/alpha/adaptive_issuance.rst | 4 ++-- docs/alpha/baking_power.rst | 14 +++++++------- docs/alpha/consensus.rst | 12 ++++++------ docs/alpha/proof_of_stake.rst | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/alpha/adaptive_issuance.rst b/docs/alpha/adaptive_issuance.rst index 05100a590f81..d147836979f1 100644 --- a/docs/alpha/adaptive_issuance.rst +++ b/docs/alpha/adaptive_issuance.rst @@ -49,7 +49,7 @@ Adaptive issuance rate ---------------------- The adaptive issuance rate determines, at the end -of cycle :math:`\IL{c}`, the issuance for cycle :math:`\IL{c + 3}`. The +of cycle :math:`\IL{c}`, the issuance for cycle :math:`\IL{c + 2}`. The adaptive issuance rate is the sum of a :ref:`static rate ` and a :ref:`dynamic rate `. This value is kept within a minimal and a maximal value, to ensure nominal emissions remain within @@ -72,7 +72,7 @@ Where: - ``issuance_modification_delay`` is a :ref:`derived protocol constant` which is set to the same value as ``CONSENSUS_RIGHTS_DELAY`` (see :ref:`active_stake_alpha`), that - is, 2 cycles. + is, 1 cycle. - ``total_supply(cycle)`` returns the total supply of tez at the end of the given ``cycle``. - ``total_frozen_stake(cycle)`` returns the total frozen stake at the given ``cycle``. diff --git a/docs/alpha/baking_power.rst b/docs/alpha/baking_power.rst index dc6ef947edef..3a6837cd00c6 100644 --- a/docs/alpha/baking_power.rst +++ b/docs/alpha/baking_power.rst @@ -41,16 +41,16 @@ Overview At the end of :ref:`cycle` ``n`` (that is, the beginning of cycle ``n + 1``), the protocol :doc:`randomly generates` the baking rights for cycle ``n + -1 + CONSENSUS_RIGHTS_DELAY = n + 3``, using the **current baking +1 + CONSENSUS_RIGHTS_DELAY = n + 2``, using the **current baking power** as the weight for each delegate that meets the :ref:`requirements`. (``CONSENSUS_RIGHTS_DELAY -= 2`` is a :ref:`protocol constant`.) += 1`` is a :ref:`protocol constant`.) The ``.../delegates//baking_power`` RPC can be used to retrieve the current baking power of a delegate, that is, its baking power as of the end of the requested block ```` (see the note above on RPC paths). Therefore, the baking power used for the -rights of cycle ``n + 3`` is the one returned by this RPC called on +rights of cycle ``n + 2`` is the one returned by this RPC called on the last block of cycle ``n``. The baking power of a delegate is defined as: @@ -230,14 +230,14 @@ For a given delegate, we define the following: Min-delegated-in-current-cycle ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -When computing baking rights for cycle ``n + 3`` at the end of cycle +When computing baking rights for cycle ``n + 2`` at the end of cycle ``n``, the ``total_delegated`` value used for each delegate is actually the **minimum** of its ``total_delegated`` **over the whole cycle** ``n``, called ``min_delegated_in_current_cycle``. The purpose of this mechanism is to prevent any manipulation of baking rights through short-duration transfers. (Note that such a mechanism is not needed for staked tez because they are inherently :ref:`frozen for at -least four cycles`, so short-duration +least three cycles`, so short-duration staking is already not possible.) Since the Paris protocol, the considered minimum is the minimum at any @@ -276,7 +276,7 @@ those of the ```` in the RPC path; it also returns the earliest level at the end of which this minimum has been reached in the current cycle. This means that calling the RPC on the last block of cycle ``n`` returns the value actually used during the generation -of baking rights for cycle ``n + 3``. +of baking rights for cycle ``n + 2``. Example @@ -492,4 +492,4 @@ are :ref:`protocol constants`. If any of these conditions is not met at the end of cycle ``n``, the delegate still has a *baking power* as computed above, but receives no *baking -rights* at all for cycle ``n + 3``. +rights* at all for cycle ``n + 2``. diff --git a/docs/alpha/consensus.rst b/docs/alpha/consensus.rst index 7fa87459863c..19689de4d3e9 100644 --- a/docs/alpha/consensus.rst +++ b/docs/alpha/consensus.rst @@ -155,9 +155,9 @@ formula`. The baking rights are determined :ref:`CONSENSUS_RIGHTS_DELAY` in advance, which is -currently ``2`` :ref:`cycles`. More +currently ``1`` :ref:`cycle`. More precisely, at the end of cycle ``n`` and beginning of cycle ``n+1``, -the baking rights for cycle ``n+1+CONSENSUS_RIGHTS_DELAY=n+3`` are +the baking rights for cycle ``n+1+CONSENSUS_RIGHTS_DELAY=n+2`` are :doc:`randomly generated` based on the current :doc:`baking power` of each delegate that meets the :ref:`minimal power and own staked @@ -386,7 +386,7 @@ Consensus related protocol parameters * - ``DELAY_INCREMENT_PER_ROUND`` - 4s * - ``CONSENSUS_RIGHTS_DELAY`` - - 2 cycles + - 1 cycle * - ``GLOBAL_LIMIT_OF_STAKING_OVER_BAKING`` - 9 * - ``LIMIT_OF_DELEGATION_OVER_BAKING`` @@ -402,11 +402,11 @@ Consensus related protocol parameters * - ``SLASHING_DELAY`` - 1 cycle * - ``CONSENSUS_KEY_ACTIVATION_DELAY`` [#derived_cs]_ - - 2 cycles + - 1 cycle * - ``ISSUANCE_MODIFICATION_DELAY`` [#derived_cs]_ - - 2 cycles + - 1 cycle * - ``UNSTAKE_FINALIZATION_DELAY`` [#derived_cs+sd]_ - - 3 cycles + - 2 cycles The above list of protocol parameters is a subset of the :ref:`protocol constants `. diff --git a/docs/alpha/proof_of_stake.rst b/docs/alpha/proof_of_stake.rst index 67c8200643a9..2310401d0e4d 100644 --- a/docs/alpha/proof_of_stake.rst +++ b/docs/alpha/proof_of_stake.rst @@ -187,7 +187,7 @@ Proof-of-stake parameters * - ``BLOCKS_PER_CYCLE`` - 1800 blocks * - ``CONSENSUS_RIGHTS_DELAY`` - - 2 cycles + - 1 cycle * - ``MINIMAL_STAKE`` - 6,000 ꜩ * - ``MINIMAL_FROZEN_STAKE`` -- GitLab From 949d2b8960f6bdff077686d7f732fcec44569e90 Mon Sep 17 00:00:00 2001 From: Marina Polubelova Date: Wed, 30 Jul 2025 17:47:49 +0200 Subject: [PATCH 12/13] Tezt/Tests/DAL: increase blocks per cycle in `dal attester with baker daemon` scenario --- tezt/tests/dal.ml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tezt/tests/dal.ml b/tezt/tests/dal.ml index 47ebb6ff20a8..3afbbc106e54 100644 --- a/tezt/tests/dal.ml +++ b/tezt/tests/dal.ml @@ -686,12 +686,12 @@ let scenario_with_layer1_node ?attestation_threshold ?regression ?(tags = []) let scenario_with_layer1_and_dal_nodes ?regression ?(tags = []) ?(uses = fun _ -> []) ?custom_constants ?minimal_block_delay - ?delay_increment_per_round ?redundancy_factor ?slot_size ?number_of_shards - ?number_of_slots ?attestation_lag ?attestation_threshold ?traps_fraction - ?commitment_period ?challenge_window ?(dal_enable = true) ?incentives_enable - ?dal_rewards_weight ?activation_timestamp ?bootstrap_profile - ?event_sections_levels ?operator_profiles ?history_mode ?prover - ?l1_history_mode ?wait_ready ?env ?disable_shard_validation + ?blocks_per_cycle ?delay_increment_per_round ?redundancy_factor ?slot_size + ?number_of_shards ?number_of_slots ?attestation_lag ?attestation_threshold + ?traps_fraction ?commitment_period ?challenge_window ?(dal_enable = true) + ?incentives_enable ?dal_rewards_weight ?activation_timestamp + ?bootstrap_profile ?event_sections_levels ?operator_profiles ?history_mode + ?prover ?l1_history_mode ?wait_ready ?env ?disable_shard_validation ?disable_amplification ?ignore_pkhs variant scenario = let description = "Testing DAL node" in let tags = if List.mem team tags then tags else team :: tags in @@ -712,6 +712,7 @@ let scenario_with_layer1_and_dal_nodes ?regression ?(tags = []) ~custom_constants ?minimal_block_delay ?delay_increment_per_round + ?blocks_per_cycle ?redundancy_factor ?slot_size ?number_of_slots @@ -11200,6 +11201,10 @@ let register ~protocols = ~activation_timestamp:Now ~number_of_slots:8 ~operator_profiles:[0; 1; 2; 3; 4; 5; 6; 7] + (* when consensus_rights_delay = 1 and attestation_lag = 16, + blocks_per_cycle must be at least 16: + attestation_lag <= consensus_rights_delay * blocks_per_cycle *) + ~blocks_per_cycle:16 "dal attester with baker daemon" test_attester_with_daemon protocols ; -- GitLab From 07decff3231e3392e6132b2d151c413cfa92bcc3 Mon Sep 17 00:00:00 2001 From: Marina Polubelova Date: Wed, 30 Jul 2025 18:00:24 +0200 Subject: [PATCH 13/13] Tezt/Tests/DAL: attestation rewards = 0 if nonce is not revealed --- tezt/tests/dal.ml | 58 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/tezt/tests/dal.ml b/tezt/tests/dal.ml index 3afbbc106e54..76e8aaf92fd8 100644 --- a/tezt/tests/dal.ml +++ b/tezt/tests/dal.ml @@ -10365,7 +10365,7 @@ let create_account_and_reveal ?source ~amount ~alias client = - No delegates are denounced (there is no accuser running actually). - The attestable slots field of /dal_participation's result is equal to the number of attested slots counted in blocks metadata. *) -let test_dal_rewards_distribution _protocol dal_parameters cryptobox node client +let test_dal_rewards_distribution protocol dal_parameters cryptobox node client _dal_node = let* proto_params = Node.RPC.call node @@ RPC.get_chain_block_context_constants () @@ -10727,14 +10727,15 @@ let test_dal_rewards_distribution _protocol dal_parameters cryptobox node client account.Account.public_key_hash in let* l = - Lwt.all + Lwt_list.map_s + participation [ - participation baker; - participation attesting_dal_slot_10; - participation not_attesting_at_all; - participation not_attesting_dal; - participation not_sufficiently_attesting_dal_slot_10; - participation small_baker; + baker; + attesting_dal_slot_10; + not_attesting_at_all; + not_attesting_dal; + not_sufficiently_attesting_dal_slot_10; + small_baker; ] in match l with @@ -10753,13 +10754,32 @@ let test_dal_rewards_distribution _protocol dal_parameters cryptobox node client (* We now bake the last block of the cycle, which should trigger TB and DAL rewards distribution. TB rewards are actually set to 0. *) let* () = bake_for ~delegates:(`For [baker.Account.public_key_hash]) client in - let* _json = Node.RPC.(call node @@ get_chain_block_metadata_raw ()) in + let* metadata = Node.RPC.(call node @@ get_chain_block_metadata_raw ()) in incr level ; let* current_level = Node.RPC.call node @@ RPC.get_chain_block_helper_current_level () in assert (current_level.cycle_position = blocks_per_cycle - 1) ; + let balance_updates = JSON.(metadata |-> "balance_updates" |> as_list) in + let expected_to_lose_attesting_rewards = + if Protocol.number protocol >= 023 then + (* keep those that lost consensus attesting rewards because they haven't + revealed their nonces *) + List.filter_map + (fun json -> + let check json = + JSON.(json |-> "kind" |> as_string) |> String.equal "burned" + && JSON.(json |-> "category" |> as_string) + |> String.equal "lost attesting rewards" + && (not JSON.(json |-> "participation" |> as_bool)) + && JSON.(json |-> "revelation" |> as_bool) + in + if check json then Some JSON.(json |-> "delegate" |> as_string) + else None) + balance_updates + else [] + in (* We snapshot the balances of the delegates at the end of the cycle. *) let* ( _baker_bal2, attesting_dal_slot_10_bal2, @@ -10880,22 +10900,28 @@ let test_dal_rewards_distribution _protocol dal_parameters cryptobox node client ~error_msg: ("account " ^ account.Account.public_key_hash ^ ", expected to have sufficient DAL participation? %R, but got %L")) ; + let expecting_attesting_rewards = + not + @@ List.mem account.public_key_hash expected_to_lose_attesting_rewards + in + let expected_attesting_rewards = + if expecting_attesting_rewards then + Tez.to_mutez tb_participation.RPC.expected_attesting_rewards + else 0 + in let expected_dal_rewards = - if sufficient_dal_participation then + if sufficient_dal_participation && expecting_attesting_rewards then Tez.to_mutez dal_participation.expected_dal_rewards else 0 in - let delta = - Tez.to_mutez tb_participation.RPC.expected_attesting_rewards - + expected_dal_rewards - in + let delta = expected_attesting_rewards + expected_dal_rewards in Log.info "[check] %s %s: %Ld = %Ld + %d + %d" account.Account.alias account.public_key_hash bal1 bal2 - (Tez.to_mutez tb_participation.expected_attesting_rewards) + expected_attesting_rewards expected_dal_rewards ; check_bal_incr ~__LOC__ account bal1 bal2 ~delta) [ @@ -11068,7 +11094,7 @@ let register ~protocols = ~attestation_threshold:30 ~attestation_lag:2 ~blocks_per_cycle:16 - ~blocks_per_commitment:16 ; + ~blocks_per_commitment:17 (* so that there's no nonce revelation required *) ; scenario_with_layer1_node ~attestation_lag:5 "slots attestation operation behavior" -- GitLab