Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1943,6 +1943,7 @@ bool AppInitMain()
LogPrintf("* Using %.1fMiB for in-memory UTXO set (plus up to %.1fMiB of unused mempool space)\n", nCoinCacheUsage * (1.0 / 1024 / 1024), nMempoolSizeMax * (1.0 / 1024 / 1024));

bool fLoaded = false;
bool fReconsiderInvalidTip{false};
int64_t nStart = GetTimeMillis();

while (!fLoaded && !fRequestShutdown) {
Expand Down Expand Up @@ -2117,7 +2118,7 @@ bool AppInitMain()
break;
}

ResetBlockFailureFlags(nullptr);
fReconsiderInvalidTip = ResetBlockFailureFlags(nullptr);
}
} catch (const std::exception& e) {
LogPrintf("%s\n", e.what());
Expand Down Expand Up @@ -2158,6 +2159,23 @@ bool AppInitMain()
return false;
}

if (fReconsiderInvalidTip) {
// Do this outside of ThreadImport to avoid exposing rpc while we are still reconsidering the chain
uiInterface.InitMessage(_("Trying to activate a better chain which was marked invalid previousely..."));
CValidationState state;
if (!ActivateBestChain(state, chainparams)) {
LogPrintf("Failed to connect best block (%s), exiting\n", FormatStateMessage(state));
StartShutdown();
return false;
}

// ActivateBestChain can be a heavy one, see if the user requested to kill the GUI
if (fRequestShutdown) {
LogPrintf("Shutdown requested. Exiting.\n");
return false;
}
}

fs::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME;
CAutoFile est_filein(fsbridge::fopen(est_path, "rb"), SER_DISK, CLIENT_VERSION);
// Allowed to fail as this file IS missing on first startup.
Expand Down
8 changes: 5 additions & 3 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3379,11 +3379,13 @@ bool CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {

if (!pindex) {
if (pindexBestInvalid && pindexBestInvalid->GetAncestor(chainActive.Height()) == chainActive.Tip()) {
LogPrintf("%s: the best known invalid block (%s) is ahead of our tip, reconsidering\n",
__func__, pindexBestInvalid->GetBlockHash().ToString());
LogPrintf("%s: the best known invalid block (hash=%s, height=%d) is ahead of our tip (hash=%s, height=%d), reconsidering\n", __func__,
pindexBestInvalid->GetBlockHash().ToString(), pindexBestInvalid->nHeight,
chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height());
pindex = pindexBestInvalid;
} else {
return true;
// nothing to do
return false;
}
}

Expand Down