Skip to content

Commit f35503c

Browse files
committed
fixup! splice: Add locked field to inflight db
1 parent 51054f2 commit f35503c

File tree

10 files changed

+67
-49
lines changed

10 files changed

+67
-49
lines changed

channeld/channeld.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3537,7 +3537,7 @@ static void resume_splice_negotiation(struct peer *peer,
35373537
msg = towire_channeld_update_inflight(NULL, current_psbt,
35383538
their_commit->tx,
35393539
&their_commit->commit_signature,
3540-
inflight->is_locked);
3540+
inflight->locked_scid);
35413541
wire_sync_write(MASTER_FD, take(msg));
35423542
}
35433543

@@ -3608,7 +3608,7 @@ static void resume_splice_negotiation(struct peer *peer,
36083608
&& send_signature) {
36093609
msg = towire_channeld_update_inflight(NULL, current_psbt,
36103610
NULL, NULL,
3611-
inflight->is_locked);
3611+
inflight->locked_scid);
36123612
wire_sync_write(MASTER_FD, take(msg));
36133613

36143614
msg = towire_channeld_splice_sending_sigs(tmpctx, &final_txid);
@@ -3778,7 +3778,7 @@ static void resume_splice_negotiation(struct peer *peer,
37783778
/* We let core validate our peer's signatures are correct. */
37793779
msg = towire_channeld_update_inflight(NULL, current_psbt, NULL,
37803780
NULL,
3781-
inflight->is_locked);
3781+
inflight->locked_scid);
37823782
wire_sync_write(MASTER_FD, take(msg));
37833783
}
37843784

@@ -4011,7 +4011,7 @@ static void splice_accepter(struct peer *peer, const u8 *inmsg)
40114011
new_inflight->last_tx = NULL;
40124012
new_inflight->i_am_initiator = false;
40134013
new_inflight->force_sign_first = peer->splicing->force_sign_first;
4014-
new_inflight->is_locked = false;
4014+
new_inflight->locked_scid = NULL;
40154015

40164016
current_push_val = relative_splice_balance_fundee(peer, our_role,ictx->current_psbt,
40174017
outpoint.n, splice_funding_index);
@@ -4233,7 +4233,7 @@ static void splice_initiator_user_finalized(struct peer *peer)
42334233
new_inflight->last_tx = NULL;
42344234
new_inflight->i_am_initiator = true;
42354235
new_inflight->force_sign_first = peer->splicing->force_sign_first;
4236-
new_inflight->is_locked = false;
4236+
new_inflight->locked_scid = NULL;
42374237

42384238
audit_psbt(ictx->current_psbt, ictx->current_psbt);
42394239

@@ -4265,7 +4265,7 @@ static void splice_initiator_user_finalized(struct peer *peer)
42654265
outmsg = towire_channeld_update_inflight(NULL, new_inflight->psbt,
42664266
their_commit->tx,
42674267
&their_commit->commit_signature,
4268-
new_inflight->is_locked);
4268+
new_inflight->locked_scid);
42694269
wire_sync_write(MASTER_FD, take(outmsg));
42704270

42714271
sign_first = do_i_sign_first(peer, new_inflight->psbt, our_role,
@@ -4459,7 +4459,7 @@ static void splice_initiator_user_signed(struct peer *peer, const u8 *inmsg)
44594459
outmsg = towire_channeld_update_inflight(NULL, inflight->psbt,
44604460
inflight->last_tx,
44614461
&inflight->last_sig,
4462-
inflight->is_locked);
4462+
inflight->locked_scid);
44634463

44644464
wire_sync_write(MASTER_FD, take(outmsg));
44654465

@@ -5791,13 +5791,13 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg)
57915791
" inflights to"
57925792
"match, %s",
57935793
fmt_bitcoin_txid(tmpctx, &txid));
5794-
inflight->is_locked = true;
5794+
inflight->locked_scid = tal_steal(inflight, scid);
57955795
assert(inflight->psbt);
57965796
msg = towire_channeld_update_inflight(NULL,
57975797
inflight->psbt,
57985798
NULL,
57995799
NULL,
5800-
inflight->is_locked);
5800+
inflight->locked_scid);
58015801
wire_sync_write(MASTER_FD, take(msg));
58025802
inflight_match = inflight;
58035803
}
@@ -6405,7 +6405,7 @@ static void init_channel(struct peer *peer)
64056405

