Add functions to construct locators without CChain

This introduces an insignificant performance penalty, as it means locator
construction needs to use the skiplist-based CBlockIndex::GetAncestor()
function instead of the lookup-based CChain, but avoids the need for
callers to have access to a relevant CChain object.
This commit is contained in:
Pieter Wuille
2022-08-07 20:56:17 -04:00
committed by Suhas Daftuar
parent 84852bb6bb
commit ed470940cd
5 changed files with 41 additions and 34 deletions

View File

@@ -400,7 +400,7 @@ bool FillBlock(const CBlockIndex* index, const FoundBlock& block, UniqueLock<Rec
if (block.m_max_time) *block.m_max_time = index->GetBlockTimeMax();
if (block.m_mtp_time) *block.m_mtp_time = index->GetMedianTimePast();
if (block.m_in_active_chain) *block.m_in_active_chain = active[index->nHeight] == index;
if (block.m_locator) { *block.m_locator = active.GetLocator(index); }
if (block.m_locator) { *block.m_locator = GetLocator(index); }
if (block.m_next_block) FillBlock(active[index->nHeight] == index ? active[index->nHeight + 1] : nullptr, *block.m_next_block, lock, active);
if (block.m_data) {
REVERSE_LOCK(lock);
@@ -527,8 +527,7 @@ public:
{
LOCK(::cs_main);
const CBlockIndex* index = chainman().m_blockman.LookupBlockIndex(block_hash);
if (!index) return {};
return chainman().ActiveChain().GetLocator(index);
return GetLocator(index);
}
std::optional<int> findLocatorFork(const CBlockLocator& locator) override
{