18 const TxId &txid = tx->GetId();
26 unsigned int sz = tx->GetTotalSize();
29 "ignoring large %s tx (size: %u, hash: %s)\n",
txKind,
sz,
39 for (
const CTxIn &
txin : tx->vin) {
44 "stored %s tx %s, size: %u (mapsz %u outsz %u)\n",
txKind,
57 std::map<TxId, PoolTx>::iterator it =
m_pool_txs.find(txid);
61 for (
const CTxIn &
txin : it->second.tx->vin) {
67 if (
itPrev->second.empty()) {
72 size_t old_pos = it->second.list_pos;
87 it->second.nTimeExpire));
104 if (
orphan.fromPeer == peer) {
110 "Erased %d %s transaction(s) from peer=%d\n",
nErased,
txKind,
154 for (
size_t i = 0; i < tx.vout.size(); i++) {
167 "added %s tx %s to peer %d workset\n",
txKind,
168 tx.GetId().ToString(),
elem->second.fromPeer);
184 return tx_it->second.tx;
190std::vector<CTransactionRef>
195 for (
const auto &
txin : tx->vin) {
221 return tx_it->second.tx;
245 const CTransaction &tx = *
ptx;
248 for (
const auto &
txin : tx.vin) {
256 const CTransaction &
orphanTx = *(*mi)->second.tx;
271 "Erased %d %s transaction(s) included or conflicted by block\n",
276std::vector<CTransactionRef>
283 std::vector<PoolTxMap::iterator>
iters;
287 for (
unsigned int i = 0; i < parent->vout.size(); i++) {
292 if (
elem->second.fromPeer == nodeid) {
303 std::sort(
iters.begin(),
iters.end(), [](
const auto &
lhs,
const auto &
rhs) {
304 if (lhs->second.nTimeExpire == rhs->second.nTimeExpire) {
305 return &(*lhs) < &(*rhs);
307 return lhs->second.nTimeExpire >
rhs->second.nTimeExpire;
321std::vector<std::pair<CTransactionRef, NodeId>>
328 std::vector<PoolTxMap::iterator>
iters;
332 for (
unsigned int i = 0; i < parent->vout.size(); i++) {
337 if (
elem->second.fromPeer != nodeid) {
std::vector< CTransactionRef > vtx
uint64_t randrange(uint64_t range) noexcept
Generate a random integer in the range [0..range).
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.
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.
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.
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.
Mutex m_mutex
Guards transactions.
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::string ToString() const
#define LogPrint(category,...)
static constexpr unsigned int MAX_STANDARD_TX_SIZE
The maximum size for transactions we're willing to relay/mine.
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...
static time_point now() noexcept
Return current system time or mocked time, if set.
A TxId is the identifier of a transaction.
#define AssertLockHeld(cs)