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 <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2024-01-31 15:01:33 +10:30
parent ddc6783cf0
commit 66574882a3
5 changed files with 20 additions and 26 deletions

View File

@@ -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,

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;
};

View File

@@ -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,