From c4f6020677bf898f39fcaff9a33eacf3bef52395 Mon Sep 17 00:00:00 2001 From: Nishant Das Date: Tue, 19 Mar 2024 21:37:23 +0800 Subject: [PATCH] add mplex timeout (#13745) --- beacon-chain/p2p/BUILD.bazel | 1 + beacon-chain/p2p/options.go | 7 +++++++ beacon-chain/p2p/service.go | 3 ++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/beacon-chain/p2p/BUILD.bazel b/beacon-chain/p2p/BUILD.bazel index 28d92e3b6..af7562399 100644 --- a/beacon-chain/p2p/BUILD.bazel +++ b/beacon-chain/p2p/BUILD.bazel @@ -94,6 +94,7 @@ go_library( "@com_github_libp2p_go_libp2p_mplex//:go_default_library", "@com_github_libp2p_go_libp2p_pubsub//:go_default_library", "@com_github_libp2p_go_libp2p_pubsub//pb:go_default_library", + "@com_github_libp2p_go_mplex//:go_default_library", "@com_github_multiformats_go_multiaddr//:go_default_library", "@com_github_multiformats_go_multiaddr//net:go_default_library", "@com_github_pkg_errors//:go_default_library", diff --git a/beacon-chain/p2p/options.go b/beacon-chain/p2p/options.go index bf5322137..5d4b8fa31 100644 --- a/beacon-chain/p2p/options.go +++ b/beacon-chain/p2p/options.go @@ -4,6 +4,7 @@ import ( "crypto/ecdsa" "fmt" "net" + "time" "github.com/libp2p/go-libp2p" mplex "github.com/libp2p/go-libp2p-mplex" @@ -11,6 +12,7 @@ import ( "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/p2p/security/noise" "github.com/libp2p/go-libp2p/p2p/transport/tcp" + gomplex "github.com/libp2p/go-mplex" ma "github.com/multiformats/go-multiaddr" "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/config/features" @@ -135,3 +137,8 @@ func privKeyOption(privkey *ecdsa.PrivateKey) libp2p.Option { return cfg.Apply(libp2p.Identity(ifaceKey)) } } + +// Configures stream timeouts on mplex. +func configureMplex() { + gomplex.ResetStreamTimeout = 5 * time.Second +} diff --git a/beacon-chain/p2p/service.go b/beacon-chain/p2p/service.go index a70ede6db..f87a99aa1 100644 --- a/beacon-chain/p2p/service.go +++ b/beacon-chain/p2p/service.go @@ -124,7 +124,8 @@ func NewService(ctx context.Context, cfg *Config) (*Service, error) { if err != nil { return nil, errors.Wrapf(err, "failed to build p2p options") } - + // Sets mplex timeouts + configureMplex() h, err := libp2p.New(opts...) if err != nil { log.WithError(err).Error("Failed to create p2p host")