From 66574882a32d5c3ca45674f43f22e58902fefd5d Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 31 Jan 2024 15:01:33 +1030 Subject: [PATCH] gossipd: simplify seeker startup. Most nodes don't really care about exact timestamps on gossip filters, so just keep a flag on whether we have anything in the gossip_store, and use that to determine whether we ask peers for everything. Signed-off-by: Rusty Russell --- gossipd/gossipd.c | 15 ++++++--------- gossipd/gossipd.h | 3 +++ gossipd/routing.c | 7 ------- gossipd/routing.h | 3 --- gossipd/seeker.c | 18 +++++++++++------- 5 files changed, 20 insertions(+), 26 deletions(-) diff --git a/gossipd/gossipd.c b/gossipd/gossipd.c index a3e89889f..6e1700679 100644 --- a/gossipd/gossipd.c +++ b/gossipd/gossipd.c @@ -498,6 +498,9 @@ static void handle_recv_gossip(struct daemon *daemon, const u8 *outermsg) handled_msg: if (err) queue_peer_msg(peer->daemon, &peer->id, take(err)); + else + /* Some peer gave us gossip, so we're not at zero. */ + peer->daemon->gossip_store_populated = true; } /*~ connectd's input handler is very simple. */ @@ -674,7 +677,6 @@ bool timestamp_reasonable(const struct daemon *daemon, u32 timestamp) static void gossip_init(struct daemon *daemon, const u8 *msg) { u32 *dev_gossip_time; - u32 timestamp; if (!fromwire_gossipd_init(daemon, msg, &chainparams, @@ -696,14 +698,9 @@ static void gossip_init(struct daemon *daemon, const u8 *msg) daemon->rstate = new_routing_state(daemon, daemon); - /* Load stored gossip messages, get last modified time of file */ - timestamp = gossip_store_load(daemon->rstate->gs); - - /* If last_timestamp was > modified time of file, reduce it. - * Usually it's capped to "now", but in the reload case it needs to - * be the gossip_store mtime. */ - if (daemon->rstate->last_timestamp > timestamp) - daemon->rstate->last_timestamp = timestamp; + /* Load stored gossip messages (FIXME: API sucks)*/ + daemon->gossip_store_populated = + (gossip_store_load(daemon->rstate->gs) != 0); /* Start the twice- weekly refresh timer. */ notleak(new_reltimer(&daemon->timers, daemon, diff --git a/gossipd/gossipd.h b/gossipd/gossipd.h index baef9737a..ac324da59 100644 --- a/gossipd/gossipd.h +++ b/gossipd/gossipd.h @@ -65,6 +65,9 @@ struct daemon { /* Features lightningd told us to set. */ struct feature_set *our_features; + /* Was there anything in the gossip store at startup? */ + bool gossip_store_populated; + /* Override local time for gossip messages */ struct timeabs *dev_gossip_time; diff --git a/gossipd/routing.c b/gossipd/routing.c index 3ce8c03e9..2e88ec21a 100644 --- a/gossipd/routing.c +++ b/gossipd/routing.c @@ -242,7 +242,6 @@ struct routing_state *new_routing_state(const tal_t *ctx, rstate->daemon = daemon; rstate->nodes = new_node_map(rstate); rstate->gs = gossip_store_new(daemon); - rstate->last_timestamp = 0; rstate->dying_channels = tal_arr(rstate, struct dying_channel, 0); rstate->pending_cannouncements = tal(rstate, struct pending_cannouncement_map); @@ -1375,9 +1374,6 @@ bool routing_add_channel_update(struct routing_state *rstate, hc->rgraph.index = gossip_store_add(rstate->gs, update, timestamp, zombie, spam, dying, NULL); - if (hc->bcast.timestamp > rstate->last_timestamp - && hc->bcast.timestamp < time_now().ts.tv_sec) - rstate->last_timestamp = hc->bcast.timestamp; if (!spam) hc->bcast.index = hc->rgraph.index; @@ -1794,9 +1790,6 @@ bool routing_add_node_announcement(struct routing_state *rstate, node->rgraph.index = gossip_store_add(rstate->gs, msg, timestamp, false, spam, false, NULL); - if (node->bcast.timestamp > rstate->last_timestamp - && node->bcast.timestamp < time_now().ts.tv_sec) - rstate->last_timestamp = node->bcast.timestamp; if (!spam) node->bcast.index = node->rgraph.index; diff --git a/gossipd/routing.h b/gossipd/routing.h index e630d1e86..63ff8d1bd 100644 --- a/gossipd/routing.h +++ b/gossipd/routing.h @@ -200,9 +200,6 @@ struct routing_state { * checks if we get another announcement for the same scid. */ struct txout_failures *txf; - /* Highest timestamp of gossip we accepted (before now) */ - u32 last_timestamp; - /* Channels which are closed, but we're waiting 12 blocks */ struct dying_channel *dying_channels; }; diff --git a/gossipd/seeker.c b/gossipd/seeker.c index 65ad8afb5..bd1ec17b6 100644 --- a/gossipd/seeker.c +++ b/gossipd/seeker.c @@ -209,17 +209,21 @@ static void disable_gossip_stream(struct seeker *seeker, struct peer *peer) static void enable_gossip_stream(struct seeker *seeker, struct peer *peer) { - /* We seek some way back, to take into account propagation time */ - const u32 polltime = GOSSIP_SEEKER_INTERVAL(seeker) * 10; - u32 start = seeker->daemon->rstate->last_timestamp; + u32 start; u8 *msg; - if (start > polltime) - start -= polltime; - else + /* Modern timestamp_filter is a trinary: 0 = all, FFFFFFFF = none, + * other = from now on */ + if (seeker->daemon->gossip_store_populated) { + /* Just in case they care */ + start = time_now().ts.tv_sec - GOSSIP_SEEKER_INTERVAL(seeker) * 10; + } else { start = 0; + } - status_peer_debug(&peer->id, "seeker: starting gossip"); + status_peer_debug(&peer->id, "seeker: starting gossip (%s)", + seeker->daemon->gossip_store_populated + ? "streaming" : "EVERTHING"); /* This is allowed even if they don't understand it (odd) */ msg = towire_gossip_timestamp_filter(NULL,