gossipd: tell lightningd its node_announcement on startup, if any.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2024-01-31 13:46:18 +10:30
parent 48b9b6a05c
commit dd86e817b4
6 changed files with 44 additions and 2 deletions

View file

@ -633,6 +633,17 @@ static void tell_master_local_cupdates(struct daemon *daemon)
&c->scid,
cupdate)));
}
/* Tell lightningd about our current node_announcement, if any */
if (me->bcast.index) {
const u8 *nannounce;
nannounce = gossip_store_get(tmpctx,
daemon->rstate->gs,
me->bcast.index);
daemon_conn_send(daemon->master,
take(towire_gossipd_init_nannounce(NULL,
nannounce)));
}
}
struct peer *first_random_peer(struct daemon *daemon,
@ -721,7 +732,7 @@ static void gossip_init(struct daemon *daemon, const u8 *msg)
tal_add_destructor(daemon->connectd, master_or_connectd_gone);
/* Tell it about all our local (public) channel_update messages,
* so it doesn't unnecessarily regenerate them. */
* and node_announcement, so it doesn't unnecessarily regenerate them. */
tell_master_local_cupdates(daemon);
/* OK, we are ready. */
@ -967,6 +978,7 @@ static struct io_plan *recv_req(struct io_conn *conn,
/* We send these, we don't receive them */
case WIRE_GOSSIPD_INIT_CUPDATE:
case WIRE_GOSSIPD_INIT_NANNOUNCE:
case WIRE_GOSSIPD_INIT_REPLY:
case WIRE_GOSSIPD_GET_TXOUT:
case WIRE_GOSSIPD_DEV_MEMLEAK_REPLY:

View file

@ -24,6 +24,11 @@ msgdata,gossipd_init_cupdate,scid,short_channel_id,
msgdata,gossipd_init_cupdate,len,u16,
msgdata,gossipd_init_cupdate,cupdate,u8,len
# Gossipd tells us our node_announcement before init_reply.
msgtype,gossipd_init_nannounce,3102
msgdata,gossipd_init_nannounce,len,u16,
msgdata,gossipd_init_nannounce,nannounce,u8,len
msgtype,gossipd_init_reply,3100
# In developer mode, we can mess with time.

1 #include <common/cryptomsg.h>
24 msgtype,gossipd_init_reply,3100 # Gossipd tells us our node_announcement before init_reply.
25 # In developer mode, we can mess with time. msgtype,gossipd_init_nannounce,3102
26 msgtype,gossipd_dev_set_time,3001 msgdata,gossipd_init_nannounce,len,u16,
27 msgdata,gossipd_init_nannounce,nannounce,u8,len
28 msgtype,gossipd_init_reply,3100
29 # In developer mode, we can mess with time.
30 msgtype,gossipd_dev_set_time,3001
31 msgdata,gossipd_dev_set_time,dev_gossip_time,u32,
32 msgdata,gossipd_dev_set_time,dev_gossip_time,u32, # Set artificial maximum reply_channel_range size. Master->gossipd
33 # Set artificial maximum reply_channel_range size. Master->gossipd msgtype,gossipd_dev_set_max_scids_encode_size,3030
34 msgtype,gossipd_dev_set_max_scids_encode_size,3030 msgdata,gossipd_dev_set_max_scids_encode_size,max,u32,

View file

@ -1032,6 +1032,11 @@ void channel_gossip_node_announce(struct lightningd *ld)
nannounce = unsigned_node_announcement(tmpctx, ld);
/* Don't bother with duplicates */
if (ld->node_announcement
&& node_announcement_same(ld->node_announcement, nannounce))
return;
/* Ask hsmd to sign it (synchronous) */
msg = hsm_sync_req(tmpctx, ld,
take(towire_hsmd_node_announcement_sig_req(NULL,

View file

@ -138,6 +138,19 @@ static void handle_init_cupdate(struct lightningd *ld, const u8 *msg)
channel_gossip_update_from_gossipd(channel, take(update));
}
static void handle_init_nannounce(struct lightningd *ld, const u8 *msg)
{
u8 *nannounce;
if (!fromwire_gossipd_init_nannounce(ld, msg, &nannounce)) {
fatal("Gossip gave bad GOSSIPD_INIT_NANNOUNCE %s",
tal_hex(msg, msg));
}
assert(!ld->node_announcement);
ld->node_announcement = nannounce;
}
static void handle_peer_update_data(struct lightningd *ld, const u8 *msg)
{
struct peer_update update;
@ -180,6 +193,9 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
case WIRE_GOSSIPD_INIT_CUPDATE:
handle_init_cupdate(gossip->ld, msg);
break;
case WIRE_GOSSIPD_INIT_NANNOUNCE:
handle_init_nannounce(gossip->ld, msg);
break;
case WIRE_GOSSIPD_GET_TXOUT:
get_txout(gossip, msg);
break;

View file

@ -237,6 +237,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
ld->announce_dns = false;
ld->lease_rates = NULL;
ld->node_announcement = NULL;
ld->remote_addr_v4 = NULL;
ld->remote_addr_v6 = NULL;
ld->discovered_ip_v4 = NULL;

View file

@ -183,10 +183,13 @@ struct lightningd {
/* Setup: And the bitset for each, whether to listen, announce or both */
enum addr_listen_announce *proposed_listen_announce;
/* Actual bindings and announceables from gossipd */
/* Actual bindings and announceables from connectd */
struct wireaddr_internal *binding;
struct wireaddr *announceable;
/* Current node announcement (if any) */
const u8 *node_announcement;
/* Lease rates to advertize, set by json_setleaserates */
struct lease_rates *lease_rates;