Skip to content

Commit 92baa8d

Browse files
committed
staticaddr: use generated change addresses
1 parent c0a240d commit 92baa8d

21 files changed

Lines changed: 1059 additions & 136 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE static_address_swaps DROP COLUMN change_static_address_id;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
ALTER TABLE static_address_swaps
2+
ADD change_static_address_id INT REFERENCES static_addresses(id);
3+
4+
-- Existing fractional swaps sent change back to the legacy static address.
5+
-- Backfill that relation so in-flight swaps remain recoverable after the
6+
-- client starts requiring explicit per-swap change metadata.
7+
UPDATE static_address_swaps
8+
SET change_static_address_id = (
9+
SELECT id FROM static_addresses ORDER BY id ASC LIMIT 1
10+
)
11+
WHERE selected_amount > 0
12+
AND change_static_address_id IS NULL
13+
AND EXISTS (SELECT 1 FROM static_addresses);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ALTER TABLE static_address_swaps
2+
DROP COLUMN confirmed_htlc_output_value;
3+
4+
ALTER TABLE static_address_swaps
5+
DROP COLUMN confirmed_htlc_output_index;
6+
7+
ALTER TABLE static_address_swaps
8+
DROP COLUMN confirmed_htlc_tx_id;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ALTER TABLE static_address_swaps
2+
ADD confirmed_htlc_tx_id TEXT;
3+
4+
ALTER TABLE static_address_swaps
5+
ADD confirmed_htlc_output_index INTEGER;
6+
7+
ALTER TABLE static_address_swaps
8+
ADD confirmed_htlc_output_value BIGINT;

loopdb/sqlc/models.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: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ INSERT INTO static_address_swaps (
1010
htlc_tx_fee_rate_sat_kw,
1111
htlc_timeout_sweep_tx_id,
1212
htlc_timeout_sweep_address,
13-
fast
13+
fast,
14+
change_static_address_id
1415
) VALUES (
1516
$1,
1617
$2,
@@ -22,14 +23,18 @@ INSERT INTO static_address_swaps (
2223
$8,
2324
$9,
2425
$10,
25-
$11
26+
$11,
27+
$12
2628
);
2729

2830
-- name: UpdateStaticAddressLoopIn :exec
2931
UPDATE static_address_swaps
3032
SET
3133
htlc_tx_fee_rate_sat_kw = $2,
32-
htlc_timeout_sweep_tx_id = $3
34+
htlc_timeout_sweep_tx_id = $3,
35+
confirmed_htlc_tx_id = $4,
36+
confirmed_htlc_output_index = $5,
37+
confirmed_htlc_output_value = $6
3338
WHERE
3439
swap_hash = $1;
3540

@@ -56,27 +61,49 @@ INSERT INTO static_address_swap_updates (
5661
SELECT
5762
swaps.*,
5863
static_address_swaps.*,
59-
htlc_keys.*
64+
htlc_keys.*,
65+
change_address.client_pubkey change_client_pubkey,
66+
change_address.server_pubkey change_server_pubkey,
67+
change_address.expiry change_expiry,
68+
change_address.client_key_family change_client_key_family,
69+
change_address.client_key_index change_client_key_index,
70+
change_address.pkscript change_pkscript,
71+
change_address.protocol_version change_protocol_version,
72+
change_address.initiation_height change_initiation_height
6073
FROM
6174
swaps
6275
JOIN
6376
static_address_swaps ON swaps.swap_hash = static_address_swaps.swap_hash
6477
JOIN
6578
htlc_keys ON swaps.swap_hash = htlc_keys.swap_hash
79+
LEFT JOIN
80+
static_addresses change_address
81+
ON static_address_swaps.change_static_address_id = change_address.id
6682
WHERE
6783
swaps.swap_hash = $1;
6884

6985
-- name: GetStaticAddressLoopInSwapsByStates :many
7086
SELECT
7187
swaps.*,
7288
static_address_swaps.*,
73-
htlc_keys.*
89+
htlc_keys.*,
90+
change_address.client_pubkey change_client_pubkey,
91+
change_address.server_pubkey change_server_pubkey,
92+
change_address.expiry change_expiry,
93+
change_address.client_key_family change_client_key_family,
94+
change_address.client_key_index change_client_key_index,
95+
change_address.pkscript change_pkscript,
96+
change_address.protocol_version change_protocol_version,
97+
change_address.initiation_height change_initiation_height
7498
FROM
7599
swaps
76100
JOIN
77101
static_address_swaps ON swaps.swap_hash = static_address_swaps.swap_hash
78102
JOIN
79103
htlc_keys ON swaps.swap_hash = htlc_keys.swap_hash
104+
LEFT JOIN
105+
static_addresses change_address
106+
ON static_address_swaps.change_static_address_id = change_address.id
80107
JOIN
81108
static_address_swap_updates u ON swaps.swap_hash = u.swap_hash
82109
-- This subquery ensures that we are checking only the latest update for
@@ -165,5 +192,3 @@ WHERE
165192

166193

167194

168-
169-

loopdb/sqlc/static_address_loopin.sql.go

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

0 commit comments

Comments
 (0)