@@ -33,7 +33,7 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTransaction& _tx, const CAmount& _nFee,
3333
3434 nCountWithDescendants = 1 ;
3535 nSizeWithDescendants = nTxSize;
36- nFeesWithDescendants = nFee;
36+ nModFeesWithDescendants = nFee;
3737 CAmount nValueIn = tx.GetValueOut ()+nFee;
3838 assert (inChainInputValue <= nValueIn);
3939
@@ -57,6 +57,7 @@ CTxMemPoolEntry::GetPriority(unsigned int currentHeight) const
5757
5858void CTxMemPoolEntry::UpdateFeeDelta (int64_t newFeeDelta)
5959{
60+ nModFeesWithDescendants += newFeeDelta - feeDelta;
6061 feeDelta = newFeeDelta;
6162}
6263
@@ -114,7 +115,7 @@ bool CTxMemPool::UpdateForDescendants(txiter updateIt, int maxDescendantsToVisit
114115 BOOST_FOREACH (txiter cit, setAllDescendants) {
115116 if (!setExclude.count (cit->GetTx ().GetHash ())) {
116117 modifySize += cit->GetTxSize ();
117- modifyFee += cit->GetFee ();
118+ modifyFee += cit->GetModifiedFee ();
118119 modifyCount++;
119120 cachedDescendants[updateIt].insert (cit);
120121 }
@@ -244,7 +245,7 @@ void CTxMemPool::UpdateAncestorsOf(bool add, txiter it, setEntries &setAncestors
244245 }
245246 const int64_t updateCount = (add ? 1 : -1 );
246247 const int64_t updateSize = updateCount * it->GetTxSize ();
247- const CAmount updateFee = updateCount * it->GetFee ();
248+ const CAmount updateFee = updateCount * it->GetModifiedFee ();
248249 BOOST_FOREACH (txiter ancestorIt, setAncestors) {
249250 mapTx.modify (ancestorIt, update_descendant_state (updateSize, updateFee, updateCount));
250251 }
@@ -304,16 +305,15 @@ void CTxMemPoolEntry::SetDirty()
304305{
305306 nCountWithDescendants = 0 ;
306307 nSizeWithDescendants = nTxSize;
307- nFeesWithDescendants = nFee ;
308+ nModFeesWithDescendants = GetModifiedFee () ;
308309}
309310
310311void CTxMemPoolEntry::UpdateState (int64_t modifySize, CAmount modifyFee, int64_t modifyCount)
311312{
312313 if (!IsDirty ()) {
313314 nSizeWithDescendants += modifySize;
314315 assert (int64_t (nSizeWithDescendants) > 0 );
315- nFeesWithDescendants += modifyFee;
316- assert (nFeesWithDescendants >= 0 );
316+ nModFeesWithDescendants += modifyFee;
317317 nCountWithDescendants += modifyCount;
318318 assert (int64_t (nCountWithDescendants) > 0 );
319319 }
@@ -372,6 +372,17 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry,
372372 indexed_transaction_set::iterator newit = mapTx.insert (entry).first ;
373373 mapLinks.insert (make_pair (newit, TxLinks ()));
374374
375+ // Update transaction for any feeDelta created by PrioritiseTransaction
376+ // TODO: refactor so that the fee delta is calculated before inserting
377+ // into mapTx.
378+ std::map<uint256, std::pair<double , CAmount> >::const_iterator pos = mapDeltas.find (hash);
379+ if (pos != mapDeltas.end ()) {
380+ const std::pair<double , CAmount> &deltas = pos->second ;
381+ if (deltas.second ) {
382+ mapTx.modify (newit, update_fee_delta (deltas.second ));
383+ }
384+ }
385+
375386 // Update cachedInnerUsage to include contained transaction's usage.
376387 // (When we update the entry for in-mempool parents, memory usage will be
377388 // further updated.)
@@ -399,15 +410,6 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry,
399410 }
400411 UpdateAncestorsOf (true , newit, setAncestors);
401412
402- // Update transaction's score for any feeDelta created by PrioritiseTransaction
403- std::map<uint256, std::pair<double , CAmount> >::const_iterator pos = mapDeltas.find (hash);
404- if (pos != mapDeltas.end ()) {
405- const std::pair<double , CAmount> &deltas = pos->second ;
406- if (deltas.second ) {
407- mapTx.modify (newit, update_fee_delta (deltas.second ));
408- }
409- }
410-
411413 nTransactionsUpdated++;
412414 totalTxSize += entry.GetTxSize ();
413415 minerPolicyEstimator->processTransaction (entry, fCurrentEstimate );
@@ -644,27 +646,24 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
644646 CTxMemPool::setEntries setChildrenCheck;
645647 std::map<COutPoint, CInPoint>::const_iterator iter = mapNextTx.lower_bound (COutPoint (it->GetTx ().GetHash (), 0 ));
646648 int64_t childSizes = 0 ;
647- CAmount childFees = 0 ;
649+ CAmount childModFee = 0 ;
648650 for (; iter != mapNextTx.end () && iter->first .hash == it->GetTx ().GetHash (); ++iter) {
649651 txiter childit = mapTx.find (iter->second .ptx ->GetHash ());
650652 assert (childit != mapTx.end ()); // mapNextTx points to in-mempool transactions
651653 if (setChildrenCheck.insert (childit).second ) {
652654 childSizes += childit->GetTxSize ();
653- childFees += childit->GetFee ();
655+ childModFee += childit->GetModifiedFee ();
654656 }
655657 }
656658 assert (setChildrenCheck == GetMemPoolChildren (it));
657- // Also check to make sure size/fees is greater than sum with immediate children.
659+ // Also check to make sure size is greater than sum with immediate children.
658660 // just a sanity check, not definitive that this calc is correct...
659- // also check that the size is less than the size of the entire mempool.
660661 if (!it->IsDirty ()) {
661662 assert (it->GetSizeWithDescendants () >= childSizes + it->GetTxSize ());
662- assert (it->GetFeesWithDescendants () >= childFees + it->GetFee ());
663663 } else {
664664 assert (it->GetSizeWithDescendants () == it->GetTxSize ());
665- assert (it->GetFeesWithDescendants () == it->GetFee ());
665+ assert (it->GetModFeesWithDescendants () == it->GetModifiedFee ());
666666 }
667- assert (it->GetFeesWithDescendants () >= 0 );
668667
669668 if (fDependsWait )
670669 waitingOnDependants.push_back (&(*it));
@@ -788,6 +787,14 @@ void CTxMemPool::PrioritiseTransaction(const uint256 hash, const string strHash,
788787 txiter it = mapTx.find (hash);
789788 if (it != mapTx.end ()) {
790789 mapTx.modify (it, update_fee_delta (deltas.second ));
790+ // Now update all ancestors' modified fees with descendants
791+ setEntries setAncestors;
792+ uint64_t nNoLimit = std::numeric_limits<uint64_t >::max ();
793+ std::string dummy;
794+ CalculateMemPoolAncestors (*it, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy, false );
795+ BOOST_FOREACH (txiter ancestorIt, setAncestors) {
796+ mapTx.modify (ancestorIt, update_descendant_state (0 , nFeeDelta, 0 ));
797+ }
791798 }
792799 }
793800 LogPrintf (" PrioritiseTransaction: %s priority += %f, fee += %d\n " , strHash, dPriorityDelta, FormatMoney (nFeeDelta));
@@ -956,7 +963,7 @@ void CTxMemPool::TrimToSize(size_t sizelimit, std::vector<uint256>* pvNoSpendsRe
956963 // "minimum reasonable fee rate" (ie some value under which we consider txn
957964 // to have 0 fee). This way, we don't allow txn to enter mempool with feerate
958965 // equal to txn which were removed with no block in between.
959- CFeeRate removed (it->GetFeesWithDescendants (), it->GetSizeWithDescendants ());
966+ CFeeRate removed (it->GetModFeesWithDescendants (), it->GetSizeWithDescendants ());
960967 removed += minReasonableRelayFee;
961968 trackPackageRemoved (removed);
962969 maxFeeRateRemoved = std::max (maxFeeRateRemoved, removed);
0 commit comments