From bf06a2ce4b0af690d2df01bf143a588e2433bc4c Mon Sep 17 00:00:00 2001 From: "alex.sharov" <AskAlexSharov@gmail.com> Date: Sat, 3 Jul 2021 10:35:11 +0700 Subject: [PATCH] better peers logging --- p2p/dial.go | 12 ++++++++---- p2p/peer.go | 2 +- p2p/server.go | 6 +++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/p2p/dial.go b/p2p/dial.go index 3e5bedeee7..ce1a6e4ebd 100644 --- a/p2p/dial.go +++ b/p2p/dial.go @@ -42,8 +42,8 @@ const ( dialHistoryExpiration = inboundThrottleTime + 5*time.Second // Config for the "Looking for peers" message. - dialStatsLogInterval = 10 * time.Second // printed at most this often - dialStatsPeerLimit = 3 // but not if more than this many dialed peers + dialStatsLogInterval = 60 * time.Second // printed at most this often + dialStatsPeerLimit = 20 // but not if more than this many dialed peers // Endpoint resolution is throttled with bounded backoff. initialResolveDelay = 60 * time.Second @@ -106,6 +106,8 @@ type dialScheduler struct { addPeerCh chan *conn remPeerCh chan *conn + subProtocolVersion uint + // Everything below here belongs to loop and // should only be accessed by code on the loop goroutine. dialing map[enode.ID]*dialTask // active tasks @@ -164,7 +166,7 @@ func (cfg dialConfig) withDefaults() dialConfig { return cfg } -func newDialScheduler(config dialConfig, it enode.Iterator, setupFunc dialSetupFunc) *dialScheduler { +func newDialScheduler(config dialConfig, it enode.Iterator, setupFunc dialSetupFunc, subProtocolVersion uint) *dialScheduler { d := &dialScheduler{ dialConfig: config.withDefaults(), setupFunc: setupFunc, @@ -177,6 +179,8 @@ func newDialScheduler(config dialConfig, it enode.Iterator, setupFunc dialSetupF remStaticCh: make(chan *enode.Node), addPeerCh: make(chan *conn), remPeerCh: make(chan *conn), + + subProtocolVersion: subProtocolVersion, } d.lastStatsLog = d.clock.Now() d.ctx, d.cancel = context.WithCancel(context.Background()) @@ -343,7 +347,7 @@ func (d *dialScheduler) logStats() { return } if d.dialPeers < dialStatsPeerLimit && d.dialPeers < d.maxDialPeers { - d.log.Debug("Looking for peers", "peercount", len(d.peers), "tried", d.doneSinceLastLog, "static", len(d.static)) + d.log.Info("[p2p] Looking for peers", "protocol", d.subProtocolVersion, "peers", fmt.Sprintf("%d/%d", len(d.peers), d.maxDialPeers), "tried", d.doneSinceLastLog, "static", len(d.static)) } d.doneSinceLastLog = 0 d.lastStatsLog = now diff --git a/p2p/peer.go b/p2p/peer.go index 434a9e28e0..a3b1434c83 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -317,7 +317,7 @@ func (p *Peer) handle(msg Msg) error { // This is the last message. We don't need to discard or // check errors because, the connection will be closed after it. _ = rlp.Decode(msg.Payload, &reason) - return reason[0] + return fmt.Errorf("peer has: %w", reason[0]) case msg.Code < baseProtocolLength: // ignore other base protocol messages msg.Discard() diff --git a/p2p/server.go b/p2p/server.go index ae2495a43e..3883f763e6 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -649,7 +649,11 @@ func (srv *Server) setupDialScheduler() { if config.dialer == nil { config.dialer = tcpDialer{&net.Dialer{Timeout: defaultDialTimeout}} } - srv.dialsched = newDialScheduler(config, srv.discmix, srv.SetupConn) + var subProtocolVersion uint + if len(srv.Protocols) > 0 { + subProtocolVersion = srv.Protocols[0].Version + } + srv.dialsched = newDialScheduler(config, srv.discmix, srv.SetupConn, subProtocolVersion) for _, n := range srv.StaticNodes { srv.dialsched.addStatic(n) } -- GitLab