Browse Source

mempool: make `max_tx_bytes` configurable instead of `max_msg_bytes` (#3877)

Fix #3868 (comment)

Commits:

* mempool: make `max_tx_bytes` configurable instead of `max_msg_bytes`

* update CHANGELOG_PENDING

* apply suggestions from code review
pull/3912/head
Jun Kimura 5 years ago
committed by Anton Kaliaev
parent
commit
e179787d40
7 changed files with 21 additions and 17 deletions
  1. +1
    -0
      CHANGELOG_PENDING.md
  2. +4
    -4
      config/config.go
  3. +3
    -2
      config/toml.go
  4. +3
    -2
      docs/tendermint-core/configuration.md
  5. +2
    -2
      mempool/clist_mempool.go
  6. +2
    -2
      mempool/clist_mempool_test.go
  7. +6
    -5
      mempool/reactor.go

+ 1
- 0
CHANGELOG_PENDING.md View File

@ -21,6 +21,7 @@ program](https://hackerone.com/tendermint).
- [privval] \#3370 Refactors and simplifies validator/kms connection handling. Please refer to thttps://github.com/tendermint/tendermint/pull/3370#issue-257360971 - [privval] \#3370 Refactors and simplifies validator/kms connection handling. Please refer to thttps://github.com/tendermint/tendermint/pull/3370#issue-257360971
- [consensus] \#3839 Reduce "Error attempting to add vote" message severity (Error -> Info) - [consensus] \#3839 Reduce "Error attempting to add vote" message severity (Error -> Info)
- [mempool] \#3877 Make `max_tx_bytes` configurable instead of `max_msg_bytes`
### BUG FIXES: ### BUG FIXES:


+ 4
- 4
config/config.go View File

@ -637,7 +637,7 @@ type MempoolConfig struct {
Size int `mapstructure:"size"` Size int `mapstructure:"size"`
MaxTxsBytes int64 `mapstructure:"max_txs_bytes"` MaxTxsBytes int64 `mapstructure:"max_txs_bytes"`
CacheSize int `mapstructure:"cache_size"` CacheSize int `mapstructure:"cache_size"`
MaxMsgBytes int `mapstructure:"max_msg_bytes"`
MaxTxBytes int `mapstructure:"max_tx_bytes"`
} }
// DefaultMempoolConfig returns a default configuration for the Tendermint mempool // DefaultMempoolConfig returns a default configuration for the Tendermint mempool
@ -651,7 +651,7 @@ func DefaultMempoolConfig() *MempoolConfig {
Size: 5000, Size: 5000,
MaxTxsBytes: 1024 * 1024 * 1024, // 1GB MaxTxsBytes: 1024 * 1024 * 1024, // 1GB
CacheSize: 10000, CacheSize: 10000,
MaxMsgBytes: 1024 * 1024, // 1MB
MaxTxBytes: 1024 * 1024, // 1MB
} }
} }
@ -684,8 +684,8 @@ func (cfg *MempoolConfig) ValidateBasic() error {
if cfg.CacheSize < 0 { if cfg.CacheSize < 0 {
return errors.New("cache_size can't be negative") return errors.New("cache_size can't be negative")
} }
if cfg.MaxMsgBytes < 0 {
return errors.New("max_msg_bytes can't be negative")
if cfg.MaxTxBytes < 0 {
return errors.New("max_tx_bytes can't be negative")
} }
return nil return nil
} }


+ 3
- 2
config/toml.go View File

@ -294,8 +294,9 @@ max_txs_bytes = {{ .Mempool.MaxTxsBytes }}
# Size of the cache (used to filter transactions we saw earlier) in transactions # Size of the cache (used to filter transactions we saw earlier) in transactions
cache_size = {{ .Mempool.CacheSize }} cache_size = {{ .Mempool.CacheSize }}
# Limit the size of TxMessage
max_msg_bytes = {{ .Mempool.MaxMsgBytes }}
# Maximum size of a single transaction.
# NOTE: the max size of a tx transmitted over the network is {max_tx_bytes} + {amino overhead}.
max_tx_bytes = {{ .Mempool.MaxTxBytes }}
##### fast sync configuration options ##### ##### fast sync configuration options #####
[fastsync] [fastsync]


