Move FindForkInGlobalIndex from BlockManager to CChainState

The helper was moved in commit b026e318c3,
which also mentioned that it could be moved to CChainState. So do that,
as the functionality is not block-storage related.

This also allows to drop one function argument.
This commit is contained in:
MarcoFalke
2021-11-23 18:07:00 +01:00
parent c09b41dc66
commit fa3d62cf7b
5 changed files with 15 additions and 14 deletions

View File

@@ -155,23 +155,24 @@ CBlockIndex* BlockManager::LookupBlockIndex(const uint256& hash) const
return it == m_block_index.end() ? nullptr : it->second;
}
CBlockIndex* BlockManager::FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& locator)
CBlockIndex* CChainState::FindForkInGlobalIndex(const CBlockLocator& locator) const
{
AssertLockHeld(cs_main);
// Find the latest block common to locator and chain - we expect that
// locator.vHave is sorted descending by height.
for (const uint256& hash : locator.vHave) {
CBlockIndex* pindex = LookupBlockIndex(hash);
CBlockIndex* pindex{m_blockman.LookupBlockIndex(hash)};
if (pindex) {
if (chain.Contains(pindex))
if (m_chain.Contains(pindex)) {
return pindex;
if (pindex->GetAncestor(chain.Height()) == chain.Tip()) {
return chain.Tip();
}
if (pindex->GetAncestor(m_chain.Height()) == m_chain.Tip()) {
return m_chain.Tip();
}
}
}
return chain.Genesis();
return m_chain.Genesis();
}
bool CheckInputScripts(const CTransaction& tx, TxValidationState& state,