mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
[validation] RewindBlockIndex no longer needed
Instead of rewinding blocks, we request that the user restarts with -reindex
This commit is contained in:
28
src/init.cpp
28
src/init.cpp
@@ -1698,29 +1698,17 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
|
||||
break;
|
||||
}
|
||||
|
||||
bool failed_rewind{false};
|
||||
// Can't hold cs_main while calling RewindBlockIndex, so retrieve the relevant
|
||||
// chainstates beforehand.
|
||||
for (CChainState* chainstate : WITH_LOCK(::cs_main, return chainman.GetAll())) {
|
||||
if (!fReset) {
|
||||
// Note that RewindBlockIndex MUST run even if we're about to -reindex-chainstate.
|
||||
// It both disconnects blocks based on the chainstate, and drops block data in
|
||||
// BlockIndex() based on lack of available witness data.
|
||||
uiInterface.InitMessage(_("Rewinding blocks...").translated);
|
||||
if (!chainstate->RewindBlockIndex(chainparams)) {
|
||||
strLoadError = _(
|
||||
"Unable to rewind the database to a pre-fork state. "
|
||||
"You will need to redownload the blockchain");
|
||||
failed_rewind = true;
|
||||
break; // out of the per-chainstate loop
|
||||
}
|
||||
if (!fReset) {
|
||||
LOCK(cs_main);
|
||||
auto chainstates{chainman.GetAll()};
|
||||
if (std::any_of(chainstates.begin(), chainstates.end(),
|
||||
[&chainparams](const CChainState* cs) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { return cs->NeedsRedownload(chainparams); })) {
|
||||
strLoadError = strprintf(_("Witness data for blocks after height %d requires validation. Please restart with -reindex."),
|
||||
chainparams.GetConsensus().SegwitHeight);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (failed_rewind) {
|
||||
break; // out of the chainstate activation do-while
|
||||
}
|
||||
|
||||
bool failed_verification = false;
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user