Browse Source

gossip: instead of refresh interval, have routing know prune_timeout.

This is twice the 'update_channel_interval' we get handed.

We delete the non-existent channel_add_connection and delete_connection
declarations from the header too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
33726b0a08
  1. 23
      gossipd/gossip.c
  2. 8
      gossipd/routing.c
  3. 13
      gossipd/routing.h
  4. 2
      gossipd/test/run-bench-find_route.c
  5. 2
      gossipd/test/run-find_route-specific.c
  6. 2
      gossipd/test/run-find_route.c
  7. 8
      tests/test_lightningd.py

23
gossipd/gossip.c

@ -83,8 +83,6 @@ struct daemon {
/* To make sure our node_announcement timestamps increase */ /* To make sure our node_announcement timestamps increase */
u32 last_announce_timestamp; u32 last_announce_timestamp;
u32 update_channel_interval;
}; };
/* Peers we're trying to reach. */ /* Peers we're trying to reach. */
@ -1331,19 +1329,19 @@ static void gossip_send_keepalive_update(struct routing_state *rstate,
} }
static void gossip_prune_network(struct daemon *daemon) static void gossip_refresh_network(struct daemon *daemon)
{ {
u64 now = time_now().ts.tv_sec; u64 now = time_now().ts.tv_sec;
struct node_map_iter it; struct node_map_iter it;
/* Anything below this highwater mark ought to be pruned */ /* Anything below this highwater mark ought to be pruned */
s64 highwater = now - 2*daemon->update_channel_interval; s64 highwater = now - daemon->rstate->prune_timeout;
struct node *n; struct node *n;
const tal_t *pruned = tal_tmpctx(daemon); const tal_t *pruned = tal_tmpctx(daemon);
/* Schedule next run now */ /* Schedule next run now */
new_reltimer(&daemon->timers, daemon, new_reltimer(&daemon->timers, daemon,
time_from_sec(daemon->update_channel_interval/2), time_from_sec(daemon->rstate->prune_timeout/4),
gossip_prune_network, daemon); gossip_refresh_network, daemon);
/* Find myself in the network */ /* Find myself in the network */
n = get_node(daemon->rstate, &daemon->id); n = get_node(daemon->rstate, &daemon->id);
@ -1361,7 +1359,7 @@ static void gossip_prune_network(struct daemon *daemon)
continue; continue;
} }
if (now - nc->last_timestamp < daemon->update_channel_interval) { if (now - nc->last_timestamp < daemon->rstate->prune_timeout / 2) {
/* No need to send a keepalive update message */ /* No need to send a keepalive update message */
continue; continue;
} }
@ -1522,21 +1520,24 @@ static struct io_plan *gossip_init(struct daemon_conn *master,
{ {
struct bitcoin_blkid chain_hash; struct bitcoin_blkid chain_hash;
u16 port; u16 port;
u32 update_channel_interval;
if (!fromwire_gossipctl_init( if (!fromwire_gossipctl_init(
daemon, msg, &daemon->broadcast_interval, &chain_hash, daemon, msg, &daemon->broadcast_interval, &chain_hash,
&daemon->id, &port, &daemon->globalfeatures, &daemon->id, &port, &daemon->globalfeatures,
&daemon->localfeatures, &daemon->wireaddrs, daemon->rgb, &daemon->localfeatures, &daemon->wireaddrs, daemon->rgb,
daemon->alias, &daemon->update_channel_interval)) { daemon->alias, &update_channel_interval)) {
master_badmsg(WIRE_GOSSIPCTL_INIT, msg); master_badmsg(WIRE_GOSSIPCTL_INIT, msg);
} }
daemon->rstate = new_routing_state(daemon, &chain_hash, &daemon->id); /* Prune time is twice update time */
daemon->rstate = new_routing_state(daemon, &chain_hash, &daemon->id,
update_channel_interval * 2);
setup_listeners(daemon, port); setup_listeners(daemon, port);
new_reltimer(&daemon->timers, daemon, new_reltimer(&daemon->timers, daemon,
time_from_sec(daemon->update_channel_interval/2), time_from_sec(daemon->rstate->prune_timeout/4),
gossip_prune_network, daemon); gossip_refresh_network, daemon);
return daemon_conn_read_next(master->conn, master); return daemon_conn_read_next(master->conn, master);
} }

8
gossipd/routing.c

@ -94,13 +94,15 @@ 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 bitcoin_blkid *chain_hash, const struct bitcoin_blkid *chain_hash,
const struct pubkey *local_id) const struct pubkey *local_id,
u32 prune_timeout)
{ {
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);
rstate->broadcasts = new_broadcast_state(rstate); rstate->broadcasts = new_broadcast_state(rstate);
rstate->chain_hash = *chain_hash; rstate->chain_hash = *chain_hash;
rstate->local_id = *local_id; rstate->local_id = *local_id;
rstate->prune_timeout = prune_timeout;
list_head_init(&rstate->pending_cannouncement); list_head_init(&rstate->pending_cannouncement);
uintmap_init(&rstate->channels); uintmap_init(&rstate->channels);
@ -242,9 +244,9 @@ static struct node_connection *new_node_connection(struct routing_state *rstate,
c->unroutable_until = 0; c->unroutable_until = 0;
c->active = false; c->active = false;
c->flags = idx; c->flags = idx;
/* We haven't seen channel_update: give it an hour before we prune, /* 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 - (1209600 - 3600); c->last_timestamp = time_now().ts.tv_sec - rstate->prune_timeout/2;
/* Hook it into in/out arrays. */ /* Hook it into in/out arrays. */
chan->connections[idx] = c; chan->connections[idx] = c;

13
gossipd/routing.h

@ -157,6 +157,9 @@ struct routing_state {
/* Our own ID so we can identify local channels */ /* Our own ID so we can identify local channels */
struct pubkey local_id; struct pubkey local_id;
/* How old does a channel have to be before we prune it? */
u32 prune_timeout;
/* A map of channels indexed by short_channel_ids */ /* A map of channels indexed by short_channel_ids */
UINTMAP(struct routing_channel*) channels; UINTMAP(struct routing_channel*) channels;
}; };
@ -177,7 +180,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 bitcoin_blkid *chain_hash, const struct bitcoin_blkid *chain_hash,
const struct pubkey *local_id); const struct pubkey *local_id,
u32 prune_timeout);
struct routing_channel *new_routing_channel(struct routing_state *rstate, struct routing_channel *new_routing_channel(struct routing_state *rstate,
const struct short_channel_id *scid, const struct short_channel_id *scid,
@ -236,12 +240,7 @@ void routing_failure(struct routing_state *rstate,
void mark_channel_unroutable(struct routing_state *rstate, void mark_channel_unroutable(struct routing_state *rstate,
const struct short_channel_id *channel); const struct short_channel_id *channel);
/* Add the connection to the channel */ void route_prune(struct routing_state *rstate);
void channel_add_connection(struct routing_state *rstate,
struct routing_channel *chan,
struct node_connection *nc);
void delete_connection(struct routing_channel *chan, int idx);
/* Utility function that, given a source and a destination, gives us /* Utility function that, given a source and a destination, gives us
* the direction bit the matching channel should get */ * the direction bit the matching channel should get */

2
gossipd/test/run-bench-find_route.c

@ -191,7 +191,7 @@ int main(int argc, char *argv[])
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
| SECP256K1_CONTEXT_SIGN); | SECP256K1_CONTEXT_SIGN);
rstate = new_routing_state(ctx, &zerohash, &me); rstate = new_routing_state(ctx, &zerohash, &me, 0);
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");

2
gossipd/test/run-find_route-specific.c

@ -110,7 +110,7 @@ int main(void)
strlen("02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06"), strlen("02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06"),
&c); &c);
rstate = new_routing_state(ctx, &zerohash, &a); rstate = new_routing_state(ctx, &zerohash, &a, 0);
/* [{'active': True, 'short_id': '6990:2:1/1', 'fee_per_kw': 10, 'delay': 5, 'flags': 1, 'destination': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'source': '02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06', 'last_update': 1504064344}, */ /* [{'active': True, 'short_id': '6990:2:1/1', 'fee_per_kw': 10, 'delay': 5, 'flags': 1, 'destination': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'source': '02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06', 'last_update': 1504064344}, */
nc = get_or_make_connection(rstate, &c, &b, "6990:2:1"); nc = get_or_make_connection(rstate, &c, &b, "6990:2:1");

2
gossipd/test/run-find_route.c

@ -146,7 +146,7 @@ int main(void)
| SECP256K1_CONTEXT_SIGN); | SECP256K1_CONTEXT_SIGN);
memset(&tmp, 'a', sizeof(tmp)); memset(&tmp, 'a', sizeof(tmp));
rstate = new_routing_state(ctx, &zerohash, &a); rstate = new_routing_state(ctx, &zerohash, &a, 0);
pubkey_from_privkey(&tmp, &a); pubkey_from_privkey(&tmp, &a);
new_node(rstate, &a); new_node(rstate, &a);

8
tests/test_lightningd.py

@ -1854,7 +1854,7 @@ class LightningDTests(BaseLightningDTests):
assert [c['active'] for c in l2.rpc.listchannels()['channels']] == [True, True] assert [c['active'] for c in l2.rpc.listchannels()['channels']] == [True, True]
assert [c['public'] for c in l2.rpc.listchannels()['channels']] == [True, True] assert [c['public'] for c in l2.rpc.listchannels()['channels']] == [True, True]
@unittest.skip("Temporarily broken for short pruning times") @unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1 for --dev-broadcast-interval")
def test_gossip_pruning(self): def test_gossip_pruning(self):
""" Create channel and see it being updated in time before pruning """ Create channel and see it being updated in time before pruning
""" """
@ -1889,6 +1889,12 @@ class LightningDTests(BaseLightningDTests):
]) ])
# Now kill l3, so that l2 and l1 can prune it from their view after 10 seconds # Now kill l3, so that l2 and l1 can prune it from their view after 10 seconds
# FIXME: This sleep() masks a real bug: that channeld sends a
# channel_update message (to disable the channel) with same
# timestamp as the last keepalive, and thus is ignored. The minimal
# fix is to backdate the keepalives 1 second, but maybe we should
# simply have gossipd generate all updates?
time.sleep(1) time.sleep(1)
l3.stop() l3.stop()

Loading…
Cancel
Save