Bitcoin ABC 0.33.10
P2P Digital Currency
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};
27 int64_t time{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:
77 uint64_t entryId = 0;
78
83 const Amount nFee;
85 const size_t nTxSize;
87 const size_t nUsageSize;
89 const int64_t nTime;
91 const unsigned int entryHeight;
93 const int64_t sigChecks;
99
101
102public:
103 CTxMemPoolEntry(const CTransactionRef &_tx, const Amount fee, int64_t time,
104 unsigned int entry_height, int64_t sigchecks, LockPoints lp)
105 : tx{_tx}, nFee{fee}, nTxSize(tx->GetTotalSize()),
107 entryHeight{entry_height}, sigChecks(sigchecks), m_modified_fee{nFee},
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),
118 lockPoints(std::move(other.lockPoints)),
119 refcount(other.refcount.load()){};
120
121 uint64_t GetEntryId() const { return entryId; }
124 void SetEntryId(uint64_t eid) { entryId = eid; }
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; }
130 size_t GetTxVirtualSize() const {
133 }
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; }
141 }
142 size_t DynamicMemoryUsage() const { return nUsageSize; }
143 const LockPoints &GetLockPoints() const { return lockPoints; }
144
145 // Updates the modified fees used for mining priority score
146 void UpdateModifiedFee(Amount fee_diff) {
148 };
149
150 const Parents &GetMemPoolParentsConst() const { return m_parents; }
151 const Children &GetMemPoolChildrenConst() const { return m_children; }
154};
155
156#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...
Definition: mempool_entry.h:65
const CTransactionRef tx
Definition: mempool_entry.h:79
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)
void UpdateModifiedFee(Amount fee_diff)
uint64_t GetEntryId() const
const int64_t nTime
Local time when entering the mempool.
Definition: mempool_entry.h:89
const Amount nFee
Cached to avoid expensive parent-transaction lookups.
Definition: mempool_entry.h:83
const size_t nTxSize
... and avoid recomputing tx size
Definition: mempool_entry.h:85
const size_t nUsageSize
... and total memory usage
Definition: mempool_entry.h:87
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
Definition: mempool_entry.h:73
const Children & GetMemPoolChildrenConst() const
Parents m_parents
Definition: mempool_entry.h:80
size_t GetTxSize() const
CTxMemPoolEntry(const CTxMemPoolEntry &other)=delete
CTxMemPoolEntry(CTxMemPoolEntry &&other)
CTransactionRef GetSharedTx() const
Amount GetModifiedFee() const
const Parents & GetMemPoolParentsConst() const
Amount m_modified_fee
Used for determining the priority of the transaction for mining in a block.
Definition: mempool_entry.h:96
CFeeRate GetModifiedFeeRate() const
size_t DynamicMemoryUsage() const
size_t GetTxVirtualSize() const
Parents & GetMemPoolParents() const
uint64_t entryId
Unique identifier – used for topological sorting.
Definition: mempool_entry.h:77
LockPoints lockPoints
Track the height and time at which tx was final.
Definition: mempool_entry.h:98
Children m_children
Definition: mempool_entry.h:81
const unsigned int entryHeight
Chain height when entering the mempool.
Definition: mempool_entry.h:91
std::set< std::reference_wrapper< const CTxMemPoolEntryRef >, CompareIteratorById > Parents
Definition: mempool_entry.h:70
const int64_t sigChecks
Total sigChecks.
Definition: mempool_entry.h:93
Definition: rcu.h:85
static size_t RecursiveDynamicUsage(const CScript &script)
Definition: core_memusage.h:12
LockPoints lp
Implement std::hash so RCUPtr can be used as a key for maps or sets.
Definition: rcu.h:259
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
Definition: transaction.h:315
Definition: amount.h:23
void SaturatingAdd(const Amount &other) noexcept
Amount addition with integer saturation.
Definition: amount.cpp:57
static constexpr Amount zero() noexcept
Definition: amount.h:36
bool operator()(const std::reference_wrapper< T > &a, const std::reference_wrapper< T > &b) const
Definition: mempool_entry.h:34
bool operator()(const T &a, const T &b) const
Definition: mempool_entry.h:38
Iterate txs in reverse-topological order.
Definition: mempool_entry.h:43
bool operator()(const std::reference_wrapper< T > &a, const std::reference_wrapper< T > &b) const
Definition: mempool_entry.h:45
bool operator()(const T &a, const T &b) const
Definition: mempool_entry.h:50
int64_t time
Definition: mempool_entry.h:27