mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-25 13:47:19 +00:00
Merge pull request #3469 from nspcc-dev/warn
logs: distinguish WARN and INFO for `peer disconnected`
This commit is contained in:
commit
cf4d4a2611
1 changed files with 20 additions and 12 deletions
|
@ -50,6 +50,7 @@ var (
|
||||||
errMaxPeers = errors.New("max peers reached")
|
errMaxPeers = errors.New("max peers reached")
|
||||||
errServerShutdown = errors.New("server shutdown")
|
errServerShutdown = errors.New("server shutdown")
|
||||||
errInvalidInvType = errors.New("invalid inventory type")
|
errInvalidInvType = errors.New("invalid inventory type")
|
||||||
|
errBlocksRequestFailed = errors.New("blocks request failed")
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
@ -512,10 +513,17 @@ func (s *Server) run() {
|
||||||
if s.peers[drop.peer] {
|
if s.peers[drop.peer] {
|
||||||
delete(s.peers, drop.peer)
|
delete(s.peers, drop.peer)
|
||||||
s.lock.Unlock()
|
s.lock.Unlock()
|
||||||
|
if errors.Is(drop.reason, errInvalidInvType) || errors.Is(drop.reason, errStateMismatch) || errors.Is(drop.reason, errBlocksRequestFailed) {
|
||||||
s.log.Warn("peer disconnected",
|
s.log.Warn("peer disconnected",
|
||||||
zap.Stringer("addr", drop.peer.RemoteAddr()),
|
zap.Stringer("addr", drop.peer.RemoteAddr()),
|
||||||
zap.Error(drop.reason),
|
zap.Error(drop.reason),
|
||||||
zap.Int("peerCount", s.PeerCount()))
|
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) {
|
if errors.Is(drop.reason, errIdenticalID) {
|
||||||
s.discovery.RegisterSelf(drop.peer)
|
s.discovery.RegisterSelf(drop.peer)
|
||||||
} else {
|
} else {
|
||||||
|
@ -793,7 +801,7 @@ func (s *Server) requestBlocksOrHeaders(p Peer) error {
|
||||||
}
|
}
|
||||||
err := s.requestBlocks(bq, p)
|
err := s.requestBlocks(bq, p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("%w: %w", errBlocksRequestFailed, err)
|
||||||
}
|
}
|
||||||
if requestMPTNodes {
|
if requestMPTNodes {
|
||||||
return s.requestMPTNodes(p, s.stateSync.GetUnknownMPTNodesBatch(payload.MaxMPTHashesCount))
|
return s.requestMPTNodes(p, s.stateSync.GetUnknownMPTNodesBatch(payload.MaxMPTHashesCount))
|
||||||
|
@ -1345,7 +1353,7 @@ func (s *Server) handleMessage(peer Peer, msg *Message) error {
|
||||||
if peer.Handshaked() {
|
if peer.Handshaked() {
|
||||||
if inv, ok := msg.Payload.(*payload.Inventory); ok {
|
if inv, ok := msg.Payload.(*payload.Inventory); ok {
|
||||||
if !inv.Type.Valid(s.chain.P2PSigExtensionsEnabled()) || len(inv.Hashes) == 0 {
|
if !inv.Type.Valid(s.chain.P2PSigExtensionsEnabled()) || len(inv.Hashes) == 0 {
|
||||||
return errInvalidInvType
|
return fmt.Errorf("%w: %s", errInvalidInvType, inv.Type.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch msg.Command {
|
switch msg.Command {
|
||||||
|
|
Loading…
Reference in a new issue