* 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. */
| 443 | * removing the first element if necessary. |
| 444 | */ |
| 445 | static 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 | |
| 481 | static bool TipMayBeStale(const Consensus::Params &consensusParams) EXCLUSIVE_LOCKS_REQUIRED(cs_main) |
| 482 | { |
no test coverage detected