Skip to content

Commit 56212e2

Browse files
committed
net: set message deserialization version when it's actually time to deserialize
We'll soon no longer have access to vRecvMsg, and this is more intuitive anyway.
1 parent 0e973d9 commit 56212e2

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete
653653
// get current incomplete message, or create a new one
654654
if (vRecvMsg.empty() ||
655655
vRecvMsg.back().complete())
656-
vRecvMsg.push_back(CNetMessage(Params().MessageStart(), SER_NETWORK, nRecvVersion));
656+
vRecvMsg.push_back(CNetMessage(Params().MessageStart(), SER_NETWORK, INIT_PROTO_VERSION));
657657

658658
CNetMessage& msg = vRecvMsg.back();
659659

src/net.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ class CNode
607607
std::list<CNetMessage> vRecvMsg;
608608
CCriticalSection cs_vRecvMsg;
609609
uint64_t nRecvBytes;
610-
int nRecvVersion;
610+
std::atomic<int> nRecvVersion;
611611

612612
int64_t nLastSend;
613613
int64_t nLastRecv;
@@ -747,12 +747,13 @@ class CNode
747747
// requires LOCK(cs_vRecvMsg)
748748
bool ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete);
749749

750-
// requires LOCK(cs_vRecvMsg)
751750
void SetRecvVersion(int nVersionIn)
752751
{
753752
nRecvVersion = nVersionIn;
754-
BOOST_FOREACH(CNetMessage &msg, vRecvMsg)
755-
msg.SetVersion(nVersionIn);
753+
}
754+
int GetRecvVersion()
755+
{
756+
return nRecvVersion;
756757
}
757758
void SetSendVersion(int nVersionIn)
758759
{

src/net_processing.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,6 +2485,7 @@ bool ProcessMessages(CNode* pfrom, CConnman& connman, std::atomic<bool>& interru
24852485
// at this point, any failure means we can delete the current message
24862486
it++;
24872487

2488+
msg.SetVersion(pfrom->GetRecvVersion());
24882489
// Scan for message start
24892490
if (memcmp(msg.hdr.pchMessageStart, chainparams.MessageStart(), CMessageHeader::MESSAGE_START_SIZE) != 0) {
24902491
LogPrintf("PROCESSMESSAGE: INVALID MESSAGESTART %s peer=%d\n", SanitizeString(msg.hdr.GetCommand()), pfrom->id);

0 commit comments

Comments
 (0)