Merge conflicts

This commit is contained in:
Eitan Seri-Levi
2026-04-30 09:48:04 +02:00
86 changed files with 2835 additions and 1038 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

@@ -4,8 +4,8 @@ use super::per_block_processing::{
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_eip7805, upgrade_to_fulu, upgrade_to_gloas,
upgrade_to_altair, upgrade_to_bellatrix, upgrade_to_capella, upgrade_to_deneb, upgrade_to_fulu,
upgrade_to_gloas, upgrade_to_heze,
};
use fixed_bytes::FixedBytesExtended;
use safe_arith::{ArithError, SafeArith};
@@ -141,22 +141,6 @@ pub fn initialize_beacon_state_from_eth1<E: EthSpec>(
}
}
// Upgrade to eip7805 if configured from genesis.
if spec
.eip7805_fork_epoch
.is_some_and(|fork_epoch| fork_epoch == E::genesis_epoch())
{
upgrade_to_eip7805(&mut state, spec)?;
// Remove intermediate Electra fork from `state.fork`.
state.fork_mut().previous_version = spec.eip7805_fork_version;
// Override latest execution payload header.
if let Some(ExecutionPayloadHeader::Eip7805(ref header)) = execution_payload_header {
*state.latest_execution_payload_header_eip7805_mut()? = header.clone();
}
}
// Upgrade to fulu if configured from genesis.
if spec
.fulu_fork_epoch
@@ -198,6 +182,17 @@ pub fn initialize_beacon_state_from_eth1<E: EthSpec>(
state.latest_block_header_mut().body_root = genesis_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)?;
@@ -209,10 +204,9 @@ pub fn initialize_beacon_state_from_eth1<E: EthSpec>(
/// Create an unsigned genesis `BeaconBlock`.
///
/// Per spec, the genesis block body is empty (all default fields) except for Gloas,
/// where `body.signed_execution_payload_bid.message` is initialised from
/// `state.latest_execution_payload_bid` so that the first post-genesis proposer can
/// build on the correct execution layer head.
/// 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`.
///
/// `state.latest_block_header.body_root` is set from this same block's body, so the
/// two must stay in sync.
@@ -221,9 +215,16 @@ pub fn genesis_block<E: EthSpec>(
spec: &ChainSpec,
) -> Result<BeaconBlock<E>, BeaconStateError> {
let mut block = BeaconBlock::empty(spec);
if let BeaconBlock::Gloas(ref mut gloas_block) = block {
let bid = state.latest_execution_payload_bid()?.clone();
gloas_block.body.signed_execution_payload_bid.message = bid;
if let Ok(block) = block.as_gloas_mut() {
let state_bid = 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;
} else if let Ok(block) = block.as_heze_mut() {
let state_bid = 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

@@ -472,9 +472,9 @@ pub fn process_execution_payload<E: EthSpec, Payload: AbstractExecPayload<E>>(
_ => return Err(BlockProcessingError::IncorrectStateType),
}
}
ExecutionPayloadHeaderRefMut::Eip7805(header_mut) => {
ExecutionPayloadHeaderRefMut::Heze(header_mut) => {
match payload.to_execution_payload_header() {
ExecutionPayloadHeader::Eip7805(header) => *header_mut = header,
ExecutionPayloadHeader::Heze(header) => *header_mut = header,
_ => return Err(BlockProcessingError::IncorrectStateType),
}
}

View File

@@ -1,6 +1,6 @@
use crate::upgrade::{
upgrade_to_altair, upgrade_to_bellatrix, upgrade_to_capella, upgrade_to_deneb,
upgrade_to_eip7805, 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;
@@ -96,15 +96,20 @@ pub fn per_slot_processing<E: EthSpec>(
if spec.fulu_fork_epoch == Some(state.current_epoch()) {
upgrade_to_fulu(state, spec)?;
}
// Eip7805.
if spec.eip7805_fork_epoch == Some(state.current_epoch()) {
upgrade_to_eip7805(state, spec)?;
// Heze.
if spec.heze_fork_epoch == Some(state.current_epoch()) {
upgrade_to_heze(state, spec)?;
}
// Gloas.
if spec.gloas_fork_epoch == Some(state.current_epoch()) {
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

@@ -2,16 +2,16 @@ pub mod altair;
pub mod bellatrix;
pub mod capella;
pub mod deneb;
pub mod eip7805;
pub mod electra;
pub mod fulu;
pub mod gloas;
pub mod heze;
pub use altair::upgrade_to_altair;
pub use bellatrix::upgrade_to_bellatrix;
pub use capella::upgrade_to_capella;
pub use deneb::upgrade_to_deneb;
pub use eip7805::upgrade_to_eip7805;
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

@@ -1,39 +1,37 @@
use std::mem;
use types::{BeaconState, BeaconStateEip7805, BeaconStateError as Error, ChainSpec, EthSpec, Fork};
use types::{BeaconState, BeaconStateError as Error, BeaconStateHeze, ChainSpec, EthSpec, Fork};
/// Transform a `Electra` state into an `Eip7805s` state.
pub fn upgrade_to_eip7805<E: EthSpec>(
/// 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 _epoch = pre_state.current_epoch();
let post = upgrade_state_to_eip7805(pre_state, spec)?;
let post = upgrade_state_to_heze(pre_state, spec)?;
*pre_state = post;
Ok(())
}
pub fn upgrade_state_to_eip7805<E: EthSpec>(
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_fulu_mut()?;
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::Eip7805(BeaconStateEip7805 {
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.eip7805_fork_version,
current_version: spec.heze_fork_version,
epoch,
},
// History
@@ -52,7 +50,7 @@ pub fn upgrade_state_to_eip7805<E: EthSpec>(
randao_mixes: pre.randao_mixes.clone(),
// Slashings
slashings: pre.slashings.clone(),
// `Participation
// Participation
previous_epoch_participation: mem::take(&mut pre.previous_epoch_participation),
current_epoch_participation: mem::take(&mut pre.current_epoch_participation),
// Finality
@@ -65,8 +63,8 @@ pub fn upgrade_state_to_eip7805<E: EthSpec>(
// 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_eip7805(),
// 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,
@@ -81,6 +79,16 @@ pub fn upgrade_state_to_eip7805<E: EthSpec>(
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),
@@ -89,7 +97,7 @@ pub fn upgrade_state_to_eip7805<E: EthSpec>(
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: pre.proposer_lookahead.clone(),
});
Ok(post)
}