Browse Source

Use global mempool nullifier count, not local wallet nullifier count

pull/63/head
Duke Leto 4 years ago
parent
commit
cc3e1c11d7
  1. 1
      src/rpc/server.h
  2. 1
      src/txdb.h
  3. 4
      src/txmempool.cpp
  4. 1
      src/txmempool.h
  5. 20
      src/wallet/rpcwallet.cpp
  6. 28
      src/wallet/wallet.cpp
  7. 1
      src/wallet/wallet.h

1
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

1
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.

4
src/txmempool.cpp

@ -888,6 +888,10 @@ bool CTxMemPool::IsFullyNotified() {
return nRecentlyAddedSequence == nNotifiedSequence;
}
std::map<uint256, const CTransaction*> CTxMemPool::getNullifiers() {
return mapSaplingNullifiers;
}
CCoinsViewMemPool::CCoinsViewMemPool(CCoinsView *baseIn, CTxMemPool &mempoolIn) : CCoinsViewBacked(baseIn), mempool(mempoolIn) { }
bool CCoinsViewMemPool::GetNullifier(const uint256 &nf, ShieldedType type) const

1
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<uint256, const CTransaction*> getNullifiers();
void check(const CCoinsViewCache *pcoins) const;
void setSanityCheck(double dFrequency = 1.0) { nCheckFrequency = static_cast<uint32_t>(dFrequency * 4294967295.0); }

20
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;
}

28
src/wallet/wallet.cpp

@ -613,15 +613,6 @@ std::set<std::pair<libzcash::PaymentAddress, uint256>> 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<uint256> CWallet::GetNullifiers()
{
std::set<uint256> 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);

1
src/wallet/wallet.h

@ -797,6 +797,7 @@ public:
void ClearNoteWitnessCache();
int64_t NullifierCount();
std::set<uint256> GetNullifiers();
protected:
/**

Loading…
Cancel
Save