mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-18 22:35:39 +01:00
Merge #19776: net, rpc: expose high bandwidth mode state via getpeerinfo
343dc4760ftest: add test for high-bandwidth mode states in getpeerinfo (Sebastian Falbesoner)dab6583307doc: release note for new getpeerinfo fields "bip152_hb_{from,to}" (Sebastian Falbesoner)a7ed00f8bbrpc: expose high-bandwidth mode states via getpeerinfo (Sebastian Falbesoner)30bc8fab68net: save high-bandwidth mode states in CNodeStats (Sebastian Falbesoner) Pull request description: Fixes #19676, "_For every peer expose through getpeerinfo RPC whether or not we selected them as HB peers, and whether or not they selected us as HB peers._" See [BIP152](https://github.com/bitcoin/bips/blob/master/bip-0152.mediawiki), in particular the [protocol flow diagram](https://github.com/bitcoin/bips/raw/master/bip-0152/protocol-flow.png). The newly introduced states are changed on the following places in the code: * on reception of a `SENDCMPCT` message with valid version, the field `m_highbandwidth_from` is changed depending on the first integer parameter in the message (1=high bandwidth, 0=low bandwidth), i.e. it just mirrors the field `CNodeState.fPreferHeaderAndIDs`. * after adding a `SENDCMPCT` message to the send queue, the field `m_highbandwidth_to` is changed depending on how the first integer parameter is set (same as above) Note that after receiving `VERACK`, the node also sends `SENDCMPCT`, but that is only to announce the preferred version and never selects high-bandwidth mode, hence there is no need to change the state variables there, which are initialized to `false` anyways. ACKs for top commit: naumenkogs: reACK343dc4760fjonatack: re-ACK343dc4760fper `git range-diff7ea64994df1d12 343dc47` Tree-SHA512: f4999e6a935266812c2259a9b5dc459710037d3c9e938006d282557cc225e56128f72965faffb207fc60c6531fab1206db976dd8729a69e8ca29d4835317b99f
This commit is contained in:
@@ -557,11 +557,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;
|
||||
});
|
||||
@@ -2603,8 +2607,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);
|
||||
|
||||
Reference in New Issue
Block a user