Alex Stokes' review
This commit is contained in:
parent
e15b02d16f
commit
8488fb79d9
|
@ -290,21 +290,21 @@ def get_expected_withdrawals(state: BeaconState) -> Sequence[Withdrawal]:
|
||||||
withdrawals: List[Withdrawal] = []
|
withdrawals: List[Withdrawal] = []
|
||||||
for _ in range(len(state.validators)):
|
for _ in range(len(state.validators)):
|
||||||
validator_index = ValidatorIndex((validator_index + 1) % 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]
|
balance = state.balances[validator_index]
|
||||||
if is_fully_withdrawable_validator(val, balance, epoch):
|
if is_fully_withdrawable_validator(validator, balance, epoch):
|
||||||
withdrawals.append(Withdrawal(
|
withdrawals.append(Withdrawal(
|
||||||
index=withdrawal_index,
|
index=withdrawal_index,
|
||||||
validator_index=validator_index,
|
validator_index=validator_index,
|
||||||
address=ExecutionAddress(val.withdrawal_credentials[12:]),
|
address=ExecutionAddress(validator.withdrawal_credentials[12:]),
|
||||||
amount=balance,
|
amount=balance,
|
||||||
))
|
))
|
||||||
withdrawal_index += WithdrawalIndex(1)
|
withdrawal_index += WithdrawalIndex(1)
|
||||||
elif is_partially_withdrawable_validator(val, balance):
|
elif is_partially_withdrawable_validator(validator, balance):
|
||||||
withdrawals.append(Withdrawal(
|
withdrawals.append(Withdrawal(
|
||||||
index=withdrawal_index,
|
index=withdrawal_index,
|
||||||
validator_index=validator_index,
|
validator_index=validator_index,
|
||||||
address=ExecutionAddress(val.withdrawal_credentials[12:]),
|
address=ExecutionAddress(validator.withdrawal_credentials[12:]),
|
||||||
amount=balance - MAX_EFFECTIVE_BALANCE,
|
amount=balance - MAX_EFFECTIVE_BALANCE,
|
||||||
))
|
))
|
||||||
withdrawal_index += WithdrawalIndex(1)
|
withdrawal_index += WithdrawalIndex(1)
|
||||||
|
@ -324,6 +324,7 @@ def process_withdrawals(state: BeaconState, payload: ExecutionPayload) -> None:
|
||||||
assert withdrawal == expected_withdrawal
|
assert withdrawal == expected_withdrawal
|
||||||
decrease_balance(state, withdrawal.validator_index, withdrawal.amount)
|
decrease_balance(state, withdrawal.validator_index, withdrawal.amount)
|
||||||
if len(expected_withdrawals) > 0:
|
if len(expected_withdrawals) > 0:
|
||||||
|
# withdrawal holds the last withdrawal object in the payload.
|
||||||
state.next_withdrawal_index = WithdrawalIndex(withdrawal.index + 1)
|
state.next_withdrawal_index = WithdrawalIndex(withdrawal.index + 1)
|
||||||
state.latest_withdrawal_validator_index = withdrawal.validator_index
|
state.latest_withdrawal_validator_index = withdrawal.validator_index
|
||||||
```
|
```
|
||||||
|
|
|
@ -42,6 +42,10 @@ def prepare_expected_withdrawals(spec, state,
|
||||||
|
|
||||||
def verify_post_state(state, spec, expected_withdrawals,
|
def verify_post_state(state, spec, expected_withdrawals,
|
||||||
fully_withdrawable_indices, partial_withdrawals_indices):
|
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]
|
expected_withdrawals_validator_indices = [withdrawal.validator_index for withdrawal in expected_withdrawals]
|
||||||
assert state.next_withdrawal_index == expected_withdrawals[-1].index + 1
|
assert state.next_withdrawal_index == expected_withdrawals[-1].index + 1
|
||||||
assert state.latest_withdrawal_validator_index == expected_withdrawals_validator_indices[-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(fully_withdrawable_indices) == 0
|
||||||
assert len(partial_withdrawals_indices) == 1
|
assert len(partial_withdrawals_indices) == 1
|
||||||
for index in partial_withdrawals_indices:
|
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)
|
next_slot(spec, state)
|
||||||
execution_payload = build_empty_execution_payload(spec, state)
|
execution_payload = build_empty_execution_payload(spec, state)
|
||||||
|
|
Loading…
Reference in New Issue