ChainstateManager::LoadExternalBlockFile

Import blocks from an external file

Synopsis

Declared in <validation.h>

void
LoadExternalBlockFile(
    AutoFile& file_in,
    FlatFilePos* dbp = nullptr,
    std::multimap<uint256, FlatFilePos>* blocks_with_unknown_parent = nullptr);

Description

During reindexing, this function is called for each block file (datadir/blocks/blk?????.dat). It reads all blocks contained in the given file and attempts to process them (add them to the block index). The blocks may be out of order within each file and across files. Often this function reads a block but finds that its parent hasn't been read yet, so the block can't be processed yet. The function will add an entry to the blocks_with_unknown_parent map (which is passed as an argument), so that when the block's parent is later read and processed, this function can re-read the child block from disk and process it.

Because a block's parent may be in a later file, not just later in the same file, the blocks_with_unknown_parent map must be passed in and out with each call. It's a multimap, rather than just a map, because multiple blocks may have the same parent (when chain splits or stale blocks exist). It maps from parent-hash to child-disk-position.

This function can also be used to read blocks from user-specified block files using the -loadblock= option. There's no unknown-parent tracking, so the last two arguments are omitted.

Parameters

NameDescription
file_in [in]File containing blocks to read
dbp [in](optional) Disk block position (only for reindex)
blocks_with_unknown_parent [inout](optional) Map of disk positions for blocks with unknown parent, key is parent block hash (only used for reindex)