mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-02 15:32:34 +02:00
refactor: Replace feeDelta by m_modified_fee
* feeDelta tracked the delta (to be applied on top of the actual fee) * m_modified_fee tracks the actual fee with the delta included * Instead of passing in the new total delta to the Updater, pass in by how much the total delta should be modified. This is needed for the next commit, but makes sense on its own because the same is done by UpdateDescendantState and UpdateAncestorState.
This commit is contained in:
parent
e3b06e8dd8
commit
fa52cf8e11
@ -14,6 +14,7 @@
|
|||||||
#include <policy/policy.h>
|
#include <policy/policy.h>
|
||||||
#include <policy/settings.h>
|
#include <policy/settings.h>
|
||||||
#include <reverse_iterator.h>
|
#include <reverse_iterator.h>
|
||||||
|
#include <util/check.h>
|
||||||
#include <util/moneystr.h>
|
#include <util/moneystr.h>
|
||||||
#include <util/system.h>
|
#include <util/system.h>
|
||||||
#include <util/time.h>
|
#include <util/time.h>
|
||||||
@ -82,6 +83,7 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee,
|
|||||||
entryHeight{entry_height},
|
entryHeight{entry_height},
|
||||||
spendsCoinbase{spends_coinbase},
|
spendsCoinbase{spends_coinbase},
|
||||||
sigOpCost{sigops_cost},
|
sigOpCost{sigops_cost},
|
||||||
|
m_modified_fee{nFee},
|
||||||
lockPoints{lp},
|
lockPoints{lp},
|
||||||
nSizeWithDescendants{GetTxSize()},
|
nSizeWithDescendants{GetTxSize()},
|
||||||
nModFeesWithDescendants{nFee},
|
nModFeesWithDescendants{nFee},
|
||||||
@ -89,11 +91,11 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee,
|
|||||||
nModFeesWithAncestors{nFee},
|
nModFeesWithAncestors{nFee},
|
||||||
nSigOpCostWithAncestors{sigOpCost} {}
|
nSigOpCostWithAncestors{sigOpCost} {}
|
||||||
|
|
||||||
void CTxMemPoolEntry::UpdateFeeDelta(CAmount newFeeDelta)
|
void CTxMemPoolEntry::UpdateModifiedFee(CAmount fee_diff)
|
||||||
{
|
{
|
||||||
nModFeesWithDescendants += newFeeDelta - feeDelta;
|
nModFeesWithDescendants += fee_diff;
|
||||||
nModFeesWithAncestors += newFeeDelta - feeDelta;
|
nModFeesWithAncestors += fee_diff;
|
||||||
feeDelta = newFeeDelta;
|
m_modified_fee += fee_diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTxMemPoolEntry::UpdateLockPoints(const LockPoints& lp)
|
void CTxMemPoolEntry::UpdateLockPoints(const LockPoints& lp)
|
||||||
@ -483,8 +485,10 @@ void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, setEntries &setAnces
|
|||||||
// Update transaction for any feeDelta created by PrioritiseTransaction
|
// Update transaction for any feeDelta created by PrioritiseTransaction
|
||||||
CAmount delta{0};
|
CAmount delta{0};
|
||||||
ApplyDelta(entry.GetTx().GetHash(), delta);
|
ApplyDelta(entry.GetTx().GetHash(), delta);
|
||||||
|
// The following call to UpdateModifiedFee assumes no previous fee modifications
|
||||||
|
Assume(entry.GetFee() == entry.GetModifiedFee());
|
||||||
if (delta) {
|
if (delta) {
|
||||||
mapTx.modify(newit, [&delta](CTxMemPoolEntry& e) { e.UpdateFeeDelta(delta); });
|
mapTx.modify(newit, [&delta](CTxMemPoolEntry& e) { e.UpdateModifiedFee(delta); });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update cachedInnerUsage to include contained transaction's usage.
|
// Update cachedInnerUsage to include contained transaction's usage.
|
||||||
@ -920,7 +924,7 @@ void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeD
|
|||||||
delta += nFeeDelta;
|
delta += nFeeDelta;
|
||||||
txiter it = mapTx.find(hash);
|
txiter it = mapTx.find(hash);
|
||||||
if (it != mapTx.end()) {
|
if (it != mapTx.end()) {
|
||||||
mapTx.modify(it, [&delta](CTxMemPoolEntry& e) { e.UpdateFeeDelta(delta); });
|
mapTx.modify(it, [&nFeeDelta](CTxMemPoolEntry& e) { e.UpdateModifiedFee(nFeeDelta); });
|
||||||
// Now update all ancestors' modified fees with descendants
|
// Now update all ancestors' modified fees with descendants
|
||||||
setEntries setAncestors;
|
setEntries setAncestors;
|
||||||
uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
|
uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
|
||||||
|
@ -101,7 +101,7 @@ private:
|
|||||||
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 int64_t sigOpCost; //!< Total sigop cost
|
const int64_t sigOpCost; //!< Total sigop cost
|
||||||
CAmount feeDelta{0}; //!< Used for determining the priority of the transaction for mining in a block
|
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
|
// Information about descendants of this transaction that are in the
|
||||||
@ -131,7 +131,7 @@ public:
|
|||||||
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; }
|
||||||
int64_t GetSigOpCost() const { return sigOpCost; }
|
int64_t GetSigOpCost() const { return sigOpCost; }
|
||||||
CAmount GetModifiedFee() const { return nFee + feeDelta; }
|
CAmount GetModifiedFee() const { return m_modified_fee; }
|
||||||
size_t DynamicMemoryUsage() const { return nUsageSize; }
|
size_t DynamicMemoryUsage() const { return nUsageSize; }
|
||||||
const LockPoints& GetLockPoints() const { return lockPoints; }
|
const LockPoints& GetLockPoints() const { return lockPoints; }
|
||||||
|
|
||||||
@ -139,9 +139,8 @@ public:
|
|||||||
void UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount);
|
void UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount);
|
||||||
// Adjusts the ancestor state
|
// Adjusts the ancestor state
|
||||||
void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int64_t modifySigOps);
|
void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int64_t modifySigOps);
|
||||||
// Updates the fee delta used for mining priority score, and the
|
// Updates the modified fees with descendants/ancestors.
|
||||||
// modified fees with descendants/ancestors.
|
void UpdateModifiedFee(CAmount fee_diff);
|
||||||
void UpdateFeeDelta(CAmount newFeeDelta);
|
|
||||||
// Update the LockPoints after a reorg
|
// Update the LockPoints after a reorg
|
||||||
void UpdateLockPoints(const LockPoints& lp);
|
void UpdateLockPoints(const LockPoints& lp);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user