Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 4,619 Lines • ▼ Show 20 Lines | static bool LoadBlockIndexDB(const Consensus::Params ¶ms) | ||||
// Check whether we need to continue reindexing | // Check whether we need to continue reindexing | ||||
if (pblocktree->IsReindexing()) { | if (pblocktree->IsReindexing()) { | ||||
fReindex = true; | fReindex = true; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool LoadChainTip(const Config &config) { | bool CChainState::LoadChainTip(const CChainParams &chainparams) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
const CCoinsViewCache &coins_cache = ::ChainstateActive().CoinsTip(); | const CCoinsViewCache &coins_cache = CoinsTip(); | ||||
// Never called when the coins view is empty | // Never called when the coins view is empty | ||||
assert(!coins_cache.GetBestBlock().IsNull()); | assert(!coins_cache.GetBestBlock().IsNull()); | ||||
const CBlockIndex *tip = m_chain.Tip(); | |||||
if (::ChainActive().Tip() && | if (tip && tip->GetBlockHash() == coins_cache.GetBestBlock()) { | ||||
::ChainActive().Tip()->GetBlockHash() == coins_cache.GetBestBlock()) { | |||||
return true; | return true; | ||||
} | } | ||||
// Load pointer to end of best chain | // Load pointer to end of best chain | ||||
CBlockIndex *pindex = LookupBlockIndex(coins_cache.GetBestBlock()); | CBlockIndex *pindex = LookupBlockIndex(coins_cache.GetBestBlock()); | ||||
if (!pindex) { | if (!pindex) { | ||||
return false; | return false; | ||||
} | } | ||||
::ChainActive().SetTip(pindex); | m_chain.SetTip(pindex); | ||||
PruneBlockIndexCandidates(); | |||||
::ChainstateActive().PruneBlockIndexCandidates(); | |||||
tip = m_chain.Tip(); | |||||
LogPrintf( | LogPrintf( | ||||
"Loaded best chain: hashBestChain=%s height=%d date=%s progress=%f\n", | "Loaded best chain: hashBestChain=%s height=%d date=%s progress=%f\n", | ||||
::ChainActive().Tip()->GetBlockHash().ToString(), | tip->GetBlockHash().ToString(), m_chain.Height(), | ||||
::ChainActive().Height(), | FormatISO8601DateTime(tip->GetBlockTime()), | ||||
FormatISO8601DateTime(::ChainActive().Tip()->GetBlockTime()), | GuessVerificationProgress(chainparams.TxData(), tip)); | ||||
GuessVerificationProgress(config.GetChainParams().TxData(), | |||||
::ChainActive().Tip())); | |||||
return true; | return true; | ||||
} | } | ||||
CVerifyDB::CVerifyDB() { | CVerifyDB::CVerifyDB() { | ||||
uiInterface.ShowProgress(_("Verifying blocks...").translated, 0, false); | uiInterface.ShowProgress(_("Verifying blocks...").translated, 0, false); | ||||
} | } | ||||
CVerifyDB::~CVerifyDB() { | CVerifyDB::~CVerifyDB() { | ||||
▲ Show 20 Lines • Show All 193 Lines • ▼ Show 20 Lines | for (const CTransactionRef &tx : block.vtx) { | ||||
for (const CTxIn &txin : tx->vin) { | for (const CTxIn &txin : tx->vin) { | ||||
view.SpendCoin(txin.prevout); | view.SpendCoin(txin.prevout); | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool CChainState::ReplayBlocks(const Consensus::Params ¶ms, | bool CChainState::ReplayBlocks(const Consensus::Params ¶ms) { | ||||
CCoinsView *view) { | |||||
LOCK(cs_main); | LOCK(cs_main); | ||||
CCoinsViewCache cache(view); | CCoinsView &db = this->CoinsDB(); | ||||
CCoinsViewCache cache(&db); | |||||
std::vector<BlockHash> hashHeads = view->GetHeadBlocks(); | std::vector<BlockHash> hashHeads = db.GetHeadBlocks(); | ||||
if (hashHeads.empty()) { | if (hashHeads.empty()) { | ||||
// We're already in a consistent state. | // We're already in a consistent state. | ||||
return true; | return true; | ||||
} | } | ||||
if (hashHeads.size() != 2) { | if (hashHeads.size() != 2) { | ||||
return error("ReplayBlocks(): unknown inconsistent state"); | return error("ReplayBlocks(): unknown inconsistent state"); | ||||
} | } | ||||
uiInterface.ShowProgress(_("Replaying blocks...").translated, 0, false); | uiInterface.ShowProgress(_("Replaying blocks...").translated, 0, false); | ||||
LogPrintf("Replaying blocks\n"); | LogPrintf("Replaying blocks\n"); | ||||
// Old tip during the interrupted flush. | // Old tip during the interrupted flush. | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | bool CChainState::ReplayBlocks(const Consensus::Params ¶ms) { | ||||
} | } | ||||
cache.SetBestBlock(pindexNew->GetBlockHash()); | cache.SetBestBlock(pindexNew->GetBlockHash()); | ||||
cache.Flush(); | cache.Flush(); | ||||
uiInterface.ShowProgress("", 100, false); | uiInterface.ShowProgress("", 100, false); | ||||
return true; | return true; | ||||
} | } | ||||
bool ReplayBlocks(const Consensus::Params ¶ms, CCoinsView *view) { | |||||
return ::ChainstateActive().ReplayBlocks(params, view); | |||||
} | |||||
// May NOT be used after any connections are up as much of the peer-processing | // May NOT be used after any connections are up as much of the peer-processing | ||||
// logic assumes a consistent block index state | // logic assumes a consistent block index state | ||||
void CChainState::UnloadBlockIndex() { | void CChainState::UnloadBlockIndex() { | ||||
nBlockSequenceId = 1; | nBlockSequenceId = 1; | ||||
setBlockIndexCandidates.clear(); | setBlockIndexCandidates.clear(); | ||||
// Do not point to CBlockIndex that will be free'd | // Do not point to CBlockIndex that will be free'd | ||||
m_finalizedBlockIndex = nullptr; | m_finalizedBlockIndex = nullptr; | ||||
▲ Show 20 Lines • Show All 791 Lines • Show Last 20 Lines |