mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-08-05 14:34:49 +02:00
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:
parent
c09b41dc66
commit
fa3d62cf7b
@ -65,7 +65,7 @@ bool BaseIndex::Init()
|
|||||||
if (locator.IsNull()) {
|
if (locator.IsNull()) {
|
||||||
m_best_block_index = nullptr;
|
m_best_block_index = nullptr;
|
||||||
} else {
|
} else {
|
||||||
m_best_block_index = m_chainstate->m_blockman.FindForkInGlobalIndex(active_chain, locator);
|
m_best_block_index = m_chainstate->FindForkInGlobalIndex(locator);
|
||||||
}
|
}
|
||||||
m_synced = m_best_block_index.load() == active_chain.Tip();
|
m_synced = m_best_block_index.load() == active_chain.Tip();
|
||||||
if (!m_synced) {
|
if (!m_synced) {
|
||||||
|
@ -3083,7 +3083,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
|
||||||
// Find the last block the caller has in the main chain
|
// Find the last block the caller has in the main chain
|
||||||
const CBlockIndex* pindex = m_chainman.m_blockman.FindForkInGlobalIndex(m_chainman.ActiveChain(), locator);
|
const CBlockIndex* pindex = m_chainman.ActiveChainstate().FindForkInGlobalIndex(locator);
|
||||||
|
|
||||||
// Send the rest of the chain
|
// Send the rest of the chain
|
||||||
if (pindex)
|
if (pindex)
|
||||||
@ -3203,7 +3203,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Find the last block the caller has in the main chain
|
// Find the last block the caller has in the main chain
|
||||||
pindex = m_chainman.m_blockman.FindForkInGlobalIndex(m_chainman.ActiveChain(), locator);
|
pindex = m_chainman.ActiveChainstate().FindForkInGlobalIndex(locator);
|
||||||
if (pindex)
|
if (pindex)
|
||||||
pindex = m_chainman.ActiveChain().Next(pindex);
|
pindex = m_chainman.ActiveChain().Next(pindex);
|
||||||
}
|
}
|
||||||
|
@ -494,8 +494,8 @@ public:
|
|||||||
std::optional<int> findLocatorFork(const CBlockLocator& locator) override
|
std::optional<int> findLocatorFork(const CBlockLocator& locator) override
|
||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
const CChain& active = Assert(m_node.chainman)->ActiveChain();
|
const CChainState& active = Assert(m_node.chainman)->ActiveChainstate();
|
||||||
if (CBlockIndex* fork = m_node.chainman->m_blockman.FindForkInGlobalIndex(active, locator)) {
|
if (CBlockIndex* fork = active.FindForkInGlobalIndex(locator)) {
|
||||||
return fork->nHeight;
|
return fork->nHeight;
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
@ -155,23 +155,24 @@ CBlockIndex* BlockManager::LookupBlockIndex(const uint256& hash) const
|
|||||||
return it == m_block_index.end() ? nullptr : it->second;
|
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);
|
AssertLockHeld(cs_main);
|
||||||
|
|
||||||
// Find the latest block common to locator and chain - we expect that
|
// Find the latest block common to locator and chain - we expect that
|
||||||
// locator.vHave is sorted descending by height.
|
// locator.vHave is sorted descending by height.
|
||||||
for (const uint256& hash : locator.vHave) {
|
for (const uint256& hash : locator.vHave) {
|
||||||
CBlockIndex* pindex = LookupBlockIndex(hash);
|
CBlockIndex* pindex{m_blockman.LookupBlockIndex(hash)};
|
||||||
if (pindex) {
|
if (pindex) {
|
||||||
if (chain.Contains(pindex))
|
if (m_chain.Contains(pindex)) {
|
||||||
return 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,
|
bool CheckInputScripts(const CTransaction& tx, TxValidationState& state,
|
||||||
|
@ -466,9 +466,6 @@ public:
|
|||||||
|
|
||||||
CBlockIndex* LookupBlockIndex(const uint256& hash) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
CBlockIndex* LookupBlockIndex(const uint256& hash) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
|
||||||
/** Find the last common block between the parameter chain and a locator. */
|
|
||||||
CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& locator) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
|
||||||
|
|
||||||
//! Returns last CBlockIndex* that is a checkpoint
|
//! Returns last CBlockIndex* that is a checkpoint
|
||||||
CBlockIndex* GetLastCheckpoint(const CCheckpointData& data) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
CBlockIndex* GetLastCheckpoint(const CCheckpointData& data) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
|
||||||
@ -756,6 +753,9 @@ public:
|
|||||||
/** Check whether we are doing an initial block download (synchronizing from disk or network) */
|
/** Check whether we are doing an initial block download (synchronizing from disk or network) */
|
||||||
bool IsInitialBlockDownload() const;
|
bool IsInitialBlockDownload() const;
|
||||||
|
|
||||||
|
/** Find the last common block of this chain and a locator. */
|
||||||
|
CBlockIndex* FindForkInGlobalIndex(const CBlockLocator& locator) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make various assertions about the state of the block index.
|
* Make various assertions about the state of the block index.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user