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

Add logging in UnknownBlockHashFromAttestation handling #5546

Merged
merged 2 commits into from
Apr 10, 2024
Merged
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
37 changes: 20 additions & 17 deletions beacon_node/network/src/sync/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,12 +680,8 @@ impl<T: BeaconChainTypes> SyncManager<T> {
);
}
SyncMessage::UnknownBlockHashFromAttestation(peer_id, block_root) => {
// If we are not synced, ignore this block.
if self.synced_and_connected(&peer_id) {
debug!(self.log, "Received sync_message"; "message" => "UnknownBlockHashFromAttestation", "block_root" => %block_root);
self.block_lookups
.search_block(block_root, &[peer_id], &mut self.network);
}
debug!(self.log, "Received unknown block hash message"; "block_root" => %block_root);
self.handle_unknown_block_root(peer_id, block_root);
}
SyncMessage::Disconnect(peer_id) => {
self.peer_disconnect(&peer_id);
Expand Down Expand Up @@ -757,7 +753,7 @@ impl<T: BeaconChainTypes> SyncManager<T> {
slot: Slot,
child_components: ChildComponents<T::EthSpec>,
) {
match self.should_search_for_block(slot, &peer_id) {
match self.should_search_for_block(Some(slot), &peer_id) {
Ok(_) => {
self.block_lookups.search_parent(
slot,
Expand All @@ -779,12 +775,28 @@ 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_block(block_root, &[peer_id], &mut self.network);
}
Err(reason) => {
debug!(self.log, "Ignoring unknown block request"; "block_root" => %block_root, "reason" => reason);
}
}
}

fn should_search_for_block(
&mut self,
block_slot: Slot,
block_slot: Option<Slot>,
peer_id: &PeerId,
) -> Result<(), &'static str> {
if !self.network_globals().sync_state.read().is_synced() {
let Some(block_slot) = block_slot else {
return Err("not synced");
};

let head_slot = self.chain.canonical_head.cached_head().head_slot();

// if the block is far in the future, ignore it. If its within the slot tolerance of
Expand All @@ -807,15 +819,6 @@ impl<T: BeaconChainTypes> SyncManager<T> {
Ok(())
}

fn synced(&mut self) -> bool {
self.network_globals().sync_state.read().is_synced()
&& self.network.is_execution_engine_online()
}

fn synced_and_connected(&mut self, peer_id: &PeerId) -> bool {
self.synced() && self.network_globals().peers.read().is_connected(peer_id)
}

fn handle_new_execution_engine_state(&mut self, engine_state: EngineState) {
self.network.update_execution_engine_state(engine_state);

Expand Down