@@ -669,12 +669,12 @@ static void MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid, CConnman& connma
669669 // As per BIP152, we only get 3 of our peers to announce
670670 // blocks using compact encodings.
671671 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));
673673 return true ;
674674 });
675675 lNodesAnnouncingHeaderAndIDs.pop_front ();
676676 }
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));
678678 lNodesAnnouncingHeaderAndIDs.push_back (pfrom->GetId ());
679679 return true ;
680680 });
@@ -1359,7 +1359,7 @@ void PeerManager::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_
13591359 LockAssertion lock (::cs_main);
13601360
13611361 // 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 )
13631363 return ;
13641364 ProcessBlockAvailability (pnode->GetId ());
13651365 CNodeState &state = *State (pnode->GetId ());
@@ -1586,7 +1586,7 @@ void static ProcessGetBlockData(CNode& pfrom, const CChainParams& chainparams, c
15861586 LogPrint (BCLog::NET, " %s: ignoring request from peer=%i for old block that isn't in the main chain\n " , __func__, pfrom.GetId ());
15871587 }
15881588 }
1589- const CNetMsgMaker msgMaker (pfrom.GetSendVersion ());
1589+ const CNetMsgMaker msgMaker (pfrom.GetCommonVersion ());
15901590 // disconnect node in case we have reached the outbound limit for serving historical blocks
15911591 if (send &&
15921592 connman.OutboundTargetReached (true ) &&
@@ -1729,7 +1729,7 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm
17291729
17301730 std::deque<CInv>::iterator it = pfrom.vRecvGetData .begin ();
17311731 std::vector<CInv> vNotFound;
1732- const CNetMsgMaker msgMaker (pfrom.GetSendVersion ());
1732+ const CNetMsgMaker msgMaker (pfrom.GetCommonVersion ());
17331733
17341734 const std::chrono::seconds now = GetTime<std::chrono::seconds>();
17351735 // Get last mempool request time
@@ -1835,14 +1835,14 @@ void PeerManager::SendBlockTransactions(CNode& pfrom, const CBlock& block, const
18351835 resp.txn [i] = block.vtx [req.indexes [i]];
18361836 }
18371837 LOCK (cs_main);
1838- const CNetMsgMaker msgMaker (pfrom.GetSendVersion ());
1838+ const CNetMsgMaker msgMaker (pfrom.GetCommonVersion ());
18391839 int nSendFlags = State (pfrom.GetId ())->fWantsCmpctWitness ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS;
18401840 m_connman.PushMessage (&pfrom, msgMaker.Make (nSendFlags, NetMsgType::BLOCKTXN, resp));
18411841}
18421842
18431843void PeerManager::ProcessHeadersMessage (CNode& pfrom, const std::vector<CBlockHeader>& headers, bool via_compact_block)
18441844{
1845- const CNetMsgMaker msgMaker (pfrom.GetSendVersion ());
1845+ const CNetMsgMaker msgMaker (pfrom.GetCommonVersion ());
18461846 size_t nCount = headers.size ();
18471847
18481848 if (nCount == 0 ) {
@@ -2212,7 +2212,7 @@ static void ProcessGetCFilters(CNode& peer, CDataStream& vRecv, const CChainPara
22122212 }
22132213
22142214 for (const auto & filter : filters) {
2215- CSerializedNetMsg msg = CNetMsgMaker (peer.GetSendVersion ())
2215+ CSerializedNetMsg msg = CNetMsgMaker (peer.GetCommonVersion ())
22162216 .Make (NetMsgType::CFILTER, filter);
22172217 connman.PushMessage (&peer, std::move (msg));
22182218 }
@@ -2264,7 +2264,7 @@ static void ProcessGetCFHeaders(CNode& peer, CDataStream& vRecv, const CChainPar
22642264 return ;
22652265 }
22662266
2267- CSerializedNetMsg msg = CNetMsgMaker (peer.GetSendVersion ())
2267+ CSerializedNetMsg msg = CNetMsgMaker (peer.GetCommonVersion ())
22682268 .Make (NetMsgType::CFHEADERS,
22692269 filter_type_ser,
22702270 stop_index->GetBlockHash (),
@@ -2316,7 +2316,7 @@ static void ProcessGetCFCheckPt(CNode& peer, CDataStream& vRecv, const CChainPar
23162316 }
23172317 }
23182318
2319- CSerializedNetMsg msg = CNetMsgMaker (peer.GetSendVersion ())
2319+ CSerializedNetMsg msg = CNetMsgMaker (peer.GetCommonVersion ())
23202320 .Make (NetMsgType::CFCHECKPT,
23212321 filter_type_ser,
23222322 stop_index->GetBlockHash (),
@@ -2351,13 +2351,11 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
23512351 uint64_t nServiceInt;
23522352 ServiceFlags nServices;
23532353 int nVersion;
2354- int nSendVersion;
23552354 std::string cleanSubVer;
23562355 int nStartingHeight = -1 ;
23572356 bool fRelay = true ;
23582357
23592358 vRecv >> nVersion >> nServiceInt >> nTime >> addrMe;
2360- nSendVersion = std::min (nVersion, PROTOCOL_VERSION);
23612359 nServices = ServiceFlags (nServiceInt);
23622360 if (!pfrom.IsInboundConn ())
23632361 {
@@ -2406,11 +2404,16 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
24062404 if (pfrom.IsInboundConn ())
24072405 PushNodeVersion (pfrom, m_connman, GetAdjustedTime ());
24082406
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));
24112414 }
24122415
2413- m_connman.PushMessage (&pfrom, CNetMsgMaker (INIT_PROTO_VERSION ).Make (NetMsgType::VERACK));
2416+ m_connman.PushMessage (&pfrom, CNetMsgMaker (greatest_common_version ).Make (NetMsgType::VERACK));
24142417
24152418 pfrom.nServices = nServices;
24162419 pfrom.SetAddrLocal (addrMe);
@@ -2431,10 +2434,6 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
24312434 pfrom.m_tx_relay ->fRelayTxes = fRelay ; // set to true after we get the first filter* message
24322435 }
24332436
2434- // Change version
2435- pfrom.SetSendVersion (nSendVersion);
2436- pfrom.nVersion = nVersion;
2437-
24382437 if ((nServices & NODE_WITNESS))
24392438 {
24402439 LOCK (cs_main);
@@ -2480,7 +2479,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
24802479 }
24812480
24822481 // 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));
24842483 pfrom.fGetAddr = true ;
24852484
24862485 // 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
25022501 AddTimeData (pfrom.addr , nTimeOffset);
25032502
25042503 // 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 ) {
25062505 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));
25082507 }
25092508
25102509 // 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
25212520 }
25222521
25232522 // At this point, the outgoing message serialization version can't change.
2524- const CNetMsgMaker msgMaker (pfrom.GetSendVersion ());
2523+ const CNetMsgMaker msgMaker (pfrom.GetCommonVersion ());
25252524
25262525 if (msg_type == NetMsgType::VERACK)
25272526 {
2528- pfrom.SetRecvVersion (std::min (pfrom.nVersion .load (), PROTOCOL_VERSION));
2529-
25302527 if (!pfrom.IsInboundConn ()) {
25312528 // Mark this node as currently connected, so we update its timestamp later.
25322529 LOCK (cs_main);
@@ -2537,14 +2534,14 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
25372534 pfrom.m_tx_relay == nullptr ? " block-relay" : " full-relay" );
25382535 }
25392536
2540- if (pfrom.nVersion >= SENDHEADERS_VERSION) {
2537+ if (pfrom.GetCommonVersion () >= SENDHEADERS_VERSION) {
25412538 // Tell our peer we prefer to receive headers rather than inv's
25422539 // We send this to non-NODE NETWORK peers as well, because even
25432540 // non-NODE NETWORK peers can announce blocks (such as pruning
25442541 // nodes)
25452542 m_connman.PushMessage (&pfrom, msgMaker.Make (NetMsgType::SENDHEADERS));
25462543 }
2547- if (pfrom.nVersion >= SHORT_IDS_BLOCKS_VERSION) {
2544+ if (pfrom.GetCommonVersion () >= SHORT_IDS_BLOCKS_VERSION) {
25482545 // Tell our peer we are willing to provide version 1 or 2 cmpctblocks
25492546 // However, we do not request new block announcements using
25502547 // cmpctblock messages.
@@ -2570,7 +2567,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
25702567 pfrom.fDisconnect = true ;
25712568 return ;
25722569 }
2573- if (pfrom.nVersion >= WTXID_RELAY_VERSION) {
2570+ if (pfrom.GetCommonVersion () >= WTXID_RELAY_VERSION) {
25742571 LOCK (cs_main);
25752572 if (!State (pfrom.GetId ())->m_wtxid_relay ) {
25762573 State (pfrom.GetId ())->m_wtxid_relay = true ;
@@ -3583,8 +3580,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
35833580 }
35843581
35853582 if (msg_type == NetMsgType::PING) {
3586- if (pfrom.nVersion > BIP0031_VERSION)
3587- {
3583+ if (pfrom.GetCommonVersion () > BIP0031_VERSION) {
35883584 uint64_t nonce = 0 ;
35893585 vRecv >> nonce;
35903586 // 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
38713867 }
38723868 CNetMessage& msg (msgs.front ());
38733869
3874- msg.SetVersion (pfrom->GetRecvVersion ());
3870+ msg.SetVersion (pfrom->GetCommonVersion ());
38753871 // Check network magic
38763872 if (!msg.m_valid_netmagic ) {
38773873 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)
39193915 AssertLockHeld (cs_main);
39203916
39213917 CNodeState &state = *State (pto.GetId ());
3922- const CNetMsgMaker msgMaker (pto.GetSendVersion ());
3918+ const CNetMsgMaker msgMaker (pto.GetCommonVersion ());
39233919
39243920 if (!state.m_chain_sync .m_protect && pto.IsOutboundOrBlockRelayConn () && state.fSyncStarted ) {
39253921 // This is an outbound peer subject to disconnection if they don't
@@ -4081,7 +4077,7 @@ bool PeerManager::SendMessages(CNode* pto)
40814077 return true ;
40824078
40834079 // 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 ());
40854081
40864082 //
40874083 // Message: ping
@@ -4102,7 +4098,7 @@ bool PeerManager::SendMessages(CNode* pto)
41024098 }
41034099 pto->fPingQueued = false ;
41044100 pto->m_ping_start = GetTime<std::chrono::microseconds>();
4105- if (pto->nVersion > BIP0031_VERSION) {
4101+ if (pto->GetCommonVersion () > BIP0031_VERSION) {
41064102 pto->nPingNonceSent = nonce;
41074103 m_connman.PushMessage (pto, msgMaker.Make (NetMsgType::PING, nonce));
41084104 } else {
@@ -4641,7 +4637,7 @@ bool PeerManager::SendMessages(CNode* pto)
46414637 //
46424638 // Message: feefilter
46434639 //
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) &&
46454641 !pto->HasPermission (PF_FORCERELAY) // peers with the forcerelay permission should not filter txs to us
46464642 ) {
46474643 CAmount currentFilter = m_mempool.GetMinFee (gArgs .GetArg (" -maxmempool" , DEFAULT_MAX_MEMPOOL_SIZE) * 1000000 ).GetFeePerK ();
0 commit comments