From 8470b53d88d202948295dec28fda2d9340f00204 Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Mon, 30 Oct 2017 07:49:33 +0000 Subject: [PATCH 1/4] core: allow price bump at threshold --- core/tx_list.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/tx_list.go b/core/tx_list.go index 2935929d72c8..838433b89719 100644 --- a/core/tx_list.go +++ b/core/tx_list.go @@ -254,7 +254,10 @@ func (l *txList) Add(tx *types.Transaction, priceBump uint64) (bool, *types.Tran old := l.txs.Get(tx.Nonce()) if old != nil { threshold := new(big.Int).Div(new(big.Int).Mul(old.GasPrice(), big.NewInt(100+int64(priceBump))), big.NewInt(100)) - if threshold.Cmp(tx.GasPrice()) >= 0 { + // Have to ensure that the new gas price is higher than the old gas + // price as well as checking the percentage threshold to ensure that + // this is accurate for low (Wei-level) gas price replacements + if old.GasPrice().Cmp(tx.GasPrice()) >= 0 || threshold.Cmp(tx.GasPrice()) > 0 { return false, nil } } From 00e371d15985fd52db23f00dbcdc0b1606d772bd Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Mon, 30 Oct 2017 07:50:02 +0000 Subject: [PATCH 2/4] core: test changes to allow price bump at threshold --- core/tx_pool_test.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/core/tx_pool_test.go b/core/tx_pool_test.go index eec128cbaf5a..7436c4c79256 100644 --- a/core/tx_pool_test.go +++ b/core/tx_pool_test.go @@ -1411,10 +1411,7 @@ func TestTransactionReplacement(t *testing.T) { if err := pool.AddRemote(pricedTransaction(0, big.NewInt(100000), big.NewInt(price), key)); err != nil { t.Fatalf("failed to add original proper pending transaction: %v", err) } - if err := pool.AddRemote(pricedTransaction(0, big.NewInt(100000), big.NewInt(threshold), key)); err != ErrReplaceUnderpriced { - t.Fatalf("original proper pending transaction replacement error mismatch: have %v, want %v", err, ErrReplaceUnderpriced) - } - if err := pool.AddRemote(pricedTransaction(0, big.NewInt(100000), big.NewInt(threshold+1), key)); err != nil { + if err := pool.AddRemote(pricedTransaction(0, big.NewInt(100000), big.NewInt(threshold), key)); err != nil { t.Fatalf("failed to replace original proper pending transaction: %v", err) } if err := validateEvents(events, 2); err != nil { @@ -1434,10 +1431,7 @@ func TestTransactionReplacement(t *testing.T) { if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100000), big.NewInt(price), key)); err != nil { t.Fatalf("failed to add original queued transaction: %v", err) } - if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100001), big.NewInt(threshold), key)); err != ErrReplaceUnderpriced { - t.Fatalf("original queued transaction replacement error mismatch: have %v, want %v", err, ErrReplaceUnderpriced) - } - if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100000), big.NewInt(threshold+1), key)); err != nil { + if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100000), big.NewInt(threshold), key)); err != nil { t.Fatalf("failed to replace original queued transaction: %v", err) } From 53cbf58b998a18de2d1132f263e6a73926cd8670 Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Mon, 30 Oct 2017 09:34:10 +0000 Subject: [PATCH 3/4] core: reinstate tx replacement test underneath threshold --- core/tx_pool_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/tx_pool_test.go b/core/tx_pool_test.go index 7436c4c79256..912b7e96ef28 100644 --- a/core/tx_pool_test.go +++ b/core/tx_pool_test.go @@ -1411,6 +1411,9 @@ func TestTransactionReplacement(t *testing.T) { if err := pool.AddRemote(pricedTransaction(0, big.NewInt(100000), big.NewInt(price), key)); err != nil { t.Fatalf("failed to add original proper pending transaction: %v", err) } + if err := pool.AddRemote(pricedTransaction(0, big.NewInt(100001), big.NewInt(threshold-1), key)); err != ErrReplaceUnderpriced { + t.Fatalf("original cheap pending transaction replacement error mismatch: have %v, want %v", err, ErrReplaceUnderpriced) + } if err := pool.AddRemote(pricedTransaction(0, big.NewInt(100000), big.NewInt(threshold), key)); err != nil { t.Fatalf("failed to replace original proper pending transaction: %v", err) } @@ -1431,6 +1434,9 @@ func TestTransactionReplacement(t *testing.T) { if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100000), big.NewInt(price), key)); err != nil { t.Fatalf("failed to add original queued transaction: %v", err) } + if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100001), big.NewInt(threshold-1), key)); err != ErrReplaceUnderpriced { + t.Fatalf("original cheap pending transaction replacement error mismatch: have %v, want %v", err, ErrReplaceUnderpriced) + } if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100000), big.NewInt(threshold), key)); err != nil { t.Fatalf("failed to replace original queued transaction: %v", err) } From 866c16f1304366e794af35ae8efa48f4ab430bec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Mon, 30 Oct 2017 12:35:34 +0200 Subject: [PATCH 4/4] core: minor test failure message cleanups --- core/tx_pool_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/tx_pool_test.go b/core/tx_pool_test.go index 912b7e96ef28..737ea4cd3946 100644 --- a/core/tx_pool_test.go +++ b/core/tx_pool_test.go @@ -1412,7 +1412,7 @@ func TestTransactionReplacement(t *testing.T) { t.Fatalf("failed to add original proper pending transaction: %v", err) } if err := pool.AddRemote(pricedTransaction(0, big.NewInt(100001), big.NewInt(threshold-1), key)); err != ErrReplaceUnderpriced { - t.Fatalf("original cheap pending transaction replacement error mismatch: have %v, want %v", err, ErrReplaceUnderpriced) + t.Fatalf("original proper pending transaction replacement error mismatch: have %v, want %v", err, ErrReplaceUnderpriced) } if err := pool.AddRemote(pricedTransaction(0, big.NewInt(100000), big.NewInt(threshold), key)); err != nil { t.Fatalf("failed to replace original proper pending transaction: %v", err) @@ -1422,23 +1422,23 @@ func TestTransactionReplacement(t *testing.T) { } // Add queued transactions, ensuring the minimum price bump is enforced for replacement (for ultra low prices too) if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100000), big.NewInt(1), key)); err != nil { - t.Fatalf("failed to add original queued transaction: %v", err) + t.Fatalf("failed to add original cheap queued transaction: %v", err) } if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100001), big.NewInt(1), key)); err != ErrReplaceUnderpriced { - t.Fatalf("original queued transaction replacement error mismatch: have %v, want %v", err, ErrReplaceUnderpriced) + t.Fatalf("original cheap queued transaction replacement error mismatch: have %v, want %v", err, ErrReplaceUnderpriced) } if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100000), big.NewInt(2), key)); err != nil { - t.Fatalf("failed to replace original queued transaction: %v", err) + t.Fatalf("failed to replace original cheap queued transaction: %v", err) } if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100000), big.NewInt(price), key)); err != nil { - t.Fatalf("failed to add original queued transaction: %v", err) + t.Fatalf("failed to add original proper queued transaction: %v", err) } if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100001), big.NewInt(threshold-1), key)); err != ErrReplaceUnderpriced { - t.Fatalf("original cheap pending transaction replacement error mismatch: have %v, want %v", err, ErrReplaceUnderpriced) + t.Fatalf("original proper queued transaction replacement error mismatch: have %v, want %v", err, ErrReplaceUnderpriced) } if err := pool.AddRemote(pricedTransaction(2, big.NewInt(100000), big.NewInt(threshold), key)); err != nil { - t.Fatalf("failed to replace original queued transaction: %v", err) + t.Fatalf("failed to replace original proper queued transaction: %v", err) } if err := validateEvents(events, 0); err != nil {