refactoring: move ReplayBlocks under CChainState

pull/16743/head
James O'Beirne 6 years ago
parent bcf73d3b84
commit 3cf36736e5

@ -1545,7 +1545,7 @@ bool AppInitMain(InitInterfaces& interfaces)
} }
// ReplayBlocks is a no-op if we cleared the coinsviewdb with -reindex or -reindex-chainstate // ReplayBlocks is a no-op if we cleared the coinsviewdb with -reindex or -reindex-chainstate
if (!ReplayBlocks(chainparams, &::ChainstateActive().CoinsDB())) { if (!::ChainstateActive().ReplayBlocks(chainparams)) {
strLoadError = _("Unable to replay blocks. You will need to rebuild the database using -reindex-chainstate.").translated; strLoadError = _("Unable to replay blocks. You will need to rebuild the database using -reindex-chainstate.").translated;
break; break;
} }

@ -4091,13 +4091,14 @@ bool CChainState::RollforwardBlock(const CBlockIndex* pindex, CCoinsViewCache& i
return true; return true;
} }
bool CChainState::ReplayBlocks(const CChainParams& params, CCoinsView* view) bool CChainState::ReplayBlocks(const CChainParams& params)
{ {
LOCK(cs_main); LOCK(cs_main);
CCoinsViewCache cache(view); CCoinsView& db = this->CoinsDB();
CCoinsViewCache cache(&db);
std::vector<uint256> hashHeads = view->GetHeadBlocks(); std::vector<uint256> hashHeads = db.GetHeadBlocks();
if (hashHeads.empty()) return true; // We're already in a consistent state. if (hashHeads.empty()) return true; // We're already in a consistent state.
if (hashHeads.size() != 2) return error("ReplayBlocks(): unknown inconsistent state"); if (hashHeads.size() != 2) return error("ReplayBlocks(): unknown inconsistent state");
@ -4157,10 +4158,6 @@ bool CChainState::ReplayBlocks(const CChainParams& params, CCoinsView* view)
return true; return true;
} }
bool ReplayBlocks(const CChainParams& params, CCoinsView* view) {
return ::ChainstateActive().ReplayBlocks(params, view);
}
//! Helper for CChainState::RewindBlockIndex //! Helper for CChainState::RewindBlockIndex
void CChainState::EraseBlockData(CBlockIndex* index) void CChainState::EraseBlockData(CBlockIndex* index)
{ {

@ -398,9 +398,6 @@ public:
bool VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth); bool VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth);
}; };
/** Replay blocks that aren't fully applied to the database. */
bool ReplayBlocks(const CChainParams& params, CCoinsView* view);
CBlockIndex* LookupBlockIndex(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main); CBlockIndex* LookupBlockIndex(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
/** Find the last common block between the parameter chain and a locator. */ /** Find the last common block between the parameter chain and a locator. */
@ -701,7 +698,8 @@ public:
bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindex) LOCKS_EXCLUDED(cs_main); bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindex) LOCKS_EXCLUDED(cs_main);
void ResetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main); void ResetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
bool ReplayBlocks(const CChainParams& params, CCoinsView* view); /** Replay blocks that aren't fully applied to the database. */
bool ReplayBlocks(const CChainParams& params);
bool RewindBlockIndex(const CChainParams& params) LOCKS_EXCLUDED(cs_main); bool RewindBlockIndex(const CChainParams& params) LOCKS_EXCLUDED(cs_main);
bool LoadGenesisBlock(const CChainParams& chainparams); bool LoadGenesisBlock(const CChainParams& chainparams);

Loading…
Cancel
Save