Created
May 14, 2025 09:29
-
-
Save ydm/4b810ac45e18b13d6ec37b52806c326f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# | |
# Phase0 | |
# | |
def is_eligible_for_activation_queue(validator: Validator) -> bool: | |
""" | |
Check if ``validator`` is eligible to be placed into the activation queue. | |
""" | |
return ( | |
validator.activation_eligibility_epoch == FAR_FUTURE_EPOCH | |
and validator.effective_balance == MAX_EFFECTIVE_BALANCE | |
) | |
def is_eligible_for_activation(state: BeaconState, validator: Validator) -> bool: | |
""" | |
Check if ``validator`` is eligible for activation. | |
""" | |
return ( | |
# Placement in queue is finalized | |
validator.activation_eligibility_epoch <= state.finalized_checkpoint.epoch | |
# Has not yet been activated | |
and validator.activation_epoch == FAR_FUTURE_EPOCH | |
) | |
def get_validator_churn_limit(state: BeaconState) -> uint64: | |
""" | |
Return the validator churn limit for the current epoch. | |
""" | |
active_validator_indices = get_active_validator_indices(state, get_current_epoch(state)) | |
return max(MIN_PER_EPOCH_CHURN_LIMIT, uint64(len(active_validator_indices)) // CHURN_LIMIT_QUOTIENT) | |
# | |
# Deneb | |
# | |
def get_validator_activation_churn_limit(state: BeaconState) -> uint64: | |
""" | |
Return the validator activation churn limit for the current epoch. | |
""" | |
return min(MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT, get_validator_churn_limit(state)) | |
def process_registry_updates(state: BeaconState) -> None: | |
# Process activation eligibility and ejections | |
for index, validator in enumerate(state.validators): | |
if is_eligible_for_activation_queue(validator): | |
validator.activation_eligibility_epoch = get_current_epoch(state) + 1 | |
if ( | |
is_active_validator(validator, get_current_epoch(state)) | |
and validator.effective_balance <= EJECTION_BALANCE | |
): | |
initiate_validator_exit(state, ValidatorIndex(index)) | |
# Queue validators eligible for activation and not yet dequeued for activation | |
activation_queue = sorted([ | |
index for index, validator in enumerate(state.validators) | |
if is_eligible_for_activation(state, validator) | |
# Order by the sequence of activation_eligibility_epoch setting and then index | |
], key=lambda index: (state.validators[index].activation_eligibility_epoch, index)) | |
# Dequeued validators for activation up to activation churn limit | |
# [Modified in Deneb:EIP7514] | |
for index in activation_queue[:get_validator_activation_churn_limit(state)]: | |
validator = state.validators[index] | |
validator.activation_epoch = compute_activation_exit_epoch(get_current_epoch(state)) | |
# | |
# Electra | |
# | |
def is_eligible_for_activation_queue(validator: Validator) -> bool: | |
""" | |
Check if ``validator`` is eligible to be placed into the activation queue. | |
""" | |
return ( | |
validator.activation_eligibility_epoch == FAR_FUTURE_EPOCH | |
and validator.effective_balance >= MIN_ACTIVATION_BALANCE # [Modified in Electra:EIP7251] | |
) | |
def process_registry_updates(state: BeaconState) -> None: | |
current_epoch = get_current_epoch(state) | |
activation_epoch = compute_activation_exit_epoch(current_epoch) | |
# Process activation eligibility, ejections, and activations | |
for index, validator in enumerate(state.validators): | |
if is_eligible_for_activation_queue(validator): # [Modified in Electra:EIP7251] | |
validator.activation_eligibility_epoch = current_epoch + 1 | |
elif is_active_validator(validator, current_epoch) and validator.effective_balance <= EJECTION_BALANCE: | |
initiate_validator_exit(state, ValidatorIndex(index)) # [Modified in Electra:EIP7251] | |
elif is_eligible_for_activation(state, validator): | |
validator.activation_epoch = activation_epoch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment