From 6e011861d9aacceeb08f22f996dbc429b14187ff Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Fri, 18 Oct 2024 12:43:00 +0600 Subject: [PATCH 1/4] Simplify validator activation flow --- specs/electra/beacon-chain.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index 0c56491907..5f11ac22f5 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -41,7 +41,7 @@ - [Helper functions](#helper-functions) - [Predicates](#predicates) - [Modified `compute_proposer_index`](#modified-compute_proposer_index) - - [Modified `is_eligible_for_activation_queue`](#modified-is_eligible_for_activation_queue) + - [Modified `is_eligible_for_activation`](#modified-is_eligible_for_activation) - [New `is_compounding_withdrawal_credential`](#new-is_compounding_withdrawal_credential) - [New `has_compounding_withdrawal_credential`](#new-has_compounding_withdrawal_credential) - [New `has_execution_withdrawal_credential`](#new-has_execution_withdrawal_credential) @@ -419,18 +419,21 @@ def compute_proposer_index(state: BeaconState, indices: Sequence[ValidatorIndex] i += 1 ``` -#### Modified `is_eligible_for_activation_queue` +#### Modified `is_eligible_for_activation` -*Note*: The function `is_eligible_for_activation_queue` is modified to use `MIN_ACTIVATION_BALANCE` instead of `MAX_EFFECTIVE_BALANCE`. +*Note*: The function `is_eligible_for_activation` is modified to directly use `effective_balance` +instead of `activation_eligibility_epoch` as one of the elgibility criteria. ```python -def is_eligible_for_activation_queue(validator: Validator) -> bool: +def is_eligible_for_activation(state: BeaconState, validator: Validator) -> bool: """ - Check if ``validator`` is eligible to be placed into the activation queue. + Check if ``validator`` is eligible for activation. """ return ( - validator.activation_eligibility_epoch == FAR_FUTURE_EPOCH - and validator.effective_balance >= MIN_ACTIVATION_BALANCE # [Modified in Electra:EIP7251] + # Has sufficient effective balance + validator.effective_balance >= MIN_ACTIVATION_BALANCE + # Has not yet been activated + and validator.activation_epoch == FAR_FUTURE_EPOCH ) ``` @@ -778,23 +781,20 @@ def process_epoch(state: BeaconState) -> None: #### Modified `process_registry_updates` -*Note*: The function `process_registry_updates` is modified to use the updated definition of `initiate_validator_exit` -and changes how the activation epochs are computed for eligible validators. +*Note*: The function `process_registry_updates` is modified to use the updated definition of `initiate_validator_exit`, +changes how `activation_epoch` is computed for an eligible validator and removes the usage of `activation_eligibility_epoch`. ```python def process_registry_updates(state: BeaconState) -> None: - # Process activation eligibility and ejections + # Process 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)) + initiate_validator_exit(state, ValidatorIndex(index)) # [Modified in Electra:EIP7251] - # Activate all eligible validators + # Activate all eligible validators [Modified in Electra:EIP7251] activation_epoch = compute_activation_exit_epoch(get_current_epoch(state)) for validator in state.validators: if is_eligible_for_activation(state, validator): From 92e7c761839e817becebf29d581cf0c73e208fc8 Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Mon, 21 Oct 2024 13:07:09 +0600 Subject: [PATCH 2/4] Apply suggestions by @ppopth Co-authored-by: Pop Chunhapanya --- specs/electra/beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index 5f11ac22f5..195a1c2bf0 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -422,7 +422,7 @@ def compute_proposer_index(state: BeaconState, indices: Sequence[ValidatorIndex] #### Modified `is_eligible_for_activation` *Note*: The function `is_eligible_for_activation` is modified to directly use `effective_balance` -instead of `activation_eligibility_epoch` as one of the elgibility criteria. +instead of `activation_eligibility_epoch` as one of the eligibility criteria. ```python def is_eligible_for_activation(state: BeaconState, validator: Validator) -> bool: From 208d9e9b0c90de13dfc40dfceb6bf0a686fd10b1 Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Mon, 21 Oct 2024 13:37:25 +0600 Subject: [PATCH 3/4] Set activation_eligibility_epoch for backwards compatibility --- specs/electra/beacon-chain.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index 195a1c2bf0..c00c1cd6f9 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -782,7 +782,7 @@ def process_epoch(state: BeaconState) -> None: #### Modified `process_registry_updates` *Note*: The function `process_registry_updates` is modified to use the updated definition of `initiate_validator_exit`, -changes how `activation_epoch` is computed for an eligible validator and removes the usage of `activation_eligibility_epoch`. +changes how `activation_epoch` and `activation_eligibility_epoch` are computed for an eligible validator. ```python def process_registry_updates(state: BeaconState) -> None: @@ -796,9 +796,13 @@ def process_registry_updates(state: BeaconState) -> None: # Activate all eligible validators [Modified in Electra:EIP7251] activation_epoch = compute_activation_exit_epoch(get_current_epoch(state)) + activation_eligibility_epoch = get_current_epoch(state) + 1 for validator in state.validators: if is_eligible_for_activation(state, validator): validator.activation_epoch = activation_epoch + # Set activation eligibility epoch for backwards compatibility, + # to be deprecated in one of the future upgrades + validator.activation_eligibility_epoch = activation_eligibility_epoch ``` #### Modified `process_slashings` From 32e6129db66cabd0d94edcb5fe49367b7a5ac020 Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Mon, 21 Oct 2024 16:17:21 +0600 Subject: [PATCH 4/4] Remove from is_eligible_for_activation params --- specs/electra/beacon-chain.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index c00c1cd6f9..638a9f0a51 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -425,7 +425,7 @@ def compute_proposer_index(state: BeaconState, indices: Sequence[ValidatorIndex] instead of `activation_eligibility_epoch` as one of the eligibility criteria. ```python -def is_eligible_for_activation(state: BeaconState, validator: Validator) -> bool: +def is_eligible_for_activation(validator: Validator) -> bool: """ Check if ``validator`` is eligible for activation. """ @@ -798,7 +798,7 @@ def process_registry_updates(state: BeaconState) -> None: activation_epoch = compute_activation_exit_epoch(get_current_epoch(state)) activation_eligibility_epoch = get_current_epoch(state) + 1 for validator in state.validators: - if is_eligible_for_activation(state, validator): + if is_eligible_for_activation(validator): validator.activation_epoch = activation_epoch # Set activation eligibility epoch for backwards compatibility, # to be deprecated in one of the future upgrades