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

Class responsible for deciding what transactions to request and, once downloaded, whether and how to validate them. More...

#include <txdownloadman.h>

Public Member Functions

 TxDownloadManager (const TxDownloadOptions &options)
 
 ~TxDownloadManager ()
 
void ActiveTipChange ()
 
void BlockConnected (const std::shared_ptr< const CBlock > &pblock)
 
void BlockDisconnected ()
 
void ConnectedPeer (NodeId nodeid, const TxDownloadConnectionInfo &info)
 Creates a new PeerInfo. More...
 
void DisconnectedPeer (NodeId nodeid)
 Deletes all txrequest announcements and orphans for a given peer. More...
 
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)
 Should be called when a notfound for a tx has been received. More...
 
void MempoolAcceptedTx (const CTransactionRef &tx)
 Respond to successful transaction submission to mempool. More...
 
RejectedTxTodo MempoolRejectedTx (const CTransactionRef &ptx, const TxValidationState &state, NodeId nodeid, bool first_time_failure)
 Respond to transaction rejected from mempool. More...
 
void MempoolRejectedPackage (const Package &package)
 Respond to package rejected from mempool. More...
 
std::pair< bool, std::optional< PackageToValidate > > ReceivedTx (NodeId nodeid, const CTransactionRef &ptx)
 Marks a tx as ReceivedResponse in txrequest and checks whether AlreadyHaveTx. More...
 
bool HaveMoreWork (NodeId nodeid) const
 Whether there are any orphans to reconsider for this peer. More...
 
CTransactionRef GetTxToReconsider (NodeId nodeid)
 Returns next orphan tx to consider, or nullptr if none exist. More...
 
void CheckIsEmpty () const
 Check that all data structures are empty. More...
 
void CheckIsEmpty (NodeId nodeid) const
 Check that all data structures that track per-peer information have nothing for this peer. More...
 
std::vector< TxOrphanage::OrphanTxBaseGetOrphanTransactions () const
 Wrapper for TxOrphanage::GetOrphanTransactions. More...
 

Private Attributes

const std::unique_ptr< TxDownloadManagerImplm_impl
 

Detailed Description

Class responsible for deciding what transactions to request and, once downloaded, whether and how to validate them.

It is also responsible for deciding what transaction packages to validate and how to resolve orphan transactions. Its data structures include TxRequestTracker for scheduling requests, rolling bloom filters for remembering transactions that have already been {accepted, rejected, confirmed}, an orphanage, and a registry of each peer's transaction relay-related information.

Caller needs to interact with TxDownloadManager:

This class is not thread-safe. Access must be synchronized using an external mutex.

Definition at line 119 of file txdownloadman.h.

Constructor & Destructor Documentation

◆ TxDownloadManager()

node::TxDownloadManager::TxDownloadManager ( const TxDownloadOptions options)
explicit

Definition at line 17 of file txdownloadman_impl.cpp.

◆ ~TxDownloadManager()

node::TxDownloadManager::~TxDownloadManager ( )
default

Member Function Documentation

◆ ActiveTipChange()

void node::TxDownloadManager::ActiveTipChange ( )

Definition at line 22 of file txdownloadman_impl.cpp.

◆ AddTxAnnouncement()

bool node::TxDownloadManager::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.

Parameters
[in]p2p_invWhen true, only add this announcement if we don't already have the tx. Returns true if this was a dropped inv (p2p_inv=true and we already have the tx), false otherwise.

Definition at line 42 of file txdownloadman_impl.cpp.

◆ BlockConnected()

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

Definition at line 26 of file txdownloadman_impl.cpp.

◆ BlockDisconnected()

void node::TxDownloadManager::BlockDisconnected ( )

Definition at line 30 of file txdownloadman_impl.cpp.

◆ CheckIsEmpty() [1/2]

void node::TxDownloadManager::CheckIsEmpty ( ) const

Check that all data structures are empty.

Definition at line 78 of file txdownloadman_impl.cpp.

◆ CheckIsEmpty() [2/2]

void node::TxDownloadManager::CheckIsEmpty ( NodeId  nodeid) const

Check that all data structures that track per-peer information have nothing for this peer.

Definition at line 82 of file txdownloadman_impl.cpp.

◆ ConnectedPeer()

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

Creates a new PeerInfo.

Saves the connection info to calculate tx announcement delays later.

Definition at line 34 of file txdownloadman_impl.cpp.

◆ DisconnectedPeer()

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

Deletes all txrequest announcements and orphans for a given peer.

Definition at line 38 of file txdownloadman_impl.cpp.

◆ GetOrphanTransactions()

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

◆ GetRequestsToSend()

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

Get getdata requests to send.

Definition at line 46 of file txdownloadman_impl.cpp.

◆ GetTxToReconsider()

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

Returns next orphan tx to consider, or nullptr if none exist.

Definition at line 74 of file txdownloadman_impl.cpp.

◆ HaveMoreWork()

bool node::TxDownloadManager::HaveMoreWork ( NodeId  nodeid) const

Whether there are any orphans to reconsider for this peer.

Definition at line 70 of file txdownloadman_impl.cpp.

◆ MempoolAcceptedTx()

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

Respond to successful transaction submission to mempool.

Definition at line 54 of file txdownloadman_impl.cpp.

◆ MempoolRejectedPackage()

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

Respond to package rejected from mempool.

Definition at line 62 of file txdownloadman_impl.cpp.

◆ MempoolRejectedTx()

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

Respond to transaction rejected from mempool.

Definition at line 58 of file txdownloadman_impl.cpp.

◆ ReceivedNotFound()

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

Should be called when a notfound for a tx has been received.

Definition at line 50 of file txdownloadman_impl.cpp.

◆ ReceivedTx()

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

Marks a tx as ReceivedResponse in txrequest and checks whether AlreadyHaveTx.

Return a bool indicating whether this tx should be validated. If false, optionally, a PackageToValidate.

Definition at line 66 of file txdownloadman_impl.cpp.

Member Data Documentation

◆ m_impl

const std::unique_ptr<TxDownloadManagerImpl> node::TxDownloadManager::m_impl
private

Definition at line 120 of file txdownloadman.h.


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