mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 14:42:40 +01:00
gossmap: ensure htables are always tal objects.
We want to change the htable allocator to use tal, which will need this. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
763d02e424
commit
4a570c9419
1 changed files with 17 additions and 15 deletions
|
@ -59,10 +59,10 @@ struct gossmap {
|
|||
size_t map_end, map_size;
|
||||
|
||||
/* Map of node id -> node */
|
||||
struct nodeidx_htable nodes;
|
||||
struct nodeidx_htable *nodes;
|
||||
|
||||
/* Map of short_channel_id id -> channel */
|
||||
struct chanidx_htable channels;
|
||||
struct chanidx_htable *channels;
|
||||
|
||||
/* Array of nodes, so we can use simple index. */
|
||||
struct gossmap_node *node_arr;
|
||||
|
@ -235,7 +235,7 @@ static struct node_id nodeidx_id(const ptrint_t *pidx)
|
|||
struct gossmap_node *gossmap_find_node(const struct gossmap *map,
|
||||
const struct node_id *id)
|
||||
{
|
||||
ptrint_t *pi = nodeidx_htable_get(&map->nodes, *id);
|
||||
ptrint_t *pi = nodeidx_htable_get(map->nodes, *id);
|
||||
if (pi)
|
||||
return ptrint2node(pi);
|
||||
return NULL;
|
||||
|
@ -244,7 +244,7 @@ struct gossmap_node *gossmap_find_node(const struct gossmap *map,
|
|||
struct gossmap_chan *gossmap_find_chan(const struct gossmap *map,
|
||||
const struct short_channel_id *scid)
|
||||
{
|
||||
ptrint_t *pi = chanidx_htable_get(&map->channels, *scid);
|
||||
ptrint_t *pi = chanidx_htable_get(map->channels, *scid);
|
||||
if (pi)
|
||||
return ptrint2chan(pi);
|
||||
return NULL;
|
||||
|
@ -295,7 +295,7 @@ static u32 new_node(struct gossmap *map)
|
|||
static void remove_node(struct gossmap *map, struct gossmap_node *node)
|
||||
{
|
||||
u32 nodeidx = gossmap_node_idx(map, node);
|
||||
if (!nodeidx_htable_del(&map->nodes, node2ptrint(node)))
|
||||
if (!nodeidx_htable_del(map->nodes, node2ptrint(node)))
|
||||
abort();
|
||||
node->nann_off = map->freed_nodes;
|
||||
free(node->chan_idxs);
|
||||
|
@ -359,7 +359,7 @@ static struct gossmap_chan *new_channel(struct gossmap *map,
|
|||
chan->half[1].nodeidx = n2idx;
|
||||
node_add_channel(map->node_arr + n1idx, gossmap_chan_idx(map, chan));
|
||||
node_add_channel(map->node_arr + n2idx, gossmap_chan_idx(map, chan));
|
||||
chanidx_htable_add(&map->channels, chan2ptrint(chan));
|
||||
chanidx_htable_add(map->channels, chan2ptrint(chan));
|
||||
|
||||
return chan;
|
||||
}
|
||||
|
@ -386,7 +386,7 @@ static void remove_chan_from_node(struct gossmap *map,
|
|||
void gossmap_remove_chan(struct gossmap *map, struct gossmap_chan *chan)
|
||||
{
|
||||
u32 chanidx = gossmap_chan_idx(map, chan);
|
||||
if (!chanidx_htable_del(&map->channels, chan2ptrint(chan)))
|
||||
if (!chanidx_htable_del(map->channels, chan2ptrint(chan)))
|
||||
abort();
|
||||
remove_chan_from_node(map, gossmap_nth_node(map, chan, 0), chanidx);
|
||||
remove_chan_from_node(map, gossmap_nth_node(map, chan, 1), chanidx);
|
||||
|
@ -460,10 +460,10 @@ static struct gossmap_chan *add_channel(struct gossmap *map,
|
|||
|
||||
/* Now we have a channel, we can add nodes to htable */
|
||||
if (!n[0])
|
||||
nodeidx_htable_add(&map->nodes,
|
||||
nodeidx_htable_add(map->nodes,
|
||||
node2ptrint(map->node_arr + nidx[0]));
|
||||
if (!n[1])
|
||||
nodeidx_htable_add(&map->nodes,
|
||||
nodeidx_htable_add(map->nodes,
|
||||
node2ptrint(map->node_arr + nidx[1]));
|
||||
|
||||
return chan;
|
||||
|
@ -678,8 +678,10 @@ static bool load_gossip_store(struct gossmap *map, size_t *num_rejected)
|
|||
* and 10000 nodes, let's assume each channel gets about 750 bytes.
|
||||
*
|
||||
* We halve this, since often some records are deleted. */
|
||||
chanidx_htable_init_sized(&map->channels, map->map_size / 750 / 2);
|
||||
nodeidx_htable_init_sized(&map->nodes, map->map_size / 2500 / 2);
|
||||
map->channels = tal(map, struct chanidx_htable);
|
||||
chanidx_htable_init_sized(map->channels, map->map_size / 750 / 2);
|
||||
map->nodes = tal(map, struct nodeidx_htable);
|
||||
nodeidx_htable_init_sized(map->nodes, map->map_size / 2500 / 2);
|
||||
|
||||
map->num_chan_arr = map->map_size / 750 / 2 + 1;
|
||||
map->chan_arr = tal_arr(map, struct gossmap_chan, map->num_chan_arr);
|
||||
|
@ -697,8 +699,8 @@ static void destroy_map(struct gossmap *map)
|
|||
{
|
||||
if (map->mmap)
|
||||
munmap(map->mmap, map->map_size);
|
||||
chanidx_htable_clear(&map->channels);
|
||||
nodeidx_htable_clear(&map->nodes);
|
||||
chanidx_htable_clear(map->channels);
|
||||
nodeidx_htable_clear(map->nodes);
|
||||
|
||||
for (size_t i = 0; i < tal_count(map->node_arr); i++)
|
||||
free(map->node_arr[i].chan_idxs);
|
||||
|
@ -1059,7 +1061,7 @@ struct gossmap_node *gossmap_nth_node(const struct gossmap *map,
|
|||
|
||||
size_t gossmap_num_nodes(const struct gossmap *map)
|
||||
{
|
||||
return nodeidx_htable_count(&map->nodes);
|
||||
return nodeidx_htable_count(map->nodes);
|
||||
}
|
||||
|
||||
static struct gossmap_node *node_iter(const struct gossmap *map, size_t start)
|
||||
|
@ -1084,7 +1086,7 @@ struct gossmap_node *gossmap_next_node(const struct gossmap *map,
|
|||
|
||||
size_t gossmap_num_chans(const struct gossmap *map)
|
||||
{
|
||||
return chanidx_htable_count(&map->channels);
|
||||
return chanidx_htable_count(map->channels);
|
||||
}
|
||||
|
||||
static struct gossmap_chan *chan_iter(const struct gossmap *map, size_t start)
|
||||
|
|
Loading…
Add table
Reference in a new issue