Bitcoin Core 28.99.0
P2P Digital Currency
Classes | Public Member Functions | Public Attributes | List of all members
node::TxDownloadManagerImpl Class Reference

#include <txdownloadman_impl.h>

Collaboration diagram for node::TxDownloadManagerImpl:
[legend]

Classes

struct  PeerInfo
 

Public Member Functions

CRollingBloomFilterRecentRejectsFilter ()
 
CRollingBloomFilterRecentRejectsReconsiderableFilter ()
 
CRollingBloomFilterRecentConfirmedTransactionsFilter ()
 
 TxDownloadManagerImpl (const TxDownloadOptions &options)
 
void ActiveTipChange ()
 
void BlockConnected (const std::shared_ptr< const CBlock > &pblock)
 
void BlockDisconnected ()
 
bool AlreadyHaveTx (const GenTxid &gtxid, bool include_reconsiderable)
 Check whether we already have this gtxid in: More...
 
void ConnectedPeer (NodeId nodeid, const TxDownloadConnectionInfo &info)
 
void DisconnectedPeer (NodeId nodeid)
 
bool AddTxAnnouncement (NodeId peer, const GenTxid &gtxid, std::chrono::microseconds now, bool p2p_inv)
 Consider adding this tx hash to txrequest. More...
 
std::vector< GenTxidGetRequestsToSend (NodeId nodeid, std::chrono::microseconds current_time)
 Get getdata requests to send. More...
 
void ReceivedNotFound (NodeId nodeid, const std::vector< uint256 > &txhashes)
 Marks a tx as ReceivedResponse in txrequest. More...
 
std::optional< PackageToValidateFind1P1CPackage (const CTransactionRef &ptx, NodeId nodeid)
 Look for a child of this transaction in the orphanage to form a 1-parent-1-child package, skipping any combinations that have already been tried. More...
 
void MempoolAcceptedTx (const CTransactionRef &tx)
 
RejectedTxTodo MempoolRejectedTx (const CTransactionRef &ptx, const TxValidationState &state, NodeId nodeid, bool first_time_failure)
 
void MempoolRejectedPackage (const Package &package)
 
std::pair< bool, std::optional< PackageToValidate > > ReceivedTx (NodeId nodeid, const CTransactionRef &ptx)
 
bool HaveMoreWork (NodeId nodeid)
 
CTransactionRef GetTxToReconsider (NodeId nodeid)
 
void CheckIsEmpty ()
 
void CheckIsEmpty (NodeId nodeid)
 
std::vector< TxOrphanage::OrphanTxBaseGetOrphanTransactions () const
 

Public Attributes

TxDownloadOptions m_opts
 
TxOrphanage m_orphanage
 Manages unvalidated tx data (orphan transactions for which we are downloading ancestors). More...
 
TxRequestTracker m_txrequest
 Tracks candidates for requesting and downloading transaction data. More...
 
std::unique_ptr< CRollingBloomFilterm_lazy_recent_rejects {nullptr}
 Filter for transactions that were recently rejected by the mempool. More...
 
std::unique_ptr< CRollingBloomFilterm_lazy_recent_rejects_reconsiderable {nullptr}
 Filter for: (1) wtxids of transactions that were recently rejected by the mempool but are eligible for reconsideration if submitted with other transactions. More...
 
std::unique_ptr< CRollingBloomFilterm_lazy_recent_confirmed_transactions {nullptr}
 
std::map< NodeId, PeerInfom_peer_info
 Information for all of the peers we may download transactions from. More...
 
uint32_t m_num_wtxid_peers {0}
 Number of wtxid relay peers we have in m_peer_info. More...
 

Detailed Description

Definition at line 20 of file txdownloadman_impl.h.

Constructor & Destructor Documentation

◆ TxDownloadManagerImpl()

node::TxDownloadManagerImpl::TxDownloadManagerImpl ( const TxDownloadOptions options)
inline

Definition at line 131 of file txdownloadman_impl.h.

Member Function Documentation

◆ ActiveTipChange()

void node::TxDownloadManagerImpl::ActiveTipChange ( )

Definition at line 92 of file txdownloadman_impl.cpp.

Here is the call graph for this function:

◆ AddTxAnnouncement()

bool node::TxDownloadManagerImpl::AddTxAnnouncement ( NodeId  peer,
const GenTxid gtxid,
std::chrono::microseconds  now,
bool  p2p_inv 
)

Consider adding this tx hash to txrequest.

Should be called whenever a new inv has been received. Also called internally when a transaction is missing parents so that we can request them.

Definition at line 175 of file txdownloadman_impl.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AlreadyHaveTx()

bool node::TxDownloadManagerImpl::AlreadyHaveTx ( const GenTxid gtxid,
bool  include_reconsiderable 
)

