From 172ac60765265cb220be7da36bfe95916696c546 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 28 Dec 2019 12:49:01 -0500 Subject: [PATCH] Initial implementation of shielded pool size. Tweaks to data stored in zindex are needed to get a more correct value --- src/rpc/blockchain.cpp | 6 ++++++ src/wallet/wallet.cpp | 6 ++++++ src/wallet/wallet.h | 2 ++ 3 files changed, 14 insertions(+) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index ffbc74e63..f41578c54 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -37,6 +37,7 @@ #include "script/script_error.h" #include "script/sign.h" #include "script/standard.h" +#include "wallet/wallet.h" #include @@ -1994,6 +1995,11 @@ UniValue getchaintxstats(const UniValue& params, bool fHelp, const CPubKey& mypk ret.pushKV("fully_shielded_payments", (int64_t)pindex->nChainFullyShieldedPayments); ret.pushKV("deshielding_payments", (int64_t)pindex->nChainDeshieldingPayments); ret.pushKV("shielding_payments", (int64_t)pindex->nChainShieldingPayments); + + int64_t nullifierCount = pwalletMain->NullifierCount(); + //TODO: we actually need to have zindex keep track of total number of zouts, including change + // Currently zpayments does not include change and will underestimate actual zpool size + ret.pushKV("shielded_pool_size", (int64_t)pindex->nChainShieldedPayments - nullifierCount); } if (blockcount > 0) { diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index c2d899060..e7ce0cd65 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -960,6 +960,12 @@ void CWallet::AddToSpends(const uint256& wtxid) } } +int64_t CWallet::NullifierCount() +{ + LOCK(cs_wallet); + return mapTxSaplingNullifiers.size(); +} + void CWallet::ClearNoteWitnessCache() { LOCK(cs_wallet); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 07b80cd6a..f00e1336f 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -796,6 +796,8 @@ public: void ClearNoteWitnessCache(); + int64_t NullifierCount(); + protected: /** * pindex is the new tip being connected.