Skip to content

Commit

Permalink
test: respect P2PConfig fuzzing configuration in MultiplexTransport (c…
Browse files Browse the repository at this point in the history
…ometbft#1414) (cometbft#1668)

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 <mail@eliasnaur.com>
Co-authored-by: Sergio Mena <sergio@informal.systems>
(cherry picked from commit 245185a)

Co-authored-by: Elias Naur <103319121+elias-orijtech@users.noreply.github.com>
  • Loading branch information
2 people authored and nivasan1 committed Nov 28, 2023
1 parent 4aed10d commit 6fb3b46
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,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"`
}
Expand Down
5 changes: 5 additions & 0 deletions p2p/conn/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions p2p/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
5 changes: 5 additions & 0 deletions p2p/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6fb3b46

Please sign in to comment.