mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-21 05:44:44 +00:00
Report RPC Errors to the application on peer disconnections (#5680)
* Report RPC Errors to the application on peer disconnections Co-authored-by: Age Manning <Age@AgeManning.com> * Expect RPCError::Disconnect to fail ongoing requests * Drop lookups after peer disconnect and not awaiting events * Allow RPCError disconnect through network service * Update beacon_node/lighthouse_network/src/service/mod.rs Co-authored-by: Age Manning <Age@AgeManning.com> * Merge branch 'unstable' into rpc-error-on-disconnect
This commit is contained in:
@@ -382,16 +382,13 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
||||
/* Error responses */
|
||||
|
||||
pub fn peer_disconnected(&mut self, peer_id: &PeerId) {
|
||||
/* Check disconnection for single lookups */
|
||||
self.single_block_lookups.retain(|_, req| {
|
||||
let should_drop_lookup =
|
||||
req.should_drop_lookup_on_disconnected_peer(peer_id );
|
||||
|
||||
if should_drop_lookup {
|
||||
debug!(self.log, "Dropping single lookup after peer disconnection"; "block_root" => ?req.block_root());
|
||||
self.single_block_lookups.retain(|_, lookup| {
|
||||
if lookup.remove_peer(peer_id) {
|
||||
debug!(self.log, "Dropping single lookup after peer disconnection"; "block_root" => ?lookup.block_root());
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
|
||||
!should_drop_lookup
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -186,21 +186,11 @@ impl<T: BeaconChainTypes> SingleBlockLookup<T> {
|
||||
&& self.blob_request_state.state.is_processed()
|
||||
}
|
||||
|
||||
/// Checks both the block and blob request states to see if the peer is disconnected.
|
||||
///
|
||||
/// Returns true if the lookup should be dropped.
|
||||
pub fn should_drop_lookup_on_disconnected_peer(&mut self, peer_id: &PeerId) -> bool {
|
||||
self.block_request_state.state.remove_peer(peer_id);
|
||||
self.blob_request_state.state.remove_peer(peer_id);
|
||||
|
||||
if self.all_available_peers().count() == 0 {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Note: if the peer disconnected happens to have an on-going request associated with this
|
||||
// lookup we will receive an RPCError and the lookup will fail. No need to manually retry
|
||||
// now.
|
||||
false
|
||||
/// Remove peer from available peers. Return true if there are no more available peers and all
|
||||
/// requests are not expecting any future event (AwaitingDownload).
|
||||
pub fn remove_peer(&mut self, peer_id: &PeerId) -> bool {
|
||||
self.block_request_state.state.remove_peer(peer_id)
|
||||
&& self.blob_request_state.state.remove_peer(peer_id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -465,9 +455,11 @@ impl<T: Clone> SingleLookupRequestState<T> {
|
||||
self.available_peers.insert(*peer_id)
|
||||
}
|
||||
|
||||
/// If a peer disconnects, this request could be failed. If so, an error is returned
|
||||
pub fn remove_peer(&mut self, disconnected_peer_id: &PeerId) {
|
||||
/// Remove peer from available peers. Return true if there are no more available peers and the
|
||||
/// request is not expecting any future event (AwaitingDownload).
|
||||
pub fn remove_peer(&mut self, disconnected_peer_id: &PeerId) -> bool {
|
||||
self.available_peers.remove(disconnected_peer_id);
|
||||
self.available_peers.is_empty() && self.is_awaiting_download()
|
||||
}
|
||||
|
||||
pub fn get_used_peers(&self) -> impl Iterator<Item = &PeerId> {
|
||||
|
||||
@@ -450,8 +450,25 @@ impl TestRig {
|
||||
})
|
||||
}
|
||||
|
||||
fn peer_disconnected(&mut self, peer_id: PeerId) {
|
||||
self.send_sync_message(SyncMessage::Disconnect(peer_id));
|
||||
fn peer_disconnected(&mut self, disconnected_peer_id: PeerId) {
|
||||
self.send_sync_message(SyncMessage::Disconnect(disconnected_peer_id));
|
||||
|
||||
// Return RPCErrors for all active requests of peer
|
||||
self.drain_network_rx();
|
||||
while let Ok(request_id) = self.pop_received_network_event(|ev| match ev {
|
||||
NetworkMessage::SendRequest {
|
||||
peer_id,
|
||||
request_id: RequestId::Sync(id),
|
||||
..
|
||||
} if *peer_id == disconnected_peer_id => Some(*id),
|
||||
_ => None,
|
||||
}) {
|
||||
self.send_sync_message(SyncMessage::RpcError {
|
||||
peer_id: disconnected_peer_id,
|
||||
request_id,
|
||||
error: RPCError::Disconnected,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn drain_network_rx(&mut self) {
|
||||
|
||||
Reference in New Issue
Block a user