5#ifndef BITCOIN_TXPOOL_H
6#define BITCOIN_TXPOOL_H
26 TxPool(
const std::string &txKindIn, std::chrono::seconds expireTimeIn,
27 std::chrono::seconds expireIntervalIn)
46 std::vector<CTransactionRef>
87 std::vector<CTransactionRef>
125 template <
typename I>
bool operator()(
const I &a,
const I &b)
const {
126 return a->first < b->first;
134 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.
void EraseForPeer(NodeId peer)
Maybe erase all txs announced by a peer (eg, after that peer disconnects).
TxPool(const std::string &txKindIn, std::chrono::seconds expireTimeIn, std::chrono::seconds expireIntervalIn)
void EraseForBlock(const CBlock &block)
Erase all txs included in or invalidated by a new block.
CTransactionRef GetTx(const TxId &txid) const
const std::chrono::seconds expireInterval
Minimum time between transactions expire time checks.
std::map< COutPoint, std::set< PoolTxMap ::iterator, IteratorComparator > > m_outpoint_to_tx_it
Index from the parents' COutPoint into the m_pool_txs.
CTransactionRef GetTxToReconsider(NodeId peer)
Extract a transaction from a peer's work set.
bool AddAnnouncer(const TxId &txid, NodeId peer)
Add an additional announcer to a tx if it exists.
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.
const std::chrono::seconds expireTime
Expiration time for transactions.
bool AddTx(const CTransactionRef &tx, NodeId peer)
Add a new transaction to the pool.
NodeSeconds m_next_sweep
Timestamp for the next scheduled sweep of expired transactions.
const std::string txKind
The transaction kind as string, used for logging.
std::vector< CTransactionRef > GetConflictTxs(const CTransactionRef &tx) const
size_t Size() const
Return how many entries exist in the pool.
std::map< NodeId, std::set< TxId > > m_peer_work_set
Which peer provided the transactions that need to be reconsidered.
std::vector< PoolTxMap::iterator > m_txs_list
Pool transactions in vector for quick random eviction.
unsigned int LimitTxs(unsigned int max_txs, FastRandomContext &rng)
Limit the txs to the given maximum.
std::vector< CTransactionRef > GetChildrenFromSamePeer(const CTransactionRef &parent, NodeId nodeid) const
Get all children that spend from this tx and were received from nodeid.
bool HaveTx(const TxId &txid) const
Check if we already have an the transaction.
bool HaveTxToReconsider(NodeId peer)
Does this peer have any work to do?
int EraseTx(const TxId &txid)
Erase a tx by txid.
bool HaveTxFromPeer(const TxId &txid, NodeId peer) const
Check if a {tx, peer} exists in the pool.
std::vector< PoolTx > GetPoolTransactions() const
decltype(m_pool_txs) PoolTxMap
std::map< TxId, PoolTx > m_pool_txs
Map from txid to pool transaction record.
std::shared_ptr< const CTransaction > CTransactionRef
A TxId is the identifier of a transaction.
bool operator()(const I &a, const I &b) const
Allows providing pool transaction information externally.
std::set< NodeId > announcers
Peers added with AddTx or AddAnnouncer.
std::chrono::time_point< NodeClock, std::chrono::seconds > NodeSeconds