From 0c2487c4271eaf80286478cb21ad8754ec281f0a Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 18 Jul 2022 10:43:22 -0400 Subject: [PATCH 01/12] Throw error in wallet if ReadBlockFromDisk fails --- src/wallet/wallet.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 8d12d903a..bda0140f0 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1032,7 +1032,10 @@ int CWallet::VerifyAndSetInitialWitness(const CBlockIndex* pindex, bool witnessO //Cycle through blocks and transactions building sapling tree until the commitment needed is reached const CBlock* pblock; CBlock block; - ReadBlockFromDisk(block, pblockindex, 1); + if (!ReadBlockFromDisk(block, pblockindex, 1)) { + throw std::runtime_error( + strprintf("Cannot read block height %d (%s) from disk", pindex->GetHeight(), pindex->GetBlockHash().GetHex())); + } pblock = █ for (const CTransaction& tx : block.vtx) { @@ -1102,7 +1105,10 @@ void CWallet::BuildWitnessCache(const CBlockIndex* pindex, bool witnessOnly) //Cycle through blocks and transactions building sapling tree until the commitment needed is reached CBlock block; - ReadBlockFromDisk(block, pblockindex, 1); + if (!ReadBlockFromDisk(block, pblockindex, 1)) { + throw std::runtime_error( + strprintf("Cannot read block height %d (%s) from disk", pindex->GetHeight(), pindex->GetBlockHash().GetHex())); + } for (std::pair& wtxItem : mapWallet) { @@ -2721,7 +2727,11 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate) CBlock block; bool involvesMe = false; - ReadBlockFromDisk(block, pindex,1); + if (!ReadBlockFromDisk(block, pindex,1)) { + throw std::runtime_error( + strprintf("Cannot read block height %d (%s) from disk", pindex->GetHeight(), pindex->GetBlockHash().GetHex())); + } + BOOST_FOREACH(CTransaction& tx, block.vtx) { if (AddToWalletIfInvolvingMe(tx, &block, fUpdate)) { From 43e0ec186b50b596008496ed8d044f0a2a79b485 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Sat, 3 Sep 2022 09:13:19 -0400 Subject: [PATCH 02/12] Get rid of CLIENT_DATE --- src/clientversion.cpp | 9 --------- src/clientversion.h | 1 - src/init.cpp | 2 +- src/wallet/rpcdump.cpp | 2 +- 4 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/clientversion.cpp b/src/clientversion.cpp index 5702fbb95..cd6126eb1 100644 --- a/src/clientversion.cpp +++ b/src/clientversion.cpp @@ -104,16 +104,7 @@ const std::string CLIENT_NAME = GetArg("-clientname", "GoldenSandtrout"); #endif #endif -#ifndef BUILD_DATE -#ifdef GIT_COMMIT_DATE -#define BUILD_DATE GIT_COMMIT_DATE -#else -#define BUILD_DATE __DATE__ ", " __TIME__ -#endif -#endif - const std::string CLIENT_BUILD(BUILD_DESC CLIENT_VERSION_SUFFIX); -const std::string CLIENT_DATE(BUILD_DATE); std::string FormatVersion(int nVersion) { diff --git a/src/clientversion.h b/src/clientversion.h index 1b2802b35..03657120e 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -73,7 +73,6 @@ static const int CLIENT_VERSION = extern const std::string CLIENT_NAME; extern const std::string CLIENT_BUILD; -extern const std::string CLIENT_DATE; std::string FormatVersion(int nVersion); diff --git a/src/init.cpp b/src/init.cpp index e057282be..6c0b81b75 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1063,7 +1063,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); - LogPrintf("Hush version %s (%s)\n", FormatFullVersion(), CLIENT_DATE); + LogPrintf("Hush version %s (%s)\n", FormatFullVersion()); // when specifying an explicit binding address, you want to listen on it // even when -connect or -proxy is specified diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index db2727923..8b3b932c1 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -677,7 +677,7 @@ UniValue dumpwallet_impl(const UniValue& params, bool fHelp, bool fDumpZKeys) std::sort(vKeyBirth.begin(), vKeyBirth.end()); // produce output - file << strprintf("# Wallet dump created by Hush %s (%s)\n", CLIENT_BUILD, CLIENT_DATE); + file << strprintf("# Wallet dump created by Hush %s (%s)\n", CLIENT_BUILD); file << strprintf("# * Created on %s\n", EncodeDumpTime(GetTime())); file << strprintf("# * Best block at time of backup was %i (%s),\n", chainActive.Height(), chainActive.Tip()->GetBlockHash().ToString()); file << strprintf("# mined on %s\n", EncodeDumpTime(chainActive.Tip()->GetBlockTime())); From b9101e67ab7703b064006f7e018463fe7a49684d Mon Sep 17 00:00:00 2001 From: jahway603 Date: Sat, 3 Sep 2022 09:20:09 -0400 Subject: [PATCH 03/12] removed unused file --- share/genbuild.sh | 51 ----------------------------------------------- 1 file changed, 51 deletions(-) delete mode 100755 share/genbuild.sh diff --git a/share/genbuild.sh b/share/genbuild.sh deleted file mode 100755 index a15cb34e4..000000000 --- a/share/genbuild.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/sh -if [ $# -gt 1 ]; then - cd "$2" -fi -if [ $# -gt 0 ]; then - FILE="$1" - shift - if [ -f "$FILE" ]; then - INFO="$(head -n 1 "$FILE")" - fi -else - echo "Usage: $0 " - exit 1 -fi - -DESC="" -SUFFIX="" -LAST_COMMIT_DATE="" -if [ -e "$(which git 2>/dev/null)" -a "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then - # clean 'dirty' status of touched files that haven't been modified - git diff >/dev/null 2>/dev/null - - # if latest commit is tagged and not dirty, then override using the tag name - RAWDESC=$(git describe --abbrev=0 2>/dev/null) - if [ "$(git rev-parse HEAD)" = "$(git rev-list -1 $RAWDESC 2>/dev/null)" ]; then - git diff-index --quiet HEAD -- && DESC=$RAWDESC - fi - - # otherwise generate suffix from git, i.e. string like "59887e8-dirty" - SUFFIX=$(git rev-parse --short HEAD) - git diff-index --quiet HEAD -- || SUFFIX="$SUFFIX-dirty" - - # get a string like "2012-04-10 16:27:19 +0200" - LAST_COMMIT_DATE="$(git log -n 1 --format="%ci")" -fi - -if [ -n "$DESC" ]; then - NEWINFO="#define BUILD_DESC \"$DESC\"" -elif [ -n "$SUFFIX" ]; then - NEWINFO="#define BUILD_SUFFIX $SUFFIX" -else - NEWINFO="// No build information available" -fi - -# only update build.h if necessary -if [ "$INFO" != "$NEWINFO" ]; then - echo "$NEWINFO" >"$FILE" - if [ -n "$LAST_COMMIT_DATE" ]; then - echo "#define BUILD_DATE \"$LAST_COMMIT_DATE\"" >> "$FILE" - fi -fi From 8ea5438a1615dfd135481519ab48ca9a5a37a813 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Sat, 3 Sep 2022 09:26:55 -0400 Subject: [PATCH 04/12] updated .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index b2010491e..9fc50df80 100644 --- a/.gitignore +++ b/.gitignore @@ -31,7 +31,6 @@ libtool src/config/bitcoin-config.h src/config/bitcoin-config.h.in src/config/stamp-h1 -share/setup.nsi cache/ venv-mnf/ From 658160ce6cf73367020fb63e184e745a29ae5ac3 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Sat, 3 Sep 2022 09:44:59 -0400 Subject: [PATCH 05/12] still removing CLIENT_DATE --- src/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index 6c0b81b75..e9adae1f4 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1501,7 +1501,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) //fprintf(stderr,"%s tik12\n", __FUNCTION__); LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); - LogPrintf("Hush version %s (%s)\n", FormatFullVersion(), CLIENT_DATE); + LogPrintf("Hush version %s\n", FormatFullVersion()); if (fPrintToDebugLog) OpenDebugLog(); From 1085d15a2df6efd0b875e007ce4e68925b9da904 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Sat, 3 Sep 2022 09:51:59 -0400 Subject: [PATCH 06/12] Revert "removed unused file" This reverts commit b9101e67ab7703b064006f7e018463fe7a49684d. --- share/genbuild.sh | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 share/genbuild.sh diff --git a/share/genbuild.sh b/share/genbuild.sh new file mode 100755 index 000000000..a15cb34e4 --- /dev/null +++ b/share/genbuild.sh @@ -0,0 +1,51 @@ +#!/bin/sh +if [ $# -gt 1 ]; then + cd "$2" +fi +if [ $# -gt 0 ]; then + FILE="$1" + shift + if [ -f "$FILE" ]; then + INFO="$(head -n 1 "$FILE")" + fi +else + echo "Usage: $0 " + exit 1 +fi + +DESC="" +SUFFIX="" +LAST_COMMIT_DATE="" +if [ -e "$(which git 2>/dev/null)" -a "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then + # clean 'dirty' status of touched files that haven't been modified + git diff >/dev/null 2>/dev/null + + # if latest commit is tagged and not dirty, then override using the tag name + RAWDESC=$(git describe --abbrev=0 2>/dev/null) + if [ "$(git rev-parse HEAD)" = "$(git rev-list -1 $RAWDESC 2>/dev/null)" ]; then + git diff-index --quiet HEAD -- && DESC=$RAWDESC + fi + + # otherwise generate suffix from git, i.e. string like "59887e8-dirty" + SUFFIX=$(git rev-parse --short HEAD) + git diff-index --quiet HEAD -- || SUFFIX="$SUFFIX-dirty" + + # get a string like "2012-04-10 16:27:19 +0200" + LAST_COMMIT_DATE="$(git log -n 1 --format="%ci")" +fi + +if [ -n "$DESC" ]; then + NEWINFO="#define BUILD_DESC \"$DESC\"" +elif [ -n "$SUFFIX" ]; then + NEWINFO="#define BUILD_SUFFIX $SUFFIX" +else + NEWINFO="// No build information available" +fi + +# only update build.h if necessary +if [ "$INFO" != "$NEWINFO" ]; then + echo "$NEWINFO" >"$FILE" + if [ -n "$LAST_COMMIT_DATE" ]; then + echo "#define BUILD_DATE \"$LAST_COMMIT_DATE\"" >> "$FILE" + fi +fi From 7fc594d220830226777799400b59a17999b02ba1 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Sat, 3 Sep 2022 09:56:55 -0400 Subject: [PATCH 07/12] edits to genbuild.sh --- share/genbuild.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/share/genbuild.sh b/share/genbuild.sh index a15cb34e4..efe083f05 100755 --- a/share/genbuild.sh +++ b/share/genbuild.sh @@ -15,7 +15,6 @@ fi DESC="" SUFFIX="" -LAST_COMMIT_DATE="" if [ -e "$(which git 2>/dev/null)" -a "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then # clean 'dirty' status of touched files that haven't been modified git diff >/dev/null 2>/dev/null @@ -30,8 +29,6 @@ if [ -e "$(which git 2>/dev/null)" -a "$(git rev-parse --is-inside-work-tree 2>/ SUFFIX=$(git rev-parse --short HEAD) git diff-index --quiet HEAD -- || SUFFIX="$SUFFIX-dirty" - # get a string like "2012-04-10 16:27:19 +0200" - LAST_COMMIT_DATE="$(git log -n 1 --format="%ci")" fi if [ -n "$DESC" ]; then @@ -45,7 +42,4 @@ fi # only update build.h if necessary if [ "$INFO" != "$NEWINFO" ]; then echo "$NEWINFO" >"$FILE" - if [ -n "$LAST_COMMIT_DATE" ]; then - echo "#define BUILD_DATE \"$LAST_COMMIT_DATE\"" >> "$FILE" - fi fi From bf51d37e5dc20687f2bb820c0c95c6b6a7907032 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Sat, 3 Sep 2022 10:09:46 -0400 Subject: [PATCH 08/12] added copyright to genbuild.sh --- share/genbuild.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/share/genbuild.sh b/share/genbuild.sh index efe083f05..d4dc35ed4 100755 --- a/share/genbuild.sh +++ b/share/genbuild.sh @@ -1,4 +1,7 @@ #!/bin/sh +# Copyright (c) 2018-2022 The Hush developers +# Distributed under the GPLv3 software license, see the accompanying +# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html if [ $# -gt 1 ]; then cd "$2" fi From 325dcec0ac790cae2dc2ed931f4ad73fab30483c Mon Sep 17 00:00:00 2001 From: jahway603 Date: Sat, 3 Sep 2022 10:22:00 -0400 Subject: [PATCH 09/12] remove unused function GetKeyID_NoCheck --- src/base58.cpp | 8 -------- src/base58.h | 2 -- 2 files changed, 10 deletions(-) diff --git a/src/base58.cpp b/src/base58.cpp index d46894ea0..831a4842e 100644 --- a/src/base58.cpp +++ b/src/base58.cpp @@ -323,14 +323,6 @@ bool CBitcoinAddress::GetKeyID(CKeyID& keyID) const return true; } -bool CBitcoinAddress::GetKeyID_NoCheck(CKeyID& keyID) const -{ - uint160 id; - memcpy(&id, &vchData[0], 20); - keyID = CKeyID(id); - return true; -} - bool CBitcoinAddress::IsScript() const { return IsValid() && vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS); diff --git a/src/base58.h b/src/base58.h index 6fa3f457f..1032a4f00 100644 --- a/src/base58.h +++ b/src/base58.h @@ -146,7 +146,6 @@ public: CTxDestination Get() const; bool GetKeyID(CKeyID &keyID) const; - bool GetKeyID_NoCheck(CKeyID& keyID) const; bool GetIndexKey(uint160& hashBytes, int& type, bool ccflag) const; bool IsScript() const; }; @@ -171,7 +170,6 @@ public: CTxDestination Get() const; bool GetKeyID(CKeyID &keyID) const; - bool GetKeyID_NoCheck(CKeyID& keyID) const; bool GetIndexKey(uint160& hashBytes, int& type, bool ccflag) const; bool IsScript() const; }; From 3e75a2be225b7f3bdfc5394a53658725af8c7971 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Wed, 7 Sep 2022 00:35:08 -0400 Subject: [PATCH 10/12] delete unused zcbenchmarks --- src/Makefile.am | 2 - src/wallet/rpcwallet.cpp | 1 - src/zcbenchmarks.cpp | 405 --------------------------------------- src/zcbenchmarks.h | 27 --- 4 files changed, 435 deletions(-) delete mode 100644 src/zcbenchmarks.cpp delete mode 100644 src/zcbenchmarks.h diff --git a/src/Makefile.am b/src/Makefile.am index 5d73c049f..5364a6366 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -340,8 +340,6 @@ endif libbitcoin_wallet_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) libbitcoin_wallet_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) libbitcoin_wallet_a_SOURCES = \ - zcbenchmarks.cpp \ - zcbenchmarks.h \ wallet/asyncrpcoperation_mergetoaddress.cpp \ wallet/asyncrpcoperation_saplingconsolidation.cpp \ wallet/asyncrpcoperation_sendmany.cpp \ diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 42a145b94..c4827df02 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -33,7 +33,6 @@ #include "wallet.h" #include "walletdb.h" #include "primitives/transaction.h" -#include "zcbenchmarks.h" #include "script/interpreter.h" #include "zcash/zip32.h" #include "zcash/Note.hpp" diff --git a/src/zcbenchmarks.cpp b/src/zcbenchmarks.cpp deleted file mode 100644 index 3476918e6..000000000 --- a/src/zcbenchmarks.cpp +++ /dev/null @@ -1,405 +0,0 @@ -// Copyright (c) 2016-2021 The Hush developers -// Distributed under the GPLv3 software license, see the accompanying -// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html - -#include -#include -#include -#include -#include -#include -#include "coins.h" -#include "util.h" -#include "init.h" -#include "primitives/transaction.h" -#include "base58.h" -#include "crypto/equihash.h" -#include "chain.h" -#include "chainparams.h" -#include "consensus/upgrades.h" -#include "consensus/validation.h" -#include "main.h" -#include "miner.h" -#include "pow.h" -#include "rpc/server.h" -#include "script/sign.h" -#include "sodium.h" -#include "streams.h" -#include "txdb.h" -#include "wallet/wallet.h" -#include "zcbenchmarks.h" -#include "zcash/Zcash.h" -#include "zcash/IncrementalMerkleTree.hpp" -#include "zcash/Note.hpp" -#include "librustzcash.h" - -using namespace libzcash; -// This method is based on Shutdown from init.cpp -void pre_wallet_load() -{ - LogPrintf("%s: In progress...\n", __func__); - if (ShutdownRequested()) - throw new std::runtime_error("The Hush node is shutting down"); - - if (pwalletMain) - pwalletMain->Flush(false); -#ifdef ENABLE_MINING - GenerateBitcoins(false, NULL, 0); -#endif - UnregisterNodeSignals(GetNodeSignals()); - if (pwalletMain) - pwalletMain->Flush(true); - - UnregisterValidationInterface(pwalletMain); - delete pwalletMain; - pwalletMain = NULL; - bitdb.Reset(); - RegisterNodeSignals(GetNodeSignals()); - LogPrintf("%s: done\n", __func__); -} - -void post_wallet_load(){ - RegisterValidationInterface(pwalletMain); -#ifdef ENABLE_MINING - // Generate coins in the background - if (pwalletMain || !GetArg("-mineraddress", "").empty()) - GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", 1)); -#endif -} - - -void timer_start(timeval &tv_start) -{ - gettimeofday(&tv_start, 0); -} - -double timer_stop(timeval &tv_start) -{ - double elapsed; - struct timeval tv_end; - gettimeofday(&tv_end, 0); - elapsed = double(tv_end.tv_sec-tv_start.tv_sec) + - (tv_end.tv_usec-tv_start.tv_usec)/double(1000000); - return elapsed; -} - -double benchmark_sleep() -{ - struct timeval tv_start; - timer_start(tv_start); - sleep(1); - return timer_stop(tv_start); -} - -#ifdef ENABLE_MINING -double benchmark_solve_equihash() -{ - CBlock pblock; - CEquihashInput I{pblock}; - CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); - ss << I; - - unsigned int n = Params(CBaseChainParams::MAIN).EquihashN(); - unsigned int k = Params(CBaseChainParams::MAIN).EquihashK(); - crypto_generichash_blake2b_state eh_state; - EhInitialiseState(n, k, eh_state); - crypto_generichash_blake2b_update(&eh_state, (unsigned char*)&ss[0], ss.size()); - - uint256 nonce; - randombytes_buf(nonce.begin(), 32); - crypto_generichash_blake2b_update(&eh_state, - nonce.begin(), - nonce.size()); - - struct timeval tv_start; - timer_start(tv_start); - std::set> solns; - EhOptimisedSolveUncancellable(n, k, eh_state, - [](std::vector soln) { return false; }); - return timer_stop(tv_start); -} - -std::vector benchmark_solve_equihash_threaded(int nThreads) -{ - std::vector ret; - std::vector> tasks; - std::vector threads; - for (int i = 0; i < nThreads; i++) { - std::packaged_task task(&benchmark_solve_equihash); - tasks.emplace_back(task.get_future()); - threads.emplace_back(std::move(task)); - } - std::future_status status; - for (auto it = tasks.begin(); it != tasks.end(); it++) { - it->wait(); - ret.push_back(it->get()); - } - for (auto it = threads.begin(); it != threads.end(); it++) { - it->join(); - } - return ret; -} -#endif // ENABLE_MINING - -double benchmark_verify_equihash() -{ - CChainParams params = Params(CBaseChainParams::MAIN); - CBlock genesis = Params(CBaseChainParams::MAIN).GenesisBlock(); - CBlockHeader genesis_header = genesis.GetBlockHeader(); - struct timeval tv_start; - timer_start(tv_start); - CheckEquihashSolution(&genesis_header, params); - return timer_stop(tv_start); -} - -double benchmark_large_tx(size_t nInputs) -{ - // Create priv/pub key - CKey priv; - priv.MakeNewKey(false); - auto pub = priv.GetPubKey(); - CBasicKeyStore tempKeystore; - tempKeystore.AddKey(priv); - - // The "original" transaction that the spending transaction will spend - // from. - CMutableTransaction m_orig_tx; - m_orig_tx.vout.resize(1); - m_orig_tx.vout[0].nValue = 1000000; - CScript prevPubKey = GetScriptForDestination(pub.GetID()); - m_orig_tx.vout[0].scriptPubKey = prevPubKey; - - auto orig_tx = CTransaction(m_orig_tx); - - CMutableTransaction spending_tx; - spending_tx.fOverwintered = true; - spending_tx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; - spending_tx.nVersion = SAPLING_TX_VERSION; - - auto input_hash = orig_tx.GetHash(); - // Add nInputs inputs - for (size_t i = 0; i < nInputs; i++) { - spending_tx.vin.emplace_back(input_hash, 0); - } - - // Sign for all the inputs - auto consensusBranchId = NetworkUpgradeInfo[Consensus::UPGRADE_SAPLING].nBranchId; - for (size_t i = 0; i < nInputs; i++) { - SignSignature(tempKeystore, prevPubKey, spending_tx, i, 1000000, SIGHASH_ALL, consensusBranchId); - } - - // Spending tx has all its inputs signed and does not need to be mutated anymore - CTransaction final_spending_tx(spending_tx); - - // Benchmark signature verification costs: - struct timeval tv_start; - timer_start(tv_start); - PrecomputedTransactionData txdata(final_spending_tx); - for (size_t i = 0; i < nInputs; i++) { - ScriptError serror = SCRIPT_ERR_OK; - assert(VerifyScript(final_spending_tx.vin[i].scriptSig, - prevPubKey, - STANDARD_SCRIPT_VERIFY_FLAGS, - TransactionSignatureChecker(&final_spending_tx, i, 1000000, txdata), - consensusBranchId, - &serror)); - } - return timer_stop(tv_start); -} - -extern UniValue getnewaddress(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp -extern UniValue sendtoaddress(const UniValue& params, bool fHelp, const CPubKey& mypk); - -double benchmark_sendtoaddress(CAmount amount) -{ - UniValue params(UniValue::VARR); - auto addr = getnewaddress(params, false, CPubKey()); - - params.push_back(addr); - params.push_back(ValueFromAmount(amount)); - - struct timeval tv_start; - timer_start(tv_start); - auto txid = sendtoaddress(params, false, CPubKey()); - return timer_stop(tv_start); -} - -double benchmark_loadwallet() -{ - pre_wallet_load(); - struct timeval tv_start; - bool fFirstRunRet=true; - timer_start(tv_start); - pwalletMain = new CWallet("wallet.dat"); - DBErrors nLoadWalletRet = pwalletMain->LoadWallet(fFirstRunRet); - auto res = timer_stop(tv_start); - post_wallet_load(); - return res; -} - -extern UniValue listunspent(const UniValue& params, bool fHelp, const CPubKey& mypk); - -double benchmark_listunspent() -{ - UniValue params(UniValue::VARR); - struct timeval tv_start; - timer_start(tv_start); - auto unspent = listunspent(params, false, CPubKey()); - return timer_stop(tv_start); -} - -double benchmark_create_sapling_spend() -{ - auto sk = libzcash::SaplingSpendingKey::random(); - auto expsk = sk.expanded_spending_key(); - auto address = sk.default_address(); - SaplingNote note(address, GetRand(MAX_MONEY)); - SaplingMerkleTree tree; - auto maybe_cm = note.cm(); - tree.append(maybe_cm.get()); - auto anchor = tree.root(); - auto witness = tree.witness(); - auto maybe_nf = note.nullifier(expsk.full_viewing_key(), witness.position()); - if (!(maybe_cm && maybe_nf)) { - throw JSONRPCError(RPC_INTERNAL_ERROR, "Could not create note commitment and nullifier"); - } - - CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); - ss << witness.path(); - std::vector witnessChars(ss.begin(), ss.end()); - - uint256 alpha; - librustzcash_sapling_generate_r(alpha.begin()); - - auto ctx = librustzcash_sapling_proving_ctx_init(); - - struct timeval tv_start; - timer_start(tv_start); - - SpendDescription sdesc; - bool result = librustzcash_sapling_spend_proof( - ctx, - expsk.full_viewing_key().ak.begin(), - expsk.nsk.begin(), - note.d.data(), - note.r.begin(), - alpha.begin(), - note.value(), - anchor.begin(), - witnessChars.data(), - sdesc.cv.begin(), - sdesc.rk.begin(), - sdesc.zkproof.data()); - - double t = timer_stop(tv_start); - librustzcash_sapling_proving_ctx_free(ctx); - if (!result) { - throw JSONRPCError(RPC_INTERNAL_ERROR, "librustzcash_sapling_spend_proof() should return true"); - } - return t; -} - -double benchmark_create_sapling_output() -{ - auto sk = libzcash::SaplingSpendingKey::random(); - auto address = sk.default_address(); - - std::array memo; - SaplingNote note(address, GetRand(MAX_MONEY)); - - libzcash::SaplingNotePlaintext notePlaintext(note, memo); - auto res = notePlaintext.encrypt(note.pk_d); - if (!res) { - throw JSONRPCError(RPC_INTERNAL_ERROR, "SaplingNotePlaintext::encrypt() failed"); - } - - auto enc = res.get(); - auto encryptor = enc.second; - - auto ctx = librustzcash_sapling_proving_ctx_init(); - - struct timeval tv_start; - timer_start(tv_start); - - OutputDescription odesc; - bool result = librustzcash_sapling_output_proof( - ctx, - encryptor.get_esk().begin(), - note.d.data(), - note.pk_d.begin(), - note.r.begin(), - note.value(), - odesc.cv.begin(), - odesc.zkproof.begin()); - - double t = timer_stop(tv_start); - librustzcash_sapling_proving_ctx_free(ctx); - if (!result) { - throw JSONRPCError(RPC_INTERNAL_ERROR, "librustzcash_sapling_output_proof() should return true"); - } - return t; -} - -// Verify Sapling spend from testnet -// txid: abbd823cbd3d4e3b52023599d81a96b74817e95ce5bb58354f979156bd22ecc8 -// position: 0 -double benchmark_verify_sapling_spend() -{ - SpendDescription spend; - CDataStream ss(ParseHex("8c6cf86bbb83bf0d075e5bd9bb4b5cd56141577be69f032880b11e26aa32aa5ef09fd00899e4b469fb11f38e9d09dc0379f0b11c23b5fe541765f76695120a03f0261d32af5d2a2b1e5c9a04200cd87d574dc42349de9790012ce560406a8a876a1e54cfcdc0eb74998abec2a9778330eeb2a0ac0e41d0c9ed5824fbd0dbf7da930ab299966ce333fd7bc1321dada0817aac5444e02c754069e218746bf879d5f2a20a8b028324fb2c73171e63336686aa5ec2e6e9a08eb18b87c14758c572f4531ccf6b55d09f44beb8b47563be4eff7a52598d80959dd9c9fee5ac4783d8370cb7d55d460053d3e067b5f9fe75ff2722623fb1825fcba5e9593d4205b38d1f502ff03035463043bd393a5ee039ce75a5d54f21b395255df6627ef96751566326f7d4a77d828aa21b1827282829fcbc42aad59cdb521e1a3aaa08b99ea8fe7fff0a04da31a52260fc6daeccd79bb877bdd8506614282258e15b3fe74bf71a93f4be3b770119edf99a317b205eea7d5ab800362b97384273888106c77d633600"), SER_NETWORK, PROTOCOL_VERSION); - ss >> spend; - uint256 dataToBeSigned = uint256S("0x2dbf83fe7b88a7cbd80fac0c719483906bb9a0c4fc69071e4780d5f2c76e592c"); - - auto ctx = librustzcash_sapling_verification_ctx_init(); - - struct timeval tv_start; - timer_start(tv_start); - - bool result = librustzcash_sapling_check_spend( - ctx, - spend.cv.begin(), - spend.anchor.begin(), - spend.nullifier.begin(), - spend.rk.begin(), - spend.zkproof.begin(), - spend.spendAuthSig.begin(), - dataToBeSigned.begin() - ); - - double t = timer_stop(tv_start); - librustzcash_sapling_verification_ctx_free(ctx); - if (!result) { - throw JSONRPCError(RPC_INTERNAL_ERROR, "librustzcash_sapling_check_spend() should return true"); - } - return t; -} - -// Verify Sapling output from testnet -// txid: abbd823cbd3d4e3b52023599d81a96b74817e95ce5bb58354f979156bd22ecc8 -// position: 0 -double benchmark_verify_sapling_output() -{ - OutputDescription output; - CDataStream ss(ParseHex("edd742af18857e5ec2d71d346a7fe2ac97c137339bd5268eea86d32e0ff4f38f76213fa8cfed3347ac4e8572dd88aff395c0c10a59f8b3f49d2bc539ed6c726667e29d4763f914ddd0abf1cdfa84e44de87c233434c7e69b8b5b8f4623c8aa444163425bae5cef842972fed66046c1c6ce65c866ad894d02e6e6dcaae7a962d9f2ef95757a09c486928e61f0f7aed90ad0a542b0d3dc5fe140dfa7626b9315c77e03b055f19cbacd21a866e46f06c00e0c7792b2a590a611439b510a9aaffcf1073bad23e712a9268b36888e3727033eee2ab4d869f54a843f93b36ef489fb177bf74b41a9644e5d2a0a417c6ac1c8869bc9b83273d453f878ed6fd96b82a5939903f7b64ecaf68ea16e255a7fb7cc0b6d8b5608a1c6b0ed3024cc62c2f0f9c5cfc7b431ae6e9d40815557aa1d010523f9e1960de77b2274cb6710d229d475c87ae900183206ba90cb5bbc8ec0df98341b82726c705e0308ca5dc08db4db609993a1046dfb43dfd8c760be506c0bed799bb2205fc29dc2e654dce731034a23b0aaf6da0199248702ee0523c159f41f4cbfff6c35ace4dd9ae834e44e09c76a0cbdda1d3f6a2c75ad71212daf9575ab5f09ca148718e667f29ddf18c8a330a86ace18a86e89454653902aa393c84c6b694f27d0d42e24e7ac9fe34733de5ec15f5066081ce912c62c1a804a2bb4dedcef7cc80274f6bb9e89e2fce91dc50d6a73c8aefb9872f1cf3524a92626a0b8f39bbf7bf7d96ca2f770fc04d7f457021c536a506a187a93b2245471ddbfb254a71bc4a0d72c8d639a31c7b1920087ffca05c24214157e2e7b28184e91989ef0b14f9b34c3dc3cc0ac64226b9e337095870cb0885737992e120346e630a416a9b217679ce5a778fb15779c136bcecca5efe79012013d77d90b4e99dd22c8f35bc77121716e160d05bd30d288ee8886390ee436f85bdc9029df888a3a3326d9d4ddba5cb5318b3274928829d662e96fea1d601f7a306251ed8c6cc4e5a3a7a98c35a3650482a0eee08f3b4c2da9b22947c96138f1505c2f081f8972d429f3871f32bef4aaa51aa6945df8e9c9760531ac6f627d17c1518202818a91ca304fb4037875c666060597976144fcbbc48a776a2c61beb9515fa8f3ae6d3a041d320a38a8ac75cb47bb9c866ee497fc3cd13299970c4b369c1c2ceb4220af082fbecdd8114492a8e4d713b5a73396fd224b36c1185bd5e20d683e6c8db35346c47ae7401988255da7cfffdced5801067d4d296688ee8fe424b4a8a69309ce257eefb9345ebfda3f6de46bb11ec94133e1f72cd7ac54934d6cf17b3440800e70b80ebc7c7bfc6fb0fc2c"), SER_NETWORK, PROTOCOL_VERSION); - ss >> output; - - auto ctx = librustzcash_sapling_verification_ctx_init(); - - struct timeval tv_start; - timer_start(tv_start); - - bool result = librustzcash_sapling_check_output( - ctx, - output.cv.begin(), - output.cm.begin(), - output.ephemeralKey.begin(), - output.zkproof.begin() - ); - - double t = timer_stop(tv_start); - librustzcash_sapling_verification_ctx_free(ctx); - if (!result) { - throw JSONRPCError(RPC_INTERNAL_ERROR, "librustzcash_sapling_check_output() should return true"); - } - return timer_stop(tv_start); -} diff --git a/src/zcbenchmarks.h b/src/zcbenchmarks.h deleted file mode 100644 index c79081bc2..000000000 --- a/src/zcbenchmarks.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2016-2021 The Hush developers -#ifndef BENCHMARKS_H -#define BENCHMARKS_H - -#include -#include - -extern double benchmark_sleep(); -extern double benchmark_create_joinsplit(); -extern std::vector benchmark_create_joinsplit_threaded(int nThreads); -extern double benchmark_solve_equihash(); -extern std::vector benchmark_solve_equihash_threaded(int nThreads); -extern double benchmark_verify_joinsplit(const JSDescription &joinsplit); -extern double benchmark_verify_equihash(); -extern double benchmark_large_tx(size_t nInputs); -extern double benchmark_try_decrypt_notes(size_t nAddrs); -extern double benchmark_increment_note_witnesses(size_t nTxs); -extern double benchmark_connectblock_slow(); -extern double benchmark_sendtoaddress(CAmount amount); -extern double benchmark_loadwallet(); -extern double benchmark_listunspent(); -extern double benchmark_create_sapling_spend(); -extern double benchmark_create_sapling_output(); -extern double benchmark_verify_sapling_spend(); -extern double benchmark_verify_sapling_output(); - -#endif From b2987b43f01ef04bcfc6c67557b4a1db904944d3 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Wed, 7 Sep 2022 01:10:53 -0400 Subject: [PATCH 11/12] miner: fix MAXSOLS --- src/miner.cpp | 2 +- src/test/miner_tests.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 71ce266ce..16c18146b 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1732,7 +1732,7 @@ void static BitcoinMiner() ehSolverRuns.increment(); // Convert solution indices to byte array (decompress) and pass it to validBlock method. - for (size_t s = 0; s < eq.nsols; s++) { + for (size_t s = 0; s < std::min(MAXSOLS, eq.nsols); s++) { LogPrint("pow", "Checking solution %d\n", s+1); std::vector index_vector(PROOFSIZE); for (size_t i = 0; i < PROOFSIZE; i++) { diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp index ed2777c6d..52f0a0211 100644 --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -225,7 +225,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) // Convert solution indices to byte array (decompress) and pass it to validBlock method. std::set> solns; - for (size_t s = 0; s < eq.nsols; s++) { + for (size_t s = 0; s < std::min(MAXSOLS, eq.nsols); s++) { LogPrint("pow", "Checking solution %d\n", s+1); std::vector index_vector(PROOFSIZE); for (size_t i = 0; i < PROOFSIZE; i++) { From b06c3788510556b99cc61a829cb7e3874d52323a Mon Sep 17 00:00:00 2001 From: jahway603 Date: Sun, 11 Sep 2022 18:01:11 -0400 Subject: [PATCH 12/12] removed unused function mta_find_output --- .../asyncrpcoperation_mergetoaddress.cpp | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/wallet/asyncrpcoperation_mergetoaddress.cpp b/src/wallet/asyncrpcoperation_mergetoaddress.cpp index ac462f5b8..d1f207571 100644 --- a/src/wallet/asyncrpcoperation_mergetoaddress.cpp +++ b/src/wallet/asyncrpcoperation_mergetoaddress.cpp @@ -52,24 +52,6 @@ using namespace libzcash; extern UniValue sendrawtransaction(const UniValue& params, bool fHelp, const CPubKey& mypk); -int mta_find_output(UniValue obj, int n) -{ - UniValue outputMapValue = find_value(obj, "outputmap"); - if (!outputMapValue.isArray()) { - throw JSONRPCError(RPC_WALLET_ERROR, "Missing outputmap for JoinSplit operation"); - } - - UniValue outputMap = outputMapValue.get_array(); - assert(outputMap.size() == HUSH_NUM_JS_OUTPUTS); - for (size_t i = 0; i < outputMap.size(); i++) { - if (outputMap[i].get_int() == n) { - return i; - } - } - - throw std::logic_error("n is not present in outputmap"); -} - AsyncRPCOperation_mergetoaddress::AsyncRPCOperation_mergetoaddress( boost::optional builder, CMutableTransaction contextualTx,