5#ifndef BITCOIN_TXPOOL_H
6#define BITCOIN_TXPOOL_H
82 std::vector<CTransactionRef>
90 std::vector<std::pair<CTransactionRef, NodeId>>
132 return a->first <
b->first;
140 std::map<COutPoint, std::set<PoolTxMap ::iterator, IteratorComparator>>
The basic transaction that is broadcasted on the network and contained in blocks.
A class to store and track transactions by peers.
CTransactionRef GetTx(const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
int EraseTx(const TxId &txid) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Erase a tx by txid.
TxPool(const std::string &txKindIn, std::chrono::seconds expireTimeIn, std::chrono::seconds expireIntervalIn)
const std::chrono::seconds expireInterval
Minimum time between transactions expire time checks.
void EraseForPeer(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Erase all txs announced by a peer (eg, after that peer disconnects)
std::vector< CTransactionRef > GetChildrenFromSamePeer(const CTransactionRef &parent, NodeId nodeid) const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Get all children that spend from this tx and were received from nodeid.
size_t Size() const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Return how many entries exist in the pool.
bool AddTx(const CTransactionRef &tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Add a new transaction to the pool.
int EraseTxNoLock(const TxId &txid) EXCLUSIVE_LOCKS_REQUIRED(m_mutex)
Erase a transaction by txid.
unsigned int LimitTxs(unsigned int max_txs, FastRandomContext &rng) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Limit the txs to the given maximum.
NodeSeconds m_next_sweep GUARDED_BY(m_mutex)
Timestamp for the next scheduled sweep of expired transactions.
void EraseForBlock(const CBlock &block) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Erase all txs included in or invalidated by a new block.
const std::chrono::seconds expireTime
Expiration time for transactions.
std::vector< CTransactionRef > GetConflictTxs(const CTransactionRef &tx) const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
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.
const std::string txKind
The transaction kind as string, used for logging.
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::map< TxId, PoolTx > m_pool_txs GUARDED_BY(m_mutex)
Map from txid to pool transaction record.
Mutex m_mutex
Guards transactions.
std::vector< PoolTxMap::iterator > m_txs_list GUARDED_BY(m_mutex)
Pool transactions in vector for quick random eviction.
bool HaveTx(const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Check if we already have an the transaction.
CTransactionRef GetTxToReconsider(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Extract a transaction from a peer's work set.
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.
bool HaveTxToReconsider(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Does this peer have any work to do?
std::map< NodeId, std::set< TxId > > m_peer_work_set GUARDED_BY(m_mutex)
Which peer provided the transactions that need to be reconsidered.
decltype(m_pool_txs) PoolTxMap
std::shared_ptr< const CTransaction > CTransactionRef
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
A TxId is the identifier of a transaction.
bool operator()(const I &a, const I &b) const
#define EXCLUSIVE_LOCKS_REQUIRED(...)
std::chrono::time_point< NodeClock, std::chrono::seconds > NodeSeconds