From dd86e817b47cdc03dc80633f3a1c2c5254722059 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 31 Jan 2024 13:46:18 +1030 Subject: [PATCH] gossipd: tell lightningd its node_announcement on startup, if any. Signed-off-by: Rusty Russell --- gossipd/gossipd.c | 14 +++++++++++++- gossipd/gossipd_wire.csv | 5 +++++ lightningd/channel_gossip.c | 5 +++++ lightningd/gossip_control.c | 16 ++++++++++++++++ lightningd/lightningd.c | 1 + lightningd/lightningd.h | 5 ++++- 6 files changed, 44 insertions(+), 2 deletions(-) diff --git a/gossipd/gossipd.c b/gossipd/gossipd.c index 7505aa02d..5ffdaf069 100644 --- a/gossipd/gossipd.c +++ b/gossipd/gossipd.c @@ -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: diff --git a/gossipd/gossipd_wire.csv b/gossipd/gossipd_wire.csv index 1f6dfdc8e..7b6b4fc82 100644 --- a/gossipd/gossipd_wire.csv +++ b/gossipd/gossipd_wire.csv @@ -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. diff --git a/lightningd/channel_gossip.c b/lightningd/channel_gossip.c index dfbd7f7d5..32c4a9f5e 100644 --- a/lightningd/channel_gossip.c +++ b/lightningd/channel_gossip.c @@ -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, diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index 6c1996756..f0d065a0b 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -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; diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index ea1fc911e..85ad05260 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -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; diff --git a/lightningd/lightningd.h b/lightningd/lightningd.h index c0c1501ae..4d4f37e90 100644 --- a/lightningd/lightningd.h +++ b/lightningd/lightningd.h @@ -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;