avoid iterating over already selected txs#7664
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request implements a selection offset mechanism to avoid re-iterating over transactions that have already been selected for proposed blocks. The feature tracks which transactions have been included in proposed blocks and maintains an offset per sender to skip those transactions during future selections.
Changes:
- Added
selectionOffsetfield totxListForSenderto track the index from which selection should start - Refactored transaction insertion logic to separate index finding from insertion, enabling proper offset adjustment
- Integrated offset management with the block proposal and replacement flows in the selection tracker
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| txcache/txListForSender.go | Added selectionOffset field and methods to manage it (increment, decrement, reset); updated AddTx and removal methods to adjust offset |
| txcache/orderedTransactionsList.go | Refactored insert method into findInsertionIndex and insertAt; added getAllFromIndex and findIndexByNonce helper methods |
| txcache/selection.go | Updated acquireBunchesOfTransactions to use getTxsForSelection instead of getTxs, respecting the selection offset |
| txcache/txCache.go | Added SetSelectionOffsetsByLastNonce and ResetSelectionOffsetsToNonce public methods; minor import reordering |
| txcache/selectionTracker.go | Integrated offset updates after block proposal and removal, collecting sender nonces to reset offsets appropriately |
| txcache/trackedBlock.go | Modified compileBreadcrumbs to return lastNoncePerSender map for offset updates |
| txcache/interface.go | Extended txCacheForSelectionTracker interface with new offset management methods |
| txcache/*_test.go | Updated tests to handle new return values and added comprehensive test coverage for offset functionality |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…in-go into optimize-txs-selection
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| // If transaction was inserted before the selection offset, increment offset to maintain position | ||
| if insertionIndex < listForSender.selectionOffset { | ||
| listForSender.selectionOffset++ |
There was a problem hiding this comment.
| listForSender.selectionOffset++ | |
| listForSender.incrementSelectionOffset(1) |
|
|
||
| // If removal is at index < offset, decrement offset | ||
| if i < listForSender.selectionOffset { | ||
| listForSender.selectionOffset-- |
There was a problem hiding this comment.
| listForSender.selectionOffset-- | |
| listForSender.decrementSelectionOffset(1) |
| func (listForSender *txListForSender) getTxsForSelection() []*WrappedTransaction { | ||
| listForSender.mutex.RLock() | ||
| defer listForSender.mutex.RUnlock() | ||
|
|
There was a problem hiding this comment.
not for this PR: maybe to have the methods with mutex protection exported, not very clear from here what should be with mutex protection and what is used internally
…selection fix test after optimization
Reasoning behind the pull request
This pull request implements a selection offset mechanism to avoid re-iterating over transactions that have already been selected for proposed blocks. The feature tracks which transactions have been included in proposed blocks and maintains an offset per sender to skip those transactions during future selections.
Proposed changes
Testing procedure
Pre-requisites
Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:
featbranch created?featbranch merging, do all satellite projects have a proper tag insidego.mod?