Skip to content

Commit 7386408

Browse files
committed
Splice: Verify splice conf txid
Sometimes if you splice twice in a row the original splice’s confirmation on chain can send a spurious funding depth notif next to the one we’re interested in (for the second splice). Add some validation inside channeld to check that this funding depth notification is for an inflight we’re definetely interested in — otherwise ignore it. Changelog-None
1 parent 0a58ec3 commit 7386408

File tree

1 file changed

+76
-46
lines changed

1 file changed

+76
-46
lines changed

channeld/channeld.c

Lines changed: 76 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5623,6 +5623,7 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg)
56235623
struct pubkey point;
56245624
bool splicing;
56255625
struct bitcoin_txid txid;
5626+
struct inflight *inflight_match;
56265627

56275628
if (!fromwire_channeld_funding_depth(tmpctx,
56285629
msg,
@@ -5636,35 +5637,91 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg)
56365637
if (peer->shutdown_sent[LOCAL])
56375638
return;
56385639

5639-
if (depth < peer->channel->minimum_depth) {
5640-
peer->depth_togo = peer->channel->minimum_depth - depth;
5641-
} else {
5642-
peer->depth_togo = 0;
5640+
if (splicing) {
5641+
if (depth < peer->channel->minimum_depth)
5642+
return;
56435643

5644-
/* For splicing we only update the short channel id on mutual
5645-
* splice lock */
5646-
if (splicing) {
5644+
assert(peer->channel_ready[LOCAL]);
5645+
assert(peer->channel_ready[REMOTE]);
5646+
5647+
if(!peer->splice_state->locked_ready[LOCAL]) {
5648+
assert(scid);
5649+
5650+
inflight_match = NULL;
5651+
for (size_t i = 0; i < tal_count(peer->splice_state->inflights); i++) {
5652+
struct inflight *inflight = peer->splice_state->inflights[i];
5653+
if (bitcoin_txid_eq(&inflight->outpoint.txid,
5654+
&txid)) {
5655+
if (inflight_match)
5656+
peer_failed_err(peer->pps,
5657+
&peer->channel_id,
5658+
"It should be"
5659+
" impossible"
5660+
" for two"
5661+
" inflights to"
5662+
"match, %s",
5663+
fmt_bitcoin_txid(tmpctx, &txid));
5664+
inflight->is_locked = true;
5665+
assert(inflight->psbt);
5666+
msg = towire_channeld_update_inflight(NULL,
5667+
inflight->psbt,
5668+
NULL,
5669+
NULL,
5670+
inflight->is_locked);
5671+
wire_sync_write(MASTER_FD, take(msg));
5672+
inflight_match = inflight;
5673+
}
5674+
}
5675+
5676+
if (!inflight_match) {
5677+
status_debug("Ignoring stale fudning depth"
5678+
" notification %s for splice depth"
5679+
" check",
5680+
fmt_bitcoin_txid(tmpctx, &txid));
5681+
return;
5682+
}
5683+
5684+
/* For splicing we only update the short channel id on mutual
5685+
* splice lock */
56475686
peer->splice_state->short_channel_id = *scid;
56485687
status_debug("Current channel id is %s, "
56495688
"splice_short_channel_id now set to %s",
56505689
fmt_short_channel_id(tmpctx,
56515690
peer->short_channel_ids[LOCAL]),
56525691
fmt_short_channel_id(tmpctx,
56535692
peer->splice_state->short_channel_id));
5654-
} else {
5655-
status_debug("handle_funding_depth: Setting short_channel_ids[LOCAL] to %s",
5656-
fmt_short_channel_id(tmpctx,
5657-
(scid ? *scid : peer->local_alias)));
5658-
/* If we know an actual short_channel_id prefer to use
5659-
* that, otherwise fill in the alias. From channeld's
5660-
* point of view switching from zeroconf to an actual
5661-
* funding scid is just a reorg. */
5662-
if (scid)
5663-
peer->short_channel_ids[LOCAL] = *scid;
5664-
else
5665-
peer->short_channel_ids[LOCAL] = peer->local_alias;
5693+
5694+
peer->splice_state->locked_txid = txid;
5695+
5696+
msg = towire_splice_locked(NULL, &peer->channel_id,
5697+
&txid);
5698+
5699+
peer_write(peer->pps, take(msg));
5700+
5701+
peer->splice_state->locked_ready[LOCAL] = true;
5702+
check_mutual_splice_locked(peer);
56665703
}
56675704

5705+
return;
5706+
}
5707+
5708+
if (depth < peer->channel->minimum_depth) {
5709+
peer->depth_togo = peer->channel->minimum_depth - depth;
5710+
} else {
5711+
peer->depth_togo = 0;
5712+
5713+
status_debug("handle_funding_depth: Setting short_channel_ids[LOCAL] to %s",
5714+
fmt_short_channel_id(tmpctx,
5715+
(scid ? *scid : peer->local_alias)));
5716+
/* If we know an actual short_channel_id prefer to use
5717+
* that, otherwise fill in the alias. From channeld's
5718+
* point of view switching from zeroconf to an actual
5719+
* funding scid is just a reorg. */
5720+
if (scid)
5721+
peer->short_channel_ids[LOCAL] = *scid;
5722+
else
5723+
peer->short_channel_ids[LOCAL] = peer->local_alias;
5724+
56685725
if (!peer->channel_ready[LOCAL]) {
56695726
status_debug("channel_ready: sending commit index"
56705727
" %"PRIu64": %s",
@@ -5685,33 +5742,6 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg)
56855742

56865743
peer->channel_ready[LOCAL] = true;
56875744
check_mutual_channel_ready(peer);
5688-
} else if(splicing && !peer->splice_state->locked_ready[LOCAL]) {
5689-
assert(scid);
5690-
5691-
for (size_t i = 0; i < tal_count(peer->splice_state->inflights); i++) {
5692-
struct inflight *inflight = peer->splice_state->inflights[i];
5693-
if (bitcoin_txid_eq(&inflight->outpoint.txid,
5694-
&txid)) {
5695-
inflight->is_locked = true;
5696-
assert(inflight->psbt);
5697-
msg = towire_channeld_update_inflight(NULL,
5698-
inflight->psbt,
5699-
NULL,
5700-
NULL,
5701-
inflight->is_locked);
5702-
wire_sync_write(MASTER_FD, take(msg));
5703-
}
5704-
}
5705-
5706-
peer->splice_state->locked_txid = txid;
5707-
5708-
msg = towire_splice_locked(NULL, &peer->channel_id,
5709-
&txid);
5710-
5711-
peer_write(peer->pps, take(msg));
5712-
5713-
peer->splice_state->locked_ready[LOCAL] = true;
5714-
check_mutual_splice_locked(peer);
57155745
}
57165746
}
57175747

0 commit comments

Comments
 (0)