From 0cbb00f33d9326284e30c00b50cdf9698ae7706b Mon Sep 17 00:00:00 2001 From: nisdas Date: Thu, 8 Feb 2024 19:58:33 +0800 Subject: [PATCH 1/3] supress unwanted errors --- beacon-chain/sync/error.go | 13 ++++++++++++- beacon-chain/sync/rpc.go | 3 +++ beacon-chain/sync/rpc_status.go | 6 +++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/beacon-chain/sync/error.go b/beacon-chain/sync/error.go index ea70f06099da..b8babc2f2fb1 100644 --- a/beacon-chain/sync/error.go +++ b/beacon-chain/sync/error.go @@ -3,9 +3,11 @@ package sync import ( "bytes" "errors" + "io" libp2pcore "github.com/libp2p/go-libp2p/core" "github.com/libp2p/go-libp2p/core/network" + multiplex "github.com/libp2p/go-mplex" "github.com/prysmaticlabs/prysm/v4/beacon-chain/p2p" "github.com/prysmaticlabs/prysm/v4/beacon-chain/p2p/encoder" "github.com/prysmaticlabs/prysm/v4/beacon-chain/p2p/types" @@ -98,7 +100,7 @@ func readStatusCodeNoDeadline(stream network.Stream, encoding encoder.NetworkEnc func isValidStreamError(err error) bool { // check the error message itself as well as libp2p doesn't currently // return the correct error type from Close{Read,Write,}. - return err != nil && !errors.Is(err, network.ErrReset) && err.Error() != network.ErrReset.Error() + return err != nil && !isUnwantedError(err) } func closeStream(stream network.Stream, log *logrus.Entry) { @@ -130,3 +132,12 @@ func closeStreamAndWait(stream network.Stream, log *logrus.Entry) { _err = stream.Close() _ = _err } + +func isUnwantedError(err error) bool { + for _, e := range []error{network.ErrReset, multiplex.ErrShutdown, io.EOF, types.ErrIODeadline} { + if errors.Is(err, e) || err.Error() == e.Error() { + return true + } + } + return false +} diff --git a/beacon-chain/sync/rpc.go b/beacon-chain/sync/rpc.go index d46b46f63176..73c9e23c1f24 100644 --- a/beacon-chain/sync/rpc.go +++ b/beacon-chain/sync/rpc.go @@ -244,6 +244,9 @@ func (s *Service) registerRPC(baseTopic string, handle rpcHandler) { } func logStreamErrors(err error, topic string) { + if isUnwantedError(err) { + return + } if strings.Contains(topic, p2p.RPCGoodByeTopicV1) { log.WithError(err).WithField("topic", topic).Trace("Could not decode goodbye stream message") return diff --git a/beacon-chain/sync/rpc_status.go b/beacon-chain/sync/rpc_status.go index 2f9f79b2f98e..94dd172d3088 100644 --- a/beacon-chain/sync/rpc_status.go +++ b/beacon-chain/sync/rpc_status.go @@ -181,7 +181,7 @@ func (s *Service) reValidatePeer(ctx context.Context, id peer.ID) error { return err } // Do not return an error for ping requests. - if err := s.sendPingRequest(ctx, id); err != nil { + if err := s.sendPingRequest(ctx, id); err != nil && !isUnwantedError(err) { log.WithError(err).Debug("Could not ping peer") } return nil @@ -235,7 +235,7 @@ func (s *Service) statusRPCHandler(ctx context.Context, msg interface{}, stream resp, err := s.generateErrorResponse(respCode, err.Error()) if err != nil { log.WithError(err).Debug("Could not generate a response error") - } else if _, err := stream.Write(resp); err != nil { + } else if _, err := stream.Write(resp); err != nil && !isUnwantedError(err) { // The peer may already be ignoring us, as we disagree on fork version, so log this as debug only. log.WithError(err).Debug("Could not write to stream") } @@ -273,7 +273,7 @@ func (s *Service) respondWithStatus(ctx context.Context, stream network.Stream) HeadSlot: s.cfg.chain.HeadSlot(), } - if _, err := stream.Write([]byte{responseCodeSuccess}); err != nil { + if _, err := stream.Write([]byte{responseCodeSuccess}); err != nil && !isUnwantedError(err) { log.WithError(err).Debug("Could not write to stream") } _, err = s.cfg.p2p.Encoding().EncodeWithMaxLength(stream, resp) From a75f16ee2616bbefb7ea8a002a3f3d8d0c6d512f Mon Sep 17 00:00:00 2001 From: nisdas Date: Thu, 8 Feb 2024 20:07:03 +0800 Subject: [PATCH 2/3] gaz --- beacon-chain/sync/BUILD.bazel | 1 + 1 file changed, 1 insertion(+) diff --git a/beacon-chain/sync/BUILD.bazel b/beacon-chain/sync/BUILD.bazel index bfe8a44ed0cc..266ae26ae8dd 100644 --- a/beacon-chain/sync/BUILD.bazel +++ b/beacon-chain/sync/BUILD.bazel @@ -125,6 +125,7 @@ go_library( "@com_github_libp2p_go_libp2p//core/peer:go_default_library", "@com_github_libp2p_go_libp2p//core/protocol:go_default_library", "@com_github_libp2p_go_libp2p_pubsub//:go_default_library", + "@com_github_libp2p_go_mplex//:go_default_library", "@com_github_patrickmn_go_cache//:go_default_library", "@com_github_pkg_errors//:go_default_library", "@com_github_prometheus_client_golang//prometheus:go_default_library", From 7087064e9e054d76afa8cb6188bc1e59f43ff4d4 Mon Sep 17 00:00:00 2001 From: nisdas Date: Thu, 8 Feb 2024 20:09:27 +0800 Subject: [PATCH 3/3] mod --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index ff97d340e0c6..e0bec7f6e69f 100644 --- a/go.mod +++ b/go.mod @@ -47,6 +47,7 @@ require ( github.com/libp2p/go-libp2p v0.32.1 github.com/libp2p/go-libp2p-mplex v0.9.0 github.com/libp2p/go-libp2p-pubsub v0.10.0 + github.com/libp2p/go-mplex v0.7.0 github.com/logrusorgru/aurora v2.0.3+incompatible github.com/manifoldco/promptui v0.7.0 github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b @@ -171,7 +172,6 @@ require ( github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/libp2p/go-flow-metrics v0.1.0 // indirect github.com/libp2p/go-libp2p-asn-util v0.4.1 // indirect - github.com/libp2p/go-mplex v0.7.0 // indirect github.com/libp2p/go-msgio v0.3.0 // indirect github.com/libp2p/go-nat v0.2.0 // indirect github.com/libp2p/go-netroute v0.2.1 // indirect