wallet: make z_sweepstatus report what the sweep actually does
Three z_sweepstatus fields read members nothing kept up to date:
- zsweepmaxinputs showed a member never set from -zsweepmaxinputs, so it always said 200 while
the op used GetArg("-zsweepmaxinputs", 8). Parse and range-check the option once at startup into
that member (5 to 100, default 8; same fallback as before) and have the op read it.
- zsweepfee showed a member never set from -zsweepfee. Report fSweepTxFee, which the op uses, and
drop the dead member.
- amount_swept showed a counter nothing incremented (an int of puposhis, which would also have
overflowed past ~21 DRGX). Count committed sweep transactions in a CAmount and report DRGX.
Add wallet_locked, so it is visible at a glance why nothing is being swept, and give the RPC a real
help text (it had a stray "}" and no Result section). Add the include guard that
asyncrpcoperation_sweep.h lacked, now that rpcwallet.cpp includes it too.
Release-notes item: amount_swept is now a decimal DRGX amount (it was an integer that was always 0).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+8
-1
@@ -656,7 +656,7 @@ std::string HelpMessage(HelpMessageMode mode)
|
||||
strUsage += HelpMessageOpt("-zsweepaddress=<zaddr>", _("Specify the shielded address where swept funds will be sent)"));
|
||||
strUsage += HelpMessageOpt("-zsweepfee", strprintf(_("Fee amount in puposhis used send sweep transactions. (default %i)"), DEFAULT_SWEEP_FEE));
|
||||
strUsage += HelpMessageOpt("-zsweepinterval", strprintf(_("Sweep shielded funds every X blocks (default %i)"), 10));
|
||||
strUsage += HelpMessageOpt("-zsweepmaxinputs", strprintf(_("Maximum number of shielded inputs to sweep per transaction (default %i)"), 8));
|
||||
strUsage += HelpMessageOpt("-zsweepmaxinputs", strprintf(_("Maximum number of shielded inputs to sweep per transaction, %i to %i (default %i)"), MIN_SWEEP_MAX_INPUTS, MAX_SWEEP_MAX_INPUTS, DEFAULT_SWEEP_MAX_INPUTS));
|
||||
// By default we only allow sweeping to the current wallet which must have the spending key of the sweep zaddr
|
||||
// This hopefully will make it harder for people to accidentally sweep funds to a wrong zaddr and lose funds
|
||||
strUsage += HelpMessageOpt("-zsweepexternal", _("Enable sweeping to an external wallet (default false)"));
|
||||
@@ -2630,6 +2630,13 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
LogPrintf("%s: set nextSweep=%d with sweepInterval=%d\n", __func__, pwalletMain->nextSweep, pwalletMain->sweepInterval );
|
||||
fSweepTxFee = GetArg("-zsweepfee", DEFAULT_SWEEP_FEE);
|
||||
fSweepMapUsed = !mapMultiArgs["-zsweepaddress"].empty();
|
||||
int sweepMaxInputs = GetArg("-zsweepmaxinputs", DEFAULT_SWEEP_MAX_INPUTS);
|
||||
if (sweepMaxInputs < MIN_SWEEP_MAX_INPUTS || sweepMaxInputs > MAX_SWEEP_MAX_INPUTS) {
|
||||
LogPrintf("%s: Invalid -zsweepmaxinputs=%d (must be %d to %d), using the default of %d\n", __func__,
|
||||
sweepMaxInputs, MIN_SWEEP_MAX_INPUTS, MAX_SWEEP_MAX_INPUTS, DEFAULT_SWEEP_MAX_INPUTS);
|
||||
sweepMaxInputs = DEFAULT_SWEEP_MAX_INPUTS;
|
||||
}
|
||||
pwalletMain->sweepMaxInputs = sweepMaxInputs;
|
||||
|
||||
//Validate Sapling Addresses
|
||||
vector<string>& vSweep = mapMultiArgs["-zsweepaddress"];
|
||||
|
||||
@@ -209,11 +209,8 @@ bool AsyncRPCOperation_sweep::main_impl() {
|
||||
|
||||
std::vector<SaplingNoteEntry> fromNotes;
|
||||
CAmount amountToSend = 0;
|
||||
int maxInputs = GetArg("-zsweepmaxinputs", 8);
|
||||
if( maxInputs > 100 || maxInputs < 5) {
|
||||
fprintf(stderr,"%s: Invalid zsweep maxinputs=%d is >100 and <5, setting to default of 8\n", __func__, maxInputs);
|
||||
maxInputs = 8;
|
||||
}
|
||||
// -zsweepmaxinputs, parsed and range-checked once at startup.
|
||||
const size_t maxInputs = pwalletMain->sweepMaxInputs;
|
||||
|
||||
//Count Notes availiable for this address
|
||||
int targetCount = 0;
|
||||
@@ -343,6 +340,10 @@ bool AsyncRPCOperation_sweep::main_impl() {
|
||||
if (pwalletMain->CommitAutomatedTx(tx)) {
|
||||
LogPrintf("%s: Committed sweep transaction with txid=%s\n", getId(), tx.GetHash().ToString());
|
||||
amountSwept += amountToSend - fee;
|
||||
{
|
||||
LOCK(pwalletMain->cs_wallet);
|
||||
pwalletMain->amountSwept += amountToSend - fee;
|
||||
}
|
||||
sweepTxIds.push_back(tx.GetHash().ToString());
|
||||
numTxCreated++;
|
||||
} else {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
// Copyright (c) 2016-2024 The Hush developers
|
||||
// Distributed under the GPLv3 software license, see the accompanying
|
||||
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
|
||||
#ifndef HUSH_WALLET_ASYNCRPCOPERATION_SWEEP_H
|
||||
#define HUSH_WALLET_ASYNCRPCOPERATION_SWEEP_H
|
||||
|
||||
#include "amount.h"
|
||||
#include "asyncrpcoperation.h"
|
||||
#include "univalue.h"
|
||||
@@ -44,3 +47,5 @@ private:
|
||||
void setSweepResult(int numTxCreated, const CAmount& amountSwept, const std::vector<std::string>& sweepTxIds);
|
||||
|
||||
};
|
||||
|
||||
#endif // HUSH_WALLET_ASYNCRPCOPERATION_SWEEP_H
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include "wallet/asyncrpcoperation_sendmany.h"
|
||||
#include "wallet/asyncrpcoperation_shieldcoinbase.h"
|
||||
#include "wallet/asyncrpcoperation_saplingconsolidation.h"
|
||||
#include "wallet/asyncrpcoperation_sweep.h"
|
||||
#include "consensus/upgrades.h"
|
||||
#include "sodium.h"
|
||||
#include <stdint.h>
|
||||
@@ -3541,7 +3542,21 @@ UniValue z_sweepstatus(const UniValue& params, bool fHelp, const CPubKey& mypk)
|
||||
if (fHelp || params.size() > 0)
|
||||
throw runtime_error(
|
||||
"z_sweepstatus\n"
|
||||
"\nGive details about zsweep operations since the node was started."
|
||||
"\nGive details about zsweep operations since the node was started.\n"
|
||||
"\nResult:\n"
|
||||
"{\n"
|
||||
" \"zsweep\" : true|false, (boolean) whether -zsweep is enabled\n"
|
||||
" \"running\" : true|false, (boolean) whether a sweep round is in flight\n"
|
||||
" \"wallet_locked\" : true|false, (boolean) the wallet is encrypted and locked, so nothing can be swept\n"
|
||||
" until it is unlocked with walletpassphrase\n"
|
||||
" \"amount_swept\" : x.xxx, (numeric) DRGX sent to the sweep address since startup\n"
|
||||
" \"next_zsweep\" : n, (numeric) height of the next round\n"
|
||||
" \"zsweepinterval\" : n, (numeric) blocks between rounds\n"
|
||||
" \"zsweepaddress\" : \"zaddr\", (string) where swept funds are sent\n"
|
||||
" \"zsweepexclude\" : [\"zaddr\",...], (array) addresses that are never swept\n"
|
||||
" \"zsweepmaxinputs\" : n, (numeric) shielded inputs per sweep transaction\n"
|
||||
" \"zsweepfee\" : n, (numeric) fee per sweep transaction in puposhis\n"
|
||||
" \"zsweepexternal\" : true|false (boolean) whether sweeping to an external wallet is allowed\n"
|
||||
"}\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("z_sweepstatus", "")
|
||||
@@ -3553,7 +3568,8 @@ UniValue z_sweepstatus(const UniValue& params, bool fHelp, const CPubKey& mypk)
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
ret.push_back(Pair("zsweep", pwalletMain->fSweepEnabled));
|
||||
ret.push_back(Pair("running", pwalletMain->fSweepRunning));
|
||||
ret.push_back(Pair("amount_swept", pwalletMain->amountSwept));
|
||||
ret.push_back(Pair("wallet_locked", pwalletMain->IsLocked()));
|
||||
ret.push_back(Pair("amount_swept", ValueFromAmount(pwalletMain->amountSwept)));
|
||||
ret.push_back(Pair("next_zsweep", pwalletMain->nextSweep));
|
||||
ret.push_back(Pair("zsweepinterval", pwalletMain->sweepInterval));
|
||||
ret.push_back(Pair("zsweepaddress", pwalletMain->sweepAddress));
|
||||
@@ -3563,7 +3579,7 @@ UniValue z_sweepstatus(const UniValue& params, bool fHelp, const CPubKey& mypk)
|
||||
}
|
||||
ret.push_back(Pair("zsweepexclude", excludes));
|
||||
ret.push_back(Pair("zsweepmaxinputs", pwalletMain->sweepMaxInputs));
|
||||
ret.push_back(Pair("zsweepfee", pwalletMain->sweepFee));
|
||||
ret.push_back(Pair("zsweepfee", fSweepTxFee));
|
||||
ret.push_back(Pair("zsweepexternal", pwalletMain->fSweepExternalEnabled));
|
||||
|
||||
return ret;
|
||||
|
||||
+8
-3
@@ -112,6 +112,10 @@ static const int MIN_AUTOSHIELD_INTERVAL = 5;
|
||||
static const int DEFAULT_AUTOSHIELD_MIN_UTXOS = 1;
|
||||
static const CAmount AUTOSHIELD_MIN_FEE = 1000; // comfortably above minRelayTxFee for a small tx
|
||||
static const CAmount AUTOSHIELD_MAX_FEE = 10000000; // 0.1 DRGX; no sane autoshield fee exceeds this
|
||||
// zsweep (-zsweepmaxinputs): Sapling spends per sweep transaction. Out-of-range values fall back to the default.
|
||||
static const int DEFAULT_SWEEP_MAX_INPUTS = 8;
|
||||
static const int MIN_SWEEP_MAX_INPUTS = 5;
|
||||
static const int MAX_SWEEP_MAX_INPUTS = 100;
|
||||
// Sapling consolidation (-consolidation / z_consolidate). An address is only consolidated once it holds
|
||||
// MORE than the threshold of spendable notes; a round then sends up to maxtxs transactions per address,
|
||||
// each spending up to batchsize of its smallest notes back to that same address.
|
||||
@@ -932,7 +936,8 @@ public:
|
||||
AsyncRPCOperationId saplingSweepOperationId;
|
||||
// Block height at which that op was enqueued (for the log while RunSaplingSweep waits on it).
|
||||
int sweepDispatchHeight = 0;
|
||||
int amountSwept = 0;
|
||||
// Total sent to the sweep address by committed sweep transactions since startup. Guarded by cs_wallet.
|
||||
CAmount amountSwept = 0;
|
||||
// What consolidation rounds have done since startup. Guarded by cs_wallet.
|
||||
SaplingConsolidationStats consolidationStats;
|
||||
// With -consolidation off: how many addresses are over the threshold (-1 until counted), at which
|
||||
@@ -947,8 +952,8 @@ public:
|
||||
int consolidationMaxTxs = DEFAULT_CONSOLIDATION_MAXTXS;
|
||||
// -consolidatesaplingaddress (or the zsweep address); empty: every address the wallet can spend.
|
||||
std::vector<libzcash::SaplingPaymentAddress> consolidationAddresses;
|
||||
int sweepFee = 10000;
|
||||
int sweepMaxInputs = 200;
|
||||
// Set from -zsweepmaxinputs at startup and read by every sweep op. (The fee lives in fSweepTxFee.)
|
||||
int sweepMaxInputs = DEFAULT_SWEEP_MAX_INPUTS;
|
||||
std::string sweepAddress = "";
|
||||
std::vector<std::string> sweepExcludeAddresses;
|
||||
std::string consolidationAddress = "";
|
||||
|
||||
Reference in New Issue
Block a user