refine naming for withdrawals

This commit is contained in:
Danny Ryan 2022-03-22 07:55:45 -06:00
parent 36aae1d848
commit 493b169022
No known key found for this signature in database
GPG Key ID: 2765A792E42CE07A
4 changed files with 8 additions and 8 deletions

View File

@ -61,7 +61,7 @@ class Validator(Container):
activation_epoch: Epoch
exit_epoch: Epoch
withdrawable_epoch: Epoch # When validator can withdraw funds
withdrawn_epoch: Epoch # [New in Capella]
fully_withdrawn_epoch: Epoch # [New in Capella]
```
#### `BeaconState`
@ -173,7 +173,7 @@ class Withdrawal(Container):
#### `withdraw`
```python
def withdraw(state: BeaconState, index: ValidatorIndex, amount: Gwei) -> None:
def withdraw_balance(state: BeaconState, index: ValidatorIndex, amount: Gwei) -> None:
# Decrease the validator's balance
decrease_balance(state, index, amount)
# Create a corresponding withdrawal receipt
@ -196,7 +196,7 @@ def is_fully_withdrawable_validator(validator: Validator, epoch: Epoch) -> bool:
Check if ``validator`` is fully withdrawable.
"""
is_eth1_withdrawal_prefix = validator.withdrawal_credentials[0:1] == ETH1_ADDRESS_WITHDRAWAL_PREFIX
return is_eth1_withdrawal_prefix and validator.withdrawable_epoch <= epoch < validator.withdrawn_epoch
return is_eth1_withdrawal_prefix and validator.withdrawable_epoch <= epoch < validator.fully_withdrawn_epoch
```
## Beacon chain state transition function
@ -230,8 +230,8 @@ def process_full_withdrawals(state: BeaconState) -> None:
for index, validator in enumerate(state.validators):
if is_fully_withdrawable_validator(validator, current_epoch):
# TODO, consider the zero-balance case
withdraw(state, ValidatorIndex(index), state.balances[index])
validator.withdrawn_epoch = current_epoch
withdraw_balance(state, ValidatorIndex(index), state.balances[index])
validator.fully_withdrawn_epoch = current_epoch
```
### Block processing

View File

@ -97,7 +97,7 @@ def upgrade_to_capella(pre: bellatrix.BeaconState) -> BeaconState:
activation_epoch=pre_validator.activation_epoch,
exit_epoch=pre_validator.exit_epoch,
withdrawable_epoch=pre_validator.withdrawable_epoch,
withdrawn_epoch=FAR_FUTURE_EPOCH,
fully_withdrawn_epoch=FAR_FUTURE_EPOCH,
)
post.validators.append(post_validator)

View File

@ -31,7 +31,7 @@ def run_process_full_withdrawals(spec, state, num_expected_withdrawals=None):
for index in to_be_withdrawn_indices:
validator = state.validators[index]
assert validator.withdrawn_epoch == spec.get_current_epoch(state)
assert validator.fully_withdrawn_epoch == spec.get_current_epoch(state)
assert state.balances[index] == 0
assert len(state.withdrawals_queue) == len(pre_withdrawals_queue) + num_expected_withdrawals

View File

@ -20,7 +20,7 @@ def build_mock_validator(spec, i: int, balance: int):
)
if spec.fork not in FORKS_BEFORE_CAPELLA:
validator.withdrawn_epoch = spec.FAR_FUTURE_EPOCH
validator.fully_withdrawn_epoch = spec.FAR_FUTURE_EPOCH
return validator