Add parent_block_number to payload SSE (#4053)
## Issue Addressed In #4027 I forgot to add the `parent_block_number` to the payload attributes SSE. ## Proposed Changes Compute the parent block number while computing the pre-payload attributes. Pass it on to the SSE stream. ## Additional Info Not essential for v3.5.1 as I suspect most builders don't need the `parent_block_root`. I would like to use it for my dummy no-op builder however.
This commit is contained in:
parent
e190ebb8a0
commit
36e163c042
@ -197,6 +197,9 @@ pub enum ProduceBlockVerification {
|
|||||||
pub struct PrePayloadAttributes {
|
pub struct PrePayloadAttributes {
|
||||||
pub proposer_index: u64,
|
pub proposer_index: u64,
|
||||||
pub prev_randao: Hash256,
|
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
|
/// Define whether a forkchoiceUpdate needs to be checked for an override (`Yes`) or has already
|
||||||
@ -3866,16 +3869,21 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
|||||||
proposer as u64
|
proposer as u64
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get the `prev_randao` value.
|
// Get the `prev_randao` and parent block number.
|
||||||
let prev_randao = if proposer_head == parent_block_root {
|
let head_block_number = cached_head.head_block_number()?;
|
||||||
cached_head.parent_random()
|
let (prev_randao, parent_block_number) = if proposer_head == parent_block_root {
|
||||||
|
(
|
||||||
|
cached_head.parent_random()?,
|
||||||
|
head_block_number.saturating_sub(1),
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
cached_head.head_random()
|
(cached_head.head_random()?, head_block_number)
|
||||||
}?;
|
};
|
||||||
|
|
||||||
Ok(Some(PrePayloadAttributes {
|
Ok(Some(PrePayloadAttributes {
|
||||||
proposer_index,
|
proposer_index,
|
||||||
prev_randao,
|
prev_randao,
|
||||||
|
parent_block_number,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4865,6 +4873,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
|||||||
proposal_slot: prepare_slot,
|
proposal_slot: prepare_slot,
|
||||||
proposer_index: proposer,
|
proposer_index: proposer,
|
||||||
parent_block_root: head_root,
|
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(),
|
parent_block_hash: forkchoice_update_params.head_hash.unwrap_or_default(),
|
||||||
payload_attributes: payload_attributes.into(),
|
payload_attributes: payload_attributes.into(),
|
||||||
},
|
},
|
||||||
|
@ -167,6 +167,17 @@ impl<E: EthSpec> CachedHead<E> {
|
|||||||
.map(|payload| payload.prev_randao())
|
.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.
|
/// 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
|
/// Should only return `None` if the caches have not been built on the head state (this should
|
||||||
|
@ -47,7 +47,7 @@ use types::{
|
|||||||
|
|
||||||
mod block_hash;
|
mod block_hash;
|
||||||
mod engine_api;
|
mod engine_api;
|
||||||
mod engines;
|
pub mod engines;
|
||||||
mod keccak;
|
mod keccak;
|
||||||
mod metrics;
|
mod metrics;
|
||||||
pub mod payload_cache;
|
pub mod payload_cache;
|
||||||
|
@ -921,6 +921,8 @@ pub struct SseExtendedPayloadAttributesGeneric<T> {
|
|||||||
#[serde(with = "eth2_serde_utils::quoted_u64")]
|
#[serde(with = "eth2_serde_utils::quoted_u64")]
|
||||||
pub proposer_index: u64,
|
pub proposer_index: u64,
|
||||||
pub parent_block_root: Hash256,
|
pub parent_block_root: Hash256,
|
||||||
|
#[serde(with = "eth2_serde_utils::quoted_u64")]
|
||||||
|
pub parent_block_number: u64,
|
||||||
pub parent_block_hash: ExecutionBlockHash,
|
pub parent_block_hash: ExecutionBlockHash,
|
||||||
pub payload_attributes: T,
|
pub payload_attributes: T,
|
||||||
}
|
}
|
||||||
@ -958,6 +960,7 @@ impl ForkVersionDeserialize for SseExtendedPayloadAttributes {
|
|||||||
proposal_slot: helper.proposal_slot,
|
proposal_slot: helper.proposal_slot,
|
||||||
proposer_index: helper.proposer_index,
|
proposer_index: helper.proposer_index,
|
||||||
parent_block_root: helper.parent_block_root,
|
parent_block_root: helper.parent_block_root,
|
||||||
|
parent_block_number: helper.parent_block_number,
|
||||||
parent_block_hash: helper.parent_block_hash,
|
parent_block_hash: helper.parent_block_hash,
|
||||||
payload_attributes: SsePayloadAttributes::deserialize_by_fork::<D>(
|
payload_attributes: SsePayloadAttributes::deserialize_by_fork::<D>(
|
||||||
helper.payload_attributes,
|
helper.payload_attributes,
|
||||||
|
Loading…
Reference in New Issue
Block a user