Skip to content

Commit c5fc1b5

Browse files
committed
lightningd: make sure channels always have a local alias.
If we pull and old channel from the database, it might not. Fixes: #7645 Changelog-Fixes: lightningd: crash when starting channeld for older channel with no local alias. Signed-off-by: Rusty Russell <[email protected]>
1 parent 2bd9c22 commit c5fc1b5

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lightningd/channel.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,11 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
513513
channel->remote_channel_ready = remote_channel_ready;
514514
channel->scid = tal_steal(channel, scid);
515515
channel->alias[LOCAL] = tal_dup_or_null(channel, struct short_channel_id, alias_local);
516+
/* We always make sure this is set (historical channels from db might not) */
517+
if (!channel->alias[LOCAL]) {
518+
channel->alias[LOCAL] = tal(channel, struct short_channel_id);
519+
randombytes_buf(channel->alias[LOCAL], sizeof(struct short_channel_id));
520+
}
516521
channel->alias[REMOTE] = tal_steal(channel, alias_remote); /* Haven't gotten one yet. */
517522
channel->cid = *cid;
518523
channel->our_msat = our_msat;

lightningd/opening_control.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <lightningd/plugin_hook.h>
2929
#include <lightningd/subd.h>
3030
#include <openingd/openingd_wiregen.h>
31-
#include <sodium/randombytes.h>
3231
#include <wally_psbt.h>
3332

3433
void json_add_uncommitted_channel(struct command *cmd,
@@ -108,7 +107,6 @@ wallet_commit_channel(struct lightningd *ld,
108107
s64 final_key_idx;
109108
u64 static_remotekey_start;
110109
u32 lease_start_blockheight = 0; /* No leases on v1 */
111-
struct short_channel_id local_alias;
112110
struct timeabs timestamp;
113111
bool any_active = peer_any_channel(uc->peer, channel_state_wants_peercomms, NULL);
114112

@@ -158,9 +156,6 @@ wallet_commit_channel(struct lightningd *ld,
158156
else
159157
static_remotekey_start = 0x7FFFFFFFFFFFFFFF;
160158

161-
/* This won't clash, we don't even bother checking */
162-
randombytes_buf(&local_alias, sizeof(local_alias));
163-
164159
channel = new_channel(uc->peer, uc->dbid,
165160
NULL, /* No shachain yet */
166161
CHANNELD_AWAITING_LOCKIN,
@@ -178,7 +173,7 @@ wallet_commit_channel(struct lightningd *ld,
178173
local_funding,
179174
false, /* !remote_channel_ready */
180175
NULL, /* no scid yet */
181-
&local_alias,
176+
NULL, /* assign random local alias */
182177
NULL, /* They haven't told us an alias yet */
183178
cid,
184179
/* The three arguments below are msatoshi_to_us,

0 commit comments

Comments
 (0)