zeroconf: Add alias_remote and alias_local to channel and DB

`alias_local` is generated locally and sent to the peer so it knows
what we're calling the channel, while `alias_remote` is received by
the peer so we know what to include in routehints when generating
invoices.
This commit is contained in:
Christian Decker
2022-04-22 12:57:01 +02:00
parent 9d3cb95489
commit de1c0b51f0
7 changed files with 71 additions and 4 deletions

View File

@@ -352,6 +352,8 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
bool remote_funding_locked,
/* NULL or stolen */
struct short_channel_id *scid,
struct short_channel_id *alias_local STEALS,
struct short_channel_id *alias_remote STEALS,
struct channel_id *cid,
struct amount_msat our_msat,
struct amount_msat msat_to_us_min,
@@ -437,6 +439,8 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
channel->our_funds = our_funds;
channel->remote_funding_locked = remote_funding_locked;
channel->scid = tal_steal(channel, scid);
channel->alias[LOCAL] = tal_steal(channel, alias_local);
channel->alias[REMOTE] = tal_steal(channel, alias_remote); /* Haven't gotten one yet. */
channel->cid = *cid;
channel->our_msat = our_msat;
channel->msat_to_us_min = msat_to_us_min;

View File

@@ -135,6 +135,12 @@ struct channel {
/* Channel if locked locally. */
struct short_channel_id *scid;
/* Alias used for option_zeroconf, or option_scid_alias, if
* present. LOCAL are all the alias we told the peer about and
* REMOTE is one of the aliases we got from the peer and we'll
* use in a routehint. */
struct short_channel_id *alias[NUM_SIDES];
struct channel_id cid;
/* Amount going to us, not counting unfinished HTLCs; if we have one. */
@@ -278,6 +284,8 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
bool remote_funding_locked,
/* NULL or stolen */
struct short_channel_id *scid STEALS,
struct short_channel_id *alias_local STEALS,
struct short_channel_id *alias_remote STEALS,
struct channel_id *cid,
struct amount_msat our_msatoshi,
struct amount_msat msatoshi_to_us_min,

View File

@@ -33,6 +33,7 @@
#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;
@@ -1239,6 +1240,12 @@ wallet_commit_channel(struct lightningd *ld,
= p2wpkh_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);

View File

@@ -29,6 +29,7 @@
#include <lightningd/plugin_hook.h>
#include <lightningd/subd.h>
#include <openingd/openingd_wiregen.h>
#include <sodium/randombytes.h>
#include <wally_psbt.h>
void json_add_uncommitted_channel(struct json_stream *response,
@@ -99,6 +100,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;
/* We cannot both be the fundee *and* have a `fundchannel_start`
* command running!
@@ -158,6 +160,9 @@ 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));
channel = new_channel(uc->peer, uc->dbid,
NULL, /* No shachain yet */
CHANNELD_AWAITING_LOCKIN,
@@ -174,6 +179,8 @@ wallet_commit_channel(struct lightningd *ld,
local_funding,
false, /* !remote_funding_locked */
NULL, /* no scid yet */
alias_local, /* But maybe we have an alias we want to use? */
NULL, /* They haven't told us an alias yet */
cid,
/* The three arguments below are msatoshi_to_us,
* msatoshi_to_us_min, and msatoshi_to_us_max.