diff --git a/polygon/p2p/message_sender.go b/polygon/p2p/message_sender.go index b435b48c439..a670ebe279b 100644 --- a/polygon/p2p/message_sender.go +++ b/polygon/p2p/message_sender.go @@ -19,8 +19,10 @@ package p2p import ( "context" "errors" + "fmt" sentry "github.com/erigontech/erigon-lib/gointerfaces/sentryproto" + libsentry "github.com/erigontech/erigon-lib/p2p/sentry" "github.com/erigontech/erigon/eth/protocols/eth" "github.com/erigontech/erigon/rlp" ) @@ -64,10 +66,13 @@ func (ms *messageSender) sendMessage(ctx context.Context, messageId sentry.Messa }, }) if err != nil { + if libsentry.IsPeerNotFoundErr(err) { + return fmt.Errorf("%w: %s", ErrPeerNotFound, peerId.String()) + } return err } if len(sent.Peers) == 0 { - return ErrPeerNotFound + return fmt.Errorf("%w: %s", ErrPeerNotFound, peerId.String()) } return nil diff --git a/polygon/sync/sync.go b/polygon/sync/sync.go index 4e437446741..52f1e92bbb4 100644 --- a/polygon/sync/sync.go +++ b/polygon/sync/sync.go @@ -181,7 +181,7 @@ func (s *Sync) applyNewBlockOnTip( } else { blocks, err := s.p2pService.FetchBlocks(ctx, rootNum, newBlockHeaderNum+1, event.PeerId) if err != nil { - if (p2p.ErrIncompleteHeaders{}).Is(err) || (p2p.ErrMissingBodies{}).Is(err) { + if s.ignoreFetchBlocksErrOnTipEvent(err) { s.logger.Debug( syncLogPrefix("applyNewBlockOnTip: failed to fetch complete blocks, ignoring event"), "err", err, @@ -256,7 +256,7 @@ func (s *Sync) applyNewBlockHashesOnTip( newBlocks, err := s.p2pService.FetchBlocks(ctx, headerHashNum.Number, headerHashNum.Number+1, event.PeerId) if err != nil { - if (p2p.ErrIncompleteHeaders{}).Is(err) || (p2p.ErrMissingBodies{}).Is(err) { + if s.ignoreFetchBlocksErrOnTipEvent(err) { s.logger.Debug( syncLogPrefix("applyNewBlockHashesOnTip: failed to fetch complete blocks, ignoring event"), "err", err, @@ -383,3 +383,9 @@ func (s *Sync) sync(ctx context.Context, tip *types.Header, tipDownloader tipDow return tip, nil } + +func (s *Sync) ignoreFetchBlocksErrOnTipEvent(err error) bool { + return errors.Is(err, &p2p.ErrIncompleteHeaders{}) || + errors.Is(err, &p2p.ErrMissingBodies{}) || + errors.Is(err, p2p.ErrPeerNotFound) +}