-
Notifications
You must be signed in to change notification settings - Fork 35.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mempool clean up: replace update_* structs with lambdas #26048
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -24,38 +24,6 @@ | |||||
#include <cmath> | ||||||
#include <optional> | ||||||
|
||||||
// Helpers for modifying CTxMemPool::mapTx, which is a boost multi_index. | ||||||
struct update_descendant_state | ||||||
{ | ||||||
update_descendant_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount) : | ||||||
modifySize(_modifySize), modifyFee(_modifyFee), modifyCount(_modifyCount) | ||||||
{} | ||||||
|
||||||
void operator() (CTxMemPoolEntry &e) | ||||||
{ e.UpdateDescendantState(modifySize, modifyFee, modifyCount); } | ||||||
|
||||||
private: | ||||||
int64_t modifySize; | ||||||
CAmount modifyFee; | ||||||
int64_t modifyCount; | ||||||
}; | ||||||
|
||||||
struct update_ancestor_state | ||||||
{ | ||||||
update_ancestor_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount, int64_t _modifySigOpsCost) : | ||||||
modifySize(_modifySize), modifyFee(_modifyFee), modifyCount(_modifyCount), modifySigOpsCost(_modifySigOpsCost) | ||||||
{} | ||||||
|
||||||
void operator() (CTxMemPoolEntry &e) | ||||||
{ e.UpdateAncestorState(modifySize, modifyFee, modifyCount, modifySigOpsCost); } | ||||||
|
||||||
private: | ||||||
int64_t modifySize; | ||||||
CAmount modifyFee; | ||||||
int64_t modifyCount; | ||||||
int64_t modifySigOpsCost; | ||||||
}; | ||||||
|
||||||
bool TestLockPointValidity(CChain& active_chain, const LockPoints& lp) | ||||||
{ | ||||||
AssertLockHeld(cs_main); | ||||||
|
@@ -146,7 +114,9 @@ void CTxMemPool::UpdateForDescendants(txiter updateIt, cacheMap& cachedDescendan | |||||
modifyCount++; | ||||||
cachedDescendants[updateIt].insert(mapTx.iterator_to(descendant)); | ||||||
// Update ancestor state for each descendant | ||||||
mapTx.modify(mapTx.iterator_to(descendant), update_ancestor_state(updateIt->GetTxSize(), updateIt->GetModifiedFee(), 1, updateIt->GetSigOpCost())); | ||||||
mapTx.modify(mapTx.iterator_to(descendant), [=](CTxMemPoolEntry& e) { | ||||||
e.UpdateAncestorState(updateIt->GetTxSize(), updateIt->GetModifiedFee(), 1, updateIt->GetSigOpCost()); | ||||||
}); | ||||||
// Don't directly remove the transaction here -- doing so would | ||||||
// invalidate iterators in cachedDescendants. Mark it for removal | ||||||
// by inserting into descendants_to_remove. | ||||||
|
@@ -155,7 +125,7 @@ void CTxMemPool::UpdateForDescendants(txiter updateIt, cacheMap& cachedDescendan | |||||
} | ||||||
} | ||||||
} | ||||||
mapTx.modify(updateIt, update_descendant_state(modifySize, modifyFee, modifyCount)); | ||||||
mapTx.modify(updateIt, [=](CTxMemPoolEntry& e) { e.UpdateDescendantState(modifySize, modifyFee, modifyCount); }); | ||||||
} | ||||||
|
||||||
void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256>& vHashesToUpdate) | ||||||
|
@@ -347,7 +317,7 @@ void CTxMemPool::UpdateAncestorsOf(bool add, txiter it, setEntries &setAncestors | |||||
const int64_t updateSize = updateCount * it->GetTxSize(); | ||||||
const CAmount updateFee = updateCount * it->GetModifiedFee(); | ||||||
for (txiter ancestorIt : setAncestors) { | ||||||
mapTx.modify(ancestorIt, update_descendant_state(updateSize, updateFee, updateCount)); | ||||||
mapTx.modify(ancestorIt, [=](CTxMemPoolEntry& e) { e.UpdateDescendantState(updateSize, updateFee, updateCount); }); | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -362,7 +332,7 @@ void CTxMemPool::UpdateEntryForAncestors(txiter it, const setEntries &setAncesto | |||||
updateFee += ancestorIt->GetModifiedFee(); | ||||||
updateSigOpsCost += ancestorIt->GetSigOpCost(); | ||||||
} | ||||||
mapTx.modify(it, update_ancestor_state(updateSize, updateFee, updateCount, updateSigOpsCost)); | ||||||
mapTx.modify(it, [=](CTxMemPoolEntry& e){ e.UpdateAncestorState(updateSize, updateFee, updateCount, updateSigOpsCost); }); | ||||||
} | ||||||
|
||||||
void CTxMemPool::UpdateChildrenForRemoval(txiter it) | ||||||
|
@@ -393,7 +363,7 @@ void CTxMemPool::UpdateForRemoveFromMempool(const setEntries &entriesToRemove, b | |||||
CAmount modifyFee = -removeIt->GetModifiedFee(); | ||||||
int modifySigOps = -removeIt->GetSigOpCost(); | ||||||
for (txiter dit : setDescendants) { | ||||||
mapTx.modify(dit, update_ancestor_state(modifySize, modifyFee, -1, modifySigOps)); | ||||||
mapTx.modify(dit, [=](CTxMemPoolEntry& e){ e.UpdateAncestorState(modifySize, modifyFee, -1, modifySigOps); }); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
} | ||||||
} | ||||||
|
@@ -942,14 +912,14 @@ void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeD | |||||
std::string dummy; | ||||||
CalculateMemPoolAncestors(*it, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy, false); | ||||||
for (txiter ancestorIt : setAncestors) { | ||||||
mapTx.modify(ancestorIt, update_descendant_state(0, nFeeDelta, 0)); | ||||||
mapTx.modify(ancestorIt, [=](CTxMemPoolEntry& e){ e.UpdateDescendantState(0, nFeeDelta, 0);}); | ||||||
} | ||||||
// Now update all descendants' modified fees with ancestors | ||||||
setEntries setDescendants; | ||||||
CalculateDescendants(it, setDescendants); | ||||||
setDescendants.erase(it); | ||||||
for (txiter descendantIt : setDescendants) { | ||||||
mapTx.modify(descendantIt, update_ancestor_state(0, nFeeDelta, 0, 0)); | ||||||
mapTx.modify(descendantIt, [=](CTxMemPoolEntry& e){ e.UpdateAncestorState(0, nFeeDelta, 0, 0); }); | ||||||
} | ||||||
++nTransactionsUpdated; | ||||||
} | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.