Use next_validator_withdrawal_index

This commit is contained in:
Potuz 2022-11-10 08:33:11 -03:00
parent 710b124cdc
commit 7f266bcb0f
3 changed files with 7 additions and 6 deletions

View File

@ -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`

View File

@ -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

View File

@ -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)