Skip to content

Commit 2f21a48

Browse files
authored
Merge pull request #988 from hieblmi/normalize-deposit-swap
staticaddr: migrate deposit swap hashes
2 parents bbd9813 + fe7622d commit 2f21a48

16 files changed

+976
-44
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ require (
1616
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0
1717
github.com/jackc/pgconn v1.14.3
1818
github.com/jackc/pgerrcode v0.0.0-20240316143900-6e2875d9b438
19+
github.com/jackc/pgx/v5 v5.6.0
1920
github.com/jessevdk/go-flags v1.4.0
2021
github.com/lib/pq v1.10.9
2122
github.com/lightninglabs/aperture v0.3.13-beta
@@ -104,7 +105,6 @@ require (
104105
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
105106
github.com/jackc/pgtype v1.14.0 // indirect
106107
github.com/jackc/pgx/v4 v4.18.2 // indirect
107-
github.com/jackc/pgx/v5 v5.6.0 // indirect
108108
github.com/jackc/puddle v1.3.0 // indirect
109109
github.com/jackc/puddle/v2 v2.2.1 // indirect
110110
github.com/jackpal/gateway v1.0.5 // indirect

loopd/daemon.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,16 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
626626
clock.NewDefaultClock(), d.lnd.ChainParams,
627627
)
628628

629+
// Run the deposit swap hash migration.
630+
err = loopin.MigrateDepositSwapHash(
631+
d.mainCtx, swapDb, depositStore, staticAddressLoopInStore,
632+
)
633+
if err != nil {
634+
errorf("Deposit swap hash migration failed: %v", err)
635+
636+
return err
637+
}
638+
629639
staticLoopInManager = loopin.NewManager(&loopin.Config{
630640
Server: staticAddressClient,
631641
QuoteGetter: swapClient.Server,

loopdb/sqlc/migrations/000010_static_address_deposits.up.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ CREATE TABLE IF NOT EXISTS deposit_updates (
4545

4646
-- update_timestamp is the timestamp of the update.
4747
update_timestamp TIMESTAMP NOT NULL
48-
);
48+
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE deposits DROP COLUMN swap_hash;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE deposits ADD swap_hash BLOB;

loopdb/sqlc/models.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

loopdb/sqlc/querier.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

loopdb/sqlc/queries/static_address_loopin.sql

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,51 @@ SELECT EXISTS (
9393
FROM static_address_swaps
9494
WHERE swap_hash = $1
9595
);
96+
97+
-- name: MapDepositToSwap :exec
98+
UPDATE
99+
deposits
100+
SET
101+
swap_hash = $2
102+
WHERE
103+
deposit_id = $1;
104+
105+
-- name: SwapHashForDepositID :one
106+
SELECT
107+
swap_hash
108+
FROM
109+
deposits
110+
WHERE
111+
deposit_id = $1;
112+
113+
-- name: DepositIDsForSwapHash :many
114+
SELECT
115+
deposit_id
116+
FROM
117+
deposits
118+
WHERE
119+
swap_hash = $1;
120+
121+
-- name: DepositsForSwapHash :many
122+
SELECT
123+
d.*,
124+
u.update_state,
125+
u.update_timestamp
126+
FROM
127+
deposits d
128+
LEFT JOIN
129+
deposit_updates u ON u.id = (
130+
SELECT id
131+
FROM deposit_updates
132+
WHERE deposit_id = d.deposit_id
133+
ORDER BY update_timestamp DESC
134+
LIMIT 1
135+
)
136+
WHERE
137+
d.swap_hash = $1;
138+
139+
140+
141+
142+
143+

loopdb/sqlc/static_address_deposits.sql.go

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

loopdb/sqlc/static_address_loopin.sql.go

Lines changed: 137 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)