Skip to content

Conversation

@starius
Copy link
Collaborator

@starius starius commented Nov 13, 2025

Fixes a crash window where handleConf updated the batch row to confirmed but failed before marking sweeps complete, so re-added sweeps spawned a duplicate batch or kept retrying. Batch confirmation and sweep completion are now persisted inside a single DB transaction ConfirmBatchWithSweeps, and handleConf uses the helper to atomically store the batch and the set of confirmed sweeps.

Added TestSweepBatcherConfirmedBatchIncompleteSweeps that runs against the real loopdb backend, injects a failure mid-transaction, and verifies the database never ends up with confirmed=true batches paired with completed=false sweeps.

Pull Request Checklist

  • Update release_notes.md if your PR contains major features, breaking changes or bugfixes

@starius starius marked this pull request as ready for review November 15, 2025 04:29
Copy link
Collaborator

@hieblmi hieblmi left a comment

Choose a reason for hiding this comment

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

The change LGTM!

Could we just check that this couldn't happen in other places where we call b.persist(ctx)?

"purged swaps: %v. Saving the batch and sweeps to DB",
confirmedSweeps, purgedSweeps, purgedSwaps)

if err := b.persistConfirmedBatch(ctx, dbConfirmed); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice, now both batch and sweeps are persisted at the same time!

Can we make sure that in other places where we call b.persist(ctx) there doesn't arise this discrepancy?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I re-checked all other places. This is the only one when a batch and a sweep are mutated simultaneously. Also double-checked with AI - no other findings.

@lightninglabs-deploy
Copy link

@bhandras: review reminder
@sputn1ck: review reminder
@starius, remember to re-request review from reviewers when ready

Copy link
Member

@bhandras bhandras left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

Fixes a crash window where handleConf updated the batch row to confirmed but
failed before marking sweeps complete, so re-added sweeps spawned a duplicate
batch or kept retrying. Batch confirmation and sweep completion are now
persisted inside a single DB transaction ConfirmBatchWithSweeps, and handleConf
uses the helper to atomically store the batch and the set of confirmed sweeps.

Added TestSweepBatcherConfirmedBatchIncompleteSweeps that runs against the real
loopdb backend, injects a failure mid-transaction, and verifies the database
never ends up with confirmed=true batches paired with completed=false sweeps.
@starius starius force-pushed the sweepbatcher-db-tx branch from 1beb6b9 to 6d58965 Compare December 4, 2025 03:37
@starius
Copy link
Collaborator Author

starius commented Dec 4, 2025

Rebased

@starius starius requested a review from hieblmi December 4, 2025 03:37
Copy link
Collaborator

@hieblmi hieblmi left a comment

Choose a reason for hiding this comment

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

LGTM

@starius starius merged commit e79b1d4 into lightninglabs:master Dec 4, 2025
17 of 18 checks passed
@starius starius deleted the sweepbatcher-db-tx branch December 4, 2025 18:05
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.

4 participants