Skip to content

Commit 363b721

Browse files
endothermicdevrustyrussell
authored andcommitted
gossipd: use autoconnect-seeker-peers setting
1 parent dc878dc commit 363b721

File tree

6 files changed

+28
-9
lines changed

6 files changed

+28
-9
lines changed

gossipd/gossipd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,8 @@ static void gossip_init(struct daemon *daemon, const u8 *msg)
432432
&daemon->id,
433433
&dev_gossip_time,
434434
&daemon->dev_fast_gossip,
435-
&daemon->dev_fast_gossip_prune)) {
435+
&daemon->dev_fast_gossip_prune,
436+
&daemon->autoconnect_seeker_peers)) {
436437
master_badmsg(WIRE_GOSSIPD_INIT, msg);
437438
}
438439

gossipd/gossipd.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ struct daemon {
7979

8080
/* Speed up pruning. */
8181
bool dev_fast_gossip_prune;
82+
83+
/* Minimum gossip peers - seeker connects to random peers to fill. */
84+
u32 autoconnect_seeker_peers;
8285
};
8386

8487
struct range_query_reply {

gossipd/gossipd_wire.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ msgdata,gossipd_init,id,node_id,
1212
msgdata,gossipd_init,dev_gossip_time,?u32,
1313
msgdata,gossipd_init,dev_fast_gossip,bool,
1414
msgdata,gossipd_init,dev_fast_gossip_prune,bool,
15+
msgdata,gossipd_init,autoconnect_seeker_peers,u32,
1516

1617
# Gossipd tells us all our public channel_updates before init_reply.
1718
msgtype,gossipd_init_cupdate,3101

gossipd/seeker.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#define GOSSIP_SEEKER_RESYNC_INTERVAL(seeker) \
2626
DEV_FAST_GOSSIP((seeker)->daemon->dev_fast_gossip, 30, 3600)
2727

28+
#define SEEKER_GOSSIPERS 10
29+
2830
enum seeker_state {
2931
/* Still streaming gossip from single peer. */
3032
STARTING_UP,
@@ -152,7 +154,9 @@ struct seeker *new_seeker(struct daemon *daemon)
152154
uintmap_init(&seeker->unknown_scids);
153155
uintmap_init(&seeker->stale_scids);
154156
seeker->random_peer = NULL;
155-
seeker->gossiper = tal_arrz(seeker, struct peer *, 10);
157+
u32 gossipers = daemon->autoconnect_seeker_peers > SEEKER_GOSSIPERS ?
158+
daemon->autoconnect_seeker_peers : SEEKER_GOSSIPERS;
159+
seeker->gossiper = tal_arrz(seeker, struct peer *, gossipers);
156160
seeker->preferred_peer = NULL;
157161
seeker->unknown_nodes = false;
158162
seeker->last_full_sync_peer = NULL;
@@ -1017,7 +1021,8 @@ static void maybe_get_new_peer(struct seeker *seeker)
10171021
{
10181022
size_t connected_peers = peer_node_id_map_count(seeker->daemon->peers);
10191023

1020-
if (connected_peers >= tal_count(seeker->gossiper))
1024+
/* Respect user-defined autoconnect peer limit. */
1025+
if (connected_peers >= seeker->daemon->autoconnect_seeker_peers)
10211026
return;
10221027

10231028
status_debug("seeker: need more peers for gossip (have %zu)",

lightningd/gossip_control.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ void gossip_init(struct lightningd *ld, int connectd_fd)
333333
&ld->our_nodeid,
334334
ld->dev_gossip_time ? &ld->dev_gossip_time: NULL,
335335
ld->dev_fast_gossip,
336-
ld->dev_fast_gossip_prune);
336+
ld->dev_fast_gossip_prune,
337+
ld->autoconnect_seeker_peers);
337338

338339
subd_req(ld->gossip, ld->gossip, take(msg), -1, 0,
339340
gossipd_init_done, NULL);

tests/test_gossip.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,12 +2335,20 @@ def test_gossip_seeker_autoconnect(node_factory):
23352335
necessary."""
23362336

23372337
port = node_factory.get_unused_port()
2338-
opts = [{}, {}, {'bind-addr': f'127.0.0.1:{port}',
2339-
'announce-addr': f'127.0.0.1:{port}'}]
2340-
# l1, l2 = node_factory.get_nodes(2)
2338+
opts = [{'autoconnect-seeker-peers': 0, 'may_reconnect': True},
2339+
{'may_reconnect': True},
2340+
{'bind-addr': f'127.0.0.1:{port}',
2341+
'announce-addr': f'127.0.0.1:{port}'}]
23412342
l1, l2, l3 = node_factory.line_graph(3, opts=opts, wait_for_announce=True)
2342-
# L1 and L3 should autoconnect with valid node announcement connection addresses
2343-
# Wait for seeker to decide to autoconnect
2343+
l2.daemon.wait_for_log('gossipd: seeker: need more peers for gossip')
2344+
time.sleep(1)
2345+
# The seeker wants more peers, but l1 should not autoconnect due to option.
2346+
assert not l1.daemon.is_in_log(r'lightningd: attempting connection to ')
2347+
2348+
# Try again with default settings.
2349+
del l1.daemon.opts['autoconnect-seeker-peers']
2350+
l1.restart()
2351+
# L1 and L3 should autoconnect with valid node announcement connection addresses.
23442352
l1.daemon.wait_for_log('gossipd: seeker: need more peers for gossip')
23452353
l1.daemon.wait_for_log(r'lightningd: attempting connection to '
23462354
rf'{l3.info["id"]} for additional gossip')

0 commit comments

Comments
 (0)