Skip to content

Commit

Permalink
Use next_validator_withdrawal_index
Browse files Browse the repository at this point in the history
  • Loading branch information
potuz committed Nov 10, 2022
1 parent 710b124 commit 7f266bc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions specs/capella/beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion specs/capella/fork.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7f266bc

Please sign in to comment.