aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/index/base.cpp2
-rw-r--r--src/net_processing.cpp4
-rw-r--r--src/node/interfaces.cpp4
-rw-r--r--src/validation.cpp13
-rw-r--r--src/validation.h6
5 files changed, 15 insertions, 14 deletions
diff --git a/src/index/base.cpp b/src/index/base.cpp
index 8525dcbfa0..419b6fa982 100644
--- a/src/index/base.cpp
+++ b/src/index/base.cpp
@@ -65,7 +65,7 @@ bool BaseIndex::Init()
if (locator.IsNull()) {
m_best_block_index = nullptr;
} 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();
if (!m_synced) {
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 2a30afdb5b..d4f0e94056 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -3083,7 +3083,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
LOCK(cs_main);
// 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
if (pindex)
@@ -3203,7 +3203,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
else
{
// 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)
pindex = m_chainman.ActiveChain().Next(pindex);
}
diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp
index 075842ef73..8109dce2c0 100644
--- a/src/node/interfaces.cpp
+++ b/src/node/interfaces.cpp
@@ -494,8 +494,8 @@ public:
std::optional<int> findLocatorFork(const CBlockLocator& locator) override
{
LOCK(cs_main);
- const CChain& active = Assert(m_node.chainman)->ActiveChain();
- if (CBlockIndex* fork = m_node.chainman->m_blockman.FindForkInGlobalIndex(active, locator)) {
+ const CChainState& active = Assert(m_node.chainman)->ActiveChainstate();
+ if (CBlockIndex* fork = active.FindForkInGlobalIndex(locator)) {
return fork->nHeight;
}
return std::nullopt;
diff --git a/src/validation.cpp b/src/validation.cpp
index 1aac71fb0f..c2d86d89c5 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -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,
diff --git a/src/validation.h b/src/validation.h
index 534df9bc87..27b8f4e906 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -466,9 +466,6 @@ public:
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
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) */
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.
*