wallet: suggest consolidation when it is off and notes pile up
Consolidation stays off by default, but a miner whose autoshield adds one note per round should hear that it would help before the wallet slows down. With -consolidation off, count the addresses holding more than -consolidationthreshold eligible notes right after the startup note cache warm-up (the plaintexts are in memory then, so the walk is cheap) and log once: N addresses have more than 25 spendable notes; consider -consolidation=1 or z_consolidate z_autoshieldstatus reports it as consolidation_suggested (refreshing the count at most once per consolidation interval, since autoshield is what keeps adding the notes), and z_consolidationstatus verbose as consolidation_suggested and consolidation_suggested_count from its own walk. A later count that first finds an address over the threshold logs the line then, still only once per run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2771,6 +2771,10 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
if (GetBoolArg("-notecachewarmup", true) && !ShutdownRequested()) {
|
||||
uiInterface.InitMessage(_("Decrypting wallet notes..."));
|
||||
pwalletMain->WarmSaplingNoteCache();
|
||||
// With the notes decrypted, counting them per address is cheap: suggest consolidation to a
|
||||
// wallet that has piled up notes (typically a miner's, one note per autoshield round).
|
||||
if (!pwalletMain->fSaplingConsolidationEnabled && !ShutdownRequested())
|
||||
pwalletMain->RefreshConsolidationSuggestion();
|
||||
}
|
||||
|
||||
pwalletMain->SetBroadcastTransactions(GetBoolArg("-walletbroadcast", true));
|
||||
|
||||
@@ -3339,7 +3339,10 @@ UniValue z_consolidationstatus(const UniValue& params, bool fHelp, const CPubKey
|
||||
" \"addresses\" : [ (array, verbose only) every address with eligible notes\n"
|
||||
" { \"address\" : \"zaddr\", \"eligible_notes\" : n, \"over_threshold\" : true|false, \"included\" : true|false }\n"
|
||||
" ],\n"
|
||||
" \"addresses_over_threshold\" : n (numeric, verbose only) included addresses over the threshold\n"
|
||||
" \"addresses_over_threshold\" : n, (numeric, verbose only) included addresses over the threshold\n"
|
||||
" \"consolidation_suggested\" : true|false, (boolean, verbose only) -consolidation is off and some\n"
|
||||
" address is over the threshold: consider -consolidation=1 or z_consolidate\n"
|
||||
" \"consolidation_suggested_count\" : n (numeric, verbose only) addresses over the threshold while it is off\n"
|
||||
"}\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("z_consolidationstatus", "")
|
||||
@@ -3411,6 +3414,9 @@ UniValue z_consolidationstatus(const UniValue& params, bool fHelp, const CPubKey
|
||||
}
|
||||
ret.push_back(Pair("addresses", list));
|
||||
ret.push_back(Pair("addresses_over_threshold", over));
|
||||
pwalletMain->SetConsolidationSuggestion(over);
|
||||
ret.push_back(Pair("consolidation_suggested", !pwalletMain->fSaplingConsolidationEnabled && over > 0));
|
||||
ret.push_back(Pair("consolidation_suggested_count", pwalletMain->consolidationSuggestCount));
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -3576,7 +3582,9 @@ UniValue z_autoshieldstatus(const UniValue& params, bool fHelp, const CPubKey& m
|
||||
" \"hdseedorigin\" : n, (numeric) 0 unrecorded, 1 created, 2 restored, 3 retrofit, 4 unknown\n"
|
||||
" \"hdseedorigin_desc\" : \"...\", (string) readable form of hdseedorigin\n"
|
||||
" \"seed_recoverable\" : true|false, (boolean) whether a seed phrase can be exported\n"
|
||||
" \"disabled_reason\" : \"...\" (string) why auto-shielding is not running, if it is not\n"
|
||||
" \"disabled_reason\" : \"...\", (string) why auto-shielding is not running, if it is not\n"
|
||||
" \"consolidation_suggested\" : true|false (boolean) -consolidation is off and some address holds more\n"
|
||||
" than -consolidationthreshold spendable notes (see z_consolidationstatus)\n"
|
||||
"}\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("z_autoshieldstatus", "")
|
||||
@@ -3628,6 +3636,16 @@ UniValue z_autoshieldstatus(const UniValue& params, bool fHelp, const CPubKey& m
|
||||
}
|
||||
ret.push_back(Pair("disabled_reason", why));
|
||||
|
||||
// Autoshield is what fills a miner's wallet with notes, one per round, so say here when consolidation
|
||||
// would help. The count is refreshed at most once per consolidation interval: it walks the wallet.
|
||||
if (!pwalletMain->fSaplingConsolidationEnabled &&
|
||||
(pwalletMain->consolidationSuggestHeight < 0 ||
|
||||
chainActive.Height() - pwalletMain->consolidationSuggestHeight >= pwalletMain->consolidationInterval)) {
|
||||
pwalletMain->RefreshConsolidationSuggestion();
|
||||
}
|
||||
ret.push_back(Pair("consolidation_suggested",
|
||||
!pwalletMain->fSaplingConsolidationEnabled && pwalletMain->consolidationSuggestCount > 0));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -772,6 +772,34 @@ std::map<libzcash::SaplingPaymentAddress, int> CWallet::CountConsolidationEligib
|
||||
return counts;
|
||||
}
|
||||
|
||||
void CWallet::SetConsolidationSuggestion(int overThreshold) {
|
||||
LOCK2(cs_main, cs_wallet);
|
||||
if (fSaplingConsolidationEnabled)
|
||||
overThreshold = 0;
|
||||
consolidationSuggestCount = overThreshold;
|
||||
consolidationSuggestHeight = chainActive.Height();
|
||||
if (overThreshold > 0 && !fConsolidationSuggestLogged) {
|
||||
fConsolidationSuggestLogged = true;
|
||||
LogPrintf("%d %s more than %d spendable notes; consider -consolidation=1 or z_consolidate\n",
|
||||
overThreshold, overThreshold == 1 ? "address has" : "addresses have", consolidationThreshold);
|
||||
}
|
||||
}
|
||||
|
||||
void CWallet::RefreshConsolidationSuggestion() {
|
||||
LOCK2(cs_main, cs_wallet);
|
||||
if (fSaplingConsolidationEnabled) {
|
||||
SetConsolidationSuggestion(0);
|
||||
return;
|
||||
}
|
||||
std::set<libzcash::SaplingPaymentAddress> included(consolidationAddresses.begin(), consolidationAddresses.end());
|
||||
int over = 0;
|
||||
for (const auto& p : CountConsolidationEligibleNotes()) {
|
||||
if ((included.empty() || included.count(p.first)) && p.second > consolidationThreshold)
|
||||
over++;
|
||||
}
|
||||
SetConsolidationSuggestion(over);
|
||||
}
|
||||
|
||||
// Periodically drain matured transparent coinbase into a wallet-owned Sapling
|
||||
// z-address. Default-ON but conditional: this is enqueue-only (all gathering
|
||||
// happens on the async worker thread inside the op, which is why we must not
|
||||
|
||||
@@ -932,6 +932,11 @@ public:
|
||||
int 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
|
||||
// height that was counted, and whether the "consider -consolidation" hint has been logged.
|
||||
int consolidationSuggestCount = -1;
|
||||
int consolidationSuggestHeight = -1;
|
||||
bool fConsolidationSuggestLogged = false;
|
||||
int sweepInterval = 10;
|
||||
int consolidationInterval = DEFAULT_CONSOLIDATION_INTERVAL;
|
||||
int consolidationThreshold = DEFAULT_CONSOLIDATION_THRESHOLD;
|
||||
@@ -1379,6 +1384,11 @@ public:
|
||||
/** Notes a consolidation round would count as eligible, per address. Walks the whole wallet
|
||||
* under cs_main + cs_wallet, so it is only run on request. */
|
||||
std::map<libzcash::SaplingPaymentAddress, int> CountConsolidationEligibleNotes();
|
||||
/** With -consolidation off, counts the addresses over the threshold into consolidationSuggestCount
|
||||
* and logs, once, that consolidation would help. Walks the wallet like the above. */
|
||||
void RefreshConsolidationSuggestion();
|
||||
/** Records a count of addresses over the threshold (from either walk) and logs the hint once. */
|
||||
void SetConsolidationSuggestion(int overThreshold);
|
||||
void RunAutoShieldCoinbase(int blockHeight);
|
||||
bool CommitAutomatedTx(const CTransaction& tx);
|
||||
/** Saves witness caches and best block locator to disk. Overrides CValidationInterface. */
|
||||
|
||||
Reference in New Issue
Block a user