wallet/rpc: add z_consolidate, one consolidation round on demand

A CLI miner who keeps -consolidation off (the default) has no way to
shed the notes autoshield piles up short of scripting z_mergetoaddress,
which pauses the miner and rebuilds its RandomX dataset on every call.

z_consolidate ( fee batchsize maxtxs ["zaddr",...] ) runs one round of
the built-in consolidation now, with the -consolidation policy, also
when -consolidation is off. Any argument may be null to keep its
setting; out-of-range values and addresses that are not the wallet's
own Sapling addresses are refused rather than clamped. It returns the
operation id; z_getoperationstatus/-result give the round's result,
and z_consolidationstatus records it as a last_round with manual=true.

It refuses while the node is syncing (the test ChainTip applies to the
periodic ops), while the wallet is locked, and while a consolidation,
zsweep or autoshield round is in flight. It takes the scheduler's slot
like RunSaplingConsolidation does (fConsolidationRunning plus the op
id), so sweep and autoshield defer to it and its completion releases
the slot. The scheduler no longer pops a z_consolidate op from the
queue when it starts the next round, so the user's result stays until
z_getoperationresult collects it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-28 11:09:20 -05:00
co-authored by Claude Opus 5.5
parent e5791fea71
commit 52b747f6d3
7 changed files with 124 additions and 3 deletions
+5 -2
View File
@@ -738,8 +738,10 @@ void CWallet::RunSaplingConsolidation(int blockHeight) {
lastOperation->cancel();
// Drop it from the queue's map as well. Nothing else ever removes these:
// popOperationForId is only reached from z_getoperationresult, so on a node
// running this every interval the map grew without bound.
q->popOperationForId(saplingConsolidationOperationId);
// running this every interval the map grew without bound. A z_consolidate
// round is the user's: its result stays until z_getoperationresult takes it.
if (!saplingConsolidationOpManual)
q->popOperationForId(saplingConsolidationOperationId);
}
pendingSaplingConsolidationTxs.clear();
SaplingConsolidationRequest request;
@@ -750,6 +752,7 @@ void CWallet::RunSaplingConsolidation(int blockHeight) {
request.addresses = consolidationAddresses;
std::shared_ptr<AsyncRPCOperation> operation(new AsyncRPCOperation_saplingconsolidation(blockHeight + AUTO_OP_TARGET_HEIGHT_OFFSET, request));
saplingConsolidationOperationId = operation->getId();
saplingConsolidationOpManual = false;
if (!q->addOperation(operation)) {
// Queue is closing (shutdown). Release the flag we just set, or it stays
// set with no operation in flight and blocks every later round.