|
|
@ -431,18 +431,19 @@ CBlockLocator CChain::GetLocator(const CBlockIndex *pindex) const {
|
|
|
|
return CBlockLocator(vHave);
|
|
|
|
return CBlockLocator(vHave);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CBlockIndex *CChain::FindFork(const CBlockLocator &locator) const {
|
|
|
|
CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& locator)
|
|
|
|
|
|
|
|
{
|
|
|
|
// Find the first block the caller has in the main chain
|
|
|
|
// Find the first block the caller has in the main chain
|
|
|
|
BOOST_FOREACH(const uint256& hash, locator.vHave) {
|
|
|
|
BOOST_FOREACH(const uint256& hash, locator.vHave) {
|
|
|
|
BlockMap::iterator mi = mapBlockIndex.find(hash);
|
|
|
|
BlockMap::iterator mi = mapBlockIndex.find(hash);
|
|
|
|
if (mi != mapBlockIndex.end())
|
|
|
|
if (mi != mapBlockIndex.end())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CBlockIndex* pindex = (*mi).second;
|
|
|
|
CBlockIndex* pindex = (*mi).second;
|
|
|
|
if (Contains(pindex))
|
|
|
|
if (chain.Contains(pindex))
|
|
|
|
return pindex;
|
|
|
|
return pindex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Genesis();
|
|
|
|
return chain.Genesis();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const CBlockIndex *CChain::FindFork(const CBlockIndex *pindex) const {
|
|
|
|
const CBlockIndex *CChain::FindFork(const CBlockIndex *pindex) const {
|
|
|
@ -3672,7 +3673,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
|
|
|
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
|
|
|
|
CBlockIndex* pindex = chainActive.FindFork(locator);
|
|
|
|
CBlockIndex* pindex = FindForkInGlobalIndex(chainActive, locator);
|
|
|
|
|
|
|
|
|
|
|
|
// Send the rest of the chain
|
|
|
|
// Send the rest of the chain
|
|
|
|
if (pindex)
|
|
|
|
if (pindex)
|
|
|
@ -3719,7 +3720,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
|
|
|
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 = chainActive.FindFork(locator);
|
|
|
|
pindex = FindForkInGlobalIndex(chainActive, locator);
|
|
|
|
if (pindex)
|
|
|
|
if (pindex)
|
|
|
|
pindex = chainActive.Next(pindex);
|
|
|
|
pindex = chainActive.Next(pindex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|