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

fix: Check L1DataFee in txpool promoteExecutables and demoteUnexecutables #627

Merged
merged 11 commits into from
Mar 27, 2024
25 changes: 25 additions & 0 deletions core/tx_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,31 @@ func (l *txList) Filter(costLimit *big.Int, gasLimit uint64) (types.Transactions
return removed, invalids
}

// FilterF removes all transactions from the list that satisfy a predicate.
// Every removed transaction is returned for any
// post-removal maintenance. Strict-mode invalidated transactions are also
// returned.
Thegaram marked this conversation as resolved.
Show resolved Hide resolved
func (l *txList) FilterF(f func(tx *types.Transaction) bool) (types.Transactions, types.Transactions) {
Thegaram marked this conversation as resolved.
Show resolved Hide resolved
removed := l.txs.Filter(f)

if len(removed) == 0 {
return nil, nil
}
var invalids types.Transactions
// If the list was strict, filter anything above the lowest nonce
Thegaram marked this conversation as resolved.
Show resolved Hide resolved
if l.strict {
lowest := uint64(math.MaxUint64)
for _, tx := range removed {
if nonce := tx.Nonce(); lowest > nonce {
lowest = nonce
}
}
invalids = l.txs.filter(func(tx *types.Transaction) bool { return tx.Nonce() > lowest })
}
l.txs.reheap()
return removed, invalids
}

// Cap places a hard limit on the number of items, returning all transactions
// exceeding that limit.
func (l *txList) Cap(threshold int) types.Transactions {
Expand Down
21 changes: 20 additions & 1 deletion core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1381,8 +1381,27 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans
pool.all.Remove(hash)
}
log.Trace("Removed old queued transactions", "count", len(forwards))

// Drop all transactions that are too costly (low balance or out of gas)
drops, _ := list.Filter(pool.currentState.GetBalance(addr), pool.currentMaxGas)
costLimit := pool.currentState.GetBalance(addr)
drops, _ := list.FilterF(func(tx *types.Transaction) bool {
if tx.Gas() > pool.currentMaxGas || tx.Cost().Cmp(costLimit) > 0 {
return true
}

if pool.chainconfig.Scroll.FeeVaultEnabled() {
// recheck L1 data fee, as the oracle price may have changed
l1DataFee, err := fees.CalculateL1DataFee(tx, pool.currentState)
if err != nil {
log.Trace("Failed to calculate L1 data fee", "err", err)
return false
}
return costLimit.Cmp(new(big.Int).Add(tx.Cost(), l1DataFee)) < 0
}

return false
})

for _, tx := range drops {
hash := tx.Hash()
pool.all.Remove(hash)
Expand Down
2 changes: 1 addition & 1 deletion params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
const (
VersionMajor = 5 // Major version component of the current release
VersionMinor = 1 // Minor version component of the current release
VersionPatch = 14 // Patch version component of the current release
VersionPatch = 15 // Patch version component of the current release
VersionMeta = "mainnet" // Version metadata to append to the version string
)

Expand Down
Loading