Skip to content

Commit 531fc8d

Browse files
committed
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.
1 parent 5e33160 commit 531fc8d

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

beacon_node/beacon_chain/src/beacon_chain.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ pub enum ProduceBlockVerification {
197197
pub struct PrePayloadAttributes {
198198
pub proposer_index: u64,
199199
pub prev_randao: Hash256,
200+
/// The parent block number is not part of the payload attributes sent to the EL, but *is*
201+
/// sent to builders via SSE.
202+
pub parent_block_number: u64,
200203
}
201204

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

3869-
// Get the `prev_randao` value.
3870-
let prev_randao = if proposer_head == parent_block_root {
3871-
cached_head.parent_random()
3872+
// Get the `prev_randao` and parent block number.
3873+
let head_block_number = cached_head.head_block_number()?;
3874+
let (prev_randao, parent_block_number) = if proposer_head == parent_block_root {
3875+
(
3876+
cached_head.parent_random()?,
3877+
head_block_number.saturating_sub(1),
3878+
)
38723879
} else {
3873-
cached_head.head_random()
3874-
}?;
3880+
(cached_head.head_random()?, head_block_number)
3881+
};
38753882

38763883
Ok(Some(PrePayloadAttributes {
38773884
proposer_index,
38783885
prev_randao,
3886+
parent_block_number,
38793887
}))
38803888
}
38813889

@@ -4865,6 +4873,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
48654873
proposal_slot: prepare_slot,
48664874
proposer_index: proposer,
48674875
parent_block_root: head_root,
4876+
parent_block_number: pre_payload_attributes.parent_block_number,
48684877
parent_block_hash: forkchoice_update_params.head_hash.unwrap_or_default(),
48694878
payload_attributes: payload_attributes.into(),
48704879
},

beacon_node/beacon_chain/src/canonical_head.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,17 @@ impl<E: EthSpec> CachedHead<E> {
167167
.map(|payload| payload.prev_randao())
168168
}
169169

170+
/// Returns the execution block number of the block at the head of the chain.
171+
///
172+
/// Returns an error if the chain is prior to Bellatrix.
173+
pub fn head_block_number(&self) -> Result<u64, BeaconStateError> {
174+
self.snapshot
175+
.beacon_block
176+
.message()
177+
.execution_payload()
178+
.map(|payload| payload.block_number())
179+
}
180+
170181
/// Returns the active validator count for the current epoch of the head state.
171182
///
172183
/// Should only return `None` if the caches have not been built on the head state (this should

beacon_node/execution_layer/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use types::{
4747

4848
mod block_hash;
4949
mod engine_api;
50-
mod engines;
50+
pub mod engines;
5151
mod keccak;
5252
mod metrics;
5353
pub mod payload_cache;

common/eth2/src/types.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,8 @@ pub struct SseExtendedPayloadAttributesGeneric<T> {
921921
#[serde(with = "eth2_serde_utils::quoted_u64")]
922922
pub proposer_index: u64,
923923
pub parent_block_root: Hash256,
924+
#[serde(with = "eth2_serde_utils::quoted_u64")]
925+
pub parent_block_number: u64,
924926
pub parent_block_hash: ExecutionBlockHash,
925927
pub payload_attributes: T,
926928
}
@@ -958,6 +960,7 @@ impl ForkVersionDeserialize for SseExtendedPayloadAttributes {
958960
proposal_slot: helper.proposal_slot,
959961
proposer_index: helper.proposer_index,
960962
parent_block_root: helper.parent_block_root,
963+
parent_block_number: helper.parent_block_number,
961964
parent_block_hash: helper.parent_block_hash,
962965
payload_attributes: SsePayloadAttributes::deserialize_by_fork::<D>(
963966
helper.payload_attributes,

0 commit comments

Comments
 (0)