Skip to content

Commit 4630c54

Browse files
committed
merge bitcoin#24625: Replace struct update_fee_delta with lambda
1 parent 1573a82 commit 4630c54

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

src/node/miner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct CTxMemPoolModifiedEntry {
6464
nSigOpCountWithAncestors = entry->GetSigOpCountWithAncestors();
6565
}
6666

67-
int64_t GetModifiedFee() const { return iter->GetModifiedFee(); }
67+
CAmount GetModifiedFee() const { return iter->GetModifiedFee(); }
6868
uint64_t GetSizeWithAncestors() const { return nSizeWithAncestors; }
6969
CAmount GetModFeesWithAncestors() const { return nModFeesWithAncestors; }
7070
size_t GetTxSize() const { return iter->GetTxSize(); }

src/txmempool.cpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@
3131
#include <optional>
3232
#include <ranges>
3333

34-
struct update_fee_delta
35-
{
36-
explicit update_fee_delta(int64_t _feeDelta) : feeDelta(_feeDelta) { }
37-
38-
void operator() (CTxMemPoolEntry &e) { e.UpdateModifiedFee(feeDelta); }
39-
40-
private:
41-
int64_t feeDelta;
42-
};
43-
4434
bool TestLockPointValidity(CChain& active_chain, const LockPoints& lp)
4535
{
4636
AssertLockHeld(cs_main);
@@ -77,11 +67,11 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee,
7767
nModFeesWithAncestors{nFee},
7868
nSigOpCountWithAncestors{sigOpCount} {}
7969

80-
void CTxMemPoolEntry::UpdateModifiedFee(int64_t fee_diff)
70+
void CTxMemPoolEntry::UpdateModifiedFee(CAmount newFeeDelta)
8171
{
82-
nModFeesWithDescendants = SaturatingAdd(nModFeesWithDescendants, fee_diff);
83-
nModFeesWithAncestors = SaturatingAdd(nModFeesWithAncestors, fee_diff);
84-
m_modified_fee = SaturatingAdd(m_modified_fee, fee_diff);
72+
nModFeesWithDescendants = SaturatingAdd(nModFeesWithDescendants, newFeeDelta);
73+
nModFeesWithAncestors = SaturatingAdd(nModFeesWithAncestors, newFeeDelta);
74+
m_modified_fee = SaturatingAdd(m_modified_fee, newFeeDelta);
8575
}
8676

8777
void CTxMemPoolEntry::UpdateLockPoints(const LockPoints& lp)
@@ -485,7 +475,7 @@ void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, setEntries &setAnces
485475
// The following call to UpdateModifiedFee assumes no previous fee modifications
486476
Assume(entry.GetFee() == entry.GetModifiedFee());
487477
if (delta) {
488-
mapTx.modify(newit, update_fee_delta(delta));
478+
mapTx.modify(newit, [&delta](CTxMemPoolEntry& e) { e.UpdateModifiedFee(delta); });
489479
}
490480

491481
// Update cachedInnerUsage to include contained transaction's usage.
@@ -1449,7 +1439,7 @@ void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeD
14491439
delta = SaturatingAdd(delta, nFeeDelta);
14501440
txiter it = mapTx.find(hash);
14511441
if (it != mapTx.end()) {
1452-
mapTx.modify(it, update_fee_delta(nFeeDelta));
1442+
mapTx.modify(it, [&nFeeDelta](CTxMemPoolEntry& e) { e.UpdateModifiedFee(nFeeDelta); });
14531443
// Now update all ancestors' modified fees with descendants
14541444
setEntries setAncestors;
14551445
uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();

src/txmempool.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class CTxMemPoolEntry
114114
const unsigned int entryHeight; //!< Chain height when entering the mempool
115115
const bool spendsCoinbase; //!< keep track of transactions that spend a coinbase
116116
const int64_t sigOpCount; //!< Legacy sig ops plus P2SH sig op count
117-
int64_t m_modified_fee; //!< Used for determining the priority of the transaction for mining in a block
117+
CAmount m_modified_fee; //!< Used for determining the priority of the transaction for mining in a block
118118
LockPoints lockPoints; //!< Track the height and time at which tx was final
119119

120120
// Information about descendants of this transaction that are in the
@@ -143,7 +143,7 @@ class CTxMemPoolEntry
143143
std::chrono::seconds GetTime() const { return std::chrono::seconds{nTime}; }
144144
unsigned int GetHeight() const { return entryHeight; }
145145
int64_t GetSigOpCount() const { return sigOpCount; }
146-
int64_t GetModifiedFee() const { return m_modified_fee; }
146+
CAmount GetModifiedFee() const { return m_modified_fee; }
147147
size_t DynamicMemoryUsage() const { return nUsageSize; }
148148
const LockPoints& GetLockPoints() const { return lockPoints; }
149149

@@ -152,7 +152,7 @@ class CTxMemPoolEntry
152152
// Adjusts the ancestor state
153153
void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int64_t modifySigOps);
154154
// Updates the modified fees with descendants/ancestors.
155-
void UpdateModifiedFee(int64_t fee_diff);
155+
void UpdateModifiedFee(CAmount newFeeDelta);
156156
// Update the LockPoints after a reorg
157157
void UpdateLockPoints(const LockPoints& lp);
158158

0 commit comments

Comments
 (0)