mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-20 13:37:28 +02:00
Merge 702cfc8c53 into merged_master (Bitcoin PR #21055)
This commit is contained in:
commit
1668dac3d6
9 changed files with 103 additions and 127 deletions
|
|
@ -217,6 +217,7 @@ static FlatFileSeq UndoFileSeq();
|
|||
bool CheckFinalTx(const CBlockIndex* active_chain_tip, const CTransaction &tx, int flags)
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
assert(active_chain_tip); // TODO: Make active_chain_tip a reference
|
||||
assert(std::addressof(*::ChainActive().Tip()) == std::addressof(*active_chain_tip));
|
||||
|
||||
// By convention a negative value for flags indicates that the
|
||||
|
|
@ -227,12 +228,12 @@ bool CheckFinalTx(const CBlockIndex* active_chain_tip, const CTransaction &tx, i
|
|||
// scheduled, so no flags are set.
|
||||
flags = std::max(flags, 0);
|
||||
|
||||
// CheckFinalTx() uses ::ChainActive().Height()+1 to evaluate
|
||||
// CheckFinalTx() uses active_chain_tip.Height()+1 to evaluate
|
||||
// nLockTime because when IsFinalTx() is called within
|
||||
// CBlock::AcceptBlock(), the height of the block *being*
|
||||
// evaluated is what is used. Thus if we want to know if a
|
||||
// transaction can be part of the *next* block, we need to call
|
||||
// IsFinalTx() with one more than ::ChainActive().Height().
|
||||
// IsFinalTx() with one more than active_chain_tip.Height().
|
||||
const int nBlockHeight = active_chain_tip->nHeight + 1;
|
||||
|
||||
// BIP113 requires that time-locked transactions have nLockTime set to
|
||||
|
|
@ -1443,16 +1444,18 @@ static void AlertNotify(const std::string& strMessage)
|
|||
#endif
|
||||
}
|
||||
|
||||
static void CheckForkWarningConditions() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
||||
void CChainState::CheckForkWarningConditions()
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
assert(std::addressof(::ChainstateActive()) == std::addressof(*this));
|
||||
|
||||
// Before we get past initial download, we cannot reliably alert about forks
|
||||
// (we assume we don't get stuck on a fork before finishing our initial sync)
|
||||
if (::ChainstateActive().IsInitialBlockDownload()) {
|
||||
if (IsInitialBlockDownload()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pindexBestInvalid && pindexBestInvalid->nChainWork > ::ChainActive().Tip()->nChainWork + (GetBlockProof(*::ChainActive().Tip()) * 6)) {
|
||||
if (pindexBestInvalid && pindexBestInvalid->nChainWork > m_chain.Tip()->nChainWork + (GetBlockProof(*m_chain.Tip()) * 6)) {
|
||||
LogPrintf("%s: Warning: Found invalid chain at least ~6 blocks longer than our best chain.\nChain state database corruption likely.\n", __func__);
|
||||
SetfLargeWorkInvalidChainFound(true);
|
||||
} else {
|
||||
|
|
@ -1461,21 +1464,22 @@ static void CheckForkWarningConditions() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
|||
}
|
||||
|
||||
// Called both upon regular invalid block discovery *and* InvalidateBlock
|
||||
void static InvalidChainFound(CBlockIndex* pindexNew) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
||||
void CChainState::InvalidChainFound(CBlockIndex* pindexNew)
|
||||
{
|
||||
assert(std::addressof(::ChainstateActive()) == std::addressof(*this));
|
||||
if (!pindexBestInvalid || pindexNew->nChainWork > pindexBestInvalid->nChainWork)
|
||||
pindexBestInvalid = pindexNew;
|
||||
if (pindexBestHeader != nullptr && pindexBestHeader->GetAncestor(pindexNew->nHeight) == pindexNew) {
|
||||
pindexBestHeader = ::ChainActive().Tip();
|
||||
pindexBestHeader = m_chain.Tip();
|
||||
}
|
||||
|
||||
LogPrintf("%s: invalid block=%s height=%d date=%s\n", __func__,
|
||||
pindexNew->GetBlockHash().ToString(), pindexNew->nHeight,
|
||||
FormatISO8601DateTime(pindexNew->GetBlockTime()));
|
||||
CBlockIndex *tip = ::ChainActive().Tip();
|
||||
CBlockIndex *tip = m_chain.Tip();
|
||||
assert (tip);
|
||||
LogPrintf("%s: current best=%s height=%d date=%s\n", __func__,
|
||||
tip->GetBlockHash().ToString(), ::ChainActive().Height(),
|
||||
tip->GetBlockHash().ToString(), m_chain.Height(),
|
||||
FormatISO8601DateTime(tip->GetBlockTime()));
|
||||
CheckForkWarningConditions();
|
||||
}
|
||||
|
|
@ -2620,7 +2624,7 @@ static void AppendWarning(bilingual_str& res, const bilingual_str& warn)
|
|||
}
|
||||
|
||||
/** Check warning conditions and do some notifications on new chain tip set. */
|
||||
static void UpdateTip(CTxMemPool& mempool, const CBlockIndex* pindexNew, const CChainParams& chainParams)
|
||||
static void UpdateTip(CTxMemPool& mempool, const CBlockIndex* pindexNew, const CChainParams& chainParams, CChainState& active_chainstate)
|
||||
EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
|
||||
{
|
||||
// New best block
|
||||
|
|
@ -2633,7 +2637,8 @@ static void UpdateTip(CTxMemPool& mempool, const CBlockIndex* pindexNew, const C
|
|||
}
|
||||
|
||||
bilingual_str warning_messages;
|
||||
if (!::ChainstateActive().IsInitialBlockDownload()) {
|
||||
assert(std::addressof(::ChainstateActive()) == std::addressof(active_chainstate));
|
||||
if (!active_chainstate.IsInitialBlockDownload()) {
|
||||
const CBlockIndex* pindex = pindexNew;
|
||||
for (int bit = 0; bit < VERSIONBITS_NUM_BITS; bit++) {
|
||||
WarningBitsConditionChecker checker(bit);
|
||||
|
|
@ -2648,12 +2653,13 @@ static void UpdateTip(CTxMemPool& mempool, const CBlockIndex* pindexNew, const C
|
|||
}
|
||||
}
|
||||
}
|
||||
assert(std::addressof(::ChainstateActive()) == std::addressof(active_chainstate));
|
||||
LogPrintf("%s: new best=%s height=%d version=0x%08x tx=%lu date='%s' progress=%f cache=%.1fMiB(%utxo)%s\n", __func__,
|
||||
pindexNew->GetBlockHash().ToString(), pindexNew->nHeight, pindexNew->nVersion,
|
||||
(unsigned long)pindexNew->nChainTx,
|
||||
FormatISO8601DateTime(pindexNew->GetBlockTime()),
|
||||
GuessVerificationProgress(pindexNew, chainParams.GetConsensus().nPowTargetSpacing),
|
||||
::ChainstateActive().CoinsTip().DynamicMemoryUsage() * (1.0 / (1<<20)), ::ChainstateActive().CoinsTip().GetCacheSize(),
|
||||
active_chainstate.CoinsTip().DynamicMemoryUsage() * (1.0 / (1<<20)), active_chainstate.CoinsTip().GetCacheSize(),
|
||||
!warning_messages.empty() ? strprintf(" warning='%s'", warning_messages.original) : "");
|
||||
}
|
||||
|
||||
|
|
@ -2709,7 +2715,7 @@ bool CChainState::DisconnectTip(BlockValidationState& state, const CChainParams&
|
|||
|
||||
m_chain.SetTip(pindexDelete->pprev);
|
||||
|
||||
UpdateTip(m_mempool, pindexDelete->pprev, chainparams);
|
||||
UpdateTip(m_mempool, pindexDelete->pprev, chainparams, *this);
|
||||
// Let wallets know transactions went from 1-confirmed to
|
||||
// 0-confirmed or conflicted:
|
||||
GetMainSignals().BlockDisconnected(pblock, pindexDelete);
|
||||
|
|
@ -2849,7 +2855,7 @@ bool CChainState::ConnectTip(BlockValidationState& state, const CChainParams& ch
|
|||
disconnectpool.removeForBlock(blockConnecting.vtx);
|
||||
// Update m_chain & related variables.
|
||||
m_chain.SetTip(pindexNew);
|
||||
UpdateTip(m_mempool, pindexNew, chainparams);
|
||||
UpdateTip(m_mempool, pindexNew, chainparams, *this);
|
||||
|
||||
int64_t nTime6 = GetTimeMicros(); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1;
|
||||
LogPrint(BCLog::BENCH, " - Connect postprocess: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime6 - nTime5) * MILLI, nTimePostConnect * MICRO, nTimePostConnect * MILLI / nBlocksTotal);
|
||||
|
|
@ -2940,6 +2946,7 @@ bool CChainState::ActivateBestChainStep(BlockValidationState& state, const CChai
|
|||
{
|
||||
AssertLockHeld(cs_main);
|
||||
AssertLockHeld(m_mempool.cs);
|
||||
assert(std::addressof(::ChainstateActive()) == std::addressof(*this));
|
||||
|
||||
const CBlockIndex* pindexOldTip = m_chain.Tip();
|
||||
const CBlockIndex* pindexFork = m_chain.FindFork(pindexMostWork);
|
||||
|
|
@ -2951,7 +2958,7 @@ bool CChainState::ActivateBestChainStep(BlockValidationState& state, const CChai
|
|||
if (!DisconnectTip(state, chainparams, &disconnectpool)) {
|
||||
// This is likely a fatal error, but keep the mempool consistent,
|
||||
// just in case. Only remove from the mempool in this case.
|
||||
UpdateMempoolForReorg(::ChainstateActive(), m_mempool, disconnectpool, false);
|
||||
UpdateMempoolForReorg(*this, m_mempool, disconnectpool, false);
|
||||
|
||||
// If we're unable to disconnect a block during normal operation,
|
||||
// then that is a failure of our local system -- we should abort
|
||||
|
|
@ -2995,7 +3002,7 @@ bool CChainState::ActivateBestChainStep(BlockValidationState& state, const CChai
|
|||
// A system error occurred (disk space, database error, ...).
|
||||
// Make the mempool consistent with the current tip, just in case
|
||||
// any observers try to use it before shutdown.
|
||||
UpdateMempoolForReorg(::ChainstateActive(), m_mempool, disconnectpool, false);
|
||||
UpdateMempoolForReorg(*this, m_mempool, disconnectpool, false);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -3012,9 +3019,9 @@ bool CChainState::ActivateBestChainStep(BlockValidationState& state, const CChai
|
|||
if (fBlocksDisconnected) {
|
||||
// If any blocks were disconnected, disconnectpool may be non empty. Add
|
||||
// any disconnected transactions back to the mempool.
|
||||
UpdateMempoolForReorg(::ChainstateActive(), m_mempool, disconnectpool, true);
|
||||
UpdateMempoolForReorg(*this, m_mempool, disconnectpool, true);
|
||||
}
|
||||
m_mempool.check(&CoinsTip());
|
||||
m_mempool.check(*this);
|
||||
|
||||
CheckForkWarningConditions();
|
||||
|
||||
|
|
@ -3185,9 +3192,6 @@ bool CChainState::PreciousBlock(BlockValidationState& state, const CChainParams&
|
|||
|
||||
return ActivateBestChain(state, params, std::shared_ptr<const CBlock>());
|
||||
}
|
||||
bool PreciousBlock(BlockValidationState& state, const CChainParams& params, CBlockIndex *pindex) {
|
||||
return ::ChainstateActive().PreciousBlock(state, params, pindex);
|
||||
}
|
||||
|
||||
bool CChainState::InvalidateBlock(BlockValidationState& state, const CChainParams& chainparams, CBlockIndex *pindex)
|
||||
{
|
||||
|
|
@ -3249,7 +3253,8 @@ bool CChainState::InvalidateBlock(BlockValidationState& state, const CChainParam
|
|||
// transactions back to the mempool if disconnecting was successful,
|
||||
// and we're not doing a very deep invalidation (in which case
|
||||
// keeping the mempool up to date is probably futile anyway).
|
||||
UpdateMempoolForReorg(::ChainstateActive(), m_mempool, disconnectpool, /* fAddToMempool = */ (++disconnected <= 10) && ret);
|
||||
assert(std::addressof(::ChainstateActive()) == std::addressof(*this));
|
||||
UpdateMempoolForReorg(*this, m_mempool, disconnectpool, /* fAddToMempool = */ (++disconnected <= 10) && ret);
|
||||
if (!ret) return false;
|
||||
assert(invalid_walk_tip->pprev == m_chain.Tip());
|
||||
|
||||
|
|
@ -3325,10 +3330,6 @@ bool CChainState::InvalidateBlock(BlockValidationState& state, const CChainParam
|
|||
return true;
|
||||
}
|
||||
|
||||
bool InvalidateBlock(BlockValidationState& state, const CChainParams& chainparams, CBlockIndex *pindex) {
|
||||
return ::ChainstateActive().InvalidateBlock(state, chainparams, pindex);
|
||||
}
|
||||
|
||||
void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
|
||||
AssertLockHeld(cs_main);
|
||||
|
||||
|
|
@ -3363,10 +3364,6 @@ void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
|
|||
}
|
||||
}
|
||||
|
||||
void ResetBlockFailureFlags(CBlockIndex *pindex) {
|
||||
return ::ChainstateActive().ResetBlockFailureFlags(pindex);
|
||||
}
|
||||
|
||||
CBlockIndex* BlockManager::AddToBlockIndex(const CBlockHeader& block)
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
|
|
@ -3450,7 +3447,7 @@ void CChainState::ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pi
|
|||
}
|
||||
}
|
||||
|
||||
static bool FindBlockPos(FlatFilePos &pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown = false)
|
||||
static bool FindBlockPos(FlatFilePos &pos, unsigned int nAddSize, unsigned int nHeight, CChain& active_chain, uint64_t nTime, bool fKnown = false)
|
||||
{
|
||||
LOCK(cs_LastBlockFile);
|
||||
|
||||
|
|
@ -3465,7 +3462,8 @@ static bool FindBlockPos(FlatFilePos &pos, unsigned int nAddSize, unsigned int n
|
|||
// when the undo file is keeping up with the block file, we want to flush it explicitly
|
||||
// when it is lagging behind (more blocks arrive than are being connected), we let the
|
||||
// undo block write case handle it
|
||||
finalize_undo = (vinfoBlockFile[nFile].nHeightLast == (unsigned int)ChainActive().Tip()->nHeight);
|
||||
assert(std::addressof(::ChainActive()) == std::addressof(active_chain));
|
||||
finalize_undo = (vinfoBlockFile[nFile].nHeightLast == (unsigned int)active_chain.Tip()->nHeight);
|
||||
nFile++;
|
||||
if (vinfoBlockFile.size() <= nFile) {
|
||||
vinfoBlockFile.resize(nFile + 1);
|
||||
|
|
@ -4056,12 +4054,12 @@ bool ChainstateManager::ProcessNewBlockHeaders(const std::vector<CBlockHeader>&
|
|||
}
|
||||
|
||||
/** Store block on disk. If dbp is non-nullptr, the file is known to already reside on disk */
|
||||
static FlatFilePos SaveBlockToDisk(const CBlock& block, int nHeight, const CChainParams& chainparams, const FlatFilePos* dbp) {
|
||||
static FlatFilePos SaveBlockToDisk(const CBlock& block, int nHeight, CChain& active_chain, const CChainParams& chainparams, const FlatFilePos* dbp) {
|
||||
unsigned int nBlockSize = ::GetSerializeSize(block, CLIENT_VERSION);
|
||||
FlatFilePos blockPos;
|
||||
if (dbp != nullptr)
|
||||
blockPos = *dbp;
|
||||
if (!FindBlockPos(blockPos, nBlockSize+8, nHeight, block.GetBlockTime(), dbp != nullptr)) {
|
||||
if (!FindBlockPos(blockPos, nBlockSize+8, nHeight, active_chain, block.GetBlockTime(), dbp != nullptr)) {
|
||||
error("%s: FindBlockPos failed", __func__);
|
||||
return FlatFilePos();
|
||||
}
|
||||
|
|
@ -4140,8 +4138,9 @@ bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, Block
|
|||
|
||||
// Write block to history file
|
||||
if (fNewBlock) *fNewBlock = true;
|
||||
assert(std::addressof(::ChainActive()) == std::addressof(m_chain));
|
||||
try {
|
||||
FlatFilePos blockPos = SaveBlockToDisk(block, pindex->nHeight, chainparams, dbp);
|
||||
FlatFilePos blockPos = SaveBlockToDisk(block, pindex->nHeight, m_chain, chainparams, dbp);
|
||||
if (blockPos.IsNull()) {
|
||||
state.Error(strprintf("%s: Failed to find position to write new block to disk", __func__));
|
||||
return false;
|
||||
|
|
@ -4312,11 +4311,12 @@ void BlockManager::FindFilesToPruneManual(std::set<int>& setFilesToPrune, int nM
|
|||
}
|
||||
|
||||
/* This function is called from the RPC code for pruneblockchain */
|
||||
void PruneBlockFilesManual(int nManualPruneHeight)
|
||||
void PruneBlockFilesManual(CChainState& active_chainstate, int nManualPruneHeight)
|
||||
{
|
||||
BlockValidationState state;
|
||||
const CChainParams& chainparams = Params();
|
||||
if (!::ChainstateActive().FlushStateToDisk(
|
||||
assert(std::addressof(::ChainstateActive()) == std::addressof(active_chainstate));
|
||||
if (!active_chainstate.FlushStateToDisk(
|
||||
chainparams, state, FlushStateMode::NONE, nManualPruneHeight)) {
|
||||
LogPrintf("%s: failed to flush state (%s)\n", __func__, state.ToString());
|
||||
}
|
||||
|
|
@ -4491,11 +4491,12 @@ void BlockManager::Unload() {
|
|||
m_block_index.clear();
|
||||
}
|
||||
|
||||
bool static LoadBlockIndexDB(ChainstateManager& chainman, const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
||||
bool CChainState::LoadBlockIndexDB(const CChainParams& chainparams)
|
||||
{
|
||||
if (!chainman.m_blockman.LoadBlockIndex(
|
||||
assert(std::addressof(::ChainstateActive()) == std::addressof(*this));
|
||||
if (!m_blockman.LoadBlockIndex(
|
||||
chainparams.GetConsensus(), *pblocktree,
|
||||
::ChainstateActive().setBlockIndexCandidates)) {
|
||||
setBlockIndexCandidates)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -4519,7 +4520,7 @@ bool static LoadBlockIndexDB(ChainstateManager& chainman, const CChainParams& ch
|
|||
// Check presence of blk files
|
||||
LogPrintf("Checking all blk files are present...\n");
|
||||
std::set<int> setBlkDataFiles;
|
||||
for (const std::pair<const uint256, CBlockIndex*>& item : chainman.BlockIndex()) {
|
||||
for (const std::pair<const uint256, CBlockIndex*>& item : m_blockman.m_block_index) {
|
||||
CBlockIndex* pindex = item.second;
|
||||
if (pindex->nStatus & BLOCK_HAVE_DATA) {
|
||||
setBlkDataFiles.insert(pindex->nFile);
|
||||
|
|
@ -4593,15 +4594,17 @@ CVerifyDB::~CVerifyDB()
|
|||
uiInterface.ShowProgress("", 100, false);
|
||||
}
|
||||
|
||||
bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth)
|
||||
bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CChainState& active_chainstate, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth)
|
||||
{
|
||||
LOCK(cs_main);
|
||||
if (::ChainActive().Tip() == nullptr || ::ChainActive().Tip()->pprev == nullptr)
|
||||
AssertLockHeld(cs_main);
|
||||
|
||||
assert(std::addressof(::ChainstateActive()) == std::addressof(active_chainstate));
|
||||
if (active_chainstate.m_chain.Tip() == nullptr || active_chainstate.m_chain.Tip()->pprev == nullptr)
|
||||
return true;
|
||||
|
||||
// Verify blocks in the best chain
|
||||
if (nCheckDepth <= 0 || nCheckDepth > ::ChainActive().Height())
|
||||
nCheckDepth = ::ChainActive().Height();
|
||||
if (nCheckDepth <= 0 || nCheckDepth > active_chainstate.m_chain.Height())
|
||||
nCheckDepth = active_chainstate.m_chain.Height();
|
||||
nCheckLevel = std::max(0, std::min(4, nCheckLevel));
|
||||
LogPrintf("Verifying last %i blocks at level %i\n", nCheckDepth, nCheckLevel);
|
||||
CCoinsViewCache coins(coinsview);
|
||||
|
|
@ -4611,15 +4614,15 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
|
|||
BlockValidationState state;
|
||||
int reportDone = 0;
|
||||
LogPrintf("[0%%]..."); /* Continued */
|
||||
for (pindex = ::ChainActive().Tip(); pindex && pindex->pprev; pindex = pindex->pprev) {
|
||||
const int percentageDone = std::max(1, std::min(99, (int)(((double)(::ChainActive().Height() - pindex->nHeight)) / (double)nCheckDepth * (nCheckLevel >= 4 ? 50 : 100))));
|
||||
for (pindex = active_chainstate.m_chain.Tip(); pindex && pindex->pprev; pindex = pindex->pprev) {
|
||||
const int percentageDone = std::max(1, std::min(99, (int)(((double)(active_chainstate.m_chain.Height() - pindex->nHeight)) / (double)nCheckDepth * (nCheckLevel >= 4 ? 50 : 100))));
|
||||
if (reportDone < percentageDone/10) {
|
||||
// report every 10% step
|
||||
LogPrintf("[%d%%]...", percentageDone); /* Continued */
|
||||
reportDone = percentageDone/10;
|
||||
}
|
||||
uiInterface.ShowProgress(_("Verifying blocks...").translated, percentageDone, false);
|
||||
if (pindex->nHeight <= ::ChainActive().Height()-nCheckDepth)
|
||||
if (pindex->nHeight <= active_chainstate.m_chain.Height()-nCheckDepth)
|
||||
break;
|
||||
if (fPruneMode && !(pindex->nStatus & BLOCK_HAVE_DATA)) {
|
||||
// If pruning, only go back as far as we have data.
|
||||
|
|
@ -4644,9 +4647,9 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
|
|||
}
|
||||
}
|
||||
// check level 3: check for inconsistencies during memory-only disconnect of tip blocks
|
||||
if (nCheckLevel >= 3 && (coins.DynamicMemoryUsage() + ::ChainstateActive().CoinsTip().DynamicMemoryUsage()) <= ::ChainstateActive().m_coinstip_cache_size_bytes) {
|
||||
if (nCheckLevel >= 3 && (coins.DynamicMemoryUsage() + active_chainstate.CoinsTip().DynamicMemoryUsage()) <= active_chainstate.m_coinstip_cache_size_bytes) {
|
||||
assert(coins.GetBestBlock() == pindex->GetBlockHash());
|
||||
DisconnectResult res = ::ChainstateActive().DisconnectBlock(block, pindex, coins);
|
||||
DisconnectResult res = active_chainstate.DisconnectBlock(block, pindex, coins);
|
||||
if (res == DISCONNECT_FAILED) {
|
||||
return error("VerifyDB(): *** irrecoverable inconsistency in block data at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
|
||||
}
|
||||
|
|
@ -4660,26 +4663,26 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
|
|||
if (ShutdownRequested()) return true;
|
||||
}
|
||||
if (pindexFailure)
|
||||
return error("VerifyDB(): *** coin database inconsistencies found (last %i blocks, %i good transactions before that)\n", ::ChainActive().Height() - pindexFailure->nHeight + 1, nGoodTransactions);
|
||||
return error("VerifyDB(): *** coin database inconsistencies found (last %i blocks, %i good transactions before that)\n", active_chainstate.m_chain.Height() - pindexFailure->nHeight + 1, nGoodTransactions);
|
||||
|
||||
// store block count as we move pindex at check level >= 4
|
||||
int block_count = ::ChainActive().Height() - pindex->nHeight;
|
||||
int block_count = active_chainstate.m_chain.Height() - pindex->nHeight;
|
||||
|
||||
// check level 4: try reconnecting blocks
|
||||
if (nCheckLevel >= 4) {
|
||||
while (pindex != ::ChainActive().Tip()) {
|
||||
const int percentageDone = std::max(1, std::min(99, 100 - (int)(((double)(::ChainActive().Height() - pindex->nHeight)) / (double)nCheckDepth * 50)));
|
||||
while (pindex != active_chainstate.m_chain.Tip()) {
|
||||
const int percentageDone = std::max(1, std::min(99, 100 - (int)(((double)(active_chainstate.m_chain.Height() - pindex->nHeight)) / (double)nCheckDepth * 50)));
|
||||
if (reportDone < percentageDone/10) {
|
||||
// report every 10% step
|
||||
LogPrintf("[%d%%]...", percentageDone); /* Continued */
|
||||
reportDone = percentageDone/10;
|
||||
}
|
||||
uiInterface.ShowProgress(_("Verifying blocks...").translated, percentageDone, false);
|
||||
pindex = ::ChainActive().Next(pindex);
|
||||
pindex = active_chainstate.m_chain.Next(pindex);
|
||||
CBlock block;
|
||||
if (!ReadBlockFromDisk(block, pindex, chainparams.GetConsensus()))
|
||||
return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
|
||||
if (!::ChainstateActive().ConnectBlock(block, state, pindex, coins, chainparams, NULL))
|
||||
if (!active_chainstate.ConnectBlock(block, state, pindex, coins, chainparams, NULL))
|
||||
return error("VerifyDB(): *** found unconnectable block at %d, hash=%s (%s)", pindex->nHeight, pindex->GetBlockHash().ToString(), state.ToString());
|
||||
if (ShutdownRequested()) return true;
|
||||
}
|
||||
|
|
@ -4950,7 +4953,7 @@ bool ChainstateManager::LoadBlockIndex(const CChainParams& chainparams)
|
|||
// Load block index from databases
|
||||
bool needs_init = fReindex;
|
||||
if (!fReindex) {
|
||||
bool ret = LoadBlockIndexDB(*this, chainparams);
|
||||
bool ret = ActiveChainstate().LoadBlockIndexDB(chainparams);
|
||||
if (!ret) return false;
|
||||
needs_init = m_blockman.m_block_index.empty();
|
||||
}
|
||||
|
|
@ -4978,9 +4981,10 @@ bool CChainState::LoadGenesisBlock(const CChainParams& chainparams)
|
|||
if (m_blockman.m_block_index.count(chainparams.GenesisBlock().GetHash()))
|
||||
return true;
|
||||
|
||||
assert(std::addressof(::ChainActive()) == std::addressof(m_chain));
|
||||
try {
|
||||
const CBlock& block = chainparams.GenesisBlock();
|
||||
FlatFilePos blockPos = SaveBlockToDisk(block, 0, chainparams, nullptr);
|
||||
FlatFilePos blockPos = SaveBlockToDisk(block, 0, m_chain, chainparams, nullptr);
|
||||
if (blockPos.IsNull())
|
||||
return error("%s: writing genesis block to disk failed", __func__);
|
||||
CBlockIndex *pindex = m_blockman.AddToBlockIndex(block);
|
||||
|
|
@ -4992,11 +4996,6 @@ bool CChainState::LoadGenesisBlock(const CChainParams& chainparams)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool LoadGenesisBlock(const CChainParams& chainparams)
|
||||
{
|
||||
return ::ChainstateActive().LoadGenesisBlock(chainparams);
|
||||
}
|
||||
|
||||
void CChainState::LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, FlatFilePos* dbp)
|
||||
{
|
||||
// Map of disk positions for blocks with unknown parent (only used for reindex)
|
||||
|
|
@ -5360,24 +5359,6 @@ CBlockFileInfo* GetBlockFileInfo(size_t n)
|
|||
return &vinfoBlockFile.at(n);
|
||||
}
|
||||
|
||||
ThresholdState VersionBitsTipState(const Consensus::Params& params, Consensus::DeploymentPos pos)
|
||||
{
|
||||
LOCK(cs_main);
|
||||
return VersionBitsState(::ChainActive().Tip(), params, pos, versionbitscache);
|
||||
}
|
||||
|
||||
BIP9Stats VersionBitsTipStatistics(const Consensus::Params& params, Consensus::DeploymentPos pos)
|
||||
{
|
||||
LOCK(cs_main);
|
||||
return VersionBitsStatistics(::ChainActive().Tip(), params, pos);
|
||||
}
|
||||
|
||||
int VersionBitsTipStateSinceHeight(const Consensus::Params& params, Consensus::DeploymentPos pos)
|
||||
{
|
||||
LOCK(cs_main);
|
||||
return VersionBitsStateSinceHeight(::ChainActive().Tip(), params, pos, versionbitscache);
|
||||
}
|
||||
|
||||
static const uint64_t MEMPOOL_DUMP_VERSION = 1;
|
||||
|
||||
bool LoadMempool(CTxMemPool& pool, CChainState& active_chainstate)
|
||||
|
|
@ -6056,7 +6037,7 @@ bool MainchainRPCCheck(const bool init)
|
|||
if (chainman.BlockIndex().count(blockhash) == 0)
|
||||
continue;
|
||||
CBlockIndex* pblockindex = chainman.BlockIndex()[blockhash];
|
||||
ResetBlockFailureFlags(pblockindex);
|
||||
::ChainstateActive().ResetBlockFailureFlags(pblockindex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue