mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 18:57:06 +01:00
dev: --dev-gossip-time so gossipd doesn't prune old data.
This is useful for canned data, such as the million channels project. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
b2c93beaed
commit
f8f6533dba
11 changed files with 64 additions and 13 deletions
|
@ -14,6 +14,7 @@ gossipctl_init,,alias,32*u8
|
||||||
gossipctl_init,,update_channel_interval,u32
|
gossipctl_init,,update_channel_interval,u32
|
||||||
gossipctl_init,,num_announcable,u16
|
gossipctl_init,,num_announcable,u16
|
||||||
gossipctl_init,,announcable,num_announcable*struct wireaddr
|
gossipctl_init,,announcable,num_announcable*struct wireaddr
|
||||||
|
gossipctl_init,,dev_gossip_time,?u32
|
||||||
|
|
||||||
# Pass JSON-RPC getnodes call through
|
# Pass JSON-RPC getnodes call through
|
||||||
gossip_getnodes_request,3005
|
gossip_getnodes_request,3005
|
||||||
|
|
|
|
@ -1859,6 +1859,7 @@ static struct io_plan *gossip_init(struct io_conn *conn,
|
||||||
const u8 *msg)
|
const u8 *msg)
|
||||||
{
|
{
|
||||||
u32 update_channel_interval;
|
u32 update_channel_interval;
|
||||||
|
u32 *dev_gossip_time;
|
||||||
|
|
||||||
if (!fromwire_gossipctl_init(daemon, msg,
|
if (!fromwire_gossipctl_init(daemon, msg,
|
||||||
/* 60,000 ms
|
/* 60,000 ms
|
||||||
|
@ -1871,7 +1872,8 @@ static struct io_plan *gossip_init(struct io_conn *conn,
|
||||||
/* 1 week in seconds
|
/* 1 week in seconds
|
||||||
* (unless --dev-channel-update-interval) */
|
* (unless --dev-channel-update-interval) */
|
||||||
&update_channel_interval,
|
&update_channel_interval,
|
||||||
&daemon->announcable)) {
|
&daemon->announcable,
|
||||||
|
&dev_gossip_time)) {
|
||||||
master_badmsg(WIRE_GOSSIPCTL_INIT, msg);
|
master_badmsg(WIRE_GOSSIPCTL_INIT, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1879,8 +1881,8 @@ static struct io_plan *gossip_init(struct io_conn *conn,
|
||||||
daemon->rstate = new_routing_state(daemon,
|
daemon->rstate = new_routing_state(daemon,
|
||||||
chainparams_by_chainhash(&daemon->chain_hash),
|
chainparams_by_chainhash(&daemon->chain_hash),
|
||||||
&daemon->id,
|
&daemon->id,
|
||||||
update_channel_interval * 2);
|
update_channel_interval * 2,
|
||||||
|
dev_gossip_time);
|
||||||
/* Load stored gossip messages */
|
/* Load stored gossip messages */
|
||||||
gossip_store_load(daemon->rstate, daemon->rstate->store);
|
gossip_store_load(daemon->rstate, daemon->rstate->store);
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,8 @@ static struct node_map *empty_node_map(const tal_t *ctx)
|
||||||
struct routing_state *new_routing_state(const tal_t *ctx,
|
struct routing_state *new_routing_state(const tal_t *ctx,
|
||||||
const struct chainparams *chainparams,
|
const struct chainparams *chainparams,
|
||||||
const struct pubkey *local_id,
|
const struct pubkey *local_id,
|
||||||
u32 prune_timeout)
|
u32 prune_timeout,
|
||||||
|
const u32 *dev_gossip_time)
|
||||||
{
|
{
|
||||||
struct routing_state *rstate = tal(ctx, struct routing_state);
|
struct routing_state *rstate = tal(ctx, struct routing_state);
|
||||||
rstate->nodes = empty_node_map(rstate);
|
rstate->nodes = empty_node_map(rstate);
|
||||||
|
@ -99,6 +100,16 @@ struct routing_state *new_routing_state(const tal_t *ctx,
|
||||||
rstate->pending_node_map = tal(ctx, struct pending_node_map);
|
rstate->pending_node_map = tal(ctx, struct pending_node_map);
|
||||||
pending_node_map_init(rstate->pending_node_map);
|
pending_node_map_init(rstate->pending_node_map);
|
||||||
|
|
||||||
|
|
||||||
|
#if DEVELOPER
|
||||||
|
if (dev_gossip_time) {
|
||||||
|
rstate->gossip_time = tal(rstate, struct timeabs);
|
||||||
|
rstate->gossip_time->ts.tv_sec = *dev_gossip_time;
|
||||||
|
rstate->gossip_time->ts.tv_nsec = 0;
|
||||||
|
} else
|
||||||
|
rstate->gossip_time = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
return rstate;
|
return rstate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,7 +281,7 @@ static void init_half_chan(struct routing_state *rstate,
|
||||||
c->message_flags = 0;
|
c->message_flags = 0;
|
||||||
/* We haven't seen channel_update: make it halfway to prune time,
|
/* We haven't seen channel_update: make it halfway to prune time,
|
||||||
* which should be older than any update we'd see. */
|
* which should be older than any update we'd see. */
|
||||||
c->last_timestamp = time_now().ts.tv_sec - rstate->prune_timeout/2;
|
c->last_timestamp = gossip_time_now(rstate).ts.tv_sec - rstate->prune_timeout/2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bad_gossip_order(const u8 *msg, const char *source,
|
static void bad_gossip_order(const u8 *msg, const char *source,
|
||||||
|
@ -1273,7 +1284,7 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update TAKES,
|
||||||
* - if the `timestamp` is unreasonably far in the future:
|
* - if the `timestamp` is unreasonably far in the future:
|
||||||
* - MAY discard the `channel_update`.
|
* - MAY discard the `channel_update`.
|
||||||
*/
|
*/
|
||||||
if (timestamp > time_now().ts.tv_sec + rstate->prune_timeout) {
|
if (timestamp > gossip_time_now(rstate).ts.tv_sec + rstate->prune_timeout) {
|
||||||
status_debug("Received channel_update for %s with far time %u",
|
status_debug("Received channel_update for %s with far time %u",
|
||||||
type_to_string(tmpctx, struct short_channel_id,
|
type_to_string(tmpctx, struct short_channel_id,
|
||||||
&short_channel_id),
|
&short_channel_id),
|
||||||
|
@ -1282,7 +1293,7 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update TAKES,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Note: we can consider old timestamps a case of "instant prune" too */
|
/* Note: we can consider old timestamps a case of "instant prune" too */
|
||||||
if (timestamp < time_now().ts.tv_sec - rstate->prune_timeout) {
|
if (timestamp < gossip_time_now(rstate).ts.tv_sec - rstate->prune_timeout) {
|
||||||
status_debug("Received channel_update for %s with old time %u",
|
status_debug("Received channel_update for %s with old time %u",
|
||||||
type_to_string(tmpctx, struct short_channel_id,
|
type_to_string(tmpctx, struct short_channel_id,
|
||||||
&short_channel_id),
|
&short_channel_id),
|
||||||
|
@ -1721,7 +1732,7 @@ void routing_failure(struct routing_state *rstate,
|
||||||
|
|
||||||
void route_prune(struct routing_state *rstate)
|
void route_prune(struct routing_state *rstate)
|
||||||
{
|
{
|
||||||
u64 now = time_now().ts.tv_sec;
|
u64 now = gossip_time_now(rstate).ts.tv_sec;
|
||||||
/* Anything below this highwater mark ought to be pruned */
|
/* Anything below this highwater mark ought to be pruned */
|
||||||
const s64 highwater = now - rstate->prune_timeout;
|
const s64 highwater = now - rstate->prune_timeout;
|
||||||
const tal_t *pruned = tal(NULL, char);
|
const tal_t *pruned = tal(NULL, char);
|
||||||
|
@ -1799,3 +1810,12 @@ bool handle_local_add_channel(struct routing_state *rstate, const u8 *msg)
|
||||||
new_chan(rstate, &scid, &rstate->local_id, &remote_node_id, sat);
|
new_chan(rstate, &scid, &rstate->local_id, &remote_node_id, sat);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct timeabs gossip_time_now(const struct routing_state *rstate)
|
||||||
|
{
|
||||||
|
#if DEVELOPER
|
||||||
|
if (rstate->gossip_time)
|
||||||
|
return *rstate->gossip_time;
|
||||||
|
#endif
|
||||||
|
return time_now();
|
||||||
|
}
|
||||||
|
|
|
@ -214,6 +214,11 @@ struct routing_state {
|
||||||
/* Cache for txout queries that failed. Allows us to skip failed
|
/* Cache for txout queries that failed. Allows us to skip failed
|
||||||
* checks if we get another announcement for the same scid. */
|
* checks if we get another announcement for the same scid. */
|
||||||
UINTMAP(bool) txout_failures;
|
UINTMAP(bool) txout_failures;
|
||||||
|
|
||||||
|
#if DEVELOPER
|
||||||
|
/* Override local time for gossip messages */
|
||||||
|
struct timeabs *gossip_time;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline struct chan *
|
static inline struct chan *
|
||||||
|
@ -234,7 +239,8 @@ struct route_hop {
|
||||||
struct routing_state *new_routing_state(const tal_t *ctx,
|
struct routing_state *new_routing_state(const tal_t *ctx,
|
||||||
const struct chainparams *chainparams,
|
const struct chainparams *chainparams,
|
||||||
const struct pubkey *local_id,
|
const struct pubkey *local_id,
|
||||||
u32 prune_timeout);
|
u32 prune_timeout,
|
||||||
|
const u32 *dev_gossip_time);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new bidirectional channel from id1 to id2 with the given
|
* Add a new bidirectional channel from id1 to id2 with the given
|
||||||
|
@ -345,4 +351,12 @@ bool handle_local_add_channel(struct routing_state *rstate, const u8 *msg);
|
||||||
void memleak_remove_routing_tables(struct htable *memtable,
|
void memleak_remove_routing_tables(struct htable *memtable,
|
||||||
const struct routing_state *rstate);
|
const struct routing_state *rstate);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the local time.
|
||||||
|
*
|
||||||
|
* This gets overridden in dev mode so we can use canned (stale) gossip.
|
||||||
|
*/
|
||||||
|
struct timeabs gossip_time_now(const struct routing_state *rstate);
|
||||||
|
|
||||||
#endif /* LIGHTNING_GOSSIPD_ROUTING_H */
|
#endif /* LIGHTNING_GOSSIPD_ROUTING_H */
|
||||||
|
|
|
@ -225,7 +225,7 @@ int main(int argc, char *argv[])
|
||||||
setup_tmpctx();
|
setup_tmpctx();
|
||||||
|
|
||||||
me = nodeid(0);
|
me = nodeid(0);
|
||||||
rstate = new_routing_state(tmpctx, NULL, &me, 0);
|
rstate = new_routing_state(tmpctx, NULL, &me, 0, NULL);
|
||||||
opt_register_noarg("--perfme", opt_set_bool, &perfme,
|
opt_register_noarg("--perfme", opt_set_bool, &perfme,
|
||||||
"Run perfme-start and perfme-stop around benchmark");
|
"Run perfme-start and perfme-stop around benchmark");
|
||||||
|
|
||||||
|
|
|
@ -184,7 +184,7 @@ int main(void)
|
||||||
strlen("02cca6c5c966fcf61d121e3a70e03a1cd9eeeea024b26ea666ce974d43b242e636"),
|
strlen("02cca6c5c966fcf61d121e3a70e03a1cd9eeeea024b26ea666ce974d43b242e636"),
|
||||||
&d);
|
&d);
|
||||||
|
|
||||||
rstate = new_routing_state(tmpctx, NULL, &a, 0);
|
rstate = new_routing_state(tmpctx, NULL, &a, 0, NULL);
|
||||||
|
|
||||||
/* [{'active': True, 'short_id': '6990:2:1/1', 'fee_per_kw': 10, 'delay': 5, 'message_flags': 0, 'channel_flags': 1, 'destination': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'source': '02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06', 'last_update': 1504064344}, */
|
/* [{'active': True, 'short_id': '6990:2:1/1', 'fee_per_kw': 10, 'delay': 5, 'message_flags': 0, 'channel_flags': 1, 'destination': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'source': '02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06', 'last_update': 1504064344}, */
|
||||||
|
|
||||||
|
|
|
@ -213,7 +213,7 @@ int main(void)
|
||||||
|
|
||||||
memset(&tmp, 'a', sizeof(tmp));
|
memset(&tmp, 'a', sizeof(tmp));
|
||||||
pubkey_from_privkey(&tmp, &a);
|
pubkey_from_privkey(&tmp, &a);
|
||||||
rstate = new_routing_state(tmpctx, NULL, &a, 0);
|
rstate = new_routing_state(tmpctx, NULL, &a, 0, NULL);
|
||||||
|
|
||||||
new_node(rstate, &a);
|
new_node(rstate, &a);
|
||||||
|
|
||||||
|
|
|
@ -164,7 +164,13 @@ void gossip_init(struct lightningd *ld, int connectd_fd)
|
||||||
get_offered_globalfeatures(tmpctx),
|
get_offered_globalfeatures(tmpctx),
|
||||||
ld->rgb,
|
ld->rgb,
|
||||||
ld->alias, ld->config.channel_update_interval,
|
ld->alias, ld->config.channel_update_interval,
|
||||||
ld->announcable);
|
ld->announcable,
|
||||||
|
#if DEVELOPER
|
||||||
|
ld->dev_gossip_time ? &ld->dev_gossip_time: NULL
|
||||||
|
#else
|
||||||
|
NULL
|
||||||
|
#endif
|
||||||
|
);
|
||||||
subd_send_msg(ld->gossip, msg);
|
subd_send_msg(ld->gossip, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,6 +116,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
|
||||||
ld->dev_disconnect_fd = -1;
|
ld->dev_disconnect_fd = -1;
|
||||||
ld->dev_subdaemon_fail = false;
|
ld->dev_subdaemon_fail = false;
|
||||||
ld->dev_allow_localhost = false;
|
ld->dev_allow_localhost = false;
|
||||||
|
ld->dev_gossip_time = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*~ These are CCAN lists: an embedded double-linked list. It's not
|
/*~ These are CCAN lists: an embedded double-linked list. It's not
|
||||||
|
|
|
@ -196,6 +196,9 @@ struct lightningd {
|
||||||
/* Allow and accept localhost node_announcement addresses */
|
/* Allow and accept localhost node_announcement addresses */
|
||||||
bool dev_allow_localhost;
|
bool dev_allow_localhost;
|
||||||
|
|
||||||
|
/* Timestamp to use for gossipd, iff non-zero */
|
||||||
|
u32 dev_gossip_time;
|
||||||
|
|
||||||
/* Things we've marked as not leaking. */
|
/* Things we've marked as not leaking. */
|
||||||
const void **notleaks;
|
const void **notleaks;
|
||||||
#endif /* DEVELOPER */
|
#endif /* DEVELOPER */
|
||||||
|
|
|
@ -475,6 +475,10 @@ static void dev_register_opts(struct lightningd *ld)
|
||||||
"--dev-channel-update-interval=<s>", opt_set_u32, opt_show_u32,
|
"--dev-channel-update-interval=<s>", opt_set_u32, opt_show_u32,
|
||||||
&ld->config.channel_update_interval,
|
&ld->config.channel_update_interval,
|
||||||
"Time in seconds between channel updates for our own channels.");
|
"Time in seconds between channel updates for our own channels.");
|
||||||
|
|
||||||
|
opt_register_arg("--dev-gossip-time", opt_set_u32, opt_show_u32,
|
||||||
|
&ld->dev_gossip_time,
|
||||||
|
"UNIX time to override gossipd to use.");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue