diff --git a/qa/zcash/performance-measurements.sh b/qa/zcash/performance-measurements.sh index 064bef194..789cb69d5 100755 --- a/qa/zcash/performance-measurements.sh +++ b/qa/zcash/performance-measurements.sh @@ -52,6 +52,17 @@ function zcashd_valgrind_stop { cat valgrind.out } +# Precomputation +case "$1" in + *) + case "$2" in + verifyjoinsplit) + zcashd_start + RAWJOINSPLIT=$(zcash_rpc zcsamplejoinsplit) + zcashd_stop + esac +esac + case "$1" in time) zcashd_start @@ -66,7 +77,7 @@ case "$1" in zcash_rpc zcbenchmark createjoinsplit 10 ;; verifyjoinsplit) - zcash_rpc zcbenchmark verifyjoinsplit 1000 + zcash_rpc zcbenchmark verifyjoinsplit 1000 "$RAWJOINSPLIT" ;; solveequihash) zcash_rpc zcbenchmark solveequihash 10 @@ -97,7 +108,7 @@ case "$1" in zcash_rpc zcbenchmark createjoinsplit 1 ;; verifyjoinsplit) - zcash_rpc zcbenchmark verifyjoinsplit 1 + zcash_rpc zcbenchmark verifyjoinsplit 1 "$RAWJOINSPLIT" ;; solveequihash) zcash_rpc zcbenchmark solveequihash 1 @@ -126,7 +137,7 @@ case "$1" in zcash_rpc zcbenchmark createjoinsplit 1 ;; verifyjoinsplit) - zcash_rpc zcbenchmark verifyjoinsplit 1 + zcash_rpc zcbenchmark verifyjoinsplit 1 "$RAWJOINSPLIT" ;; solveequihash) zcash_rpc zcbenchmark solveequihash 1 diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 2b3a81dee..90a255401 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -380,7 +380,8 @@ static const CRPCCommand vRPCCommands[] = { "wallet", "zcbenchmark", &zc_benchmark, true }, { "wallet", "zcrawkeygen", &zc_raw_keygen, true }, { "wallet", "zcrawjoinsplit", &zc_raw_joinsplit, true }, - { "wallet", "zcrawreceive", &zc_raw_receive, true } + { "wallet", "zcrawreceive", &zc_raw_receive, true }, + { "wallet", "zcsamplejoinsplit", &zc_sample_joinsplit, true } #endif // ENABLE_WALLET }; diff --git a/src/rpcserver.h b/src/rpcserver.h index 3e9ba58d4..d90564891 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -212,6 +212,7 @@ extern json_spirit::Value zc_benchmark(const json_spirit::Array& params, bool fH extern json_spirit::Value zc_raw_keygen(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value zc_raw_joinsplit(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value zc_raw_receive(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value zc_sample_joinsplit(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getrawtransaction(const json_spirit::Array& params, bool fHelp); // in rcprawtransaction.cpp extern json_spirit::Value listunspent(const json_spirit::Array& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5b82600fa..7f1121e6e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2351,6 +2351,34 @@ Value listunspent(const Array& params, bool fHelp) return results; } +Value zc_sample_joinsplit(const json_spirit::Array& params, bool fHelp) +{ + if (fHelp) { + throw runtime_error( + "zcsamplejoinsplit\n" + "\n" + "Perform a joinsplit and return the JSDescription.\n" + ); + } + + LOCK(cs_main); + + uint256 pubKeyHash; + uint256 anchor = ZCIncrementalMerkleTree().root(); + JSDescription samplejoinsplit(*pzcashParams, + pubKeyHash, + anchor, + {JSInput(), JSInput()}, + {JSOutput(), JSOutput()}, + 0, + 0); + + CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); + ss << samplejoinsplit; + + return HexStr(ss.begin(), ss.end()); +} + Value zc_benchmark(const json_spirit::Array& params, bool fHelp) { if (!EnsureWalletIsAvailable(fHelp)) { @@ -2393,18 +2421,11 @@ Value zc_benchmark(const json_spirit::Array& params, bool fHelp) pzcashParams->loadProvingKey(); } - JSDescription* samplejoinsplit = NULL; + JSDescription samplejoinsplit; if (benchmarktype == "verifyjoinsplit") { - uint256 pubKeyHash; - uint256 anchor = ZCIncrementalMerkleTree().root(); - samplejoinsplit = new JSDescription(*pzcashParams, - pubKeyHash, - anchor, - {JSInput(), JSInput()}, - {JSOutput(), JSOutput()}, - 0, - 0); + CDataStream ss(ParseHexV(params[2].get_str(), "js"), SER_NETWORK, PROTOCOL_VERSION); + ss >> samplejoinsplit; } for (int i = 0; i < samplecount; i++) { @@ -2415,7 +2436,7 @@ Value zc_benchmark(const json_spirit::Array& params, bool fHelp) } else if (benchmarktype == "createjoinsplit") { sample_times.push_back(benchmark_create_joinsplit()); } else if (benchmarktype == "verifyjoinsplit") { - sample_times.push_back(benchmark_verify_joinsplit(*samplejoinsplit)); + sample_times.push_back(benchmark_verify_joinsplit(samplejoinsplit)); } else if (benchmarktype == "solveequihash") { sample_times.push_back(benchmark_solve_equihash()); } else if (benchmarktype == "verifyequihash") { @@ -2423,13 +2444,10 @@ Value zc_benchmark(const json_spirit::Array& params, bool fHelp) } else if (benchmarktype == "validatelargetx") { sample_times.push_back(benchmark_large_tx()); } else { - delete samplejoinsplit; throw JSONRPCError(RPC_TYPE_ERROR, "Invalid benchmarktype"); } } - delete samplejoinsplit; - Array results; for (int i = 0; i < samplecount; i++) { Object result;