31
31
#include < cmath>
32
32
#include < optional>
33
33
34
- // Helpers for modifying CTxMemPool::mapTx, which is a boost multi_index.
35
- struct update_descendant_state
36
- {
37
- update_descendant_state (int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount) :
38
- modifySize (_modifySize), modifyFee(_modifyFee), modifyCount(_modifyCount)
39
- {}
40
-
41
- void operator () (CTxMemPoolEntry &e)
42
- { e.UpdateDescendantState (modifySize, modifyFee, modifyCount); }
43
-
44
- private:
45
- int64_t modifySize;
46
- CAmount modifyFee;
47
- int64_t modifyCount;
48
- };
49
-
50
- struct update_ancestor_state
51
- {
52
- update_ancestor_state (int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount, int64_t _modifySigOpsCost) :
53
- modifySize (_modifySize), modifyFee(_modifyFee), modifyCount(_modifyCount), modifySigOpsCost(_modifySigOpsCost)
54
- {}
55
-
56
- void operator () (CTxMemPoolEntry &e)
57
- { e.UpdateAncestorState (modifySize, modifyFee, modifyCount, modifySigOpsCost); }
58
-
59
- private:
60
- int64_t modifySize;
61
- CAmount modifyFee;
62
- int64_t modifyCount;
63
- int64_t modifySigOpsCost;
64
- };
65
-
66
34
struct update_fee_delta
67
35
{
68
36
explicit update_fee_delta (int64_t _feeDelta) : feeDelta(_feeDelta) { }
@@ -164,7 +132,9 @@ void CTxMemPool::UpdateForDescendants(txiter updateIt, cacheMap& cachedDescendan
164
132
modifyCount++;
165
133
cachedDescendants[updateIt].insert (mapTx.iterator_to (descendant));
166
134
// Update ancestor state for each descendant
167
- mapTx.modify (mapTx.iterator_to (descendant), update_ancestor_state (updateIt->GetTxSize (), updateIt->GetModifiedFee (), 1 , updateIt->GetSigOpCount ()));
135
+ mapTx.modify (mapTx.iterator_to (descendant), [=](CTxMemPoolEntry& e) {
136
+ e.UpdateAncestorState (updateIt->GetTxSize (), updateIt->GetModifiedFee (), 1 , updateIt->GetSigOpCount ());
137
+ });
168
138
// Don't directly remove the transaction here -- doing so would
169
139
// invalidate iterators in cachedDescendants. Mark it for removal
170
140
// by inserting into descendants_to_remove.
@@ -173,7 +143,7 @@ void CTxMemPool::UpdateForDescendants(txiter updateIt, cacheMap& cachedDescendan
173
143
}
174
144
}
175
145
}
176
- mapTx.modify (updateIt, update_descendant_state ( modifySize, modifyFee, modifyCount));
146
+ mapTx.modify (updateIt, [=](CTxMemPoolEntry& e) { e. UpdateDescendantState ( modifySize, modifyFee, modifyCount); } );
177
147
}
178
148
179
149
void CTxMemPool::UpdateTransactionsFromBlock (const std::vector<uint256> &vHashesToUpdate, uint64_t ancestor_size_limit, uint64_t ancestor_count_limit)
@@ -365,7 +335,7 @@ void CTxMemPool::UpdateAncestorsOf(bool add, txiter it, setEntries &setAncestors
365
335
const int64_t updateSize = updateCount * it->GetTxSize ();
366
336
const CAmount updateFee = updateCount * it->GetModifiedFee ();
367
337
for (txiter ancestorIt : setAncestors) {
368
- mapTx.modify (ancestorIt, update_descendant_state ( updateSize, updateFee, updateCount));
338
+ mapTx.modify (ancestorIt, [=](CTxMemPoolEntry& e) { e. UpdateDescendantState ( updateSize, updateFee, updateCount); } );
369
339
}
370
340
}
371
341
@@ -380,7 +350,7 @@ void CTxMemPool::UpdateEntryForAncestors(txiter it, const setEntries &setAncesto
380
350
updateFee += ancestorIt->GetModifiedFee ();
381
351
updateSigOps += ancestorIt->GetSigOpCount ();
382
352
}
383
- mapTx.modify (it, update_ancestor_state ( updateSize, updateFee, updateCount, updateSigOps));
353
+ mapTx.modify (it, [=](CTxMemPoolEntry& e){ e. UpdateAncestorState ( updateSize, updateFee, updateCount, updateSigOps); } );
384
354
}
385
355
386
356
void CTxMemPool::UpdateChildrenForRemoval (txiter it)
@@ -411,7 +381,7 @@ void CTxMemPool::UpdateForRemoveFromMempool(const setEntries &entriesToRemove, b
411
381
CAmount modifyFee = -removeIt->GetModifiedFee ();
412
382
int modifySigOps = -removeIt->GetSigOpCount ();
413
383
for (txiter dit : setDescendants) {
414
- mapTx.modify (dit, update_ancestor_state ( modifySize, modifyFee, -1 , modifySigOps));
384
+ mapTx.modify (dit, [=](CTxMemPoolEntry& e){ e. UpdateAncestorState ( modifySize, modifyFee, -1 , modifySigOps); } );
415
385
}
416
386
}
417
387
}
@@ -1472,14 +1442,14 @@ void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeD
1472
1442
std::string dummy;
1473
1443
CalculateMemPoolAncestors (*it, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy, false );
1474
1444
for (txiter ancestorIt : setAncestors) {
1475
- mapTx.modify (ancestorIt, update_descendant_state ( 0 , nFeeDelta, 0 ));
1445
+ mapTx.modify (ancestorIt, [=](CTxMemPoolEntry& e){ e. UpdateDescendantState ( 0 , nFeeDelta, 0 );} );
1476
1446
}
1477
1447
// Now update all descendants' modified fees with ancestors
1478
1448
setEntries setDescendants;
1479
1449
CalculateDescendants (it, setDescendants);
1480
1450
setDescendants.erase (it);
1481
1451
for (txiter descendantIt : setDescendants) {
1482
- mapTx.modify (descendantIt, update_ancestor_state ( 0 , nFeeDelta, 0 , 0 ));
1452
+ mapTx.modify (descendantIt, [=](CTxMemPoolEntry& e){ e. UpdateAncestorState ( 0 , nFeeDelta, 0 , 0 ); } );
1483
1453
}
1484
1454
++nTransactionsUpdated;
1485
1455
}
0 commit comments