From 7f976124dff099fe6fb0d1f1c9aaa23751c55f31 Mon Sep 17 00:00:00 2001 From: Age Manning Date: Thu, 21 Mar 2019 13:34:37 +1100 Subject: [PATCH] Add logging to libp2p behaviour --- beacon_node/eth2-libp2p/src/behaviour.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/beacon_node/eth2-libp2p/src/behaviour.rs b/beacon_node/eth2-libp2p/src/behaviour.rs index a29484e2b1..a3ac8417f9 100644 --- a/beacon_node/eth2-libp2p/src/behaviour.rs +++ b/beacon_node/eth2-libp2p/src/behaviour.rs @@ -11,6 +11,7 @@ use libp2p::{ tokio_io::{AsyncRead, AsyncWrite}, NetworkBehaviour, PeerId, }; +use slog::{debug, o}; use types::Topic; /// Builds the network behaviour for the libp2p Swarm. @@ -27,6 +28,9 @@ pub struct Behaviour { identify: Identify, #[behaviour(ignore)] events: Vec, + #[behaviour(ignore)] + /// Logger for behaviour actions. + log: slog::Logger, } // Implement the NetworkBehaviourEventProcess trait so that we can derive NetworkBehaviour for Behaviour @@ -70,6 +74,10 @@ impl NetworkBehaviourEventProcess { if info.listen_addrs.len() > 20 { + debug!( + self.log, + "More than 20 peers have been identified, truncating" + ); info.listen_addrs.truncate(20); } self.events.push(BehaviourEvent::Identified(peer_id, info)); @@ -84,6 +92,7 @@ impl Behaviour { pub fn new(local_public_key: PublicKey, net_conf: &NetworkConfig, log: &slog::Logger) -> Self { let local_peer_id = local_public_key.clone().into_peer_id(); let identify_config = net_conf.identify_config.clone(); + let behaviour_log = log.new(o!()); Behaviour { gossipsub: Gossipsub::new(local_peer_id, net_conf.gs_config.clone()), @@ -94,6 +103,7 @@ impl Behaviour { local_public_key, ), events: Vec::new(), + log: behaviour_log, } }