Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | CBlockIndex *LookupBlockIndex(const BlockHash &hash) { | ||||
BlockMap::const_iterator it = g_blockman.m_block_index.find(hash); | BlockMap::const_iterator it = g_blockman.m_block_index.find(hash); | ||||
return it == g_blockman.m_block_index.end() ? nullptr : it->second; | return it == g_blockman.m_block_index.end() ? nullptr : it->second; | ||||
} | } | ||||
CBlockIndex *FindForkInGlobalIndex(const CChain &chain, | CBlockIndex *FindForkInGlobalIndex(const CChain &chain, | ||||
const CBlockLocator &locator) { | const CBlockLocator &locator) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
// Find the first block the caller has in the main chain | // Find the latest block common to locator and chain - we expect that | ||||
// locator.vHave is sorted descending by height. | |||||
for (const BlockHash &hash : locator.vHave) { | for (const BlockHash &hash : locator.vHave) { | ||||
CBlockIndex *pindex = LookupBlockIndex(hash); | CBlockIndex *pindex = LookupBlockIndex(hash); | ||||
if (pindex) { | if (pindex) { | ||||
if (chain.Contains(pindex)) { | if (chain.Contains(pindex)) { | ||||
return pindex; | return pindex; | ||||
} | } | ||||
if (pindex->GetAncestor(chain.Height()) == chain.Tip()) { | if (pindex->GetAncestor(chain.Height()) == chain.Tip()) { | ||||
return chain.Tip(); | return chain.Tip(); | ||||
▲ Show 20 Lines • Show All 5,633 Lines • Show Last 20 Lines |