mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 06:43:45 +01:00
Merge #16743: refactor: move LoadChainTip/RelayBlocks under CChainState
3cf36736e5refactoring: move ReplayBlocks under CChainState (James O'Beirne)bcf73d3b84refactoring: move LoadChainTip to CChainState method (James O'Beirne)f5809d5b13doc: fix CChainState::ActivateBestChain doc (James O'Beirne) Pull request description: This is part of the [assumeutxo project](https://github.com/bitcoin/bitcoin/projects/11): Parent PR: #15606 Issue: #15605 Specification: https://github.com/jamesob/assumeutxo-docs/tree/master/proposal --- Move more chainstate-related functionality to methods on CChainState. Nothing too interesting here, but needed to work with multiple chainstates. And brief to review. :) Also fixes doc on ActivateBestChain. ACKs for top commit: MarcoFalke: ACK3cf36736e5ryanofsky: Can confirm. utACK3cf36736e5. Removes wrapper functions and removes more ::ChainActive() and ::ChainstateActive() calls than it adds, so seems good. Tree-SHA512: 4bf8a1dd454ca9d61c85f6736910fa7354c57acc0002e3a8e5ce494035d8280e4c20e066f03478eeff7d44195e7912c282a486526da9be53854b478b961affaa
This commit is contained in:
@@ -4087,28 +4087,31 @@ bool static LoadBlockIndexDB(const CChainParams& chainparams) EXCLUSIVE_LOCKS_RE
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LoadChainTip(const CChainParams& chainparams)
|
||||
bool CChainState::LoadChainTip(const CChainParams& chainparams)
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
const CCoinsViewCache& coins_cache = ::ChainstateActive().CoinsTip();
|
||||
const CCoinsViewCache& coins_cache = CoinsTip();
|
||||
assert(!coins_cache.GetBestBlock().IsNull()); // Never called when the coins view is empty
|
||||
const CBlockIndex* tip = m_chain.Tip();
|
||||
|
||||
if (::ChainActive().Tip() &&
|
||||
::ChainActive().Tip()->GetBlockHash() == coins_cache.GetBestBlock()) return true;
|
||||
if (tip && tip->GetBlockHash() == coins_cache.GetBestBlock()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Load pointer to end of best chain
|
||||
CBlockIndex* pindex = LookupBlockIndex(coins_cache.GetBestBlock());
|
||||
if (!pindex) {
|
||||
return false;
|
||||
}
|
||||
::ChainActive().SetTip(pindex);
|
||||
|
||||
::ChainstateActive().PruneBlockIndexCandidates();
|
||||
m_chain.SetTip(pindex);
|
||||
PruneBlockIndexCandidates();
|
||||
|
||||
tip = m_chain.Tip();
|
||||
LogPrintf("Loaded best chain: hashBestChain=%s height=%d date=%s progress=%f\n",
|
||||
::ChainActive().Tip()->GetBlockHash().ToString(), ::ChainActive().Height(),
|
||||
FormatISO8601DateTime(::ChainActive().Tip()->GetBlockTime()),
|
||||
GuessVerificationProgress(chainparams.TxData(), ::ChainActive().Tip()));
|
||||
tip->GetBlockHash().ToString(),
|
||||
m_chain.Height(),
|
||||
FormatISO8601DateTime(tip->GetBlockTime()),
|
||||
GuessVerificationProgress(chainparams.TxData(), tip));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4243,13 +4246,14 @@ bool CChainState::RollforwardBlock(const CBlockIndex* pindex, CCoinsViewCache& i
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CChainState::ReplayBlocks(const CChainParams& params, CCoinsView* view)
|
||||
bool CChainState::ReplayBlocks(const CChainParams& params)
|
||||
{
|
||||
LOCK(cs_main);
|
||||
|
||||
CCoinsViewCache cache(view);
|
||||
CCoinsView& db = this->CoinsDB();
|
||||
CCoinsViewCache cache(&db);
|
||||
|
||||
std::vector<uint256> hashHeads = view->GetHeadBlocks();
|
||||
std::vector<uint256> hashHeads = db.GetHeadBlocks();
|
||||
if (hashHeads.empty()) return true; // We're already in a consistent state.
|
||||
if (hashHeads.size() != 2) return error("ReplayBlocks(): unknown inconsistent state");
|
||||
|
||||
@@ -4309,10 +4313,6 @@ bool CChainState::ReplayBlocks(const CChainParams& params, CCoinsView* view)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ReplayBlocks(const CChainParams& params, CCoinsView* view) {
|
||||
return ::ChainstateActive().ReplayBlocks(params, view);
|
||||
}
|
||||
|
||||
//! Helper for CChainState::RewindBlockIndex
|
||||
void CChainState::EraseBlockData(CBlockIndex* index)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user