From 3ca753e0b4ed30148a4250af145870a3241e75c7 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 2 Oct 2023 09:29:52 +1030 Subject: [PATCH] lightningd: fix bug where we didn't correctly change outpoint of splice scid. We used the original channel funding output number. I'm not sure if this was true in the previous code, or a regression I introduced, but it caused occasonal failures in test_splice_gossip! Signed-off-by: Rusty Russell --- lightningd/channel_control.c | 11 ++++++----- lightningd/channel_control.h | 3 ++- lightningd/peer_control.c | 2 +- lightningd/test/run-invoice-select-inchan.c | 3 ++- wallet/test/run-wallet.c | 3 ++- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index c8d57cfdd..9f544524f 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -543,7 +543,8 @@ static void handle_splice_confirmed_signed(struct lightningd *ld, } bool depthcb_update_scid(struct channel *channel, - const struct bitcoin_txid *txid) + const struct bitcoin_txid *txid, + const struct bitcoin_outpoint *outpoint) { struct txlocator *loc; struct lightningd *ld = channel->peer->ld; @@ -553,17 +554,17 @@ bool depthcb_update_scid(struct channel *channel, loc = wallet_transaction_locate(tmpctx, ld->wallet, txid); if (!mk_short_channel_id(&scid, loc->blkheight, loc->index, - channel->funding.n)) { + outpoint->n)) { channel_fail_permanent(channel, REASON_LOCAL, "Invalid funding scid %u:%u:%u", loc->blkheight, loc->index, - channel->funding.n); + outpoint->n); return false; } if (!channel->scid) { - wallet_annotate_txout(ld->wallet, &channel->funding, + wallet_annotate_txout(ld->wallet, outpoint, TX_CHANNEL_FUNDING, channel->dbid); channel->scid = tal_dup(channel, struct short_channel_id, &scid); @@ -606,7 +607,7 @@ static enum watch_result splice_depth_cb(struct lightningd *ld, if (depth == 0) return KEEP_WATCHING; - if (!depthcb_update_scid(inflight->channel, txid)) + if (!depthcb_update_scid(inflight->channel, txid, &inflight->funding->outpoint)) return DELETE_WATCH; if (inflight->channel->owner) { diff --git a/lightningd/channel_control.h b/lightningd/channel_control.h index 85ddf7069..d8c52bdb1 100644 --- a/lightningd/channel_control.h +++ b/lightningd/channel_control.h @@ -60,5 +60,6 @@ void watch_splice_inflight(struct lightningd *ld, /* Update/set scid now this txid is mined. */ bool depthcb_update_scid(struct channel *channel, - const struct bitcoin_txid *txid); + const struct bitcoin_txid *txid, + const struct bitcoin_outpoint *outpoint); #endif /* LIGHTNING_LIGHTNINGD_CHANNEL_CONTROL_H */ diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index b987d953d..eb711889e 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1950,7 +1950,7 @@ static enum watch_result funding_depth_cb(struct lightningd *ld, return KEEP_WATCHING; } - if (!depthcb_update_scid(channel, txid)) + if (!depthcb_update_scid(channel, txid, &channel->funding)) return DELETE_WATCH; /* Always tell owner about depth change */ diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index bc7c511ad..418762514 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -200,7 +200,8 @@ void delete_channel(struct channel *channel STEALS UNNEEDED) { fprintf(stderr, "delete_channel called!\n"); abort(); } /* Generated stub for depthcb_update_scid */ bool depthcb_update_scid(struct channel *channel UNNEEDED, - const struct bitcoin_txid *txid UNNEEDED) + const struct bitcoin_txid *txid UNNEEDED, + const struct bitcoin_outpoint *outpoint UNNEEDED) { fprintf(stderr, "depthcb_update_scid called!\n"); abort(); } /* Generated stub for dev_disconnect_permanent */ bool dev_disconnect_permanent(struct lightningd *ld UNNEEDED) diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index d47886ddb..813869a78 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -141,7 +141,8 @@ struct onionreply *create_onionreply(const tal_t *ctx UNNEEDED, { fprintf(stderr, "create_onionreply called!\n"); abort(); } /* Generated stub for depthcb_update_scid */ bool depthcb_update_scid(struct channel *channel UNNEEDED, - const struct bitcoin_txid *txid UNNEEDED) + const struct bitcoin_txid *txid UNNEEDED, + const struct bitcoin_outpoint *outpoint UNNEEDED) { fprintf(stderr, "depthcb_update_scid called!\n"); abort(); } /* Generated stub for derive_channel_id */ void derive_channel_id(struct channel_id *channel_id UNNEEDED,