Skip to content

Commit

Permalink
Create epoch_processing module and process_registry_updates()
Browse files Browse the repository at this point in the history
  • Loading branch information
EchoAlice committed Apr 22, 2024
1 parent 6f26186 commit 6f195ab
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rust-analyzer.linkedProjects": [
"./ethereum-consensus/Cargo.toml"
]
}
69 changes: 69 additions & 0 deletions ethereum-consensus/src/electra/epoch_processing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use crate::electra::{
compute_activation_exit_epoch, get_current_epoch, initiate_validator_exit, is_active_validator,
is_eligible_for_activation, is_eligible_for_activation_queue, BeaconState, Context, Result,
};

pub fn process_registry_updates<
const SLOTS_PER_HISTORICAL_ROOT: usize,
const HISTORICAL_ROOTS_LIMIT: usize,
const ETH1_DATA_VOTES_BOUND: usize,
const VALIDATOR_REGISTRY_LIMIT: usize,
const EPOCHS_PER_HISTORICAL_VECTOR: usize,
const EPOCHS_PER_SLASHINGS_VECTOR: usize,
const MAX_VALIDATORS_PER_COMMITTEE: usize,
const SYNC_COMMITTEE_SIZE: usize,
const BYTES_PER_LOGS_BLOOM: usize,
const MAX_EXTRA_DATA_BYTES: usize,
const PENDING_BALANCE_DEPOSITS_LIMIT: usize,
const PENDING_PARTIAL_WITHDRAWALS_LIMIT: usize,
const PENDING_CONSOLIDATIONS_LIMIT: usize,
>(
state: &mut BeaconState<
SLOTS_PER_HISTORICAL_ROOT,
HISTORICAL_ROOTS_LIMIT,
ETH1_DATA_VOTES_BOUND,
VALIDATOR_REGISTRY_LIMIT,
EPOCHS_PER_HISTORICAL_VECTOR,
EPOCHS_PER_SLASHINGS_VECTOR,
MAX_VALIDATORS_PER_COMMITTEE,
SYNC_COMMITTEE_SIZE,
BYTES_PER_LOGS_BLOOM,
MAX_EXTRA_DATA_BYTES,
PENDING_BALANCE_DEPOSITS_LIMIT,
PENDING_PARTIAL_WITHDRAWALS_LIMIT,
PENDING_CONSOLIDATIONS_LIMIT,
>,
context: &Context,
) -> Result<()> {
// Process activation eligibility and ejections
let current_epoch = get_current_epoch(state, context);
for i in 0..state.validators.len() {
let validator = &mut state.validators[i];
if is_eligible_for_activation_queue(validator, context) {
validator.activation_eligibility_epoch = current_epoch + 1;
}
if is_active_validator(validator, current_epoch) &&
validator.effective_balance <= context.ejection_balance
{
initiate_validator_exit(state, i, context)?;
}
}

// Note: Name changed from `activation_exit_epoch` (Deneb) to `activation_epoch` (Electra) in
// spec.
let activation_epoch = compute_activation_exit_epoch(current_epoch, context);
let mut eligible_val_indices = Vec::new();
for i in 0..state.validators.len() {
let validator = &state.validators[i];
if is_eligible_for_activation(state, validator) {
eligible_val_indices.push(i);
}
}

for i in eligible_val_indices.iter() {
let validator = &mut state.validators[*i];
validator.activation_epoch = activation_epoch;
}

Ok(())
}
1 change: 1 addition & 0 deletions ethereum-consensus/src/electra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod beacon_block;
pub mod beacon_state;
pub mod block_processing;
pub mod constants;
pub mod epoch_processing;
pub mod execution_payload;
pub mod fork;
pub mod genesis;
Expand Down
1 change: 1 addition & 0 deletions ethereum-consensus/src/electra/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub use crate::{
},
block_processing::{process_attestation, process_execution_payload},
constants::{FULL_EXIT_REQUEST_AMOUNT, UNSET_DEPOSIT_RECEIPTS_START_INDEX},
epoch_processing,
execution_payload::{ExecutionPayload, ExecutionPayloadHeader},
fork::upgrade_to_electra,
genesis::initialize_beacon_state_from_eth1,
Expand Down

0 comments on commit 6f195ab

Please sign in to comment.