Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Add parent_block_number to payload SSE #4053

Closed
Closed
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
19 changes: 14 additions & 5 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ pub enum ProduceBlockVerification {
pub struct PrePayloadAttributes {
pub proposer_index: u64,
pub prev_randao: Hash256,
/// The parent block number is not part of the payload attributes sent to the EL, but *is*
/// sent to builders via SSE.
pub parent_block_number: u64,
}

/// Define whether a forkchoiceUpdate needs to be checked for an override (`Yes`) or has already
Expand Down Expand Up @@ -3866,16 +3869,21 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
proposer as u64
};

// Get the `prev_randao` value.
let prev_randao = if proposer_head == parent_block_root {
cached_head.parent_random()
// Get the `prev_randao` and parent block number.
let head_block_number = cached_head.head_block_number()?;
let (prev_randao, parent_block_number) = if proposer_head == parent_block_root {
(
cached_head.parent_random()?,
head_block_number.saturating_sub(1),
)
} else {
cached_head.head_random()
}?;
(cached_head.head_random()?, head_block_number)
};

Ok(Some(PrePayloadAttributes {
proposer_index,
prev_randao,
parent_block_number,
}))
}

Expand Down Expand Up @@ -4865,6 +4873,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
proposal_slot: prepare_slot,
proposer_index: proposer,
parent_block_root: head_root,
parent_block_number: pre_payload_attributes.parent_block_number,
parent_block_hash: forkchoice_update_params.head_hash.unwrap_or_default(),
payload_attributes: payload_attributes.into(),
},
Expand Down
11 changes: 11 additions & 0 deletions beacon_node/beacon_chain/src/canonical_head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ impl<E: EthSpec> CachedHead<E> {
.map(|payload| payload.prev_randao())
}

/// Returns the execution block number of the block at the head of the chain.
///
/// Returns an error if the chain is prior to Bellatrix.
pub fn head_block_number(&self) -> Result<u64, BeaconStateError> {
self.snapshot
.beacon_block
.message()
.execution_payload()
.map(|payload| payload.block_number())
}

/// Returns the active validator count for the current epoch of the head state.
///
/// Should only return `None` if the caches have not been built on the head state (this should
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/execution_layer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use types::{

mod block_hash;
mod engine_api;
mod engines;
pub mod engines;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a sneaky change to support eleel.

mod keccak;
mod metrics;
pub mod payload_cache;
Expand Down
3 changes: 3 additions & 0 deletions common/eth2/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,8 @@ pub struct SseExtendedPayloadAttributesGeneric<T> {
#[serde(with = "eth2_serde_utils::quoted_u64")]
pub proposer_index: u64,
pub parent_block_root: Hash256,
#[serde(with = "eth2_serde_utils::quoted_u64")]
pub parent_block_number: u64,
pub parent_block_hash: ExecutionBlockHash,
pub payload_attributes: T,
}
Expand Down Expand Up @@ -958,6 +960,7 @@ impl ForkVersionDeserialize for SseExtendedPayloadAttributes {
proposal_slot: helper.proposal_slot,
proposer_index: helper.proposer_index,
parent_block_root: helper.parent_block_root,
parent_block_number: helper.parent_block_number,
parent_block_hash: helper.parent_block_hash,
payload_attributes: SsePayloadAttributes::deserialize_by_fork::<D>(
helper.payload_attributes,
Expand Down