diff --git a/specs/capella/beacon-chain.md b/specs/capella/beacon-chain.md index e2001d777..0e24fadda 100644 --- a/specs/capella/beacon-chain.md +++ b/specs/capella/beacon-chain.md @@ -290,21 +290,21 @@ def get_expected_withdrawals(state: BeaconState) -> Sequence[Withdrawal]: withdrawals: List[Withdrawal] = [] for _ in range(len(state.validators)): validator_index = ValidatorIndex((validator_index + 1) % len(state.validators)) - val = state.validators[validator_index] + validator = state.validators[validator_index] balance = state.balances[validator_index] - if is_fully_withdrawable_validator(val, balance, epoch): + if is_fully_withdrawable_validator(validator, balance, epoch): withdrawals.append(Withdrawal( index=withdrawal_index, validator_index=validator_index, - address=ExecutionAddress(val.withdrawal_credentials[12:]), + address=ExecutionAddress(validator.withdrawal_credentials[12:]), amount=balance, )) withdrawal_index += WithdrawalIndex(1) - elif is_partially_withdrawable_validator(val, balance): + elif is_partially_withdrawable_validator(validator, balance): withdrawals.append(Withdrawal( index=withdrawal_index, validator_index=validator_index, - address=ExecutionAddress(val.withdrawal_credentials[12:]), + address=ExecutionAddress(validator.withdrawal_credentials[12:]), amount=balance - MAX_EFFECTIVE_BALANCE, )) withdrawal_index += WithdrawalIndex(1) @@ -324,6 +324,7 @@ def process_withdrawals(state: BeaconState, payload: ExecutionPayload) -> None: assert withdrawal == expected_withdrawal decrease_balance(state, withdrawal.validator_index, withdrawal.amount) if len(expected_withdrawals) > 0: + # withdrawal holds the last withdrawal object in the payload. state.next_withdrawal_index = WithdrawalIndex(withdrawal.index + 1) state.latest_withdrawal_validator_index = withdrawal.validator_index ``` 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 6474fb4fd..31fb18753 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 @@ -42,6 +42,10 @@ def prepare_expected_withdrawals(spec, state, def verify_post_state(state, spec, expected_withdrawals, fully_withdrawable_indices, partial_withdrawals_indices): + # Consider verifying also the condition when no withdrawals are expected. + if len(expected_withdrawals) == 0: + return + 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] @@ -128,7 +132,7 @@ def test_success_one_partial_withdrawal(spec, state): assert len(fully_withdrawable_indices) == 0 assert len(partial_withdrawals_indices) == 1 for index in partial_withdrawals_indices: - assert state.balances[index] != spec.MAX_EFFECTIVE_BALANCE + assert state.balances[index] > spec.MAX_EFFECTIVE_BALANCE next_slot(spec, state) execution_payload = build_empty_execution_payload(spec, state)