Skip to content

Commit 0131bd6

Browse files
mcdeekaralabe
authored andcommitted
core: respect price bump threshold (#15401)
* core: allow price bump at threshold * core: test changes to allow price bump at threshold * core: reinstate tx replacement test underneath threshold * core: minor test failure message cleanups
1 parent dd8a626 commit 0131bd6

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

core/tx_list.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,10 @@ func (l *txList) Add(tx *types.Transaction, priceBump uint64) (bool, *types.Tran
254254
old := l.txs.Get(tx.Nonce())
255255
if old != nil {
256256
threshold := new(big.Int).Div(new(big.Int).Mul(old.GasPrice(), big.NewInt(100+int64(priceBump))), big.NewInt(100))
257-
if threshold.Cmp(tx.GasPrice()) >= 0 {
257+
// Have to ensure that the new gas price is higher than the old gas
258+
// price as well as checking the percentage threshold to ensure that
259+
// this is accurate for low (Wei-level) gas price replacements
260+
if old.GasPrice().Cmp(tx.GasPrice()) >= 0 || threshold.Cmp(tx.GasPrice()) > 0 {
258261
return false, nil
259262
}
260263
}

core/tx_pool_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,34 +1411,34 @@ func TestTransactionReplacement(t *testing.T) {
14111411
if err := pool.AddRemote(pricedTransaction(0, big.NewInt(100000), big.NewInt(price), key)); err != nil {
14121412
t.Fatalf("failed to add original proper pending transaction: %v", err)
14131413
}
1414-
if err := pool.AddRemote(pricedTransaction(0, big.NewInt(100000), big.NewInt(threshold), key)); err != ErrReplaceUnderpriced {
1414+
if err := pool.AddRemote(pricedTransaction(0, big.NewInt(100001), big.NewInt(threshold-1), key)); err != ErrReplaceUnderpriced {
14151415
t.Fatalf("original proper pending transaction replacement error mismatch: have %v, want %v", err, ErrReplaceUnderpriced)
14161416
}
1417-
if err := pool.AddRemote(pricedTransaction(0, big.NewInt(100000), big.NewInt(threshold+1), key)); err != nil {
1417+
if err := pool.AddRemote(pricedTransaction(0, big.NewInt(100000), big.NewInt(threshold), key)); err != nil {
14181418
t.Fatalf("failed to replace original proper pending transaction: %v", err)
14191419
}
14201420
if err := validateEvents(events, 2); err != nil {
14211421
t.Fatalf("proper replacement event firing failed: %v", err)
14221422
}
14231423
// Add queued transactions, ensuring the minimum price bump is enforced for replacement (for ultra low prices too)
14241424
if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100000), big.NewInt(1), key)); err != nil {
1425-
t.Fatalf("failed to add original queued transaction: %v", err)
1425+
t.Fatalf("failed to add original cheap queued transaction: %v", err)
14261426
}
14271427
if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100001), big.NewInt(1), key)); err != ErrReplaceUnderpriced {
1428-
t.Fatalf("original queued transaction replacement error mismatch: have %v, want %v", err, ErrReplaceUnderpriced)
1428+
t.Fatalf("original cheap queued transaction replacement error mismatch: have %v, want %v", err, ErrReplaceUnderpriced)
14291429
}
14301430
if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100000), big.NewInt(2), key)); err != nil {
1431-
t.Fatalf("failed to replace original queued transaction: %v", err)
1431+
t.Fatalf("failed to replace original cheap queued transaction: %v", err)
14321432
}
14331433

14341434
if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100000), big.NewInt(price), key)); err != nil {
1435-
t.Fatalf("failed to add original queued transaction: %v", err)
1435+
t.Fatalf("failed to add original proper queued transaction: %v", err)
14361436
}
1437-
if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100001), big.NewInt(threshold), key)); err != ErrReplaceUnderpriced {
1438-
t.Fatalf("original queued transaction replacement error mismatch: have %v, want %v", err, ErrReplaceUnderpriced)
1437+
if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100001), big.NewInt(threshold-1), key)); err != ErrReplaceUnderpriced {
1438+
t.Fatalf("original proper queued transaction replacement error mismatch: have %v, want %v", err, ErrReplaceUnderpriced)
14391439
}
1440-
if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100000), big.NewInt(threshold+1), key)); err != nil {
1441-
t.Fatalf("failed to replace original queued transaction: %v", err)
1440+
if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100000), big.NewInt(threshold), key)); err != nil {
1441+
t.Fatalf("failed to replace original proper queued transaction: %v", err)
14421442
}
14431443

14441444
if err := validateEvents(events, 0); err != nil {

0 commit comments

Comments
 (0)