Last active
April 27, 2022 16:59
-
-
Save arwer13/ed220cc5a7c0dccfbd03c14026df6c40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MAX_WITHDRAWER_EXITS = 2**4 | |
class WithdrawerExit(Container): | |
validator_index: ValidatorIndex | |
withdrawer_address: ExecutionAddress | |
class BeaconBlockBody(Container): | |
# ... | |
deposits: List[Deposit, MAX_DEPOSITS] | |
voluntary_exits: List[SignedVoluntaryExit, MAX_VOLUNTARY_EXITS] | |
withdrawer_exits: List[WithdrawerExit, MAX_WITHDRAWER_EXITS] | |
def process_operations(state: BeaconState, body: BeaconBlockBody) -> None: | |
# ... | |
for_ops(body.deposits, process_deposit) | |
for_ops(body.voluntary_exits, process_voluntary_exit) | |
for_ops(body.withdrawer_exits, process_withdrawer_exit) | |
def is_withdrawer_exit_valid(state: BeaconState, withdrawer_exit: WithdrawerExit) -> bool: | |
validator = state.validators[withdrawer_exit.validator_index] | |
# Verify the validator is active | |
assert is_active_validator(validator, get_current_epoch(state)) | |
# Verify exit has not been initiated | |
assert validator.exit_epoch == FAR_FUTURE_EPOCH | |
# Verify the validator has been active long enough | |
assert get_current_epoch(state) >= validator.activation_epoch + SHARD_COMMITTEE_PERIOD | |
# Check withdrawer_exit was indeed initiated by withdrawal credentials | |
return withdrawer_exit.withdrawer_address == validator.withdrawal_credentials | |
def process_withdrawer_exit(state: BeaconState, withdrawer_exit: WithdrawerExit) -> None: | |
if is_withdrawer_exit_valid(state, withdrawer_exit): | |
initiate_validator_exit(state, withdrawer_exit.validator_index) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment