mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +01:00
gossipd: use gossip_time_now() everywhere.
We've been slack, but it's going to be important for testing ratelimiting. And it currently has a minor memory leak. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
9aca38b279
commit
2577ad87d5
@ -743,7 +743,7 @@ bool gossip_store_load(struct routing_state *rstate, struct gossip_store *gs)
|
||||
goto corrupt;
|
||||
|
||||
/* If last timestamp is within 24 hours, say we're OK. */
|
||||
contents_ok = (last_timestamp >= time_now().ts.tv_sec - 24*3600);
|
||||
contents_ok = (last_timestamp >= gossip_time_now(rstate).ts.tv_sec - 24*3600);
|
||||
goto out;
|
||||
|
||||
badmsg:
|
||||
|
@ -405,15 +405,16 @@ static UNNEEDED bool encoding_end_external_type(u8 **encoded, u8 *type, size_t m
|
||||
}
|
||||
|
||||
/*~ We have different levels of gossipiness, depending on our needs. */
|
||||
static u32 gossip_start(enum gossip_level gossip_level)
|
||||
static u32 gossip_start(const struct routing_state *rstate,
|
||||
enum gossip_level gossip_level)
|
||||
{
|
||||
switch (gossip_level) {
|
||||
case GOSSIP_HIGH:
|
||||
return 0;
|
||||
case GOSSIP_MEDIUM:
|
||||
return time_now().ts.tv_sec - 24 * 3600;
|
||||
return gossip_time_now(rstate).ts.tv_sec - 24 * 3600;
|
||||
case GOSSIP_LOW:
|
||||
return time_now().ts.tv_sec;
|
||||
return gossip_time_now(rstate).ts.tv_sec;
|
||||
case GOSSIP_NONE:
|
||||
return UINT32_MAX;
|
||||
}
|
||||
@ -446,7 +447,8 @@ static void setup_gossip_range(struct peer *peer)
|
||||
/*~ We need to ask for something to start the gossip flowing. */
|
||||
msg = towire_gossip_timestamp_filter(peer,
|
||||
&peer->daemon->chain_hash,
|
||||
gossip_start(peer->gossip_level),
|
||||
gossip_start(peer->daemon->rstate,
|
||||
peer->gossip_level),
|
||||
UINT32_MAX);
|
||||
queue_peer_msg(peer, take(msg));
|
||||
}
|
||||
@ -484,7 +486,7 @@ static u8 *create_node_announcement(const tal_t *ctx, struct daemon *daemon,
|
||||
* (to prevent spam), so we only call this once we've announced a channel. */
|
||||
static void send_node_announcement(struct daemon *daemon)
|
||||
{
|
||||
u32 timestamp = time_now().ts.tv_sec;
|
||||
u32 timestamp = gossip_time_now(daemon->rstate).ts.tv_sec;
|
||||
secp256k1_ecdsa_signature sig;
|
||||
u8 *msg, *nannounce, *err;
|
||||
struct node *self = get_node(daemon->rstate, &daemon->id);
|
||||
@ -1644,7 +1646,7 @@ static void update_local_channel(struct daemon *daemon,
|
||||
{
|
||||
secp256k1_ecdsa_signature dummy_sig;
|
||||
u8 *update, *msg;
|
||||
u32 timestamp = time_now().ts.tv_sec;
|
||||
u32 timestamp = gossip_time_now(daemon->rstate).ts.tv_sec;
|
||||
u8 message_flags, channel_flags;
|
||||
|
||||
/* So valgrind doesn't complain */
|
||||
@ -2289,7 +2291,7 @@ static void gossip_send_keepalive_update(struct daemon *daemon,
|
||||
*/
|
||||
static void gossip_refresh_network(struct daemon *daemon)
|
||||
{
|
||||
u64 now = time_now().ts.tv_sec;
|
||||
u64 now = gossip_time_now(daemon->rstate).ts.tv_sec;
|
||||
/* Anything below this highwater mark could be pruned if not refreshed */
|
||||
s64 highwater = now - daemon->rstate->prune_timeout / 2;
|
||||
struct node *n;
|
||||
@ -2453,7 +2455,7 @@ static struct io_plan *gossip_init(struct io_conn *conn,
|
||||
&daemon->id,
|
||||
update_channel_interval * 2,
|
||||
&daemon->peers,
|
||||
dev_gossip_time);
|
||||
take(dev_gossip_time));
|
||||
|
||||
/* Load stored gossip messages */
|
||||
if (!gossip_store_load(daemon->rstate, daemon->rstate->gs))
|
||||
|
@ -190,7 +190,7 @@ struct routing_state *new_routing_state(const tal_t *ctx,
|
||||
const struct node_id *local_id,
|
||||
u32 prune_timeout,
|
||||
struct list_head *peers,
|
||||
const u32 *dev_gossip_time)
|
||||
const u32 *dev_gossip_time TAKES)
|
||||
{
|
||||
struct routing_state *rstate = tal(ctx, struct routing_state);
|
||||
rstate->nodes = new_node_map(rstate);
|
||||
@ -221,6 +221,9 @@ struct routing_state *new_routing_state(const tal_t *ctx,
|
||||
tal_add_destructor(rstate, destroy_routing_state);
|
||||
memleak_add_helper(rstate, memleak_help_routing_tables);
|
||||
|
||||
if (taken(dev_gossip_time))
|
||||
tal_free(dev_gossip_time);
|
||||
|
||||
return rstate;
|
||||
}
|
||||
|
||||
@ -1481,7 +1484,7 @@ bool routing_add_channel_announcement(struct routing_state *rstate,
|
||||
|
||||
uc = tal(rstate, struct unupdated_channel);
|
||||
uc->channel_announce = tal_dup_arr(uc, u8, msg, tal_count(msg), 0);
|
||||
uc->added = time_now();
|
||||
uc->added = gossip_time_now(rstate);
|
||||
uc->index = index;
|
||||
uc->sat = sat;
|
||||
uc->scid = scid;
|
||||
|
@ -273,7 +273,7 @@ struct routing_state *new_routing_state(const tal_t *ctx,
|
||||
const struct node_id *local_id,
|
||||
u32 prune_timeout,
|
||||
struct list_head *peers,
|
||||
const u32 *dev_gossip_time);
|
||||
const u32 *dev_gossip_time TAKES);
|
||||
|
||||
/**
|
||||
* Add a new bidirectional channel from id1 to id2 with the given
|
||||
|
@ -157,6 +157,9 @@ bool gossip_store_load(struct routing_state *rstate UNNEEDED, struct gossip_stor
|
||||
/* Generated stub for gossip_store_readonly_fd */
|
||||
int gossip_store_readonly_fd(struct gossip_store *gs UNNEEDED)
|
||||
{ fprintf(stderr, "gossip_store_readonly_fd called!\n"); abort(); }
|
||||
/* Generated stub for gossip_time_now */
|
||||
struct timeabs gossip_time_now(const struct routing_state *rstate UNNEEDED)
|
||||
{ fprintf(stderr, "gossip_time_now called!\n"); abort(); }
|
||||
/* Generated stub for got_pong */
|
||||
const char *got_pong(const u8 *pong UNNEEDED, size_t *num_pings_outstanding UNNEEDED)
|
||||
{ fprintf(stderr, "got_pong called!\n"); abort(); }
|
||||
|
@ -180,6 +180,9 @@ bool gossip_store_load(struct routing_state *rstate UNNEEDED, struct gossip_stor
|
||||
/* Generated stub for gossip_store_readonly_fd */
|
||||
int gossip_store_readonly_fd(struct gossip_store *gs UNNEEDED)
|
||||
{ fprintf(stderr, "gossip_store_readonly_fd called!\n"); abort(); }
|
||||
/* Generated stub for gossip_time_now */
|
||||
struct timeabs gossip_time_now(const struct routing_state *rstate UNNEEDED)
|
||||
{ fprintf(stderr, "gossip_time_now called!\n"); abort(); }
|
||||
/* Generated stub for got_pong */
|
||||
const char *got_pong(const u8 *pong UNNEEDED, size_t *num_pings_outstanding UNNEEDED)
|
||||
{ fprintf(stderr, "got_pong called!\n"); abort(); }
|
||||
|
Loading…
Reference in New Issue
Block a user