wallet: keep consolidation to the sweep address, warn on bad config off

With -zsweep=1 and -consolidation=0, z_consolidate consolidated every
address: the sweep-address substitution sat under
fSaplingConsolidationEnabled, and an explicit address list skipped the
sweep-address rule. Sweep and consolidation then fight over the same
notes and pay fees for nothing. Apply the rule whatever -consolidation
is, and have z_consolidate refuse any address but the sweep address
while zsweep is on.

The branch also started checking -consolidatesaplingaddress with
-consolidation=0, so an old config with a stale, watch-only or mistyped
address, which used to be ignored, stopped startup. Keep the InitError
with -consolidation=1; with it off, warn and drop the address (with
zsweep on, use the sweep address instead).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-28 12:57:58 -05:00
co-authored by Claude Opus 5.5
parent 27a2f04189
commit 25c79b7512
3 changed files with 42 additions and 28 deletions
+5 -4
View File
@@ -90,7 +90,7 @@ witness rebuilds. Consolidation keeps that in check.
| consolidationbatchsize=15 | Most notes one consolidation transaction spends (default 15, clamped to 2..50). |
| consolidationmaxtxs=3 | Most consolidation transactions per address per round (default 3, clamped to 1..100). |
| consolidationtxfee=10000 | Fee in puposhis per consolidation transaction (default 10000 = 0.0001 DRAGONX; allowed range 1000..10000000, anything else falls back to the default). |
| consolidatesaplingaddress=zs1... | Only consolidate this address (may be given several times). The default is every address the wallet can spend. The wallet must hold the address's spending key, or dragonxd refuses to start. |
| consolidatesaplingaddress=zs1... | Only consolidate this address (may be given several times). The default is every address the wallet can spend. With `consolidation=1` the wallet must hold the address's spending key, or dragonxd refuses to start; with it off, such an address is ignored with a warning (and `z_consolidate` works on all addresses unless given its own). |
1. `dragonx-cli z_consolidationstatus` shows the settings, whether a round is running, when the next one is due,
cumulative totals (`notes_consolidated`, `amount_consolidated` in puposhis), the last round (`last_round`: height,
@@ -125,9 +125,10 @@ wallet: `N addresses have more than 25 spendable notes; consider -consolidation=
1. Then follow along with the zsweep section above if you want to set specific options for the zsweep behavior.
1. With zsweep on, consolidation only works on the sweep address (a `consolidatesaplingaddress` other than the
sweep address is refused at startup). Sweep and consolidation never run at the same time, and a sweep is not
started when a consolidation round is due within 5 blocks.
1. With zsweep on, consolidation only works on the sweep address: a `consolidatesaplingaddress` other than the
sweep address is refused at startup (with `consolidation=0` it is replaced by the sweep address, with a warning),
and `z_consolidate` refuses any other address too. Sweep and consolidation never run at the same time, and a
sweep is not started when a consolidation round is due within 5 blocks.
### Copyright
+32 -23
View File
@@ -2520,46 +2520,55 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
pwalletMain->sweepExcludeAddresses.push_back( vSweepExclude[i] );
}
if (pwalletMain->fSaplingConsolidationEnabled) {
//Validate 1 Consolidation address only that matches the sweep address
vector<string>& vaddresses = mapMultiArgs["-consolidatesaplingaddress"];
if (vaddresses.size() == 0) {
fConsolidateSweepAddress = true;
mapMultiArgs["-consolidatesaplingaddress"] = vSweep;
} else {
pwalletMain->consolidationAddress = vaddresses[0];
for (int i = 0; i < vaddresses.size(); i++) {
if (vSweep[0] != vaddresses[i]) {
return InitError("Consolidation can only be used on the sweep address when sweep is enabled.");
}
}
}
// With sweep on, consolidation works on the sweep address only, also for z_consolidate with
// -consolidation off: the two would otherwise fight over the same notes and pay fees for nothing.
vector<string>& vaddresses = mapMultiArgs["-consolidatesaplingaddress"];
bool fOtherAddress = false;
for (size_t i = 0; i < vaddresses.size(); i++)
fOtherAddress |= vSweep[0] != vaddresses[i];
if (fOtherAddress) {
if (pwalletMain->fSaplingConsolidationEnabled)
return InitError("Consolidation can only be used on the sweep address when sweep is enabled.");
InitWarning(_("-consolidatesaplingaddress is not the sweep address; with -zsweep, consolidation only works on the sweep address"));
}
if (vaddresses.empty() || fOtherAddress) {
fConsolidateSweepAddress = true;
vaddresses = vSweep;
}
}
// The addresses consolidation works on: -consolidatesaplingaddress, or with -zsweep the sweep address.
// A user-given address must be one this wallet can spend, else every round would silently skip it.
// With -consolidation off, where older versions ignored the option, a bad one is only warned about
// and dropped; z_consolidate then works on all addresses unless given its own.
{
const vector<string>& vaddresses = mapMultiArgs["-consolidatesaplingaddress"];
fConsolidationMapUsed = !vaddresses.empty();
pwalletMain->consolidationAddresses.clear();
pwalletMain->consolidationAddress.clear();
for (size_t i = 0; i < vaddresses.size(); i++) {
LogPrintf("Consolidating Sapling Address: %s\n", vaddresses[i]);
std::string strProblem;
auto zAddress = DecodePaymentAddress(vaddresses[i]);
if (!IsValidPaymentAddress(zAddress) ||
boost::get<libzcash::SaplingPaymentAddress>(&zAddress) == nullptr) {
return InitError("Invalid consolidation address: -consolidatesaplingaddress must be a Sapling z-address");
strProblem = "Invalid consolidation address: -consolidatesaplingaddress must be a Sapling z-address";
} else if (!boost::apply_visitor(HaveSpendingKeyForPaymentAddress(pwalletMain), zAddress)) {
if (!fConsolidateSweepAddress)
strProblem = strprintf("Wallet must hold the spending key of -consolidatesaplingaddress %s", vaddresses[i]);
else
LogPrintf("%s: the zsweep address is external to this wallet, so consolidation has nothing to do\n", __func__);
}
if (!boost::apply_visitor(HaveSpendingKeyForPaymentAddress(pwalletMain), zAddress)) {
if (!fConsolidateSweepAddress) {
return InitError(strprintf("Wallet must hold the spending key of -consolidatesaplingaddress %s", vaddresses[i]));
}
LogPrintf("%s: the zsweep address is external to this wallet, so consolidation has nothing to do\n", __func__);
if (!strProblem.empty()) {
if (pwalletMain->fSaplingConsolidationEnabled)
return InitError(strProblem);
InitWarning(strProblem + "; ignoring it while -consolidation is off");
continue;
}
pwalletMain->consolidationAddresses.push_back(boost::get<libzcash::SaplingPaymentAddress>(zAddress));
if (pwalletMain->consolidationAddress.empty())
pwalletMain->consolidationAddress = vaddresses[i];
}
if (!vaddresses.empty())
pwalletMain->consolidationAddress = vaddresses[0];
fConsolidationMapUsed = !pwalletMain->consolidationAddresses.empty();
}
// Sweep and consolidation pick notes with GetFilteredNotes at minDepth > 1. Older versions
+5 -1
View File
@@ -3444,7 +3444,8 @@ UniValue z_consolidate(const UniValue& params, bool fHelp, const CPubKey& mypk)
+ strprintf("%d to %d", MIN_CONSOLIDATION_BATCHSIZE, MAX_CONSOLIDATION_BATCHSIZE) + "\n"
"3. maxtxs (numeric, optional, default=-consolidationmaxtxs) most transactions per address, "
+ strprintf("1 to %d", MAX_CONSOLIDATION_MAXTXS) + "\n"
"4. addresses (array, optional, default=-consolidatesaplingaddress or all) Sapling addresses to consolidate\n"
"4. addresses (array, optional, default=-consolidatesaplingaddress or all) Sapling addresses to consolidate;\n"
" with -zsweep on, only the sweep address (also the default then)\n"
"\nResult:\n"
"\"operationid\" (string) An operationid to pass to z_getoperationstatus to get the result.\n"
"\nExamples:\n"
@@ -3501,6 +3502,9 @@ UniValue z_consolidate(const UniValue& params, bool fHelp, const CPubKey& mypk)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address, must be a Sapling z-address: " + str);
if (!boost::apply_visitor(HaveSpendingKeyForPaymentAddress(pwalletMain), zaddr))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Wallet does not hold the spending key of " + str);
// As at startup: with zsweep on, consolidating any other address only feeds the next sweep.
if (pwalletMain->fSweepEnabled && str != pwalletMain->sweepAddress)
throw JSONRPCError(RPC_INVALID_PARAMETER, "With -zsweep on, only the sweep address can be consolidated: " + str);
request.addresses.push_back(boost::get<libzcash::SaplingPaymentAddress>(zaddr));
}
}