OEV-605: Adds purging unstarted txs to txmv2#274
Merged
Conversation
adds purging unstarted txs beyond the cutoff
Contributor
|
👋 cl-efornaciari, thanks for creating this pull request! To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team. Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks! |
dimriou
reviewed
Oct 16, 2025
| return nil, nil | ||
| } | ||
| prunedTxIDs := m.pruneUnstartedTransactionsWithinDuration(pruneUnstartedTxDuration) | ||
| if prunedTxIDs != nil { |
Contributor
There was a problem hiding this comment.
It's safer to check like this:
Suggested change
| if prunedTxIDs != nil { | |
| if len(prunedTxIDs) != 0 { |
because depending on the implementation, a slice could be != nil, but still have 0 elements. len method is safe to use even for nil slices.
dimriou
reviewed
Oct 16, 2025
Comment on lines
+274
to
+294
| // Shouldn't call lock because it's being called by a method that already has the lock | ||
| func (m *InMemoryStore) pruneUnstartedTransactionsWithinDuration(threshold time.Duration) []uint64 { | ||
| var txIDsToPrune []uint64 | ||
| idxTxToRetain := 0 | ||
| for ; idxTxToRetain < len(m.UnstartedTransactions); idxTxToRetain++ { | ||
| tx := m.UnstartedTransactions[idxTxToRetain] | ||
| if time.Since(tx.CreatedAt) < threshold { | ||
| break | ||
| } | ||
| txIDsToPrune = append(txIDsToPrune, tx.ID) | ||
| delete(m.Transactions, tx.ID) | ||
| m.UnstartedTransactions[idxTxToRetain] = nil // prevent memory leak | ||
| } | ||
| if len(txIDsToPrune) == 0 { | ||
| return nil | ||
| } | ||
| m.UnstartedTransactions = m.UnstartedTransactions[idxTxToRetain:] | ||
| sort.Slice(txIDsToPrune, func(i, j int) bool { return txIDsToPrune[i] < txIDsToPrune[j] }) | ||
| return txIDsToPrune | ||
| } | ||
|
|
Contributor
There was a problem hiding this comment.
Does the work 👍 . Here's a more idiomatic way for future reference:
Suggested change
| // Shouldn't call lock because it's being called by a method that already has the lock | |
| func (m *InMemoryStore) pruneUnstartedTransactionsWithinDuration(threshold time.Duration) []uint64 { | |
| var txIDsToPrune []uint64 | |
| idxTxToRetain := 0 | |
| for ; idxTxToRetain < len(m.UnstartedTransactions); idxTxToRetain++ { | |
| tx := m.UnstartedTransactions[idxTxToRetain] | |
| if time.Since(tx.CreatedAt) < threshold { | |
| break | |
| } | |
| txIDsToPrune = append(txIDsToPrune, tx.ID) | |
| delete(m.Transactions, tx.ID) | |
| m.UnstartedTransactions[idxTxToRetain] = nil // prevent memory leak | |
| } | |
| if len(txIDsToPrune) == 0 { | |
| return nil | |
| } | |
| m.UnstartedTransactions = m.UnstartedTransactions[idxTxToRetain:] | |
| sort.Slice(txIDsToPrune, func(i, j int) bool { return txIDsToPrune[i] < txIDsToPrune[j] }) | |
| return txIDsToPrune | |
| } | |
| // Shouldn't call lock because it's being called by a method that already has the lock | |
| func (m *InMemoryStore) pruneUnstartedTransactionsWithinDuration(threshold time.Duration) (txIDsToPrune []uint64) { | |
| for i, tx := range m.UnstartedTransactions { | |
| if time.Since(tx.CreatedAt) < threshold { | |
| m.UnstartedTransactions = m.UnstartedTransactions[i:] | |
| return txIDsToPrune // you can sort before this if you want to | |
| } | |
| txIDsToPrune = append(txIDsToPrune, tx.ID) | |
| delete(m.Transactions, tx.ID) | |
| m.UnstartedTransactions[i] = nil // prevent memory leak | |
| } | |
| m.UnstartedTransactions = m.UnstartedTransactions[:0] | |
| return | |
| } |
dimriou
reviewed
Oct 16, 2025
| m.lggr.Debugf("Unstarted transactions queue is empty for address: %v", m.address) | ||
| return nil, nil | ||
| } | ||
| prunedTxIDs := m.pruneUnstartedTransactionsWithinDuration(pruneUnstartedTxDuration) |
Contributor
There was a problem hiding this comment.
This will panic. Needs to be before the check on line 299.
dimriou
approved these changes
Oct 17, 2025
dhaidashenko
approved these changes
Oct 20, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
adds purging unstarted txs beyond the cutoff