Skip to content

Commit

Permalink
Merge bitcoin#23054: Use C++11 member initializer in CTxMemPoolEntry
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fanquake authored and vijaydasmp committed Sep 11, 2024
1 parent e981340 commit b9f947a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/test/getarg_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ BOOST_AUTO_TEST_CASE(intarg)

// Check under-/overflow behavior.
ResetArgs("-foo=-9223372036854775809 -bar=9223372036854775808");
BOOST_CHECK_EQUAL(m_local_args.GetIntArg("-foo", 0), std::numeric_limits<int64_t>::min());
BOOST_CHECK_EQUAL(m_local_args.GetIntArg("-bar", 0), std::numeric_limits<int64_t>::max());
BOOST_CHECK_EQUAL(m_local_args.GetArg("-foo", 0), std::numeric_limits<int64_t>::min());
BOOST_CHECK_EQUAL(m_local_args.GetArg("-bar", 0), std::numeric_limits<int64_t>::max());

ResetArgs("-foo=11 -bar=12");
BOOST_CHECK_EQUAL(m_local_args.GetArg("-foo", 0), 11);
Expand Down
34 changes: 17 additions & 17 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@
#include <cmath>
#include <optional>

CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee,
int64_t _nTime, unsigned int _entryHeight,
bool _spendsCoinbase, unsigned int _sigOps, LockPoints lp)
: tx(_tx), nFee(_nFee), nTxSize(tx->GetTotalSize()), nUsageSize(RecursiveDynamicUsage(tx)), nTime(_nTime), entryHeight(_entryHeight),
spendsCoinbase(_spendsCoinbase), sigOpCount(_sigOps), lockPoints(lp)
{
nCountWithDescendants = 1;
nSizeWithDescendants = GetTxSize();
nModFeesWithDescendants = nFee;

feeDelta = 0;

nCountWithAncestors = 1;
nSizeWithAncestors = GetTxSize();
nModFeesWithAncestors = nFee;
nSigOpCountWithAncestors = sigOpCount;
}
CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& tx, const CAmount fee,
int64_t time, unsigned int entry_height,
bool spends_coinbase, unsigned int sigops, LockPoints lp)
: tx{tx},
nFee{fee},
nTxSize(tx->GetTotalSize()),
nUsageSize{RecursiveDynamicUsage(tx)},
nTime{time},
entryHeight{entry_height},
spendsCoinbase{spends_coinbase},
sigOpCount{sigops},
lockPoints{lp},
nSizeWithDescendants{GetTxSize()},
nModFeesWithDescendants{nFee},
nSizeWithAncestors{GetTxSize()},
nModFeesWithAncestors{nFee},
nSigOpCountWithAncestors{sigops} {}

void CTxMemPoolEntry::UpdateFeeDelta(int64_t newFeeDelta)
{
Expand Down
25 changes: 11 additions & 14 deletions src/txmempool.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,16 @@ using CBLSLazyPublicKey = CBLSLazyWrapper<CBLSPublicKey>;
/** Fake height value used in Coin to signify they are only in the memory pool (since 0.8) */
static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;

struct LockPoints
{
struct LockPoints {
// Will be set to the blockchain height and median time past
// values that would be necessary to satisfy all relative locktime
// constraints (BIP68) of this tx given our view of block chain history
int height;
int64_t time;
int height{0};
int64_t time{0};
// As long as the current chain descends from the highest height block
// containing one of the inputs used in the calculation, then the cached
// values are still valid even after a reorg.
CBlockIndex* maxInputBlock;

LockPoints() : height(0), time(0), maxInputBlock(nullptr) { }
CBlockIndex* maxInputBlock{nullptr};
};

struct CompareIteratorByHash {
Expand Down Expand Up @@ -107,27 +104,27 @@ class CTxMemPoolEntry
const unsigned int entryHeight; //!< Chain height when entering the mempool
const bool spendsCoinbase; //!< keep track of transactions that spend a coinbase
const unsigned int sigOpCount; //!< Legacy sig ops plus P2SH sig op count
int64_t feeDelta; //!< Used for determining the priority of the transaction for mining in a block
int64_t feeDelta{0}; //!< Used for determining the priority of the transaction for mining in a block
LockPoints lockPoints; //!< Track the height and time at which tx was final

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

// Analogous statistics for ancestor transactions
uint64_t nCountWithAncestors;
uint64_t nCountWithAncestors{1};
uint64_t nSizeWithAncestors;
CAmount nModFeesWithAncestors;
unsigned int nSigOpCountWithAncestors;

public:
CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee,
int64_t _nTime, unsigned int _entryHeight,
bool spendsCoinbase,
unsigned int nSigOps, LockPoints lp);
CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee,
int64_t time, unsigned int entry_height,
bool spends_coinbase,
unsigned int sigops, LockPoints lp);

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

0 comments on commit b9f947a

Please sign in to comment.