From b9817d395fad5ed6c32ff573a5b5a069d9f336fb Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 22 Apr 2022 16:15:49 +0200 Subject: [PATCH] zeroconf: Wire the aliases through `channeld` --- channeld/channeld.c | 24 ++++++++++++++++-------- channeld/channeld_wire.csv | 4 ++++ lightningd/channel_control.c | 17 ++++++++++------- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/channeld/channeld.c b/channeld/channeld.c index 336f849bb..5b543ee45 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -617,9 +617,15 @@ static void handle_peer_funding_locked(struct peer *peer, const u8 *msg) peer->tx_sigs_allowed = false; peer->funding_locked[REMOTE] = true; + if (tlvs->alias != NULL) { + status_debug( + "Peer told us that they'll use alias=%s for this channel", + type_to_string(tmpctx, struct short_channel_id, + tlvs->alias)); + } wire_sync_write(MASTER_FD, - take(towire_channeld_got_funding_locked(NULL, - &peer->remote_per_commit))); + take(towire_channeld_got_funding_locked( + NULL, &peer->remote_per_commit, tlvs->alias))); channel_announcement_negotiate(peer); billboard_update(peer); @@ -3208,12 +3214,14 @@ skip_tlvs: static void handle_funding_depth(struct peer *peer, const u8 *msg) { u32 depth; - struct short_channel_id *scid; + struct short_channel_id *scid, *alias_local; + struct tlv_funding_locked_tlvs *tlvs; if (!fromwire_channeld_funding_depth(tmpctx, - msg, - &scid, - &depth)) + msg, + &scid, + &alias_local, + &depth)) master_badmsg(WIRE_CHANNELD_FUNDING_DEPTH, msg); /* Too late, we're shutting down! */ @@ -3235,8 +3243,8 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg) peer->next_index[LOCAL], type_to_string(tmpctx, struct pubkey, &peer->next_local_per_commit)); - struct tlv_funding_locked_tlvs *tlvs = - tlv_funding_locked_tlvs_new(tmpctx); + tlvs = tlv_funding_locked_tlvs_new(tmpctx); + tlvs->alias = alias_local; msg = towire_funding_locked( NULL, &peer->channel_id, diff --git a/channeld/channeld_wire.csv b/channeld/channeld_wire.csv index b2179908b..31d8237a2 100644 --- a/channeld/channeld_wire.csv +++ b/channeld/channeld_wire.csv @@ -85,8 +85,11 @@ msgdata,channeld_init,channel_update_len,u16, msgdata,channeld_init,channel_update,u8,channel_update_len # 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, # Tell channel to offer this htlc @@ -117,6 +120,7 @@ msgdata,channeld_fail_htlc,failed_htlc,failed_htlc, # When we receive funding_locked. msgtype,channeld_got_funding_locked,1019 msgdata,channeld_got_funding_locked,next_per_commit_point,pubkey, +msgdata,channeld_got_funding_locked,alias,?short_channel_id, #include diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index 9c73949de..009eceafb 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -230,9 +230,10 @@ bool channel_on_funding_locked(struct channel *channel, static void peer_got_funding_locked(struct channel *channel, const u8 *msg) { struct pubkey next_per_commitment_point; + struct short_channel_id *alias_remote; - if (!fromwire_channeld_got_funding_locked(msg, - &next_per_commitment_point)) { + if (!fromwire_channeld_got_funding_locked(tmpctx, + msg, &next_per_commitment_point, &alias_remote)) { channel_internal_error(channel, "bad channel_got_funding_locked %s", tal_hex(channel, msg)); @@ -242,11 +243,13 @@ static void peer_got_funding_locked(struct channel *channel, const u8 *msg) if (!channel_on_funding_locked(channel, &next_per_commitment_point)) return; + if (channel->alias[REMOTE] == NULL) + channel->alias[REMOTE] = tal_steal(channel, alias_remote); + + /* Remember that we got the lockin */ + wallet_channel_save(channel->peer->ld->wallet, channel); if (channel->scid) lockin_complete(channel); - else - /* Remember that we got the lockin */ - wallet_channel_save(channel->peer->ld->wallet, channel); } static void peer_got_announcement(struct channel *channel, const u8 *msg) @@ -823,8 +826,8 @@ bool channel_tell_depth(struct lightningd *ld, } subd_send_msg(channel->owner, - take(towire_channeld_funding_depth(NULL, channel->scid, - depth))); + take(towire_channeld_funding_depth( + NULL, channel->scid, channel->alias[LOCAL], depth))); if (channel->remote_funding_locked && channel->state == CHANNELD_AWAITING_LOCKIN