splice: Add remote_funding to database

Enable storing the remote funding pubkey in DB if the channel peer decides to change it during splicing. It needs to be in DB incase of restarts mid-splice.

Changelog-None
This commit is contained in:
Dusty Daemon 2024-10-04 14:44:50 -04:00 committed by Rusty Russell
parent 7d1a43d5d5
commit 560ca00a2b
8 changed files with 25 additions and 4 deletions

View file

@ -152,6 +152,7 @@ static void destroy_inflight(struct channel_inflight *inflight)
struct channel_inflight *
new_inflight(struct channel *channel,
struct pubkey *remote_funding,
const struct bitcoin_outpoint *funding_outpoint,
u32 funding_feerate,
struct amount_sat total_funds,
@ -177,6 +178,7 @@ new_inflight(struct channel *channel,
funding->feerate = funding_feerate;
funding->our_funds = our_funds;
funding->splice_amnt = splice_amnt;
funding->splice_remote_funding = tal_steal(funding, remote_funding);
inflight->funding = funding;
inflight->channel = channel;

View file

@ -41,6 +41,7 @@ struct funding_info {
/* Relative splicing balance change */
s64 splice_amnt;
struct pubkey *splice_remote_funding;
};
struct channel_inflight {
@ -431,6 +432,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
/* new_inflight - Create a new channel_inflight for a channel */
struct channel_inflight *new_inflight(struct channel *channel,
struct pubkey *remote_funding STEALS,
const struct bitcoin_outpoint *funding_outpoint,
u32 funding_feerate,
struct amount_sat funding_sat,

View file

@ -849,6 +849,7 @@ static void handle_add_inflight(struct lightningd *ld,
}
inflight = new_inflight(channel,
NULL,
&outpoint,
feerate,
satoshis,

View file

@ -1283,6 +1283,7 @@ wallet_update_channel(struct lightningd *ld,
/* Add open attempt to channel's inflights */
inflight = new_inflight(channel,
NULL,
&channel->funding,
funding_feerate,
channel->funding_sats,
@ -1502,6 +1503,7 @@ wallet_commit_channel(struct lightningd *ld,
/* Open attempt to channel's inflights */
inflight = new_inflight(channel,
NULL,
&channel->funding,
funding_feerate,
channel->funding_sats,

View file

@ -1027,6 +1027,7 @@ static struct migration dbmigrations[] = {
" keyidx BIGINT,"
" addrtype INTEGER)"), NULL},
{NULL, insert_addrtype_to_addresses},
{SQL("ALTER TABLE channel_funding_inflights ADD remote_funding BLOB DEFAULT NULL;"), NULL},
};
/**

View file

@ -213,6 +213,7 @@ struct chain_coin_mvt *new_coin_wallet_deposit(const tal_t *ctx UNNEEDED,
{ fprintf(stderr, "new_coin_wallet_deposit called!\n"); abort(); }
/* Generated stub for new_inflight */
struct channel_inflight *new_inflight(struct channel *channel UNNEEDED,
struct pubkey *remote_funding UNNEEDED,
const struct bitcoin_outpoint *funding_outpoint UNNEEDED,
u32 funding_feerate UNNEEDED,
struct amount_sat funding_sat UNNEEDED,

View file

@ -2019,7 +2019,7 @@ static bool test_channel_inflight_crud(struct lightningd *ld, const tal_t *ctx)
memset(&outpoint, 1, sizeof(outpoint));
mempat(&sig.s, sizeof(sig.s));
inflight = new_inflight(chan, &outpoint, 253,
inflight = new_inflight(chan, NULL, &outpoint, 253,
funding_sats,
our_sats,
funding_psbt,
@ -2046,7 +2046,7 @@ static bool test_channel_inflight_crud(struct lightningd *ld, const tal_t *ctx)
our_sats = AMOUNT_SAT(555555);
memset(&outpoint, 2, sizeof(outpoint));
mempat(&sig.s, sizeof(sig.s));
inflight = new_inflight(chan, &outpoint, 300,
inflight = new_inflight(chan, NULL, &outpoint, 300,
funding_sats,
our_sats,
funding_psbt,

View file

@ -1231,8 +1231,9 @@ void wallet_inflight_add(struct wallet *w, struct channel_inflight *inflight)
", splice_amnt"
", i_am_initiator"
", force_sign_first"
", remote_funding"
") VALUES ("
"?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"));
"?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"));
db_bind_u64(stmt, inflight->channel->dbid);
db_bind_txid(stmt, &inflight->funding->outpoint.txid);
@ -1271,6 +1272,10 @@ void wallet_inflight_add(struct wallet *w, struct channel_inflight *inflight)
db_bind_s64(stmt, inflight->funding->splice_amnt);
db_bind_int(stmt, inflight->i_am_initiator);
db_bind_int(stmt, inflight->force_sign_first);
if (inflight->funding->splice_remote_funding)
db_bind_pubkey(stmt, inflight->funding->splice_remote_funding);
else
db_bind_null(stmt);
db_exec_prepared_v2(stmt);
assert(!stmt->error);
@ -1348,6 +1353,7 @@ static struct channel_inflight *
wallet_stmt2inflight(struct wallet *w, struct db_stmt *stmt,
struct channel *chan)
{
struct pubkey *remote_funding = NULL;
struct amount_sat funding_sat, our_funding_sat;
struct amount_msat lease_fee;
struct bitcoin_outpoint funding;
@ -1391,11 +1397,16 @@ wallet_stmt2inflight(struct wallet *w, struct db_stmt *stmt,
db_col_ignore(stmt, "lease_satoshi");
}
if (!db_col_is_null(stmt, "remote_funding")) {
remote_funding = tal(tmpctx, struct pubkey);
db_col_pubkey(stmt, "remote_funding", remote_funding);
}
splice_amnt = db_col_s64(stmt, "splice_amnt");
i_am_initiator = db_col_int(stmt, "i_am_initiator");
force_sign_first = db_col_int(stmt, "force_sign_first");
inflight = new_inflight(chan, &funding,
inflight = new_inflight(chan, remote_funding, &funding,
db_col_int(stmt, "funding_feerate"),
funding_sat,
our_funding_sat,
@ -1461,6 +1472,7 @@ static bool wallet_channel_load_inflights(struct wallet *w,
", splice_amnt"
", i_am_initiator"
", force_sign_first"
", remote_funding"
" FROM channel_funding_inflights"
" WHERE channel_id = ?"
" ORDER BY funding_feerate"));