lightningd: set channel's local alias at init.

Rather than having channeld/dualopend do it, we can set it and tell them.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2024-01-31 13:46:17 +10:30
parent 9c80a5cebb
commit dac8964093
8 changed files with 39 additions and 29 deletions

View File

@ -139,6 +139,9 @@ struct peer {
/* Which direction of the channel do we control? */
u16 channel_direction;
/* Local scid alias */
struct short_channel_id local_alias;
/* The scriptpubkey to use for shutting down. */
u32 *final_index;
struct ext_key *final_ext_key;
@ -5272,6 +5275,7 @@ static void peer_reconnect(struct peer *peer,
&& next_commitment_number == 1) {
struct tlv_channel_ready_tlvs *tlvs = tlv_channel_ready_tlvs_new(tmpctx);
tlvs->short_channel_id = &peer->local_alias;
status_debug("Retransmitting channel_ready for channel %s",
type_to_string(tmpctx, struct channel_id, &peer->channel_id));
/* Contains per commit point #1, for first post-opening commit */
@ -5554,7 +5558,7 @@ static void peer_reconnect(struct peer *peer,
static void handle_funding_depth(struct peer *peer, const u8 *msg)
{
u32 depth;
struct short_channel_id *scid, *alias_local;
struct short_channel_id *scid;
struct tlv_channel_ready_tlvs *tlvs;
struct pubkey point;
bool splicing;
@ -5563,7 +5567,6 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg)
if (!fromwire_channeld_funding_depth(tmpctx,
msg,
&scid,
&alias_local,
&depth,
&splicing,
&txid))
@ -5594,15 +5597,15 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg)
status_debug("handle_funding_depth: Setting short_channel_ids[LOCAL] to %s",
type_to_string(tmpctx,
struct short_channel_id,
(scid ? scid : alias_local)));
(scid ? scid : &peer->local_alias)));
/* If we know an actual short_channel_id prefer to use
* that, otherwise fill in the alias. From channeld's
* point of view switching from zeroconf to an actual
* funding scid is just a reorg. */
if (scid)
peer->short_channel_ids[LOCAL] = *scid;
else if (alias_local)
peer->short_channel_ids[LOCAL] = *alias_local;
else
peer->short_channel_ids[LOCAL] = peer->local_alias;
}
if (!peer->channel_ready[LOCAL]) {
@ -5612,7 +5615,7 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg)
type_to_string(tmpctx, struct pubkey,
&peer->next_local_per_commit));
tlvs = tlv_channel_ready_tlvs_new(tmpctx);
tlvs->short_channel_id = alias_local;
tlvs->short_channel_id = &peer->local_alias;
/* Need to retrieve the first point again, even if we
* moved on, as channel_ready explicitly includes the
@ -6166,7 +6169,8 @@ static void init_channel(struct peer *peer)
&pbases,
&reestablish_only,
&peer->experimental_upgrade,
&peer->splice_state->inflights)) {
&peer->splice_state->inflights,
&peer->local_alias)) {
master_badmsg(WIRE_CHANNELD_INIT, msg);
}

View File

@ -81,13 +81,12 @@ msgdata,channeld_init,reestablish_only,bool,
msgdata,channeld_init,experimental_upgrade,bool,
msgdata,channeld_init,num_inflights,u16,
msgdata,channeld_init,inflights,inflight,num_inflights
msgdata,channeld_init,scid_alias,short_channel_id,
# master->channeld funding hit new depth(funding locked if >= lock depth)
# alias != NULL if zeroconf and short_channel_id == NULL
# short_channel_id != NULL once we have 3+ confirmations
msgtype,channeld_funding_depth,1002
msgdata,channeld_funding_depth,short_channel_id,?short_channel_id,
msgdata,channeld_funding_depth,alias_local,?short_channel_id,
msgdata,channeld_funding_depth,depth,u32,
msgdata,channeld_funding_depth,splicing,bool,
msgdata,channeld_funding_depth,txid,bitcoin_txid,

Can't render this file because it has a wrong number of fields in line 15.

View File

@ -17,6 +17,7 @@
#include <lightningd/opening_common.h>
#include <lightningd/peer_control.h>
#include <lightningd/subd.h>
#include <sodium/randombytes.h>
#include <wallet/txfilter.h>
#include <wire/peer_wire.h>
@ -278,7 +279,10 @@ struct channel *new_unsaved_channel(struct peer *peer,
channel->closing_feerate_range = NULL;
channel->peer_update = NULL;
channel->channel_update = NULL;
channel->alias[LOCAL] = channel->alias[REMOTE] = NULL;
channel->alias[REMOTE] = NULL;
/* We don't even bother checking for clashes. */
channel->alias[LOCAL] = tal(channel, struct short_channel_id);
randombytes_buf(channel->alias[LOCAL], sizeof(struct short_channel_id));
channel->shutdown_scriptpubkey[REMOTE] = NULL;
channel->last_was_revoke = false;
@ -397,7 +401,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
bool remote_channel_ready,
/* NULL or stolen */
struct short_channel_id *scid,
struct short_channel_id *alias_local STEALS,
struct short_channel_id *alias_local TAKES,
struct short_channel_id *alias_remote STEALS,
struct channel_id *cid,
struct amount_msat our_msat,
@ -508,7 +512,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
channel->our_funds = our_funds;
channel->remote_channel_ready = remote_channel_ready;
channel->scid = tal_steal(channel, scid);
channel->alias[LOCAL] = tal_steal(channel, alias_local);
channel->alias[LOCAL] = tal_dup_or_null(channel, struct short_channel_id, alias_local);
channel->alias[REMOTE] = tal_steal(channel, alias_remote); /* Haven't gotten one yet. */
channel->cid = *cid;
channel->our_msat = our_msat;

