From 7f266bcb0fc740f8b781e404c4836313e73c498d Mon Sep 17 00:00:00 2001 From: Potuz Date: Thu, 10 Nov 2022 08:33:11 -0300 Subject: [PATCH] Use next_validator_withdrawal_index --- specs/capella/beacon-chain.md | 7 ++++--- specs/capella/fork.md | 2 +- .../capella/block_processing/test_process_withdrawals.py | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/specs/capella/beacon-chain.md b/specs/capella/beacon-chain.md index e72a0dc1a..90a64925f 100644 --- a/specs/capella/beacon-chain.md +++ b/specs/capella/beacon-chain.md @@ -221,7 +221,7 @@ class BeaconState(Container): latest_execution_payload_header: ExecutionPayloadHeader # Withdrawals next_withdrawal_index: WithdrawalIndex # [New in Capella] - latest_withdrawal_validator_index: ValidatorIndex # [New in Capella] + next_withdrawal_validator_index: ValidatorIndex # [New in Capella] ``` ## Helpers @@ -286,7 +286,7 @@ def process_block(state: BeaconState, block: BeaconBlock) -> None: def get_expected_withdrawals(state: BeaconState) -> Sequence[Withdrawal]: epoch = get_current_epoch(state) withdrawal_index = state.next_withdrawal_index - validator_index = ValidatorIndex((state.latest_withdrawal_validator_index + 1) % len(state.validators)) + validator_index = state.next_withdrawal_validator_index withdrawals: List[Withdrawal] = [] for _ in range(len(state.validators)): validator = state.validators[validator_index] @@ -326,7 +326,8 @@ def process_withdrawals(state: BeaconState, payload: ExecutionPayload) -> None: if len(expected_withdrawals) > 0: latest_withdrawal = expected_withdrawals[-1] state.next_withdrawal_index = WithdrawalIndex(latest_withdrawal.index + 1) - state.latest_withdrawal_validator_index = latest_withdrawal.validator_index + next_validator_index = ValidatorIndex((latest_withdrawal.validator_index + 1) % len(state.validators)) + state.next_withdrawal_validator_index = next_validator_index ``` #### Modified `process_execution_payload` diff --git a/specs/capella/fork.md b/specs/capella/fork.md index 1ea43b463..e2493d33b 100644 --- a/specs/capella/fork.md +++ b/specs/capella/fork.md @@ -130,7 +130,7 @@ def upgrade_to_capella(pre: bellatrix.BeaconState) -> BeaconState: latest_execution_payload_header=latest_execution_payload_header, # Withdrawals next_withdrawal_index=WithdrawalIndex(0), - latest_withdrawal_validator_index=ValidatorIndex(0), + next_withdrawal_validator_index=ValidatorIndex(0), ) return post diff --git a/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_withdrawals.py b/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_withdrawals.py index fbf0387b4..843753c6c 100644 --- a/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_withdrawals.py +++ b/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_withdrawals.py @@ -33,7 +33,7 @@ def verify_post_state(state, spec, expected_withdrawals, expected_withdrawals_validator_indices = [withdrawal.validator_index for withdrawal in expected_withdrawals] assert state.next_withdrawal_index == expected_withdrawals[-1].index + 1 - assert state.latest_withdrawal_validator_index == expected_withdrawals_validator_indices[-1] + assert state.next_withdrawal_validator_index == (expected_withdrawals_validator_indices[-1]+1) % len(state.validators) for index in fully_withdrawable_indices: if index in expected_withdrawals_validator_indices: assert state.balances[index] == 0 @@ -732,7 +732,7 @@ def run_random_partial_withdrawals_test(spec, state, rng): randomize_state(spec, state, rng) num_validators = len(state.validators) - state.latest_withdrawal_validator_index = rng.randint(0, num_validators - 1) + state.next_withdrawal_validator_index = rng.randint(0, num_validators - 1) num_partially_withdrawable = rng.randint(0, num_validators - 1) partially_withdrawable_indices = rng.sample(range(num_validators), num_partially_withdrawable)