@@ -752,6 +752,39 @@ void PeerLogicValidation::SyncTransaction(const CTransaction& tx, const CBlockIn
752752 }
753753}
754754
755+ void PeerLogicValidation::NewPoWValidBlock (const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock) {
756+ CBlockHeaderAndShortTxIDs cmpctblock (*pblock, true );
757+ CNetMsgMaker msgMaker (PROTOCOL_VERSION);
758+
759+ LOCK (cs_main);
760+
761+ static int nHighestFastAnnounce = 0 ;
762+ if (pindex->nHeight <= nHighestFastAnnounce)
763+ return ;
764+ nHighestFastAnnounce = pindex->nHeight ;
765+
766+ bool fWitnessEnabled = IsWitnessEnabled (pindex->pprev , Params ().GetConsensus ());
767+ uint256 hashBlock (pblock->GetHash ());
768+
769+ connman->ForEachNode ([this , &cmpctblock, pindex, &msgMaker, fWitnessEnabled , &hashBlock](CNode* pnode) {
770+ // TODO: Avoid the repeated-serialization here
771+ if (pnode->nVersion < INVALID_CB_NO_BAN_VERSION || pnode->fDisconnect )
772+ return ;
773+ ProcessBlockAvailability (pnode->GetId ());
774+ CNodeState &state = *State (pnode->GetId ());
775+ // If the peer has, or we announced to them the previous block already,
776+ // but we don't think they have this one, go ahead and announce it
777+ if (state.fPreferHeaderAndIDs && (!fWitnessEnabled || state.fWantsCmpctWitness ) &&
778+ !PeerHasHeader (&state, pindex) && PeerHasHeader (&state, pindex->pprev )) {
779+
780+ LogPrint (" net" , " %s sending header-and-ids %s to peer %d\n " , " PeerLogicValidation::NewPoWValidBlock" ,
781+ hashBlock.ToString (), pnode->id );
782+ connman->PushMessage (pnode, msgMaker.Make (NetMsgType::CMPCTBLOCK, cmpctblock));
783+ state.pindexBestHeaderSent = pindex;
784+ }
785+ });
786+ }
787+
755788void PeerLogicValidation::UpdatedBlockTip (const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload ) {
756789 const int nNewHeight = pindexNew->nHeight ;
757790 connman->SetBestHeight (nNewHeight);
0 commit comments