Check whether we already have this gtxid in:

  • mempool
  • orphanage
  • m_recent_rejects
  • m_recent_rejects_reconsiderable (if include_reconsiderable = true)
  • m_recent_confirmed_transactions

Definition at line 125 of file txdownloadman_impl.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ BlockConnected()

void node::TxDownloadManagerImpl::BlockConnected ( const std::shared_ptr< const CBlock > &  pblock)

Definition at line 98 of file txdownloadman_impl.cpp.

Here is the call graph for this function:

◆ BlockDisconnected()

void node::TxDownloadManagerImpl::BlockDisconnected ( )

Definition at line 112 of file txdownloadman_impl.cpp.

Here is the call graph for this function:

◆ CheckIsEmpty() [1/2]

void node::TxDownloadManagerImpl::CheckIsEmpty ( )

Definition at line 526 of file txdownloadman_impl.cpp.

Here is the call graph for this function:

◆ CheckIsEmpty() [2/2]

void node::TxDownloadManagerImpl::CheckIsEmpty ( NodeId  nodeid)

Definition at line 522 of file txdownloadman_impl.cpp.

Here is the call graph for this function:

◆ ConnectedPeer()

void node::TxDownloadManagerImpl::ConnectedPeer ( NodeId  nodeid,
const TxDownloadConnectionInfo info 
)

Definition at line 154 of file txdownloadman_impl.cpp.

Here is the caller graph for this function:

◆ DisconnectedPeer()

void node::TxDownloadManagerImpl::DisconnectedPeer ( NodeId  nodeid)

Definition at line 163 of file txdownloadman_impl.cpp.

Here is the call graph for this function:

◆ Find1P1CPackage()

std::optional< PackageToValidate > node::TxDownloadManagerImpl::Find1P1CPackage ( const CTransactionRef ptx,
NodeId  nodeid 
)

Look for a child of this transaction in the orphanage to form a 1-parent-1-child package, skipping any combinations that have already been tried.

Return the resulting package along with the senders of its respective transactions, or std::nullopt if no package is found.

Definition at line 240 of file txdownloadman_impl.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetOrphanTransactions()

std::vector< TxOrphanage::OrphanTxBase > node::TxDownloadManagerImpl::GetOrphanTransactions ( ) const

Definition at line 532 of file txdownloadman_impl.cpp.

Here is the call graph for this function:

◆ GetRequestsToSend()

std::vector< GenTxid > node::TxDownloadManagerImpl::GetRequestsToSend ( NodeId  nodeid,
std::chrono::microseconds  current_time 
)

Get getdata requests to send.

Definition at line 207 of file txdownloadman_impl.cpp.

Here is the call graph for this function:

◆ GetTxToReconsider()

CTransactionRef node::TxDownloadManagerImpl::GetTxToReconsider ( NodeId  nodeid)

Definition at line 517 of file txdownloadman_impl.cpp.

Here is the call graph for this function:

◆ HaveMoreWork()

bool node::TxDownloadManagerImpl::HaveMoreWork ( NodeId  nodeid)

Definition at line 512 of file txdownloadman_impl.cpp.

Here is the call graph for this function:

◆ MempoolAcceptedTx()

void node::TxDownloadManagerImpl::MempoolAcceptedTx ( const CTransactionRef tx)

Definition at line 292 of file txdownloadman_impl.cpp.

Here is the call graph for this function:

◆ MempoolRejectedPackage()

void node::TxDownloadManagerImpl::MempoolRejectedPackage ( const Package package)

Definition at line 455 of file txdownloadman_impl.cpp.

Here is the call graph for this function:

◆ MempoolRejectedTx()

node::RejectedTxTodo node::TxDownloadManagerImpl::MempoolRejectedTx ( const CTransactionRef ptx,
const TxValidationState state,
NodeId  nodeid,
bool  first_time_failure 
)

Definition at line 304 of file txdownloadman_impl.cpp.

Here is the call graph for this function:

◆ ReceivedNotFound()

void node::TxDownloadManagerImpl::ReceivedNotFound ( NodeId  nodeid,
const std::vector< uint256 > &  txhashes 
)

Marks a tx as ReceivedResponse in txrequest.

Definition at line 231 of file txdownloadman_impl.cpp.

Here is the call graph for this function:

◆ ReceivedTx()

std::pair< bool, std::optional< PackageToValidate > > node::TxDownloadManagerImpl::ReceivedTx ( NodeId  nodeid,
const CTransactionRef ptx 
)

Definition at line 460 of file txdownloadman_impl.cpp.

Here is the call graph for this function:

◆ RecentConfirmedTransactionsFilter()

CRollingBloomFilter & node::TxDownloadManagerImpl::RecentConfirmedTransactionsFilter ( )
inline

