diff --git a/beacon_node/network/src/sync/block_lookups/mod.rs b/beacon_node/network/src/sync/block_lookups/mod.rs index 48dda03facd..73ed3a92c10 100644 --- a/beacon_node/network/src/sync/block_lookups/mod.rs +++ b/beacon_node/network/src/sync/block_lookups/mod.rs @@ -298,9 +298,12 @@ impl BlockLookups { }; let result = lookup.continue_requests(cx); - self.on_lookup_result(id, result, "new_current_lookup", cx); - self.update_metrics(); - true + if self.on_lookup_result(id, result, "new_current_lookup", cx) { + self.update_metrics(); + true + } else { + false + } } /* Lookup responses */ @@ -622,15 +625,16 @@ impl BlockLookups { } /// Common handler a lookup request error, drop it and update metrics + /// Returns true if the lookup is created or already exists fn on_lookup_result( &mut self, id: SingleLookupId, result: Result, source: &str, cx: &mut SyncNetworkContext, - ) { + ) -> bool { match result { - Ok(LookupResult::Pending) => {} // no action + Ok(LookupResult::Pending) => true, // no action Ok(LookupResult::Completed) => { if let Some(lookup) = self.single_block_lookups.remove(&id) { debug!(self.log, "Dropping completed lookup"; "block" => ?lookup.block_root(), "id" => id); @@ -641,12 +645,14 @@ impl BlockLookups { } else { debug!(self.log, "Attempting to drop non-existent lookup"; "id" => id); } + false } Err(error) => { debug!(self.log, "Dropping lookup on request error"; "id" => id, "source" => source, "error" => ?error); metrics::inc_counter_vec(&metrics::SYNC_LOOKUP_DROPPED, &[error.into()]); self.drop_lookup_and_children(id); self.update_metrics(); + false } } }