Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
501}503void TxDownloadManagerImpl::MempoolRejectedPackage(const Package& package)504{505RecentRejectsReconsiderableFilter().insert(GetPackageHash(package));506}508std::pair<bool, std::optional<PackageToValidate>> TxDownloadManagerImpl::ReceivedTx(NodeId nodeid, const CTransactionRef& ptx)509{510const Txid& txid = ptx->GetHash();511const Wtxid& wtxid = ptx->GetWitnessHash();513// Mark that we have received a response514m_txrequest.ReceivedResponse(nodeid, txid.ToUint256());515if (ptx->HasWitness()) m_txrequest.ReceivedResponse(nodeid, wtxid.ToUint256());517// First check if we should drop this tx.518// We do the AlreadyHaveTx() check using wtxid, rather than txid - in the519// absence of witness malleation, this is strictly better, because the520// recent rejects filter may contain the wtxid but rarely contains521// the txid of a segwit transaction that has been rejected.522// In the presence of witness malleation, it's possible that by only523// doing the check with wtxid, we could overlook a transaction which524// was confirmed with a different witness, or exists in our mempool525// with a different witness, but this has limited downside:526// mempool validation does its own lookup of whether we have the txid527// already; and an adversary can already relay us old transactions528// (older than our recency filter) if trying to DoS us, without any need529// for witness malleation.530if (AlreadyHaveTx(wtxid, /*include_reconsiderable=*/false)) {531// If a tx is detected by m_lazy_recent_rejects it is ignored. Because we haven't532// submitted the tx to our mempool, we won't have computed a DoS533// score for it or determined exactly why we consider it invalid.534//535// This means we won't penalize any peer subsequently relaying a DoSy536// tx (even if we penalized the first peer who gave it to us) because537// we have to account for m_lazy_recent_rejects showing false positives. In538// other words, we shouldn't penalize a peer if we aren't *sure* they539// submitted a DoSy tx.540//541// Note that m_lazy_recent_rejects doesn't just record DoSy or invalid542// transactions, but any tx not accepted by the mempool, which may be543// due to node policy (vs. consensus). So we can't blanket penalize a544// peer simply for relaying a tx that our m_lazy_recent_rejects has caught,545// regardless of false positives.546return {false, std::nullopt};547} else if (RecentRejectsReconsiderableFilter().contains(wtxid.ToUint256())) {548// When a transaction is already in m_lazy_recent_rejects_reconsiderable, we shouldn't submit549// it by itself again. However, look for a matching child in the orphanage, as it is550// possible that they succeed as a package.551LogDebug(BCLog::TXPACKAGES, "found tx %s (wtxid=%s) in reconsiderable rejects, looking for child in orphanage\n",552txid.ToString(), wtxid.ToString());553return {false, Find1P1CPackage(ptx, nodeid)};554}557return {true, std::nullopt};558}560bool TxDownloadManagerImpl::HaveMoreWork(NodeId nodeid)561{562return m_orphanage->HaveTxToReconsider(nodeid);563}565CTransactionRef TxDownloadManagerImpl::GetTxToReconsider(NodeId nodeid)566{567return m_orphanage->GetTxToReconsider(nodeid);568}570void TxDownloadManagerImpl::CheckIsEmpty(NodeId nodeid)571{572assert(m_txrequest.Count(nodeid) == 0);573assert(m_orphanage->UsageByPeer(nodeid) == 0);574}575void TxDownloadManagerImpl::CheckIsEmpty()576{577assert(m_orphanage->TotalOrphanUsage() == 0);578assert(m_orphanage->CountUniqueOrphans() == 0);579assert(m_txrequest.Size() == 0);580assert(m_num_wtxid_peers == 0);581}582std::vector<TxOrphanage::OrphanInfo> TxDownloadManagerImpl::GetOrphanTransactions() const583{584return m_orphanage->GetOrphanTransactions();585}586} // namespace node
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.