diff options
author | Martin Zumsande <mzumsande@gmail.com> | 2024-04-26 15:06:55 -0400 |
---|---|---|
committer | Martin Zumsande <mzumsande@gmail.com> | 2024-05-14 14:54:27 -0400 |
commit | d9e477c4dc39d9623ed66c35c06e28f94ae62ad5 (patch) | |
tree | ffdf694d028624320b245aa3745414f9771529b2 /src/validation.cpp | |
parent | 064859bbad6984a6ec85c744064abdf757807c58 (diff) | |
download | bitcoin-d9e477c4dc39d9623ed66c35c06e28f94ae62ad5.tar.xz |
validation, blockstorage: Separate code paths for reindex and saving new blocks
By calling SaveBlockToDisk only when we actually want to save a new
block to disk. In the reindex case, we now call UpdateBlockInfo
directly from validation.
This commit doesn't change behavior.
Diffstat (limited to 'src/validation.cpp')
-rw-r--r-- | src/validation.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/validation.cpp b/src/validation.cpp index 903f9caf13..2bdffdb1b0 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -4342,10 +4342,16 @@ bool ChainstateManager::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, // Write block to history file if (fNewBlock) *fNewBlock = true; try { - FlatFilePos blockPos{m_blockman.SaveBlockToDisk(block, pindex->nHeight, dbp)}; - if (blockPos.IsNull()) { - state.Error(strprintf("%s: Failed to find position to write new block to disk", __func__)); - return false; + FlatFilePos blockPos{}; + if (dbp) { + blockPos = *dbp; + m_blockman.UpdateBlockInfo(block, pindex->nHeight, blockPos); + } else { + blockPos = m_blockman.SaveBlockToDisk(block, pindex->nHeight); + if (blockPos.IsNull()) { + state.Error(strprintf("%s: Failed to find position to write new block to disk", __func__)); + return false; + } } ReceivedBlockTransactions(block, pindex, blockPos); } catch (const std::runtime_error& e) { @@ -4845,7 +4851,7 @@ bool Chainstate::LoadGenesisBlock() try { const CBlock& block = params.GenesisBlock(); - FlatFilePos blockPos{m_blockman.SaveBlockToDisk(block, 0, nullptr)}; + FlatFilePos blockPos{m_blockman.SaveBlockToDisk(block, 0)}; if (blockPos.IsNull()) { LogError("%s: writing genesis block to disk failed\n", __func__); return false; |