-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Mempool cleanups #12225
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 cleanups #12225
Conversation
utACK 16a8389 |
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.
What is usually bigger?
CTxMemPool::mapTx
CBlockPolicyEstimator::mapMemPoolTxs
My suggestion is to loop the shorter map.
src/policy/fees.cpp
Outdated
@@ -984,10 +984,9 @@ bool CBlockPolicyEstimator::Read(CAutoFile& filein) | |||
void CBlockPolicyEstimator::FlushUnconfirmed(CTxMemPool& pool) { | |||
int64_t startclear = GetTimeMicros(); | |||
std::vector<uint256> txids; |
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.
Remove?
src/policy/fees.cpp
Outdated
for (auto& txid : txids) { | ||
removeTx(txid, false); | ||
LOCK2(pool.cs, cs_feeEstimator); | ||
for (auto mi=pool.mapTx.begin(); mi != pool.mapTx.end(); ++mi) { |
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.
Nit, can early exit loop if mapMemPoolTxs
is empty.
src/policy/fees.cpp
Outdated
removeTx(txid, false); | ||
LOCK2(pool.cs, cs_feeEstimator); | ||
for (auto mi=pool.mapTx.begin(); mi != pool.mapTx.end(); ++mi) { | ||
removeTx(mi->GetTx().GetHash(), false); | ||
} | ||
int64_t endclear = GetTimeMicros(); | ||
LogPrint(BCLog::ESTIMATEFEE, "Recorded %u unconfirmed txs from mempool in %gs\n",txids.size(), (endclear - startclear)*0.000001); |
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.
txids
is empty, update logging.
@promag After further investigation, it looks like FlushUnconfirmed() doesn't need the mempool at all, so I re-wrote it a bit. |
// Remove every entry in mapMemPoolTxs | ||
while (!mapMemPoolTxs.empty()) { | ||
auto mi = mapMemPoolTxs.begin(); | ||
removeTx(mi->first, false); // this calls erase() on mapMemPoolTxs |
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.
IMO decreasing one by one is avoidable when the end result is to be empty. Prefer something like?
LOCK(cs_feeEstimator);
size_t num_entries = mapMemPoolTxs.size();
for (const auto& it = mapMemPoolTxs.begin(); it != mapMemPoolTxs.end(); ++it) {
const auto& stat = it->second;
feeStats->removeTx(stat.blockHeight, nBestSeenHeight, stat.bucketIndex, false);
shortStats->removeTx(stat.blockHeight, nBestSeenHeight, stat.bucketIndex, false);
longStats->removeTx(stat.blockHeight, nBestSeenHeight, stat.bucketIndex, false);
}
mapMemPoolTxs.clear();
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.
I didn't want to duplicate the code in removeTx()
or figure out how to refactor it to be more efficient for this purpose -- since FlushUnconfirmed()
is only called in shutdown, I don't think the performance savings here from more code changes is worth the review/maintenance burden.
If you'd rather see a bigger refactor here to clean things up, I think I'd prefer to just remove this commit and someone can take it on in a new PR...
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.
I think it's fine as it is. I'll take note to measure an alternative implementation.
src/txmempool.h
Outdated
@@ -242,14 +242,17 @@ class CompareTxMemPoolEntryByDescendantScore | |||
/** \class CompareTxMemPoolEntryByScore | |||
* | |||
* Sort by score of entry ((fee+delta)/size) in descending order |
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.
Remove +delta
?
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.
Fixed!
466267d
to
669c943
Compare
utACK 669c943. |
utACK 669c943 |
669c943 Avoid leaking prioritization information when relaying transactions (Suhas Daftuar) e868b22 fee estimator: avoid sorting mempool on shutdown (Suhas Daftuar) 0975406 Correct mempool mapTx comment (Suhas Daftuar) Pull request description: Following up on #12127 and #12118, this cleans up a comment that was left incorrect in txmempool.h, and addresses a couple of the observations @TheBlueMatt made about an unnecessary use of `queryHashes()` and a small information leak when prioritizing transactions. Left undone is nuking queryHashes altogether; that would require changing the behavior of the `getrawmempool` rpc call, which I think I might be in favor of doing, but wanted to save for its own PR. Tree-SHA512: c97d10b96dcd6520459287a4a2eda92774173757695100fcfe61e526aef86f394507c331d17f9e0c14b496c33ec46198a0f165a847762ca50f7c6780b993f162
Summary: 669c943 Avoid leaking prioritization information when relaying transactions (Suhas Daftuar) 0975406 Correct mempool mapTx comment (Suhas Daftuar) Pull request description: Following up on #12127 and #12118, this cleans up a comment that was left incorrect in txmempool.h, and addresses a couple of the observations @TheBlueMatt made about an unnecessary use of `queryHashes()` and a small information leak when prioritizing transactions. Left undone is nuking queryHashes altogether; that would require changing the behavior of the `getrawmempool` rpc call, which I think I might be in favor of doing, but wanted to save for its own PR. Tree-SHA512: c97d10b96dcd6520459287a4a2eda92774173757695100fcfe61e526aef86f394507c331d17f9e0c14b496c33ec46198a0f165a847762ca50f7c6780b993f162 Backport of Core PR12225 bitcoin/bitcoin#12225 Depends on D3711 Test Plan: make check test_runner.py Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc Reviewed By: deadalnix, O1 Bitcoin ABC, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D3789
669c943 Avoid leaking prioritization information when relaying transactions (Suhas Daftuar) e868b22 fee estimator: avoid sorting mempool on shutdown (Suhas Daftuar) 0975406 Correct mempool mapTx comment (Suhas Daftuar) Pull request description: Following up on bitcoin#12127 and bitcoin#12118, this cleans up a comment that was left incorrect in txmempool.h, and addresses a couple of the observations @TheBlueMatt made about an unnecessary use of `queryHashes()` and a small information leak when prioritizing transactions. Left undone is nuking queryHashes altogether; that would require changing the behavior of the `getrawmempool` rpc call, which I think I might be in favor of doing, but wanted to save for its own PR. Tree-SHA512: c97d10b96dcd6520459287a4a2eda92774173757695100fcfe61e526aef86f394507c331d17f9e0c14b496c33ec46198a0f165a847762ca50f7c6780b993f162
669c943 Avoid leaking prioritization information when relaying transactions (Suhas Daftuar) e868b22 fee estimator: avoid sorting mempool on shutdown (Suhas Daftuar) 0975406 Correct mempool mapTx comment (Suhas Daftuar) Pull request description: Following up on bitcoin#12127 and bitcoin#12118, this cleans up a comment that was left incorrect in txmempool.h, and addresses a couple of the observations @TheBlueMatt made about an unnecessary use of `queryHashes()` and a small information leak when prioritizing transactions. Left undone is nuking queryHashes altogether; that would require changing the behavior of the `getrawmempool` rpc call, which I think I might be in favor of doing, but wanted to save for its own PR. Tree-SHA512: c97d10b96dcd6520459287a4a2eda92774173757695100fcfe61e526aef86f394507c331d17f9e0c14b496c33ec46198a0f165a847762ca50f7c6780b993f162
669c943 Avoid leaking prioritization information when relaying transactions (Suhas Daftuar) e868b22 fee estimator: avoid sorting mempool on shutdown (Suhas Daftuar) 0975406 Correct mempool mapTx comment (Suhas Daftuar) Pull request description: Following up on bitcoin#12127 and bitcoin#12118, this cleans up a comment that was left incorrect in txmempool.h, and addresses a couple of the observations @TheBlueMatt made about an unnecessary use of `queryHashes()` and a small information leak when prioritizing transactions. Left undone is nuking queryHashes altogether; that would require changing the behavior of the `getrawmempool` rpc call, which I think I might be in favor of doing, but wanted to save for its own PR. Tree-SHA512: c97d10b96dcd6520459287a4a2eda92774173757695100fcfe61e526aef86f394507c331d17f9e0c14b496c33ec46198a0f165a847762ca50f7c6780b993f162
Following up on #12127 and #12118, this cleans up a comment that was left incorrect in txmempool.h, and addresses a couple of the observations @TheBlueMatt made about an unnecessary use of
queryHashes()
and a small information leak when prioritizing transactions.Left undone is nuking queryHashes altogether; that would require changing the behavior of the
getrawmempool
rpc call, which I think I might be in favor of doing, but wanted to save for its own PR.