Skip to content

Commit 957339b

Browse files
committed
splice: Pass is_locked between channeld and ld
To support resuming `splice_locked` across channel reconnect, we need to pass inflight `is_locked` between lightningd and channeld. This implements that interface between channeld and lightningd so each inflight should have up to date `is_locked` values between restarts.
1 parent 5151eb9 commit 957339b

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

channeld/channeld.c

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3361,7 +3361,8 @@ static void resume_splice_negotiation(struct peer *peer,
33613361

33623362
msg = towire_channeld_update_inflight(NULL, current_psbt,
33633363
their_commit->tx,
3364-
&their_commit->commit_signature);
3364+
&their_commit->commit_signature,
3365+
inflight->is_locked);
33653366
wire_sync_write(MASTER_FD, take(msg));
33663367
}
33673368

@@ -3431,7 +3432,8 @@ static void resume_splice_negotiation(struct peer *peer,
34313432
inflight->force_sign_first)
34323433
&& send_signature) {
34333434
msg = towire_channeld_update_inflight(NULL, current_psbt,
3434-
NULL, NULL);
3435+
NULL, NULL,
3436+
inflight->is_locked);
34353437
wire_sync_write(MASTER_FD, take(msg));
34363438

34373439
msg = towire_channeld_splice_sending_sigs(tmpctx, &final_txid);
@@ -3600,7 +3602,8 @@ static void resume_splice_negotiation(struct peer *peer,
36003602
if (recv_signature) {
36013603
/* We let core validate our peer's signatures are correct. */
36023604
msg = towire_channeld_update_inflight(NULL, current_psbt, NULL,
3603-
NULL);
3605+
NULL,
3606+
inflight->is_locked);
36043607
wire_sync_write(MASTER_FD, take(msg));
36053608
}
36063609

@@ -3831,6 +3834,7 @@ static void splice_accepter(struct peer *peer, const u8 *inmsg)
38313834
new_inflight->last_tx = NULL;
38323835
new_inflight->i_am_initiator = false;
38333836
new_inflight->force_sign_first = peer->splicing->force_sign_first;
3837+
new_inflight->is_locked = false;
38343838

38353839
current_push_val = relative_splice_balance_fundee(peer, our_role,ictx->current_psbt,
38363840
outpoint.n, splice_funding_index);
@@ -4055,6 +4059,7 @@ static void splice_initiator_user_finalized(struct peer *peer)
40554059
new_inflight->last_tx = NULL;
40564060
new_inflight->i_am_initiator = true;
40574061
new_inflight->force_sign_first = peer->splicing->force_sign_first;
4062+
new_inflight->is_locked = false;
40584063

40594064
/* Switch over to using inflight psbt. This allows us to be reentrant.
40604065
* On restart we *will* have inflight psbt but we will not have any
@@ -4085,7 +4090,8 @@ static void splice_initiator_user_finalized(struct peer *peer)
40854090

40864091
outmsg = towire_channeld_update_inflight(NULL, new_inflight->psbt,
40874092
their_commit->tx,
4088-
&their_commit->commit_signature);
4093+
&their_commit->commit_signature,
4094+
new_inflight->is_locked);
40894095
wire_sync_write(MASTER_FD, take(outmsg));
40904096

40914097
sign_first = do_i_sign_first(peer, new_inflight->psbt, our_role,
@@ -4244,7 +4250,8 @@ static void splice_initiator_user_signed(struct peer *peer, const u8 *inmsg)
42444250
* restart and reestablish later. */
42454251
outmsg = towire_channeld_update_inflight(NULL, inflight->psbt,
42464252
inflight->last_tx,
4247-
&inflight->last_sig);
4253+
&inflight->last_sig,
4254+
inflight->is_locked);
42484255

42494256
wire_sync_write(MASTER_FD, take(outmsg));
42504257

@@ -5597,6 +5604,20 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg)
55975604

55985605
peer->splice_state->locked_txid = txid;
55995606

5607+
for (size_t i = 0; i < tal_count(peer->splice_state->inflights); i++) {
5608+
struct inflight *inflight = peer->splice_state->inflights[i];
5609+
if (bitcoin_txid_eq(&inflight->outpoint.txid,
5610+
&txid)) {
5611+
inflight->is_locked = true;
5612+
msg = towire_channeld_update_inflight(NULL,
5613+
inflight->psbt,
5614+
NULL,
5615+
NULL,
5616+
inflight->is_locked);
5617+
wire_sync_write(MASTER_FD, take(msg));
5618+
}
5619+
}
5620+
56005621
peer_write(peer->pps, take(msg));
56015622

56025623
peer->splice_state->locked_ready[LOCAL] = true;
@@ -6068,6 +6089,7 @@ static void init_channel(struct peer *peer)
60686089
struct penalty_base *pbases;
60696090
bool reestablish_only;
60706091
struct channel_type *channel_type;
6092+
bool found_locked_inflight;
60716093

60726094
assert(!(fcntl(MASTER_FD, F_GETFL) & O_NONBLOCK));
60736095

channeld/channeld_wire.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ msgtype,channeld_update_inflight,7219
273273
msgdata,channeld_update_inflight,psbt,wally_psbt,
274274
msgdata,channeld_update_inflight,last_tx,?bitcoin_tx,
275275
msgdata,channeld_update_inflight,last_sig,?bitcoin_signature,
276+
msgdata,channeld_update_inflight,is_locked,bool,
276277

277278
# channeld->master: A funding error has occured
278279
msgtype,channeld_splice_funding_error,7220

lightningd/channel_control.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,9 +886,10 @@ static void handle_update_inflight(struct lightningd *ld,
886886
struct bitcoin_txid txid;
887887
struct bitcoin_tx *last_tx;
888888
struct bitcoin_signature *last_sig;
889+
bool is_locked;
889890

890891
if (!fromwire_channeld_update_inflight(tmpctx, msg, &psbt, &last_tx,
891-
&last_sig)) {
892+
&last_sig, &is_locked)) {
892893
channel_internal_error(channel,
893894
"bad channel_add_inflight %s",
894895
tal_hex(channel, msg));
@@ -916,6 +917,8 @@ static void handle_update_inflight(struct lightningd *ld,
916917
if (last_sig)
917918
inflight->last_sig = *last_sig;
918919

920+
inflight->is_locked = is_locked;
921+
919922
tal_wally_start();
920923
if (wally_psbt_combine(inflight->funding_psbt, psbt) != WALLY_OK) {
921924
channel_internal_error(channel,
@@ -1812,6 +1815,7 @@ bool peer_start_channeld(struct channel *channel,
18121815
infcopy->last_sig = inflight->last_sig;
18131816
infcopy->i_am_initiator = inflight->i_am_initiator;
18141817
infcopy->force_sign_first = inflight->force_sign_first;
1818+
infcopy->is_locked = inflight->is_locked;
18151819

18161820
tal_wally_start();
18171821
wally_psbt_clone_alloc(inflight->funding_psbt, 0, &infcopy->psbt);

0 commit comments

Comments
 (0)