Add Gloas boilerplate (#7728)

Adds the required boilerplate code for the Gloas (Glamsterdam) hard fork. This allows PRs testing Gloas-candidate features to test fork transition.

This also includes de-duplication of post-Bellatrix readiness notifiers from #6797 (credit to @dapplion)
This commit is contained in:
Mac L
2025-08-26 12:49:48 +10:00
committed by GitHub
parent daf1c7c3af
commit e438691683
75 changed files with 1801 additions and 917 deletions

View File

@@ -5,6 +5,7 @@ use crate::common::DepositDataTree;
use crate::upgrade::electra::upgrade_state_to_electra;
use crate::upgrade::{
upgrade_to_altair, upgrade_to_bellatrix, upgrade_to_capella, upgrade_to_deneb, upgrade_to_fulu,
upgrade_to_gloas,
};
use safe_arith::{ArithError, SafeArith};
use std::sync::Arc;
@@ -150,11 +151,27 @@ pub fn initialize_beacon_state_from_eth1<E: EthSpec>(
state.fork_mut().previous_version = spec.fulu_fork_version;
// Override latest execution payload header.
if let Some(ExecutionPayloadHeader::Fulu(header)) = execution_payload_header {
if let Some(ExecutionPayloadHeader::Fulu(ref header)) = execution_payload_header {
*state.latest_execution_payload_header_fulu_mut()? = header.clone();
}
}
// Upgrade to gloas if configured from genesis.
if spec
.gloas_fork_epoch
.is_some_and(|fork_epoch| fork_epoch == E::genesis_epoch())
{
upgrade_to_gloas(&mut state, spec)?;
// Remove intermediate Fulu fork from `state.fork`.
state.fork_mut().previous_version = spec.gloas_fork_version;
// Override latest execution payload header.
if let Some(ExecutionPayloadHeader::Gloas(header)) = execution_payload_header {
*state.latest_execution_payload_header_gloas_mut()? = header.clone();
}
}
// Now that we have our validators, initialize the caches (including the committees)
state.build_caches(spec)?;

View File

@@ -452,6 +452,12 @@ pub fn process_execution_payload<E: EthSpec, Payload: AbstractExecPayload<E>>(
_ => return Err(BlockProcessingError::IncorrectStateType),
}
}
ExecutionPayloadHeaderRefMut::Gloas(header_mut) => {
match payload.to_execution_payload_header() {
ExecutionPayloadHeader::Gloas(header) => *header_mut = header,
_ => return Err(BlockProcessingError::IncorrectStateType),
}
}
}
Ok(())

View File

@@ -1,6 +1,6 @@
use crate::upgrade::{
upgrade_to_altair, upgrade_to_bellatrix, upgrade_to_capella, upgrade_to_deneb,
upgrade_to_electra, upgrade_to_fulu,
upgrade_to_electra, upgrade_to_fulu, upgrade_to_gloas,
};
use crate::{per_epoch_processing::EpochProcessingSummary, *};
use safe_arith::{ArithError, SafeArith};
@@ -78,6 +78,11 @@ pub fn per_slot_processing<E: EthSpec>(
upgrade_to_fulu(state, spec)?;
}
// Gloas.
if spec.gloas_fork_epoch == Some(state.current_epoch()) {
upgrade_to_gloas(state, spec)?;
}
// Additionally build all caches so that all valid states that are advanced always have
// committee caches built, and we don't have to worry about initialising them at higher
// layers.

View File

@@ -4,6 +4,7 @@ pub mod capella;
pub mod deneb;
pub mod electra;
pub mod fulu;
pub mod gloas;
pub use altair::upgrade_to_altair;
pub use bellatrix::upgrade_to_bellatrix;
@@ -11,3 +12,4 @@ pub use capella::upgrade_to_capella;
pub use deneb::upgrade_to_deneb;
pub use electra::upgrade_to_electra;
pub use fulu::upgrade_to_fulu;
pub use gloas::upgrade_to_gloas;

View File

