Skip to content

Commit

Permalink
Make modified helpers in electra fork aware
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanjay176 committed May 3, 2024
1 parent ee974db commit 40397fb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ pub fn process_registry_updates<E: EthSpec>(
validator.is_active_at(current_epoch)
&& validator.effective_balance <= spec.ejection_balance
};
let fork_name = state.fork_name_unchecked();
let indices_to_update: Vec<_> = state
.validators()
.iter()
.enumerate()
.filter(|(_, validator)| {
validator.is_eligible_for_activation_queue(spec) || is_ejectable(validator)
validator.is_eligible_for_activation_queue(&fork_name, spec) || is_ejectable(validator)
})
.map(|(idx, _)| idx)
.collect();

for index in indices_to_update {
let validator = state.get_validator_mut(index)?;
if validator.is_eligible_for_activation_queue(spec) {
if validator.is_eligible_for_activation_queue(&fork_name, spec) {
validator.activation_eligibility_epoch = current_epoch.safe_add(1)?;
}
if is_ejectable(validator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ fn process_single_registry_update(
) -> Result<(), Error> {
let current_epoch = state_ctxt.current_epoch;

if validator.is_eligible_for_activation_queue(spec) {
if validator.is_eligible_for_activation_queue(&state_ctxt.fork_name, spec) {
validator.make_mut()?.activation_eligibility_epoch = current_epoch.safe_add(1)?;
}

Expand Down
32 changes: 29 additions & 3 deletions consensus/types/src/validator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
test_utils::TestRandom, Address, BeaconState, ChainSpec, Epoch, EthSpec, Hash256,
test_utils::TestRandom, Address, BeaconState, ChainSpec, Epoch, EthSpec, ForkName, Hash256,
PublicKeyBytes,
};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -57,8 +57,34 @@ impl Validator {

/// Returns `true` if the validator is eligible to join the activation queue.
///
/// Modified in electra
pub fn is_eligible_for_activation_queue(&self, spec: &ChainSpec) -> bool {
/// Calls the appropriate function given the fork_name.
pub fn is_eligible_for_activation_queue(
&self,
current_fork: &ForkName,
spec: &ChainSpec,
) -> bool {
match current_fork {
ForkName::Base
| ForkName::Altair
| ForkName::Bellatrix
| ForkName::Capella
| ForkName::Deneb => self.is_eligible_for_activation_queue_base(spec),
ForkName::Electra => self.is_eligible_for_activation_queue_electra(spec),
}
}

/// Returns `true` if the validator is eligible to join the activation queue.
///
/// Spec v0.12.1
pub fn is_eligible_for_activation_queue_base(&self, spec: &ChainSpec) -> bool {
self.activation_eligibility_epoch == spec.far_future_epoch
&& self.effective_balance == spec.max_effective_balance
}

/// Returns `true` if the validator is eligible to join the activation queue.
///
/// Modified in electra as part of EIP 7251.
pub fn is_eligible_for_activation_queue_electra(&self, spec: &ChainSpec) -> bool {
self.activation_eligibility_epoch == spec.far_future_epoch
&& self.effective_balance >= spec.min_activation_balance
}
Expand Down

0 comments on commit 40397fb

Please sign in to comment.