Bitcoin Core 31.99.0
P2P Digital Currency
Classes | Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
PrivateBroadcast Class Reference

Store a list of transactions to be broadcast privately. More...

#include <private_broadcast.h>

Collaboration diagram for PrivateBroadcast:
[legend]

Classes

struct  CTransactionRefComp
 
struct  CTransactionRefHash
 
struct  PeerSendInfo
 
struct  Priority
 Cumulative stats from all the send attempts for a transaction. Used to prioritize transactions. More...
 
struct  SendStatus
 Status of a transaction sent to a given node. More...
 
struct  TxAndSendStatusForNode
 A pair of a transaction and a sent status for a given node. Convenience return type of GetSendStatusByNode(). More...
 
struct  TxBroadcastInfo
 
struct  TxSendStatus
 

Public Member Functions

bool Add (const CTransactionRef &tx) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Add a transaction to the storage. More...
 
std::optional< size_t > Remove (const CTransactionRef &tx) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Forget a transaction. More...
 
std::optional< CTransactionRefPickTxForSend (const NodeId &will_send_to_nodeid, const CService &will_send_to_address) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Pick the transaction with the fewest send attempts, and confirmations, and oldest send/confirm times. More...
 
std::optional< CTransactionRefGetTxForNode (const NodeId &nodeid) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Get the transaction that was picked for sending to a given node by PickTxForSend(). More...
 
void NodeConfirmedReception (const NodeId &nodeid) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Mark that the node has confirmed reception of the transaction we sent it by responding with PONG to our PING message. More...
 
bool DidNodeConfirmReception (const NodeId &nodeid) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Check if the node has confirmed reception of the transaction. More...
 
bool HavePendingTransactions () EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Check if there are transactions that need to be broadcast. More...
 
std::vector< CTransactionRefGetStale () const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Get the transactions that have not been broadcast recently. More...
 
std::vector< TxBroadcastInfoGetBroadcastInfo () const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Get stats about all transactions currently being privately broadcast. More...
 

Static Public Attributes

static constexpr auto INITIAL_STALE_DURATION {5min}
 If a transaction is not sent to any peer for this duration, then we consider it stale / for rebroadcasting. More...
 
static constexpr auto STALE_DURATION {1min}
 If a transaction is not received back from the network for this duration after it is broadcast, then we consider it stale / for rebroadcasting. More...
 

Private Member Functions

std::optional< TxAndSendStatusForNodeGetSendStatusByNode (const NodeId &nodeid) EXCLUSIVE_LOCKS_REQUIRED(m_mutex)
 Find which transaction we sent to a given node (marked by PickTxForSend()). More...
 
std::unordered_map< CTransactionRef, TxSendStatus, CTransactionRefHash, CTransactionRefComp > m_transactions GUARDED_BY (m_mutex)
 

Static Private Member Functions

static Priority DerivePriority (const std::vector< SendStatus > &sent_to)
 Derive the sending priority of a transaction. More...
 

Private Attributes

Mutex m_mutex
 

Detailed Description

Store a list of transactions to be broadcast privately.

Supports the following operations:

Definition at line 29 of file private_broadcast.h.

Member Function Documentation

◆ Add()

bool PrivateBroadcast::Add ( const CTransactionRef tx)

Add a transaction to the storage.

Parameters
[in]txThe transaction to add.
Return values
trueThe transaction was added.
falseThe transaction was already present.

Definition at line 11 of file private_broadcast.cpp.

Here is the caller graph for this function:

◆ DerivePriority()

PrivateBroadcast::Priority PrivateBroadcast::DerivePriority ( const std::vector< SendStatus > &  sent_to)
staticprivate

Derive the sending priority of a transaction.

Parameters
[in]sent_toList of nodes that the transaction has been sent to.

Definition at line 125 of file private_broadcast.cpp.

Here is the caller graph for this function:

◆ DidNodeConfirmReception()

bool PrivateBroadcast::DidNodeConfirmReception ( const NodeId nodeid)

Check if the node has confirmed reception of the transaction.

Return values
trueNode has confirmed, NodeConfirmedReception() has been called.
falseNode has not confirmed, NodeConfirmedReception() has not been called.

Definition at line 71 of file private_broadcast.cpp.

Here is the caller graph for this function:

◆ GetBroadcastInfo()

std::vector< PrivateBroadcast::TxBroadcastInfo > PrivateBroadcast::GetBroadcastInfo ( ) const

Get stats about all transactions currently being privately broadcast.

Definition at line 106 of file private_broadcast.cpp.

Here is the caller graph for this function:

◆ GetSendStatusByNode()

std::optional< PrivateBroadcast::TxAndSendStatusForNode > PrivateBroadcast::GetSendStatusByNode ( const NodeId nodeid)
private

Find which transaction we sent to a given node (marked by PickTxForSend()).

Returns
That transaction together with the send status or nullopt if we did not send any transaction to the given node.

Definition at line 139 of file private_broadcast.cpp.

Here is the call graph for this function:

◆ GetStale()

std::vector< CTransactionRef > PrivateBroadcast::GetStale ( ) const

Get the transactions that have not been broadcast recently.

Definition at line 89 of file private_broadcast.cpp.

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

◆ GetTxForNode()

std::optional< CTransactionRef > PrivateBroadcast::GetTxForNode ( const NodeId nodeid)

Get the transaction that was picked for sending to a given node by PickTxForSend().

Parameters
[in]nodeidNode to which a transaction is being (or was) sent.
Returns
Transaction or nullopt if the nodeid is unknown.

Definition at line 50 of file private_broadcast.cpp.

Here is the caller graph for this function:

◆ GUARDED_BY()

std::unordered_map< CTransactionRef, TxSendStatus, CTransactionRefHash, CTransactionRefComp > m_transactions PrivateBroadcast::GUARDED_BY ( m_mutex  )
private

◆ HavePendingTransactions()

bool PrivateBroadcast::HavePendingTransactions ( )

Check if there are transactions that need to be broadcast.

Definition at line 82 of file private_broadcast.cpp.

Here is the caller graph for this function:

◆ NodeConfirmedReception()

void PrivateBroadcast::NodeConfirmedReception ( const NodeId nodeid)

Mark that the node has confirmed reception of the transaction we sent it by responding with PONG to our PING message.

Parameters
[in]nodeidNode that we sent a transaction to.

Definition at line 61 of file private_broadcast.cpp.

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

◆ PickTxForSend()

std::optional< CTransactionRef > PrivateBroadcast::PickTxForSend ( const NodeId will_send_to_nodeid,
const CService will_send_to_address 
)

Pick the transaction with the fewest send attempts, and confirmations, and oldest send/confirm times.

Parameters
[in]will_send_to_nodeidWill remember that the returned transaction was picked for sending to this node.
[in]will_send_to_addressAddress of the peer to which this transaction will be sent.
Returns
Most urgent transaction or nullopt if there are no transactions.

Definition at line 31 of file private_broadcast.cpp.

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

◆ Remove()

std::optional< size_t > PrivateBroadcast::Remove ( const CTransactionRef tx)

Forget a transaction.

Parameters
[in]txTransaction to forget.
Return values
!nulloptThe number of times the transaction was sent and confirmed by the recipient (if the transaction existed and was removed).
nulloptThe transaction was not in the storage.

Definition at line 19 of file private_broadcast.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ INITIAL_STALE_DURATION

constexpr auto PrivateBroadcast::INITIAL_STALE_DURATION {5min}
staticconstexpr

If a transaction is not sent to any peer for this duration, then we consider it stale / for rebroadcasting.

Definition at line 35 of file private_broadcast.h.

◆ m_mutex

Mutex PrivateBroadcast::m_mutex
mutableprivate

Definition at line 197 of file private_broadcast.h.

◆ STALE_DURATION

constexpr auto PrivateBroadcast::STALE_DURATION {1min}
staticconstexpr

If a transaction is not received back from the network for this duration after it is broadcast, then we consider it stale / for rebroadcasting.

Definition at line 39 of file private_broadcast.h.


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