def test_initiate_validator_exit(genesis_state, is_already_exited, config): state = genesis_state index = random.choice(range(len(state.validators))) validator = state.validators[index] assert not validator.slashed assert validator.activation_epoch == config.GENESIS_EPOCH assert validator.activation_eligibility_epoch == config.GENESIS_EPOCH assert validator.exit_epoch == FAR_FUTURE_EPOCH assert validator.withdrawable_epoch == FAR_FUTURE_EPOCH if is_already_exited: churn_limit = get_validator_churn_limit(state, config) exit_queue_epoch = _compute_exit_queue_epoch(state, churn_limit, config) validator = validator.copy( exit_epoch=exit_queue_epoch, withdrawable_epoch=exit_queue_epoch + config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY, ) exited_validator = initiate_exit_for_validator(validator, state, config) if is_already_exited: assert exited_validator == validator else: churn_limit = get_validator_churn_limit(state, config) exit_queue_epoch = _compute_exit_queue_epoch(state, churn_limit, config) assert exited_validator.exit_epoch == exit_queue_epoch assert exited_validator.withdrawable_epoch == ( exit_queue_epoch + config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY)
def _process_activation_eligibility_or_ejections( state: BeaconState, validator: Validator, config: Eth2Config) -> Validator: current_epoch = state.current_epoch(config.SLOTS_PER_EPOCH) if (validator.activation_eligibility_epoch == FAR_FUTURE_EPOCH and validator.effective_balance == config.MAX_EFFECTIVE_BALANCE): validator = validator.copy(activation_eligibility_epoch=current_epoch) if (validator.is_active(current_epoch) and validator.effective_balance <= config.EJECTION_BALANCE): validator = initiate_exit_for_validator(validator, state, config) return validator
def _process_activation_eligibility_or_ejections( state: BeaconState, index: ValidatorIndex, config: Eth2Config) -> BeaconState: current_epoch = state.current_epoch(config.SLOTS_PER_EPOCH) validator = state.validators[index] if validator.is_eligible_for_activation_queue(config): validator = validator.set("activation_eligibility_epoch", current_epoch + 1) if (validator.is_active(current_epoch) and validator.effective_balance <= config.EJECTION_BALANCE): validator = initiate_exit_for_validator(validator, state, config) return state.transform(("validators", index), validator)