From 0b4d567f53e473b861679e9002ec54d1c52a84e8 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 13 Sep 2024 11:59:18 +0930 Subject: [PATCH] lightningd: make sure non-stub channels always have a local alias. If we pull and old channel from the database, it might not. Fixes: https://github.com/ElementsProject/lightning/issues/7645 Changelog-Fixes: lightningd: crash when starting channeld for older channel with no local alias. Signed-off-by: Rusty Russell --- lightningd/channel.c | 6 ++++++ lightningd/opening_control.c | 6 +----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lightningd/channel.c b/lightningd/channel.c index 6c02905e42a0..4f516057cb3e 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -444,6 +445,11 @@ struct channel *new_channel(struct peer *peer, u64 dbid, channel->remote_channel_ready = remote_channel_ready; channel->scid = tal_steal(channel, scid); channel->alias[LOCAL] = tal_steal(channel, alias_local); + /* We always make sure this is set */ + if (!channel->alias[LOCAL]) { + channel->alias[LOCAL] = tal(channel, struct short_channel_id); + randombytes_buf(channel->alias[LOCAL], sizeof(struct short_channel_id)); + } channel->alias[REMOTE] = tal_steal(channel, alias_remote); /* Haven't gotten one yet. */ channel->cid = *cid; channel->our_msat = our_msat; diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index dece107cbeb4..2b022e2eec71 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -104,7 +104,6 @@ wallet_commit_channel(struct lightningd *ld, s64 final_key_idx; u64 static_remotekey_start; u32 lease_start_blockheight = 0; /* No leases on v1 */ - struct short_channel_id *alias_local; struct timeabs timestamp; bool any_active = peer_any_active_channel(uc->peer, NULL); @@ -166,9 +165,6 @@ wallet_commit_channel(struct lightningd *ld, else static_remotekey_start = 0x7FFFFFFFFFFFFFFF; - alias_local = tal(NULL, struct short_channel_id); - randombytes_buf(alias_local, sizeof(struct short_channel_id)); - channel = new_channel(uc->peer, uc->dbid, NULL, /* No shachain yet */ CHANNELD_AWAITING_LOCKIN, @@ -186,7 +182,7 @@ wallet_commit_channel(struct lightningd *ld, local_funding, false, /* !remote_channel_ready */ NULL, /* no scid yet */ - alias_local, /* But maybe we have an alias we want to use? */ + NULL, /* Will assign random alias */ NULL, /* They haven't told us an alias yet */ cid, /* The three arguments below are msatoshi_to_us,