Skip to content

Commit fa52cf8

Browse files
author
MarcoFalke
committed
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.
1 parent e3b06e8 commit fa52cf8

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/txmempool.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <policy/policy.h>
1515
#include <policy/settings.h>
1616
#include <reverse_iterator.h>
17+
#include <util/check.h>
1718
#include <util/moneystr.h>
1819
#include <util/system.h>
1920
#include <util/time.h>
@@ -82,18 +83,19 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee,
8283
entryHeight{entry_height},
8384
spendsCoinbase{spends_coinbase},
8485
sigOpCost{sigops_cost},
86+
m_modified_fee{nFee},
8587
lockPoints{lp},
8688
nSizeWithDescendants{GetTxSize()},
8789
nModFeesWithDescendants{nFee},
8890
nSizeWithAncestors{GetTxSize()},
8991
nModFeesWithAncestors{nFee},
9092
nSigOpCostWithAncestors{sigOpCost} {}
9193

92-
void CTxMemPoolEntry::UpdateFeeDelta(CAmount newFeeDelta)
94+
void CTxMemPoolEntry::UpdateModifiedFee(CAmount fee_diff)
9395
{
94-
nModFeesWithDescendants += newFeeDelta - feeDelta;
95-
nModFeesWithAncestors += newFeeDelta - feeDelta;
96-
feeDelta = newFeeDelta;
96+
nModFeesWithDescendants += fee_diff;
97+
nModFeesWithAncestors += fee_diff;
98+
m_modified_fee += fee_diff;
9799
}
98100

99101
void CTxMemPoolEntry::UpdateLockPoints(const LockPoints& lp)
@@ -483,8 +485,10 @@ void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, setEntries &setAnces
483485
// Update transaction for any feeDelta created by PrioritiseTransaction
484486
CAmount delta{0};
485487
ApplyDelta(entry.GetTx().GetHash(), delta);
488+
// The following call to UpdateModifiedFee assumes no previous fee modifications
489+
Assume(entry.GetFee() == entry.GetModifiedFee());
486490
if (delta) {
487-
mapTx.modify(newit, [&delta](CTxMemPoolEntry& e) { e.UpdateFeeDelta(delta); });
491+
mapTx.modify(newit, [&delta](CTxMemPoolEntry& e) { e.UpdateModifiedFee(delta); });
488492
}
489493

490494
// Update cachedInnerUsage to include contained transaction's usage.
@@ -920,7 +924,7 @@ void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeD
920924
delta += nFeeDelta;
921925
txiter it = mapTx.find(hash);
922926
if (it != mapTx.end()) {
923-
mapTx.modify(it, [&delta](CTxMemPoolEntry& e) { e.UpdateFeeDelta(delta); });
927+
mapTx.modify(it, [&nFeeDelta](CTxMemPoolEntry& e) { e.UpdateModifiedFee(nFeeDelta); });
924928
// Now update all ancestors' modified fees with descendants
925929
setEntries setAncestors;
926930
uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();

src/txmempool.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class CTxMemPoolEntry
101101
const unsigned int entryHeight; //!< Chain height when entering the mempool
102102
const bool spendsCoinbase; //!< keep track of transactions that spend a coinbase
103103
const int64_t sigOpCost; //!< Total sigop cost
104-
CAmount feeDelta{0}; //!< Used for determining the priority of the transaction for mining in a block
104+
CAmount m_modified_fee; //!< Used for determining the priority of the transaction for mining in a block
105105
LockPoints lockPoints; //!< Track the height and time at which tx was final
106106

107107
// Information about descendants of this transaction that are in the
@@ -131,17 +131,16 @@ class CTxMemPoolEntry
131131
std::chrono::seconds GetTime() const { return std::chrono::seconds{nTime}; }
132132
unsigned int GetHeight() const { return entryHeight; }
133133
int64_t GetSigOpCost() const { return sigOpCost; }
134-
CAmount GetModifiedFee() const { return nFee + feeDelta; }
134+
CAmount GetModifiedFee() const { return m_modified_fee; }
135135
size_t DynamicMemoryUsage() const { return nUsageSize; }
136136
const LockPoints& GetLockPoints() const { return lockPoints; }
137137

138138
// Adjusts the descendant state.
139139
void UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount);
140140
// Adjusts the ancestor state
141141
void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int64_t modifySigOps);
142-
// Updates the fee delta used for mining priority score, and the
143-
// modified fees with descendants/ancestors.
144-
void UpdateFeeDelta(CAmount newFeeDelta);
142+
// Updates the modified fees with descendants/ancestors.
143+
void UpdateModifiedFee(CAmount fee_diff);
145144
// Update the LockPoints after a reorg
146145
void UpdateLockPoints(const LockPoints& lp);
147146

0 commit comments

Comments
 (0)