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

Method NewPoWValidBlock

src/net_processing.cpp:905–946  ·  view source on GitHub ↗

* Maintain state about the best-seen block and fast-announce a compact block * to compatible peers. */

Source from the content-addressed store, hash-verified

903 * to compatible peers.
904 */
905void 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

Callers 1

AcceptBlockMethod · 0.45

Calls 9

IsWitnessEnabledFunction · 0.85
ForEachNodeMethod · 0.80
GetIdMethod · 0.80
PushMessageMethod · 0.80
MakeMethod · 0.80
ParamsClass · 0.70
StateClass · 0.50
GetHashMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected