18
18
#include < policy/policy.h>
19
19
#include < policy/settings.h>
20
20
#include < reverse_iterator.h>
21
+ #include < util/check.h>
21
22
#include < util/moneystr.h>
23
+ #include < util/overflow.h>
22
24
#include < util/system.h>
23
25
#include < util/time.h>
24
26
#include < validationinterface.h>
@@ -89,6 +91,7 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee,
89
91
entryHeight{entry_height},
90
92
spendsCoinbase{spends_coinbase},
91
93
sigOpCost{sigops_cost},
94
+ m_modified_fee{nFee},
92
95
lockPoints{lp},
93
96
nSizeWithDescendants{GetTxSize ()},
94
97
nModFeesWithDescendants{nFee},
@@ -98,11 +101,11 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee,
98
101
discountSizeWithAncestors{GetDiscountTxSize ()},
99
102
setPeginsSpent (_setPeginsSpent) {}
100
103
101
- void CTxMemPoolEntry::UpdateFeeDelta (CAmount newFeeDelta )
104
+ void CTxMemPoolEntry::UpdateModifiedFee (CAmount fee_diff )
102
105
{
103
- nModFeesWithDescendants += newFeeDelta - feeDelta ;
104
- nModFeesWithAncestors += newFeeDelta - feeDelta ;
105
- feeDelta = newFeeDelta ;
106
+ nModFeesWithDescendants = SaturatingAdd (nModFeesWithDescendants, fee_diff) ;
107
+ nModFeesWithAncestors = SaturatingAdd (nModFeesWithAncestors, fee_diff) ;
108
+ m_modified_fee = SaturatingAdd (m_modified_fee, fee_diff) ;
106
109
}
107
110
108
111
void CTxMemPoolEntry::UpdateLockPoints (const LockPoints& lp)
@@ -457,7 +460,7 @@ void CTxMemPoolEntry::UpdateDescendantState(int64_t modifySize, CAmount modifyFe
457
460
{
458
461
nSizeWithDescendants += modifySize;
459
462
assert (int64_t (nSizeWithDescendants) > 0 );
460
- nModFeesWithDescendants += modifyFee;
463
+ nModFeesWithDescendants = SaturatingAdd (nModFeesWithDescendants, modifyFee) ;
461
464
nCountWithDescendants += modifyCount;
462
465
assert (int64_t (nCountWithDescendants) > 0 );
463
466
}
@@ -466,7 +469,7 @@ void CTxMemPoolEntry::UpdateAncestorState(int64_t modifySize, CAmount modifyFee,
466
469
{
467
470
nSizeWithAncestors += modifySize;
468
471
assert (int64_t (nSizeWithAncestors) > 0 );
469
- nModFeesWithAncestors += modifyFee;
472
+ nModFeesWithAncestors = SaturatingAdd (nModFeesWithAncestors, modifyFee) ;
470
473
nCountWithAncestors += modifyCount;
471
474
assert (int64_t (nCountWithAncestors) > 0 );
472
475
nSigOpCostWithAncestors += modifySigOps;
@@ -509,8 +512,10 @@ void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, setEntries &setAnces
509
512
// into mapTx.
510
513
CAmount delta{0 };
511
514
ApplyDelta (entry.GetTx ().GetHash (), delta);
515
+ // The following call to UpdateModifiedFee assumes no previous fee modifications
516
+ Assume (entry.GetFee () == entry.GetModifiedFee ());
512
517
if (delta) {
513
- mapTx.modify (newit, [&delta](CTxMemPoolEntry& e) { e.UpdateFeeDelta (delta); });
518
+ mapTx.modify (newit, [&delta](CTxMemPoolEntry& e) { e.UpdateModifiedFee (delta); });
514
519
}
515
520
516
521
// Update cachedInnerUsage to include contained transaction's usage.
@@ -1014,10 +1019,10 @@ void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeD
1014
1019
{
1015
1020
LOCK (cs);
1016
1021
CAmount &delta = mapDeltas[hash];
1017
- delta += nFeeDelta;
1022
+ delta = SaturatingAdd (delta, nFeeDelta) ;
1018
1023
txiter it = mapTx.find (hash);
1019
1024
if (it != mapTx.end ()) {
1020
- mapTx.modify (it, [&delta ](CTxMemPoolEntry& e) { e.UpdateFeeDelta (delta ); });
1025
+ mapTx.modify (it, [&nFeeDelta ](CTxMemPoolEntry& e) { e.UpdateModifiedFee (nFeeDelta ); });
1021
1026
// Now update all ancestors' modified fees with descendants
1022
1027
setEntries setAncestors;
1023
1028
uint64_t nNoLimit = std::numeric_limits<uint64_t >::max ();
0 commit comments