MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / MaybeSetPeerAsAnnouncingHeaderAndIDs

Function MaybeSetPeerAsAnnouncingHeaderAndIDs

src/net_processing.cpp:445–479  ·  view source on GitHub ↗

* When a peer sends us a valid block, instruct it to announce blocks to us * using CMPCTBLOCK if possible by adding its nodeid to the end of * lNodesAnnouncingHeaderAndIDs, and keeping that list under a certain size by * removing the first element if necessary. */

Source from the content-addressed store, hash-verified

443 * removing the first element if necessary.
444 */
445static void MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid, CConnman* connman)
446{
447 AssertLockHeld(cs_main);
448 CNodeState* nodestate = State(nodeid);
449 if (!nodestate || !nodestate->fSupportsDesiredCmpctVersion) {
450 // Never ask from peers who can't provide witnesses.
451 return;
452 }
453 if (nodestate->fProvidesHeaderAndIDs) {
454 for (std::list<NodeId>::iterator it = lNodesAnnouncingHeaderAndIDs.begin(); it != lNodesAnnouncingHeaderAndIDs.end(); it++) {
455 if (*it == nodeid) {
456 lNodesAnnouncingHeaderAndIDs.erase(it);
457 lNodesAnnouncingHeaderAndIDs.push_back(nodeid);
458 return;
459 }
460 }
461 connman->ForNode(nodeid, [connman](CNode* pfrom){
462 AssertLockHeld(cs_main);
463 uint64_t nCMPCTBLOCKVersion = (pfrom->GetLocalServices() & NODE_WITNESS) ? 2 : 1;
464 if (lNodesAnnouncingHeaderAndIDs.size() >= 3) {
465 // As per BIP152, we only get 3 of our peers to announce
466 // blocks using compact encodings.
467 connman->ForNode(lNodesAnnouncingHeaderAndIDs.front(), [connman, nCMPCTBLOCKVersion](CNode* pnodeStop){
468 AssertLockHeld(cs_main);
469 connman->PushMessage(pnodeStop, CNetMsgMaker(pnodeStop->GetSendVersion()).Make(NetMsgType::SENDCMPCT, /*fAnnounceUsingCMPCTBLOCK=*/false, nCMPCTBLOCKVersion));
470 return true;
471 });
472 lNodesAnnouncingHeaderAndIDs.pop_front();
473 }
474 connman->PushMessage(pfrom, CNetMsgMaker(pfrom->GetSendVersion()).Make(NetMsgType::SENDCMPCT, /*fAnnounceUsingCMPCTBLOCK=*/true, nCMPCTBLOCKVersion));
475 lNodesAnnouncingHeaderAndIDs.push_back(pfrom->GetId());
476 return true;
477 });
478 }
479}
480
481static bool TipMayBeStale(const Consensus::Params &consensusParams) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
482{

Callers 1

BlockCheckedMethod · 0.85

Calls 13

CNetMsgMakerClass · 0.85
ForNodeMethod · 0.80
PushMessageMethod · 0.80
MakeMethod · 0.80
GetSendVersionMethod · 0.80
GetIdMethod · 0.80
StateClass · 0.50
beginMethod · 0.45
endMethod · 0.45
eraseMethod · 0.45
push_backMethod · 0.45
GetLocalServicesMethod · 0.45

Tested by

no test coverage detected