Skip to content

Commit 0a3adce

Browse files
ddustinremyers
authored andcommitted
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 4fb27fa commit 0a3adce

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
@@ -5647,6 +5647,7 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg)
56475647
struct pubkey point;
56485648
bool splicing;
56495649
struct bitcoin_txid txid;
5650+
struct inflight *inflight_match;
56505651

56515652
if (!fromwire_channeld_funding_depth(tmpctx,
56525653
msg,
@@ -5660,35 +5661,91 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg)
56605661
if (peer->shutdown_sent[LOCAL])
56615662
return;
56625663

5663-
if (depth < peer->channel->minimum_depth) {
5664-
peer->depth_togo = peer->channel->minimum_depth - depth;
5665-
} else {
5666-
peer->depth_togo = 0;
5664+
if (splicing) {
5665+
if (depth < peer->channel->minimum_depth)
5666+
return;
56675667

5668-
/* For splicing we only update the short channel id on mutual
5669-
* splice lock */
5670-
if (splicing) {
5668+
assert(peer->channel_ready[LOCAL]);
5669+
assert(peer->channel_ready[REMOTE]);
5670+
5671+
if(!peer->splice_state->locked_ready[LOCAL]) {
5672+
assert(scid);
5673+
5674+
inflight_match = NULL;
5675+
for (size_t i = 0; i < tal_count(peer->splice_state->inflights); i++) {
5676+
struct inflight *inflight = peer->splice_state->inflights[i];
5677+
if (bitcoin_txid_eq(&inflight->outpoint.txid,
5678+
&txid)) {
5679+
if (inflight_match)
5680+
peer_failed_err(peer->pps,
5681+
&peer->channel_id,
5682+
"It should be"
5683+
" impossible"
5684+
" for two"
5685+
" inflights to"
5686+
"match, %s",
5687+
fmt_bitcoin_txid(tmpctx, &txid));
5688+
inflight->is_locked = true;
5689+
assert(inflight->psbt);
5690+
msg = towire_channeld_update_inflight(NULL,
5691+
inflight->psbt,
5692+
NULL,
5693+
NULL,
5694+
inflight->is_locked);
5695+
wire_sync_write(MASTER_FD, take(msg));
5696+
inflight_match = inflight;
5697+
}
5698+
}
5699+
5700+
if (!inflight_match) {
5701+
status_debug("Ignoring stale fudning depth"
5702+
" notification %s for splice depth"
5703+
" check",
5704+
fmt_bitcoin_txid(tmpctx, &txid));
5705+
return;
5706+
}
5707+
5708+
/* For splicing we only update the short channel id on mutual
5709+
* splice lock */
56715710
peer->splice_state->short_channel_id = *scid;
56725711
status_debug("Current channel id is %s, "
56735712
"splice_short_channel_id now set to %s",
56745713
fmt_short_channel_id(tmpctx,
56755714
peer->short_channel_ids[LOCAL]),
56765715
fmt_short_channel_id(tmpctx,
56775716
peer->splice_state->short_channel_id));
5678-
} else {
5679-
status_debug("handle_funding_depth: Setting short_channel_ids[LOCAL] to %s",
5680-
fmt_short_channel_id(tmpctx,
5681-
(scid ? *scid : peer->local_alias)));
5682-
/* If we know an actual short_channel_id prefer to use
5683-
* that, otherwise fill in the alias. From channeld's
5684-
* point of view switching from zeroconf to an actual
5685-
* funding scid is just a reorg. */
5686-
if (scid)
5687-
peer->short_channel_ids[LOCAL] = *scid;
5688-
else
5689-
peer->short_channel_ids[LOCAL] = peer->local_alias;
5717+
5718+
peer->splice_state->locked_txid = txid;
5719+
5720+
msg = towire_splice_locked(NULL, &peer->channel_id,
5721+
&txid);
5722+
5723+
peer_write(peer->pps, take(msg));
5724+
5725+
peer->splice_state->locked_ready[LOCAL] = true;
5726+
check_mutual_splice_locked(peer);
56905727
}
56915728

5729+
return;
5730+
}
5731+
5732+
if (depth < peer->channel->minimum_depth) {
5733+
peer->depth_togo = peer->channel->minimum_depth - depth;
5734+
} else {
5735+
peer->depth_togo = 0;
5736+
5737+
status_debug("handle_funding_depth: Setting short_channel_ids[LOCAL] to %s",
5738+
fmt_short_channel_id(tmpctx,
5739+
(scid ? *scid : peer->local_alias)));
5740+
/* If we know an actual short_channel_id prefer to use
5741+
* that, otherwise fill in the alias. From channeld's
5742+
* point of view switching from zeroconf to an actual
5743+
* funding scid is just a reorg. */
5744+
if (scid)
5745+
peer->short_channel_ids[LOCAL] = *scid;
5746+
else
5747+
peer->short_channel_ids[LOCAL] = peer->local_alias;
5748+
56925749
if (!peer->channel_ready[LOCAL]) {
56935750
status_debug("channel_ready: sending commit index"
56945751
" %"PRIu64": %s",
@@ -5709,33 +5766,6 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg)
57095766

57105767
peer->channel_ready[LOCAL] = true;
57115768
check_mutual_channel_ready(peer);
5712-
} else if(splicing && !peer->splice_state->locked_ready[LOCAL]) {
5713-
assert(scid);
5714-
5715-
for (size_t i = 0; i < tal_count(peer->splice_state->inflights); i++) {
5716-
struct inflight *inflight = peer->splice_state->inflights[i];
5717-
if (bitcoin_txid_eq(&inflight->outpoint.txid,
5718-
&txid)) {
5719-
inflight->is_locked = true;
5720-
assert(inflight->psbt);
5721-
msg = towire_channeld_update_inflight(NULL,
5722-
inflight->psbt,
5723-
NULL,
5724-
NULL,
5725-
inflight->is_locked);
5726-
wire_sync_write(MASTER_FD, take(msg));
5727-
}
5728-
}
5729-
5730-
peer->splice_state->locked_txid = txid;
5731-
5732-
msg = towire_splice_locked(NULL, &peer->channel_id,
5733-
&txid);
5734-
5735-
peer_write(peer->pps, take(msg));
5736-
5737-
peer->splice_state->locked_ready[LOCAL] = true;
5738-
check_mutual_splice_locked(peer);
57395769
}
57405770
}
57415771

0 commit comments

Comments
 (0)