64066406
found_locked_inflight = false;
64076407
for (size_t i = 0; i < tal_count(peer->splice_state->inflights); i++) {
6408-
if (peer->splice_state->inflights[i]->is_locked) {
6408+
if (peer->splice_state->inflights[i]->locked_scid) {
64096409
if (found_locked_inflight)
64106410
status_failed(STATUS_FAIL_INTERNAL_ERROR,
64116411
"There should never be two splice"
@@ -6414,6 +6414,7 @@ static void init_channel(struct peer *peer)
64146414
fmt_bitcoin_txid(tmpctx, &peer->splice_state->locked_txid),
64156415
fmt_bitcoin_txid(tmpctx, &peer->splice_state->inflights[i]->outpoint.txid));
64166416
peer->splice_state->locked_txid = peer->splice_state->inflights[i]->outpoint.txid;
6417+
peer->splice_state->short_channel_id = *peer->splice_state->inflights[i]->locked_scid;
64176418
found_locked_inflight = true;
64186419
}
64196420
}

channeld/channeld_wire.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ msgtype,channeld_update_inflight,7219
272272
msgdata,channeld_update_inflight,psbt,wally_psbt,
273273
msgdata,channeld_update_inflight,last_tx,?bitcoin_tx,
274274
msgdata,channeld_update_inflight,last_sig,?bitcoin_signature,
275-
msgdata,channeld_update_inflight,is_locked,bool,
275+
msgdata,channeld_update_inflight,locked_scid,?short_channel_id,
276276

277277
# channeld->master: A funding error has occured
278278
msgtype,channeld_splice_funding_error,7220

channeld/inflight.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "config.h"
22
#include <assert.h>
33
#include <bitcoin/psbt.h>
4+
#include <bitcoin/short_channel_id.h>
45
#include <channeld/inflight.h>
56
#include <wire/wire.h>
67

@@ -25,7 +26,14 @@ struct inflight *fromwire_inflight(const tal_t *ctx, const u8 **cursor, size_t *
2526
}
2627
inflight->i_am_initiator = fromwire_bool(cursor, max);
2728
inflight->force_sign_first = fromwire_bool(cursor, max);
28-
inflight->is_locked = fromwire_bool(cursor, max);
29+
int has_locked_scid = fromwire_u8(cursor, max);
30+
if (has_locked_scid) {
31+
inflight->locked_scid = tal(inflight, struct short_channel_id);
32+
*inflight->locked_scid = fromwire_short_channel_id(cursor, max);
33+
}
34+
else {
35+
inflight->locked_scid = NULL;
36+
}
2937

3038
return inflight;
3139
}
@@ -45,5 +53,7 @@ void towire_inflight(u8 **pptr, const struct inflight *inflight)
4553
}
4654
towire_bool(pptr, inflight->i_am_initiator);
4755
towire_bool(pptr, inflight->force_sign_first);
48-
towire_bool(pptr, inflight->is_locked);
56+
towire_u8(pptr, inflight->locked_scid ? 1 : 0);
57+
if (inflight->locked_scid)
58+
towire_short_channel_id(pptr, *inflight->locked_scid);
4959
}

channeld/inflight.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct inflight {
1919
struct bitcoin_signature last_sig;
2020
bool i_am_initiator;
2121
bool force_sign_first;
22-
bool is_locked;
22+
struct short_channel_id *locked_scid;
2323
};
2424

2525
struct inflight *fromwire_inflight(const tal_t *ctx, const u8 **cursor, size_t *max);

