gossipd: don't tell connectd what address to connect to.

In fact, only 951 of 17419 (5%) of node announcements are missing an address
(and gossipd doesn't know if we can connect to Tor addresses anyway) so
just check it *has* a node_announcement.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2024-11-24 12:06:16 +10:30
parent 23dc10cf81
commit c6fce50951
6 changed files with 37 additions and 97 deletions

View File

@ -84,8 +84,6 @@ msgtype,gossipd_remote_channel_update,3010
msgdata,gossipd_remote_channel_update,source_node,?node_id,
msgdata,gossipd_remote_channel_update,peer_update,peer_update,
# Ask lightningd to connect to a peer.
# Ask lightningd to try to connect to a peer.
msgtype,gossipd_connect_to_peer,3011
msgdata,gossipd_connect_to_peer,id,node_id,
msgdata,gossipd_connect_to_peer,num,u16,
msgdata,gossipd_connect_to_peer,addrs,wireaddr,num,

1 #include <common/cryptomsg.h>
84
85
86
87
88
89

View File

@ -1373,48 +1373,3 @@ void gossmap_manage_tell_lightningd_locals(struct daemon *daemon,
take(towire_gossipd_init_nannounce(NULL,
nannounce)));
}
struct wireaddr *gossmap_manage_get_node_addresses(const tal_t *ctx,
struct gossmap *gossmap,
const struct node_id *node_id)
{
struct gossmap_node *node;
u8 *nannounce;
struct node_id id;
secp256k1_ecdsa_signature signature;
u32 timestamp;
u8 *addresses, *features;
u8 rgb_color[3], alias[32];
struct tlv_node_ann_tlvs *na_tlvs;
struct wireaddr *wireaddrs;
node = gossmap_find_node(gossmap, node_id);
if (!node)
return NULL;
nannounce = gossmap_node_get_announce(tmpctx, gossmap,
node);
if (!nannounce)
return NULL;
if (!fromwire_node_announcement(tmpctx, nannounce,
&signature, &features,
&timestamp,
&id, rgb_color, alias,
&addresses,
&na_tlvs)) {
status_broken("Bad node_announcement for %s in gossip_store: %s",
fmt_node_id(tmpctx, node_id),
tal_hex(tmpctx, nannounce));
return NULL;
}
wireaddrs = fromwire_wireaddr_array(ctx, addresses);
if (!wireaddrs) {
status_broken("Bad wireaddrs in node_announcement in gossip_store: %s",
tal_hex(tmpctx, nannounce));
return NULL;
}
return wireaddrs;
}

View File

