[#ChainstateManager-LoadExternalBlockFile]
= xref:ChainstateManager.adoc[ChainstateManager]::LoadExternalBlockFile
:relfileprefix: ../
:mrdocs:

Import blocks from an external file

== Synopsis

Declared in `&lt;validation&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
void
LoadExternalBlockFile(
    xref:AutoFile.adoc[AutoFile]& file&lowbar;in,
    xref:FlatFilePos.adoc[FlatFilePos]* dbp = nullptr,
    std::multimap&lt;uint256, FlatFilePos&gt;* blocks&lowbar;with&lowbar;unknown&lowbar;parent = nullptr);
----

== Description

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

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

This function can also be used to read blocks from user&hyphen;specified block files using the &hyphen;loadblock&equals; option&period; There&apos;s no unknown&hyphen;parent tracking, so the last two arguments are omitted&period;

== Parameters

[cols="1,4"]
|===
| Name| Description
| *file&lowbar;in* [in]
| File containing blocks to read
| *dbp* [in]
| (optional) Disk block position (only for reindex)
| *blocks&lowbar;with&lowbar;unknown&lowbar;parent* [inout]
| (optional) Map of disk positions for blocks with unknown parent, key is parent block hash (only used for reindex)
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
