Skip to content

Conversation

@starius
Copy link
Collaborator

@starius starius commented Mar 25, 2025

SwapHash used to be a key in the sweeps table. Now the key is outpoint which replaces columns outpoint_txid and outpoint_index. In-memory structures and unit tests were also updated to use outpoint as key. Outpoint is truly unique.

DB migration: this PR involves a DB migration. Table sweeps is recreated to make column swap_hash non-unique and to create column outpoint from columns outpoint_txid and outpoint_index. Column outpoint_txid is byte-reversed and converted to HEX. I tested the migration manually on both postgres and sqlite.

Pull Request Checklist

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

@starius starius requested review from bhandras and hieblmi March 25, 2025 17:41
@starius starius force-pushed the sweepbatcher-outpoint branch 2 times, most recently from 332e2bc to 86c9884 Compare March 25, 2025 18:45
@starius starius changed the title [WIP] sweepbatcher: allow swap_hash to be non-unique sweepbatcher: allow swap_hash to be non-unique Mar 25, 2025
@starius starius marked this pull request as ready for review March 25, 2025 20:55
@starius starius force-pushed the sweepbatcher-outpoint branch 2 times, most recently from 689061d to 0ae934b Compare March 26, 2025 15:44
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, very nice! 🥇


// primarySweepID is the swap hash of the primary sweep in the batch.
primarySweepID lntypes.Hash
primarySweepID wire.OutPoint
Copy link
Member

Choose a reason for hiding this comment

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

nit: update godoc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed. Thanks!


// sweepExists returns true if the batch contains the sweep with the given hash.
func (b *batch) sweepExists(hash lntypes.Hash) bool {
func (b *batch) sweepExists(outpoint wire.OutPoint) bool {
Copy link
Member

Choose a reason for hiding this comment

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

nit: update godoc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

);

-- Copy all the data from sweeps to sweeps2.
WITH RECURSIVE seq(i) AS (
Copy link
Member

Choose a reason for hiding this comment

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

I think I understand this query now, but could you add a short explanation of what we do so it looks less intimidating?

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 added explanations of sqlite query to the migration file and adjustments for postgres to loopdb/postgres.go.

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.

tAck ✅

1.) created fast-swaps on the master branch
2.) ran the migration, outpoints look good.
3.) submitted a few swaps to ensure they are stored in the new format.

@@ -0,0 +1,3 @@
-- We kept old table as sweeps_old. Use it.
ALTER TABLE sweeps RENAME TO sweeps_new;
ALTER TABLE sweeps_old RENAME TO sweeps;
Copy link
Collaborator

Choose a reason for hiding this comment

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

don't we have to drop sweeps_new to reverse the creation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is dangerous, since it would be irrevocable. If some sweeps were added after the migration, they would be lost. Ideally we should write full SQL query which would split outpoint back to outpoint_txid and outpoint_index. Then we don't need sweeps_old and could just remove an unneeded table.

SwapHash used to be a key in the sweeps table. Now the key is outpoint which
replaces columns outpoint_txid and outpoint_index. In-memory structures and unit
tests were also updated to use outpoint as key. Outpoint is truly unique.
@starius starius force-pushed the sweepbatcher-outpoint branch from cc67a11 to c80ebb9 Compare April 1, 2025 14:12
@starius starius merged commit e4f5cc7 into lightninglabs:master Apr 1, 2025
4 checks passed
@starius starius deleted the sweepbatcher-outpoint branch April 1, 2025 15:44
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