Skip to content

Commit

Permalink
gossipd: adjust gossip filters if we discover we're missing gossip.
Browse files Browse the repository at this point in the history
We pick up to three random peers and ask them to gossip more.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Jun 12, 2019
1 parent 6830233 commit 1e32b4a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Plugins: a plugin can now set the category of a newly created RPC command. This possibility has been added to libplugin.c and pylightning.
- CLI: the human readable help is now more human and more readable : commands are sorted alphabetically and ordered by categories.
- JSON API: A new parameter is added to `fundchannel`, which now accepts an utxo array to use to fund the channel.
- Protocol: no longer ask for entire gossip flood from peers, unless we're missing gossip.

### Deprecated

Expand Down
46 changes: 45 additions & 1 deletion gossipd/gossipd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2006,11 +2006,43 @@ static void gossip_disable_local_channels(struct daemon *daemon)
/* Mutual recursion, so we pre-declare this. */
static void gossip_not_missing(struct daemon *daemon);

/* Pick a random peer which is not already GOSSIP_HIGH. */
static struct peer *random_peer_to_gossip(struct daemon *daemon)
{
u64 target = UINT64_MAX;
struct peer *best = NULL, *i;

/* Reservoir sampling */
list_for_each(&daemon->peers, i, list) {
u64 r = pseudorand_u64();
if (i->gossip_level != GOSSIP_HIGH && r <= target) {
best = i;
target = r;
}
}
return best;
}

/*~ We've found gossip is missing. */
static void gossip_missing(struct daemon *daemon)
{
if (!daemon->gossip_missing)
if (!daemon->gossip_missing) {
status_info("We seem to be missing gossip messages");
/* FIXME: we could use query_channel_range. */
/* Make some peers gossip harder. */
for (size_t i = 0; i < gossip_level_targets[GOSSIP_HIGH]; i++) {
struct peer *peer = random_peer_to_gossip(daemon);

if (!peer)
break;

status_info("%s: gossip harder!",
type_to_string(tmpctx, struct node_id,
&peer->id));
peer->gossip_level = GOSSIP_HIGH;
setup_gossip_range(peer);
}
}

tal_free(daemon->gossip_missing);
/* Check again in 10 minutes. */
Expand All @@ -2027,10 +2059,22 @@ static void gossip_not_missing(struct daemon *daemon)
if (list_empty(&daemon->peers))
gossip_missing(daemon);
else {
struct peer *peer;

daemon->gossip_missing = tal_free(daemon->gossip_missing);
status_info("We seem to be caught up on gossip messages");
/* Free any lagging/stale unknown scids. */
daemon->unknown_scids = tal_free(daemon->unknown_scids);

/* Reset peers we marked as HIGH */
list_for_each(&daemon->peers, peer, list) {
if (peer->gossip_level != GOSSIP_HIGH)
continue;
if (!peer->gossip_queries_feature)
continue;
peer->gossip_level = peer_gossip_level(daemon, true);
setup_gossip_range(peer);
}
}
}

Expand Down

0 comments on commit 1e32b4a

Please sign in to comment.