diff --git a/src/main.cpp b/src/main.cpp index f3790ada2..3d520e4e7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6015,8 +6015,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, pindex = chainActive.Next(pindex); } - // we must use CBlocks, as CBlockHeaders won't include the 0x00 nTx count at the end - vector vHeaders; + // we must use CNetworkBlockHeader, as CBlockHeader won't include the 0x00 nTx count at the end for compatibility + vector vHeaders; int nLimit = MAX_HEADERS_RESULTS; LogPrint("net", "getheaders %d to %s from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString(), pfrom->id); //if ( pfrom->lasthdrsreq >= chainActive.Height()-MAX_HEADERS_RESULTS || pfrom->lasthdrsreq != (int32_t)(pindex ? pindex->nHeight : -1) )// no need to ever suppress this @@ -6170,8 +6170,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, Misbehaving(pfrom->GetId(), nDoS); } } - - + else if (strCommand == "headers" && !fImporting && !fReindex) // Ignore headers received while importing { std::vector headers; @@ -6185,7 +6184,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, headers.resize(nCount); for (unsigned int n = 0; n < nCount; n++) { vRecv >> headers[n]; - //ReadCompactSize(vRecv); // ignore tx count; assume it is 0. + ReadCompactSize(vRecv); // ignore tx count; assume it is 0. } LOCK(cs_main); diff --git a/src/primitives/block.h b/src/primitives/block.h index 997e7e0e0..f46943f99 100644 --- a/src/primitives/block.h +++ b/src/primitives/block.h @@ -129,6 +129,42 @@ public: } }; +// this class is used to address the type mismatch that existed between nodes, where block headers +// were being serialized by senders as CBlock and deserialized as CBlockHeader + an assumed extra +// compact value. although it was working, I made this because it did break, and makes the connection +// between CBlock and CBlockHeader more brittle. +// by using this intentionally specified class instead, we remove an instability in the code that could break +// due to unrelated changes, but stay compatible with the old method. +class CNetworkBlockHeader : public CBlockHeader +{ + public: + std::vector compatVec; + + CNetworkBlockHeader() : CBlockHeader() + { + SetNull(); + } + + CNetworkBlockHeader(const CBlockHeader &header) + { + SetNull(); + *((CBlockHeader*)this) = header; + } + + ADD_SERIALIZE_METHODS; + + template + inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { + READWRITE(*(CBlockHeader*)this); + READWRITE(compatVec); + } + + void SetNull() + { + CBlockHeader::SetNull(); + compatVec.clear(); + } +}; class CBlock : public CBlockHeader { @@ -147,6 +183,7 @@ public: CBlock(const CBlockHeader &header) { SetNull(); + *((CBlockHeader*)this) = header; } ADD_SERIALIZE_METHODS;