Skip to content

Commit 0afd767

Browse files
Crispin Flowerdaykaralabe
authored andcommitted
core: ensure local transactions aren't discarded as underpriced
This fixes an issue where local transactions are discarded as underpriced when the pool and queue are full.
1 parent 448d17b commit 0afd767

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

core/tx_pool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (bool, error) {
618618
// If the transaction pool is full, discard underpriced transactions
619619
if uint64(len(pool.all)) >= pool.config.GlobalSlots+pool.config.GlobalQueue {
620620
// If the new transaction is underpriced, don't accept it
621-
if pool.priced.Underpriced(tx, pool.locals) {
621+
if !local && pool.priced.Underpriced(tx, pool.locals) {
622622
log.Trace("Discarding underpriced transaction", "hash", hash, "price", tx.GasPrice())
623623
underpricedTxCounter.Inc(1)
624624
return false, ErrUnderpriced

core/tx_pool_test.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ func TestTransactionPoolUnderpricing(t *testing.T) {
13461346
defer sub.Unsubscribe()
13471347

13481348
// Create a number of test accounts and fund them
1349-
keys := make([]*ecdsa.PrivateKey, 3)
1349+
keys := make([]*ecdsa.PrivateKey, 4)
13501350
for i := 0; i < len(keys); i++ {
13511351
keys[i], _ = crypto.GenerateKey()
13521352
pool.currentState.AddBalance(crypto.PubkeyToAddress(keys[i].PublicKey), big.NewInt(1000000))
@@ -1406,18 +1406,22 @@ func TestTransactionPoolUnderpricing(t *testing.T) {
14061406
t.Fatalf("pool internal state corrupted: %v", err)
14071407
}
14081408
// Ensure that adding local transactions can push out even higher priced ones
1409-
tx := pricedTransaction(1, 100000, big.NewInt(0), keys[2])
1410-
if err := pool.AddLocal(tx); err != nil {
1411-
t.Fatalf("failed to add underpriced local transaction: %v", err)
1409+
ltx = pricedTransaction(1, 100000, big.NewInt(0), keys[2])
1410+
if err := pool.AddLocal(ltx); err != nil {
1411+
t.Fatalf("failed to append underpriced local transaction: %v", err)
1412+
}
1413+
ltx = pricedTransaction(0, 100000, big.NewInt(0), keys[3])
1414+
if err := pool.AddLocal(ltx); err != nil {
1415+
t.Fatalf("failed to add new underpriced local transaction: %v", err)
14121416
}
14131417
pending, queued = pool.Stats()
1414-
if pending != 2 {
1415-
t.Fatalf("pending transactions mismatched: have %d, want %d", pending, 2)
1418+
if pending != 3 {
1419+
t.Fatalf("pending transactions mismatched: have %d, want %d", pending, 3)
14161420
}
1417-
if queued != 2 {
1418-
t.Fatalf("queued transactions mismatched: have %d, want %d", queued, 2)
1421+
if queued != 1 {
1422+
t.Fatalf("queued transactions mismatched: have %d, want %d", queued, 1)
14191423
}
1420-
if err := validateEvents(events, 1); err != nil {
1424+
if err := validateEvents(events, 2); err != nil {
14211425
t.Fatalf("local event firing failed: %v", err)
14221426
}
14231427
if err := validateTxPoolInternals(pool); err != nil {

0 commit comments

Comments
 (0)