Skip to content

Commit 3cf3673

Browse files
committed
refactoring: move ReplayBlocks under CChainState
1 parent bcf73d3 commit 3cf3673

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,7 @@ bool AppInitMain(InitInterfaces& interfaces)
15451545
}
15461546

15471547
// ReplayBlocks is a no-op if we cleared the coinsviewdb with -reindex or -reindex-chainstate
1548-
if (!ReplayBlocks(chainparams, &::ChainstateActive().CoinsDB())) {
1548+
if (!::ChainstateActive().ReplayBlocks(chainparams)) {
15491549
strLoadError = _("Unable to replay blocks. You will need to rebuild the database using -reindex-chainstate.").translated;
15501550
break;
15511551
}

src/validation.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4091,13 +4091,14 @@ bool CChainState::RollforwardBlock(const CBlockIndex* pindex, CCoinsViewCache& i
40914091
return true;
40924092
}
40934093

4094-
bool CChainState::ReplayBlocks(const CChainParams& params, CCoinsView* view)
4094+
bool CChainState::ReplayBlocks(const CChainParams& params)
40954095
{
40964096
LOCK(cs_main);
40974097

4098-
CCoinsViewCache cache(view);
4098+
CCoinsView& db = this->CoinsDB();
4099+
CCoinsViewCache cache(&db);
40994100

4100-
std::vector<uint256> hashHeads = view->GetHeadBlocks();
4101+
std::vector<uint256> hashHeads = db.GetHeadBlocks();
41014102
if (hashHeads.empty()) return true; // We're already in a consistent state.
41024103
if (hashHeads.size() != 2) return error("ReplayBlocks(): unknown inconsistent state");
41034104

@@ -4157,10 +4158,6 @@ bool CChainState::ReplayBlocks(const CChainParams& params, CCoinsView* view)
41574158
return true;
41584159
}
41594160

4160-
bool ReplayBlocks(const CChainParams& params, CCoinsView* view) {
4161-
return ::ChainstateActive().ReplayBlocks(params, view);
4162-
}
4163-
41644161
//! Helper for CChainState::RewindBlockIndex
41654162
void CChainState::EraseBlockData(CBlockIndex* index)
41664163
{

src/validation.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,6 @@ class CVerifyDB {
398398
bool VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth);
399399
};
400400

401-
/** Replay blocks that aren't fully applied to the database. */
402-
bool ReplayBlocks(const CChainParams& params, CCoinsView* view);
403-
404401
CBlockIndex* LookupBlockIndex(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
405402

406403
/** Find the last common block between the parameter chain and a locator. */
@@ -701,7 +698,8 @@ class CChainState {
701698
bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindex) LOCKS_EXCLUDED(cs_main);
702699
void ResetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
703700

704-
bool ReplayBlocks(const CChainParams& params, CCoinsView* view);
701+
/** Replay blocks that aren't fully applied to the database. */
702+
bool ReplayBlocks(const CChainParams& params);
705703
bool RewindBlockIndex(const CChainParams& params) LOCKS_EXCLUDED(cs_main);
706704
bool LoadGenesisBlock(const CChainParams& chainparams);
707705

0 commit comments

Comments
 (0)