Skip to content

Commit

Permalink
Add MaxTxGasWanted to filter out large gas txs
Browse files Browse the repository at this point in the history
  • Loading branch information
yzang2019 committed Aug 8, 2024
1 parent 784a8e0 commit f990f4d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
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 int `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
8 changes: 8 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.MaxTxGas > 0 && wtx.gasWanted > txmp.config.MaxTxsBytes

Check failure on line 372 in internal/mempool/mempool.go

View workflow job for this annotation

GitHub Actions / tests (01)

txmp.config.MaxTxGas undefined (type *config.MempoolConfig has no field or method MaxTxGas)

Check failure on line 372 in internal/mempool/mempool.go

View workflow job for this annotation

GitHub Actions / tests (02)

txmp.config.MaxTxGas undefined (type *config.MempoolConfig has no field or method MaxTxGas)

Check failure on line 372 in internal/mempool/mempool.go

View workflow job for this annotation

GitHub Actions / tests (03)

txmp.config.MaxTxGas undefined (type *config.MempoolConfig has no field or method MaxTxGas)

Check failure on line 372 in internal/mempool/mempool.go

View workflow job for this annotation

GitHub Actions / tests (04)

txmp.config.MaxTxGas undefined (type *config.MempoolConfig has no field or method MaxTxGas)

Check failure on line 372 in internal/mempool/mempool.go

View workflow job for this annotation

GitHub Actions / tests (09)

txmp.config.MaxTxGas undefined (type *config.MempoolConfig has no field or method MaxTxGas)

Check failure on line 372 in internal/mempool/mempool.go

View workflow job for this annotation

GitHub Actions / tests (11)

txmp.config.MaxTxGas undefined (type *config.MempoolConfig has no field or method MaxTxGas)

Check failure on line 372 in internal/mempool/mempool.go

View workflow job for this annotation

GitHub Actions / tests (15)

txmp.config.MaxTxGas undefined (type *config.MempoolConfig has no field or method MaxTxGas)

Check failure on line 372 in internal/mempool/mempool.go

View workflow job for this annotation

GitHub Actions / tests (16)

txmp.config.MaxTxGas undefined (type *config.MempoolConfig has no field or method MaxTxGas)

Check failure on line 372 in internal/mempool/mempool.go

View workflow job for this annotation

GitHub Actions / tests (17)

txmp.config.MaxTxGas undefined (type *config.MempoolConfig has no field or method MaxTxGas)

Check failure on line 372 in internal/mempool/mempool.go

View workflow job for this annotation

GitHub Actions / tests (18)

txmp.config.MaxTxGas undefined (type *config.MempoolConfig has no field or method MaxTxGas)
}

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,10 @@ func (txmp *TxMempool) addNewTransaction(wtx *WrappedTx, res *abci.ResponseCheck
txInfo.SenderID: {},
}

if txmp.shouldExclude(wtx) {
return nil
}

if txmp.isInMempool(wtx.tx) {
return nil
}
Expand Down

0 comments on commit f990f4d

Please sign in to comment.