Skip to content

Conversation

@MariusVanDerWijden
Copy link
Member

@MariusVanDerWijden MariusVanDerWijden commented Sep 4, 2025

Adds a sanity check in the transaction pool

Co-authored-by @rjl493456442

lightclient
lightclient previously approved these changes Sep 4, 2025
@rjl493456442
Copy link
Member

diff --git a/core/txpool/legacypool/list.go b/core/txpool/legacypool/list.go
index e5c48d538d..85008e3310 100644
--- a/core/txpool/legacypool/list.go
+++ b/core/txpool/legacypool/list.go
@@ -323,8 +323,6 @@ func (l *list) Add(tx *types.Transaction, priceBump uint64) (bool, *types.Transa
         if tx.GasFeeCapIntCmp(thresholdFeeCap) < 0 || tx.GasTipCapIntCmp(thresholdTip) < 0 {
             return false, nil
         }
-        // Old is being replaced, subtract old cost
-        l.subTotalCost([]*types.Transaction{old})
     }
     // Add new tx cost to totalcost
     cost, overflow := uint256.FromBig(tx.Cost())
@@ -337,6 +335,10 @@ func (l *list) Add(tx *types.Transaction, priceBump uint64) (bool, *types.Transa
     }
     l.totalcost = total
 
+    // Old is being replaced, subtract old cost
+    if old != nil {
+        l.subTotalCost([]*types.Transaction{old})
+    }
     // Otherwise overwrite the old transaction with the current one
     l.txs.Put(tx)
     if l.costcap.Cmp(cost) < 0 {

@MariusVanDerWijden
Copy link
Member Author

PTAL @rjl493456442

l.totalcost = total

// Old is being replaced, subtract old cost
l.subTotalCost([]*types.Transaction{old})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old can be nil. l.subTotalCost([]*types.Transaction{nil}) will panic, isn't it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes good catch

@rjl493456442 rjl493456442 added this to the 1.16.4 milestone Sep 10, 2025
@rjl493456442 rjl493456442 merged commit d68528c into ethereum:master Sep 10, 2025
6 of 7 checks passed
Sahil-4555 pushed a commit to Sahil-4555/go-ethereum that referenced this pull request Oct 12, 2025
Adds a sanity check in the transaction pool

Co-authored-by @rjl493456442
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants