From cc3e1c11d77818ae74158451871fd2fd94d12c52 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Thu, 2 Jan 2020 10:56:14 -0500 Subject: [PATCH] Use global mempool nullifier count, not local wallet nullifier count --- src/rpc/server.h | 1 + src/txdb.h | 1 + src/txmempool.cpp | 4 ++++ src/txmempool.h | 1 + src/wallet/rpcwallet.cpp | 20 +++++++++----------- src/wallet/wallet.cpp | 28 ++++++++++++++++++---------- src/wallet/wallet.h | 1 + 7 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/rpc/server.h b/src/rpc/server.h index 7491f35ec..6ce27894a 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -481,6 +481,7 @@ extern UniValue z_exportviewingkey(const UniValue& params, bool fHelp, const CPu extern UniValue z_importviewingkey(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcdump.cpp extern UniValue z_getnewaddress(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp extern UniValue z_listaddresses(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp +extern UniValue z_listnullifiers(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp extern UniValue z_exportwallet(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcdump.cpp extern UniValue z_importwallet(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcdump.cpp extern UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp diff --git a/src/txdb.h b/src/txdb.h index 195f4c183..e089d0190 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2019-2020 The Hush developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 91fa0e3c6..ed5951e08 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -888,6 +888,10 @@ bool CTxMemPool::IsFullyNotified() { return nRecentlyAddedSequence == nNotifiedSequence; } +std::map CTxMemPool::getNullifiers() { + return mapSaplingNullifiers; +} + CCoinsViewMemPool::CCoinsViewMemPool(CCoinsView *baseIn, CTxMemPool &mempoolIn) : CCoinsViewBacked(baseIn), mempool(mempoolIn) { } bool CCoinsViewMemPool::GetNullifier(const uint256 &nf, ShieldedType type) const diff --git a/src/txmempool.h b/src/txmempool.h index 70eae0b92..fbf7e4784 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -201,6 +201,7 @@ public: * all inputs are in the mapNextTx array). If sanity-checking is turned off, * check does nothing. */ + std::map getNullifiers(); void check(const CCoinsViewCache *pcoins) const; void setSanityCheck(double dFrequency = 1.0) { nCheckFrequency = static_cast(dFrequency * 4294967295.0); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 2827aa7c3..8a8d02654 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3748,27 +3748,25 @@ UniValue z_listnullifiers(const UniValue& params, bool fHelp, const CPubKey& myp if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; - if (fHelp || params.size() > 1) + if (fHelp || params.size() > 0) throw runtime_error( - "z_listaddresses ( includeWatchonly )\n" - "\nReturns the list of Sprout and Sapling shielded addresses belonging to the wallet.\n" - "\nArguments:\n" - "1. includeWatchonly (bool, optional, default=false) Also include watchonly addresses (see 'z_importviewingkey')\n" + "z_listnullifiers\n" + "\nReturns the list of Sapling nullifiers.\n" "\nResult:\n" "[ (json array of string)\n" - " \"zaddr\" (string) a zaddr belonging to the wallet\n" + " \"nullifier\" (string) a Sapling nullifer\n" " ,...\n" "]\n" "\nExamples:\n" - + HelpExampleCli("z_listaddresses", "") - + HelpExampleRpc("z_listaddresses", "") + + HelpExampleCli("z_listnullifiers", "") + + HelpExampleRpc("z_listnullifiers", "") ); LOCK2(cs_main, pwalletMain->cs_wallet); UniValue ret(UniValue::VARR); - for (auto nullifier: Nullifiers){ - ret.push_back(EncodePaymentAddress(addr)); - } + //for (auto nullifier: mempool.getNullifiers()) { + // ret.push_back(nullifier.GetHex()); + //} return ret; } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index e7ce0cd65..10bf3405a 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -613,15 +613,6 @@ std::set> CWallet::GetNullifiersFor } } for (const auto & txPair : mapWallet) { - // Sprout - for (const auto & noteDataPair : txPair.second.mapSproutNoteData) { - auto & noteData = noteDataPair.second; - auto & nullifier = noteData.nullifier; - auto & address = noteData.address; - if (nullifier && addresses.count(address)) { - nullifierSet.insert(std::make_pair(address, nullifier.get())); - } - } // Sapling for (const auto & noteDataPair : txPair.second.mapSaplingNoteData) { auto & noteData = noteDataPair.second; @@ -960,12 +951,29 @@ void CWallet::AddToSpends(const uint256& wtxid) } } +std::set CWallet::GetNullifiers() +{ + std::set nullifierSet; + for (const auto & txPair : mapWallet) { + // Sapling + for (const auto & noteDataPair : txPair.second.mapSaplingNoteData) { + auto & noteData = noteDataPair.second; + auto & nullifier = noteData.nullifier; + if (nullifier) { + nullifierSet.insert(nullifier.get()); + } + } + } + return nullifierSet; +} + int64_t CWallet::NullifierCount() { LOCK(cs_wallet); - return mapTxSaplingNullifiers.size(); + return mempool.getNullifiers().size(); } + void CWallet::ClearNoteWitnessCache() { LOCK(cs_wallet); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index f00e1336f..eb350fb40 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -797,6 +797,7 @@ public: void ClearNoteWitnessCache(); int64_t NullifierCount(); + std::set GetNullifiers(); protected: /**