Skip to content

Commit c8dc0e3

Browse files
committed
refactor: Inline CTxMemPoolEntry class's functions
1 parent 75bbe59 commit c8dc0e3

File tree

4 files changed

+41
-60
lines changed

4 files changed

+41
-60
lines changed

src/Makefile.am

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,6 @@ libbitcoin_node_a_SOURCES = \
426426
torcontrol.cpp \
427427
txdb.cpp \
428428
txmempool.cpp \
429-
txmempool_entry.cpp \
430429
txorphanage.cpp \
431430
txrequest.cpp \
432431
validation.cpp \
@@ -932,7 +931,6 @@ libbitcoinkernel_la_SOURCES = \
932931
threadinterrupt.cpp \
933932
txdb.cpp \
934933
txmempool.cpp \
935-
txmempool_entry.cpp \
936934
uint256.cpp \
937935
util/check.cpp \
938936
util/getuniquepath.cpp \

src/txmempool_entry.cpp

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/txmempool_entry.h

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66
#define BITCOIN_TXMEMPOOL_ENTRY_H
77

88
#include <consensus/amount.h>
9+
#include <consensus/validation.h>
10+
#include <core_memusage.h>
11+
#include <policy/policy.h>
12+
#include <policy/settings.h>
913
#include <primitives/transaction.h>
1014
#include <util/epochguard.h>
15+
#include <util/overflow.h>
1116

1217
#include <chrono>
1318
#include <functional>
@@ -77,14 +82,14 @@ class CTxMemPoolEntry
7782
const bool spendsCoinbase; //!< keep track of transactions that spend a coinbase
7883
const int64_t sigOpCost; //!< Total sigop cost
7984
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
8186

8287
// Information about descendants of this transaction that are in the
8388
// mempool; if we remove this transaction we must remove all of these
8489
// descendants as well.
8590
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)
8893

8994
// Analogous statistics for ancestor transactions
9095
uint64_t nCountWithAncestors{1};
@@ -96,12 +101,30 @@ class CTxMemPoolEntry
96101
CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee,
97102
int64_t time, unsigned int entry_height,
98103
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} {}
100120

101121
const CTransaction& GetTx() const { return *this->tx; }
102122
CTransactionRef GetSharedTx() const { return this->tx; }
103123
const CAmount& GetFee() const { return nFee; }
104-
size_t GetTxSize() const;
124+
size_t GetTxSize() const
125+
{
126+
return GetVirtualTransactionSize(nTxWeight, sigOpCost, ::nBytesPerSigOp);
127+
}
105128
size_t GetTxWeight() const { return nTxWeight; }
106129
std::chrono::seconds GetTime() const { return std::chrono::seconds{nTime}; }
107130
unsigned int GetHeight() const { return entryHeight; }
@@ -115,9 +138,18 @@ class CTxMemPoolEntry
115138
// Adjusts the ancestor state
116139
void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int64_t modifySigOps);
117140
// 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+
119148
// Update the LockPoints after a reorg
120-
void UpdateLockPoints(const LockPoints& lp);
149+
void UpdateLockPoints(const LockPoints& lp)
150+
{
151+
lockPoints = lp;
152+
}
121153

122154
uint64_t GetCountWithDescendants() const { return nCountWithDescendants; }
123155
uint64_t GetSizeWithDescendants() const { return nSizeWithDescendants; }

test/sanitizer_suppressions/ubsan

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ unsigned-integer-overflow:policy/fees.cpp
5353
unsigned-integer-overflow:prevector.h
5454
unsigned-integer-overflow:script/interpreter.cpp
5555
unsigned-integer-overflow:txmempool.cpp
56-
unsigned-integer-overflow:txmempool_entry.cpp
56+
unsigned-integer-overflow:txmempool_entry.h
5757
implicit-integer-sign-change:compat/stdin.cpp
5858
implicit-integer-sign-change:compressor.h
5959
implicit-integer-sign-change:crypto/
@@ -63,7 +63,7 @@ implicit-integer-sign-change:script/bitcoinconsensus.cpp
6363
implicit-integer-sign-change:script/interpreter.cpp
6464
implicit-integer-sign-change:serialize.h
6565
implicit-integer-sign-change:txmempool.cpp
66-
implicit-integer-sign-change:txmempool_entry.cpp
66+
implicit-integer-sign-change:txmempool_entry.h
6767
implicit-signed-integer-truncation:crypto/
6868
implicit-unsigned-integer-truncation:crypto/
6969
shift-base:arith_uint256.cpp

0 commit comments

Comments
 (0)