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 max tx gas limit #251

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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 @@ -779,6 +779,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"`

// Maximium gas of a single transaction
MaxTxGas int64 `mapstructure:"max-tx-gas"`

// 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 @@ -830,6 +833,7 @@ func DefaultMempoolConfig() *MempoolConfig {
MaxTxsBytes: 1024 * 1024 * 1024, // 1GB
CacheSize: 10000,
MaxTxBytes: 1024 * 1024, // 1MB
MaxTxGas: 7000000, // Block gas limit is 10m
TTLDuration: 0 * time.Second,
TTLNumBlocks: 0,
TxNotifyThreshold: 0,
Expand Down
5 changes: 5 additions & 0 deletions internal/mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,11 @@ func (txmp *TxMempool) ReapMaxBytesMaxGas(maxBytes, maxGas int64) types.Txs {
if maxBytes > -1 && totalSize+size > maxBytes {
return false
}

if wtx.gasWanted >= txmp.config.MaxTxGas {
txmp.metrics.TxGasWantedTooHigh.Add(1)
return false
}
totalSize += size
gas := totalGas + wtx.gasWanted
if maxGas > -1 && gas > maxGas {
Expand Down
29 changes: 18 additions & 11 deletions internal/mempool/metrics.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions internal/mempool/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ type Metrics struct {
// Total current mempool uncommitted txs bytes
TotalTxsSizeBytes metrics.Gauge

// Number of txs rejected because of high gas wanted
TxGasWantedTooHigh metrics.Counter

// Number of failed transactions.
FailedTxs metrics.Counter

Expand Down
Loading