Skip to content

Commit ddefb5c

Browse files
committed
p2p: Use the greatest common version in peer logic
1 parent e084d45 commit ddefb5c

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ void CConnman::InactivityCheck(CNode *pnode)
11671167
LogPrintf("socket sending timeout: %is\n", nTime - pnode->nLastSend);
11681168
pnode->fDisconnect = true;
11691169
}
1170-
else if (nTime - pnode->nLastRecv > (pnode->nVersion > BIP0031_VERSION ? TIMEOUT_INTERVAL : 90*60))
1170+
else if (nTime - pnode->nLastRecv > (pnode->GetCommonVersion() > BIP0031_VERSION ? TIMEOUT_INTERVAL : 90*60))
11711171
{
11721172
LogPrintf("socket receive timeout: %is\n", nTime - pnode->nLastRecv);
11731173
pnode->fDisconnect = true;

src/net_processing.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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());
@@ -2408,7 +2408,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
24082408
pfrom.SetCommonVersion(greatest_common_version);
24092409
pfrom.nVersion = nVersion;
24102410

2411-
if (nVersion >= WTXID_RELAY_VERSION) {
2411+
if (greatest_common_version >= WTXID_RELAY_VERSION) {
24122412
m_connman.PushMessage(&pfrom, CNetMsgMaker(greatest_common_version).Make(NetMsgType::WTXIDRELAY));
24132413
}
24142414

@@ -2500,7 +2500,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
25002500
AddTimeData(pfrom.addr, nTimeOffset);
25012501

25022502
// If the peer is old enough to have the old alert system, send it the final alert.
2503-
if (pfrom.nVersion <= 70012) {
2503+
if (greatest_common_version <= 70012) {
25042504
CDataStream finalAlert(ParseHex("60010000000000000000000000ffffff7f00000000ffffff7ffeffff7f01ffffff7f00000000ffffff7f00ffffff7f002f555247454e543a20416c657274206b657920636f6d70726f6d697365642c2075706772616465207265717569726564004630440220653febd6410f470f6bae11cad19c48413becb1ac2c17f908fd0fd53bdc3abd5202206d0e9c96fe88d4a0f01ed9dedae2b6f9e00da94cad0fecaae66ecf689bf71b50"), SER_NETWORK, PROTOCOL_VERSION);
25052505
m_connman.PushMessage(&pfrom, CNetMsgMaker(greatest_common_version).Make("alert", finalAlert));
25062506
}
@@ -2533,14 +2533,14 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
25332533
pfrom.m_tx_relay == nullptr ? "block-relay" : "full-relay");
25342534
}
25352535

2536-
if (pfrom.nVersion >= SENDHEADERS_VERSION) {
2536+
if (pfrom.GetCommonVersion() >= SENDHEADERS_VERSION) {
25372537
// Tell our peer we prefer to receive headers rather than inv's
25382538
// We send this to non-NODE NETWORK peers as well, because even
25392539
// non-NODE NETWORK peers can announce blocks (such as pruning
25402540
// nodes)
25412541
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::SENDHEADERS));
25422542
}
2543-
if (pfrom.nVersion >= SHORT_IDS_BLOCKS_VERSION) {
2543+
if (pfrom.GetCommonVersion() >= SHORT_IDS_BLOCKS_VERSION) {
25442544
// Tell our peer we are willing to provide version 1 or 2 cmpctblocks
25452545
// However, we do not request new block announcements using
25462546
// cmpctblock messages.
@@ -2566,7 +2566,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
25662566
pfrom.fDisconnect = true;
25672567
return;
25682568
}
2569-
if (pfrom.nVersion >= WTXID_RELAY_VERSION) {
2569+
if (pfrom.GetCommonVersion() >= WTXID_RELAY_VERSION) {
25702570
LOCK(cs_main);
25712571
if (!State(pfrom.GetId())->m_wtxid_relay) {
25722572
State(pfrom.GetId())->m_wtxid_relay = true;
@@ -3581,8 +3581,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
35813581
}
35823582

35833583
if (msg_type == NetMsgType::PING) {
3584-
if (pfrom.nVersion > BIP0031_VERSION)
3585-
{
3584+
if (pfrom.GetCommonVersion() > BIP0031_VERSION) {
35863585
uint64_t nonce = 0;
35873586
vRecv >> nonce;
35883587
// Echo the message back with the nonce. This allows for two useful features:
@@ -4100,7 +4099,7 @@ bool PeerManager::SendMessages(CNode* pto)
41004099
}
41014100
pto->fPingQueued = false;
41024101
pto->m_ping_start = GetTime<std::chrono::microseconds>();
4103-
if (pto->nVersion > BIP0031_VERSION) {
4102+
if (pto->GetCommonVersion() > BIP0031_VERSION) {
41044103
pto->nPingNonceSent = nonce;
41054104
m_connman.PushMessage(pto, msgMaker.Make(NetMsgType::PING, nonce));
41064105
} else {
@@ -4639,7 +4638,7 @@ bool PeerManager::SendMessages(CNode* pto)
46394638
//
46404639
// Message: feefilter
46414640
//
4642-
if (pto->m_tx_relay != nullptr && pto->nVersion >= FEEFILTER_VERSION && gArgs.GetBoolArg("-feefilter", DEFAULT_FEEFILTER) &&
4641+
if (pto->m_tx_relay != nullptr && pto->GetCommonVersion() >= FEEFILTER_VERSION && gArgs.GetBoolArg("-feefilter", DEFAULT_FEEFILTER) &&
46434642
!pto->HasPermission(PF_FORCERELAY) // peers with the forcerelay permission should not filter txs to us
46444643
) {
46454644
CAmount currentFilter = m_mempool.GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK();

0 commit comments

Comments
 (0)