Skip to content

Commit 89eaf83

Browse files
committed
lightningd: cancel watching original funding when we switch to the new one via splice.
This happens if the channel is *not* announcable yet. Then we hit the assertion in funding_depth_cb that the txid is the same as the current funding.txid. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Changelog-EXPERIMENTAL: fixed crash when we splice a channel which hasn't been announced yet.
1 parent d4a541c commit 89eaf83

File tree

6 files changed

+35
-2
lines changed

6 files changed

+35
-2
lines changed

lightningd/channel_control.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,14 +1125,17 @@ static void handle_peer_splice_locked(struct channel *channel, const u8 *msg)
11251125
wallet_htlcsigs_confirm_inflight(channel->peer->ld->wallet, channel,
11261126
&inflight->funding->outpoint);
11271127

1128-
update_channel_from_inflight(channel->peer->ld, channel, inflight, true);
1128+
/* Stop watching previous funding tx (could be, for announcement) */
1129+
channel_unwatch_funding(channel->peer->ld, channel);
11291130

11301131
/* Stash prev funding data so we can log it after scid is updated
11311132
* (to get the blockheight) */
11321133
prev_our_msats = channel->our_msat;
11331134
prev_funding_sats = channel->funding_sats;
11341135
prev_funding_out = channel->funding;
11351136

1137+
update_channel_from_inflight(channel->peer->ld, channel, inflight, true);
1138+
11361139
channel->our_msat.millisatoshis += splice_amnt * 1000; /* Raw: splicing */
11371140
channel->msat_to_us_min.millisatoshis += splice_amnt * 1000; /* Raw: splicing */
11381141
channel->msat_to_us_max.millisatoshis += splice_amnt * 1000; /* Raw: splicing */

lightningd/peer_control.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,6 +2347,14 @@ void channel_watch_wrong_funding(struct lightningd *ld, struct channel *channel)
23472347
}
23482348
}
23492349

2350+
/* We need to do this before we change channel funding (for splice), otherwise
2351+
* funding_depth_cb will fail the assertion that it's the current funding tx */
2352+
void channel_unwatch_funding(struct lightningd *ld, struct channel *channel)
2353+
{
2354+
tal_free(find_txwatch(ld->topology,
2355+
&channel->funding.txid, funding_depth_cb, channel));
2356+
}
2357+
23502358
void channel_watch_funding(struct lightningd *ld, struct channel *channel)
23512359
{
23522360
log_debug(channel->log, "Watching for funding txid: %s",

lightningd/peer_control.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ void update_channel_from_inflight(struct lightningd *ld,
131131
const struct channel_inflight *inflight,
132132
bool is_splice);
133133

134+
void channel_unwatch_funding(struct lightningd *ld, struct channel *channel);
134135
void channel_watch_funding(struct lightningd *ld, struct channel *channel);
135136

136137
/* If this channel has a "wrong funding" shutdown, watch that too. */

lightningd/test/run-invoice-select-inchan.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,16 @@ struct channel *find_channel_by_id(const struct peer *peer UNNEEDED,
244244
struct plugin *find_plugin_for_command(struct lightningd *ld UNNEEDED,
245245
const char *cmd_name UNNEEDED)
246246
{ fprintf(stderr, "find_plugin_for_command called!\n"); abort(); }
247+
/* Generated stub for find_txwatch_ */
248+
struct txwatch *find_txwatch_(struct chain_topology *topo UNNEEDED,
249+
const struct bitcoin_txid *txid UNNEEDED,
250+
enum watch_result (*cb)(struct lightningd *ld UNNEEDED,
251+
const struct bitcoin_txid * UNNEEDED,
252+
const struct bitcoin_tx * UNNEEDED,
253+
unsigned int depth UNNEEDED,
254+
void *arg) UNNEEDED,
255+
void *arg UNNEEDED)
256+
{ fprintf(stderr, "find_txwatch_ called!\n"); abort(); }
247257
/* Generated stub for fixup_htlcs_out */
248258
void fixup_htlcs_out(struct lightningd *ld UNNEEDED)
249259
{ fprintf(stderr, "fixup_htlcs_out called!\n"); abort(); }

tests/test_splicing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,9 @@ def test_route_by_old_scid(node_factory, bitcoind):
558558
l1.rpc.waitsendpay(inv2['payment_hash'])
559559

560560

561-
@pytest.mark.xfail(strict=True)
562561
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
562+
@pytest.mark.openchannel('v1')
563+
@pytest.mark.openchannel('v2')
563564
def test_splice_unannounced(node_factory, bitcoind):
564565
l1, l2 = node_factory.line_graph(2, fundamount=1000000, wait_for_announce=False, opts={'experimental-splicing': None})
565566

wallet/test/run-wallet.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,16 @@ void fatal(const char *fmt UNNEEDED, ...)
243243
/* Generated stub for fatal_vfmt */
244244
void fatal_vfmt(const char *fmt UNNEEDED, va_list ap UNNEEDED)
245245
{ fprintf(stderr, "fatal_vfmt called!\n"); abort(); }
246+
/* Generated stub for find_txwatch_ */
247+
struct txwatch *find_txwatch_(struct chain_topology *topo UNNEEDED,
248+
const struct bitcoin_txid *txid UNNEEDED,
249+
enum watch_result (*cb)(struct lightningd *ld UNNEEDED,
250+
const struct bitcoin_txid * UNNEEDED,
251+
const struct bitcoin_tx * UNNEEDED,
252+
unsigned int depth UNNEEDED,
253+
void *arg) UNNEEDED,
254+
void *arg UNNEEDED)
255+
{ fprintf(stderr, "find_txwatch_ called!\n"); abort(); }
246256
/* Generated stub for force_peer_disconnect */
247257
void force_peer_disconnect(struct lightningd *ld UNNEEDED,
248258
const struct peer *peer UNNEEDED,

0 commit comments

Comments
 (0)