LarryRuane’s comment in #16981:
Does it bother anyone else that this is
static
? This is global state, which, in general, equals evil. It must be static, given that it’s declared here, since its state must persist across calls to this function (very often, a block and its parent are in differentblk
files). We could eliminate this global state by allocating this map in the caller of this function,src/init.cpp: ThreadImport()
, and passing it by reference toLoadExternalBlockFile()
.Another thing that seems missing from the current design is, what happens if there are leftover entries in this map after reindexing has completed? That means we’ve read blocks from disk but never found their parent blocks. In my testing, this map is empty at the end of reindexing, as expected. But what if it wasn’t? That would mean we’re missing one or more
blocks/blk00nnn.dat
files, or some blocks from those files. Isn’t that worth at least aLogPrintf()
? Making this change would also require moving the map out to the caller, because this function doesn’t know if it will be called again.