Skip to content

Commit 6043ab4

Browse files
MarcoFalkeapoelstra
authored andcommitted
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. Cherry-pick of fa52cf8 bitcoin/bitcoin#23418 (1/2)
1 parent 99c2ee7 commit 6043ab4

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

src/txmempool.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <policy/policy.h>
1919
#include <policy/settings.h>
2020
#include <reverse_iterator.h>
21+
#include <util/check.h>
2122
#include <util/moneystr.h>
2223
#include <util/system.h>
2324
#include <util/time.h>
@@ -89,6 +90,7 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee,
8990
entryHeight{entry_height},
9091
spendsCoinbase{spends_coinbase},
9192
sigOpCost{sigops_cost},
93+
m_modified_fee{nFee},
9294
lockPoints{lp},
9395
nSizeWithDescendants{GetTxSize()},
9496
nModFeesWithDescendants{nFee},
@@ -98,11 +100,11 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee,
98100
discountSizeWithAncestors{GetDiscountTxSize()},
99101
setPeginsSpent(_setPeginsSpent) {}
100102

101-
void CTxMemPoolEntry::UpdateFeeDelta(CAmount newFeeDelta)
103+
void CTxMemPoolEntry::UpdateModifiedFee(CAmount fee_diff)
102104
{
103-
nModFeesWithDescendants += newFeeDelta - feeDelta;
104-
nModFeesWithAncestors += newFeeDelta - feeDelta;
105-
feeDelta = newFeeDelta;
105+
nModFeesWithDescendants += fee_diff;
106+
nModFeesWithAncestors += fee_diff;
107+
m_modified_fee += fee_diff;
106108
}
107109

108110
void CTxMemPoolEntry::UpdateLockPoints(const LockPoints& lp)
@@ -509,8 +511,10 @@ void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, setEntries &setAnces
509511
// into mapTx.
510512
CAmount delta{0};
511513
ApplyDelta(entry.GetTx().GetHash(), delta);
514+
// The following call to UpdateModifiedFee assumes no previous fee modifications
515+
Assume(entry.GetFee() == entry.GetModifiedFee());
512516
if (delta) {
513-
mapTx.modify(newit, [&delta](CTxMemPoolEntry& e) { e.UpdateFeeDelta(delta); });
517+
mapTx.modify(newit, [&delta](CTxMemPoolEntry& e) { e.UpdateModifiedFee(delta); });
514518
}
515519

516520
// Update cachedInnerUsage to include contained transaction's usage.
@@ -1017,7 +1021,7 @@ void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeD
10171021
delta += nFeeDelta;
10181022
txiter it = mapTx.find(hash);
10191023
if (it != mapTx.end()) {
1020-
mapTx.modify(it, [&delta](CTxMemPoolEntry& e) { e.UpdateFeeDelta(delta); });
1024+
mapTx.modify(it, [&nFeeDelta](CTxMemPoolEntry& e) { e.UpdateModifiedFee(nFeeDelta); });
10211025
// Now update all ancestors' modified fees with descendants
10221026
setEntries setAncestors;
10231027
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
@@ -102,7 +102,7 @@ class CTxMemPoolEntry
102102
const unsigned int entryHeight; //!< Chain height when entering the mempool
103103
const bool spendsCoinbase; //!< keep track of transactions that spend a coinbase
104104
const int64_t sigOpCost; //!< Total sigop cost
105-
CAmount feeDelta{0}; //!< Used for determining the priority of the transaction for mining in a block
105+
CAmount m_modified_fee; //!< Used for determining the priority of the transaction for mining in a block
106106
LockPoints lockPoints; //!< Track the height and time at which tx was final
107107

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

142142
// Adjusts the descendant state.
143143
void UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount);
144144
// Adjusts the ancestor state
145145
void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int64_t modifySigOps, int64_t discountSize);
146-
// Updates the fee delta used for mining priority score, and the
147-
// modified fees with descendants/ancestors.
148-
void UpdateFeeDelta(CAmount newFeeDelta);
146+
// Updates the modified fees with descendants/ancestors.
147+
void UpdateModifiedFee(CAmount fee_diff);
149148
// Update the LockPoints after a reorg
150149
void UpdateLockPoints(const LockPoints& lp);
151150

0 commit comments

Comments
 (0)