diff options
author | mruddy <6440430+mruddy@users.noreply.github.com> | 2022-04-24 08:00:38 -0400 |
---|---|---|
committer | mruddy <6440430+mruddy@users.noreply.github.com> | 2023-02-22 05:16:28 -0500 |
commit | c4981e7f63a3e0aeec1ef3dec040261e993dd724 (patch) | |
tree | b23c47b2556e766cd59c54364b55eef2e0d49b52 /src/validation.cpp | |
parent | 80f4979322b574be29c684b2e106804432420ebf (diff) |
prune, import: fixes #23852
allows pruning to work during the loadblock import process.
Diffstat (limited to 'src/validation.cpp')
-rw-r--r-- | src/validation.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/validation.cpp b/src/validation.cpp index c839647b29..3714335b39 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -4474,6 +4474,9 @@ void Chainstate::LoadExternalBlockFile( // next block, but it's still possible to rewind to the start of the current block (without a disk read). nRewind = nBlockPos + nSize; blkdat.SkipTo(nRewind); + + std::shared_ptr<CBlock> pblock{}; // needs to remain available after the cs_main lock is released to avoid duplicate reads from disk + { LOCK(cs_main); // detect out of order blocks, and store them for later @@ -4491,7 +4494,7 @@ void Chainstate::LoadExternalBlockFile( if (!pindex || (pindex->nStatus & BLOCK_HAVE_DATA) == 0) { // This block can be processed immediately; rewind to its start, read and deserialize it. blkdat.SetPos(nBlockPos); - std::shared_ptr<CBlock> pblock{std::make_shared<CBlock>()}; + pblock = std::make_shared<CBlock>(); blkdat >> *pblock; nRewind = blkdat.GetPos(); @@ -4515,6 +4518,21 @@ void Chainstate::LoadExternalBlockFile( } } + if (m_blockman.IsPruneMode() && !fReindex && pblock) { + // must update the tip for pruning to work while importing with -loadblock. + // this is a tradeoff to conserve disk space at the expense of time + // spent updating the tip to be able to prune. + // otherwise, ActivateBestChain won't be called by the import process + // until after all of the block files are loaded. ActivateBestChain can be + // called by concurrent network message processing. but, that is not + // reliable for the purpose of pruning while importing. + BlockValidationState state; + if (!ActivateBestChain(state, pblock)) { + LogPrint(BCLog::REINDEX, "failed to activate chain (%s)\n", state.ToString()); + break; + } + } + NotifyHeaderTip(*this); if (!blocks_with_unknown_parent) continue; |