From 08e3e979c8c5f6926f2b97255981159547f7216c Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 16 Jul 2022 14:19:29 +0930 Subject: [PATCH] lightningd: set cid correctly in peer->uncommitted_channel. Setting it to 0xfffff... is just confusing. Signed-off-by: Rusty Russell --- lightningd/opening_common.c | 2 -- lightningd/opening_common.h | 2 +- lightningd/opening_control.c | 6 ++++-- lightningd/peer_control.c | 1 + 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lightningd/opening_common.c b/lightningd/opening_common.c index 866f135de..f3c455e92 100644 --- a/lightningd/opening_common.c +++ b/lightningd/opening_common.c @@ -61,8 +61,6 @@ new_uncommitted_channel(struct peer *peer) */ uc->minimum_depth = ld->config.anchor_confirms; - memset(&uc->cid, 0xFF, sizeof(uc->cid)); - /* Declare the new channel to the HSM. */ new_channel_msg = towire_hsmd_new_channel(NULL, &uc->peer->id, uc->dbid); if (!wire_sync_write(ld->hsm_fd, take(new_channel_msg))) diff --git a/lightningd/opening_common.h b/lightningd/opening_common.h index 8d1b1c490..50a236c50 100644 --- a/lightningd/opening_common.h +++ b/lightningd/opening_common.h @@ -28,7 +28,7 @@ struct uncommitted_channel { /* Reserved dbid for if we become a real struct channel */ u64 dbid; - /* Channel id, v2 opens only */ + /* Channel id (temporary!) */ struct channel_id cid; /* For logging */ diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index a89092370..987f82a1c 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -1142,6 +1142,8 @@ static struct command_result *json_fundchannel_start(struct command *cmd, return command_fail(cmd, FUNDING_PEER_NOT_CONNECTED, "Peer not connected"); + temporary_channel_id(&tmp_channel_id); + if (!peer->uncommitted_channel) { if (feature_negotiated(cmd->ld->our_features, peer->their_features, @@ -1168,6 +1170,8 @@ static struct command_result *json_fundchannel_start(struct command *cmd, "peer"); } + peer->uncommitted_channel->cid = tmp_channel_id; + /* BOLT #2: * - if both nodes advertised `option_support_large_channel`: * - MAY set `funding_satoshis` greater than or equal to 2^24 satoshi. @@ -1220,8 +1224,6 @@ static struct command_result *json_fundchannel_start(struct command *cmd, } else upfront_shutdown_script_wallet_index = NULL; - temporary_channel_id(&tmp_channel_id); - fc->open_msg = towire_openingd_funder_start(fc, *amount, diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index a510dbcfa..f8d281ec2 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1339,6 +1339,7 @@ void peer_active(struct lightningd *ld, const u8 *msg, int fd) goto send_error; } peer->uncommitted_channel = new_uncommitted_channel(peer); + peer->uncommitted_channel->cid = channel_id; peer_start_openingd(peer, peer_fd); break; case WIRE_OPEN_CHANNEL2: