diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 0c7da31e..948c7b66 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -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 - [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: diff --git a/config/config.go b/config/config.go index b00702ce..d414d056 100644 --- a/config/config.go +++ b/config/config.go @@ -637,7 +637,7 @@ type MempoolConfig struct { Size int `mapstructure:"size"` MaxTxsBytes int64 `mapstructure:"max_txs_bytes"` 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 @@ -651,7 +651,7 @@ func DefaultMempoolConfig() *MempoolConfig { Size: 5000, MaxTxsBytes: 1024 * 1024 * 1024, // 1GB CacheSize: 10000, - MaxMsgBytes: 1024 * 1024, // 1MB + MaxTxBytes: 1024 * 1024, // 1MB } } @@ -684,8 +684,8 @@ func (cfg *MempoolConfig) ValidateBasic() error { if cfg.CacheSize < 0 { 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 } diff --git a/config/toml.go b/config/toml.go index b79d14d9..268c96ff 100644 --- a/config/toml.go +++ b/config/toml.go @@ -294,8 +294,9 @@ max_txs_bytes = {{ .Mempool.MaxTxsBytes }} # Size of the cache (used to filter transactions we saw earlier) in transactions 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 ##### [fastsync] diff --git a/docs/tendermint-core/configuration.md b/docs/tendermint-core/configuration.md index 8fd369d8..59a25966 100644 --- a/docs/tendermint-core/configuration.md +++ b/docs/tendermint-core/configuration.md @@ -240,8 +240,9 @@ max_txs_bytes = 1073741824 # Size of the cache (used to filter transactions we saw earlier) in transactions 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 ##### [fastsync] diff --git a/mempool/clist_mempool.go b/mempool/clist_mempool.go index fc4591d2..8df4e670 100644 --- a/mempool/clist_mempool.go +++ b/mempool/clist_mempool.go @@ -232,8 +232,8 @@ func (mem *CListMempool) CheckTxWithInfo(tx types.Tx, cb func(*abci.Response), t // The size of the corresponding amino-encoded TxMessage // can't be larger than the maxMsgSize, otherwise we can't // 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 { diff --git a/mempool/clist_mempool_test.go b/mempool/clist_mempool_test.go index 220bb5cb..666d5530 100644 --- a/mempool/clist_mempool_test.go +++ b/mempool/clist_mempool_test.go @@ -426,8 +426,8 @@ func TestMempoolMaxMsgSize(t *testing.T) { mempl, cleanup := newMempoolWithApp(cc) defer cleanup() - maxMsgSize := mempl.config.MaxMsgBytes - maxTxSize := calcMaxTxSize(mempl.config.MaxMsgBytes) + maxTxSize := mempl.config.MaxTxBytes + maxMsgSize := calcMaxMsgSize(maxTxSize) testCases := []struct { len int diff --git a/mempool/reactor.go b/mempool/reactor.go index 0ca27340..349ed7ea 100644 --- a/mempool/reactor.go +++ b/mempool/reactor.go @@ -263,8 +263,9 @@ func RegisterMempoolMessages(cdc *amino.Codec) { } 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) return @@ -282,8 +283,8 @@ func (m *TxMessage) String() string { 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 -func calcMaxTxSize(maxMsgSize int) int { - return maxMsgSize - aminoOverheadForTxMessage +func calcMaxMsgSize(maxTxSize int) int { + return maxTxSize + aminoOverheadForTxMessage }