Skip to content

Commit 5b690f0

Browse files
committed
refactor: move RewindBlockIndex to CChainState
This is in preparation for multiple chainstate initialization in init.
1 parent 89cdf4d commit 5b690f0

File tree

3 files changed

+9
-23
lines changed

3 files changed

+9
-23
lines changed

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,7 @@ bool AppInitMain(NodeContext& node)
16141614
// It both disconnects blocks based on ::ChainActive(), and drops block data in
16151615
// BlockIndex() based on lack of available witness data.
16161616
uiInterface.InitMessage(_("Rewinding blocks...").translated);
1617-
if (!RewindBlockIndex(chainparams)) {
1617+
if (!::ChainstateActive().RewindBlockIndex(chainparams)) {
16181618
strLoadError = _("Unable to rewind the database to a pre-fork state. You will need to redownload the blockchain").translated;
16191619
break;
16201620
}

src/validation.cpp

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4538,26 +4538,15 @@ bool CChainState::RewindBlockIndex(const CChainParams& params)
45384538
PruneBlockIndexCandidates();
45394539

45404540
CheckBlockIndex(params.GetConsensus());
4541-
}
4542-
}
4543-
4544-
return true;
4545-
}
4546-
4547-
bool RewindBlockIndex(const CChainParams& params) {
4548-
if (!::ChainstateActive().RewindBlockIndex(params)) {
4549-
return false;
4550-
}
45514541

4552-
LOCK(cs_main);
4553-
if (::ChainActive().Tip() != nullptr) {
4554-
// FlushStateToDisk can possibly read ::ChainActive(). Be conservative
4555-
// and skip it here, we're about to -reindex-chainstate anyway, so
4556-
// it'll get called a bunch real soon.
4557-
BlockValidationState state;
4558-
if (!::ChainstateActive().FlushStateToDisk(params, state, FlushStateMode::ALWAYS)) {
4559-
LogPrintf("RewindBlockIndex: unable to flush state to disk (%s)\n", state.ToString());
4560-
return false;
4542+
// FlushStateToDisk can possibly read ::ChainActive(). Be conservative
4543+
// and skip it here, we're about to -reindex-chainstate anyway, so
4544+
// it'll get called a bunch real soon.
4545+
BlockValidationState state;
4546+
if (!FlushStateToDisk(params, state, FlushStateMode::ALWAYS)) {
4547+
LogPrintf("RewindBlockIndex: unable to flush state to disk (%s)\n", state.ToString());
4548+
return false;
4549+
}
45614550
}
45624551
}
45634552

src/validation.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,6 @@ bool TestBlockValidity(BlockValidationState& state, const CChainParams& chainpar
380380
* Note that transaction witness validation rules are always enforced when P2SH is enforced. */
381381
bool IsWitnessEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params);
382382

383-
/** When there are blocks in the active chain with missing data, rewind the chainstate and remove them from the block index */
384-
bool RewindBlockIndex(const CChainParams& params) LOCKS_EXCLUDED(cs_main);
385-
386383
/** Compute at which vout of the block's coinbase transaction the witness commitment occurs, or -1 if not found */
387384
int GetWitnessCommitmentIndex(const CBlock& block);
388385

0 commit comments

Comments
 (0)