lightningd: make caller to deptch_update_scid fetch the location in the block
What changed, and why it matters
This is a small internal code cleanup in Core Lightning. A function that builds a channel identifier (short_channel_id) used to look up a transaction's block position itself; now its callers look up that position and pass it in. The commit message frames this as preparation for a future change, not as a security fix. There is no indication of a vulnerability being patched.
No security action required. Treat as routine refactoring/preparatory commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors depthcb_update_scid() to take a const struct txlocator *loc argument instead of calling wallet_transaction_locate() internally. Callers in channel_control.c and peer_control.c now fetch the txlocator before invoking depthcb_update_scid(). Test stubs are updated accordingly. The change is behavioral only in where the lookup happens; it does not alter validation, authorization, or output values.
Changed components
lightningd/channel_control.clightningd/channel_control.hlightningd/peer_control.clightningd/test/run-invoice-select-inchan.cwallet/test/run-wallet.cInspect captured patch +21 / −8
diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c
index e37230ff..1d623088 100644
--- a/lightningd/channel_control.c
+++ b/lightningd/channel_control.c
@@ -803,14 +803,13 @@ static void handle_splice_sending_sigs(struct lightningd *ld,
}
bool depthcb_update_scid(struct channel *channel,
- const struct bitcoin_outpoint *outpoint)
+ const struct bitcoin_outpoint *outpoint,
+ const struct txlocator *loc)
{
- struct txlocator *loc;
struct lightningd *ld = channel->peer->ld;
struct short_channel_id scid;
/* What scid is this giving us? */
- loc = wallet_transaction_locate(tmpctx, ld->wallet, &outpoint->txid);
if (!mk_short_channel_id(&scid,
loc->blkheight, loc->index,
outpoint->n)) {
@@ -1141,6 +1140,7 @@ static void handle_peer_splice_locked(struct channel *channel, const u8 *msg)
struct channel_inflight *inflight;
struct bitcoin_txid locked_txid;
struct txwatch *txw;
+ struct txlocator *loc;
if (!fromwire_channeld_got_splice_locked(msg, &funding_sats,
&splice_amnt,
@@ -1185,7 +1185,9 @@ static void handle_peer_splice_locked(struct channel *channel, const u8 *msg)
wallet_channel_clear_inflights(channel->peer->ld->wallet, channel);
- depthcb_update_scid(channel, &inflight->funding->outpoint);
+ loc = wallet_transaction_locate(tmpctx, channel->peer->ld->wallet,
+ &inflight->funding->outpoint.txid);
+ depthcb_update_scid(channel, &inflight->funding->outpoint, loc);
/* That freed watchers in inflights: now watch funding tx */
channel_watch_funding(channel->peer->ld, channel);
diff --git a/lightningd/channel_control.h b/lightningd/channel_control.h
index 30774464..8eb1e118 100644
--- a/lightningd/channel_control.h
+++ b/lightningd/channel_control.h
@@ -56,5 +56,7 @@ void watch_splice_inflight(struct lightningd *ld,
/* Update/set scid now this outpoint is mined. */
bool depthcb_update_scid(struct channel *channel,
- const struct bitcoin_outpoint *outpoint);
+ const struct bitcoin_outpoint *outpoint,
+ const struct txlocator *loc);
+
#endif /* LIGHTNING_LIGHTNINGD_CHANNEL_CONTROL_H */
diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c
index 0f858525..d6393ffa 100644
--- a/lightningd/peer_control.c
+++ b/lightningd/peer_control.c
@@ -2312,6 +2312,8 @@ static enum watch_result funding_depth_cb(struct lightningd *ld,
unsigned int depth,
struct channel *channel)
{
+ struct txlocator *loc;
+
/* This is stub channel, we don't activate anything! */
if (channel->scid && is_stub_scid(*channel->scid))
return DELETE_WATCH;
@@ -2381,7 +2383,8 @@ static enum watch_result funding_depth_cb(struct lightningd *ld,
return KEEP_WATCHING;
}
- if (!depthcb_update_scid(channel, &channel->funding))
+ loc = wallet_transaction_locate(tmpctx, ld->wallet, &channel->funding.txid);
+ if (!depthcb_update_scid(channel, &channel->funding, loc))
return DELETE_WATCH;
switch (channel->state) {
diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c
index b8ddaa99..4dd160f3 100644
--- a/lightningd/test/run-invoice-select-inchan.c
+++ b/lightningd/test/run-invoice-select-inchan.c
@@ -246,7 +246,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_outpoint *outpoint UNNEEDED)
+ const struct bitcoin_outpoint *outpoint UNNEEDED,
+ const struct txlocator *loc UNNEEDED)
{ fprintf(stderr, "depthcb_update_scid called!\n"); abort(); }
/* Generated stub for dev_disconnect_permanent */
bool dev_disconnect_permanent(struct lightningd *ld UNNEEDED)
@@ -724,6 +725,10 @@ void wallet_transaction_add(struct wallet *w UNNEEDED, const struct wally_tx *tx
/* Generated stub for wallet_transaction_height */
u32 wallet_transaction_height(struct wallet *w UNNEEDED, const struct bitcoin_txid *txid UNNEEDED)
{ fprintf(stderr, "wallet_transaction_height called!\n"); abort(); }
+/* Generated stub for wallet_transaction_locate */
+struct txlocator *wallet_transaction_locate(const tal_t *ctx UNNEEDED, struct wallet *w UNNEEDED,
+ const struct bitcoin_txid *txid UNNEEDED)
+{ fprintf(stderr, "wallet_transaction_locate called!\n"); abort(); }
/* Generated stub for watch_opening_inflight */
void watch_opening_inflight(struct lightningd *ld UNNEEDED,
struct channel_inflight *inflight UNNEEDED)
diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c
index ce5e8b88..6913299c 100644
--- a/wallet/test/run-wallet.c
+++ b/wallet/test/run-wallet.c
@@ -244,7 +244,8 @@ u8 *create_channel_announcement(const tal_t *ctx UNNEEDED,
{ fprintf(stderr, "create_channel_announcement called!\n"); abort(); }
/* Generated stub for depthcb_update_scid */
bool depthcb_update_scid(struct channel *channel UNNEEDED,
- const struct bitcoin_outpoint *outpoint UNNEEDED)
+ const struct bitcoin_outpoint *outpoint UNNEEDED,
+ const struct txlocator *loc UNNEEDED)
{ fprintf(stderr, "depthcb_update_scid called!\n"); abort(); }
/* Generated stub for dev_disconnect_permanent */
bool dev_disconnect_permanent(struct lightningd *ld UNNEEDED)
Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.