mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 00:42:42 +00:00
fix: restore genesis_block bid population for ef-tests
The alpha-7 spec tests expect the Gloas genesis block body to contain the execution payload bid from state. Restores the genesis_block() function and body_root fixup that were removed in PR #9244. The fork choice from_anchor fix (reading latest_block_hash when bid hashes are zero) remains for Kurtosis/external genesis compatibility.
This commit is contained in:
@@ -167,12 +167,19 @@ pub fn initialize_beacon_state_from_eth1<E: EthSpec>(
|
|||||||
// Remove intermediate Fulu fork from `state.fork`.
|
// Remove intermediate Fulu fork from `state.fork`.
|
||||||
state.fork_mut().previous_version = spec.gloas_fork_version;
|
state.fork_mut().previous_version = spec.gloas_fork_version;
|
||||||
|
|
||||||
|
// The genesis block's bid must have block_hash = 0x00 per spec (empty payload).
|
||||||
// Retain the EL genesis hash in latest_block_hash and parent_block_hash so the
|
// Retain the EL genesis hash in latest_block_hash and parent_block_hash so the
|
||||||
// first post-genesis proposer can build on the correct EL head.
|
// first post-genesis proposer can build on the correct EL head.
|
||||||
let el_genesis_hash = state.latest_execution_payload_bid()?.block_hash;
|
let el_genesis_hash = state.latest_execution_payload_bid()?.block_hash;
|
||||||
let bid = state.latest_execution_payload_bid_mut()?;
|
let bid = state.latest_execution_payload_bid_mut()?;
|
||||||
bid.parent_block_hash = el_genesis_hash;
|
bid.parent_block_hash = el_genesis_hash;
|
||||||
bid.block_hash = ExecutionBlockHash::default();
|
bid.block_hash = ExecutionBlockHash::default();
|
||||||
|
|
||||||
|
// Update the `latest_block_header.body_root` so that it matches the body of the
|
||||||
|
// Gloas genesis block, which embeds `state.latest_execution_payload_bid` in its
|
||||||
|
// `signed_execution_payload_bid` field (see `genesis_block`).
|
||||||
|
let genesis_body_root = genesis_block(&state, spec)?.body_root();
|
||||||
|
state.latest_block_header_mut().body_root = genesis_body_root;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now that we have our validators, initialize the caches (including the committees)
|
// Now that we have our validators, initialize the caches (including the committees)
|
||||||
@@ -184,16 +191,25 @@ pub fn initialize_beacon_state_from_eth1<E: EthSpec>(
|
|||||||
Ok(state)
|
Ok(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create an unsigned genesis `BeaconBlock` matching the genesis state.
|
/// Create an unsigned genesis `BeaconBlock`.
|
||||||
///
|
///
|
||||||
/// Per spec, the genesis block body is empty (all default fields).
|
/// Per spec, the genesis block body is empty (all default fields) except for Gloas,
|
||||||
/// `state.latest_block_header.body_root` is set from `BeaconBlock::empty()`,
|
/// where `body.signed_execution_payload_bid.message` is initialised from
|
||||||
/// so this function must return the same empty block to keep roots consistent.
|
/// `state.latest_execution_payload_bid` so that the first post-genesis proposer can
|
||||||
|
/// build on the correct execution layer head.
|
||||||
|
///
|
||||||
|
/// `state.latest_block_header.body_root` is set from this same block's body, so the
|
||||||
|
/// two must stay in sync.
|
||||||
pub fn genesis_block<E: EthSpec>(
|
pub fn genesis_block<E: EthSpec>(
|
||||||
_genesis_state: &BeaconState<E>,
|
state: &BeaconState<E>,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
) -> Result<BeaconBlock<E>, BeaconStateError> {
|
) -> Result<BeaconBlock<E>, BeaconStateError> {
|
||||||
Ok(BeaconBlock::empty(spec))
|
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;
|
||||||
|
}
|
||||||
|
Ok(block)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determine whether a candidate genesis state is suitable for starting the chain.
|
/// Determine whether a candidate genesis state is suitable for starting the chain.
|
||||||
|
|||||||
Reference in New Issue
Block a user