Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions beacon_node/beacon_chain/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ use tracing::{debug, error, info, warn};
use tree_hash::TreeHash;
use types::data::CustodyIndex;
use types::{
BeaconState, BlobSidecarList, ChainSpec, ColumnIndex, DataColumnSidecarList, Epoch, EthSpec,
Hash256, SignedBeaconBlock, Slot,
BeaconBlock, BeaconState, BlobSidecarList, ChainSpec, ColumnIndex, DataColumnSidecarList,
Epoch, EthSpec, Hash256, SignedBeaconBlock, Slot,
};

/// An empty struct used to "witness" all the `BeaconChainTypes` traits. It has no user-facing
Expand Down Expand Up @@ -1177,9 +1177,21 @@ fn make_genesis_block<E: EthSpec>(
genesis_state: &mut BeaconState<E>,
spec: &ChainSpec,
) -> Result<SignedBeaconBlock<E>, String> {
// For Gloas, genesis_block() populates the bid in the block body. However, if
// the genesis state was produced by an external tool (e.g. ethereum-genesis-generator),
// its latest_block_header.body_root may correspond to an empty block. In that case,
// use an empty block so the stored block root matches what fork choice derives from
// the state's latest_block_header.
let mut block = genesis_block(genesis_state, spec)
.map_err(|e| format!("Error building genesis block: {:?}", e))?;

let state_body_root = genesis_state.latest_block_header().body_root;
if state_body_root != block.body_root()
&& state_body_root == BeaconBlock::<E>::empty(spec).body_root()
{
block = BeaconBlock::empty(spec);
}

*block.state_root_mut() = genesis_state
.update_tree_hash_cache()
.map_err(|e| format!("Error hashing genesis state: {:?}", e))?;
Expand Down
19 changes: 16 additions & 3 deletions consensus/fork_choice/src/fork_choice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,24 @@ where

let (execution_status, execution_payload_parent_hash, execution_payload_block_hash) =
if let Ok(signed_bid) = anchor_block.message().body().signed_execution_payload_bid() {
// Gloas: execution status is irrelevant post-Gloas; payload validation
// is decoupled from beacon blocks.
// At Gloas genesis the block bid is empty (all zeros) per spec, but the
// state holds the EL genesis hash in `latest_block_hash`. Use it so the
// first forkchoice update sends a valid head to the EL.
let parent_hash = if anchor_block.slot() == spec.genesis_slot
&& anchor_state.slot() == spec.genesis_slot
&& signed_bid.message.parent_block_hash.into_root().is_zero()
&& signed_bid.message.block_hash.into_root().is_zero()
{
*anchor_state
.latest_block_hash()
.map_err(Error::BeaconStateError)?
} else {
signed_bid.message.parent_block_hash
};

(
ExecutionStatus::irrelevant(),
Some(signed_bid.message.parent_block_hash),
Some(parent_hash),
Some(signed_bid.message.block_hash),
)
} else if let Ok(execution_payload) = anchor_block.message().execution_payload() {
Expand Down
Loading