mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-11 07:17:53 +00:00
minor fix to batched initial download in case requester has more than 500 block non-main branch
This commit is contained in:
parent
e4db374421
commit
70918a6645
4
main.cpp
4
main.cpp
@ -1960,8 +1960,8 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
|||||||
// Send the rest of the chain
|
// Send the rest of the chain
|
||||||
if (pindex)
|
if (pindex)
|
||||||
pindex = pindex->pnext;
|
pindex = pindex->pnext;
|
||||||
printf("getblocks %d to %s\n", (pindex ? pindex->nHeight : -1), hashStop.ToString().substr(0,16).c_str());
|
int nLimit = 500 + locator.GetDistanceBack();
|
||||||
int nLimit = 500;
|
printf("getblocks %d to %s limit %d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString().substr(0,16).c_str(), nLimit);
|
||||||
for (; pindex; pindex = pindex->pnext)
|
for (; pindex; pindex = pindex->pnext)
|
||||||
{
|
{
|
||||||
if (pindex->GetBlockHash() == hashStop)
|
if (pindex->GetBlockHash() == hashStop)
|
||||||
|
21
main.h
21
main.h
@ -1298,6 +1298,27 @@ public:
|
|||||||
vHave.push_back(hashGenesisBlock);
|
vHave.push_back(hashGenesisBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int GetDistanceBack()
|
||||||
|
{
|
||||||
|
// Retrace how far back it was in the sender's branch
|
||||||
|
int nDistance = 0;
|
||||||
|
int nStep = 1;
|
||||||
|
foreach(const uint256& hash, vHave)
|
||||||
|
{
|
||||||
|
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hash);
|
||||||
|
if (mi != mapBlockIndex.end())
|
||||||
|
{
|
||||||
|
CBlockIndex* pindex = (*mi).second;
|
||||||
|
if (pindex->IsInMainChain())
|
||||||
|
return nDistance;
|
||||||
|
}
|
||||||
|
nDistance += nStep;
|
||||||
|
if (nDistance > 10)
|
||||||
|
nStep *= 2;
|
||||||
|
}
|
||||||
|
return nDistance;
|
||||||
|
}
|
||||||
|
|
||||||
CBlockIndex* GetBlockIndex()
|
CBlockIndex* GetBlockIndex()
|
||||||
{
|
{
|
||||||
// Find the first block the caller has in the main chain
|
// Find the first block the caller has in the main chain
|
||||||
|
@ -20,7 +20,7 @@ class CDataStream;
|
|||||||
class CAutoFile;
|
class CAutoFile;
|
||||||
|
|
||||||
static const int VERSION = 106;
|
static const int VERSION = 106;
|
||||||
static const char* pszSubVer = " linux-test8";
|
static const char* pszSubVer = " linux-test9";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user