Skip to content

Commit

Permalink
Export p2p config errors
Browse files Browse the repository at this point in the history
  • Loading branch information
zivkovicmilos committed Jan 6, 2025
1 parent 515bc73 commit 32b843c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions tm2/pkg/p2p/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
)

var (
errInvalidFlushThrottleTimeout = errors.New("invalid flush throttle timeout")
errInvalidMaxPayloadSize = errors.New("invalid message payload size")
errInvalidSendRate = errors.New("invalid packet send rate")
errInvalidReceiveRate = errors.New("invalid packet receive rate")
ErrInvalidFlushThrottleTimeout = errors.New("invalid flush throttle timeout")
ErrInvalidMaxPayloadSize = errors.New("invalid message payload size")
ErrInvalidSendRate = errors.New("invalid packet send rate")
ErrInvalidReceiveRate = errors.New("invalid packet receive rate")
)

// P2PConfig defines the configuration options for the Tendermint peer-to-peer networking layer
Expand Down Expand Up @@ -72,19 +72,19 @@ func DefaultP2PConfig() *P2PConfig {
// returns an error if any check fails.
func (cfg *P2PConfig) ValidateBasic() error {
if cfg.FlushThrottleTimeout < 0 {
return errInvalidFlushThrottleTimeout
return ErrInvalidFlushThrottleTimeout
}

if cfg.MaxPacketMsgPayloadSize < 0 {
return errInvalidMaxPayloadSize
return ErrInvalidMaxPayloadSize
}

if cfg.SendRate < 0 {
return errInvalidSendRate
return ErrInvalidSendRate
}

if cfg.RecvRate < 0 {
return errInvalidReceiveRate
return ErrInvalidReceiveRate
}

return nil
Expand Down
8 changes: 4 additions & 4 deletions tm2/pkg/p2p/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestP2PConfig_ValidateBasic(t *testing.T) {

cfg.FlushThrottleTimeout = -1

assert.ErrorIs(t, cfg.ValidateBasic(), errInvalidFlushThrottleTimeout)
assert.ErrorIs(t, cfg.ValidateBasic(), ErrInvalidFlushThrottleTimeout)
})

t.Run("invalid max packet payload size", func(t *testing.T) {
Expand All @@ -26,7 +26,7 @@ func TestP2PConfig_ValidateBasic(t *testing.T) {

cfg.MaxPacketMsgPayloadSize = -1

assert.ErrorIs(t, cfg.ValidateBasic(), errInvalidMaxPayloadSize)
assert.ErrorIs(t, cfg.ValidateBasic(), ErrInvalidMaxPayloadSize)
})

t.Run("invalid send rate", func(t *testing.T) {
Expand All @@ -36,7 +36,7 @@ func TestP2PConfig_ValidateBasic(t *testing.T) {

cfg.SendRate = -1

assert.ErrorIs(t, cfg.ValidateBasic(), errInvalidSendRate)
assert.ErrorIs(t, cfg.ValidateBasic(), ErrInvalidSendRate)
})

t.Run("invalid receive rate", func(t *testing.T) {
Expand All @@ -46,7 +46,7 @@ func TestP2PConfig_ValidateBasic(t *testing.T) {

cfg.RecvRate = -1

assert.ErrorIs(t, cfg.ValidateBasic(), errInvalidReceiveRate)
assert.ErrorIs(t, cfg.ValidateBasic(), ErrInvalidReceiveRate)
})

t.Run("valid configuration", func(t *testing.T) {
Expand Down

0 comments on commit 32b843c

Please sign in to comment.