Changeset View
Changeset View
Standalone View
Standalone View
src/index/base.cpp
Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | bool BaseIndex::Init() { | ||||
if (!GetDB().ReadBestBlock(locator)) { | if (!GetDB().ReadBestBlock(locator)) { | ||||
locator.SetNull(); | locator.SetNull(); | ||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
if (locator.IsNull()) { | if (locator.IsNull()) { | ||||
m_best_block_index = nullptr; | m_best_block_index = nullptr; | ||||
} else { | } else { | ||||
m_best_block_index = FindForkInGlobalIndex(chainActive, locator); | m_best_block_index = FindForkInGlobalIndex(::ChainActive(), locator); | ||||
} | } | ||||
m_synced = m_best_block_index.load() == chainActive.Tip(); | m_synced = m_best_block_index.load() == ::ChainActive().Tip(); | ||||
return true; | return true; | ||||
} | } | ||||
static const CBlockIndex *NextSyncBlock(const CBlockIndex *pindex_prev) | static const CBlockIndex *NextSyncBlock(const CBlockIndex *pindex_prev) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main) { | EXCLUSIVE_LOCKS_REQUIRED(cs_main) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
if (!pindex_prev) { | if (!pindex_prev) { | ||||
return chainActive.Genesis(); | return ::ChainActive().Genesis(); | ||||
} | } | ||||
const CBlockIndex *pindex = chainActive.Next(pindex_prev); | const CBlockIndex *pindex = ::ChainActive().Next(pindex_prev); | ||||
if (pindex) { | if (pindex) { | ||||
return pindex; | return pindex; | ||||
} | } | ||||
return chainActive.Next(chainActive.FindFork(pindex_prev)); | return ::ChainActive().Next(::ChainActive().FindFork(pindex_prev)); | ||||
} | } | ||||
void BaseIndex::ThreadSync() { | void BaseIndex::ThreadSync() { | ||||
const CBlockIndex *pindex = m_best_block_index.load(); | const CBlockIndex *pindex = m_best_block_index.load(); | ||||
if (!m_synced) { | if (!m_synced) { | ||||
auto &consensus_params = GetConfig().GetChainParams().GetConsensus(); | auto &consensus_params = GetConfig().GetChainParams().GetConsensus(); | ||||
int64_t last_log_time = 0; | int64_t last_log_time = 0; | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | if (pindex) { | ||||
LogPrintf("%s is enabled at height %d\n", GetName(), pindex->nHeight); | LogPrintf("%s is enabled at height %d\n", GetName(), pindex->nHeight); | ||||
} else { | } else { | ||||
LogPrintf("%s is enabled\n", GetName()); | LogPrintf("%s is enabled\n", GetName()); | ||||
} | } | ||||
} | } | ||||
bool BaseIndex::WriteBestBlock(const CBlockIndex *block_index) { | bool BaseIndex::WriteBestBlock(const CBlockIndex *block_index) { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
if (!GetDB().WriteBestBlock(chainActive.GetLocator(block_index))) { | if (!GetDB().WriteBestBlock(::ChainActive().GetLocator(block_index))) { | ||||
return error("%s: Failed to write locator to disk", __func__); | return error("%s: Failed to write locator to disk", __func__); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
void BaseIndex::BlockConnected( | void BaseIndex::BlockConnected( | ||||
const std::shared_ptr<const CBlock> &block, const CBlockIndex *pindex, | const std::shared_ptr<const CBlock> &block, const CBlockIndex *pindex, | ||||
const std::vector<CTransactionRef> &txn_conflicted) { | const std::vector<CTransactionRef> &txn_conflicted) { | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | bool BaseIndex::BlockUntilSyncedToCurrentChain() { | ||||
AssertLockNotHeld(cs_main); | AssertLockNotHeld(cs_main); | ||||
if (!m_synced) { | if (!m_synced) { | ||||
return false; | return false; | ||||
} | } | ||||
{ | { | ||||
// Skip the queue-draining stuff if we know we're caught up with | // Skip the queue-draining stuff if we know we're caught up with | ||||
// chainActive.Tip(). | // ::ChainActive().Tip(). | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
const CBlockIndex *chain_tip = chainActive.Tip(); | const CBlockIndex *chain_tip = ::ChainActive().Tip(); | ||||
const CBlockIndex *best_block_index = m_best_block_index.load(); | const CBlockIndex *best_block_index = m_best_block_index.load(); | ||||
if (best_block_index->GetAncestor(chain_tip->nHeight) == chain_tip) { | if (best_block_index->GetAncestor(chain_tip->nHeight) == chain_tip) { | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
LogPrintf("%s: %s is catching up on block notifications\n", __func__, | LogPrintf("%s: %s is catching up on block notifications\n", __func__, | ||||
GetName()); | GetName()); | ||||
Show All 28 Lines |