Prevent duplicate headers
This commit is contained in:
16
src/main.cpp
16
src/main.cpp
@@ -4964,14 +4964,18 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
|||||||
vector<CBlock> vHeaders;
|
vector<CBlock> vHeaders;
|
||||||
int nLimit = MAX_HEADERS_RESULTS;
|
int nLimit = MAX_HEADERS_RESULTS;
|
||||||
LogPrint("net", "getheaders %d to %s from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString(), pfrom->id);
|
LogPrint("net", "getheaders %d to %s from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString(), pfrom->id);
|
||||||
//fprintf(stderr,"getheaders from %d\n",(int32_t)(pindex ? pindex->nHeight : -1));
|
fprintf(stderr,"getheaders from %d prev.%d\n",(int32_t)(pindex ? pindex->nHeight : -1),pfrom->lasthdrsreq);
|
||||||
for (; pindex; pindex = chainActive.Next(pindex))
|
if ( pfrom->lasthdrsreq != (int32_t)(pindex ? pindex->nHeight : -1) )
|
||||||
{
|
{
|
||||||
vHeaders.push_back(pindex->GetBlockHeader());
|
for (; pindex; pindex = chainActive.Next(pindex))
|
||||||
if (--nLimit <= 0 || pindex->GetBlockHash() == hashStop)
|
{
|
||||||
break;
|
vHeaders.push_back(pindex->GetBlockHeader());
|
||||||
|
if (--nLimit <= 0 || pindex->GetBlockHash() == hashStop)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pfrom->PushMessage("headers", vHeaders);
|
||||||
|
pfrom->lasthdrsreq = (int32_t)(pindex ? pindex->nHeight : -1);
|
||||||
}
|
}
|
||||||
pfrom->PushMessage("headers", vHeaders);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -264,6 +264,7 @@ public:
|
|||||||
std::string addrName;
|
std::string addrName;
|
||||||
CService addrLocal;
|
CService addrLocal;
|
||||||
int nVersion;
|
int nVersion;
|
||||||
|
int lasthdrsreq;
|
||||||
// strSubVer is whatever byte array we read from the wire. However, this field is intended
|
// strSubVer is whatever byte array we read from the wire. However, this field is intended
|
||||||
// to be printed out, displayed to humans in various forms and so on. So we sanitize it and
|
// to be printed out, displayed to humans in various forms and so on. So we sanitize it and
|
||||||
// store the sanitized version in cleanSubVer. The original should be used when dealing with
|
// store the sanitized version in cleanSubVer. The original should be used when dealing with
|
||||||
|
|||||||
Reference in New Issue
Block a user