mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 01:24:26 +01:00
gossipd: simplify pruning code.
If we make destroy_node() remove itself from the map, then we simply need to free it. We can batch the frees (as we need) simply by reparenting all the pruned nodes onto a single temporary parent, then freeing it, relying on tal's internal datastructures. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
792feb8532
commit
60e20b502e
@@ -123,8 +123,10 @@ bool node_map_node_eq(const struct node *n, const secp256k1_pubkey *key)
|
||||
return structeq(&n->id.pubkey, key);
|
||||
}
|
||||
|
||||
static void destroy_node(struct node *node)
|
||||
static void destroy_node(struct node *node, struct routing_state *rstate)
|
||||
{
|
||||
node_map_del(rstate->nodes, node);
|
||||
|
||||
/* These remove themselves from the array. */
|
||||
while (tal_count(node->in))
|
||||
tal_free(node->in[0]);
|
||||
@@ -155,7 +157,7 @@ static struct node *new_node(struct routing_state *rstate,
|
||||
n->last_timestamp = -1;
|
||||
n->addresses = tal_arr(n, struct wireaddr, 0);
|
||||
node_map_add(rstate->nodes, n);
|
||||
tal_add_destructor(n, destroy_node);
|
||||
tal_add_destructor2(n, destroy_node, rstate);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user