View File

@ -594,7 +594,6 @@ static enum watch_result splice_depth_cb(struct lightningd *ld,
subd_send_msg(inflight->channel->owner,
take(towire_channeld_funding_depth(
NULL, &scid,
inflight->channel->alias[LOCAL],
depth, true, txid)));
}
@ -1700,7 +1699,8 @@ bool peer_start_channeld(struct channel *channel,
reestablish_only,
ld->experimental_upgrade_protocol,
cast_const2(const struct inflight **,
inflights));
inflights),
channel->alias[LOCAL]);
/* We don't expect a response: we are triggered by funding_depth_cb. */
subd_send_msg(channel->owner, take(initmsg));
@ -1719,7 +1719,7 @@ bool peer_start_channeld(struct channel *channel,
/* Artificial confirmation event for zeroconf */
subd_send_msg(channel->owner,
take(towire_channeld_funding_depth(
NULL, channel->scid, channel->alias[LOCAL], 0, false,
NULL, channel->scid, 0, false,
&txid)));
return true;
}
@ -1742,7 +1742,7 @@ void channeld_tell_depth(struct channel *channel,
subd_send_msg(channel->owner,
take(towire_channeld_funding_depth(
NULL, channel->scid, channel->alias[LOCAL], depth,
NULL, channel->scid, depth,
false, txid)));
}

View File

