From 4a5e8f8592b3677359bbd63784f3eed20ad20fb5 Mon Sep 17 00:00:00 2001 From: Ekaterina Pavlova Date: Wed, 5 Jun 2024 14:26:08 +0300 Subject: [PATCH] logs: distinguish WARN and INFO for peer disconnected Peer disconnections are not warnings in some cases. Close #3182 Signed-off-by: Ekaterina Pavlova --- pkg/network/server.go | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/pkg/network/server.go b/pkg/network/server.go index 5bc4b3c8f..78c0c03c0 100644 --- a/pkg/network/server.go +++ b/pkg/network/server.go @@ -44,12 +44,13 @@ const ( ) var ( - errAlreadyConnected = errors.New("already connected") - errIdenticalID = errors.New("identical node id") - errInvalidNetwork = errors.New("invalid network") - errMaxPeers = errors.New("max peers reached") - errServerShutdown = errors.New("server shutdown") - errInvalidInvType = errors.New("invalid inventory type") + errAlreadyConnected = errors.New("already connected") + errIdenticalID = errors.New("identical node id") + errInvalidNetwork = errors.New("invalid network") + errMaxPeers = errors.New("max peers reached") + errServerShutdown = errors.New("server shutdown") + errInvalidInvType = errors.New("invalid inventory type") + errBlocksRequestFailed = errors.New("blocks request failed") ) type ( @@ -512,10 +513,17 @@ func (s *Server) run() { if s.peers[drop.peer] { delete(s.peers, drop.peer) s.lock.Unlock() - s.log.Warn("peer disconnected", - zap.Stringer("addr", drop.peer.RemoteAddr()), - zap.Error(drop.reason), - zap.Int("peerCount", s.PeerCount())) + if errors.Is(drop.reason, errInvalidInvType) || errors.Is(drop.reason, errStateMismatch) || errors.Is(drop.reason, errBlocksRequestFailed) { + s.log.Warn("peer disconnected", + zap.Stringer("addr", drop.peer.RemoteAddr()), + zap.Error(drop.reason), + zap.Int("peerCount", s.PeerCount())) + } else { + s.log.Info("peer disconnected", + zap.Stringer("addr", drop.peer.RemoteAddr()), + zap.Error(drop.reason), + zap.Int("peerCount", s.PeerCount())) + } if errors.Is(drop.reason, errIdenticalID) { s.discovery.RegisterSelf(drop.peer) } else { @@ -793,7 +801,7 @@ func (s *Server) requestBlocksOrHeaders(p Peer) error { } err := s.requestBlocks(bq, p) if err != nil { - return err + return fmt.Errorf("%w: %w", errBlocksRequestFailed, err) } if requestMPTNodes { return s.requestMPTNodes(p, s.stateSync.GetUnknownMPTNodesBatch(payload.MaxMPTHashesCount))