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
This commit is contained in:
Jun Kimura 2019-08-06 01:01:30 +09:00 committed by Anton Kaliaev
parent 0cf8812b17
commit e179787d40
7 changed files with 21 additions and 17 deletions

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:

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 { if cfg.MaxTxBytes < 0 {
return errors.New("max_msg_bytes can't be negative") return errors.New("max_tx_bytes can't be negative")
} }
return nil return nil
} }

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 # Maximum size of a single transaction.
max_msg_bytes = {{ .Mempool.MaxMsgBytes }} # 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]

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 # Maximum size of a single transaction.
max_msg_bytes = 1048576 # 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]

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 { if txSize > mem.config.MaxTxBytes {
return ErrTxTooLarge{max, txSize} return ErrTxTooLarge{mem.config.MaxTxBytes, txSize}
} }
if mem.preCheck != nil { if mem.preCheck != nil {

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 := mempl.config.MaxTxBytes
maxTxSize := calcMaxTxSize(mempl.config.MaxMsgBytes) maxMsgSize := calcMaxMsgSize(maxTxSize)
testCases := []struct { testCases := []struct {
len int len int

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 { maxMsgSize := calcMaxMsgSize(memR.config.MaxTxBytes)
return msg, ErrTxTooLarge{memR.config.MaxMsgBytes, l} 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 { func calcMaxMsgSize(maxTxSize int) int {
return maxMsgSize - aminoOverheadForTxMessage return maxTxSize + aminoOverheadForTxMessage
} }