MCPcopy Create free account
hub / github.com/ElementsProject/elements / NewPoWValidBlock

Method NewPoWValidBlock

src/net_processing.cpp:1564–1606  ·  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

1562 * to compatible peers.
1563 */
1564void PeerManagerImpl::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock)
1565{
1566 std::shared_ptr<const CBlockHeaderAndShortTxIDs> pcmpctblock = std::make_shared<const CBlockHeaderAndShortTxIDs> (*pblock, true);
1567 const CNetMsgMaker msgMaker(PROTOCOL_VERSION);
1568
1569 LOCK(cs_main);
1570
1571 static int nHighestFastAnnounce = 0;
1572 if (pindex->nHeight <= nHighestFastAnnounce)
1573 return;
1574 nHighestFastAnnounce = pindex->nHeight;
1575
1576 bool fWitnessEnabled = DeploymentActiveAt(*pindex, m_chainparams.GetConsensus(), Consensus::DEPLOYMENT_SEGWIT);
1577 uint256 hashBlock(pblock->GetHash());
1578
1579 {
1580 LOCK(cs_most_recent_block);
1581 most_recent_block_hash = hashBlock;
1582 most_recent_block = pblock;
1583 most_recent_compact_block = pcmpctblock;
1584 fWitnessesPresentInMostRecentCompactBlock = fWitnessEnabled;
1585 }
1586
1587 m_connman.ForEachNode([this, &pcmpctblock, pindex, &msgMaker, fWitnessEnabled, &hashBlock](CNode* pnode) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
1588 AssertLockHeld(::cs_main);
1589
1590 // TODO: Avoid the repeated-serialization here
1591 if (pnode->GetCommonVersion() < INVALID_CB_NO_BAN_VERSION || pnode->fDisconnect)
1592 return;
1593 ProcessBlockAvailability(pnode->GetId());
1594 CNodeState &state = *State(pnode->GetId());
1595 // If the peer has, or we announced to them the previous block already,
1596 // but we don't think they have this one, go ahead and announce it
1597 if (state.fPreferHeaderAndIDs && (!fWitnessEnabled || state.fWantsCmpctWitness) &&
1598 !PeerHasHeader(&state, pindex) && PeerHasHeader(&state, pindex->pprev)) {
1599
1600 LogPrint(BCLog::NET, "%s sending header-and-ids %s to peer=%d\n", "PeerManager::NewPoWValidBlock",
1601 hashBlock.ToString(), pnode->GetId());
1602 m_connman.PushMessage(pnode, msgMaker.Make(NetMsgType::CMPCTBLOCK, *pcmpctblock));
1603 state.pindexBestHeaderSent = pindex;
1604 }
1605 });
1606}
1607
1608/**
1609 * Update our best height and announce any block hashes which weren't previously

Callers 1

AcceptBlockMethod · 0.45

Calls 10

DeploymentActiveAtFunction · 0.85
ForEachNodeMethod · 0.80
GetCommonVersionMethod · 0.80
GetIdMethod · 0.80
PushMessageMethod · 0.80
EXCLUSIVE_LOCKS_REQUIREDFunction · 0.70
StateEnum · 0.70
GetHashMethod · 0.45
ToStringMethod · 0.45
MakeMethod · 0.45

Tested by

no test coverage detected