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/overflow.h>
16
17#include <chrono>
18#include <cstddef>
19#include <cstdint>
20#include <functional>
21#include <memory>
22#include <set>
23
24class CBlockIndex;
25
26struct LockPoints {
27 // Will be set to the blockchain height and median time past
28 // values that would be necessary to satisfy all relative locktime
29 // constraints (BIP68) of this tx given our view of block chain history
30 int height{0};
31 int64_t time{0};
32 // As long as the current chain descends from the highest height block
33 // containing one of the inputs used in the calculation, then the cached
34 // values are still valid even after a reorg.
36};
37
39 // SFINAE for T where T is either a pointer type (e.g., a txiter) or a reference_wrapper<T>
40 // (e.g. a wrapped CTxMemPoolEntry&)
41 template <typename T>
42 bool operator()(const std::reference_wrapper<T>& a, const std::reference_wrapper<T>& b) const
43 {
44 return a.get().GetTx().GetHash() < b.get().GetTx().GetHash();
45 }
46 template <typename T>
47 bool operator()(const T& a, const T& b) const
48 {
49 return a->GetTx().GetHash() < b->GetTx().GetHash();
50 }
51};
52
66{
67public:
68 typedef std::reference_wrapper<const CTxMemPoolEntry> CTxMemPoolEntryRef;
69
70private:
72
74 const CAmount nFee;
75 const int32_t nTxWeight;
76 const size_t nUsageSize;
77 const int64_t nTime;
78 const uint64_t entry_sequence;
79 const unsigned int entryHeight;
80 const bool spendsCoinbase;
81 const int64_t sigOpCost;
84
85public:
86 virtual ~CTxMemPoolEntry() = default;
88 int64_t time, unsigned int entry_height, uint64_t entry_sequence,
89 bool spends_coinbase,
90 int64_t sigops_cost, LockPoints lp)
91 : tx{tx},
92 nFee{fee},
95 nTime{time},
97 entryHeight{entry_height},
98 spendsCoinbase{spends_coinbase},
99 sigOpCost{sigops_cost},
101 lockPoints{lp} {}
102
106
107 const CTransaction& GetTx() const { return *this->tx; }
108 CTransactionRef GetSharedTx() const { return this->tx; }
109 const CAmount& GetFee() const { return nFee; }
110 int32_t GetTxSize() const
111 {
113 }
115 int32_t GetTxWeight() const { return nTxWeight; }
116 std::chrono::seconds GetTime() const { return std::chrono::seconds{nTime}; }
117 unsigned int GetHeight() const { return entryHeight; }
118 uint64_t GetSequence() const { return entry_sequence; }
119 int64_t GetSigOpCost() const { return sigOpCost; }
121 size_t DynamicMemoryUsage() const { return nUsageSize; }
122 const LockPoints& GetLockPoints() const { return lockPoints; }
123
124 // Updates the modified fees with descendants/ancestors.
125 void UpdateModifiedFee(CAmount fee_diff) const
126 {
128 }
129
130 // Update the LockPoints after a reorg
131 void UpdateLockPoints(const LockPoints& lp) const
132 {
133 lockPoints = lp;
134 }
135
136 bool GetSpendsCoinbase() const { return spendsCoinbase; }
137
138 mutable size_t idx_randomized;
139};
140
142
145 /* The fee the transaction paid */
157 /* The block height the transaction entered the mempool */
158 const unsigned int txHeight;
159
160 TransactionInfo(const CTransactionRef& tx, const CAmount& fee, const int64_t vsize, const unsigned int height)
161 : m_tx{tx},
162 m_fee{fee},
164 txHeight{height} {}
165};
166
170 : info{entry.GetSharedTx(), entry.GetFee(), entry.GetTxSize(), entry.GetHeight()} {}
171};
172
175 /*
176 * This boolean indicates whether the transaction was added
177 * without enforcing mempool fee limits.
178 */
180 /* This boolean indicates whether the transaction is part of a package. */
182 /*
183 * This boolean indicates whether the blockchain is up to date when the
184 * transaction is added to the mempool.
185 */
187 /* Indicates whether the transaction has unconfirmed parents. */
189
191 const int64_t vsize, const unsigned int height,
192 const bool mempool_limit_bypassed, const bool submitted_in_package,
193 const bool chainstate_is_current,
194 const bool has_no_mempool_parents)
195 : info{tx, fee, vsize, height},
196 m_mempool_limit_bypassed{mempool_limit_bypassed},
197 m_submitted_in_package{submitted_in_package},
198 m_chainstate_is_current{chainstate_is_current},
199 m_has_no_mempool_parents{has_no_mempool_parents} {}
200};
201
202#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:95
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:66
CAmount m_modified_fee
Used for determining the priority of the transaction for mining in a block.
Definition: mempool_entry.h:82
CTxMemPoolEntry(CTxMemPoolEntry &&)=default
const int64_t sigOpCost
Total sigop cost.
Definition: mempool_entry.h:81
const CTransactionRef tx
Definition: mempool_entry.h:73
const LockPoints & GetLockPoints() const
CTxMemPoolEntry & operator=(const CTxMemPoolEntry &)=delete
const bool spendsCoinbase
keep track of transactions that spend a coinbase
Definition: mempool_entry.h:80
uint64_t GetSequence() const
unsigned int GetHeight() const
std::chrono::seconds GetTime() const
const CTransaction & GetTx() const
virtual ~CTxMemPoolEntry()=default
int32_t GetTxWeight() const
std::reference_wrapper< const CTxMemPoolEntry > CTxMemPoolEntryRef
Definition: mempool_entry.h:68
bool GetSpendsCoinbase() const
const int64_t nTime
Local time when entering the mempool.
Definition: mempool_entry.h:77
size_t idx_randomized
Index in mempool's txns_randomized.
const size_t nUsageSize
... and total memory usage
Definition: mempool_entry.h:76
const uint64_t entry_sequence
Sequence number used to determine whether this transaction is too recent for relay.
Definition: mempool_entry.h:78
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:75
const CAmount nFee
Cached to avoid expensive parent-transaction lookups.
Definition: mempool_entry.h:74
const CAmount & GetFee() const
LockPoints lockPoints
Track the height and time at which tx was final.
Definition: mempool_entry.h:83
CAmount GetModifiedFee() const
CTxMemPoolEntry(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:87
CTxMemPoolEntry & operator=(CTxMemPoolEntry &&)=delete
void UpdateLockPoints(const LockPoints &lp) const
const unsigned int entryHeight
Chain height when entering the mempool.
Definition: mempool_entry.h:79
void UpdateModifiedFee(CAmount fee_diff) const
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:47
bool operator()(const std::reference_wrapper< T > &a, const std::reference_wrapper< T > &b) const
Definition: mempool_entry.h:42
CBlockIndex * maxInputBlock
Definition: mempool_entry.h:35
int64_t time
Definition: mempool_entry.h:31
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.