-
Notifications
You must be signed in to change notification settings - Fork 906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Seeker autoconnect #7798
Open
endothermicdev
wants to merge
10
commits into
ElementsProject:master
Choose a base branch
from
endothermicdev:seeker-autoconnect
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Seeker autoconnect #7798
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
dedc68b
gossipd: Increase gossiping peers to 10
endothermicdev 0090e63
gossipd: seeker: add hourly full gossip resync from a random peer
endothermicdev e2114fc
gossipd: seeker: choose a new node when resyncing
endothermicdev 4db9936
gossipd: add separate counter for unsolicted gossip
endothermicdev afd958b
gossipd: seeker: rotate out the worst performing gossiper
endothermicdev 1b71451
gossipd: seeker: rotate worst gossiper every 30 minutes
endothermicdev c66b6ff
pytest: allow additional gossip filters
endothermicdev 468b084
gossipd: add request to connect to new gossip peer
endothermicdev e851886
gossipd: seeker: select random peer and tell lightningd
endothermicdev bb81f52
pytest: Start of a seeker autoconnect test
endothermicdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
#include <ccan/asort/asort.h> | ||
#include <ccan/intmap/intmap.h> | ||
#include <ccan/tal/str/str.h> | ||
#include <common/daemon_conn.h> | ||
#include <common/decode_array.h> | ||
#include <common/gossmap.h> | ||
#include <common/memleak.h> | ||
|
@@ -13,6 +14,7 @@ | |
#include <common/status.h> | ||
#include <common/timeout.h> | ||
#include <gossipd/gossipd.h> | ||
#include <gossipd/gossipd_wiregen.h> | ||
#include <gossipd/gossmap_manage.h> | ||
#include <gossipd/queries.h> | ||
#include <gossipd/seeker.h> | ||
|
@@ -963,18 +965,81 @@ 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, | ||
struct seeker *seeker) | ||
{ | ||
struct gossmap *gossmap = gossmap_manage_get_gossmap(seeker->daemon->gm); | ||
if (gossmap_num_nodes(gossmap) < 1) | ||
return NULL; | ||
u32 max_idx = gossmap_max_node_idx(gossmap); | ||
if (max_idx < 1) | ||
return NULL; | ||
|
||
struct gossmap_node *random_node; | ||
struct node_and_addrs *found_node = NULL; | ||
for (int i = 0; i<20; i++) { | ||
u32 random = pseudorand(max_idx); | ||
random_node = gossmap_node_byidx(gossmap, random); | ||
if (!random_node) { | ||
continue; | ||
} | ||
found_node = tal(ctx, struct node_and_addrs); | ||
found_node->id = tal(found_node, struct node_id); | ||
gossmap_node_get_id(gossmap, random_node, found_node->id); | ||
if (node_id_eq(found_node->id, &seeker->daemon->id)) { | ||
found_node = tal_free(found_node); | ||
continue; | ||
} | ||
found_node->addrs = | ||
gossmap_manage_get_node_addresses(found_node, | ||
seeker->daemon->gm, | ||
found_node->id); | ||
if (!found_node->addrs || tal_count(found_node->addrs) == 0) { | ||
found_node = tal_free(found_node); | ||
continue; | ||
} | ||
|
||
break; | ||
} | ||
|
||
return found_node; | ||
|
||
} | ||
|
||
/* 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); | ||
|
||
if (connected_peers >= ARRAY_SIZE(seeker->gossiper)) | ||
return; | ||
|
||
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; | ||
} | ||
/* TODO: find random node announcement, see if we can connect, | ||
* ask lightningd to connect via towire_gossipd_connect_to_peer. */ | ||
|
||
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); | ||
daemon_conn_send(seeker->daemon->master, take(msg)); | ||
tal_free(random_node); | ||
Comment on lines
+1036
to
+1042
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simplify: don't hand addrs here, since connectd already has that logic internally. |
||
} | ||
|
||
/* Periodic timer to see how our gossip is going. */ | ||
|
@@ -1001,7 +1066,6 @@ static void seeker_check(struct seeker *seeker) | |
check_probe(seeker, peer_gossip_probe_nannounces); | ||
break; | ||
case NORMAL: | ||
/* FIXME: maybe_get_more_peers(seeker); */ | ||
maybe_get_new_peer(seeker); | ||
maybe_rotate_gossipers(seeker); | ||
if (!seek_any_unknown_scids(seeker) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is better done by providing a "struct gossmap_node *gossmap_random_node(const struct gossmap *map);" in gossmap.c, which can use nodeidx_htable_pick. Then iterate until NULL, or you find one with an address.