-
Notifications
You must be signed in to change notification settings - Fork 38.7k
RPC: Add new 'clearmempool' method #13836
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
Conversation
|
I don't know if adding this new method is desired. I would have found it useful from time to time, but mostly related to testing (and not production use). For instance, it can be useful in combination with Feel free to close if you think this is not useful to have. |
doc/release-notes.md
Outdated
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.
If it is only for testing, it shoulnd't be mentioned in the release notes?
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 don't know about the exact policy and included it here to have them "complete". But of course I'm happy to remove the mention if it is common to not include changes that are not meant (mainly) for end users.
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.
Removed.
src/rpc/blockchain.cpp
Outdated
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.
Could return the number of evicted txns to be more useful.
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.
Then return an object which can have more keys in the future.
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.
Yes, that makes sense. If you generally think having this method is useful, I'll add a useful return value to it (e.g. starting with the number of evicated tx).
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.
Changed the RPC to return a JSON object, with nTx holding the number of evicted transactions.
src/rpc/blockchain.cpp
Outdated
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.
Are we missing some lock acquisitions here (e.g. mempool.cs)?
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 thought so first myself, but CTxMempool::clear explicitly locks for you.
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.
Oh right, my mistake.
|
Yes. Why not. |
9a502ee to
0fd9903
Compare
src/rpc/blockchain.cpp
Outdated
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.
Use same key as?
bitcoin/src/rpc/blockchain.cpp
Line 1423 in 990e182
| " \"size\": xxxxx, (numeric) Current tx count\n" |
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.
Yeah, that makes sense. (nTx was based on getblock, but getmempoolinfo is of course more relevant in this context.) Will update the commit accordingly.
0fd9903 to
4b06094
Compare
skeees
left a comment
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.
concept ACK
I'd note that this is the first time CTxMempool::clear() will be called during normal operation (apart from startup / shutdown), so I think this requires extensive testing to make sure it leaves the mempool in a consistent state (suitable for re-use and with no cruft around).
For example, just a cursory look at that implementation suggests it might not be doing a full clear of every data structure (mapDeltas for example).
src/rpc/blockchain.cpp
Outdated
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.
maybe call this transactions_removed or something more informative
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.
Changed. size is consistent with getmempoolinfo, but in that context "size" is clearly more descriptive than for clearmempool. I agree that here transactions_removed is a better name.
src/rpc/blockchain.cpp
Outdated
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.
is there a future safety benefit to calling the toplevel mempool.clear() here?
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.
Why not - changed to clear. (Especially since _clear does not AssertLockHeld(cs).)
|
Should probably run a |
|
@MarcoFalke: If we are worried that EDIT: That said, it seems to have benefits to add the |
4b06094 to
4fb35b1
Compare
|
I've now added a call to
|
4fb35b1 to
838177c
Compare
CTxMemPool::clear() was missing mapDeltas, which should also be cleared as part of the overall mempool state. This change fixes that, and adds a consistency check between mapDeltas and mapTx to CTxMemPool::check.
838177c to
9029f0c
Compare
|
@skeees made an excellent observation. Maybe add tests involving unconfirmed wallet transactions after clearing the mempool? Also try to include other RPC's related to the mempool, like |
The new 'clearmempool' RPC method removes all transactions in the mempool. This can be useful for testing, and might be useful also in some other situations.
9029f0c to
1976013
Compare
|
I've now split out the test into a new I'm not sure what exactly you are thinking about with other mempool-related functions. In my opinion, the test strategy should look like this:
I don't think that Do you have any concrete suggestions of what else we should do for step 1) and what might be missing for |
Just a way to say that their functionality is preserved after |
|
What would this RPC be useful for? It seems pretty ill advised to expose it for production use, and for testing it can always be accomplished by restarting the node (and wiping mempool.dat). |
| No more conflicts as of last run. |
|
@sipa: The situation where I would have found it useful from time to time is certainly testing (not production). You are right that restarting with wiping But if you think we should rather not expose this, then we can of course close this PR. (And I'll just move the fix for |
|
@sipa correct me if I'm wrong (can't test ATM) but a new wallet transaction could be rejected and this would allow to add it? |
|
@promag Yes, but other nodes will still reject it. Permitting is locally seems a bad idea in that case (and at the least a privacy leak). |
| mapLinks.clear(); | ||
| mapTx.clear(); | ||
| mapNextTx.clear(); | ||
| mapDeltas.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.
mapDeltas probably shouldn't be cleared...?
| assert(&tx == it->second); | ||
| } | ||
| for (const auto& entry : mapDeltas) { | ||
| assert(mapTx.count(entry.first) > 0); |
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.
Deltas aren't necessarily in the pool (needed to prioritise ones that would be rejected otherwise).
I agree with @sipa here. This has much foot-shooting potential and, besides for a few developer corner cases, doesn't seem worth the maintenance and testing hassle. (in practice, methods such as this are going to be suggested for any common ailment, "oh have you tried 'clearmempool') |
|
Agreed - I also don't see much use besides testing, so perhaps it is safer not to add this generally. |
The new
clearmempoolRPC method removes all transactions in the mempool. This can be useful for testing, and might be useful also in some other situations.