@@ -0,0 +1,93 @@
use std::mem;
use types::{BeaconState, BeaconStateError as Error, BeaconStateGloas, ChainSpec, EthSpec, Fork};
/// Transform a `Fulu` state into a `Gloas` state.
pub fn upgrade_to_gloas<E: EthSpec>(
pre_state: &mut BeaconState<E>,
spec: &ChainSpec,
) -> Result<(), Error> {
let post = upgrade_state_to_gloas(pre_state, spec)?;
*pre_state = post;
Ok(())
}
pub fn upgrade_state_to_gloas<E: EthSpec>(
pre_state: &mut BeaconState<E>,
spec: &ChainSpec,
) -> Result<BeaconState<E>, Error> {
let epoch = pre_state.current_epoch();
let pre = pre_state.as_fulu_mut()?;
// Where possible, use something like `mem::take` to move fields from behind the &mut
// reference. For other fields that don't have a good default value, use `clone`.
//
// Fixed size vectors get cloned because replacing them would require the same size
// allocation as cloning.
let post = BeaconState::Gloas(BeaconStateGloas {
// Versioning
genesis_time: pre.genesis_time,
genesis_validators_root: pre.genesis_validators_root,
slot: pre.slot,
fork: Fork {
previous_version: pre.fork.current_version,
current_version: spec.gloas_fork_version,
epoch,
},
// History
latest_block_header: pre.latest_block_header.clone(),
block_roots: pre.block_roots.clone(),
state_roots: pre.state_roots.clone(),
historical_roots: mem::take(&mut pre.historical_roots),
// Eth1
eth1_data: pre.eth1_data.clone(),
eth1_data_votes: mem::take(&mut pre.eth1_data_votes),
eth1_deposit_index: pre.eth1_deposit_index,
// Registry
validators: mem::take(&mut pre.validators),
balances: mem::take(&mut pre.balances),
// Randomness
randao_mixes: pre.randao_mixes.clone(),
// Slashings
slashings: pre.slashings.clone(),
// `Participation
previous_epoch_participation: mem::take(&mut pre.previous_epoch_participation),
current_epoch_participation: mem::take(&mut pre.current_epoch_participation),
// Finality
justification_bits: pre.justification_bits.clone(),
previous_justified_checkpoint: pre.previous_justified_checkpoint,
current_justified_checkpoint: pre.current_justified_checkpoint,
finalized_checkpoint: pre.finalized_checkpoint,
// Inactivity
inactivity_scores: mem::take(&mut pre.inactivity_scores),
// Sync committees
current_sync_committee: pre.current_sync_committee.clone(),
next_sync_committee: pre.next_sync_committee.clone(),
// Execution
latest_execution_payload_header: pre.latest_execution_payload_header.upgrade_to_gloas(),
// Capella
next_withdrawal_index: pre.next_withdrawal_index,
next_withdrawal_validator_index: pre.next_withdrawal_validator_index,
historical_summaries: pre.historical_summaries.clone(),
// Electra
deposit_requests_start_index: pre.deposit_requests_start_index,
deposit_balance_to_consume: pre.deposit_balance_to_consume,
exit_balance_to_consume: pre.exit_balance_to_consume,
earliest_exit_epoch: pre.earliest_exit_epoch,
consolidation_balance_to_consume: pre.consolidation_balance_to_consume,
earliest_consolidation_epoch: pre.earliest_consolidation_epoch,
pending_deposits: pre.pending_deposits.clone(),
pending_partial_withdrawals: pre.pending_partial_withdrawals.clone(),
pending_consolidations: pre.pending_consolidations.clone(),
// Caches
total_active_balance: pre.total_active_balance,
progressive_balances_cache: mem::take(&mut pre.progressive_balances_cache),
committee_caches: mem::take(&mut pre.committee_caches),
pubkey_cache: mem::take(&mut pre.pubkey_cache),
exit_cache: mem::take(&mut pre.exit_cache),
slashings_cache: mem::take(&mut pre.slashings_cache),
epoch_cache: mem::take(&mut pre.epoch_cache),
proposer_lookahead: mem::take(&mut pre.proposer_lookahead),
});
Ok(post)
}