+ 3
- 2
docs/tendermint-core/configuration.md View File

@ -240,8 +240,9 @@ max_txs_bytes = 1073741824
# Size of the cache (used to filter transactions we saw earlier) in transactions # Size of the cache (used to filter transactions we saw earlier) in transactions
cache_size = 10000 cache_size = 10000
# Limit the size of TxMessage
max_msg_bytes = 1048576
# Maximum size of a single transaction.
# NOTE: the max size of a tx transmitted over the network is {max_tx_bytes} + {amino overhead}.
max_tx_bytes = 1048576
##### fast sync configuration options ##### ##### fast sync configuration options #####
[fastsync] [fastsync]


+ 2
- 2
mempool/clist_mempool.go View File

@ -232,8 +232,8 @@ func (mem *CListMempool) CheckTxWithInfo(tx types.Tx, cb func(*abci.Response), t
// The size of the corresponding amino-encoded TxMessage // The size of the corresponding amino-encoded TxMessage
// can't be larger than the maxMsgSize, otherwise we can't // can't be larger than the maxMsgSize, otherwise we can't
// relay it to peers. // relay it to peers.
if max := calcMaxTxSize(mem.config.MaxMsgBytes); txSize > max {
return ErrTxTooLarge{max, txSize}
if txSize > mem.config.MaxTxBytes {
return ErrTxTooLarge{mem.config.MaxTxBytes, txSize}
} }
if mem.preCheck != nil { if mem.preCheck != nil {


+ 2
- 2
mempool/clist_mempool_test.go View File

@ -426,8 +426,8 @@ func TestMempoolMaxMsgSize(t *testing.T) {
mempl, cleanup := newMempoolWithApp(cc) mempl, cleanup := newMempoolWithApp(cc)
defer cleanup() defer cleanup()
maxMsgSize := mempl.config.MaxMsgBytes
maxTxSize := calcMaxTxSize(mempl.config.MaxMsgBytes)
maxTxSize := mempl.config.MaxTxBytes
maxMsgSize := calcMaxMsgSize(maxTxSize)
testCases := []struct { testCases := []struct {
len int len int


+ 6
- 5
mempool/reactor.go View File

@ -263,8 +263,9 @@ func RegisterMempoolMessages(cdc *amino.Codec) {
} }
func (memR *Reactor) decodeMsg(bz []byte) (msg MempoolMessage, err error) { func (memR *Reactor) decodeMsg(bz []byte) (msg MempoolMessage, err error) {
if l := len(bz); l > memR.config.MaxMsgBytes {
return msg, ErrTxTooLarge{memR.config.MaxMsgBytes, l}
maxMsgSize := calcMaxMsgSize(memR.config.MaxTxBytes)
if l := len(bz); l > maxMsgSize {
return msg, ErrTxTooLarge{maxMsgSize, l}
} }
err = cdc.UnmarshalBinaryBare(bz, &msg) err = cdc.UnmarshalBinaryBare(bz, &msg)
return return
@ -282,8 +283,8 @@ func (m *TxMessage) String() string {
return fmt.Sprintf("[TxMessage %v]", m.Tx) return fmt.Sprintf("[TxMessage %v]", m.Tx)
} }
// calcMaxTxSize returns the max size of Tx
// calcMaxMsgSize returns the max size of TxMessage
// account for amino overhead of TxMessage // account for amino overhead of TxMessage
func calcMaxTxSize(maxMsgSize int) int {
return maxMsgSize - aminoOverheadForTxMessage
func calcMaxMsgSize(maxTxSize int) int {
return maxTxSize + aminoOverheadForTxMessage
} }

Loading…
Cancel
Save