Skip to content

Commit b9155cc

Browse files
committed
splice: Add Bolt references and conform to them
Adding Bolt references around `commitment_signed` logic and conforming to them. This allows us to remove the `await_commitment_succcess` logic which was never elegant anyway, nice! While we’re there we remove a parameter from `handle_peer_commit_sig_batch` that shouldn’t have been there anyway. Changelog-Changed: Adding stricter conformance to Bolt spec for splice commitments.
1 parent 0ecc402 commit b9155cc

File tree

3 files changed

+64
-44
lines changed

3 files changed

+64
-44
lines changed

channeld/channeld.c

Lines changed: 64 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,6 @@ static void check_mutual_splice_locked(struct peer *peer)
431431
fmt_bitcoin_txid(tmpctx,
432432
&peer->splice_state->locked_txid));
433433

434-
peer->splice_state->await_commitment_succcess = true;
435-
436434
/* This splice_locked event is used, so reset the flags to false */
437435
peer->splice_state->locked_ready[LOCAL] = false;
438436
peer->splice_state->locked_ready[REMOTE] = false;
@@ -1670,8 +1668,6 @@ static void send_revocation(struct peer *peer,
16701668
master_wait_sync_reply(tmpctx, peer, take(msg_for_master),
16711669
WIRE_CHANNELD_GOT_COMMITSIG_REPLY);
16721670

1673-
peer->splice_state->await_commitment_succcess = false;
1674-
16751671
/* Now that the master has persisted the new commitment advance the HSMD
16761672
* and fetch the revocation secret for the old one. */
16771673
msg = make_revocation_msg(peer, peer->next_index[LOCAL]-2,
@@ -1990,30 +1986,44 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
19901986
peer_failed_warn(peer->pps, &peer->channel_id,
19911987
"Bad commit_sig %s", tal_hex(msg, msg));
19921988

1993-
/* BOLT-0d8b701614b09c6ee4172b04da2203e73deec7e2 #2:
1994-
* Once a node has received and sent `splice_locked`:
1995-
* - Until sending OR receiving of `revoke_and_ack`
1996-
* ...
1997-
* - MUST ignore `commitment_signed` messages where `splice_channel_id`
1998-
* does not match the `channel_id` of the confirmed splice. */
1999-
if (peer->splice_state->await_commitment_succcess
2000-
&& !tal_count(peer->splice_state->inflights) && cs_tlv && cs_tlv->splice_info) {
2001-
if (!bitcoin_txid_eq(&peer->channel->funding.txid,
2002-
cs_tlv->splice_info)) {
2003-
status_info("Ignoring stale commit_sig for channel_id"
2004-
" %s, as %s is locked in now.",
2005-
fmt_bitcoin_txid(tmpctx,
2006-
cs_tlv->splice_info),
2007-
fmt_bitcoin_txid(tmpctx,
2008-
&peer->channel->funding.txid));
2009-
return NULL;
2010-
}
1989+
/* BOLT-f9fd539db6cc6f3e532fdc8cc1ebe8eb1a8fd717
1990+
* - If the sending node sent `start_batch` and we are processing a batch of
1991+
* `commitment_signed` messages:
1992+
*/
1993+
if (msg_batch) {
1994+
1995+
/* BOLT-f9fd539db6cc6f3e532fdc8cc1ebe8eb1a8fd717
1996+
* - If `funding_txid` is missing in one of the `commitment_signed` messages:
1997+
* - MUST send an `error` and fail the channel.
1998+
*/
1999+
if (!cs_tlv->splice_info)
2000+
peer_failed_err(peer->pps, &peer->channel_id,
2001+
"Must send funding_txid when sending"
2002+
" a commitment batch.");
2003+
2004+
/* BOLT-f9fd539db6cc6f3e532fdc8cc1ebe8eb1a8fd717
2005+
* - Otherwise (no pending splice transactions):
2006+
*...
2007+
* - If `commitment_signed` is missing for the current funding transaction:
2008+
* - MUST send an `error` and fail the channel.
2009+
*/
2010+
if (!tal_count(peer->splice_state->inflights)
2011+
&& !bitcoin_txid_eq(cs_tlv->splice_info,
2012+
&peer->channel->funding.txid))
2013+
peer_failed_err(peer->pps, &peer->channel_id,
2014+
"Commitment batch is is missing our"
2015+
" current funding transaction %s",
2016+
fmt_bitcoin_txid(tmpctx, &peer->channel->funding.txid));
20112017
}
20122018

2013-
/* In a race we can get here with a commitsig with too many splices
2014-
* attached. In that case we ignore the main commit msg for the old
2015-
* funding tx, and for the splice candidates that didnt win. But we must
2016-
* listen to the one that is for the winning splice candidate */
2019+
/* BOLT-f9fd539db6cc6f3e532fdc8cc1ebe8eb1a8fd717
2020+
* - If `funding_txid` is missing in one of the `commitment_signed` messages:
2021+
* - MUST send an `error` and fail the channel.
2022+
*/
2023+
if (commit_index && !cs_tlv->splice_info)
2024+
peer_failed_err(peer->pps, &peer->channel_id,
2025+
"Must send funding_txid when sending"
2026+
" a commitment batch");
20172027

20182028
if (!changed_htlcs) {
20192029
changed_htlcs = tal_arr(msg, const struct htlc *, 0);
@@ -2108,7 +2118,6 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
21082118
"Bad commit_sig signature %"PRIu64" %s for tx"
21092119
" %s wscript %s key %s feerate %u. Outpoint"
21102120
" %s, funding_sats: %s, splice_info: %s,"
2111-
" race_await_commit: %s,"
21122121
" inflight splice count: %zu",
21132122
local_index,
21142123
fmt_bitcoin_signature(msg, &commit_sig),
@@ -2122,8 +2131,6 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
21222131
? fmt_bitcoin_txid(tmpctx,
21232132
cs_tlv->splice_info)
21242133
: "N/A",
2125-
peer->splice_state->await_commitment_succcess ? "yes"
2126-
: "no",
21272134
tal_count(peer->splice_state->inflights));
21282135
}
21292136

@@ -2224,9 +2231,14 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
22242231
tal_count(peer->splice_state->inflights));
22252232

22262233
commitsigs = tal_arr(NULL, const struct commitsig*, 0);
2227-
/* We expect multiple consequtive commit_sig messages if we have
2228-
* inflight splices. Since consequtive is requred, we recurse for
2229-
* each expected message, blocking until all are received. */
2234+
/* BOLT-f9fd539db6cc6f3e532fdc8cc1ebe8eb1a8fd717
2235+
* - If there are pending splice transactions:
2236+
* - MUST validate each `commitment_signed` based on `funding_txid`.
2237+
* - If `commitment_signed` is missing for a funding transaction:
2238+
* - MUST send an `error` and fail the channel.
2239+
* - Otherwise:
2240+
* - MUST respond with a `revoke_and_ack` message.
2241+
*/
22302242
for (i = 0; i < tal_count(peer->splice_state->inflights); i++) {
22312243
s64 funding_diff = sats_diff(peer->splice_state->inflights[i]->amnt,
22322244
peer->channel->funding_sats);
@@ -2317,7 +2329,6 @@ static int commit_cmp(const void *a, const void *n, void *peer)
23172329

23182330
static struct commitsig_info *handle_peer_commit_sig_batch(struct peer *peer,
23192331
const u8 *msg,
2320-
u32 commit_index,
23212332
struct pubkey remote_funding,
23222333
const struct htlc **changed_htlcs,
23232334
s64 splice_amnt,
@@ -2347,6 +2358,16 @@ static struct commitsig_info *handle_peer_commit_sig_batch(struct peer *peer,
23472358
peer_failed_warn(peer->pps, &peer->channel_id,
23482359
"Bad commit_sig %s", tal_hex(msg, msg));
23492360

2361+
/* BOLT-f9fd539db6cc6f3e532fdc8cc1ebe8eb1a8fd717
2362+
* - If there are pending splice transactions and the sending node did not
2363+
* send `start_batch` followed by a batch of `commitment_signed` messages:
2364+
* - MUST send an `error` and fail the channel.
2365+
*/
2366+
if (batch_size < 2 && last_inflight(peer))
2367+
peer_failed_err(peer->pps, &peer->channel_id, "Must send a"
2368+
" commitment batch (ie. start_batch) when I"
2369+
" have pending splices inflight.");
2370+
23502371
msg_batch = tal_arr(tmpctx, const u8*, batch_size);
23512372
msg_batch[0] = msg;
23522373

@@ -2383,10 +2404,17 @@ static struct commitsig_info *handle_peer_commit_sig_batch(struct peer *peer,
23832404
msg_batch[i] = sub_msg;
23842405
}
23852406

2407+
/* BOLT-f9fd539db6cc6f3e532fdc8cc1ebe8eb1a8fd717
2408+
* - Otherwise (no pending splice transactions):
2409+
* - MUST ignore `commitment_signed` where `funding_txid` does not match
2410+
* the current funding transaction.
2411+
*/
2412+
/* Sort puts all unrecognized `commitment_signed` messages onto the back
2413+
* of `msg_batch`, where they will be ignored */
23862414
status_debug("Sorting the msg_batch of tal_count %d, batch_size: %d", (int)tal_count(msg_batch), (int)batch_size);
23872415
asort(msg_batch, tal_count(msg_batch), commit_cmp, peer);
23882416

2389-
return handle_peer_commit_sig(peer, msg_batch[0], commit_index,
2417+
return handle_peer_commit_sig(peer, msg_batch[0], 0,
23902418
remote_funding, changed_htlcs,
23912419
splice_amnt, remote_splice_amnt,
23922420
local_index, local_per_commit,
@@ -2412,7 +2440,7 @@ static void handle_peer_start_batch(struct peer *peer, const u8 *msg)
24122440
return;
24132441
}
24142442

2415-
handle_peer_commit_sig_batch(peer, peer_read(tmpctx, peer->pps), 0,
2443+
handle_peer_commit_sig_batch(peer, peer_read(tmpctx, peer->pps),
24162444
peer->channel->funding_pubkey[REMOTE],
24172445
NULL, 0, 0,
24182446
peer->next_index[LOCAL],
@@ -2561,8 +2589,6 @@ static void handle_peer_revoke_and_ack(struct peer *peer, const u8 *msg)
25612589
fmt_pubkey(tmpctx, &peer->remote_per_commit),
25622590
fmt_pubkey(tmpctx, &peer->old_remote_per_commit));
25632591

2564-
peer->splice_state->await_commitment_succcess = false;
2565-
25662592
/* STFU can't be activated during pending updates.
25672593
* With updates finish let's handle a potentially queued stfu request.
25682594
*/
@@ -4079,8 +4105,6 @@ static void splice_accepter(struct peer *peer, const u8 *inmsg)
40794105
peer->splicing->remote_funding_pubkey = last_inflight(peer)->remote_funding;
40804106
}
40814107

4082-
peer->splice_state->await_commitment_succcess = false;
4083-
40844108
if (!is_stfu_active(peer))
40854109
peer_failed_warn(peer->pps, &peer->channel_id,
40864110
"Must be in STFU mode before intiating splice");
@@ -4766,7 +4790,6 @@ static void handle_splice_stfu_success(struct peer *peer)
47664790
init_rbf_tlvs);
47674791
}
47684792

4769-
peer->splice_state->await_commitment_succcess = false;
47704793
peer_write(peer->pps, take(msg));
47714794
}
47724795

@@ -4984,7 +5007,7 @@ static void peer_in(struct peer *peer, const u8 *msg)
49845007
handle_peer_start_batch(peer, msg);
49855008
return;
49865009
case WIRE_COMMITMENT_SIGNED:
4987-
handle_peer_commit_sig_batch(peer, msg, 0,
5010+
handle_peer_commit_sig_batch(peer, msg,
49885011
peer->channel->funding_pubkey[REMOTE],
49895012
NULL, 0, 0,
49905013
peer->next_index[LOCAL],

channeld/splice.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ struct splice_state *splice_state_new(const tal_t *ctx)
99
splice_state->count = 0;
1010
splice_state->locked_ready[LOCAL] = false;
1111
splice_state->locked_ready[REMOTE] = false;
12-
splice_state->await_commitment_succcess = false;
1312
splice_state->inflights = NULL;
1413
splice_state->remote_locked_txid = NULL;
1514

channeld/splice.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ struct splice_state {
1717
struct short_channel_id last_short_channel_id;
1818
/* Tally of which sides are locked, or not */
1919
bool locked_ready[NUM_SIDES];
20-
/* Set to true when commitment cycle completes successfully */
21-
bool await_commitment_succcess;
2220
/* The txid of which splice inflight was confirmed */
2321
struct bitcoin_txid locked_txid;
2422
/* The txid our peer locked their splice on */

0 commit comments

Comments
 (0)