mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-02 23:42:33 +02:00
validation: prepare VerifyDB for assumeutxo
Removes assumptions of use only on the active chainstate.
This commit is contained in:
parent
7901647d72
commit
9b604c0207
@ -1550,11 +1550,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only verify the DB of the active chainstate. This is fixed in later
|
if (!CVerifyDB().VerifyDB(
|
||||||
// work when we allow VerifyDB to be parameterized by chainstate.
|
*chainstate, chainparams, chainstate->CoinsDB(),
|
||||||
if (&::ChainstateActive() == chainstate &&
|
|
||||||
!CVerifyDB().VerifyDB(
|
|
||||||
*chainstate, chainparams, &chainstate->CoinsDB(),
|
|
||||||
args.GetArg("-checklevel", DEFAULT_CHECKLEVEL),
|
args.GetArg("-checklevel", DEFAULT_CHECKLEVEL),
|
||||||
args.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS))) {
|
args.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS))) {
|
||||||
strLoadError = _("Corrupted block database detected");
|
strLoadError = _("Corrupted block database detected");
|
||||||
|
@ -1239,7 +1239,8 @@ static RPCHelpMan verifychain()
|
|||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
|
||||||
CChainState& active_chainstate = chainman.ActiveChainstate();
|
CChainState& active_chainstate = chainman.ActiveChainstate();
|
||||||
return CVerifyDB().VerifyDB(active_chainstate, Params(), &active_chainstate.CoinsTip(), check_level, check_depth);
|
return CVerifyDB().VerifyDB(
|
||||||
|
active_chainstate, Params(), active_chainstate.CoinsTip(), check_level, check_depth);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -4104,7 +4104,7 @@ CVerifyDB::~CVerifyDB()
|
|||||||
bool CVerifyDB::VerifyDB(
|
bool CVerifyDB::VerifyDB(
|
||||||
CChainState& chainstate,
|
CChainState& chainstate,
|
||||||
const CChainParams& chainparams,
|
const CChainParams& chainparams,
|
||||||
CCoinsView* coinsview,
|
CCoinsView& coinsview,
|
||||||
int nCheckLevel, int nCheckDepth)
|
int nCheckLevel, int nCheckDepth)
|
||||||
{
|
{
|
||||||
AssertLockHeld(cs_main);
|
AssertLockHeld(cs_main);
|
||||||
@ -4118,13 +4118,16 @@ bool CVerifyDB::VerifyDB(
|
|||||||
nCheckDepth = chainstate.m_chain.Height();
|
nCheckDepth = chainstate.m_chain.Height();
|
||||||
nCheckLevel = std::max(0, std::min(4, nCheckLevel));
|
nCheckLevel = std::max(0, std::min(4, nCheckLevel));
|
||||||
LogPrintf("Verifying last %i blocks at level %i\n", nCheckDepth, nCheckLevel);
|
LogPrintf("Verifying last %i blocks at level %i\n", nCheckDepth, nCheckLevel);
|
||||||
CCoinsViewCache coins(coinsview);
|
CCoinsViewCache coins(&coinsview);
|
||||||
CBlockIndex* pindex;
|
CBlockIndex* pindex;
|
||||||
CBlockIndex* pindexFailure = nullptr;
|
CBlockIndex* pindexFailure = nullptr;
|
||||||
int nGoodTransactions = 0;
|
int nGoodTransactions = 0;
|
||||||
BlockValidationState state;
|
BlockValidationState state;
|
||||||
int reportDone = 0;
|
int reportDone = 0;
|
||||||
LogPrintf("[0%%]..."); /* Continued */
|
LogPrintf("[0%%]..."); /* Continued */
|
||||||
|
|
||||||
|
bool is_snapshot_cs = !chainstate.m_from_snapshot_blockhash.IsNull();
|
||||||
|
|
||||||
for (pindex = chainstate.m_chain.Tip(); pindex && pindex->pprev; pindex = pindex->pprev) {
|
for (pindex = chainstate.m_chain.Tip(); pindex && pindex->pprev; pindex = pindex->pprev) {
|
||||||
const int percentageDone = std::max(1, std::min(99, (int)(((double)(chainstate.m_chain.Height() - pindex->nHeight)) / (double)nCheckDepth * (nCheckLevel >= 4 ? 50 : 100))));
|
const int percentageDone = std::max(1, std::min(99, (int)(((double)(chainstate.m_chain.Height() - pindex->nHeight)) / (double)nCheckDepth * (nCheckLevel >= 4 ? 50 : 100))));
|
||||||
if (reportDone < percentageDone/10) {
|
if (reportDone < percentageDone/10) {
|
||||||
@ -4135,8 +4138,9 @@ bool CVerifyDB::VerifyDB(
|
|||||||
uiInterface.ShowProgress(_("Verifying blocks...").translated, percentageDone, false);
|
uiInterface.ShowProgress(_("Verifying blocks...").translated, percentageDone, false);
|
||||||
if (pindex->nHeight <= chainstate.m_chain.Height()-nCheckDepth)
|
if (pindex->nHeight <= chainstate.m_chain.Height()-nCheckDepth)
|
||||||
break;
|
break;
|
||||||
if (fPruneMode && !(pindex->nStatus & BLOCK_HAVE_DATA)) {
|
if ((fPruneMode || is_snapshot_cs) && !(pindex->nStatus & BLOCK_HAVE_DATA)) {
|
||||||
// If pruning, only go back as far as we have data.
|
// If pruning or running under an assumeutxo snapshot, only go
|
||||||
|
// back as far as we have data.
|
||||||
LogPrintf("VerifyDB(): block verification stopping at height %d (pruning, no data)\n", pindex->nHeight);
|
LogPrintf("VerifyDB(): block verification stopping at height %d (pruning, no data)\n", pindex->nHeight);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -4158,9 +4162,9 @@ bool CVerifyDB::VerifyDB(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// check level 3: check for inconsistencies during memory-only disconnect of tip blocks
|
// check level 3: check for inconsistencies during memory-only disconnect of tip blocks
|
||||||
int64_t curr_coins_usage = coins.DynamicMemoryUsage() + chainstate.CoinsTip().DynamicMemoryUsage();
|
size_t curr_coins_usage = coins.DynamicMemoryUsage() + chainstate.CoinsTip().DynamicMemoryUsage();
|
||||||
|
|
||||||
if (nCheckLevel >= 3 && static_cast<unsigned long>(curr_coins_usage) <= chainstate.m_coinstip_cache_size_bytes) {
|
if (nCheckLevel >= 3 && curr_coins_usage <= chainstate.m_coinstip_cache_size_bytes) {
|
||||||
assert(coins.GetBestBlock() == pindex->GetBlockHash());
|
assert(coins.GetBestBlock() == pindex->GetBlockHash());
|
||||||
DisconnectResult res = chainstate.DisconnectBlock(block, pindex, coins);
|
DisconnectResult res = chainstate.DisconnectBlock(block, pindex, coins);
|
||||||
if (res == DISCONNECT_FAILED) {
|
if (res == DISCONNECT_FAILED) {
|
||||||
|
@ -332,7 +332,7 @@ public:
|
|||||||
bool VerifyDB(
|
bool VerifyDB(
|
||||||
CChainState& chainstate,
|
CChainState& chainstate,
|
||||||
const CChainParams& chainparams,
|
const CChainParams& chainparams,
|
||||||
CCoinsView* coinsview,
|
CCoinsView& coinsview,
|
||||||
int nCheckLevel,
|
int nCheckLevel,
|
||||||
int nCheckDepth) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
int nCheckDepth) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user