@ -33,7 +33,6 @@
#include <lightningd/peer_fd.h>
#include <lightningd/plugin_hook.h>
#include <openingd/dualopend_wiregen.h>
#include <sodium/randombytes.h>
struct commit_rcvd {
struct channel *channel;
@ -1465,12 +1464,6 @@ wallet_commit_channel(struct lightningd *ld,
= p2tr_for_keyidx(channel, channel->peer->ld,
channel->final_key_idx);
/* Can't have gotten their alias for this channel yet. */
channel->alias[REMOTE] = NULL;
/* We do generate one ourselves however. */
channel->alias[LOCAL] = tal(channel, struct short_channel_id);
randombytes_buf(channel->alias[LOCAL], sizeof(struct short_channel_id));
channel->remote_upfront_shutdown_script
= tal_steal(channel, remote_upfront_shutdown_script);
@ -4055,6 +4048,7 @@ bool peer_start_dualopend(struct peer *peer,
&channel->local_funding_pubkey,
channel->minimum_depth,
peer->ld->config.require_confirmed_inputs,
channel->alias[LOCAL],
peer->ld->dev_any_channel_type);
subd_send_msg(channel->owner, take(msg));
return true;
@ -4168,7 +4162,8 @@ bool peer_restart_dualopend(struct peer *peer,
NULL : &inflight->lease_amt,
channel->type,
channel->req_confirmed_ins[LOCAL],
channel->req_confirmed_ins[REMOTE]);
channel->req_confirmed_ins[REMOTE],
channel->alias[LOCAL]);
subd_send_msg(channel->owner, take(msg));
return true;

View File

@ -112,7 +112,7 @@ 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 short_channel_id local_alias;
struct timeabs timestamp;
bool any_active = peer_any_channel(uc->peer, channel_state_wants_peercomms, NULL);
@ -174,8 +174,8 @@ 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));
/* This won't clash, we don't even bother checking */
randombytes_buf(&local_alias, sizeof(local_alias));
channel = new_channel(uc->peer, uc->dbid,
NULL, /* No shachain yet */
@ -194,7 +194,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? */
&local_alias,
NULL, /* They haven't told us an alias yet */
cid,
/* The three arguments below are msatoshi_to_us,

View File

@ -227,6 +227,9 @@ struct state {
/* Does this negotation require confirmed inputs? */
bool require_confirmed_inputs[NUM_SIDES];
/* Our alias */
struct short_channel_id local_alias;
bool dev_accept_any_channel_type;
};
@ -3869,6 +3872,7 @@ static void send_channel_ready(struct state *state)
/* Figure out the next local commit */
hsm_per_commitment_point(1, &next_local_per_commit);
tlvs->short_channel_id = &state->local_alias;
msg = towire_channel_ready(NULL, &state->channel_id,
&next_local_per_commit, tlvs);
peer_write(state->pps, take(msg));
@ -4382,6 +4386,7 @@ int main(int argc, char *argv[])
&state->our_funding_pubkey,
&state->minimum_depth,
&state->require_confirmed_inputs[LOCAL],
&state->local_alias,
&state->dev_accept_any_channel_type)) {
/*~ Initially we're not associated with a channel, but
* handle_peer_gossip_or_error compares this. */
@ -4446,7 +4451,8 @@ int main(int argc, char *argv[])
&requested_lease,
&state->channel_type,
&state->require_confirmed_inputs[LOCAL],
&state->require_confirmed_inputs[REMOTE])) {
&state->require_confirmed_inputs[REMOTE],
&state->local_alias)) {
bool ok;

View File

@ -29,6 +29,7 @@ msgdata,dualopend_init,our_funding_pubkey,pubkey,
# Constraints in case the other end tries to open a channel.
msgdata,dualopend_init,minimum_depth,u32,
msgdata,dualopend_init,require_confirmed_inputs,bool,
msgdata,dualopend_init,local_alias,short_channel_id,
msgdata,dualopend_init,dev_accept_any_channel_type,bool,
# master-dualopend: peer has reconnected
@ -77,6 +78,7 @@ msgdata,dualopend_reinit,requested_lease,?amount_sat,
msgdata,dualopend_reinit,channel_type,channel_type,
msgdata,dualopend_reinit,we_require_confirmed_inputs,bool,
msgdata,dualopend_reinit,they_require_confirmed_inputs,bool,
msgdata,dualopend_reinit,local_alias,short_channel_id,
# dualopend->master: they offered channel, should we continue?
msgtype,dualopend_got_offer,7005

Can't render this file because it has a wrong number of fields in line 16.