* Maintain state about the best-seen block and fast-announce a compact block * to compatible peers. */
| 903 | * to compatible peers. |
| 904 | */ |
| 905 | void PeerLogicValidation::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock) { |
| 906 | std::shared_ptr<const CBlockHeaderAndShortTxIDs> pcmpctblock = std::make_shared<const CBlockHeaderAndShortTxIDs> (*pblock, true); |
| 907 | const CNetMsgMaker msgMaker(PROTOCOL_VERSION); |
| 908 | |
| 909 | LOCK(cs_main); |
| 910 | |
| 911 | static int nHighestFastAnnounce = 0; |
| 912 | if (pindex->nHeight <= nHighestFastAnnounce) |
| 913 | return; |
| 914 | nHighestFastAnnounce = pindex->nHeight; |
| 915 | |
| 916 | bool fWitnessEnabled = IsWitnessEnabled(pindex->pprev, Params().GetConsensus()); |
| 917 | uint256 hashBlock(pblock->GetHash()); |
| 918 | |
| 919 | { |
| 920 | LOCK(cs_most_recent_block); |
| 921 | most_recent_block_hash = hashBlock; |
| 922 | most_recent_block = pblock; |
| 923 | most_recent_compact_block = pcmpctblock; |
| 924 | fWitnessesPresentInMostRecentCompactBlock = fWitnessEnabled; |
| 925 | } |
| 926 | |
| 927 | connman->ForEachNode([this, &pcmpctblock, pindex, &msgMaker, fWitnessEnabled, &hashBlock](CNode* pnode) { |
| 928 | AssertLockHeld(cs_main); |
| 929 | |
| 930 | // TODO: Avoid the repeated-serialization here |
| 931 | if (pnode->nVersion < INVALID_CB_NO_BAN_VERSION || pnode->fDisconnect) |
| 932 | return; |
| 933 | ProcessBlockAvailability(pnode->GetId()); |
| 934 | CNodeState &state = *State(pnode->GetId()); |
| 935 | // If the peer has, or we announced to them the previous block already, |
| 936 | // but we don't think they have this one, go ahead and announce it |
| 937 | if (state.fPreferHeaderAndIDs && (!fWitnessEnabled || state.fWantsCmpctWitness) && |
| 938 | !PeerHasHeader(&state, pindex) && PeerHasHeader(&state, pindex->pprev)) { |
| 939 | |
| 940 | LogPrint(BCLog::NET, "%s sending header-and-ids %s to peer=%d\n", "PeerLogicValidation::NewPoWValidBlock", |
| 941 | hashBlock.ToString(), pnode->GetId()); |
| 942 | connman->PushMessage(pnode, msgMaker.Make(NetMsgType::CMPCTBLOCK, *pcmpctblock)); |
| 943 | state.pindexBestHeaderSent = pindex; |
| 944 | } |
| 945 | }); |
| 946 | } |
| 947 | |
| 948 | /** |
| 949 | * Update our best height and announce any block hashes which weren't previously |
no test coverage detected