MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / BlockConnected

Method BlockConnected

src/net_processing.cpp:2094–2120  ·  view source on GitHub ↗

* Evict orphan txn pool entries based on a newly connected * block, remember the recently confirmed transactions, and delete tracked * announcements for them. Also save the time of the last tip update and * possibly reduce dynamic block stalling timeout. */

Source from the content-addressed store, hash-verified

2092 * possibly reduce dynamic block stalling timeout.
2093 */
2094void PeerManagerImpl::BlockConnected(
2095 const ChainstateRole& role,
2096 const std::shared_ptr<const CBlock>& pblock,
2097 const CBlockIndex* pindex)
2098{
2099 // Update this for all chainstate roles so that we don't mistakenly see peers
2100 // helping us do background IBD as having a stale tip.
2101 m_last_tip_update = GetTime<std::chrono::seconds>();
2102
2103 // In case the dynamic timeout was doubled once or more, reduce it slowly back to its default value
2104 auto stalling_timeout = m_block_stalling_timeout.load();
2105 Assume(stalling_timeout >= BLOCK_STALLING_TIMEOUT_DEFAULT);
2106 if (stalling_timeout != BLOCK_STALLING_TIMEOUT_DEFAULT) {
2107 const auto new_timeout = std::max(std::chrono::duration_cast<std::chrono::seconds>(stalling_timeout * 0.85), BLOCK_STALLING_TIMEOUT_DEFAULT);
2108 if (m_block_stalling_timeout.compare_exchange_strong(stalling_timeout, new_timeout)) {
2109 LogDebug(BCLog::NET, "Decreased stalling timeout to %d seconds\n", count_seconds(new_timeout));
2110 }
2111 }
2112
2113 // The following task can be skipped since we don't maintain a mempool for
2114 // the historical chainstate, or during ibd since we don't receive incoming
2115 // transactions from peers into the mempool.
2116 if (!role.historical && !m_chainman.IsInitialBlockDownload()) {
2117 LOCK(m_tx_download_mutex);
2118 m_txdownloadman.BlockConnected(pblock);
2119 }
2120}
2121
2122void PeerManagerImpl::BlockDisconnected(const std::shared_ptr<const CBlock> &block, const CBlockIndex* pindex)
2123{

Callers

nothing calls this directly

Calls 3

count_secondsFunction · 0.85
loadMethod · 0.45

Tested by

no test coverage detected