Skip to content

Commit 068f155

Browse files
MacroFakevijaydasmp
MacroFake
authored andcommitted
Merge bitcoin#26048: mempool clean up: replace update_* structs with lambdas
1b348d2 [mempool] replace update_descendant_state with lambda (glozow) Pull request description: These were introduced in commit bitcoin@5add7a7, when the codebase was pre-C++11. We can use lambdas now. ACKs for top commit: MarcoFalke: review ACK 1b348d2 👮 w0xlt: ACK bitcoin@1b348d2 Tree-SHA512: b664425b395e39ecf1cfc1e731200378261cf58c3985075fdc6027731a5caf995de72ea25be99b4c0dbec2e3ee6cf940e7c577638844619c66c8494ead5da459
1 parent 6f99c30 commit 068f155

File tree

1 file changed

+9
-39
lines changed

1 file changed

+9
-39
lines changed

src/txmempool.cpp

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

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-
6634
struct update_fee_delta
6735
{
6836
explicit update_fee_delta(int64_t _feeDelta) : feeDelta(_feeDelta) { }
@@ -164,7 +132,9 @@ void CTxMemPool::UpdateForDescendants(txiter updateIt, cacheMap& cachedDescendan
164132
modifyCount++;
165133
cachedDescendants[updateIt].insert(mapTx.iterator_to(descendant));
166134
// 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+
});
168138
// Don't directly remove the transaction here -- doing so would
169139
// invalidate iterators in cachedDescendants. Mark it for removal
170140
// by inserting into descendants_to_remove.
@@ -173,7 +143,7 @@ void CTxMemPool::UpdateForDescendants(txiter updateIt, cacheMap& cachedDescendan
173143
}
174144
}
175145
}
176-
mapTx.modify(updateIt, update_descendant_state(modifySize, modifyFee, modifyCount));
146+
mapTx.modify(updateIt, [=](CTxMemPoolEntry& e) { e.UpdateDescendantState(modifySize, modifyFee, modifyCount); });
177147
}
178148

179149
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
365335
const int64_t updateSize = updateCount * it->GetTxSize();
366336
const CAmount updateFee = updateCount * it->GetModifiedFee();
367337
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); });
369339
}
370340
}
371341

@@ -380,7 +350,7 @@ void CTxMemPool::UpdateEntryForAncestors(txiter it, const setEntries &setAncesto
380350
updateFee += ancestorIt->GetModifiedFee();
381351
updateSigOps += ancestorIt->GetSigOpCount();
382352
}
383-
mapTx.modify(it, update_ancestor_state(updateSize, updateFee, updateCount, updateSigOps));
353+
mapTx.modify(it, [=](CTxMemPoolEntry& e){ e.UpdateAncestorState(updateSize, updateFee, updateCount, updateSigOps); });
384354
}
385355

386356
void CTxMemPool::UpdateChildrenForRemoval(txiter it)
@@ -411,7 +381,7 @@ void CTxMemPool::UpdateForRemoveFromMempool(const setEntries &entriesToRemove, b
411381
CAmount modifyFee = -removeIt->GetModifiedFee();
412382
int modifySigOps = -removeIt->GetSigOpCount();
413383
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); });
415385
}
416386
}
417387
}
@@ -1472,14 +1442,14 @@ void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeD
14721442
std::string dummy;
14731443
CalculateMemPoolAncestors(*it, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy, false);
14741444
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);});
14761446
}
14771447
// Now update all descendants' modified fees with ancestors
14781448
setEntries setDescendants;
14791449
CalculateDescendants(it, setDescendants);
14801450
setDescendants.erase(it);
14811451
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); });
14831453
}
14841454
++nTransactionsUpdated;
14851455
}

0 commit comments

Comments
 (0)