Skip to content

Disconnect sync peer on rpc HandlerReject #2610

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion beacon_node/eth2_libp2p/src/behaviour/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ pub enum BehaviourEvent<TSpec: EthSpec> {
id: RequestId,
/// The peer to which this request was sent.
peer_id: PeerId,
/// The rpc error that was received.
error: RPCError,
},
RequestReceived {
/// The peer that sent the request.
Expand Down Expand Up @@ -891,7 +893,7 @@ impl<TSpec: EthSpec> NetworkBehaviourEventProcess<RPCMessage<TSpec>> for Behavio
);
// inform failures of requests comming outside the behaviour
if !matches!(id, RequestId::Behaviour) {
self.add_event(BehaviourEvent::RPCFailed { peer_id, id });
self.add_event(BehaviourEvent::RPCFailed { peer_id, id, error });
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions beacon_node/network/src/router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use crate::error;
use crate::service::NetworkMessage;
use beacon_chain::{BeaconChain, BeaconChainTypes};
use eth2_libp2p::{
rpc::RequestId, MessageId, NetworkGlobals, PeerId, PeerRequestId, PubsubMessage, Request,
Response,
rpc::{RPCError, RequestId},
MessageId, NetworkGlobals, PeerId, PeerRequestId, PubsubMessage, Request, Response,
};
use futures::prelude::*;
use processor::Processor;
Expand Down Expand Up @@ -59,6 +59,7 @@ pub enum RouterMessage<T: EthSpec> {
RPCFailed {
peer_id: PeerId,
request_id: RequestId,
error: RPCError,
},
/// A gossip message has been received. The fields are: message id, the peer that sent us this
/// message, the message itself and a bool which indicates if the message should be processed
Expand Down Expand Up @@ -141,8 +142,9 @@ impl<T: BeaconChainTypes> Router<T> {
RouterMessage::RPCFailed {
peer_id,
request_id,
error,
} => {
self.processor.on_rpc_error(peer_id, request_id);
self.processor.on_rpc_error(peer_id, request_id, error);
}
RouterMessage::PubsubMessage(id, peer_id, gossip, should_process) => {
self.handle_gossip(id, peer_id, gossip, should_process);
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/network/src/router/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ impl<T: BeaconChainTypes> Processor<T> {

/// An error occurred during an RPC request. The state is maintained by the sync manager, so
/// this function notifies the sync manager of the error.
pub fn on_rpc_error(&mut self, peer_id: PeerId, request_id: RequestId) {
pub fn on_rpc_error(&mut self, peer_id: PeerId, request_id: RequestId, error: RPCError) {
// Check if the failed RPC belongs to sync
if let RequestId::Sync(id) = request_id {
self.send_to_sync(SyncMessage::RPCError(peer_id, id));
self.send_to_sync(SyncMessage::RPCError(peer_id, id, error));
}
}

Expand Down
4 changes: 2 additions & 2 deletions beacon_node/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,10 +611,10 @@ fn spawn_service<T: BeaconChainTypes>(
});

}
BehaviourEvent::RPCFailed{id, peer_id} => {
BehaviourEvent::RPCFailed{id, peer_id, error} => {
let _ = service
.router_send
.send(RouterMessage::RPCFailed{ peer_id, request_id: id})
.send(RouterMessage::RPCFailed{ peer_id, request_id: id, error})
.map_err(|_| {
debug!(service.log, "Failed to send RPC to router");
});
Expand Down
15 changes: 13 additions & 2 deletions beacon_node/network/src/sync/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use crate::beacon_processor::{ProcessId, WorkEvent as BeaconWorkEvent};
use crate::service::NetworkMessage;
use crate::status::ToStatusMessage;
use beacon_chain::{BeaconChain, BeaconChainTypes, BlockError};
use eth2_libp2p::rpc::RPCError;
use eth2_libp2p::rpc::{methods::MAX_REQUEST_BLOCKS, BlocksByRootRequest, GoodbyeReason};
use eth2_libp2p::types::{NetworkGlobals, SyncState};
use eth2_libp2p::SyncInfo;
Expand Down Expand Up @@ -103,7 +104,7 @@ pub enum SyncMessage<T: EthSpec> {
Disconnect(PeerId),

/// An RPC Error has occurred on a request.
RPCError(PeerId, RequestId),
RPCError(PeerId, RequestId, RPCError),

/// A batch has been processed by the block processor thread.
BatchProcessed {
Expand Down Expand Up @@ -1020,11 +1021,16 @@ impl<T: BeaconChainTypes> SyncManager<T> {
SyncMessage::Disconnect(peer_id) => {
self.peer_disconnect(&peer_id);
}
SyncMessage::RPCError(peer_id, request_id) => {
SyncMessage::RPCError(peer_id, request_id, error) => {
// Redirect to a sync mechanism if the error is related to one of their
// requests.
match self.network.blocks_by_range_response(request_id, true) {
Some(SyncRequestType::RangeSync(batch_id, chain_id)) => {
// `HandlerRejected` error signifies that the peer has disconnected from us.
// Remove the peer from any syncing chain mappings.
if let RPCError::HandlerRejected = error {
self.peer_disconnect(&peer_id);
}
self.range_sync.inject_error(
&mut self.network,
peer_id,
Expand All @@ -1035,6 +1041,11 @@ impl<T: BeaconChainTypes> SyncManager<T> {
self.update_sync_state();
}
Some(SyncRequestType::BackFillSync(batch_id)) => {
// `HandlerRejected` error signifies that the peer has disconnected from us.
// Remove the peer from any syncing chain mappings.
if let RPCError::HandlerRejected = error {
self.peer_disconnect(&peer_id);
}
match self.backfill_sync.inject_error(
&mut self.network,
batch_id,
Expand Down