heze boilerplate

This commit is contained in:
Eitan Seri-Levi
2026-04-27 12:51:16 +02:00
parent fae7941b2d
commit a9a9ccfad0
70 changed files with 2643 additions and 177 deletions

View File

@@ -17,7 +17,7 @@ use types::{
/// This function will return an error if the source of the attestation doesn't match the
/// state's relevant justified checkpoint.
///
/// This function has been abstracted to work for all forks from Altair to Gloas.
/// This function has been abstracted to work for all forks from Altair to Heze.
pub fn get_attestation_participation_flag_indices<E: EthSpec>(
state: &BeaconState<E>,
data: &AttestationData,

View File

@@ -5,7 +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,
upgrade_to_gloas, upgrade_to_heze,
};
use fixed_bytes::FixedBytesExtended;
use safe_arith::{ArithError, SafeArith};
@@ -184,6 +184,17 @@ pub fn initialize_beacon_state_from_eth1<E: EthSpec>(
state.latest_block_header_mut().body_root = block.body_root();
}
// Upgrade to heze if configured from genesis.
if spec
.heze_fork_epoch
.is_some_and(|fork_epoch| fork_epoch == E::genesis_epoch())
{
upgrade_to_heze(&mut state, spec)?;
// Remove intermediate Gloas fork from `state.fork`.
state.fork_mut().previous_version = spec.heze_fork_version;
}
// Now that we have our validators, initialize the caches (including the committees)
state.build_caches(spec)?;
@@ -195,7 +206,7 @@ pub fn initialize_beacon_state_from_eth1<E: EthSpec>(
/// Create an unsigned genesis `BeaconBlock` whose body matches the genesis state.
///
/// For Gloas, the block's `signed_execution_payload_bid` is populated from the state's
/// For Gloas and later, the block's `signed_execution_payload_bid` is populated from the state's
/// `latest_execution_payload_bid` so that the body root is consistent with
/// `state.latest_block_header.body_root`.
///
@@ -211,6 +222,11 @@ pub fn genesis_block<E: EthSpec>(
let bid = &mut block.body.signed_execution_payload_bid.message;
bid.block_hash = state_bid.block_hash;
bid.execution_requests_root = state_bid.execution_requests_root;
} else if let Ok(block) = block.as_heze_mut() {
let state_bid = genesis_state.latest_execution_payload_bid()?;
let bid = &mut block.body.signed_execution_payload_bid.message;
bid.block_hash = state_bid.block_hash;
bid.execution_requests_root = state_bid.execution_requests_root;
}
Ok(block)
}

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_gloas,
upgrade_to_electra, upgrade_to_fulu, upgrade_to_gloas, upgrade_to_heze,
};
use crate::{per_epoch_processing::EpochProcessingSummary, *};
use fixed_bytes::FixedBytesExtended;
@@ -103,6 +103,11 @@ pub fn per_slot_processing<E: EthSpec>(
upgrade_to_gloas(state, spec)?;
}
// Heze.
if spec.heze_fork_epoch == Some(state.current_epoch()) {
upgrade_to_heze(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

@@ -5,6 +5,7 @@ pub mod deneb;
pub mod electra;
pub mod fulu;
pub mod gloas;
pub mod heze;
pub use altair::upgrade_to_altair;
pub use bellatrix::upgrade_to_bellatrix;
@@ -13,3 +14,4 @@ pub use deneb::upgrade_to_deneb;
pub use electra::upgrade_to_electra;
pub use fulu::upgrade_to_fulu;
pub use gloas::upgrade_to_gloas;
pub use heze::upgrade_to_heze;

View File

@@ -0,0 +1,105 @@
use std::mem;
use types::{
BeaconState, BeaconStateError as Error, BeaconStateHeze, ChainSpec, EthSpec, Fork,
};
/// Transform a `Gloas` state into a `Heze` state.
pub fn upgrade_to_heze<E: EthSpec>(
pre_state: &mut BeaconState<E>,
spec: &ChainSpec,
) -> Result<(), Error> {
let post = upgrade_state_to_heze(pre_state, spec)?;
*pre_state = post;
Ok(())
}
pub fn upgrade_state_to_heze<E: EthSpec>(
pre_state: &mut BeaconState<E>,
spec: &ChainSpec,
) -> Result<BeaconState<E>, Error> {
let epoch = pre_state.current_epoch();
let pre = pre_state.as_gloas_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::Heze(BeaconStateHeze {
// 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.heze_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 Bid
latest_execution_payload_bid: pre.latest_execution_payload_bid.clone(),
// 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(),
proposer_lookahead: mem::take(&mut pre.proposer_lookahead),
// Gloas
builders: mem::take(&mut pre.builders),
next_withdrawal_builder_index: pre.next_withdrawal_builder_index,
execution_payload_availability: pre.execution_payload_availability.clone(),
builder_pending_payments: pre.builder_pending_payments.clone(),
builder_pending_withdrawals: mem::take(&mut pre.builder_pending_withdrawals),
latest_block_hash: pre.latest_block_hash,
payload_expected_withdrawals: mem::take(&mut pre.payload_expected_withdrawals),
ptc_window: pre.ptc_window.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),
});
Ok(post)
}