When a block comes in whose parent is unkown, queue the block for processing and lookup the parent envelope

This commit is contained in:
Eitan Seri- Levi
2026-03-26 23:40:35 -07:00
parent e1a2cfe202
commit 09e9a54314
14 changed files with 608 additions and 43 deletions

View File

@@ -74,7 +74,8 @@ use strum::IntoStaticStr;
use tokio::sync::mpsc;
use tracing::{debug, error, info, trace};
use types::{
BlobSidecar, DataColumnSidecar, EthSpec, ForkContext, Hash256, SignedBeaconBlock, Slot,
BlobSidecar, DataColumnSidecar, EthSpec, ForkContext, Hash256, SignedBeaconBlock,
SignedExecutionPayloadEnvelope, Slot,
};
/// The number of slots ahead of us that is allowed before requesting a long-range (batch) Sync
@@ -133,6 +134,14 @@ pub enum SyncMessage<E: EthSpec> {
seen_timestamp: Duration,
},
/// An execution payload envelope has been received from the RPC.
RpcPayloadEnvelope {
sync_request_id: SyncRequestId,
peer_id: PeerId,
envelope: Option<Arc<SignedExecutionPayloadEnvelope<E>>>,
seen_timestamp: Duration,
},
/// A block with an unknown parent has been received.
UnknownParentBlock(PeerId, Arc<SignedBeaconBlock<E>>, Hash256),
@@ -142,6 +151,9 @@ pub enum SyncMessage<E: EthSpec> {
/// A data column with an unknown parent has been received.
UnknownParentDataColumn(PeerId, Arc<DataColumnSidecar<E>>),
/// A block's parent is known but its execution payload envelope has not been received yet.
UnknownParentEnvelope(PeerId, Arc<SignedBeaconBlock<E>>, Hash256),
/// A peer has sent an attestation that references a block that is unknown. This triggers the
/// manager to attempt to find the block matching the unknown hash.
UnknownBlockHashFromAttestation(PeerId, Hash256),
@@ -184,6 +196,7 @@ pub enum BlockProcessType {
SingleBlock { id: Id },
SingleBlob { id: Id },
SingleCustodyColumn(Id),
SinglePayloadEnvelope { id: Id, block_root: Hash256 },
}
impl BlockProcessType {
@@ -191,7 +204,8 @@ impl BlockProcessType {
match self {
BlockProcessType::SingleBlock { id }
| BlockProcessType::SingleBlob { id }
| BlockProcessType::SingleCustodyColumn(id) => *id,
| BlockProcessType::SingleCustodyColumn(id)
| BlockProcessType::SinglePayloadEnvelope { id, .. } => *id,
}
}
}
@@ -505,6 +519,9 @@ impl<T: BeaconChainTypes> SyncManager<T> {
SyncRequestId::DataColumnsByRange(req_id) => {
self.on_data_columns_by_range_response(req_id, peer_id, RpcEvent::RPCError(error))
}
SyncRequestId::SinglePayloadEnvelope { id } => {
self.on_single_envelope_response(id, peer_id, RpcEvent::RPCError(error))
}
}
}
@@ -839,6 +856,17 @@ impl<T: BeaconChainTypes> SyncManager<T> {
} => {
self.rpc_data_column_received(sync_request_id, peer_id, data_column, seen_timestamp)
}
SyncMessage::RpcPayloadEnvelope {
sync_request_id,
peer_id,
envelope,
seen_timestamp,
} => self.rpc_payload_envelope_received(
sync_request_id,
peer_id,
envelope,
seen_timestamp,
),
SyncMessage::UnknownParentBlock(peer_id, block, block_root) => {
let block_slot = block.slot();
let parent_root = block.parent_root();
@@ -900,6 +928,27 @@ impl<T: BeaconChainTypes> SyncManager<T> {
}
}
}
SyncMessage::UnknownParentEnvelope(peer_id, block, block_root) => {
let block_slot = block.slot();
let parent_root = block.parent_root();
debug!(
%block_root,
%parent_root,
"Parent envelope not yet available, creating lookup"
);
self.handle_unknown_parent(
peer_id,
block_root,
parent_root,
block_slot,
BlockComponent::Block(DownloadResult {
value: block.block_cloned(),
block_root,
seen_timestamp: timestamp_now(),
peer_group: PeerGroup::from_single(peer_id),
}),
);
}
SyncMessage::UnknownBlockHashFromAttestation(peer_id, block_root) => {
if !self.notified_unknown_roots.contains(&(peer_id, block_root)) {
self.notified_unknown_roots.insert((peer_id, block_root));
@@ -1200,6 +1249,59 @@ impl<T: BeaconChainTypes> SyncManager<T> {
}
}
fn rpc_payload_envelope_received(
&mut self,
sync_request_id: SyncRequestId,
peer_id: PeerId,
envelope: Option<Arc<SignedExecutionPayloadEnvelope<T::EthSpec>>>,
seen_timestamp: Duration,
) {
match sync_request_id {
SyncRequestId::SinglePayloadEnvelope { id } => self.on_single_envelope_response(
id,
peer_id,
RpcEvent::from_chunk(envelope, seen_timestamp),
),
_ => {
crit!(%peer_id, "bad request id for payload envelope");
}
}
}
fn on_single_envelope_response(
&mut self,
id: SingleLookupReqId,
peer_id: PeerId,
rpc_event: RpcEvent<Arc<SignedExecutionPayloadEnvelope<T::EthSpec>>>,
) {
if let Some(resp) = self
.network
.on_single_envelope_response(id, peer_id, rpc_event)
{
match resp {
Ok((envelope, seen_timestamp)) => {
let block_root = envelope.beacon_block_root();
debug!(
?block_root,
%id,
"Downloaded payload envelope, sending for processing"
);
if let Err(e) = self.network.send_envelope_for_processing(
id.req_id,
envelope,
seen_timestamp,
block_root,
) {
error!(error = ?e, "Failed to send envelope for processing");
}
}
Err(e) => {
debug!(error = ?e, %id, "Payload envelope download failed");
}
}
}
}
fn on_single_blob_response(
&mut self,
id: SingleLookupReqId,