Browse Source

Add z_getwitnesscachestats RPC to get various stats about the witness cache

witness_cache
Duke 7 months ago
parent
commit
afd2953c62
  1. 38
      src/wallet/rpcwallet.cpp

38
src/wallet/rpcwallet.cpp

@ -3636,6 +3636,43 @@ UniValue z_listsentbyaddress(const UniValue& params, bool fHelp,const CPubKey&)
return ret;
}
UniValue z_getwitnesscachestats(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (fHelp || params.size() < 1 || params.size() > 2)
throw runtime_error(
"z_getwitnesscachestats\n"
"\nReturns statistics about the witness cache for zaddrs\n"
"\nResult:\n"
"\njson\n"
"\nExamples:\n"
+ HelpExampleCli("z_getwitnesscachestats", "456")
+ HelpExampleRpc("z_getwitnesscachestats", "456")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
uint32_t nMinDepth = 1;
uint64_t total_witnesses = 0;
uint64_t total_zutxos = 0;
for (auto& wtx : pwalletMain->mapWallet) {
if (wtx.second.GetDepthInMainChain() >= nMinDepth) {
total_zutxos += wtx.second.mapSaplingNoteData.size();
for (mapSaplingNoteData_t::value_type& item : wtx.second.mapSaplingNoteData) {
auto* nd = &(item.second);
total_witnesses += nd->witnesses.size();
}
}
}
UniValue ret(UniValue::VOBJ);
ret.pushKV("total_witnesses", total_witnesses);
ret.pushKV("total_zutxos", total_zutxos);
ret.pushKV("witnesses_cache_size", pwalletMain->nWitnessCacheSize);
ret.pushKV("max_witnesses_cache_size", (int) WITNESS_CACHE_SIZE);
return ret;
}
UniValue z_getstats(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
if (!EnsureWalletIsAvailable(fHelp))
@ -8710,6 +8747,7 @@ static const CRPCCommand commands[] =
{ "wallet", "z_getbalance", &z_getbalance, false },
{ "wallet", "z_getbalances", &z_getbalances, false },
{ "wallet", "z_getstats", &z_getstats, true },
{ "wallet", "z_getwitnesscachestats", &z_getwitnesscachestats, true },
{ "wallet", "z_anonsettxdelta", &z_anonsettxdelta, true },
{ "wallet", "z_anonsetblockdelta", &z_anonsetblockdelta, true },
{ "wallet", "z_gettotalbalance", &z_gettotalbalance, false },

Loading…
Cancel
Save