diff --git a/config/config.go b/config/config.go index 538f191fb..e0e6d30a8 100644 --- a/config/config.go +++ b/config/config.go @@ -776,6 +776,9 @@ type MempoolConfig struct { // NOTE: the max size of a tx transmitted over the network is {max-tx-bytes}. MaxTxBytes int `mapstructure:"max-tx-bytes"` + // Maximum gas wanted of a single transaction + MaxTxGasWanted int64 `mapstructure:"max-tx-gas-wanted"` + // Maximum size of a batch of transactions to send to a peer // Including space needed by encoding (one varint per transaction). // XXX: Unused due to https://github.com/tendermint/tendermint/issues/5796 @@ -827,6 +830,7 @@ func DefaultMempoolConfig() *MempoolConfig { MaxTxsBytes: 1024 * 1024 * 1024, // 1GB CacheSize: 10000, MaxTxBytes: 1024 * 1024, // 1MB + MaxTxGasWanted: 0, TTLDuration: 0 * time.Second, TTLNumBlocks: 0, TxNotifyThreshold: 0, diff --git a/config/toml.go b/config/toml.go index 0dceb12e5..0f426469e 100644 --- a/config/toml.go +++ b/config/toml.go @@ -381,6 +381,9 @@ keep-invalid-txs-in-cache = {{ .Mempool.KeepInvalidTxsInCache }} # NOTE: the max size of a tx transmitted over the network is {max-tx-bytes}. max-tx-bytes = {{ .Mempool.MaxTxBytes }} +# Maximum gas of a single transaction. +max-tx-gas-wanted = {{ .Mempool.MaxTxGasWanted }} + # Maximum size of a batch of transactions to send to a peer # Including space needed by encoding (one varint per transaction). # XXX: Unused due to https://github.com/tendermint/tendermint/issues/5796 diff --git a/internal/mempool/mempool.go b/internal/mempool/mempool.go index 1f069b1c9..05bd7335a 100644 --- a/internal/mempool/mempool.go +++ b/internal/mempool/mempool.go @@ -368,6 +368,10 @@ func (txmp *TxMempool) CheckTx( return nil } +func (txmp *TxMempool) shouldExclude(wtx *WrappedTx) bool { + return txmp.config.MaxTxGasWanted > 0 && wtx.gasWanted > txmp.config.MaxTxGasWanted +} + func (txmp *TxMempool) isInMempool(tx types.Tx) bool { existingTx := txmp.txStore.GetTxByHash(tx.Key()) return existingTx != nil && !existingTx.removed @@ -681,6 +685,16 @@ func (txmp *TxMempool) addNewTransaction(wtx *WrappedTx, res *abci.ResponseCheck txInfo.SenderID: {}, } + if txmp.shouldExclude(wtx) { + txmp.logger.Info( + "excluded good transaction which has high gas wanted", + "gasWanted", wtx.gasWanted, + "tx", fmt.Sprintf("%X", wtx.tx.Hash()), + "height", txmp.height, + ) + return nil + } + if txmp.isInMempool(wtx.tx) { return nil }