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

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 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?

@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 🎉

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