From 580d2f7873093114bafe5f84f862173eab7d4ff5 Mon Sep 17 00:00:00 2001 From: Divma Date: Wed, 13 Apr 2022 03:54:43 +0000 Subject: [PATCH] log upgrades + prevent dialing of disconnecting peers (#3148) ## Issue Addressed We still ping peers that are considered in a disconnecting state ## Proposed Changes Do not ping peers once we decide they are disconnecting Upgrade logs about ignored rpc messages ## Additional Info -- --- .../lighthouse_network/src/behaviour/mod.rs | 2 +- .../src/peer_manager/mod.rs | 2 ++ .../lighthouse_network/src/rpc/methods.rs | 13 +++++++ beacon_node/lighthouse_network/src/rpc/mod.rs | 35 +++++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/beacon_node/lighthouse_network/src/behaviour/mod.rs b/beacon_node/lighthouse_network/src/behaviour/mod.rs index b5b0049cbd..e67bb29de3 100644 --- a/beacon_node/lighthouse_network/src/behaviour/mod.rs +++ b/beacon_node/lighthouse_network/src/behaviour/mod.rs @@ -991,7 +991,7 @@ where debug!( self.log, "Ignoring rpc message of disconnecting peer"; - "peer" => %peer_id + event ); return; } diff --git a/beacon_node/lighthouse_network/src/peer_manager/mod.rs b/beacon_node/lighthouse_network/src/peer_manager/mod.rs index 9c881e0625..11f59b0d21 100644 --- a/beacon_node/lighthouse_network/src/peer_manager/mod.rs +++ b/beacon_node/lighthouse_network/src/peer_manager/mod.rs @@ -213,6 +213,8 @@ impl PeerManager { ScoreUpdateResult::Disconnect => { // The peer has transitioned to a disconnect state and has been marked as such in // the peer db. We must inform libp2p to disconnect this peer. + self.inbound_ping_peers.remove(peer_id); + self.outbound_ping_peers.remove(peer_id); self.events.push(PeerManagerEvent::DisconnectPeer( *peer_id, GoodbyeReason::BadScore, diff --git a/beacon_node/lighthouse_network/src/rpc/methods.rs b/beacon_node/lighthouse_network/src/rpc/methods.rs index f38cde3633..1ac9c9b2c0 100644 --- a/beacon_node/lighthouse_network/src/rpc/methods.rs +++ b/beacon_node/lighthouse_network/src/rpc/methods.rs @@ -335,6 +335,19 @@ impl RPCResponseErrorCode { } } +use super::Protocol; +impl RPCResponse { + pub fn protocol(&self) -> Protocol { + match self { + RPCResponse::Status(_) => Protocol::Status, + RPCResponse::BlocksByRange(_) => Protocol::BlocksByRange, + RPCResponse::BlocksByRoot(_) => Protocol::BlocksByRoot, + RPCResponse::Pong(_) => Protocol::Ping, + RPCResponse::MetaData(_) => Protocol::MetaData, + } + } +} + impl std::fmt::Display for RPCResponseErrorCode { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let repr = match self { diff --git a/beacon_node/lighthouse_network/src/rpc/mod.rs b/beacon_node/lighthouse_network/src/rpc/mod.rs index 884acd9bcf..0bedd423b2 100644 --- a/beacon_node/lighthouse_network/src/rpc/mod.rs +++ b/beacon_node/lighthouse_network/src/rpc/mod.rs @@ -271,3 +271,38 @@ where Poll::Pending } } + +impl slog::KV for RPCMessage +where + TSpec: EthSpec, + Id: ReqId, +{ + fn serialize( + &self, + _record: &slog::Record, + serializer: &mut dyn slog::Serializer, + ) -> slog::Result { + serializer.emit_arguments("peer_id", &format_args!("{}", self.peer_id))?; + let (msg_kind, protocol) = match &self.event { + Ok(received) => match received { + RPCReceived::Request(_, req) => ("request", req.protocol()), + RPCReceived::Response(_, res) => ("response", res.protocol()), + RPCReceived::EndOfStream(_, end) => ( + "end_of_stream", + match end { + ResponseTermination::BlocksByRange => Protocol::BlocksByRange, + ResponseTermination::BlocksByRoot => Protocol::BlocksByRoot, + }, + ), + }, + Err(error) => match &error { + HandlerErr::Inbound { proto, .. } => ("inbound_err", *proto), + HandlerErr::Outbound { proto, .. } => ("outbound_err", *proto), + }, + }; + serializer.emit_str("msg_kind", msg_kind)?; + serializer.emit_arguments("protocol", &format_args!("{}", protocol))?; + + slog::Result::Ok(()) + } +}