new CNetworkBlockHeader for robust compat
This commit is contained in:
@@ -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<CBlockHeader> vHeaders;
|
||||
// we must use CNetworkBlockHeader, as CBlockHeader won't include the 0x00 nTx count at the end for compatibility
|
||||
vector<CNetworkBlockHeader> 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<CBlockHeader> 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);
|
||||
|
||||
@@ -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<CTransaction> compatVec;
|
||||
|
||||
CNetworkBlockHeader() : CBlockHeader()
|
||||
{
|
||||
SetNull();
|
||||
}
|
||||
|
||||
CNetworkBlockHeader(const CBlockHeader &header)
|
||||
{
|
||||
SetNull();
|
||||
*((CBlockHeader*)this) = header;
|
||||
}
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user