Bitcoin Core 30.99.0
P2P Digital Currency
mempool_entry.h
Go to the documentation of this file.
1// Copyright (c) 2009-present 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>
10#include <core_memusage.h>
11#include <policy/policy.h>
12#include <policy/settings.h>
14#include <txgraph.h>
15#include <util/epochguard.h>
16#include <util/overflow.h>
17
18#include <chrono>
19#include <cstddef>
20#include <cstdint>
21#include <functional>
22#include <memory>
23#include <set>
24
25class CBlockIndex;
26
27struct LockPoints {
28 // Will be set to the blockchain height and median time past
29 // values that would be necessary to satisfy all relative locktime
30 // constraints (BIP68) of this tx given our view of block chain history
31 int height{0};
32 int64_t time{0};
33 // As long as the current chain descends from the highest height block
34 // containing one of the inputs used in the calculation, then the cached
35 // values are still valid even after a reorg.
37};
38
40 // SFINAE for T where T is either a pointer type (e.g., a txiter) or a reference_wrapper<T>
41 // (e.g. a wrapped CTxMemPoolEntry&)
42 template <typename T>
43 bool operator()(const std::reference_wrapper<T>& a, const std::reference_wrapper<T>& b) const
44 {
45 return a.get().GetTx().GetHash() < b.get().GetTx().GetHash();
46 }
47 template <typename T>
48 bool operator()(const T& a, const T& b) const
49 {
50 return a->GetTx().GetHash() < b->GetTx().GetHash();
51 }
52};
53
67{
68public:
69 typedef std::reference_wrapper<const CTxMemPoolEntry> CTxMemPoolEntryRef;
70
71private:
73
75 const CAmount nFee;
76 const int32_t nTxWeight;
77 const size_t nUsageSize;
78 const int64_t nTime;
79 const uint64_t entry_sequence;
80 const unsigned int entryHeight;
81 const bool spendsCoinbase;
82 const int64_t sigOpCost;
85
86public:
87 virtual ~CTxMemPoolEntry() = default;
89 int64_t time, unsigned int entry_height, uint64_t entry_sequence,
90 bool spends_coinbase,
91 int64_t sigops_cost, LockPoints lp)
92 : TxGraph::Ref(std::move(ref)),
93 tx{tx},
94 nFee{fee},
97 nTime{time},
99 entryHeight{entry_height},
100 spendsCoinbase{spends_coinbase},
101 sigOpCost{sigops_cost},
103 lockPoints{lp} {}
104
108
109 const CTransaction& GetTx() const { return *this->tx; }
110 CTransactionRef GetSharedTx() const { return this->tx; }
111 const CAmount& GetFee() const { return nFee; }
112 int32_t GetTxSize() const
113 {
115 }
117 int32_t GetTxWeight() const { return nTxWeight; }
118 std::chrono::seconds GetTime() const { return std::chrono::seconds{nTime}; }
119 unsigned int GetHeight() const { return entryHeight; }
120 uint64_t GetSequence() const { return entry_sequence; }
121 int64_t GetSigOpCost() const { return sigOpCost; }
123 size_t DynamicMemoryUsage() const { return nUsageSize; }
124 const LockPoints& GetLockPoints() const { return lockPoints; }
125
126 // Updates the modified fees with descendants/ancestors.
127 void UpdateModifiedFee(CAmount fee_diff) const
128 {
130 }
131
132 // Update the LockPoints after a reorg
133 void UpdateLockPoints(const LockPoints& lp) const
134 {
135 lockPoints = lp;
136 }
137
138 bool GetSpendsCoinbase() const { return spendsCoinbase; }
139
140 mutable size_t idx_randomized;
142};
143
145
148 /* The fee the transaction paid */
160 /* The block height the transaction entered the mempool */
161 const unsigned int txHeight;
162
163 TransactionInfo(const CTransactionRef& tx, const CAmount& fee, const int64_t vsize, const unsigned int height)
164 : m_tx{tx},
165 m_fee{fee},
167 txHeight{height} {}
168};
169
173 : info{entry.GetSharedTx(), entry.GetFee(), entry.GetTxSize(), entry.GetHeight()} {}
174};
175
178 /*
179 * This boolean indicates whether the transaction was added
180 * without enforcing mempool fee limits.
181 */
183 /* This boolean indicates whether the transaction is part of a package. */
185 /*
186 * This boolean indicates whether the blockchain is up to date when the
187 * transaction is added to the mempool.
188 */
190 /* Indicates whether the transaction has unconfirmed parents. */
192
194 const int64_t vsize, const unsigned int height,
195 const bool mempool_limit_bypassed, const bool submitted_in_package,
196 const bool chainstate_is_current,
197 const bool has_no_mempool_parents)
198 : info{tx, fee, vsize, height},
199 m_mempool_limit_bypassed{mempool_limit_bypassed},
200 m_submitted_in_package{submitted_in_package},
201 m_chainstate_is_current{chainstate_is_current},
202 m_has_no_mempool_parents{has_no_mempool_parents} {}
203};
204
205#endif // BITCOIN_KERNEL_MEMPOOL_ENTRY_H
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:103
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:281
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
Definition: mempool_entry.h:67
CAmount m_modified_fee
Used for determining the priority of the transaction for mining in a block.
Definition: mempool_entry.h:83
CTxMemPoolEntry(CTxMemPoolEntry &&)=default
const int64_t sigOpCost
Total sigop cost.
Definition: mempool_entry.h:82
const CTransactionRef tx
Definition: mempool_entry.h:74
const LockPoints & GetLockPoints() const
Epoch::Marker m_epoch_marker
epoch when last touched, useful for graph algorithms
CTxMemPoolEntry & operator=(const CTxMemPoolEntry &)=delete
const bool spendsCoinbase
keep track of transactions that spend a coinbase
Definition: mempool_entry.h:81
uint64_t GetSequence() const
unsigned int GetHeight() const
std::chrono::seconds GetTime() const
const CTransaction & GetTx() const
virtual ~CTxMemPoolEntry()=default
int32_t GetTxWeight() const
CTxMemPoolEntry(TxGraph::Ref &&ref, const CTransactionRef &tx, CAmount fee, int64_t time, unsigned int entry_height, uint64_t entry_sequence, bool spends_coinbase, int64_t sigops_cost, LockPoints lp)
Definition: mempool_entry.h:88
std::reference_wrapper< const CTxMemPoolEntry > CTxMemPoolEntryRef
Definition: mempool_entry.h:69
bool GetSpendsCoinbase() const
const int64_t nTime
Local time when entering the mempool.
Definition: mempool_entry.h:78
size_t idx_randomized
Index in mempool's txns_randomized.
const size_t nUsageSize
... and total memory usage
Definition: mempool_entry.h:77
const uint64_t entry_sequence
Sequence number used to determine whether this transaction is too recent for relay.
Definition: mempool_entry.h:79
int64_t GetSigOpCost() const
int32_t GetAdjustedWeight() const
CTransactionRef GetSharedTx() const
CTxMemPoolEntry(const CTxMemPoolEntry &)=delete
size_t DynamicMemoryUsage() const
int32_t GetTxSize() const
const int32_t nTxWeight
... and avoid recomputing tx weight (also used for GetTxSize())
Definition: mempool_entry.h:76
const CAmount nFee
Cached to avoid expensive parent-transaction lookups.
Definition: mempool_entry.h:75
const CAmount & GetFee() const
LockPoints lockPoints
Track the height and time at which tx was final.
Definition: mempool_entry.h:84
CAmount GetModifiedFee() const
CTxMemPoolEntry & operator=(CTxMemPoolEntry &&)=delete
void UpdateLockPoints(const LockPoints &lp) const
const unsigned int entryHeight
Chain height when entering the mempool.
Definition: mempool_entry.h:80
void UpdateModifiedFee(CAmount fee_diff) const
Ref() noexcept=default
Construct an empty Ref.
Data structure to encapsulate fees, sizes, and dependencies for a set of transactions.
Definition: txgraph.h:47
static int32_t GetTransactionWeight(const CTransaction &tx)
Definition: validation.h:132
static size_t RecursiveDynamicUsage(const CScript &script)
Definition: core_memusage.h:12
CTxMemPoolEntry::CTxMemPoolEntryRef CTxMemPoolEntryRef
uint64_t fee
LockPoints lp
T SaturatingAdd(const T i, const T j) noexcept
Definition: overflow.h:35
unsigned int nBytesPerSigOp
Definition: settings.cpp:10
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop)
Compute the virtual transaction size (weight reinterpreted as bytes).
Definition: policy.cpp:381
int64_t GetSigOpsAdjustedWeight(int64_t weight, int64_t sigop_cost, unsigned int bytes_per_sigop)
Definition: policy.cpp:376
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:403
bool operator()(const T &a, const T &b) const
Definition: mempool_entry.h:48
bool operator()(const std::reference_wrapper< T > &a, const std::reference_wrapper< T > &b) const
Definition: mempool_entry.h:43
CBlockIndex * maxInputBlock
Definition: mempool_entry.h:36
int64_t time
Definition: mempool_entry.h:32
const bool m_has_no_mempool_parents
const bool m_chainstate_is_current
const bool m_mempool_limit_bypassed
NewMempoolTransactionInfo(const CTransactionRef &tx, const CAmount &fee, const int64_t vsize, const unsigned int height, const bool mempool_limit_bypassed, const bool submitted_in_package, const bool chainstate_is_current, const bool has_no_mempool_parents)
RemovedMempoolTransactionInfo(const CTxMemPoolEntry &entry)
TransactionInfo(const CTransactionRef &tx, const CAmount &fee, const int64_t vsize, const unsigned int height)
const CAmount m_fee
const unsigned int txHeight
const CTransactionRef m_tx
const int64_t m_virtual_transaction_size
The virtual transaction size.