Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MaxTxGasWanted to filter out large gas txs #241

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions internal/mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
Loading