Skip to content

Commit 453a4e1

Browse files
committed
splice: Add locked field to inflight db
This is needed to remember if a splice was locked and reconnect occurs mid `splice_locked` attempted so it can be resumed in reestablish.
1 parent c70942e commit 453a4e1

File tree

5 files changed

+25
-5
lines changed

5 files changed

+25
-5
lines changed

lightningd/channel.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ new_inflight(struct channel *channel,
200200

201201
inflight->i_am_initiator = i_am_initiator;
202202
inflight->force_sign_first = force_sign_first;
203+
inflight->is_locked = false;
203204
inflight->splice_locked_memonly = false;
204205

205206
list_add_tail(&channel->inflights, &inflight->list);

lightningd/channel.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ struct channel_inflight {
8181
/* On reestablish recovery; should I sign first? */
8282
bool force_sign_first;
8383

84+
/* Has this inflight reached sufficent depth on chain? This is needed
85+
* for splices that need to coordinate `splice_locked` with their
86+
* peer through reconnect flows. */
87+
bool is_locked;
88+
8489
/* Note: This field is not stored in the database.
8590
*
8691
* After splice_locked, we need a way to stop the chain watchers from

wallet/db.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,7 @@ static struct migration dbmigrations[] = {
10301030
{SQL("ALTER TABLE channel_funding_inflights ADD remote_funding BLOB DEFAULT NULL;"), NULL},
10311031
{SQL("ALTER TABLE peers ADD last_known_address BLOB DEFAULT NULL;"), NULL},
10321032
{SQL("ALTER TABLE channels ADD close_attempt_height INTEGER DEFAULT 0;"), NULL},
1033+
{SQL("ALTER TABLE channel_funding_inflights ADD locked_onchain INTEGER DEFAULT 0;"), NULL},
10331034
};
10341035

10351036
/**

wallet/test/run-wallet.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,8 @@ static bool channel_inflightseq(struct channel_inflight *i1,
16161616
CHECK(i1->lease_chan_max_msat == i2->lease_chan_max_msat);
16171617
CHECK(i1->lease_chan_max_ppt == i2->lease_chan_max_ppt);
16181618
CHECK(i1->lease_blockheight_start == i2->lease_blockheight_start);
1619+
CHECK(i1->is_locked == i2->is_locked);
1620+
CHECK(i1->splice_locked_memonly == i2->splice_locked_memonly);
16191621

16201622
return true;
16211623
}
@@ -2037,6 +2039,8 @@ static bool test_channel_inflight_crud(struct lightningd *ld, const tal_t *ctx)
20372039
0,
20382040
false,
20392041
false);
2042+
inflight->splice_locked_memonly = true;
2043+
inflight->is_locked = true;
20402044

20412045
inflight_set_last_tx(inflight, last_tx, sig);
20422046

@@ -2064,6 +2068,8 @@ static bool test_channel_inflight_crud(struct lightningd *ld, const tal_t *ctx)
20642068
0,
20652069
false,
20662070
false);
2071+
inflight->splice_locked_memonly = false;
2072+
inflight->is_locked = false;
20672073
inflight_set_last_tx(inflight, last_tx, sig);
20682074
wallet_inflight_add(w, inflight);
20692075
CHECK_MSG(c2 = wallet_channel_load(w, chan->dbid),

wallet/wallet.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,8 +1244,9 @@ void wallet_inflight_add(struct wallet *w, struct channel_inflight *inflight)
12441244
", i_am_initiator"
12451245
", force_sign_first"
12461246
", remote_funding"
1247+
", locked_onchain"
12471248
") VALUES ("
1248-
"?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"));
1249+
"?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"));
12491250

12501251
db_bind_u64(stmt, inflight->channel->dbid);
12511252
db_bind_txid(stmt, &inflight->funding->outpoint.txid);
@@ -1288,6 +1289,7 @@ void wallet_inflight_add(struct wallet *w, struct channel_inflight *inflight)
12881289
db_bind_pubkey(stmt, inflight->funding->splice_remote_funding);
12891290
else
12901291
db_bind_null(stmt);
1292+
db_bind_int(stmt, inflight->is_locked);
12911293

12921294
db_exec_prepared_v2(stmt);
12931295
assert(!stmt->error);
@@ -1316,17 +1318,18 @@ void wallet_inflight_save(struct wallet *w,
13161318
struct db_stmt *stmt;
13171319
/* The *only* thing you can update on an
13181320
* inflight is the funding PSBT (to add sigs)
1319-
* and the last_tx/last_sig if this is for a splice */
1321+
* and the last_tx/last_sig or locked_onchain if this is for a splice */
13201322
stmt = db_prepare_v2(w->db,
13211323
SQL("UPDATE channel_funding_inflights SET"
13221324
" funding_psbt=?" // 0
13231325
", funding_tx_remote_sigs_received=?" // 1
13241326
", last_tx=?" // 2
13251327
", last_sig=?" // 3
1328+
", locked_onchain=?" // 4
13261329
" WHERE"
1327-
" channel_id=?" // 4
1328-
" AND funding_tx_id=?" // 5
1329-
" AND funding_tx_outnum=?")); // 6
1330+
" channel_id=?" // 5
1331+
" AND funding_tx_id=?" // 6
1332+
" AND funding_tx_outnum=?")); // 7
13301333
db_bind_psbt(stmt, inflight->funding_psbt);
13311334
db_bind_int(stmt, inflight->remote_tx_sigs);
13321335
if (inflight->last_tx) {
@@ -1336,6 +1339,7 @@ void wallet_inflight_save(struct wallet *w,
13361339
db_bind_null(stmt);
13371340
db_bind_null(stmt);
13381341
}
1342+
db_bind_int(stmt, inflight->is_locked);
13391343
db_bind_u64(stmt, inflight->channel->dbid);
13401344
db_bind_txid(stmt, &inflight->funding->outpoint.txid);
13411345
db_bind_int(stmt, inflight->funding->outpoint.n);
@@ -1434,6 +1438,8 @@ wallet_stmt2inflight(struct wallet *w, struct db_stmt *stmt,
14341438
i_am_initiator,
14351439
force_sign_first);
14361440

1441+
inflight->is_locked = db_col_int(stmt, "locked_onchain");
1442+
14371443
/* last_tx is null for not yet committed
14381444
* channels + static channel backup recoveries */
14391445
if (!db_col_is_null(stmt, "last_tx")) {
@@ -1485,6 +1491,7 @@ static bool wallet_channel_load_inflights(struct wallet *w,
14851491
", i_am_initiator"
14861492
", force_sign_first"
14871493
", remote_funding"
1494+
", locked_onchain"
14881495
" FROM channel_funding_inflights"
14891496
" WHERE channel_id = ?"
14901497
" ORDER BY funding_feerate"));

0 commit comments

Comments
 (0)