@@ -669,12 +669,12 @@ static void MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid, CConnman& connma
669
669
// As per BIP152, we only get 3 of our peers to announce
670
670
// blocks using compact encodings.
671
671
connman.ForNode (lNodesAnnouncingHeaderAndIDs.front (), [&connman, nCMPCTBLOCKVersion](CNode* pnodeStop){
672
- connman.PushMessage (pnodeStop, CNetMsgMaker (pnodeStop->GetSendVersion ()).Make (NetMsgType::SENDCMPCT, /* fAnnounceUsingCMPCTBLOCK=*/ false , nCMPCTBLOCKVersion));
672
+ connman.PushMessage (pnodeStop, CNetMsgMaker (pnodeStop->GetCommonVersion ()).Make (NetMsgType::SENDCMPCT, /* fAnnounceUsingCMPCTBLOCK=*/ false , nCMPCTBLOCKVersion));
673
673
return true ;
674
674
});
675
675
lNodesAnnouncingHeaderAndIDs.pop_front ();
676
676
}
677
- connman.PushMessage (pfrom, CNetMsgMaker (pfrom->GetSendVersion ()).Make (NetMsgType::SENDCMPCT, /* fAnnounceUsingCMPCTBLOCK=*/ true , nCMPCTBLOCKVersion));
677
+ connman.PushMessage (pfrom, CNetMsgMaker (pfrom->GetCommonVersion ()).Make (NetMsgType::SENDCMPCT, /* fAnnounceUsingCMPCTBLOCK=*/ true , nCMPCTBLOCKVersion));
678
678
lNodesAnnouncingHeaderAndIDs.push_back (pfrom->GetId ());
679
679
return true ;
680
680
});
@@ -1359,7 +1359,7 @@ void PeerManager::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_
1359
1359
LockAssertion lock (::cs_main);
1360
1360
1361
1361
// TODO: Avoid the repeated-serialization here
1362
- if (pnode->nVersion < INVALID_CB_NO_BAN_VERSION || pnode->fDisconnect )
1362
+ if (pnode->GetCommonVersion () < INVALID_CB_NO_BAN_VERSION || pnode->fDisconnect )
1363
1363
return ;
1364
1364
ProcessBlockAvailability (pnode->GetId ());
1365
1365
CNodeState &state = *State (pnode->GetId ());
@@ -1586,7 +1586,7 @@ void static ProcessGetBlockData(CNode& pfrom, const CChainParams& chainparams, c
1586
1586
LogPrint (BCLog::NET, " %s: ignoring request from peer=%i for old block that isn't in the main chain\n " , __func__, pfrom.GetId ());
1587
1587
}
1588
1588
}
1589
- const CNetMsgMaker msgMaker (pfrom.GetSendVersion ());
1589
+ const CNetMsgMaker msgMaker (pfrom.GetCommonVersion ());
1590
1590
// disconnect node in case we have reached the outbound limit for serving historical blocks
1591
1591
if (send &&
1592
1592
connman.OutboundTargetReached (true ) &&
@@ -1729,7 +1729,7 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm
1729
1729
1730
1730
std::deque<CInv>::iterator it = pfrom.vRecvGetData .begin ();
1731
1731
std::vector<CInv> vNotFound;
1732
- const CNetMsgMaker msgMaker (pfrom.GetSendVersion ());
1732
+ const CNetMsgMaker msgMaker (pfrom.GetCommonVersion ());
1733
1733
1734
1734
const std::chrono::seconds now = GetTime<std::chrono::seconds>();
1735
1735
// Get last mempool request time
@@ -1835,14 +1835,14 @@ void PeerManager::SendBlockTransactions(CNode& pfrom, const CBlock& block, const
1835
1835
resp.txn [i] = block.vtx [req.indexes [i]];
1836
1836
}
1837
1837
LOCK (cs_main);
1838
- const CNetMsgMaker msgMaker (pfrom.GetSendVersion ());
1838
+ const CNetMsgMaker msgMaker (pfrom.GetCommonVersion ());
1839
1839
int nSendFlags = State (pfrom.GetId ())->fWantsCmpctWitness ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS;
1840
1840
m_connman.PushMessage (&pfrom, msgMaker.Make (nSendFlags, NetMsgType::BLOCKTXN, resp));
1841
1841
}
1842
1842
1843
1843
void PeerManager::ProcessHeadersMessage (CNode& pfrom, const std::vector<CBlockHeader>& headers, bool via_compact_block)
1844
1844
{
1845
- const CNetMsgMaker msgMaker (pfrom.GetSendVersion ());
1845
+ const CNetMsgMaker msgMaker (pfrom.GetCommonVersion ());
1846
1846
size_t nCount = headers.size ();
1847
1847
1848
1848
if (nCount == 0 ) {
@@ -2212,7 +2212,7 @@ static void ProcessGetCFilters(CNode& peer, CDataStream& vRecv, const CChainPara
2212
2212
}
2213
2213
2214
2214
for (const auto & filter : filters) {
2215
- CSerializedNetMsg msg = CNetMsgMaker (peer.GetSendVersion ())
2215
+ CSerializedNetMsg msg = CNetMsgMaker (peer.GetCommonVersion ())
2216
2216
.Make (NetMsgType::CFILTER, filter);
2217
2217
connman.PushMessage (&peer, std::move (msg));
2218
2218
}
@@ -2264,7 +2264,7 @@ static void ProcessGetCFHeaders(CNode& peer, CDataStream& vRecv, const CChainPar
2264
2264
return ;
2265
2265
}
2266
2266
2267
- CSerializedNetMsg msg = CNetMsgMaker (peer.GetSendVersion ())
2267
+ CSerializedNetMsg msg = CNetMsgMaker (peer.GetCommonVersion ())
2268
2268
.Make (NetMsgType::CFHEADERS,
2269
2269
filter_type_ser,
2270
2270
stop_index->GetBlockHash (),
@@ -2316,7 +2316,7 @@ static void ProcessGetCFCheckPt(CNode& peer, CDataStream& vRecv, const CChainPar
2316
2316
}
2317
2317
}
2318
2318
2319
- CSerializedNetMsg msg = CNetMsgMaker (peer.GetSendVersion ())
2319
+ CSerializedNetMsg msg = CNetMsgMaker (peer.GetCommonVersion ())
2320
2320
.Make (NetMsgType::CFCHECKPT,
2321
2321
filter_type_ser,
2322
2322
stop_index->GetBlockHash (),
@@ -2351,13 +2351,11 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
2351
2351
uint64_t nServiceInt;
2352
2352
ServiceFlags nServices;
2353
2353
int nVersion;
2354
- int nSendVersion;
2355
2354
std::string cleanSubVer;
2356
2355
int nStartingHeight = -1 ;
2357
2356
bool fRelay = true ;
2358
2357
2359
2358
vRecv >> nVersion >> nServiceInt >> nTime >> addrMe;
2360
- nSendVersion = std::min (nVersion, PROTOCOL_VERSION);
2361
2359
nServices = ServiceFlags (nServiceInt);
2362
2360
if (!pfrom.IsInboundConn ())
2363
2361
{
@@ -2406,11 +2404,16 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
2406
2404
if (pfrom.IsInboundConn ())
2407
2405
PushNodeVersion (pfrom, m_connman, GetAdjustedTime ());
2408
2406
2409
- if (nVersion >= WTXID_RELAY_VERSION) {
2410
- m_connman.PushMessage (&pfrom, CNetMsgMaker (INIT_PROTO_VERSION).Make (NetMsgType::WTXIDRELAY));
2407
+ // Change version
2408
+ const int greatest_common_version = std::min (nVersion, PROTOCOL_VERSION);
2409
+ pfrom.SetCommonVersion (greatest_common_version);
2410
+ pfrom.nVersion = nVersion;
2411
+
2412
+ if (greatest_common_version >= WTXID_RELAY_VERSION) {
2413
+ m_connman.PushMessage (&pfrom, CNetMsgMaker (greatest_common_version).Make (NetMsgType::WTXIDRELAY));
2411
2414
}
2412
2415
2413
- m_connman.PushMessage (&pfrom, CNetMsgMaker (INIT_PROTO_VERSION ).Make (NetMsgType::VERACK));
2416
+ m_connman.PushMessage (&pfrom, CNetMsgMaker (greatest_common_version ).Make (NetMsgType::VERACK));
2414
2417
2415
2418
pfrom.nServices = nServices;
2416
2419
pfrom.SetAddrLocal (addrMe);
@@ -2431,10 +2434,6 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
2431
2434
pfrom.m_tx_relay ->fRelayTxes = fRelay ; // set to true after we get the first filter* message
2432
2435
}
2433
2436
2434
- // Change version
2435
- pfrom.SetSendVersion (nSendVersion);
2436
- pfrom.nVersion = nVersion;
2437
-
2438
2437
if ((nServices & NODE_WITNESS))
2439
2438
{
2440
2439
LOCK (cs_main);
@@ -2480,7 +2479,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
2480
2479
}
2481
2480
2482
2481
// Get recent addresses
2483
- m_connman.PushMessage (&pfrom, CNetMsgMaker (nSendVersion ).Make (NetMsgType::GETADDR));
2482
+ m_connman.PushMessage (&pfrom, CNetMsgMaker (greatest_common_version ).Make (NetMsgType::GETADDR));
2484
2483
pfrom.fGetAddr = true ;
2485
2484
2486
2485
// Moves address from New to Tried table in Addrman, resolves
@@ -2502,9 +2501,9 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
2502
2501
AddTimeData (pfrom.addr , nTimeOffset);
2503
2502
2504
2503
// If the peer is old enough to have the old alert system, send it the final alert.
2505
- if (pfrom. nVersion <= 70012 ) {
2504
+ if (greatest_common_version <= 70012 ) {
2506
2505
CDataStream finalAlert (ParseHex (" 60010000000000000000000000ffffff7f00000000ffffff7ffeffff7f01ffffff7f00000000ffffff7f00ffffff7f002f555247454e543a20416c657274206b657920636f6d70726f6d697365642c2075706772616465207265717569726564004630440220653febd6410f470f6bae11cad19c48413becb1ac2c17f908fd0fd53bdc3abd5202206d0e9c96fe88d4a0f01ed9dedae2b6f9e00da94cad0fecaae66ecf689bf71b50" ), SER_NETWORK, PROTOCOL_VERSION);
2507
- m_connman.PushMessage (&pfrom, CNetMsgMaker (nSendVersion ).Make (" alert" , finalAlert));
2506
+ m_connman.PushMessage (&pfrom, CNetMsgMaker (greatest_common_version ).Make (" alert" , finalAlert));
2508
2507
}
2509
2508
2510
2509
// Feeler connections exist only to verify if address is online.
@@ -2521,12 +2520,10 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
2521
2520
}
2522
2521
2523
2522
// At this point, the outgoing message serialization version can't change.
2524
- const CNetMsgMaker msgMaker (pfrom.GetSendVersion ());
2523
+ const CNetMsgMaker msgMaker (pfrom.GetCommonVersion ());
2525
2524
2526
2525
if (msg_type == NetMsgType::VERACK)
2527
2526
{
2528
- pfrom.SetRecvVersion (std::min (pfrom.nVersion .load (), PROTOCOL_VERSION));
2529
-
2530
2527
if (!pfrom.IsInboundConn ()) {
2531
2528
// Mark this node as currently connected, so we update its timestamp later.
2532
2529
LOCK (cs_main);
@@ -2537,14 +2534,14 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
2537
2534
pfrom.m_tx_relay == nullptr ? " block-relay" : " full-relay" );
2538
2535
}
2539
2536
2540
- if (pfrom.nVersion >= SENDHEADERS_VERSION) {
2537
+ if (pfrom.GetCommonVersion () >= SENDHEADERS_VERSION) {
2541
2538
// Tell our peer we prefer to receive headers rather than inv's
2542
2539
// We send this to non-NODE NETWORK peers as well, because even
2543
2540
// non-NODE NETWORK peers can announce blocks (such as pruning
2544
2541
// nodes)
2545
2542
m_connman.PushMessage (&pfrom, msgMaker.Make (NetMsgType::SENDHEADERS));
2546
2543
}
2547
- if (pfrom.nVersion >= SHORT_IDS_BLOCKS_VERSION) {
2544
+ if (pfrom.GetCommonVersion () >= SHORT_IDS_BLOCKS_VERSION) {
2548
2545
// Tell our peer we are willing to provide version 1 or 2 cmpctblocks
2549
2546
// However, we do not request new block announcements using
2550
2547
// cmpctblock messages.
@@ -2570,7 +2567,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
2570
2567
pfrom.fDisconnect = true ;
2571
2568
return ;
2572
2569
}
2573
- if (pfrom.nVersion >= WTXID_RELAY_VERSION) {
2570
+ if (pfrom.GetCommonVersion () >= WTXID_RELAY_VERSION) {
2574
2571
LOCK (cs_main);
2575
2572
if (!State (pfrom.GetId ())->m_wtxid_relay ) {
2576
2573
State (pfrom.GetId ())->m_wtxid_relay = true ;
@@ -3583,8 +3580,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
3583
3580
}
3584
3581
3585
3582
if (msg_type == NetMsgType::PING) {
3586
- if (pfrom.nVersion > BIP0031_VERSION)
3587
- {
3583
+ if (pfrom.GetCommonVersion () > BIP0031_VERSION) {
3588
3584
uint64_t nonce = 0 ;
3589
3585
vRecv >> nonce;
3590
3586
// Echo the message back with the nonce. This allows for two useful features:
@@ -3871,7 +3867,7 @@ bool PeerManager::ProcessMessages(CNode* pfrom, std::atomic<bool>& interruptMsgP
3871
3867
}
3872
3868
CNetMessage& msg (msgs.front ());
3873
3869
3874
- msg.SetVersion (pfrom->GetRecvVersion ());
3870
+ msg.SetVersion (pfrom->GetCommonVersion ());
3875
3871
// Check network magic
3876
3872
if (!msg.m_valid_netmagic ) {
3877
3873
LogPrint (BCLog::NET, " PROCESSMESSAGE: INVALID MESSAGESTART %s peer=%d\n " , SanitizeString (msg.m_command ), pfrom->GetId ());
@@ -3919,7 +3915,7 @@ void PeerManager::ConsiderEviction(CNode& pto, int64_t time_in_seconds)
3919
3915
AssertLockHeld (cs_main);
3920
3916
3921
3917
CNodeState &state = *State (pto.GetId ());
3922
- const CNetMsgMaker msgMaker (pto.GetSendVersion ());
3918
+ const CNetMsgMaker msgMaker (pto.GetCommonVersion ());
3923
3919
3924
3920
if (!state.m_chain_sync .m_protect && pto.IsOutboundOrBlockRelayConn () && state.fSyncStarted ) {
3925
3921
// This is an outbound peer subject to disconnection if they don't
@@ -4081,7 +4077,7 @@ bool PeerManager::SendMessages(CNode* pto)
4081
4077
return true ;
4082
4078
4083
4079
// If we get here, the outgoing message serialization version is set and can't change.
4084
- const CNetMsgMaker msgMaker (pto->GetSendVersion ());
4080
+ const CNetMsgMaker msgMaker (pto->GetCommonVersion ());
4085
4081
4086
4082
//
4087
4083
// Message: ping
@@ -4102,7 +4098,7 @@ bool PeerManager::SendMessages(CNode* pto)
4102
4098
}
4103
4099
pto->fPingQueued = false ;
4104
4100
pto->m_ping_start = GetTime<std::chrono::microseconds>();
4105
- if (pto->nVersion > BIP0031_VERSION) {
4101
+ if (pto->GetCommonVersion () > BIP0031_VERSION) {
4106
4102
pto->nPingNonceSent = nonce;
4107
4103
m_connman.PushMessage (pto, msgMaker.Make (NetMsgType::PING, nonce));
4108
4104
} else {
@@ -4641,7 +4637,7 @@ bool PeerManager::SendMessages(CNode* pto)
4641
4637
//
4642
4638
// Message: feefilter
4643
4639
//
4644
- if (pto->m_tx_relay != nullptr && pto->nVersion >= FEEFILTER_VERSION && gArgs .GetBoolArg (" -feefilter" , DEFAULT_FEEFILTER) &&
4640
+ if (pto->m_tx_relay != nullptr && pto->GetCommonVersion () >= FEEFILTER_VERSION && gArgs .GetBoolArg (" -feefilter" , DEFAULT_FEEFILTER) &&
4645
4641
!pto->HasPermission (PF_FORCERELAY) // peers with the forcerelay permission should not filter txs to us
4646
4642
) {
4647
4643
CAmount currentFilter = m_mempool.GetMinFee (gArgs .GetArg (" -maxmempool" , DEFAULT_MAX_MEMPOOL_SIZE) * 1000000 ).GetFeePerK ();
0 commit comments