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

Function map_catchup

common/gossmap.c:819–942  ·  view source on GitHub ↗

Returns false only if must_be_clean is true. */

Source from the content-addressed store, hash-verified

817
818/* Returns false only if must_be_clean is true. */
819static bool map_catchup(struct gossmap *map,
820 void (*dyingcb)(struct short_channel_id scid,
821 u32 blockheight,
822 u64 offset,
823 void *cb_arg),
824 void *cb_arg,
825 bool must_be_clean,
826 bool *changed)
827{
828 size_t reclen, num_bad_cupdates = 0;
829
830 *changed = false;
831
832 for (; map->map_end + sizeof(struct gossip_hdr) < map->map_size;
833 map->map_end += reclen) {
834 struct gossip_hdr ghdr;
835 u64 off;
836 u16 msglen, type, flags;
837
838 map_copy(map, map->map_end, &ghdr, sizeof(ghdr));
839 msglen = be16_to_cpu(ghdr.len);
840 reclen = msglen + sizeof(ghdr);
841
842 flags = be16_to_cpu(ghdr.flags);
843
844 /* Not finished, this can happen. */
845 if (!(flags & GOSSIP_STORE_COMPLETED_BIT))
846 break;
847
848 if (flags & GOSSIP_STORE_DELETED_BIT) {
849 map->num_dead++;
850 map->deleted_bytes_read += reclen;
851 continue;
852 }
853
854 /* Partial write, should not happen with completed records. */
855 if (map->map_end + reclen > map->map_size)
856 break;
857
858 /* FIXME: In corruption, we can see zeroes here: don't crash. */
859 if (msglen < sizeof(be16)) {
860 map->logcb(map->cbarg,
861 LOG_BROKEN,
862 "Truncated gossmap record @%"PRIu64
863 "/%"PRIu64" (len %zu): waiting%s",
864 map->map_end, map->map_size, msglen,
865 gossmap_has_mmap(map) ? " and disabling mmap" : "");
866 gossmap_disable_mmap(map);
867 if (must_be_clean)
868 return false;
869 break;
870 }
871
872 off = map->map_end + sizeof(ghdr);
873 type = map_be16(map, off);
874
875 if (!csum_matches(map, off,
876 be32_to_cpu(ghdr.timestamp),

Callers 3

reopen_storeFunction · 0.85
load_gossip_storeFunction · 0.85
gossmap_refreshFunction · 0.85

Calls 14

map_copyFunction · 0.85
be16_to_cpuFunction · 0.85
gossmap_has_mmapFunction · 0.85
gossmap_disable_mmapFunction · 0.85
map_be16Function · 0.85
csum_matchesFunction · 0.85
be32_to_cpuFunction · 0.85
tal_hexstrFunction · 0.85
add_channelFunction · 0.85
update_channelFunction · 0.85
reopen_storeFunction · 0.85

Tested by

no test coverage detected