6
6
#define BITCOIN_TXMEMPOOL_ENTRY_H
7
7
8
8
#include < consensus/amount.h>
9
+ #include < consensus/validation.h>
10
+ #include < core_memusage.h>
11
+ #include < policy/policy.h>
12
+ #include < policy/settings.h>
9
13
#include < primitives/transaction.h>
10
14
#include < util/epochguard.h>
15
+ #include < util/overflow.h>
11
16
12
17
#include < chrono>
13
18
#include < functional>
@@ -77,14 +82,14 @@ class CTxMemPoolEntry
77
82
const bool spendsCoinbase; // !< keep track of transactions that spend a coinbase
78
83
const int64_t sigOpCost; // !< Total sigop cost
79
84
CAmount m_modified_fee; // !< Used for determining the priority of the transaction for mining in a block
80
- LockPoints lockPoints; // !< Track the height and time at which tx was final
85
+ LockPoints lockPoints; // !< Track the height and time at which tx was final
81
86
82
87
// Information about descendants of this transaction that are in the
83
88
// mempool; if we remove this transaction we must remove all of these
84
89
// descendants as well.
85
90
uint64_t nCountWithDescendants{1 }; // !< number of descendant transactions
86
- uint64_t nSizeWithDescendants; // !< ... and size
87
- CAmount nModFeesWithDescendants; // !< ... and total fees (all including us)
91
+ uint64_t nSizeWithDescendants; // !< ... and size
92
+ CAmount nModFeesWithDescendants; // !< ... and total fees (all including us)
88
93
89
94
// Analogous statistics for ancestor transactions
90
95
uint64_t nCountWithAncestors{1 };
@@ -96,12 +101,30 @@ class CTxMemPoolEntry
96
101
CTxMemPoolEntry (const CTransactionRef& tx, CAmount fee,
97
102
int64_t time, unsigned int entry_height,
98
103
bool spends_coinbase,
99
- int64_t sigops_cost, LockPoints lp);
104
+ int64_t sigops_cost, LockPoints lp)
105
+ : tx{tx},
106
+ nFee{fee},
107
+ nTxWeight (GetTransactionWeight(*tx)),
108
+ nUsageSize{RecursiveDynamicUsage (tx)},
109
+ nTime{time},
110
+ entryHeight{entry_height},
111
+ spendsCoinbase{spends_coinbase},
112
+ sigOpCost{sigops_cost},
113
+ m_modified_fee{nFee},
114
+ lockPoints{lp},
115
+ nSizeWithDescendants{GetTxSize ()},
116
+ nModFeesWithDescendants{nFee},
117
+ nSizeWithAncestors{GetTxSize ()},
118
+ nModFeesWithAncestors{nFee},
119
+ nSigOpCostWithAncestors{sigOpCost} {}
100
120
101
121
const CTransaction& GetTx () const { return *this ->tx ; }
102
122
CTransactionRef GetSharedTx () const { return this ->tx ; }
103
123
const CAmount& GetFee () const { return nFee; }
104
- size_t GetTxSize () const ;
124
+ size_t GetTxSize () const
125
+ {
126
+ return GetVirtualTransactionSize (nTxWeight, sigOpCost, ::nBytesPerSigOp);
127
+ }
105
128
size_t GetTxWeight () const { return nTxWeight; }
106
129
std::chrono::seconds GetTime () const { return std::chrono::seconds{nTime}; }
107
130
unsigned int GetHeight () const { return entryHeight; }
@@ -115,9 +138,18 @@ class CTxMemPoolEntry
115
138
// Adjusts the ancestor state
116
139
void UpdateAncestorState (int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int64_t modifySigOps);
117
140
// Updates the modified fees with descendants/ancestors.
118
- void UpdateModifiedFee (CAmount fee_diff);
141
+ void UpdateModifiedFee (CAmount fee_diff)
142
+ {
143
+ nModFeesWithDescendants = SaturatingAdd (nModFeesWithDescendants, fee_diff);
144
+ nModFeesWithAncestors = SaturatingAdd (nModFeesWithAncestors, fee_diff);
145
+ m_modified_fee = SaturatingAdd (m_modified_fee, fee_diff);
146
+ }
147
+
119
148
// Update the LockPoints after a reorg
120
- void UpdateLockPoints (const LockPoints& lp);
149
+ void UpdateLockPoints (const LockPoints& lp)
150
+ {
151
+ lockPoints = lp;
152
+ }
121
153
122
154
uint64_t GetCountWithDescendants () const { return nCountWithDescendants; }
123
155
uint64_t GetSizeWithDescendants () const { return nSizeWithDescendants; }
0 commit comments