staticaddr/loopin: use generated change addresses

Create a fresh static change address for fractional loop-ins and persist
its key locator with the selected HTLC outpoint. Recovery reconstructs
the same change output instead of returning funds to the legacy root
address.
This commit is contained in:
Slyghtning 2026-07-10 14:23:57 +02:00
parent d1b29e0bb5
commit b2f37bfa78
No known key found for this signature in database
GPG key ID: F82D456EA023C9BF
18 changed files with 878 additions and 90 deletions

View file

@ -10,7 +10,8 @@ INSERT INTO static_address_swaps (
htlc_tx_fee_rate_sat_kw,
htlc_timeout_sweep_tx_id,
htlc_timeout_sweep_address,
fast
fast,
change_static_address_id
) VALUES (
$1,
$2,
@ -22,14 +23,18 @@ INSERT INTO static_address_swaps (
$8,
$9,
$10,
$11
$11,
$12
);
-- name: UpdateStaticAddressLoopIn :exec
UPDATE static_address_swaps
SET
htlc_tx_fee_rate_sat_kw = $2,
htlc_timeout_sweep_tx_id = $3
htlc_timeout_sweep_tx_id = $3,
confirmed_htlc_tx_id = $4,
confirmed_htlc_output_index = $5,
confirmed_htlc_output_value = $6
WHERE
swap_hash = $1;
@ -64,13 +69,24 @@ INSERT INTO static_address_swap_updates (
SELECT
swaps.*,
static_address_swaps.*,
htlc_keys.*
htlc_keys.*,
change_address.client_pubkey change_client_pubkey,
change_address.server_pubkey change_server_pubkey,
change_address.expiry change_expiry,
change_address.client_key_family change_client_key_family,
change_address.client_key_index change_client_key_index,
change_address.pkscript change_pkscript,
change_address.protocol_version change_protocol_version,
change_address.initiation_height change_initiation_height
FROM
swaps
JOIN
static_address_swaps ON swaps.swap_hash = static_address_swaps.swap_hash
JOIN
htlc_keys ON swaps.swap_hash = htlc_keys.swap_hash
LEFT JOIN
static_addresses change_address
ON static_address_swaps.change_static_address_id = change_address.id
WHERE
swaps.swap_hash = $1;
@ -78,13 +94,24 @@ WHERE
SELECT
swaps.*,
static_address_swaps.*,
htlc_keys.*
htlc_keys.*,
change_address.client_pubkey change_client_pubkey,
change_address.server_pubkey change_server_pubkey,
change_address.expiry change_expiry,
change_address.client_key_family change_client_key_family,
change_address.client_key_index change_client_key_index,
change_address.pkscript change_pkscript,
change_address.protocol_version change_protocol_version,
change_address.initiation_height change_initiation_height
FROM
swaps
JOIN
static_address_swaps ON swaps.swap_hash = static_address_swaps.swap_hash
JOIN
htlc_keys ON swaps.swap_hash = htlc_keys.swap_hash
LEFT JOIN
static_addresses change_address
ON static_address_swaps.change_static_address_id = change_address.id
JOIN
static_address_swap_updates u ON swaps.swap_hash = u.swap_hash
-- This subquery ensures that we are checking only the latest update for
@ -170,5 +197,3 @@ FROM
)
WHERE
d.swap_hash = $1;