| 921 | } |
| 922 | |
| 923 | void PeerManagerImpl::MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid) |
| 924 | { |
| 925 | AssertLockHeld(cs_main); |
| 926 | |
| 927 | // Never request high-bandwidth mode from peers if we're blocks-only. Our |
| 928 | // mempool will not contain the transactions necessary to reconstruct the |
| 929 | // compact block. |
| 930 | if (m_ignore_incoming_txs) return; |
| 931 | |
| 932 | CNodeState* nodestate = State(nodeid); |
| 933 | if (!nodestate || !nodestate->fSupportsDesiredCmpctVersion) { |
| 934 | // Never ask from peers who can't provide witnesses. |
| 935 | return; |
| 936 | } |
| 937 | if (nodestate->fProvidesHeaderAndIDs) { |
| 938 | int num_outbound_hb_peers = 0; |
| 939 | for (std::list<NodeId>::iterator it = lNodesAnnouncingHeaderAndIDs.begin(); it != lNodesAnnouncingHeaderAndIDs.end(); it++) { |
| 940 | if (*it == nodeid) { |
| 941 | lNodesAnnouncingHeaderAndIDs.erase(it); |
| 942 | lNodesAnnouncingHeaderAndIDs.push_back(nodeid); |
| 943 | return; |
| 944 | } |
| 945 | CNodeState *state = State(*it); |
| 946 | if (state != nullptr && !state->m_is_inbound) ++num_outbound_hb_peers; |
| 947 | } |
| 948 | if (nodestate->m_is_inbound) { |
| 949 | // If we're adding an inbound HB peer, make sure we're not removing |
| 950 | // our last outbound HB peer in the process. |
| 951 | if (lNodesAnnouncingHeaderAndIDs.size() >= 3 && num_outbound_hb_peers == 1) { |
| 952 | CNodeState *remove_node = State(lNodesAnnouncingHeaderAndIDs.front()); |
| 953 | if (remove_node != nullptr && !remove_node->m_is_inbound) { |
| 954 | // Put the HB outbound peer in the second slot, so that it |
| 955 | // doesn't get removed. |
| 956 | std::swap(lNodesAnnouncingHeaderAndIDs.front(), *std::next(lNodesAnnouncingHeaderAndIDs.begin())); |
| 957 | } |
| 958 | } |
| 959 | } |
| 960 | m_connman.ForNode(nodeid, [this](CNode* pfrom) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) { |
| 961 | AssertLockHeld(::cs_main); |
| 962 | uint64_t nCMPCTBLOCKVersion = 2; |
| 963 | if (lNodesAnnouncingHeaderAndIDs.size() >= 3) { |
| 964 | // As per BIP152, we only get 3 of our peers to announce |
| 965 | // blocks using compact encodings. |
| 966 | m_connman.ForNode(lNodesAnnouncingHeaderAndIDs.front(), [this, nCMPCTBLOCKVersion](CNode* pnodeStop){ |
| 967 | m_connman.PushMessage(pnodeStop, CNetMsgMaker(pnodeStop->GetCommonVersion()).Make(NetMsgType::SENDCMPCT, /*fAnnounceUsingCMPCTBLOCK=*/false, nCMPCTBLOCKVersion)); |
| 968 | // save BIP152 bandwidth state: we select peer to be low-bandwidth |
| 969 | pnodeStop->m_bip152_highbandwidth_to = false; |
| 970 | return true; |
| 971 | }); |
| 972 | lNodesAnnouncingHeaderAndIDs.pop_front(); |
| 973 | } |
| 974 | m_connman.PushMessage(pfrom, CNetMsgMaker(pfrom->GetCommonVersion()).Make(NetMsgType::SENDCMPCT, /*fAnnounceUsingCMPCTBLOCK=*/true, nCMPCTBLOCKVersion)); |
| 975 | // save BIP152 bandwidth state: we select peer to be high-bandwidth |
| 976 | pfrom->m_bip152_highbandwidth_to = true; |
| 977 | lNodesAnnouncingHeaderAndIDs.push_back(pfrom->GetId()); |
| 978 | return true; |
| 979 | }); |
| 980 | } |
nothing calls this directly
no test coverage detected