MCPcopy Create free account
hub / github.com/ElementsProject/lightning / load_gossip_store

Function load_gossip_store

common/gossmap.c:654–694  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

652}
653
654static bool load_gossip_store(struct gossmap *map, size_t *num_rejected)
655{
656 map->fd = open(map->fname, O_RDONLY);
657 if (map->fd < 0)
658 return false;
659
660 map->map_size = lseek(map->fd, 0, SEEK_END);
661 map->local = NULL;
662 /* If this fails, we fall back to read */
663 map->mmap = mmap(NULL, map->map_size, PROT_READ, MAP_SHARED, map->fd, 0);
664 if (map->mmap == MAP_FAILED)
665 map->mmap = NULL;
666
667 /* We only support major version 0 */
668 if (GOSSIP_STORE_MAJOR_VERSION(map_u8(map, 0)) != 0) {
669 close(map->fd);
670 if (map->mmap)
671 munmap(map->mmap, map->map_size);
672 errno = EINVAL;
673 return false;
674 }
675
676 /* Since channel_announcement is ~430 bytes, and channel_update is 136,
677 * node_announcement is 144, and current topology has 35000 channels
678 * and 10000 nodes, let's assume each channel gets about 750 bytes.
679 *
680 * We halve this, since often some records are deleted. */
681 chanidx_htable_init_sized(&map->channels, map->map_size / 750 / 2);
682 nodeidx_htable_init_sized(&map->nodes, map->map_size / 2500 / 2);
683
684 map->num_chan_arr = map->map_size / 750 / 2 + 1;
685 map->chan_arr = tal_arr(map, struct gossmap_chan, map->num_chan_arr);
686 map->freed_chans = init_chan_arr(map->chan_arr, 0);
687 map->num_node_arr = map->map_size / 2500 / 2 + 1;
688 map->node_arr = tal_arr(map, struct gossmap_node, map->num_node_arr);
689 map->freed_nodes = init_node_arr(map->node_arr, 0);
690
691 map->map_end = 1;
692 map_catchup(map, num_rejected);
693 return true;
694}
695
696static void destroy_map(struct gossmap *map)
697{

Callers 1

gossmap_loadFunction · 0.85

Calls 4

map_u8Function · 0.85
init_chan_arrFunction · 0.85
init_node_arrFunction · 0.85
map_catchupFunction · 0.85

Tested by

no test coverage detected