diff --git a/connectd/connectd_wire.csv b/connectd/connectd_wire.csv index 7af157794..39506d8ae 100644 --- a/connectd/connectd_wire.csv +++ b/connectd/connectd_wire.csv @@ -79,7 +79,7 @@ msgdata,connectd_peer_disconnect_done,id,node_id, # Master -> connectd: make peer active immediately (we want to talk) msgtype,connectd_peer_make_active,2004 msgdata,connectd_peer_make_active,id,node_id, -msgdata,connectd_peer_make_active,channel_id,?channel_id, +msgdata,connectd_peer_make_active,channel_id,channel_id, # Connectd -> master: peer said something interesting (or you said make_active) # Plus fd for peer daemon. diff --git a/connectd/multiplex.c b/connectd/multiplex.c index eb384acee..dbc6014e6 100644 --- a/connectd/multiplex.c +++ b/connectd/multiplex.c @@ -440,9 +440,9 @@ void peer_make_active(struct daemon *daemon, const u8 *msg) { struct node_id id; struct peer *peer; - struct channel_id *channel_id; + struct channel_id channel_id; - if (!fromwire_connectd_peer_make_active(msg, msg, &id, &channel_id)) + if (!fromwire_connectd_peer_make_active(msg, &id, &channel_id)) master_badmsg(WIRE_CONNECTD_PEER_MAKE_ACTIVE, msg); /* Races can happen: this might be gone by now. */ @@ -458,7 +458,7 @@ void peer_make_active(struct daemon *daemon, const u8 *msg) if (tal_count(peer->subds) != 0) return; - if (!activate_peer(peer, NULL, channel_id)) + if (!activate_peer(peer, NULL, &channel_id)) tal_free(peer); } diff --git a/lightningd/channel.c b/lightningd/channel.c index 23bd3ae17..640c3f390 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -235,7 +235,6 @@ struct channel *new_unsaved_channel(struct peer *peer, "chan#%"PRIu64, channel->unsaved_dbid); - memset(&channel->cid, 0xFF, sizeof(channel->cid)); channel->our_config.id = 0; channel->open_attempt = NULL; diff --git a/lightningd/dual_open_control.c b/lightningd/dual_open_control.c index c2a498451..a968409f7 100644 --- a/lightningd/dual_open_control.c +++ b/lightningd/dual_open_control.c @@ -2595,6 +2595,11 @@ static struct command_result *json_openchannel_init(struct command *cmd, channel = new_unsaved_channel(peer, peer->ld->config.fee_base, peer->ld->config.fee_per_satoshi); + + /* We derive initial channel_id *now*, so we can tell it to + * connectd. */ + derive_tmp_channel_id(&channel->cid, + &channel->local_basepoints.revocation); } if (channel->open_attempt @@ -2688,7 +2693,7 @@ static struct command_result *json_openchannel_init(struct command *cmd, /* Tell connectd to hand us this so we can start dualopend */ subd_send_msg(peer->ld->connectd, take(towire_connectd_peer_make_active(NULL, &peer->id, - NULL))); + &channel->cid))); return command_still_pending(cmd); } @@ -3099,6 +3104,11 @@ static struct command_result *json_queryrates(struct command *cmd, channel = new_unsaved_channel(peer, peer->ld->config.fee_base, peer->ld->config.fee_per_satoshi); + + /* We derive initial channel_id *now*, so we can tell it to + * connectd. */ + derive_tmp_channel_id(&channel->cid, + &channel->local_basepoints.revocation); } if (channel->open_attempt @@ -3167,7 +3177,7 @@ static struct command_result *json_queryrates(struct command *cmd, /* Tell connectd to hand us this so we can start dualopend */ subd_send_msg(peer->ld->connectd, take(towire_connectd_peer_make_active(NULL, &peer->id, - NULL))); + &channel->cid))); return command_still_pending(cmd); } diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 6c99ada1f..832009e9c 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -1079,6 +1079,7 @@ static struct command_result *json_fundchannel_start(struct command *cmd, struct amount_sat *amount; struct amount_msat *push_msat; u32 *upfront_shutdown_script_wallet_index; + struct channel_id tmp_channel_id; fc->cmd = cmd; fc->cancels = tal_arr(fc, struct command *, 0); @@ -1207,6 +1208,8 @@ 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, @@ -1214,12 +1217,13 @@ static struct command_result *json_fundchannel_start(struct command *cmd, fc->our_upfront_shutdown_script, upfront_shutdown_script_wallet_index, *feerate_per_kw, + &tmp_channel_id, fc->channel_flags); /* Tell connectd to make this active; when it does, we can continue */ subd_send_msg(peer->ld->connectd, take(towire_connectd_peer_make_active(NULL, &peer->id, - NULL))); + &tmp_channel_id))); return command_still_pending(cmd); } diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 4a8d20654..99a6e84be 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1374,6 +1374,7 @@ void peer_active(struct lightningd *ld, const u8 *msg, int fd) channel = new_unsaved_channel(peer, peer->ld->config.fee_base, peer->ld->config.fee_per_satoshi); + channel->cid = *channel_id; peer_start_dualopend(peer, peer_fd, channel); } else { peer->uncommitted_channel = new_uncommitted_channel(peer); diff --git a/openingd/openingd.c b/openingd/openingd.c index 040168083..0b4ca5f13 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -240,10 +240,6 @@ static bool setup_channel_funder(struct state *state) * could do it for the we-are-funding case. */ set_reserve(state, state->localconf.dust_limit); - /*~ Grab a random ID until the funding tx is created (we can't do that - * until we know their funding_pubkey) */ - temporary_channel_id(&state->channel_id); - #if DEVELOPER /* --dev-force-tmp-channel-id specified */ if (dev_force_tmp_channel_id) @@ -1308,6 +1304,7 @@ static u8 *handle_master_in(struct state *state) &state->upfront_shutdown_script[LOCAL], &state->local_upfront_shutdown_wallet_index, &state->feerate_per_kw, + &state->channel_id, &channel_flags)) master_badmsg(WIRE_OPENINGD_FUNDER_START, msg); msg = funder_channel_start(state, channel_flags); diff --git a/openingd/openingd_wire.csv b/openingd/openingd_wire.csv index ee90e0894..a759e1a4f 100644 --- a/openingd/openingd_wire.csv +++ b/openingd/openingd_wire.csv @@ -77,6 +77,7 @@ msgdata,openingd_funder_start,len_upfront,u16, msgdata,openingd_funder_start,upfront_shutdown_script,u8,len_upfront msgdata,openingd_funder_start,upfront_shutdown_wallet_index,?u32, msgdata,openingd_funder_start,feerate_per_kw,u32, +msgdata,openingd_funder_start,temporary_channel_id,channel_id, msgdata,openingd_funder_start,channel_flags,u8, # openingd->master: send back output script for 2-of-2 funding output