merge bitcoin#23054: Use C++11 member initializer in CTxMemPoolEntry

This commit is contained in:
Kittywhiskers Van Gogh 2024-09-08 16:08:41 +00:00
parent d158063b6d
commit 22e59fb464
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD
2 changed files with 33 additions and 36 deletions

View File

@ -29,23 +29,23 @@
#include <cmath> #include <cmath>
#include <optional> #include <optional>
CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee, CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee,
int64_t _nTime, unsigned int _entryHeight, int64_t time, unsigned int entry_height,
bool _spendsCoinbase, unsigned int _sigOps, LockPoints lp) bool spends_coinbase, int64_t sigops_count, LockPoints lp)
: tx(_tx), nFee(_nFee), nTxSize(tx->GetTotalSize()), nUsageSize(RecursiveDynamicUsage(tx)), nTime(_nTime), entryHeight(_entryHeight), : tx{tx},
spendsCoinbase(_spendsCoinbase), sigOpCount(_sigOps), lockPoints(lp) nFee{fee},
{ nTxSize(tx->GetTotalSize()),
nCountWithDescendants = 1; nUsageSize{RecursiveDynamicUsage(tx)},
nSizeWithDescendants = GetTxSize(); nTime{time},
nModFeesWithDescendants = nFee; entryHeight{entry_height},
spendsCoinbase{spends_coinbase},
feeDelta = 0; sigOpCount{sigops_count},
lockPoints{lp},
nCountWithAncestors = 1; nSizeWithDescendants{GetTxSize()},
nSizeWithAncestors = GetTxSize(); nModFeesWithDescendants{nFee},
nModFeesWithAncestors = nFee; nSizeWithAncestors{GetTxSize()},
nSigOpCountWithAncestors = sigOpCount; nModFeesWithAncestors{nFee},
} nSigOpCountWithAncestors{sigOpCount} {}
void CTxMemPoolEntry::UpdateFeeDelta(int64_t newFeeDelta) void CTxMemPoolEntry::UpdateFeeDelta(int64_t newFeeDelta)
{ {

View File

@ -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) */ /** 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; static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
struct LockPoints struct LockPoints {
{
// Will be set to the blockchain height and median time past // Will be set to the blockchain height and median time past
// values that would be necessary to satisfy all relative locktime // values that would be necessary to satisfy all relative locktime
// constraints (BIP68) of this tx given our view of block chain history // constraints (BIP68) of this tx given our view of block chain history
int height; int height{0};
int64_t time; int64_t time{0};
// As long as the current chain descends from the highest height block // As long as the current chain descends from the highest height block
// containing one of the inputs used in the calculation, then the cached // containing one of the inputs used in the calculation, then the cached
// values are still valid even after a reorg. // values are still valid even after a reorg.
CBlockIndex* maxInputBlock; CBlockIndex* maxInputBlock{nullptr};
LockPoints() : height(0), time(0), maxInputBlock(nullptr) { }
}; };
struct CompareIteratorByHash { struct CompareIteratorByHash {
@ -106,28 +103,28 @@ private:
const int64_t nTime; //!< Local time when entering the mempool const int64_t nTime; //!< Local time when entering the mempool
const unsigned int entryHeight; //!< Chain height when entering the mempool const unsigned int entryHeight; //!< Chain height when entering the mempool
const bool spendsCoinbase; //!< keep track of transactions that spend a coinbase const bool spendsCoinbase; //!< keep track of transactions that spend a coinbase
const unsigned int sigOpCount; //!< Legacy sig ops plus P2SH sig op count const int64_t 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 LockPoints lockPoints; //!< Track the height and time at which tx was final
// Information about descendants of this transaction that are in the // Information about descendants of this transaction that are in the
// mempool; if we remove this transaction we must remove all of these // mempool; if we remove this transaction we must remove all of these
// descendants as well. // descendants as well.
uint64_t nCountWithDescendants; //!< number of descendant transactions uint64_t nCountWithDescendants{1}; //!< number of descendant transactions
uint64_t nSizeWithDescendants; //!< ... and size uint64_t nSizeWithDescendants; //!< ... and size
CAmount nModFeesWithDescendants; //!< ... and total fees (all including us) CAmount nModFeesWithDescendants; //!< ... and total fees (all including us)
// Analogous statistics for ancestor transactions // Analogous statistics for ancestor transactions
uint64_t nCountWithAncestors; uint64_t nCountWithAncestors{1};
uint64_t nSizeWithAncestors; uint64_t nSizeWithAncestors;
CAmount nModFeesWithAncestors; CAmount nModFeesWithAncestors;
unsigned int nSigOpCountWithAncestors; int64_t nSigOpCountWithAncestors;
public: public:
CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee, CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee,
int64_t _nTime, unsigned int _entryHeight, int64_t time, unsigned int entry_height,
bool spendsCoinbase, bool spends_coinbase,
unsigned int nSigOps, LockPoints lp); int64_t sigops_count, LockPoints lp);
const CTransaction& GetTx() const { return *this->tx; } const CTransaction& GetTx() const { return *this->tx; }
CTransactionRef GetSharedTx() const { return this->tx; } CTransactionRef GetSharedTx() const { return this->tx; }
@ -135,7 +132,7 @@ public:
size_t GetTxSize() const; size_t GetTxSize() const;
std::chrono::seconds GetTime() const { return std::chrono::seconds{nTime}; } std::chrono::seconds GetTime() const { return std::chrono::seconds{nTime}; }
unsigned int GetHeight() const { return entryHeight; } unsigned int GetHeight() const { return entryHeight; }
unsigned int GetSigOpCount() const { return sigOpCount; } int64_t GetSigOpCount() const { return sigOpCount; }
int64_t GetModifiedFee() const { return nFee + feeDelta; } int64_t GetModifiedFee() const { return nFee + feeDelta; }
size_t DynamicMemoryUsage() const { return nUsageSize; } size_t DynamicMemoryUsage() const { return nUsageSize; }
const LockPoints& GetLockPoints() const { return lockPoints; } const LockPoints& GetLockPoints() const { return lockPoints; }
@ -159,7 +156,7 @@ public:
uint64_t GetCountWithAncestors() const { return nCountWithAncestors; } uint64_t GetCountWithAncestors() const { return nCountWithAncestors; }
uint64_t GetSizeWithAncestors() const { return nSizeWithAncestors; } uint64_t GetSizeWithAncestors() const { return nSizeWithAncestors; }
CAmount GetModFeesWithAncestors() const { return nModFeesWithAncestors; } CAmount GetModFeesWithAncestors() const { return nModFeesWithAncestors; }
unsigned int GetSigOpCountWithAncestors() const { return nSigOpCountWithAncestors; } int64_t GetSigOpCountWithAncestors() const { return nSigOpCountWithAncestors; }
const Parents& GetMemPoolParentsConst() const { return m_parents; } const Parents& GetMemPoolParentsConst() const { return m_parents; }
const Children& GetMemPoolChildrenConst() const { return m_children; } const Children& GetMemPoolChildrenConst() const { return m_children; }