mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 16:55:46 +00:00
Attempt to continue lookups after adding peers (#5993)
* Attempt to continue lookups after adding peers
This commit is contained in:
@@ -291,7 +291,7 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = self.add_peers_to_lookup_and_ancestors(lookup_id, peers) {
|
if let Err(e) = self.add_peers_to_lookup_and_ancestors(lookup_id, peers, cx) {
|
||||||
warn!(self.log, "Error adding peers to ancestor lookup"; "error" => ?e);
|
warn!(self.log, "Error adding peers to ancestor lookup"; "error" => ?e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -844,14 +844,17 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
lookup_id: SingleLookupId,
|
lookup_id: SingleLookupId,
|
||||||
peers: &[PeerId],
|
peers: &[PeerId],
|
||||||
|
cx: &mut SyncNetworkContext<T>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
let lookup = self
|
let lookup = self
|
||||||
.single_block_lookups
|
.single_block_lookups
|
||||||
.get_mut(&lookup_id)
|
.get_mut(&lookup_id)
|
||||||
.ok_or(format!("Unknown lookup for id {lookup_id}"))?;
|
.ok_or(format!("Unknown lookup for id {lookup_id}"))?;
|
||||||
|
|
||||||
|
let mut added_some_peer = false;
|
||||||
for peer in peers {
|
for peer in peers {
|
||||||
if lookup.add_peer(*peer) {
|
if lookup.add_peer(*peer) {
|
||||||
|
added_some_peer = true;
|
||||||
debug!(self.log, "Adding peer to existing single block lookup";
|
debug!(self.log, "Adding peer to existing single block lookup";
|
||||||
"block_root" => ?lookup.block_root(),
|
"block_root" => ?lookup.block_root(),
|
||||||
"peer" => ?peer
|
"peer" => ?peer
|
||||||
@@ -859,22 +862,25 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We may choose to attempt to continue a lookup here. It is possible that a lookup had zero
|
|
||||||
// peers and after adding this set of peers it can make progress again. Note that this
|
|
||||||
// recursive function iterates from child to parent, so continuing the child first is weird.
|
|
||||||
// However, we choose to not attempt to continue the lookup for simplicity. It's not
|
|
||||||
// strictly required and just and optimization for a rare corner case.
|
|
||||||
|
|
||||||
if let Some(parent_root) = lookup.awaiting_parent() {
|
if let Some(parent_root) = lookup.awaiting_parent() {
|
||||||
if let Some((&child_id, _)) = self
|
if let Some((&child_id, _)) = self
|
||||||
.single_block_lookups
|
.single_block_lookups
|
||||||
.iter()
|
.iter()
|
||||||
.find(|(_, l)| l.block_root() == parent_root)
|
.find(|(_, l)| l.block_root() == parent_root)
|
||||||
{
|
{
|
||||||
self.add_peers_to_lookup_and_ancestors(child_id, peers)
|
self.add_peers_to_lookup_and_ancestors(child_id, peers, cx)
|
||||||
} else {
|
} else {
|
||||||
Err(format!("Lookup references unknown parent {parent_root:?}"))
|
Err(format!("Lookup references unknown parent {parent_root:?}"))
|
||||||
}
|
}
|
||||||
|
} else if added_some_peer {
|
||||||
|
// If this lookup is not awaiting a parent and we added at least one peer, attempt to
|
||||||
|
// make progress. It is possible that a lookup is created with zero peers, attempted to
|
||||||
|
// make progress, and then receives peers. After that time the lookup will never be
|
||||||
|
// pruned with `drop_lookups_without_peers` because it has peers. This is rare corner
|
||||||
|
// case, but it can result in stuck lookups.
|
||||||
|
let result = lookup.continue_requests(cx);
|
||||||
|
self.on_lookup_result(lookup_id, result, "add_peers", cx);
|
||||||
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user