mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
refactor: Inline CTxMemPoolEntry
class's functions
This commit is contained in:
parent
75bbe594e5
commit
c8dc0e3eaa
4 changed files with 41 additions and 60 deletions
|
@ -426,7 +426,6 @@ libbitcoin_node_a_SOURCES = \
|
|||
torcontrol.cpp \
|
||||
txdb.cpp \
|
||||
txmempool.cpp \
|
||||
txmempool_entry.cpp \
|
||||
txorphanage.cpp \
|
||||
txrequest.cpp \
|
||||
validation.cpp \
|
||||
|
@ -932,7 +931,6 @@ libbitcoinkernel_la_SOURCES = \
|
|||
threadinterrupt.cpp \
|
||||
txdb.cpp \
|
||||
txmempool.cpp \
|
||||
txmempool_entry.cpp \
|
||||
uint256.cpp \
|
||||
util/check.cpp \
|
||||
util/getuniquepath.cpp \
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
// Copyright (c) 2009-2022 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <txmempool_entry.h>
|
||||
|
||||
#include <consensus/amount.h>
|
||||
#include <consensus/validation.h>
|
||||
#include <core_memusage.h>
|
||||
#include <policy/policy.h>
|
||||
#include <policy/settings.h>
|
||||
#include <primitives/transaction.h>
|
||||
#include <util/overflow.h>
|
||||
|
||||
CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee,
|
||||
int64_t time, unsigned int entry_height,
|
||||
bool spends_coinbase, int64_t sigops_cost, LockPoints lp)
|
||||
: tx{tx},
|
||||
nFee{fee},
|
||||
nTxWeight(GetTransactionWeight(*tx)),
|
||||
nUsageSize{RecursiveDynamicUsage(tx)},
|
||||
nTime{time},
|
||||
entryHeight{entry_height},
|
||||
spendsCoinbase{spends_coinbase},
|
||||
sigOpCost{sigops_cost},
|
||||
m_modified_fee{nFee},
|
||||
lockPoints{lp},
|
||||
nSizeWithDescendants{GetTxSize()},
|
||||
nModFeesWithDescendants{nFee},
|
||||
nSizeWithAncestors{GetTxSize()},
|
||||
nModFeesWithAncestors{nFee},
|
||||
nSigOpCostWithAncestors{sigOpCost} {}
|
||||
|
||||
void CTxMemPoolEntry::UpdateModifiedFee(CAmount fee_diff)
|
||||
{
|
||||
nModFeesWithDescendants = SaturatingAdd(nModFeesWithDescendants, fee_diff);
|
||||
nModFeesWithAncestors = SaturatingAdd(nModFeesWithAncestors, fee_diff);
|
||||
m_modified_fee = SaturatingAdd(m_modified_fee, fee_diff);
|
||||
}
|
||||
|
||||
void CTxMemPoolEntry::UpdateLockPoints(const LockPoints& lp)
|
||||
{
|
||||
lockPoints = lp;
|
||||
}
|
||||
|
||||
size_t CTxMemPoolEntry::GetTxSize() const
|
||||
{
|
||||
return GetVirtualTransactionSize(nTxWeight, sigOpCost, ::nBytesPerSigOp);
|
||||
}
|
|
@ -6,8 +6,13 @@
|
|||
#define BITCOIN_TXMEMPOOL_ENTRY_H
|
||||
|
||||
#include <consensus/amount.h>
|
||||
#include <consensus/validation.h>
|
||||
#include <core_memusage.h>
|
||||
#include <policy/policy.h>
|
||||
#include <policy/settings.h>
|
||||
#include <primitives/transaction.h>
|
||||
#include <util/epochguard.h>
|
||||
#include <util/overflow.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
|
@ -77,14 +82,14 @@ private:
|
|||
const bool spendsCoinbase; //!< keep track of transactions that spend a coinbase
|
||||
const int64_t sigOpCost; //!< Total sigop cost
|
||||
CAmount m_modified_fee; //!< 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
|
||||
// mempool; if we remove this transaction we must remove all of these
|
||||
// descendants as well.
|
||||
uint64_t nCountWithDescendants{1}; //!< number of descendant transactions
|
||||
uint64_t nSizeWithDescendants; //!< ... and size
|
||||
CAmount nModFeesWithDescendants; //!< ... and total fees (all including us)
|
||||
uint64_t nSizeWithDescendants; //!< ... and size
|
||||
CAmount nModFeesWithDescendants; //!< ... and total fees (all including us)
|
||||
|
||||
// Analogous statistics for ancestor transactions
|
||||
uint64_t nCountWithAncestors{1};
|
||||
|
@ -96,12 +101,30 @@ public:
|
|||
CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee,
|
||||
int64_t time, unsigned int entry_height,
|
||||
bool spends_coinbase,
|
||||
int64_t sigops_cost, LockPoints lp);
|
||||
int64_t sigops_cost, LockPoints lp)
|
||||
: tx{tx},
|
||||
nFee{fee},
|
||||
nTxWeight(GetTransactionWeight(*tx)),
|
||||
nUsageSize{RecursiveDynamicUsage(tx)},
|
||||
nTime{time},
|
||||
entryHeight{entry_height},
|
||||
spendsCoinbase{spends_coinbase},
|
||||
sigOpCost{sigops_cost},
|
||||
m_modified_fee{nFee},
|
||||
lockPoints{lp},
|
||||
nSizeWithDescendants{GetTxSize()},
|
||||
nModFeesWithDescendants{nFee},
|
||||
nSizeWithAncestors{GetTxSize()},
|
||||
nModFeesWithAncestors{nFee},
|
||||
nSigOpCostWithAncestors{sigOpCost} {}
|
||||
|
||||
const CTransaction& GetTx() const { return *this->tx; }
|
||||
CTransactionRef GetSharedTx() const { return this->tx; }
|
||||
const CAmount& GetFee() const { return nFee; }
|
||||
size_t GetTxSize() const;
|
||||
size_t GetTxSize() const
|
||||
{
|
||||
return GetVirtualTransactionSize(nTxWeight, sigOpCost, ::nBytesPerSigOp);
|
||||
}
|
||||
size_t GetTxWeight() const { return nTxWeight; }
|
||||
std::chrono::seconds GetTime() const { return std::chrono::seconds{nTime}; }
|
||||
unsigned int GetHeight() const { return entryHeight; }
|
||||
|
@ -115,9 +138,18 @@ public:
|
|||
// Adjusts the ancestor state
|
||||
void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int64_t modifySigOps);
|
||||
// Updates the modified fees with descendants/ancestors.
|
||||
void UpdateModifiedFee(CAmount fee_diff);
|
||||
void UpdateModifiedFee(CAmount fee_diff)
|
||||
{
|
||||
nModFeesWithDescendants = SaturatingAdd(nModFeesWithDescendants, fee_diff);
|
||||
nModFeesWithAncestors = SaturatingAdd(nModFeesWithAncestors, fee_diff);
|
||||
m_modified_fee = SaturatingAdd(m_modified_fee, fee_diff);
|
||||
}
|
||||
|
||||
// Update the LockPoints after a reorg
|
||||
void UpdateLockPoints(const LockPoints& lp);
|
||||
void UpdateLockPoints(const LockPoints& lp)
|
||||
{
|
||||
lockPoints = lp;
|
||||
}
|
||||
|
||||
uint64_t GetCountWithDescendants() const { return nCountWithDescendants; }
|
||||
uint64_t GetSizeWithDescendants() const { return nSizeWithDescendants; }
|
||||
|
|
|
@ -53,7 +53,7 @@ unsigned-integer-overflow:policy/fees.cpp
|
|||
unsigned-integer-overflow:prevector.h
|
||||
unsigned-integer-overflow:script/interpreter.cpp
|
||||
unsigned-integer-overflow:txmempool.cpp
|
||||
unsigned-integer-overflow:txmempool_entry.cpp
|
||||
unsigned-integer-overflow:txmempool_entry.h
|
||||
implicit-integer-sign-change:compat/stdin.cpp
|
||||
implicit-integer-sign-change:compressor.h
|
||||
implicit-integer-sign-change:crypto/
|
||||
|
@ -63,7 +63,7 @@ implicit-integer-sign-change:script/bitcoinconsensus.cpp
|
|||
implicit-integer-sign-change:script/interpreter.cpp
|
||||
implicit-integer-sign-change:serialize.h
|
||||
implicit-integer-sign-change:txmempool.cpp
|
||||
implicit-integer-sign-change:txmempool_entry.cpp
|
||||
implicit-integer-sign-change:txmempool_entry.h
|
||||
implicit-signed-integer-truncation:crypto/
|
||||
implicit-unsigned-integer-truncation:crypto/
|
||||
shift-base:arith_uint256.cpp
|
||||
|
|
Loading…
Add table
Reference in a new issue