lightningd/channel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ new_inflight(struct channel *channel,
207207

208208
inflight->i_am_initiator = i_am_initiator;
209209
inflight->force_sign_first = force_sign_first;
210-
inflight->is_locked = false;
210+
inflight->locked_scid = NULL;
211211
inflight->splice_locked_memonly = false;
212212

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

lightningd/channel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ struct channel_inflight {
8484
/* Has this inflight reached sufficent depth on chain? This is needed
8585
* for splices that need to coordinate `splice_locked` with their
8686
* peer through reconnect flows. */
87-
bool is_locked;
87+
struct short_channel_id *locked_scid;
8888

8989
/* Note: This field is not stored in the database.
9090
*

lightningd/channel_control.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -891,10 +891,10 @@ static void handle_update_inflight(struct lightningd *ld,
891891
struct bitcoin_txid txid;
892892
struct bitcoin_tx *last_tx;
893893
struct bitcoin_signature *last_sig;
894-
bool is_locked;
894+
struct short_channel_id *locked_scid;
895895

896896
if (!fromwire_channeld_update_inflight(tmpctx, msg, &psbt, &last_tx,
897-
&last_sig, &is_locked)) {
897+
&last_sig, &locked_scid)) {
898898
channel_internal_error(channel,
899899
"bad channel_add_inflight %s",
900900
tal_hex(channel, msg));
@@ -922,7 +922,7 @@ static void handle_update_inflight(struct lightningd *ld,
922922
if (last_sig)
923923
inflight->last_sig = *last_sig;
924924

925-
inflight->is_locked = is_locked;
925+
inflight->locked_scid = tal_steal(inflight, locked_scid);
926926

927927
tal_wally_start();
928928
if (wally_psbt_combine(inflight->funding_psbt, psbt) != WALLY_OK) {
@@ -1812,14 +1812,11 @@ bool peer_start_channeld(struct channel *channel,
18121812
infcopy->amnt = inflight->funding->total_funds;
18131813
infcopy->remote_tx_sigs = inflight->remote_tx_sigs;
18141814
infcopy->splice_amnt = inflight->funding->splice_amnt;
1815-
if (inflight->last_tx)
1816-
infcopy->last_tx = tal_dup(infcopy, struct bitcoin_tx, inflight->last_tx);
1817-
else
1818-
infcopy->last_tx = NULL;
1815+
infcopy->last_tx = tal_dup_or_null(infcopy, struct bitcoin_tx, inflight->last_tx);
18191816
infcopy->last_sig = inflight->last_sig;
18201817
infcopy->i_am_initiator = inflight->i_am_initiator;
18211818
infcopy->force_sign_first = inflight->force_sign_first;
1822-
infcopy->is_locked = inflight->is_locked;
1819+
infcopy->locked_scid = tal_dup_or_null(infcopy, struct short_channel_id, inflight->locked_scid);
18231820

18241821
tal_wally_start();
18251822
wally_psbt_clone_alloc(inflight->funding_psbt, 0, &infcopy->psbt);

wallet/db.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ static struct migration dbmigrations[] = {
10401040
{SQL("ALTER TABLE channel_htlcs ADD updated_index BIGINT DEFAULT 0"), NULL},
10411041
{SQL("CREATE INDEX channel_htlcs_updated_idx ON channel_htlcs (updated_index)"), NULL},
10421042
{NULL, migrate_initialize_channel_htlcs_wait_indexes},
1043-
{SQL("ALTER TABLE channel_funding_inflights ADD locked_onchain INTEGER DEFAULT 0;"), NULL},
1043+
{SQL("ALTER TABLE channel_funding_inflights ADD locked_scid BIGINT DEFAULT 0;"), NULL},
10441044
};
10451045

10461046
/**

wallet/test/run-wallet.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,10 @@ static bool channel_inflightseq(struct channel_inflight *i1,
16481648
CHECK(i1->lease_chan_max_msat == i2->lease_chan_max_msat);
16491649
CHECK(i1->lease_chan_max_ppt == i2->lease_chan_max_ppt);
16501650
CHECK(i1->lease_blockheight_start == i2->lease_blockheight_start);
1651-
CHECK(i1->is_locked == i2->is_locked);
1651+
CHECK(!i1->locked_scid == !i2->locked_scid);
1652+
if (i1->locked_scid)
1653+
CHECK(memeq(i1->locked_scid, sizeof(*i1->locked_scid),
1654+
i2->locked_scid, sizeof(*i2->locked_scid)));
16521655
CHECK(i1->splice_locked_memonly == i2->splice_locked_memonly);
16531656

16541657
return true;
@@ -2072,7 +2075,8 @@ static bool test_channel_inflight_crud(struct lightningd *ld, const tal_t *ctx)
20722075
false,
20732076
false);
20742077
inflight->splice_locked_memonly = true;
2075-
inflight->is_locked = true;
2078+
inflight->locked_scid = tal(inflight, struct short_channel_id);
2079+
memset(inflight->locked_scid, 7, sizeof(struct short_channel_id));
20762080

20772081
inflight_set_last_tx(inflight, last_tx, sig);
20782082

@@ -2101,7 +2105,7 @@ static bool test_channel_inflight_crud(struct lightningd *ld, const tal_t *ctx)
21012105
false,
21022106
false);
21032107
inflight->splice_locked_memonly = false;
2104-
inflight->is_locked = false;
2108+
inflight->locked_scid = NULL;
21052109
inflight_set_last_tx(inflight, last_tx, sig);
21062110
wallet_inflight_add(w, inflight);
21072111
CHECK_MSG(c2 = wallet_channel_load(w, chan->dbid),

wallet/wallet.c

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,7 @@ void wallet_inflight_add(struct wallet *w, struct channel_inflight *inflight)
13741374
", i_am_initiator"
13751375
", force_sign_first"
13761376
", remote_funding"
1377-
", locked_onchain"
1377+
", locked_scid"
13781378
") VALUES ("
13791379
"?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"));
13801380

@@ -1419,7 +1419,10 @@ void wallet_inflight_add(struct wallet *w, struct channel_inflight *inflight)
14191419
db_bind_pubkey(stmt, inflight->funding->splice_remote_funding);
14201420
else
14211421
db_bind_null(stmt);
1422-
db_bind_int(stmt, inflight->is_locked);
1422+
if (inflight->locked_scid)
1423+
db_bind_short_channel_id(stmt, *inflight->locked_scid);
1424+
else
1425+
db_bind_null(stmt);
14231426

14241427
db_exec_prepared_v2(stmt);
14251428
assert(!stmt->error);
@@ -1448,14 +1451,14 @@ void wallet_inflight_save(struct wallet *w,
14481451
struct db_stmt *stmt;
14491452
/* The *only* thing you can update on an
14501453
* inflight is the funding PSBT (to add sigs)
1451-
* and the last_tx/last_sig or locked_onchain if this is for a splice */
1454+
* and the last_tx/last_sig or locked_scid if this is for a splice */
14521455
stmt = db_prepare_v2(w->db,
14531456
SQL("UPDATE channel_funding_inflights SET"
14541457
" funding_psbt=?" // 0
14551458
", funding_tx_remote_sigs_received=?" // 1
14561459
", last_tx=?" // 2
14571460
", last_sig=?" // 3
1458-
", locked_onchain=?" // 4
1461+
", locked_scid=?" // 4
14591462
" WHERE"
14601463
" channel_id=?" // 5
14611464
" AND funding_tx_id=?" // 6
@@ -1469,14 +1472,31 @@ void wallet_inflight_save(struct wallet *w,
14691472
db_bind_null(stmt);
14701473
db_bind_null(stmt);
14711474
}
1472-
db_bind_int(stmt, inflight->is_locked);
1475+
if (inflight->locked_scid)
1476+
db_bind_short_channel_id(stmt, *inflight->locked_scid);
1477+
else
1478+
db_bind_null(stmt);
14731479
db_bind_u64(stmt, inflight->channel->dbid);
14741480
db_bind_txid(stmt, &inflight->funding->outpoint.txid);
14751481
db_bind_int(stmt, inflight->funding->outpoint.n);
14761482

14771483
db_exec_prepared_v2(take(stmt));
14781484
}
14791485

1486+
static struct short_channel_id *db_col_optional_scid(const tal_t *ctx,
1487+
struct db_stmt *stmt,
1488+
const char *colname)
1489+
{
1490+
struct short_channel_id *scid;
1491+
1492+
if (db_col_is_null(stmt, colname))
1493+
return NULL;
1494+
1495+
scid = tal(ctx, struct short_channel_id);
1496+
*scid = db_col_short_channel_id(stmt, colname);
1497+
return scid;
1498+
}
1499+
14801500
void wallet_channel_clear_inflights(struct wallet *w,
14811501
struct channel *chan)
14821502
{
@@ -1568,7 +1588,7 @@ wallet_stmt2inflight(struct wallet *w, struct db_stmt *stmt,
15681588
i_am_initiator,
15691589
force_sign_first);
15701590

1571-
inflight->is_locked = db_col_int(stmt, "locked_onchain");
1591+
inflight->locked_scid = db_col_optional_scid(inflight, stmt, "locked_scid");
15721592

15731593
/* last_tx is null for not yet committed
15741594
* channels + static channel backup recoveries */
@@ -1621,7 +1641,7 @@ static bool wallet_channel_load_inflights(struct wallet *w,
16211641
", i_am_initiator"
16221642
", force_sign_first"
16231643
", remote_funding"
1624-
", locked_onchain"
1644+
", locked_scid"
16251645
" FROM channel_funding_inflights"
16261646
" WHERE channel_id = ?"
16271647
" ORDER BY funding_feerate"));
@@ -1670,20 +1690,6 @@ static bool wallet_channel_config_load(struct wallet *w, const u64 id,
16701690
return ok;
16711691
}
16721692

1673-
static struct short_channel_id *db_col_optional_scid(const tal_t *ctx,
1674-
struct db_stmt *stmt,
1675-
const char *colname)
1676-
{
1677-
struct short_channel_id *scid;
1678-
1679-
if (db_col_is_null(stmt, colname))
1680-
return NULL;
1681-
1682-
scid = tal(ctx, struct short_channel_id);
1683-
*scid = db_col_short_channel_id(stmt, colname);
1684-
return scid;
1685-
}
1686-
16871693
static struct channel_state_change **wallet_state_change_get(const tal_t *ctx,
16881694
struct wallet *w,
16891695
u64 channel_id)

0 commit comments

Comments
 (0)