| 652 | } |
| 653 | |
| 654 | static 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 | |
| 696 | static void destroy_map(struct gossmap *map) |
| 697 | { |
no test coverage detected