refactoring: move LoadChainTip to CChainState method
This commit is contained in:
parent
f5809d5b13
commit
bcf73d3b84
|
@ -1557,8 +1557,8 @@ bool AppInitMain(InitInterfaces& interfaces)
|
||||||
is_coinsview_empty = fReset || fReindexChainState ||
|
is_coinsview_empty = fReset || fReindexChainState ||
|
||||||
::ChainstateActive().CoinsTip().GetBestBlock().IsNull();
|
::ChainstateActive().CoinsTip().GetBestBlock().IsNull();
|
||||||
if (!is_coinsview_empty) {
|
if (!is_coinsview_empty) {
|
||||||
// LoadChainTip sets ::ChainActive() based on CoinsTip()'s best block
|
// LoadChainTip initializes the chain based on CoinsTip()'s best block
|
||||||
if (!LoadChainTip(chainparams)) {
|
if (!::ChainstateActive().LoadChainTip(chainparams)) {
|
||||||
strLoadError = _("Error initializing block database").translated;
|
strLoadError = _("Error initializing block database").translated;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3932,28 +3932,31 @@ bool static LoadBlockIndexDB(const CChainParams& chainparams) EXCLUSIVE_LOCKS_RE
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LoadChainTip(const CChainParams& chainparams)
|
bool CChainState::LoadChainTip(const CChainParams& chainparams)
|
||||||
{
|
{
|
||||||
AssertLockHeld(cs_main);
|
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
|
assert(!coins_cache.GetBestBlock().IsNull()); // Never called when the coins view is empty
|
||||||
|
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("Loaded best chain: hashBestChain=%s height=%d date=%s progress=%f\n",
|
LogPrintf("Loaded best chain: hashBestChain=%s height=%d date=%s progress=%f\n",
|
||||||
::ChainActive().Tip()->GetBlockHash().ToString(), ::ChainActive().Height(),
|
tip->GetBlockHash().ToString(),
|
||||||
FormatISO8601DateTime(::ChainActive().Tip()->GetBlockTime()),
|
m_chain.Height(),
|
||||||
GuessVerificationProgress(chainparams.TxData(), ::ChainActive().Tip()));
|
FormatISO8601DateTime(tip->GetBlockTime()),
|
||||||
|
GuessVerificationProgress(chainparams.TxData(), tip));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -240,8 +240,6 @@ bool LoadGenesisBlock(const CChainParams& chainparams);
|
||||||
/** Load the block tree and coins database from disk,
|
/** Load the block tree and coins database from disk,
|
||||||
* initializing state if we're running with -reindex. */
|
* initializing state if we're running with -reindex. */
|
||||||
bool LoadBlockIndex(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
bool LoadBlockIndex(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
/** Update the chain tip based on database information. */
|
|
||||||
bool LoadChainTip(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
|
||||||
/** Unload database information */
|
/** Unload database information */
|
||||||
void UnloadBlockIndex();
|
void UnloadBlockIndex();
|
||||||
/** Run an instance of the script checking thread */
|
/** Run an instance of the script checking thread */
|
||||||
|
@ -721,6 +719,9 @@ public:
|
||||||
*/
|
*/
|
||||||
void CheckBlockIndex(const Consensus::Params& consensusParams);
|
void CheckBlockIndex(const Consensus::Params& consensusParams);
|
||||||
|
|
||||||
|
/** Update the chain tip based on database information, i.e. CoinsTip()'s best block. */
|
||||||
|
bool LoadChainTip(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool ActivateBestChainStep(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const std::shared_ptr<const CBlock>& pblock, bool& fInvalidFound, ConnectTrace& connectTrace) EXCLUSIVE_LOCKS_REQUIRED(cs_main, ::mempool.cs);
|
bool ActivateBestChainStep(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const std::shared_ptr<const CBlock>& pblock, bool& fInvalidFound, ConnectTrace& connectTrace) EXCLUSIVE_LOCKS_REQUIRED(cs_main, ::mempool.cs);
|
||||||
bool ConnectTip(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const std::shared_ptr<const CBlock>& pblock, ConnectTrace& connectTrace, DisconnectedBlockTransactions& disconnectpool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, ::mempool.cs);
|
bool ConnectTip(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const std::shared_ptr<const CBlock>& pblock, ConnectTrace& connectTrace, DisconnectedBlockTransactions& disconnectpool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, ::mempool.cs);
|
||||||
|
|
Loading…
Reference in a new issue