mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-05 15:24:18 +01:00
gossipd: start streaming gossip from last gossip timestamp minus 10 minutes.
We assume that the time for gossip propagation is < 10 minutes, so by going back that far from last gossip we won't miss anything, Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
neil saitug
parent
70e88b0dfb
commit
82a5efa932
@@ -816,9 +816,15 @@ static struct io_plan *gossip_init(struct io_conn *conn,
|
||||
dev_fast_gossip,
|
||||
dev_fast_gossip_prune);
|
||||
|
||||
/* Load stored gossip messages */
|
||||
/* Load stored gossip messages, get last modified time of file */
|
||||
timestamp = gossip_store_load(daemon->rstate, 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;
|
||||
|
||||
/* Now disable all local channels, they can't be connected yet. */
|
||||
gossip_disable_local_channels(daemon);
|
||||
|
||||
@@ -832,7 +838,7 @@ static struct io_plan *gossip_init(struct io_conn *conn,
|
||||
gossip_refresh_network, daemon));
|
||||
|
||||
/* Fire up the seeker! */
|
||||
daemon->seeker = new_seeker(daemon, timestamp);
|
||||
daemon->seeker = new_seeker(daemon);
|
||||
|
||||
return daemon_conn_read_next(conn, daemon->master);
|
||||
}
|
||||
|
||||
@@ -298,6 +298,7 @@ struct routing_state *new_routing_state(const tal_t *ctx,
|
||||
rstate->chainparams = chainparams;
|
||||
rstate->local_id = *local_id;
|
||||
rstate->local_channel_announced = false;
|
||||
rstate->last_timestamp = 0;
|
||||
|
||||
pending_cannouncement_map_init(&rstate->pending_cannouncements);
|
||||
|
||||
@@ -2183,6 +2184,10 @@ bool routing_add_channel_update(struct routing_state *rstate,
|
||||
= gossip_store_add(rstate->gs, update,
|
||||
hc->bcast.timestamp,
|
||||
NULL);
|
||||
if (hc->bcast.timestamp > rstate->last_timestamp
|
||||
&& hc->bcast.timestamp < time_now().ts.tv_sec)
|
||||
rstate->last_timestamp = hc->bcast.timestamp;
|
||||
|
||||
peer_supplied_good_gossip(peer, 1);
|
||||
}
|
||||
|
||||
@@ -2504,6 +2509,10 @@ bool routing_add_node_announcement(struct routing_state *rstate,
|
||||
WIRE_NODE_ANNOUNCEMENT);
|
||||
|
||||
node->bcast.timestamp = timestamp;
|
||||
if (node->bcast.timestamp > rstate->last_timestamp
|
||||
&& node->bcast.timestamp < time_now().ts.tv_sec)
|
||||
rstate->last_timestamp = node->bcast.timestamp;
|
||||
|
||||
if (index)
|
||||
node->bcast.index = index;
|
||||
else {
|
||||
|
||||
@@ -292,6 +292,9 @@ struct routing_state {
|
||||
/* A map of local channels by short_channel_ids */
|
||||
struct local_chan_map local_chan_map;
|
||||
|
||||
/* Highest timestamp of gossip we accepted (before now) */
|
||||
u32 last_timestamp;
|
||||
|
||||
#if DEVELOPER
|
||||
/* Override local time for gossip messages */
|
||||
struct timeabs *gossip_time;
|
||||
|
||||
@@ -85,9 +85,6 @@ struct seeker {
|
||||
/* Range of scid blocks we've probed. */
|
||||
size_t scid_probe_start, scid_probe_end;
|
||||
|
||||
/* Timestamp of gossip store (or 0). */
|
||||
u32 last_gossip_timestamp;
|
||||
|
||||
/* During startup, we ask a single peer for gossip. */
|
||||
struct peer *random_peer_softref;
|
||||
|
||||
@@ -136,14 +133,13 @@ static void set_state_(struct seeker *seeker, enum seeker_state state,
|
||||
seeker->state = state;
|
||||
}
|
||||
|
||||
struct seeker *new_seeker(struct daemon *daemon, u32 timestamp)
|
||||
struct seeker *new_seeker(struct daemon *daemon)
|
||||
{
|
||||
struct seeker *seeker = tal(daemon, struct seeker);
|
||||
|
||||
seeker->daemon = daemon;
|
||||
scid_map_init(&seeker->unknown_scids);
|
||||
stale_scid_map_init(&seeker->stale_scids);
|
||||
seeker->last_gossip_timestamp = timestamp;
|
||||
seeker->random_peer_softref = NULL;
|
||||
for (size_t i = 0; i < ARRAY_SIZE(seeker->gossiper_softref); i++)
|
||||
seeker->gossiper_softref[i] = NULL;
|
||||
@@ -202,12 +198,15 @@ static void disable_gossip_stream(struct seeker *seeker, struct peer *peer)
|
||||
|
||||
static void enable_gossip_stream(struct seeker *seeker, struct peer *peer)
|
||||
{
|
||||
u32 start;
|
||||
/* 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;
|
||||
u8 *msg;
|
||||
|
||||
/* FIXME: gets the last minute of gossip, works around our current
|
||||
* lack of discovery if we're missing gossip. */
|
||||
start = time_now().ts.tv_sec - 60;
|
||||
if (start > polltime)
|
||||
start -= polltime;
|
||||
else
|
||||
start = 0;
|
||||
|
||||
status_debug("seeker: starting gossip from %s",
|
||||
type_to_string(tmpctx, struct node_id, &peer->id));
|
||||
@@ -265,23 +264,8 @@ static struct short_channel_id *unknown_scids_arr(const tal_t *ctx,
|
||||
/* We have selected this peer to stream us startup gossip */
|
||||
static void peer_gossip_startup(struct seeker *seeker, struct peer *peer)
|
||||
{
|
||||
const u32 polltime = GOSSIP_SEEKER_INTERVAL(seeker);
|
||||
u8 *msg;
|
||||
u32 start;
|
||||
|
||||
if (seeker->last_gossip_timestamp < polltime)
|
||||
start = 0;
|
||||
else
|
||||
start = seeker->last_gossip_timestamp - polltime;
|
||||
|
||||
selected_peer(seeker, peer);
|
||||
|
||||
status_debug("seeker: startup gossip from t=%u from %s",
|
||||
start, type_to_string(tmpctx, struct node_id, &peer->id));
|
||||
msg = towire_gossip_timestamp_filter(NULL,
|
||||
&peer->daemon->chain_hash,
|
||||
start, UINT32_MAX);
|
||||
queue_peer_msg(peer, take(msg));
|
||||
normal_gossip_start(seeker, peer);
|
||||
}
|
||||
|
||||
static bool peer_has_gossip_queries(const struct peer *peer)
|
||||
|
||||
@@ -6,7 +6,7 @@ struct daemon;
|
||||
struct peer;
|
||||
struct short_channel_id;
|
||||
|
||||
struct seeker *new_seeker(struct daemon *daemon, u32 timestamp);
|
||||
struct seeker *new_seeker(struct daemon *daemon);
|
||||
|
||||
void query_unknown_channel(struct daemon *daemon,
|
||||
struct peer *peer,
|
||||
|
||||
Reference in New Issue
Block a user