mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-26 08:51:55 +02:00
refactor: move RewindBlockIndex to CChainState
This is in preparation for multiple chainstate initialization in init.
This commit is contained in:
parent
89cdf4d569
commit
5b690f0aae
@ -1614,7 +1614,7 @@ bool AppInitMain(NodeContext& node)
|
|||||||
// It both disconnects blocks based on ::ChainActive(), and drops block data in
|
// It both disconnects blocks based on ::ChainActive(), and drops block data in
|
||||||
// BlockIndex() based on lack of available witness data.
|
// BlockIndex() based on lack of available witness data.
|
||||||
uiInterface.InitMessage(_("Rewinding blocks...").translated);
|
uiInterface.InitMessage(_("Rewinding blocks...").translated);
|
||||||
if (!RewindBlockIndex(chainparams)) {
|
if (!::ChainstateActive().RewindBlockIndex(chainparams)) {
|
||||||
strLoadError = _("Unable to rewind the database to a pre-fork state. You will need to redownload the blockchain").translated;
|
strLoadError = _("Unable to rewind the database to a pre-fork state. You will need to redownload the blockchain").translated;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -4538,28 +4538,17 @@ bool CChainState::RewindBlockIndex(const CChainParams& params)
|
|||||||
PruneBlockIndexCandidates();
|
PruneBlockIndexCandidates();
|
||||||
|
|
||||||
CheckBlockIndex(params.GetConsensus());
|
CheckBlockIndex(params.GetConsensus());
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RewindBlockIndex(const CChainParams& params) {
|
|
||||||
if (!::ChainstateActive().RewindBlockIndex(params)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOCK(cs_main);
|
|
||||||
if (::ChainActive().Tip() != nullptr) {
|
|
||||||
// FlushStateToDisk can possibly read ::ChainActive(). Be conservative
|
// FlushStateToDisk can possibly read ::ChainActive(). Be conservative
|
||||||
// and skip it here, we're about to -reindex-chainstate anyway, so
|
// and skip it here, we're about to -reindex-chainstate anyway, so
|
||||||
// it'll get called a bunch real soon.
|
// it'll get called a bunch real soon.
|
||||||
BlockValidationState state;
|
BlockValidationState state;
|
||||||
if (!::ChainstateActive().FlushStateToDisk(params, state, FlushStateMode::ALWAYS)) {
|
if (!FlushStateToDisk(params, state, FlushStateMode::ALWAYS)) {
|
||||||
LogPrintf("RewindBlockIndex: unable to flush state to disk (%s)\n", state.ToString());
|
LogPrintf("RewindBlockIndex: unable to flush state to disk (%s)\n", state.ToString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -380,9 +380,6 @@ bool TestBlockValidity(BlockValidationState& state, const CChainParams& chainpar
|
|||||||
* Note that transaction witness validation rules are always enforced when P2SH is enforced. */
|
* Note that transaction witness validation rules are always enforced when P2SH is enforced. */
|
||||||
bool IsWitnessEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params);
|
bool IsWitnessEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params);
|
||||||
|
|
||||||
/** When there are blocks in the active chain with missing data, rewind the chainstate and remove them from the block index */
|
|
||||||
bool RewindBlockIndex(const CChainParams& params) LOCKS_EXCLUDED(cs_main);
|
|
||||||
|
|
||||||
/** Compute at which vout of the block's coinbase transaction the witness commitment occurs, or -1 if not found */
|
/** Compute at which vout of the block's coinbase transaction the witness commitment occurs, or -1 if not found */
|
||||||
int GetWitnessCommitmentIndex(const CBlock& block);
|
int GetWitnessCommitmentIndex(const CBlock& block);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user