Skip to content

Commit

Permalink
gossipd: add request to connect to new gossip peer
Browse files Browse the repository at this point in the history
Gossipd uses this to ask lightningd -> connectd to initiate
a connection to a new gossip peer.  This can be used when
there are insufficient peers already connected to gossip with.

Changelog-Changed: Gossipd can now request connections to additional nodes for improved gossip sync
  • Loading branch information
endothermicdev committed Nov 12, 2024
1 parent c66b6ff commit 468b084
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions gossipd/gossipd.c
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ static struct io_plan *recv_req(struct io_conn *conn,
case WIRE_GOSSIPD_NEW_BLOCKHEIGHT_REPLY:
case WIRE_GOSSIPD_GET_ADDRS_REPLY:
case WIRE_GOSSIPD_REMOTE_CHANNEL_UPDATE:
case WIRE_GOSSIPD_CONNECT_TO_PEER:
break;
}

Expand Down
6 changes: 6 additions & 0 deletions gossipd/gossipd_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,9 @@ subtypedata,peer_update,htlc_maximum_msat,amount_msat,
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.
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,
15 changes: 15 additions & 0 deletions gossipd/seeker.c
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,20 @@ static bool seek_any_unknown_nodes(struct seeker *seeker)
return true;
}

/* Ask lightningd for more peers if we're short on gossip streamers. */
static void maybe_get_new_peer(struct seeker *seeker)
{
size_t connected_peers = peer_node_id_map_count(seeker->daemon->peers);
if (connected_peers < ARRAY_SIZE(seeker->gossiper)) {
status_debug("seeker: have only %zu connected peers."
" Should connect to more.",
connected_peers);

}
/* TODO: find random node announcement, see if we can connect,
* ask lightningd to connect via towire_gossipd_connect_to_peer. */
}

/* Periodic timer to see how our gossip is going. */
static void seeker_check(struct seeker *seeker)
{
Expand All @@ -988,6 +1002,7 @@ static void seeker_check(struct seeker *seeker)
break;
case NORMAL:
/* FIXME: maybe_get_more_peers(seeker); */
maybe_get_new_peer(seeker);
maybe_rotate_gossipers(seeker);
if (!seek_any_unknown_scids(seeker)
&& !seek_any_stale_scids(seeker))
Expand Down
17 changes: 17 additions & 0 deletions lightningd/gossip_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,20 @@ static void handle_peer_update_data(struct lightningd *ld, const u8 *msg)
channel_gossip_set_remote_update(ld, &update, source);
}

/* 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))
log_broken(gossip->ld->log, "malformed peer connect request"
" from gossipd %s", tal_hex(msg, msg));
else
log_debug(gossip->ld->log, "asked to connect to %s",
fmt_node_id(msg, &id));
/* TODO: send node_id and address to connectd. */
}

static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
{
enum gossipd_wire t = fromwire_peektype(msg);
Expand Down Expand Up @@ -203,6 +217,9 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
handle_peer_update_data(gossip->ld, msg);
tal_free(msg);
break;
case WIRE_GOSSIPD_CONNECT_TO_PEER:
/* Please try connecting to this peer for more gossip. */
handle_connect_to_peer(gossip, msg);
}
return 0;
}
Expand Down

0 comments on commit 468b084

Please sign in to comment.