Skip to content

Commit 3120bce

Browse files
committed
Merge bitcoin/bitcoin#23054: Use C++11 member initializer in CTxMemPoolEntry
fa08d4c Use C++11 member initializer in CTxMemPoolEntry (MarcoFalke) Pull request description: This removes a bunch of boilerplate, makes the code easier to read. Also, C++11 member initialization avoids accidental uninitialized members. Can be reviewed with the git option "--word-diff-regex=." or with "git difftool --tool=meld". ACKs for top commit: jnewbery: Code review ACK fa08d4c shaavan: Code Review ACK fa08d4c Tree-SHA512: 2424861002fbcef2a3f01845662c115b973a7a5103f359305b5d9237c055eb003aa7646fc1cb30e6eaf90810d662f94cedc6f90795e30b56680f9c81f631d64b
2 parents faecb2e + fa08d4c commit 3120bce

File tree

2 files changed

+28
-31
lines changed

2 files changed

+28
-31
lines changed

src/txmempool.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,23 @@
2121
#include <cmath>
2222
#include <optional>
2323

24-
CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee,
25-
int64_t _nTime, unsigned int _entryHeight,
26-
bool _spendsCoinbase, int64_t _sigOpsCost, LockPoints lp)
27-
: tx(_tx), nFee(_nFee), nTxWeight(GetTransactionWeight(*tx)), nUsageSize(RecursiveDynamicUsage(tx)), nTime(_nTime), entryHeight(_entryHeight),
28-
spendsCoinbase(_spendsCoinbase), sigOpCost(_sigOpsCost), lockPoints(lp)
29-
{
30-
nCountWithDescendants = 1;
31-
nSizeWithDescendants = GetTxSize();
32-
nModFeesWithDescendants = nFee;
33-
34-
feeDelta = 0;
35-
36-
nCountWithAncestors = 1;
37-
nSizeWithAncestors = GetTxSize();
38-
nModFeesWithAncestors = nFee;
39-
nSigOpCostWithAncestors = sigOpCost;
40-
}
24+
CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee,
25+
int64_t time, unsigned int entry_height,
26+
bool spends_coinbase, int64_t sigops_cost, LockPoints lp)
27+
: tx{tx},
28+
nFee{fee},
29+
nTxWeight(GetTransactionWeight(*tx)),
30+
nUsageSize{RecursiveDynamicUsage(tx)},
31+
nTime{time},
32+
entryHeight{entry_height},
33+
spendsCoinbase{spends_coinbase},
34+
sigOpCost{sigops_cost},
35+
lockPoints{lp},
36+
nSizeWithDescendants{GetTxSize()},
37+
nModFeesWithDescendants{nFee},
38+
nSizeWithAncestors{GetTxSize()},
39+
nModFeesWithAncestors{nFee},
40+
nSigOpCostWithAncestors{sigOpCost} {}
4141

4242
void CTxMemPoolEntry::UpdateFeeDelta(int64_t newFeeDelta)
4343
{

src/txmempool.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,16 @@ extern RecursiveMutex cs_main;
3737
/** Fake height value used in Coin to signify they are only in the memory pool (since 0.8) */
3838
static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
3939

40-
struct LockPoints
41-
{
40+
struct LockPoints {
4241
// Will be set to the blockchain height and median time past
4342
// values that would be necessary to satisfy all relative locktime
4443
// constraints (BIP68) of this tx given our view of block chain history
45-
int height;
46-
int64_t time;
44+
int height{0};
45+
int64_t time{0};
4746
// As long as the current chain descends from the highest height block
4847
// containing one of the inputs used in the calculation, then the cached
4948
// values are still valid even after a reorg.
50-
CBlockIndex* maxInputBlock;
51-
52-
LockPoints() : height(0), time(0), maxInputBlock(nullptr) { }
49+
CBlockIndex* maxInputBlock{nullptr};
5350
};
5451

5552
struct CompareIteratorByHash {
@@ -98,27 +95,27 @@ class CTxMemPoolEntry
9895
const unsigned int entryHeight; //!< Chain height when entering the mempool
9996
const bool spendsCoinbase; //!< keep track of transactions that spend a coinbase
10097
const int64_t sigOpCost; //!< Total sigop cost
101-
int64_t feeDelta; //!< Used for determining the priority of the transaction for mining in a block
98+
int64_t feeDelta{0}; //!< Used for determining the priority of the transaction for mining in a block
10299
LockPoints lockPoints; //!< Track the height and time at which tx was final
103100

104101
// Information about descendants of this transaction that are in the
105102
// mempool; if we remove this transaction we must remove all of these
106103
// descendants as well.
107-
uint64_t nCountWithDescendants; //!< number of descendant transactions
104+
uint64_t nCountWithDescendants{1}; //!< number of descendant transactions
108105
uint64_t nSizeWithDescendants; //!< ... and size
109106
CAmount nModFeesWithDescendants; //!< ... and total fees (all including us)
110107

111108
// Analogous statistics for ancestor transactions
112-
uint64_t nCountWithAncestors;
109+
uint64_t nCountWithAncestors{1};
113110
uint64_t nSizeWithAncestors;
114111
CAmount nModFeesWithAncestors;
115112
int64_t nSigOpCostWithAncestors;
116113

117114
public:
118-
CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee,
119-
int64_t _nTime, unsigned int _entryHeight,
120-
bool spendsCoinbase,
121-
int64_t nSigOpsCost, LockPoints lp);
115+
CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee,
116+
int64_t time, unsigned int entry_height,
117+
bool spends_coinbase,
118+
int64_t sigops_cost, LockPoints lp);
122119

123120
const CTransaction& GetTx() const { return *this->tx; }
124121
CTransactionRef GetSharedTx() const { return this->tx; }

0 commit comments

Comments
 (0)