Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
TxPool Class Reference

A class to store and track transactions by peers. More...

#include <txpool.h>

Inheritance diagram for TxPool:
[legend]
Collaboration diagram for TxPool:
[legend]

Classes

struct  IteratorComparator
 
struct  PoolTx
 

Public Member Functions

 TxPool (const std::string &txKindIn, std::chrono::seconds expireTimeIn, std::chrono::seconds expireIntervalIn)
 
bool AddTx (const CTransactionRef &tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Add a new transaction to the pool.
 
bool HaveTx (const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Check if we already have an the transaction.
 
CTransactionRef GetTx (const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 
std::vector< CTransactionRefGetConflictTxs (const CTransactionRef &tx) const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 
CTransactionRef GetTxToReconsider (NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Extract a transaction from a peer's work set.
 
int EraseTx (const TxId &txid) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Erase a tx by txid.
 
void EraseForPeer (NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Erase all txs announced by a peer (eg, after that peer disconnects)
 
void EraseForBlock (const CBlock &block) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Erase all txs included in or invalidated by a new block.
 
unsigned int LimitTxs (unsigned int max_txs, FastRandomContext &rng) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Limit the txs to the given maximum.
 
void AddChildrenToWorkSet (const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Add any tx that list a particular tx as a parent into the from peer's work set.
 
bool HaveTxToReconsider (NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Does this peer have any work to do?
 
std::vector< CTransactionRefGetChildrenFromSamePeer (const CTransactionRef &parent, NodeId nodeid) const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Get all children that spend from this tx and were received from nodeid.
 
std::vector< std::pair< CTransactionRef, NodeId > > GetChildrenFromDifferentPeer (const CTransactionRef &parent, NodeId nodeid) const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Get all children that spend from this tx but were not received from nodeid.
 
size_t Size () const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Return how many entries exist in the pool.
 

Protected Types

using PoolTxMap = decltype(m_pool_txs)
 

Protected Member Functions

std::map< TxId, PoolTx > m_pool_txs GUARDED_BY (m_mutex)
 Map from txid to pool transaction record.
 
std::map< NodeId, std::set< TxId > > m_peer_work_set GUARDED_BY (m_mutex)
 Which peer provided the transactions that need to be reconsidered.
 
std::map< COutPoint, std::set< PoolTxMap ::iterator, IteratorComparator > > m_outpoint_to_tx_it GUARDED_BY (m_mutex)
 Index from the parents' COutPoint into the m_pool_txs.
 
std::vector< PoolTxMap::iterator > m_txs_list GUARDED_BY (m_mutex)
 Pool transactions in vector for quick random eviction.
 
int EraseTxNoLock (const TxId &txid) EXCLUSIVE_LOCKS_REQUIRED(m_mutex)
 Erase a transaction by txid.
 
NodeSeconds m_next_sweep GUARDED_BY (m_mutex)
 Timestamp for the next scheduled sweep of expired transactions.
 

Protected Attributes

const std::string txKind
 The transaction kind as string, used for logging.
 
const std::chrono::seconds expireTime
 Expiration time for transactions.
 
const std::chrono::seconds expireInterval
 Minimum time between transactions expire time checks.
 
Mutex m_mutex
 Guards transactions.
 

Detailed Description

A class to store and track transactions by peers.

Definition at line 24 of file txpool.h.

Member Typedef Documentation

◆ PoolTxMap

Definition at line 128 of file txpool.h.

Constructor & Destructor Documentation

◆ TxPool()

TxPool::TxPool ( const std::string &  txKindIn,
std::chrono::seconds  expireTimeIn,
std::chrono::seconds  expireIntervalIn 
)
inline

Definition at line 26 of file txpool.h.

Member Function Documentation

◆ AddChildrenToWorkSet()

void TxPool::AddChildrenToWorkSet ( const CTransaction tx)

Add any tx that list a particular tx as a parent into the from peer's work set.

Definition at line 151 of file txpool.cpp.

Here is the call graph for this function:

◆ AddTx()

bool TxPool::AddTx ( const CTransactionRef tx,
NodeId  peer 
)

Add a new transaction to the pool.

Definition at line 15 of file txpool.cpp.

Here is the call graph for this function:

◆ EraseForBlock()

void TxPool::EraseForBlock ( const CBlock block)

Erase all txs included in or invalidated by a new block.

Definition at line 239 of file txpool.cpp.

Here is the call graph for this function:

◆ EraseForPeer()

void TxPool::EraseForPeer ( NodeId  peer)

Erase all txs announced by a peer (eg, after that peer disconnects)

Definition at line 94 of file txpool.cpp.

Here is the call graph for this function:

◆ EraseTx()

int TxPool::EraseTx ( const TxId txid)

Erase a tx by txid.

Definition at line 50 of file txpool.cpp.

Here is the call graph for this function:

◆ EraseTxNoLock()

int TxPool::EraseTxNoLock ( const TxId txid)
protected

Erase a transaction by txid.

Definition at line 55 of file txpool.cpp.

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

◆ GetChildrenFromDifferentPeer()

std::vector< std::pair< CTransactionRef, NodeId > > TxPool::GetChildrenFromDifferentPeer ( const CTransactionRef parent,
NodeId  nodeid 
) const

Get all children that spend from this tx but were not received from nodeid.

Also return which peer provided each tx.

Definition at line 322 of file txpool.cpp.

Here is the call graph for this function:

◆ GetChildrenFromSamePeer()

std::vector< CTransactionRef > TxPool::GetChildrenFromSamePeer ( const CTransactionRef parent,
NodeId  nodeid 
) const

Get all children that spend from this tx and were received from nodeid.

Sorted from most recent to least recent.

Definition at line 277 of file txpool.cpp.

Here is the call graph for this function:

◆ GetConflictTxs()

std::vector< CTransactionRef > TxPool::GetConflictTxs ( const CTransactionRef tx) const

Definition at line 191 of file txpool.cpp.

Here is the call graph for this function:

◆ GetTx()

CTransactionRef TxPool::GetTx ( const TxId txid) const

Definition at line 179 of file txpool.cpp.

Here is the call graph for this function:

◆ GetTxToReconsider()

CTransactionRef TxPool::GetTxToReconsider ( NodeId  peer)

Extract a transaction from a peer's work set.

Returns nullptr if there are no transactions to work on. Otherwise returns the transaction reference, and removes it from the work set.

Definition at line 209 of file txpool.cpp.

Here is the call graph for this function:

◆ GUARDED_BY() [1/5]

std::map< TxId, PoolTx > m_pool_txs TxPool::GUARDED_BY ( m_mutex  )
protected

Map from txid to pool transaction record.

Should be size constrained by calling LimitTxs() with the desired max size.

◆ GUARDED_BY() [2/5]

std::map< NodeId, std::set< TxId > > m_peer_work_set TxPool::GUARDED_BY ( m_mutex  )
protected

Which peer provided the transactions that need to be reconsidered.

◆ GUARDED_BY() [3/5]

std::map< COutPoint, std::set< PoolTxMap ::iterator, IteratorComparator > > m_outpoint_to_tx_it TxPool::GUARDED_BY ( m_mutex  )
protected

Index from the parents' COutPoint into the m_pool_txs.

Used to remove transactions from the m_pool_txs

◆ GUARDED_BY() [4/5]

std::vector< PoolTxMap::iterator > m_txs_list TxPool::GUARDED_BY ( m_mutex  )
protected

Pool transactions in vector for quick random eviction.

◆ GUARDED_BY() [5/5]

NodeSeconds m_next_sweep TxPool::GUARDED_BY ( m_mutex  )
inlineprotected

Timestamp for the next scheduled sweep of expired transactions.

Definition at line 150 of file txpool.h.

◆ HaveTx()

bool TxPool::HaveTx ( const TxId txid) const

Check if we already have an the transaction.

Definition at line 174 of file txpool.cpp.

Here is the call graph for this function:

◆ HaveTxToReconsider()

bool TxPool::HaveTxToReconsider ( NodeId  peer)

Does this peer have any work to do?

Definition at line 228 of file txpool.cpp.

Here is the call graph for this function:

◆ LimitTxs()

unsigned int TxPool::LimitTxs ( unsigned int  max_txs,
FastRandomContext rng 
)

Limit the txs to the given maximum.

Definition at line 115 of file txpool.cpp.

Here is the call graph for this function:

◆ Size()

size_t TxPool::Size ( ) const
inline

Return how many entries exist in the pool.

Definition at line 96 of file txpool.h.

Here is the call graph for this function:

Member Data Documentation

◆ expireInterval

const std::chrono::seconds TxPool::expireInterval
protected

Minimum time between transactions expire time checks.

Definition at line 107 of file txpool.h.

◆ expireTime

const std::chrono::seconds TxPool::expireTime
protected

Expiration time for transactions.

Definition at line 105 of file txpool.h.

◆ m_mutex

Mutex TxPool::m_mutex
mutableprotected

Guards transactions.

Definition at line 110 of file txpool.h.

◆ txKind

const std::string TxPool::txKind
protected

The transaction kind as string, used for logging.

Definition at line 103 of file txpool.h.


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