Skip to content

Commit

Permalink
Perform gas price limit check for dynamic tx (#1846)
Browse files Browse the repository at this point in the history
  • Loading branch information
begmaroman committed Aug 24, 2023
1 parent 1794897 commit 2fea208
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
12 changes: 6 additions & 6 deletions txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,13 +659,13 @@ func (p *TxPool) validateTx(tx *types.Transaction) error {

return ErrUnderpriced
}
} else {
// Legacy approach to check if the given tx is not underpriced
if tx.GetGasPrice(baseFee).Cmp(big.NewInt(0).SetUint64(p.priceLimit)) < 0 {
metrics.IncrCounter([]string{txPoolMetrics, "underpriced_tx"}, 1)
}

return ErrUnderpriced
}
// Check if the given tx is not underpriced
if tx.GetGasPrice(baseFee).Cmp(new(big.Int).SetUint64(p.priceLimit)) < 0 {
metrics.IncrCounter([]string{txPoolMetrics, "underpriced_tx"}, 1)

return ErrUnderpriced
}

// Check nonce ordering
Expand Down
3 changes: 3 additions & 0 deletions txpool/txpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

const (
defaultPriceLimit uint64 = 1
defaultBaseFee uint64 = 1
defaultMaxSlots uint64 = 4096
defaultMaxAccountEnqueued uint64 = 128
validGasLimit uint64 = 4712350
Expand Down Expand Up @@ -2793,6 +2794,8 @@ func TestExecutablesOrder(t *testing.T) {

pool, err := newTestPool()
assert.NoError(t, err)

pool.baseFee = defaultBaseFee
pool.SetSigner(&mockSigner{})

pool.Start()
Expand Down
2 changes: 1 addition & 1 deletion types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (t *Transaction) Cost() *big.Int {
//
// Here is the logic:
// - use existing gas price if exists
// - or calculate a value with formula: min(gasFeeCap, gasTipCap * baseFee);
// - or calculate a value with formula: min(gasFeeCap, gasTipCap + baseFee);
func (t *Transaction) GetGasPrice(baseFee uint64) *big.Int {
if t.GasPrice != nil && t.GasPrice.BitLen() > 0 {
return new(big.Int).Set(t.GasPrice)
Expand Down

0 comments on commit 2fea208

Please sign in to comment.