Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
62 changes: 42 additions & 20 deletions beacon_node/network/src/sync/block_lookups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub type SingleLookupId = u32;
enum Action {
Retry,
ParentUnknown { parent_root: Hash256 },
Drop,
Drop(/* reason: */ String),
Continue,
}

Expand Down Expand Up @@ -194,19 +194,22 @@ impl<T: BeaconChainTypes> BlockLookups<T> {

/// Creates a parent lookup for the block with the given `block_root` and immediately triggers it.
/// If a parent lookup exists or is triggered, a current lookup will be created.
///
/// Returns true if the lookup is created or already exists
#[instrument(parent = None,
level = "info",
fields(service = "lookup_sync"),
name = "lookup_sync",
skip_all
)]
#[must_use = "only reference the new lookup if returns true"]
pub fn search_child_and_parent(
&mut self,
block_root: Hash256,
block_component: BlockComponent<T::EthSpec>,
peer_id: PeerId,
cx: &mut SyncNetworkContext<T>,
) {
) -> bool {
let parent_root = block_component.parent_root();

let parent_lookup_exists =
Expand All @@ -223,25 +226,29 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
// the lookup with zero peers to house the block components.
&[],
cx,
);
)
} else {
false
}
}

/// Seach a block whose parent root is unknown.
///
/// Returns true if the lookup is created or already exists
#[instrument(parent = None,
level = "info",
fields(service = "lookup_sync"),
name = "lookup_sync",
skip_all
)]
#[must_use = "only reference the new lookup if returns true"]
pub fn search_unknown_block(
&mut self,
block_root: Hash256,
peer_source: &[PeerId],
cx: &mut SyncNetworkContext<T>,
) {
self.new_current_lookup(block_root, None, None, peer_source, cx);
) -> bool {
self.new_current_lookup(block_root, None, None, peer_source, cx)
}

/// A block or blob triggers the search of a parent.
Expand All @@ -256,6 +263,7 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
name = "lookup_sync",
skip_all
)]
#[must_use = "only reference the new lookup if returns true"]
pub fn search_parent_of_child(
&mut self,
block_root_to_search: Hash256,
Expand Down Expand Up @@ -363,6 +371,7 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
name = "lookup_sync",
skip_all
)]
#[must_use = "only reference the new lookup if returns true"]
fn new_current_lookup(
&mut self,
block_root: Hash256,
Expand Down Expand Up @@ -656,7 +665,7 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
// This is unreachable because RPC blocks do not undergo gossip verification, and
// this error can *only* come from gossip verification.
error!(?block_root, "Single block lookup hit unreachable condition");
Action::Drop
Action::Drop("DuplicateImportStatusUnknown".to_owned())
}
BlockProcessingResult::Ignored => {
// Beacon processor signalled to ignore the block processing result.
Expand All @@ -665,14 +674,14 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
component = ?R::response_type(),
"Lookup component processing ignored, cpu might be overloaded"
);
Action::Drop
Action::Drop("Block processing ignored".to_owned())
}
BlockProcessingResult::Err(e) => {
match e {
BlockError::BeaconChainError(e) => {
// Internal error
error!(%block_root, error = ?e, "Beacon chain error processing lookup component");
Action::Drop
Action::Drop(format!("{e:?}"))
}
BlockError::ParentUnknown { parent_root, .. } => {
// Reverts the status of this request to `AwaitingProcessing` holding the
Expand All @@ -691,7 +700,7 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
error = ?e,
"Single block lookup failed. Execution layer is offline / unsynced / misconfigured"
);
Action::Drop
Action::Drop(format!("{e:?}"))
}
BlockError::AvailabilityCheck(e)
if e.category() == AvailabilityCheckErrorCategory::Internal =>
Expand All @@ -703,7 +712,7 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
// lookup state transition. This error invalidates both blob and block requests, and we don't know the
// state of both requests. Blobs may have already successfullly processed for example.
// We opt to drop the lookup instead.
Action::Drop
Action::Drop(format!("{e:?}"))
}
other => {
debug!(
Expand Down Expand Up @@ -757,19 +766,32 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
}
Action::ParentUnknown { parent_root } => {
let peers = lookup.all_peers();
// Mark lookup as awaiting **before** creating the parent lookup. At this point the
// lookup maybe inconsistent.
lookup.set_awaiting_parent(parent_root);
debug!(
id = lookup.id,
?block_root,
?parent_root,
"Marking lookup as awaiting parent"
);
self.search_parent_of_child(parent_root, block_root, &peers, cx);
Ok(LookupResult::Pending)
let parent_lookup_exists =
self.search_parent_of_child(parent_root, block_root, &peers, cx);
if parent_lookup_exists {
// The parent lookup exist or has been created. It's safe for `lookup` to
// reference the parent as awaiting.
debug!(
id = lookup_id,
?block_root,
?parent_root,
"Marking lookup as awaiting parent"
);
Ok(LookupResult::Pending)
} else {
// The parent lookup is faulty and was not created, we must drop the `lookup` as
// it's in an inconsistent state. We must drop all of its children too.
Err(LookupRequestError::Failed(format!(
"Parent lookup is faulty {parent_root:?}"
)))
}
}
Action::Drop => {
Action::Drop(reason) => {
// Drop with noop
Err(LookupRequestError::Failed)
Err(LookupRequestError::Failed(reason))
}
Action::Continue => {
// Drop this completed lookup only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub enum LookupRequestError {
/// Inconsistent lookup request state
BadState(String),
/// Lookup failed for some other reason and should be dropped
Failed,
Failed(/* reason: */ String),
/// Received MissingComponents when all components have been processed. This should never
/// happen, and indicates some internal bug
MissingComponentsAfterAllProcessed,
Expand Down
23 changes: 19 additions & 4 deletions beacon_node/network/src/sync/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,12 +909,20 @@ impl<T: BeaconChainTypes> SyncManager<T> {
) {
match self.should_search_for_block(Some(slot), &peer_id) {
Ok(_) => {
self.block_lookups.search_child_and_parent(
if self.block_lookups.search_child_and_parent(
block_root,
block_component,
peer_id,
&mut self.network,
);
) {
// Lookup created. No need to log here it's logged in `new_current_lookup`
} else {
debug!(
?block_root,
?parent_root,
"No lookup created for child and parent"
);
}
}
Err(reason) => {
debug!(%block_root, %parent_root, reason, "Ignoring unknown parent request");
Expand All @@ -925,8 +933,15 @@ impl<T: BeaconChainTypes> SyncManager<T> {
fn handle_unknown_block_root(&mut self, peer_id: PeerId, block_root: Hash256) {
match self.should_search_for_block(None, &peer_id) {
Ok(_) => {
self.block_lookups
.search_unknown_block(block_root, &[peer_id], &mut self.network);
if self.block_lookups.search_unknown_block(
block_root,
&[peer_id],
&mut self.network,
) {
// Lookup created. No need to log here it's logged in `new_current_lookup`
} else {
debug!(?block_root, "No lookup created for unknown block");
}
}
Err(reason) => {
debug!(%block_root, reason, "Ignoring unknown block request");
Expand Down
Loading