@ -94,18 +94,6 @@ void gossmap_manage_channel_spent(struct gossmap_manage *gm,
*/
struct gossmap *gossmap_manage_get_gossmap(struct gossmap_manage *gm);
/**
* gossmap_manage_get_node_addresses: get addresses for this node.
* @ctx: the allocation context
* @gossmap: the gossmap
* @node_id: the node_id to look up
*
* Returns NULL if we don't have node_announcement for it.
*/
struct wireaddr *gossmap_manage_get_node_addresses(const tal_t *ctx,
struct gossmap *gossmap,
const struct node_id *node_id);
/**
* gossmap_manage_tell_lightningd_locals: tell lightningd our latest updates.
* @daemon: the gossip daemon

View File

@ -969,13 +969,8 @@ static bool seek_any_unknown_nodes(struct seeker *seeker)
return true;
}
struct node_and_addrs {
struct node_id *id;
struct wireaddr *addrs;
};
/* Find a random node with an address in the announcement. */
static struct node_and_addrs *get_random_node(const tal_t *ctx,
/* Find a random node with an announcement. */
static struct node_id *get_random_node(const tal_t *ctx,
struct seeker *seeker)
{
struct gossmap *gossmap = gossmap_manage_get_gossmap(seeker->daemon->gm);
@ -985,17 +980,21 @@ static struct node_and_addrs *get_random_node(const tal_t *ctx,
return NULL;
for (int i = 0; i<20; i++) {
struct node_and_addrs *found_node = tal(ctx, struct node_and_addrs);
found_node->id = tal(found_node, struct node_id);
gossmap_node_get_id(gossmap, node, found_node->id);
found_node->addrs =
gossmap_manage_get_node_addresses(found_node,
gossmap,
found_node->id);
if (found_node->addrs && tal_count(found_node->addrs) != 0)
return found_node;
tal_free(found_node);
struct node_id id;
gossmap_node_get_id(gossmap, node, &id);
/* Make sure it *has* an announcement, and we're not
* already connected */
if (gossmap_node_get_announce(tmpctx, gossmap, node)
&& !find_peer(seeker->daemon, &id)) {
return tal_dup(ctx, struct node_id, &id);
}
node = gossmap_next_node(gossmap, node);
if (!node)
node = gossmap_first_node(gossmap);
}
return NULL;
}
@ -1003,6 +1002,7 @@ static struct node_and_addrs *get_random_node(const tal_t *ctx,
static void maybe_get_new_peer(struct seeker *seeker)
{
size_t connected_peers = peer_node_id_map_count(seeker->daemon->peers);
struct node_id *random_node;
/* Respect user-defined autoconnect peer limit. */
if (connected_peers >= seeker->daemon->autoconnect_seeker_peers)
@ -1011,21 +1011,13 @@ static void maybe_get_new_peer(struct seeker *seeker)
status_debug("seeker: need more peers for gossip (have %zu)",
connected_peers);
const struct node_and_addrs *random_node;
random_node = get_random_node(tmpctx, seeker);
if (!random_node) {
status_debug("seeker: no more potential peers found");
return;
}
if(!random_node->id)
status_broken("seeker: random gossip node missing node_id");
if(!random_node->addrs || tal_count(random_node->addrs) == 0)
status_broken("seeker: random gossip node missing address");
u8 *msg = towire_gossipd_connect_to_peer(NULL, random_node->id,
random_node->addrs);
u8 *msg = towire_gossipd_connect_to_peer(NULL, random_node);
daemon_conn_send(seeker->daemon->master, take(msg));
tal_free(random_node);
}

View File

@ -62,20 +62,27 @@ struct short_channel_id gossmap_chan_scid(const struct gossmap *map UNNEEDED,
struct gossmap_chan *gossmap_find_chan(const struct gossmap *map UNNEEDED,
const struct short_channel_id *scid UNNEEDED)
{ fprintf(stderr, "gossmap_find_chan called!\n"); abort(); }
/* Generated stub for gossmap_first_node */
struct gossmap_node *gossmap_first_node(const struct gossmap *map UNNEEDED)
{ fprintf(stderr, "gossmap_first_node called!\n"); abort(); }
/* Generated stub for gossmap_manage_get_gossmap */
struct gossmap *gossmap_manage_get_gossmap(struct gossmap_manage *gm UNNEEDED)
{ fprintf(stderr, "gossmap_manage_get_gossmap called!\n"); abort(); }
/* Generated stub for gossmap_manage_get_node_addresses */
struct wireaddr *gossmap_manage_get_node_addresses(const tal_t *ctx UNNEEDED,
struct gossmap *gossmap UNNEEDED,
const struct node_id *node_id UNNEEDED)
{ fprintf(stderr, "gossmap_manage_get_node_addresses called!\n"); abort(); }
/* Generated stub for gossmap_max_node_idx */
u32 gossmap_max_node_idx(const struct gossmap *map UNNEEDED)
{ fprintf(stderr, "gossmap_max_node_idx called!\n"); abort(); }
/* Generated stub for gossmap_next_node */
struct gossmap_node *gossmap_next_node(const struct gossmap *map UNNEEDED,
const struct gossmap_node *prev UNNEEDED)
{ fprintf(stderr, "gossmap_next_node called!\n"); abort(); }
/* Generated stub for gossmap_node_byidx */
struct gossmap_node *gossmap_node_byidx(const struct gossmap *map UNNEEDED, u32 idx UNNEEDED)
{ fprintf(stderr, "gossmap_node_byidx called!\n"); abort(); }
/* Generated stub for gossmap_node_get_announce */
u8 *gossmap_node_get_announce(const tal_t *ctx UNNEEDED,
const struct gossmap *map UNNEEDED,
const struct gossmap_node *n UNNEEDED)
{ fprintf(stderr, "gossmap_node_get_announce called!\n"); abort(); }
/* Generated stub for gossmap_node_get_id */
void gossmap_node_get_id(const struct gossmap *map UNNEEDED,
const struct gossmap_node *node UNNEEDED,
@ -142,7 +149,7 @@ void status_fmt(enum log_level level UNNEEDED,
{ fprintf(stderr, "status_fmt called!\n"); abort(); }
/* Generated stub for towire_gossipd_connect_to_peer */
u8 *towire_gossipd_connect_to_peer(const tal_t *ctx UNNEEDED, const struct node_id *id UNNEEDED, const struct wireaddr *addrs UNNEEDED)
u8 *towire_gossipd_connect_to_peer(const tal_t *ctx UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "towire_gossipd_connect_to_peer called!\n"); abort(); }
/* Generated stub for towire_sciddir_or_pubkey */
void towire_sciddir_or_pubkey(u8 **pptr UNNEEDED,

View File

@ -175,18 +175,18 @@ static void handle_peer_update_data(struct lightningd *ld, const u8 *msg)
/* gossipd would like a connection to this peer for more gossiping. */
static void handle_connect_to_peer(struct subd *gossip, const u8 *msg)
{
struct node_id *id = tal(tmpctx, struct node_id);
struct wireaddr *addrs;
if (!fromwire_gossipd_connect_to_peer(tmpctx, msg, id, &addrs)) {
struct node_id id;
if (!fromwire_gossipd_connect_to_peer(msg, &id)) {
log_broken(gossip->ld->log, "malformed peer connect request"
" from gossipd %s", tal_hex(msg, msg));
return;
}
log_debug(gossip->ld->log, "attempting connection to %s "
"for additional gossip", fmt_node_id(tmpctx, id));
"for additional gossip", fmt_node_id(tmpctx, &id));
u8 *connectmsg;
connectmsg = towire_connectd_connect_to_peer(NULL,
id,
&id,
NULL, //addrhint,
false, //dns_fallback
true); //transient