refine naming for withdrawals
This commit is contained in:
parent
36aae1d848
commit
493b169022
|
@ -61,7 +61,7 @@ class Validator(Container):
|
||||||
activation_epoch: Epoch
|
activation_epoch: Epoch
|
||||||
exit_epoch: Epoch
|
exit_epoch: Epoch
|
||||||
withdrawable_epoch: Epoch # When validator can withdraw funds
|
withdrawable_epoch: Epoch # When validator can withdraw funds
|
||||||
withdrawn_epoch: Epoch # [New in Capella]
|
fully_withdrawn_epoch: Epoch # [New in Capella]
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `BeaconState`
|
#### `BeaconState`
|
||||||
|
@ -173,7 +173,7 @@ class Withdrawal(Container):
|
||||||
#### `withdraw`
|
#### `withdraw`
|
||||||
|
|
||||||
```python
|
```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 the validator's balance
|
||||||
decrease_balance(state, index, amount)
|
decrease_balance(state, index, amount)
|
||||||
# Create a corresponding withdrawal receipt
|
# 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.
|
Check if ``validator`` is fully withdrawable.
|
||||||
"""
|
"""
|
||||||
is_eth1_withdrawal_prefix = validator.withdrawal_credentials[0:1] == ETH1_ADDRESS_WITHDRAWAL_PREFIX
|
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
|
## Beacon chain state transition function
|
||||||
|
@ -230,8 +230,8 @@ def process_full_withdrawals(state: BeaconState) -> None:
|
||||||
for index, validator in enumerate(state.validators):
|
for index, validator in enumerate(state.validators):
|
||||||
if is_fully_withdrawable_validator(validator, current_epoch):
|
if is_fully_withdrawable_validator(validator, current_epoch):
|
||||||
# TODO, consider the zero-balance case
|
# TODO, consider the zero-balance case
|
||||||
withdraw(state, ValidatorIndex(index), state.balances[index])
|
withdraw_balance(state, ValidatorIndex(index), state.balances[index])
|
||||||
validator.withdrawn_epoch = current_epoch
|
validator.fully_withdrawn_epoch = current_epoch
|
||||||
```
|
```
|
||||||
|
|
||||||
### Block processing
|
### Block processing
|
||||||
|
|
|
@ -97,7 +97,7 @@ def upgrade_to_capella(pre: bellatrix.BeaconState) -> BeaconState:
|
||||||
activation_epoch=pre_validator.activation_epoch,
|
activation_epoch=pre_validator.activation_epoch,
|
||||||
exit_epoch=pre_validator.exit_epoch,
|
exit_epoch=pre_validator.exit_epoch,
|
||||||
withdrawable_epoch=pre_validator.withdrawable_epoch,
|
withdrawable_epoch=pre_validator.withdrawable_epoch,
|
||||||
withdrawn_epoch=FAR_FUTURE_EPOCH,
|
fully_withdrawn_epoch=FAR_FUTURE_EPOCH,
|
||||||
)
|
)
|
||||||
post.validators.append(post_validator)
|
post.validators.append(post_validator)
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ def run_process_full_withdrawals(spec, state, num_expected_withdrawals=None):
|
||||||
|
|
||||||
for index in to_be_withdrawn_indices:
|
for index in to_be_withdrawn_indices:
|
||||||
validator = state.validators[index]
|
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 state.balances[index] == 0
|
||||||
|
|
||||||
assert len(state.withdrawals_queue) == len(pre_withdrawals_queue) + num_expected_withdrawals
|
assert len(state.withdrawals_queue) == len(pre_withdrawals_queue) + num_expected_withdrawals
|
||||||
|
|
|
@ -20,7 +20,7 @@ def build_mock_validator(spec, i: int, balance: int):
|
||||||
)
|
)
|
||||||
|
|
||||||
if spec.fork not in FORKS_BEFORE_CAPELLA:
|
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
|
return validator
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue