mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 18:57:06 +01:00
gossip: Forget nodes that have no associated channels anymore
Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
3a42e52bcd
commit
8f16f6ca09
1 changed files with 23 additions and 1 deletions
|
@ -1254,6 +1254,8 @@ static void gossip_prune_network(struct daemon *daemon)
|
||||||
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 - 2*daemon->update_channel_interval;
|
||||||
|
struct node *n;
|
||||||
|
struct node **prunednodes;
|
||||||
|
|
||||||
/* Schedule next run now */
|
/* Schedule next run now */
|
||||||
new_reltimer(&daemon->timers, daemon,
|
new_reltimer(&daemon->timers, daemon,
|
||||||
|
@ -1261,7 +1263,7 @@ static void gossip_prune_network(struct daemon *daemon)
|
||||||
gossip_prune_network, daemon);
|
gossip_prune_network, daemon);
|
||||||
|
|
||||||
/* Find myself in the network */
|
/* Find myself in the network */
|
||||||
struct node *n = node_map_get(daemon->rstate->nodes, &daemon->id.pubkey);
|
n = node_map_get(daemon->rstate->nodes, &daemon->id.pubkey);
|
||||||
if (!n) {
|
if (!n) {
|
||||||
status_trace("Could not find myself in the nodemap, do we have a channel yet?");
|
status_trace("Could not find myself in the nodemap, do we have a channel yet?");
|
||||||
return;
|
return;
|
||||||
|
@ -1318,6 +1320,26 @@ static void gossip_prune_network(struct daemon *daemon)
|
||||||
tal_free(nc);
|
tal_free(nc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Finally remove all nodes that do not have any edges
|
||||||
|
* anymore. Accumulate into prunednodes, and delete in the
|
||||||
|
* second loop. */
|
||||||
|
prunednodes = tal_arr(n, struct node*, 0);
|
||||||
|
for (n = node_map_first(daemon->rstate->nodes, &it); n;
|
||||||
|
n = node_map_next(daemon->rstate->nodes, &it)) {
|
||||||
|
if (tal_count(n->in) == 0 && tal_count(n->out) == 0) {
|
||||||
|
size_t count = tal_count(prunednodes);
|
||||||
|
tal_resize(&prunednodes, count + 1);
|
||||||
|
prunednodes[count] = n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i=0; i<tal_count(prunednodes); i++) {
|
||||||
|
node_map_del(daemon->rstate->nodes, prunednodes[i]);
|
||||||
|
tal_free(prunednodes[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
tal_free(prunednodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct io_plan *connection_in(struct io_conn *conn, struct daemon *daemon)
|
static struct io_plan *connection_in(struct io_conn *conn, struct daemon *daemon)
|
||||||
|
|
Loading…
Add table
Reference in a new issue