Skip to content

Commit d6af06d

Browse files
TheBlueMattsipa
authored andcommitted
Dont create pcoinsTip until after ReplayBlocks.
This requires that we not access pcoinsTip in InitBlockIndex's FlushStateToDisk (so we just skip it until later in AppInitMain) and the LoadChainTip in LoadBlockIndex (which there is already one later in AppinitMain, after ReplayBlocks, so skipping it there is fine). Includes some simplifications by Suhas Daftuar and Pieter Wuille.
1 parent eaca1b7 commit d6af06d

File tree

3 files changed

+2
-12
lines changed

3 files changed

+2
-12
lines changed

src/init.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,6 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
13851385
pblocktree = new CBlockTreeDB(nBlockTreeDBCache, false, fReindex);
13861386
pcoinsdbview = new CCoinsViewDB(nCoinDBCache, false, fReindex || fReindexChainState);
13871387
pcoinscatcher = new CCoinsViewErrorCatcher(pcoinsdbview);
1388-
pcoinsTip = new CCoinsViewCache(pcoinscatcher);
13891388

13901389
if (fReindex) {
13911390
pblocktree->WriteReindexing(true);
@@ -1433,7 +1432,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
14331432
strLoadError = _("Unable to replay blocks. You will need to rebuild the database using -reindex-chainstate.");
14341433
break;
14351434
}
1436-
pcoinsTip->SetBestBlock(pcoinsdbview->GetBestBlock()); // TODO: only initialize pcoinsTip after ReplayBlocks
1435+
pcoinsTip = new CCoinsViewCache(pcoinscatcher);
14371436
LoadChainTip(chainparams);
14381437

14391438
if (!fReindex && chainActive.Tip() != NULL) {

src/txdb.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) {
8585
size_t changed = 0;
8686
size_t batch_size = (size_t)GetArg("-dbbatchsize", nDefaultDbBatchSize);
8787
int crash_simulate = GetArg("-dbcrashratio", 0);
88+
assert(!hashBlock.IsNull());
8889

8990
uint256 old_tip = GetBestBlock();
9091
if (old_tip.IsNull()) {
@@ -96,13 +97,6 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) {
9697
}
9798
}
9899

99-
if (hashBlock.IsNull()) {
100-
// Initial flush, nothing to write.
101-
assert(mapCoins.empty());
102-
assert(old_tip.IsNull());
103-
return true;
104-
}
105-
106100
// In the first batch, mark the database as being in the middle of a
107101
// transition from old_tip to hashBlock.
108102
// A vector is used for future extensibility, as we may want to support

src/validation.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3420,7 +3420,6 @@ bool static LoadBlockIndexDB(const CChainParams& chainparams)
34203420
pblocktree->ReadFlag("txindex", fTxIndex);
34213421
LogPrintf("%s: transaction index %s\n", __func__, fTxIndex ? "enabled" : "disabled");
34223422

3423-
LoadChainTip(chainparams);
34243423
return true;
34253424
}
34263425

@@ -3783,8 +3782,6 @@ bool InitBlockIndex(const CChainParams& chainparams)
37833782
CBlockIndex *pindex = AddToBlockIndex(block);
37843783
if (!ReceivedBlockTransactions(block, state, pindex, blockPos, chainparams.GetConsensus()))
37853784
return error("LoadBlockIndex(): genesis block not accepted");
3786-
// Force a chainstate write so that when we VerifyDB in a moment, it doesn't check stale data
3787-
return FlushStateToDisk(chainparams, state, FLUSH_STATE_ALWAYS);
37883785
} catch (const std::runtime_error& e) {
37893786
return error("LoadBlockIndex(): failed to initialize block database: %s", e.what());
37903787
}

0 commit comments

Comments
 (0)