Bitcoin ABC 0.34.5
P2P Digital Currency
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Types | 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]

Classes

struct  IteratorComparator
 
struct  PoolTx
 Allows providing pool transaction information externally. More...
 

Public Member Functions

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

Protected Types

using PoolTxMap = decltype(m_pool_txs)
 

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.
 
std::map< TxId, PoolTx > m_pool_txs
 Map from txid to pool transaction record.
 
std::map< NodeId, std::set< TxId > > m_peer_work_set
 Which peer provided the transactions that need to be reconsidered.
 
std::map< COutPoint, std::set< PoolTxMap ::iterator, IteratorComparator > > m_outpoint_to_tx_it
 Index from the parents' COutPoint into the m_pool_txs.
 
std::vector< PoolTxMap::iterator > m_txs_list
 Pool transactions in vector for quick random eviction.
 
NodeSeconds m_next_sweep {0s}
 Timestamp for the next scheduled sweep of expired transactions.
 

Detailed Description

A class to store and track transactions by peers.

Definition at line 24 of file txpool.h.

Member Typedef Documentation

◆ PoolTxMap

using TxPool::PoolTxMap = decltype(m_pool_txs)
protected

Definition at line 122 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

◆ AddAnnouncer()

bool TxPool::AddAnnouncer ( const TxId &  txid,
NodeId  peer 
)

Add an additional announcer to a tx if it exists.

Otherwise, do nothing.

Definition at line 50 of file txpool.cpp.

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

◆ AddChildrenToWorkSet()

void TxPool::AddChildrenToWorkSet ( const CTransaction &  tx,
FastRandomContext &  rng 
)

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

Definition at line 162 of file txpool.cpp.

Here is the call graph for this function:
Here is the caller 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:
Here is the caller 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 260 of file txpool.cpp.

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

◆ EraseForPeer()

void TxPool::EraseForPeer ( NodeId  peer)

Maybe erase all txs announced by a peer (eg, after that peer disconnects).

If a tx has been announced by another peer, don't erase, just remove this peer from the list of announcers.

Definition at line 103 of file txpool.cpp.

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

◆ EraseTx()

int TxPool::EraseTx ( const TxId &  txid)

Erase a tx by txid.

Definition at line 65 of file txpool.cpp.

Here is the call graph for this function:
Here is the caller 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 300 of file txpool.cpp.

Here is the caller graph for this function:

◆ GetConflictTxs()

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

Definition at line 218 of file txpool.cpp.

◆ GetPoolTransactions()

std::vector< TxPool::PoolTx > TxPool::GetPoolTransactions ( ) const

Definition at line 342 of file txpool.cpp.

Here is the caller graph for this function:

◆ GetTx()

CTransactionRef TxPool::GetTx ( const TxId &  txid) const

Definition at line 208 of file txpool.cpp.

Here is the caller 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 234 of file txpool.cpp.

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

◆ HaveTx()

bool TxPool::HaveTx ( const TxId &  txid) const

Check if we already have an the transaction.

Definition at line 199 of file txpool.cpp.

Here is the caller graph for this function:

◆ HaveTxFromPeer()

bool TxPool::HaveTxFromPeer ( const TxId &  txid,
NodeId  peer 
) const

Check if a {tx, peer} exists in the pool.

Definition at line 203 of file txpool.cpp.

◆ HaveTxToReconsider()

bool TxPool::HaveTxToReconsider ( NodeId  peer)

Does this peer have any work to do?

Definition at line 251 of file txpool.cpp.

Here is the caller 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 128 of file txpool.cpp.

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

◆ Size()

size_t TxPool::Size ( ) const
inline

Return how many entries exist in the pool.

Definition at line 92 of file txpool.h.

Member Data Documentation

◆ expireInterval

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

Minimum time between transactions expire time checks.

Definition at line 111 of file txpool.h.

◆ expireTime

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

Expiration time for transactions.

Definition at line 109 of file txpool.h.

◆ m_next_sweep

NodeSeconds TxPool::m_next_sweep {0s}
protected

Timestamp for the next scheduled sweep of expired transactions.

Definition at line 141 of file txpool.h.

◆ m_outpoint_to_tx_it

std::map<COutPoint, std::set<PoolTxMap ::iterator, IteratorComparator> > TxPool::m_outpoint_to_tx_it
protected

Index from the parents' COutPoint into the m_pool_txs.

Used to remove transactions from the m_pool_txs

Definition at line 135 of file txpool.h.

◆ m_peer_work_set

std::map<NodeId, std::set<TxId> > TxPool::m_peer_work_set
protected

Which peer provided the transactions that need to be reconsidered.

Definition at line 120 of file txpool.h.

◆ m_pool_txs

std::map<TxId, PoolTx> TxPool::m_pool_txs
protected

Map from txid to pool transaction record.

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

Definition at line 117 of file txpool.h.

◆ m_txs_list

std::vector<PoolTxMap::iterator> TxPool::m_txs_list
protected

Pool transactions in vector for quick random eviction.

Definition at line 138 of file txpool.h.

◆ txKind

const std::string TxPool::txKind
protected

The transaction kind as string, used for logging.

Definition at line 107 of file txpool.h.


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