From 30bc8fab6833e0447ceadd3fff1566a680e33a98 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Fri, 21 Aug 2020 15:17:42 +0200 Subject: net: save high-bandwidth mode states in CNodeStats --- src/net.cpp | 2 ++ src/net.h | 6 ++++++ src/net_processing.cpp | 10 +++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/net.cpp b/src/net.cpp index 5b533d7d17..2c41b314ff 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -563,6 +563,8 @@ void CNode::copyStats(CNodeStats &stats, const std::vector &m_asmap) } stats.fInbound = IsInboundConn(); stats.m_manual_connection = IsManualConn(); + X(m_bip152_highbandwidth_to); + X(m_bip152_highbandwidth_from); X(nStartingHeight); { LOCK(cs_vSend); diff --git a/src/net.h b/src/net.h index 5a8e57b68b..4605000092 100644 --- a/src/net.h +++ b/src/net.h @@ -681,6 +681,8 @@ public: std::string cleanSubVer; bool fInbound; bool m_manual_connection; + bool m_bip152_highbandwidth_to; + bool m_bip152_highbandwidth_from; int nStartingHeight; uint64_t nSendBytes; mapMsgCmdSize mapSendBytesPerMsgCmd; @@ -942,6 +944,10 @@ protected: public: uint256 hashContinue; std::atomic nStartingHeight{-1}; + // We selected peer as (compact blocks) high-bandwidth peer (BIP152) + std::atomic m_bip152_highbandwidth_to{false}; + // Peer selected us as (compact blocks) high-bandwidth peer (BIP152) + std::atomic m_bip152_highbandwidth_from{false}; // flood relay std::vector vAddrToSend; diff --git a/src/net_processing.cpp b/src/net_processing.cpp index d2a76550ea..fb9978664c 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -670,11 +670,15 @@ static void MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid, CConnman& connma // blocks using compact encodings. connman.ForNode(lNodesAnnouncingHeaderAndIDs.front(), [&connman, nCMPCTBLOCKVersion](CNode* pnodeStop){ connman.PushMessage(pnodeStop, CNetMsgMaker(pnodeStop->GetCommonVersion()).Make(NetMsgType::SENDCMPCT, /*fAnnounceUsingCMPCTBLOCK=*/false, nCMPCTBLOCKVersion)); + // save BIP152 bandwidth state: we select peer to be low-bandwidth + pnodeStop->m_bip152_highbandwidth_to = false; return true; }); lNodesAnnouncingHeaderAndIDs.pop_front(); } connman.PushMessage(pfrom, CNetMsgMaker(pfrom->GetCommonVersion()).Make(NetMsgType::SENDCMPCT, /*fAnnounceUsingCMPCTBLOCK=*/true, nCMPCTBLOCKVersion)); + // save BIP152 bandwidth state: we select peer to be high-bandwidth + pfrom->m_bip152_highbandwidth_to = true; lNodesAnnouncingHeaderAndIDs.push_back(pfrom->GetId()); return true; }); @@ -2652,8 +2656,12 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat State(pfrom.GetId())->fProvidesHeaderAndIDs = true; State(pfrom.GetId())->fWantsCmpctWitness = nCMPCTBLOCKVersion == 2; } - if (State(pfrom.GetId())->fWantsCmpctWitness == (nCMPCTBLOCKVersion == 2)) // ignore later version announces + if (State(pfrom.GetId())->fWantsCmpctWitness == (nCMPCTBLOCKVersion == 2)) { // ignore later version announces State(pfrom.GetId())->fPreferHeaderAndIDs = fAnnounceUsingCMPCTBLOCK; + // save whether peer selects us as BIP152 high-bandwidth peer + // (receiving sendcmpct(1) signals high-bandwidth, sendcmpct(0) low-bandwidth) + pfrom.m_bip152_highbandwidth_from = fAnnounceUsingCMPCTBLOCK; + } if (!State(pfrom.GetId())->fSupportsDesiredCmpctVersion) { if (pfrom.GetLocalServices() & NODE_WITNESS) State(pfrom.GetId())->fSupportsDesiredCmpctVersion = (nCMPCTBLOCKVersion == 2); -- cgit v1.2.3 From a7ed00f8bbc07dfc09f9e0a5bae10a1afe7612bb Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Fri, 21 Aug 2020 15:20:21 +0200 Subject: rpc: expose high-bandwidth mode states via getpeerinfo --- src/rpc/net.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index def21b119e..8e0cb17628 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -116,6 +116,8 @@ static RPCHelpMan getpeerinfo() {RPCResult::Type::NUM, "version", "The peer version, such as 70001"}, {RPCResult::Type::STR, "subver", "The string version"}, {RPCResult::Type::BOOL, "inbound", "Inbound (true) or Outbound (false)"}, + {RPCResult::Type::BOOL, "bip152_hb_to", "Whether we selected peer as (compact blocks) high-bandwidth peer"}, + {RPCResult::Type::BOOL, "bip152_hb_from", "Whether peer selected us as (compact blocks) high-bandwidth peer"}, {RPCResult::Type::BOOL, "addnode", "Whether connection was due to addnode/-connect or if it was an automatic/inbound connection\n" "(DEPRECATED, returned only if the config option -deprecatedrpc=getpeerinfo_addnode is passed)"}, {RPCResult::Type::STR, "connection_type", "Type of connection: \n" + Join(CONNECTION_TYPE_DOC, ",\n") + "."}, @@ -198,6 +200,8 @@ static RPCHelpMan getpeerinfo() // their ver message. obj.pushKV("subver", stats.cleanSubVer); obj.pushKV("inbound", stats.fInbound); + obj.pushKV("bip152_hb_to", stats.m_bip152_highbandwidth_to); + obj.pushKV("bip152_hb_from", stats.m_bip152_highbandwidth_from); if (IsDeprecatedRPCEnabled("getpeerinfo_addnode")) { // addnode is deprecated in v0.21 for removal in v0.22 obj.pushKV("addnode", stats.m_manual_connection); -- cgit v1.2.3