Definition at line 122 of file txdownloadman_impl.h.

Here is the caller graph for this function:

◆ RecentRejectsFilter()

CRollingBloomFilter & node::TxDownloadManagerImpl::RecentRejectsFilter ( )
inline

Definition at line 65 of file txdownloadman_impl.h.

Here is the caller graph for this function:

◆ RecentRejectsReconsiderableFilter()

CRollingBloomFilter & node::TxDownloadManagerImpl::RecentRejectsReconsiderableFilter ( )
inline

Definition at line 96 of file txdownloadman_impl.h.

Here is the caller graph for this function:

Member Data Documentation

◆ m_lazy_recent_confirmed_transactions

std::unique_ptr<CRollingBloomFilter> node::TxDownloadManagerImpl::m_lazy_recent_confirmed_transactions {nullptr}

Definition at line 120 of file txdownloadman_impl.h.

◆ m_lazy_recent_rejects

std::unique_ptr<CRollingBloomFilter> node::TxDownloadManagerImpl::m_lazy_recent_rejects {nullptr}

Filter for transactions that were recently rejected by the mempool.

These are not rerequested until the chain tip changes, at which point the entire filter is reset.

Without this filter we'd be re-requesting txs from each of our peers, increasing bandwidth consumption considerably. For instance, with 100 peers, half of which relay a tx we don't accept, that might be a 50x bandwidth increase. A flooding attacker attempting to roll-over the filter using minimum-sized, 60byte, transactions might manage to send 1000/sec if we have fast peers, so we pick 120,000 to give our peers a two minute window to send invs to us.

Decreasing the false positive rate is fairly cheap, so we pick one in a million to make it highly unlikely for users to have issues with this filter.

We typically only add wtxids to this filter. For non-segwit transactions, the txid == wtxid, so this only prevents us from re-downloading non-segwit transactions when communicating with non-wtxidrelay peers – which is important for avoiding malleation attacks that could otherwise interfere with transaction relay from non-wtxidrelay peers. For communicating with wtxidrelay peers, having the reject filter store wtxids is exactly what we want to avoid redownload of a rejected transaction.

In cases where we can tell that a segwit transaction will fail validation no matter the witness, we may add the txid of such transaction to the filter as well. This can be helpful when communicating with txid-relay peers or if we were to otherwise fetch a transaction via txid (eg in our orphan handling).

Memory used: 1.3 MB

Definition at line 63 of file txdownloadman_impl.h.

◆ m_lazy_recent_rejects_reconsiderable

std::unique_ptr<CRollingBloomFilter> node::TxDownloadManagerImpl::m_lazy_recent_rejects_reconsiderable {nullptr}

Filter for: (1) wtxids of transactions that were recently rejected by the mempool but are eligible for reconsideration if submitted with other transactions.

(2) packages (see GetPackageHash) we have already rejected before and should not retry.

Similar to m_lazy_recent_rejects, this filter is used to save bandwidth when e.g. all of our peers have larger mempools and thus lower minimum feerates than us.

When a transaction's error is TxValidationResult::TX_RECONSIDERABLE (in a package or by itself), add its wtxid to this filter. When a package fails for any reason, add the combined hash to this filter.

Upon receiving an announcement for a transaction, if it exists in this filter, do not download the txdata. When considering packages, if it exists in this filter, drop it.

Reset this filter when the chain tip changes.

Parameters are picked to be the same as m_lazy_recent_rejects, with the same rationale.

Definition at line 94 of file txdownloadman_impl.h.

◆ m_num_wtxid_peers

uint32_t node::TxDownloadManagerImpl::m_num_wtxid_peers {0}

Number of wtxid relay peers we have in m_peer_info.

Definition at line 145 of file txdownloadman_impl.h.

◆ m_opts

TxDownloadOptions node::TxDownloadManagerImpl::m_opts

Definition at line 22 of file txdownloadman_impl.h.

◆ m_orphanage

TxOrphanage node::TxDownloadManagerImpl::m_orphanage

Manages unvalidated tx data (orphan transactions for which we are downloading ancestors).

Definition at line 25 of file txdownloadman_impl.h.

◆ m_peer_info

std::map<NodeId, PeerInfo> node::TxDownloadManagerImpl::m_peer_info

Information for all of the peers we may download transactions from.

This is not necessarily all peers we are connected to (no block-relay-only and temporary connections).

Definition at line 142 of file txdownloadman_impl.h.

◆ m_txrequest

TxRequestTracker node::TxDownloadManagerImpl::m_txrequest

Tracks candidates for requesting and downloading transaction data.

Definition at line 27 of file txdownloadman_impl.h.


The documentation for this class was generated from the following files: