mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-19 13:27:35 +02:00
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.
This commit is contained in:
parent
064859bbad
commit
d9e477c4dc
5 changed files with 34 additions and 42 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue