Skip to content

Commit e7bc059

Browse files
committed
refactor: move RewindBlockIndex to CChainState
This is in preparation for multiple chainstate initialization in init.
1 parent 10837ab commit e7bc059

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
@@ -1568,7 +1568,7 @@ bool AppInitMain(NodeContext& node)
15681568
// It both disconnects blocks based on ::ChainActive(), and drops block data in
15691569
// BlockIndex() based on lack of available witness data.
15701570
uiInterface.InitMessage(_("Rewinding blocks...").translated);
1571-
if (!RewindBlockIndex(chainparams)) {
1571+
if (!::ChainstateActive().RewindBlockIndex(chainparams)) {
15721572
strLoadError = _("Unable to rewind the database to a pre-fork state. You will need to redownload the blockchain").translated;
15731573
break;
15741574
}

src/validation.cpp

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

45344534
CheckBlockIndex(params.GetConsensus());
4535-
}
4536-
}
4537-
4538-
return true;
4539-
}
4540-
4541-
bool RewindBlockIndex(const CChainParams& params) {
4542-
if (!::ChainstateActive().RewindBlockIndex(params)) {
4543-
return false;
4544-
}
45454535

4546-
LOCK(cs_main);
4547-
if (::ChainActive().Tip() != nullptr) {
4548-
// FlushStateToDisk can possibly read ::ChainActive(). Be conservative
4549-
// and skip it here, we're about to -reindex-chainstate anyway, so
4550-
// it'll get called a bunch real soon.
4551-
BlockValidationState state;
4552-
if (!::ChainstateActive().FlushStateToDisk(params, state, FlushStateMode::ALWAYS)) {
4553-
LogPrintf("RewindBlockIndex: unable to flush state to disk (%s)\n", FormatStateMessage(state));
4554-
return false;
4536+
// FlushStateToDisk can possibly read ::ChainActive(). Be conservative
4537+
// and skip it here, we're about to -reindex-chainstate anyway, so
4538+
// it'll get called a bunch real soon.
4539+
BlockValidationState state;
4540+
if (!FlushStateToDisk(params, state, FlushStateMode::ALWAYS)) {
4541+
LogPrintf("RewindBlockIndex: unable to flush state to disk (%s)\n", FormatStateMessage(state));
4542+
return false;
4543+
}
45554544
}
45564545
}
45574546

src/validation.h

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

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

0 commit comments

Comments
 (0)