Skip to content

Commit da02fad

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 5f83e46 commit da02fad

3 files changed

Lines changed: 64 additions & 44 deletions

File tree

channeld/channeld.c

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

428-
peer->splice_state->await_commitment_succcess = true;
429-
430428
/* This splice_locked event is used, so reset the flags to false */
431429
peer->splice_state->locked_ready[LOCAL] = false;
432430
peer->splice_state->locked_ready[REMOTE] = false;
@@ -1666,8 +1664,6 @@ static void send_revocation(struct peer *peer,
16661664
master_wait_sync_reply(tmpctx, peer, take(msg_for_master),
16671665
WIRE_CHANNELD_GOT_COMMITSIG_REPLY);
16681666

1669-
peer->splice_state->await_commitment_succcess = false;
1670-
16711667
/* Now that the master has persisted the new commitment advance the HSMD
16721668
* and fetch the revocation secret for the old one. */
16731669
msg = make_revocation_msg(peer, peer->next_index[LOCAL]-2,
@@ -1986,30 +1982,44 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
19861982
peer_failed_warn(peer->pps, &peer->channel_id,
19871983
"Bad commit_sig %s", tal_hex(msg, msg));
19881984

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

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

20142024
if (!changed_htlcs) {
20152025
changed_htlcs = tal_arr(msg, const struct htlc *, 0);
@@ -2104,7 +2114,6 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
21042114
"Bad commit_sig signature %"PRIu64" %s for tx"
21052115
" %s wscript %s key %s feerate %u. Outpoint"
21062116
" %s, funding_sats: %s, splice_info: %s,"
2107-
" race_await_commit: %s,"
21082117
" inflight splice count: %zu",
21092118
local_index,
21102119
fmt_bitcoin_signature(msg, &commit_sig),
@@ -2118,8 +2127,6 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
21182127
? fmt_bitcoin_txid(tmpctx,
21192128
cs_tlv->splice_info)
21202129
: "N/A",
2121-
peer->splice_state->await_commitment_succcess ? "yes"
2122-
: "no",
21232130
tal_count(peer->splice_state->inflights));
21242131
}
21252132

@@ -2220,9 +2227,14 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
22202227
tal_count(peer->splice_state->inflights));
22212228

22222229
commitsigs = tal_arr(NULL, const struct commitsig*, 0);
2223-
/* We expect multiple consequtive commit_sig messages if we have
2224-
* inflight splices. Since consequtive is requred, we recurse for
2225-
* each expected message, blocking until all are received. */
2230+
/* BOLT-f9fd539db6cc6f3e532fdc8cc1ebe8eb1a8fd717
2231+
* - If there are pending splice transactions:
2232+
* - MUST validate each `commitment_signed` based on `funding_txid`.
2233+
* - If `commitment_signed` is missing for a funding transaction:
2234+
* - MUST send an `error` and fail the channel.
2235+
* - Otherwise:
2236+
* - MUST respond with a `revoke_and_ack` message.
2237+
*/
22262238
for (i = 0; i < tal_count(peer->splice_state->inflights); i++) {
22272239
s64 funding_diff = sats_diff(peer->splice_state->inflights[i]->amnt,
22282240
peer->channel->funding_sats);
@@ -2313,7 +2325,6 @@ static int commit_cmp(const void *a, const void *n, void *peer)
23132325

23142326
static struct commitsig_info *handle_peer_commit_sig_batch(struct peer *peer,
23152327
const u8 *msg,
2316-
u32 commit_index,
23172328
struct pubkey remote_funding,
23182329
const struct htlc **changed_htlcs,
23192330
s64 splice_amnt,
@@ -2343,6 +2354,16 @@ static struct commitsig_info *handle_peer_commit_sig_batch(struct peer *peer,
23432354
peer_failed_warn(peer->pps, &peer->channel_id,
23442355
"Bad commit_sig %s", tal_hex(msg, msg));
23452356

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

@@ -2379,9 +2400,16 @@ static struct commitsig_info *handle_peer_commit_sig_batch(struct peer *peer,
23792400
msg_batch[i] = sub_msg;
23802401
}
23812402

2403+
/* BOLT-f9fd539db6cc6f3e532fdc8cc1ebe8eb1a8fd717
2404+
* - Otherwise (no pending splice transactions):
2405+
* - MUST ignore `commitment_signed` where `funding_txid` does not match
2406+
* the current funding transaction.
2407+
*/
2408+
/* Sort puts all unrecognized `commitment_signed` messages onto the back
2409+
* of `msg_batch`, where they will be ignored */
23822410
asort(msg_batch, tal_count(msg_batch), commit_cmp, peer);
23832411

2384-
return handle_peer_commit_sig(peer, msg_batch[0], commit_index,
2412+
return handle_peer_commit_sig(peer, msg_batch[0], 0,
23852413
remote_funding, changed_htlcs,
23862414
splice_amnt, remote_splice_amnt,
23872415
local_index, local_per_commit,
@@ -2407,7 +2435,7 @@ static void handle_peer_start_batch(struct peer *peer, const u8 *msg)
24072435
return;
24082436
}
24092437

2410-
handle_peer_commit_sig_batch(peer, peer_read(tmpctx, peer->pps), 0,
2438+
handle_peer_commit_sig_batch(peer, peer_read(tmpctx, peer->pps),
24112439
peer->channel->funding_pubkey[REMOTE],
24122440
NULL, 0, 0,
24132441
peer->next_index[LOCAL],
@@ -2556,8 +2584,6 @@ static void handle_peer_revoke_and_ack(struct peer *peer, const u8 *msg)
25562584
fmt_pubkey(tmpctx, &peer->remote_per_commit),
25572585
fmt_pubkey(tmpctx, &peer->old_remote_per_commit));
25582586

2559-
peer->splice_state->await_commitment_succcess = false;
2560-
25612587
/* STFU can't be activated during pending updates.
25622588
* With updates finish let's handle a potentially queued stfu request.
25632589
*/
@@ -4074,8 +4100,6 @@ static void splice_accepter(struct peer *peer, const u8 *inmsg)
40744100
peer->splicing->remote_funding_pubkey = last_inflight(peer)->remote_funding;
40754101
}
40764102

4077-
peer->splice_state->await_commitment_succcess = false;
4078-
40794103
if (!is_stfu_active(peer))
40804104
peer_failed_warn(peer->pps, &peer->channel_id,
40814105
"Must be in STFU mode before intiating splice");
@@ -4761,7 +4785,6 @@ static void handle_splice_stfu_success(struct peer *peer)
47614785
init_rbf_tlvs);
47624786
}
47634787

4764-
peer->splice_state->await_commitment_succcess = false;
47654788
peer_write(peer->pps, take(msg));
47664789
}
47674790

@@ -4979,7 +5002,7 @@ static void peer_in(struct peer *peer, const u8 *msg)
49795002
handle_peer_start_batch(peer, msg);
49805003
return;
49815004
case WIRE_COMMITMENT_SIGNED:
4982-
handle_peer_commit_sig_batch(peer, msg, 0,
5005+
handle_peer_commit_sig_batch(peer, msg,
49835006
peer->channel->funding_pubkey[REMOTE],
49845007
NULL, 0, 0,
49855008
peer->next_index[LOCAL],

channeld/splice.c

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

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)