Skip to content

OEV-605: Adds purging unstarted txs to txmv2#274

Merged
dimriou merged 5 commits into
developfrom
feature/OEV-605/prune-unstarted-txs
Oct 20, 2025
Merged

OEV-605: Adds purging unstarted txs to txmv2#274
dimriou merged 5 commits into
developfrom
feature/OEV-605/prune-unstarted-txs

Conversation

@cl-efornaciari
Copy link
Copy Markdown
Contributor

adds purging unstarted txs beyond the cutoff

adds purging unstarted txs beyond the cutoff
@cl-efornaciari cl-efornaciari requested review from a team and dimriou as code owners October 15, 2025 17:02
@github-actions
Copy link
Copy Markdown
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!

Comment thread pkg/txm/storage/inmemory_store.go Outdated
return nil, nil
}
prunedTxIDs := m.pruneUnstartedTransactionsWithinDuration(pruneUnstartedTxDuration)
if prunedTxIDs != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

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
}

Copy link
Copy Markdown
Contributor

@dimriou dimriou Oct 16, 2025

Choose a reason for hiding this comment

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

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
}

m.lggr.Debugf("Unstarted transactions queue is empty for address: %v", m.address)
return nil, nil
}
prunedTxIDs := m.pruneUnstartedTransactionsWithinDuration(pruneUnstartedTxDuration)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will panic. Needs to be before the check on line 299.

@dimriou dimriou merged commit cd88603 into develop Oct 20, 2025
34 checks passed
@dimriou dimriou deleted the feature/OEV-605/prune-unstarted-txs branch October 20, 2025 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants