From f5ea57d4c0a9ffcf248781d826b9d3e0aedf4c5e Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 12 Jun 2019 08:58:40 +0930 Subject: [PATCH] gossipd: reset gossip_missing if no reports for 10 minutes. An arbitrary timeout. Signed-off-by: Rusty Russell --- gossipd/gossipd.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/gossipd/gossipd.c b/gossipd/gossipd.c index 255951e44..09d851194 100644 --- a/gossipd/gossipd.c +++ b/gossipd/gossipd.c @@ -114,8 +114,8 @@ struct daemon { /* What addresses we can actually announce. */ struct wireaddr *announcable; - /* Do we think we're missing gossip? */ - bool gossip_missing; + /* Do we think we're missing gossip? Contains timer to re-check */ + struct oneshot *gossip_missing; /* Channels we've heard about, but don't know. */ struct short_channel_id *unknown_scids; @@ -1927,10 +1927,35 @@ static void gossip_disable_local_channels(struct daemon *daemon) local_disable_chan(daemon->rstate, c); } +/* Mutual recursion, so we pre-declare this. */ +static void gossip_not_missing(struct daemon *daemon); + /*~ We've found gossip is missing. */ static void gossip_missing(struct daemon *daemon) { - daemon->gossip_missing = true; + if (!daemon->gossip_missing) + status_info("We seem to be missing gossip messages"); + + tal_free(daemon->gossip_missing); + /* Check again in 10 minutes. */ + daemon->gossip_missing = new_reltimer(&daemon->timers, daemon, + time_from_sec(600), + gossip_not_missing, daemon); +} + +/*~ This is a timer, which goes off 10 minutes after the last time we noticed + * that gossip was missing. */ +static void gossip_not_missing(struct daemon *daemon) +{ + /* Corner case: no peers, try again! */ + if (list_empty(&daemon->peers)) + gossip_missing(daemon); + else { + 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); + } } /*~ Parse init message from lightningd: starts the daemon properly. */