Fixes #23852
This allows pruning to work during the -loadblock
import process.
An example use case is where you have a clean set of block files and you want to create a pruned node from them, but you don’t want to alter the input set of block files.
#23852 noted that pruning was not working reliably during the loadblock import process. The reason why the loadblock process was not pruning regularly as it progressed is that the pruning process (BlockManager::FindFilesToPrune
) checks the tip height of the active chainstate, and CChainState::ActivateBestChain
was not called (which updates that tip height) in ThreadImport
until after all the import files were processed.
An example bash command line that makes it easy to import a bunch of block files:
0./src/qt/bitcoin-qt -debug -logthreadnames -datadir=/tmp/btc -prune=550 -loadblock=/readonly/btc/main/blk{00000..00043}.dat
One interesting side note is that CChainState::ActivateBestChain
can be called while the import process is running (in the loadblk
thread) by concurrent network message processing activity in the msghand
thread. For example, one way to reproduce this easily is with the getblockfrompeer
RPC (requesting a block with height greater than 100000) run from a node connected to an importing node. There are other ways too, but this is an easy way. I only mention this to explain how the max_prune_height=225719
log message in the original issue came to occur.