From d6af06d68aae985436cbc942f0d11078041d121b Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 17 Apr 2017 11:41:10 -0400 Subject: [PATCH] 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. --- src/init.cpp | 3 +-- src/txdb.cpp | 8 +------- src/validation.cpp | 3 --- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 51f0d400356..794c6bc45e3 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1385,7 +1385,6 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler) pblocktree = new CBlockTreeDB(nBlockTreeDBCache, false, fReindex); pcoinsdbview = new CCoinsViewDB(nCoinDBCache, false, fReindex || fReindexChainState); pcoinscatcher = new CCoinsViewErrorCatcher(pcoinsdbview); - pcoinsTip = new CCoinsViewCache(pcoinscatcher); if (fReindex) { pblocktree->WriteReindexing(true); @@ -1433,7 +1432,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler) strLoadError = _("Unable to replay blocks. You will need to rebuild the database using -reindex-chainstate."); break; } - pcoinsTip->SetBestBlock(pcoinsdbview->GetBestBlock()); // TODO: only initialize pcoinsTip after ReplayBlocks + pcoinsTip = new CCoinsViewCache(pcoinscatcher); LoadChainTip(chainparams); if (!fReindex && chainActive.Tip() != NULL) { diff --git a/src/txdb.cpp b/src/txdb.cpp index 7de11cc6172..4cdfc7d6f5f 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -85,6 +85,7 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { size_t changed = 0; size_t batch_size = (size_t)GetArg("-dbbatchsize", nDefaultDbBatchSize); int crash_simulate = GetArg("-dbcrashratio", 0); + assert(!hashBlock.IsNull()); uint256 old_tip = GetBestBlock(); if (old_tip.IsNull()) { @@ -96,13 +97,6 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { } } - if (hashBlock.IsNull()) { - // Initial flush, nothing to write. - assert(mapCoins.empty()); - assert(old_tip.IsNull()); - return true; - } - // In the first batch, mark the database as being in the middle of a // transition from old_tip to hashBlock. // A vector is used for future extensibility, as we may want to support diff --git a/src/validation.cpp b/src/validation.cpp index 77b96be1e51..6100ccb33dd 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3420,7 +3420,6 @@ bool static LoadBlockIndexDB(const CChainParams& chainparams) pblocktree->ReadFlag("txindex", fTxIndex); LogPrintf("%s: transaction index %s\n", __func__, fTxIndex ? "enabled" : "disabled"); - LoadChainTip(chainparams); return true; } @@ -3783,8 +3782,6 @@ bool InitBlockIndex(const CChainParams& chainparams) CBlockIndex *pindex = AddToBlockIndex(block); if (!ReceivedBlockTransactions(block, state, pindex, blockPos, chainparams.GetConsensus())) return error("LoadBlockIndex(): genesis block not accepted"); - // Force a chainstate write so that when we VerifyDB in a moment, it doesn't check stale data - return FlushStateToDisk(chainparams, state, FLUSH_STATE_ALWAYS); } catch (const std::runtime_error& e) { return error("LoadBlockIndex(): failed to initialize block database: %s", e.what()); }