-
Notifications
You must be signed in to change notification settings - Fork 215
Supernova TxPool Part2: Fixed eviction consistency #7352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/mempool-supernova-part2
Are you sure you want to change the base?
Supernova TxPool Part2: Fixed eviction consistency #7352
Conversation
// Keep track of removed transactions | ||
txHashesToEvict = append(txHashesToEvict, tx.TxHash) | ||
if !tracker.IsTransactionTracked(tx) { | ||
_ = listForSender.items.Remove(element) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove only if the transaction is not tracked
return breadcrumb.lastNonce.Value + 1, st.latestRootHash, nil | ||
} | ||
|
||
// GetBulkOfUntrackedTransactions returns the hashes of the untracked transactions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not used anymore
require.Nil(t, err) | ||
|
||
cache.AddTx(createTx([]byte("tx-alice-3"), "alice", 3).withGasLimit(1500000)) | ||
require.Equal(t, []string{"tx-alice-1", "tx-alice-2", "tx-alice-3", "tx-alice-4"}, cache.getHashesForSender("alice")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because the nonce=3 is tracked for alice, no tx is removed from the list.
evictedTxHashes := make([][]byte, 0) | ||
|
||
// Iterate back to front | ||
for element := listForSender.items.Back(); element != nil; element = element.Prev() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discovered a bug here.
when removing an element, the previous becomes nil, so at the first tx removed, we break the loop. which means that we can't evict more txs. the bug is solved here by first finding the next element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes eviction consistency issues in the transaction pool by ensuring tracked transactions are handled properly during eviction. The main issue was that transactions removed from sender lists might not be removed from the txByHashMap, and there was a bug in the eviction loop iteration.
Key changes:
- Added tracking checks before removing transactions during eviction
- Fixed iterator bug in
applySizeConstraints
method that was preventing proper eviction - Updated function signatures to accept
tracker
parameter for tracking validation
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
txcache/txListForSender.go | Fixed eviction loop iterator and added tracking validation before removal |
txcache/txCache.go | Simplified eviction logic by removing redundant tracking checks |
txcache/eviction.go | Added tracking validation to eviction process |
txcache/autoClean.go | Added tracking validation to sweepable transaction removal |
txcache/selectionTracker.go | Made IsTransactionTracked method public and removed unused bulk methods |
txcache/txListBySenderMap.go | Updated method signature to pass tracker parameter |
Test files | Updated test calls to include tracker parameter |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
for element := listForSender.items.Back(); element != nil; { | ||
if !listForSender.isCapacityExceeded() { | ||
break | ||
} | ||
|
||
listForSender.items.Remove(element) | ||
listForSender.onRemovedListElement(element) | ||
|
||
// Keep track of removed transactions | ||
value := element.Value.(*WrappedTransaction) | ||
evictedTxHashes = append(evictedTxHashes, value.TxHash) | ||
|
||
prevElem := element.Prev() | ||
|
||
if !tracker.IsTransactionTracked(value) { | ||
listForSender.items.Remove(element) | ||
listForSender.onRemovedListElement(element) | ||
|
||
// Keep track of removed transactions | ||
evictedTxHashes = append(evictedTxHashes, value.TxHash) | ||
} | ||
|
||
element = prevElem | ||
} |
Copilot
AI
Oct 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for removing transactions is incorrect. Currently, only untracked transactions are removed from the list and added to evictedTxHashes, but tracked transactions that exceed capacity are skipped entirely. This means capacity constraints may not be properly enforced when transactions are tracked. The removal logic should handle both cases appropriately.
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, added already a TODO for this discussion.
if !tracker.IsTransactionTracked(tx) { | ||
_ = listForSender.items.Remove(element) | ||
listForSender.onRemovedListElement(element) | ||
|
||
// Keep track of removed transactions | ||
txHashesToEvict = append(txHashesToEvict, tx.TxHash) | ||
} | ||
|
||
element = nextElement |
Copilot
AI
Oct 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the previous issue, this logic only removes untracked transactions but doesn't handle tracked transactions that should be swept. If a transaction with a lower nonce is tracked, it will remain in the list even though it should be removed based on the sweeping criteria.
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, added already a TODO for this discussion.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## feat/mempool-supernova-part2 #7352 +/- ##
================================================================
- Coverage 75.30% 75.29% -0.01%
================================================================
Files 842 842
Lines 138067 138017 -50
================================================================
- Hits 103969 103920 -49
- Misses 28270 28273 +3
+ Partials 5828 5824 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
// AddTx adds a transaction in sender's list | ||
// This is a "sorted" insert | ||
func (listForSender *txListForSender) AddTx(tx *WrappedTransaction) (bool, [][]byte) { | ||
func (listForSender *txListForSender) AddTx(tx *WrappedTransaction, tracker *selectionTracker) (bool, [][]byte) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check tracker for against nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
hashesBeforeEviction := list.getTxHashesAsStrings() | ||
|
||
list.removeSweepableTransactionsReturnHashes(uint64(3)) | ||
list.removeSweepableTransactionsReturnHashes(uint64(3), txCache.tracker) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we also check autoclean for tracked transactions and also consistency between the 2 maps?
Reasoning behind the pull request
Current issue: the transactions which are removed from the list of the sender might not be removed from the txByHashMap.
Proposed changes
Testing procedure
Pre-requisites
Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:
feat
branch created?feat
branch merging, do all satellite projects have a proper tag insidego.mod
?