Skip to content

Commit

Permalink
Introduce zcsamplejoinsplit for creating a raw joinsplit descriptio…
Browse files Browse the repository at this point in the history
…n, and use it to construct the joinsplit for the performance tests that verify joinsplits.
  • Loading branch information
ebfull committed Jul 19, 2016
1 parent d20d866 commit 1737627
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 18 deletions.
17 changes: 14 additions & 3 deletions qa/zcash/performance-measurements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/rpcserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
1 change: 1 addition & 0 deletions src/rpcserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
46 changes: 32 additions & 14 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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++) {
Expand All @@ -2415,21 +2436,18 @@ 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") {
sample_times.push_back(benchmark_verify_equihash());
} 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;
Expand Down

0 comments on commit 1737627

Please sign in to comment.