Skip to content

Commit 30bc8fa

Browse files
committed
net: save high-bandwidth mode states in CNodeStats
1 parent 655937e commit 30bc8fa

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/net.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,8 @@ void CNode::copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap)
563563
}
564564
stats.fInbound = IsInboundConn();
565565
stats.m_manual_connection = IsManualConn();
566+
X(m_bip152_highbandwidth_to);
567+
X(m_bip152_highbandwidth_from);
566568
X(nStartingHeight);
567569
{
568570
LOCK(cs_vSend);

src/net.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,8 @@ class CNodeStats
681681
std::string cleanSubVer;
682682
bool fInbound;
683683
bool m_manual_connection;
684+
bool m_bip152_highbandwidth_to;
685+
bool m_bip152_highbandwidth_from;
684686
int nStartingHeight;
685687
uint64_t nSendBytes;
686688
mapMsgCmdSize mapSendBytesPerMsgCmd;
@@ -942,6 +944,10 @@ class CNode
942944
public:
943945
uint256 hashContinue;
944946
std::atomic<int> nStartingHeight{-1};
947+
// We selected peer as (compact blocks) high-bandwidth peer (BIP152)
948+
std::atomic<bool> m_bip152_highbandwidth_to{false};
949+
// Peer selected us as (compact blocks) high-bandwidth peer (BIP152)
950+
std::atomic<bool> m_bip152_highbandwidth_from{false};
945951

946952
// flood relay
947953
std::vector<CAddress> vAddrToSend;

src/net_processing.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,11 +670,15 @@ static void MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid, CConnman& connma
670670
// blocks using compact encodings.
671671
connman.ForNode(lNodesAnnouncingHeaderAndIDs.front(), [&connman, nCMPCTBLOCKVersion](CNode* pnodeStop){
672672
connman.PushMessage(pnodeStop, CNetMsgMaker(pnodeStop->GetCommonVersion()).Make(NetMsgType::SENDCMPCT, /*fAnnounceUsingCMPCTBLOCK=*/false, nCMPCTBLOCKVersion));
673+
// save BIP152 bandwidth state: we select peer to be low-bandwidth
674+
pnodeStop->m_bip152_highbandwidth_to = false;
673675
return true;
674676
});
675677
lNodesAnnouncingHeaderAndIDs.pop_front();
676678
}
677679
connman.PushMessage(pfrom, CNetMsgMaker(pfrom->GetCommonVersion()).Make(NetMsgType::SENDCMPCT, /*fAnnounceUsingCMPCTBLOCK=*/true, nCMPCTBLOCKVersion));
680+
// save BIP152 bandwidth state: we select peer to be high-bandwidth
681+
pfrom->m_bip152_highbandwidth_to = true;
678682
lNodesAnnouncingHeaderAndIDs.push_back(pfrom->GetId());
679683
return true;
680684
});
@@ -2652,8 +2656,12 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
26522656
State(pfrom.GetId())->fProvidesHeaderAndIDs = true;
26532657
State(pfrom.GetId())->fWantsCmpctWitness = nCMPCTBLOCKVersion == 2;
26542658
}
2655-
if (State(pfrom.GetId())->fWantsCmpctWitness == (nCMPCTBLOCKVersion == 2)) // ignore later version announces
2659+
if (State(pfrom.GetId())->fWantsCmpctWitness == (nCMPCTBLOCKVersion == 2)) { // ignore later version announces
26562660
State(pfrom.GetId())->fPreferHeaderAndIDs = fAnnounceUsingCMPCTBLOCK;
2661+
// save whether peer selects us as BIP152 high-bandwidth peer
2662+
// (receiving sendcmpct(1) signals high-bandwidth, sendcmpct(0) low-bandwidth)
2663+
pfrom.m_bip152_highbandwidth_from = fAnnounceUsingCMPCTBLOCK;
2664+
}
26572665
if (!State(pfrom.GetId())->fSupportsDesiredCmpctVersion) {
26582666
if (pfrom.GetLocalServices() & NODE_WITNESS)
26592667
State(pfrom.GetId())->fSupportsDesiredCmpctVersion = (nCMPCTBLOCKVersion == 2);

0 commit comments

Comments
 (0)