From 245185a7ba1130f5042bbb176f6817e50e68f0e8 Mon Sep 17 00:00:00 2001 From: Elias Naur <103319121+elias-orijtech@users.noreply.github.com> Date: Tue, 10 Oct 2023 09:03:16 -0500 Subject: [PATCH] test: respect P2PConfig fuzzing configuration in MultiplexTransport (#1414) As part of porting the cosmos-sdk simulator to running on top of its testutil/network runner, we need a way to simulate adversarial network connections between validators. This change adds the existing fuzzing configuration of P2PConfig to MConnConfig and uses it to conditionally create an unreliable connection in MultiplexTransport. Co-authored-by: Elias Naur Co-authored-by: Sergio Mena --- config/config.go | 2 +- p2p/conn/connection.go | 5 +++++ p2p/switch.go | 2 ++ p2p/transport.go | 5 +++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 5c44c55eac1..d631ed388f9 100644 --- a/config/config.go +++ b/config/config.go @@ -735,7 +735,7 @@ type P2PConfig struct { //nolint: maligned // Testing params. // Force dial to fail TestDialFail bool `mapstructure:"test_dial_fail"` - // FUzz connection + // Fuzz connection TestFuzz bool `mapstructure:"test_fuzz"` TestFuzzConfig *FuzzConnConfig `mapstructure:"test_fuzz_config"` } diff --git a/p2p/conn/connection.go b/p2p/conn/connection.go index df783753d49..7bd8e34dc13 100644 --- a/p2p/conn/connection.go +++ b/p2p/conn/connection.go @@ -14,6 +14,7 @@ import ( "github.com/cosmos/gogoproto/proto" + "github.com/cometbft/cometbft/config" flow "github.com/cometbft/cometbft/libs/flowrate" "github.com/cometbft/cometbft/libs/log" cmtmath "github.com/cometbft/cometbft/libs/math" @@ -136,6 +137,10 @@ type MConnConfig struct { // Maximum wait time for pongs PongTimeout time.Duration `mapstructure:"pong_timeout"` + + // Fuzz connection + TestFuzz bool `mapstructure:"test_fuzz"` + TestFuzzConfig *config.FuzzConnConfig `mapstructure:"test_fuzz_config"` } // DefaultMConnConfig returns the default config. diff --git a/p2p/switch.go b/p2p/switch.go index 71586d27790..68ad5669b3e 100644 --- a/p2p/switch.go +++ b/p2p/switch.go @@ -39,6 +39,8 @@ func MConnConfig(cfg *config.P2PConfig) conn.MConnConfig { mConfig.SendRate = cfg.SendRate mConfig.RecvRate = cfg.RecvRate mConfig.MaxPacketMsgPayloadSize = cfg.MaxPacketMsgPayloadSize + mConfig.TestFuzz = cfg.TestFuzz + mConfig.TestFuzzConfig = cfg.TestFuzzConfig return mConfig } diff --git a/p2p/transport.go b/p2p/transport.go index 96d3738d662..d6043da3beb 100644 --- a/p2p/transport.go +++ b/p2p/transport.go @@ -218,6 +218,11 @@ func (mt *MultiplexTransport) Dial( return nil, err } + if mt.mConfig.TestFuzz { + // so we have time to do peer handshakes and get set up. + c = FuzzConnAfterFromConfig(c, 10*time.Second, mt.mConfig.TestFuzzConfig) + } + // TODO(xla): Evaluate if we should apply filters if we explicitly dial. if err := mt.filterConn(c); err != nil { return nil, err