Skip to content

Commit 5558d2f

Browse files
author
MacroFake
committed
Merge bitcoin/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/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/bitcoin@1b348d2 Tree-SHA512: b664425b395e39ecf1cfc1e731200378261cf58c3985075fdc6027731a5caf995de72ea25be99b4c0dbec2e3ee6cf940e7c577638844619c66c8494ead5da459
2 parents 2e34374 + 1b348d2 commit 5558d2f

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
@@ -24,38 +24,6 @@
2424
#include <cmath>
2525
#include <optional>
2626

27-
// Helpers for modifying CTxMemPool::mapTx, which is a boost multi_index.
28-
struct update_descendant_state
29-
{
30-
update_descendant_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount) :
31-
modifySize(_modifySize), modifyFee(_modifyFee), modifyCount(_modifyCount)
32-
{}
33-
34-
void operator() (CTxMemPoolEntry &e)
35-
{ e.UpdateDescendantState(modifySize, modifyFee, modifyCount); }
36-
37-
private:
38-
int64_t modifySize;
39-
CAmount modifyFee;
40-
int64_t modifyCount;
41-
};
42-
43-
struct update_ancestor_state
44-
{
45-
update_ancestor_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount, int64_t _modifySigOpsCost) :
46-
modifySize(_modifySize), modifyFee(_modifyFee), modifyCount(_modifyCount), modifySigOpsCost(_modifySigOpsCost)
47-
{}
48-
49-
void operator() (CTxMemPoolEntry &e)
50-
{ e.UpdateAncestorState(modifySize, modifyFee, modifyCount, modifySigOpsCost); }
51-
52-
private:
53-
int64_t modifySize;
54-
CAmount modifyFee;
55-
int64_t modifyCount;
56-
int64_t modifySigOpsCost;
57-
};
58-
5927
bool TestLockPointValidity(CChain& active_chain, const LockPoints& lp)
6028
{
6129
AssertLockHeld(cs_main);
@@ -146,7 +114,9 @@ void CTxMemPool::UpdateForDescendants(txiter updateIt, cacheMap& cachedDescendan
146114
modifyCount++;
147115
cachedDescendants[updateIt].insert(mapTx.iterator_to(descendant));
148116
// Update ancestor state for each descendant
149-
mapTx.modify(mapTx.iterator_to(descendant), update_ancestor_state(updateIt->GetTxSize(), updateIt->GetModifiedFee(), 1, updateIt->GetSigOpCost()));
117+
mapTx.modify(mapTx.iterator_to(descendant), [=](CTxMemPoolEntry& e) {
118+
e.UpdateAncestorState(updateIt->GetTxSize(), updateIt->GetModifiedFee(), 1, updateIt->GetSigOpCost());
119+
});
150120
// Don't directly remove the transaction here -- doing so would
151121
// invalidate iterators in cachedDescendants. Mark it for removal
152122
// by inserting into descendants_to_remove.
@@ -155,7 +125,7 @@ void CTxMemPool::UpdateForDescendants(txiter updateIt, cacheMap& cachedDescendan
155125
}
156126
}
157127
}
158-
mapTx.modify(updateIt, update_descendant_state(modifySize, modifyFee, modifyCount));
128+
mapTx.modify(updateIt, [=](CTxMemPoolEntry& e) { e.UpdateDescendantState(modifySize, modifyFee, modifyCount); });
159129
}
160130

161131
void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256>& vHashesToUpdate)
@@ -347,7 +317,7 @@ void CTxMemPool::UpdateAncestorsOf(bool add, txiter it, setEntries &setAncestors
347317
const int64_t updateSize = updateCount * it->GetTxSize();
348318
const CAmount updateFee = updateCount * it->GetModifiedFee();
349319
for (txiter ancestorIt : setAncestors) {
350-
mapTx.modify(ancestorIt, update_descendant_state(updateSize, updateFee, updateCount));
320+
mapTx.modify(ancestorIt, [=](CTxMemPoolEntry& e) { e.UpdateDescendantState(updateSize, updateFee, updateCount); });
351321
}
352322
}
353323

@@ -362,7 +332,7 @@ void CTxMemPool::UpdateEntryForAncestors(txiter it, const setEntries &setAncesto
362332
updateFee += ancestorIt->GetModifiedFee();
363333
updateSigOpsCost += ancestorIt->GetSigOpCost();
364334
}
365-
mapTx.modify(it, update_ancestor_state(updateSize, updateFee, updateCount, updateSigOpsCost));
335+
mapTx.modify(it, [=](CTxMemPoolEntry& e){ e.UpdateAncestorState(updateSize, updateFee, updateCount, updateSigOpsCost); });
366336
}
367337

368338
void CTxMemPool::UpdateChildrenForRemoval(txiter it)
@@ -393,7 +363,7 @@ void CTxMemPool::UpdateForRemoveFromMempool(const setEntries &entriesToRemove, b
393363
CAmount modifyFee = -removeIt->GetModifiedFee();
394364
int modifySigOps = -removeIt->GetSigOpCost();
395365
for (txiter dit : setDescendants) {
396-
mapTx.modify(dit, update_ancestor_state(modifySize, modifyFee, -1, modifySigOps));
366+
mapTx.modify(dit, [=](CTxMemPoolEntry& e){ e.UpdateAncestorState(modifySize, modifyFee, -1, modifySigOps); });
397367
}
398368
}
399369
}
@@ -942,14 +912,14 @@ void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeD
942912
std::string dummy;
943913
CalculateMemPoolAncestors(*it, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy, false);
944914
for (txiter ancestorIt : setAncestors) {
945-
mapTx.modify(ancestorIt, update_descendant_state(0, nFeeDelta, 0));
915+
mapTx.modify(ancestorIt, [=](CTxMemPoolEntry& e){ e.UpdateDescendantState(0, nFeeDelta, 0);});
946916
}
947917
// Now update all descendants' modified fees with ancestors
948918
setEntries setDescendants;
949919
CalculateDescendants(it, setDescendants);
950920
setDescendants.erase(it);
951921
for (txiter descendantIt : setDescendants) {
952-
mapTx.modify(descendantIt, update_ancestor_state(0, nFeeDelta, 0, 0));
922+
mapTx.modify(descendantIt, [=](CTxMemPoolEntry& e){ e.UpdateAncestorState(0, nFeeDelta, 0, 0); });
953923
}
954924
++nTransactionsUpdated;
955925
}

0 commit comments

Comments
 (0)