Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
mempool_entry.h
Go to the documentation of this file.
1// Copyright (c) 2009-2022 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef BITCOIN_KERNEL_MEMPOOL_ENTRY_H
6#define BITCOIN_KERNEL_MEMPOOL_ENTRY_H
7
8#include <consensus/amount.h>
9#include <core_memusage.h>
10#include <policy/policy.h>
11#include <policy/settings.h>
13#include <rcu.h>
14
15#include <chrono>
16#include <cstddef>
17#include <cstdint>
18#include <functional>
19#include <memory>
20#include <set>
21
22struct LockPoints {
23 // Will be set to the blockchain height and median time past values that
24 // would be necessary to satisfy all relative locktime constraints (BIP68)
25 // of this tx given our view of block chain history
26 int height{0};
28};
29
31 // SFINAE for T where T is either a std::reference_wrapper<T> (e.g. a
32 // CTxMemPoolEntryRef) or an iterator to a pointer type (e.g., a txiter)
33 template <typename T>
34 bool operator()(const std::reference_wrapper<T> &a,
35 const std::reference_wrapper<T> &b) const {
36 return a.get()->GetTx().GetId() < b.get()->GetTx().GetId();
37 }
38 template <typename T> bool operator()(const T &a, const T &b) const {
39 return (*a)->GetTx().GetId() < (*b)->GetTx().GetId();
40 }
41};
44 template <typename T>
45 bool operator()(const std::reference_wrapper<T> &a,
46 const std::reference_wrapper<T> &b) const {
47 return a.get()->GetEntryId() > b.get()->GetEntryId();
48 }
49
50 template <typename T> bool operator()(const T &a, const T &b) const {
51 return (*a)->GetEntryId() > (*b)->GetEntryId();
52 }
53};
54
55class CTxMemPoolEntry;
57
66public:
67 // two aliases, should the types ever diverge
68 typedef std::set<std::reference_wrapper<const CTxMemPoolEntryRef>,
71 typedef std::set<std::reference_wrapper<const CTxMemPoolEntryRef>,
74
75private:
78
83 const Amount nFee;
85 const size_t nTxSize;
87 const size_t nUsageSize;
91 const unsigned int entryHeight;
99
101
102public:
105 : tx{_tx}, nFee{fee},
106 nTxSize(tx->GetTotalSize()), nUsageSize{RecursiveDynamicUsage(tx)},
108 lockPoints(lp) {}
109
110 CTxMemPoolEntry(const CTxMemPoolEntry &other) = delete;
112 : entryId(other.entryId), tx(std::move(other.tx)),
113 m_parents(std::move(other.m_parents)),
114 m_children(std::move(other.m_children)), nFee(other.nFee),
115 nTxSize(other.nTxSize), nUsageSize(other.nUsageSize),
116 nTime(other.nTime), entryHeight(other.entryHeight),
117 sigChecks(other.sigChecks), feeDelta(other.feeDelta),
118 lockPoints(std::move(other.lockPoints)),
119 refcount(other.refcount.load()){};
120
121 uint64_t GetEntryId() const { return entryId; }
125
126 const CTransaction &GetTx() const { return *this->tx; }
127 CTransactionRef GetSharedTx() const { return this->tx; }
128 Amount GetFee() const { return nFee; }
129 size_t GetTxSize() const { return nTxSize; }
134
135 std::chrono::seconds GetTime() const { return std::chrono::seconds{nTime}; }
136 unsigned int GetHeight() const { return entryHeight; }
137 int64_t GetSigChecks() const { return sigChecks; }
138 Amount GetModifiedFee() const { return nFee + feeDelta; }
142 size_t DynamicMemoryUsage() const { return nUsageSize; }
143 const LockPoints &GetLockPoints() const { return lockPoints; }
144
145 // Updates the fee delta used for mining priority score
147
148 const Parents &GetMemPoolParentsConst() const { return m_parents; }
149 const Children &GetMemPoolChildrenConst() const { return m_children; }
152};
153
154#endif // BITCOIN_KERNEL_MEMPOOL_ENTRY_H
Fee rate in satoshis per kilobyte: Amount / kB.
Definition feerate.h:21
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
const CTransactionRef tx
const LockPoints & GetLockPoints() const
unsigned int GetHeight() const
std::chrono::seconds GetTime() const
const CTransaction & GetTx() const
Children & GetMemPoolChildren() const
IMPLEMENT_RCU_REFCOUNT(uint64_t)
uint64_t GetEntryId() const
const int64_t nTime
Local time when entering the mempool.
const Amount nFee
Cached to avoid expensive parent-transaction lookups.
const size_t nTxSize
... and avoid recomputing tx size
const size_t nUsageSize
... and total memory usage
Amount GetFee() const
CTxMemPoolEntry(const CTransactionRef &_tx, const Amount fee, int64_t time, unsigned int entry_height, int64_t sigchecks, LockPoints lp)
int64_t GetSigChecks() const
void SetEntryId(uint64_t eid)
This should only be set by addUnchecked() before entry insertion into mempool.
std::set< std::reference_wrapper< const CTxMemPoolEntryRef >, CompareIteratorById > Children
const Children & GetMemPoolChildrenConst() const
Parents m_parents
size_t GetTxSize() const
CTxMemPoolEntry(const CTxMemPoolEntry &other)=delete
Amount feeDelta
Used for determining the priority of the transaction for mining in a block.
CTxMemPoolEntry(CTxMemPoolEntry &&other)
CTransactionRef GetSharedTx() const
Amount GetModifiedFee() const
const Parents & GetMemPoolParentsConst() const
CFeeRate GetModifiedFeeRate() const
size_t DynamicMemoryUsage() const
void UpdateFeeDelta(Amount newFeeDelta)
size_t GetTxVirtualSize() const
Parents & GetMemPoolParents() const
uint64_t entryId
Unique identifier – used for topological sorting.
LockPoints lockPoints
Track the height and time at which tx was final.
Children m_children
const unsigned int entryHeight
Chain height when entering the mempool.
std::set< std::reference_wrapper< const CTxMemPoolEntryRef >, CompareIteratorById > Parents
const int64_t sigChecks
Total sigChecks.
Definition rcu.h:85
static size_t RecursiveDynamicUsage(const CScript &script)
LockPoints lp
Implement std::hash so RCUPtr can be used as a key for maps or sets.
Definition rcu.h:257
uint32_t nBytesPerSigCheck
Definition settings.cpp:10
int64_t GetVirtualTransactionSize(int64_t nSize, int64_t nSigChecks, unsigned int bytes_per_sigCheck)
Compute the virtual transaction size (size, or more if sigChecks are too dense).
Definition policy.cpp:165
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...
Definition random.h:85
static constexpr Amount zero() noexcept
Definition amount.h:32
bool operator()(const std::reference_wrapper< T > &a, const std::reference_wrapper< T > &b) const
bool operator()(const T &a, const T &b) const
Iterate txs in reverse-topological order.
bool operator()(const std::reference_wrapper< T > &a, const std::reference_wrapper< T > &b) const
bool operator()(const T &a, const T &b) const
int64_t time