Description
This commit adds a new RPC command called clearmempool
. It is designed to remove all tranasctions from the mempool (including those from invalidated blocks), and return their TXIDs.
The purpose of this command is to clear the mempool, then use the returned TXIDs to perform additional cleanup.
When used in combination with invalidateblock
, it allows me to roll-back the chain to a particular height, clear the mempool, then properly clean up wallets with abandontransaction
.
Note that this command does not prevent the transactions from being re-inserted back into the mempool, either through mempool.dat or user wallets. You have to perform additional cleanup to make sure your changes persist.
I restricted this command to regtest mode as I only need it for running tests, but it could work in any mode.
Rationale
My rationale for adding this command is that I need the ability to cleanly rollback the chain and wallets during testing, and I kept running into the following roadblock:
-
invalidateblock
will rollback the chain height, but all the transactions are dumped into the mempool, creating spending conflicts with the wallets. -
You can prevent this dump from happening, most notably with
-walletbroadcast=0
, however that just hides the problem. -
The real issue is that wallets are still tracking these transactions, and you need to pull their TXIDs from the mempool to properly purge them with
abandontransaction
. -
But if the transactions are in the mempool, then
abandontransaction
will fail, which puts you in a catch-22 situation.
clearmempool
allows you to clear the mempool and capture a list of these transactions, so that you can perform the proper cleanup with abandontransaction
.