Add benchmark for decrypting sapling notes
This commit is contained in:
parent
8f41036701
commit
89e75c8c0d
|
@ -5,6 +5,7 @@
|
|||
#include "utiltest.h"
|
||||
|
||||
#include "consensus/upgrades.h"
|
||||
#include "transaction_builder.h"
|
||||
|
||||
#include <array>
|
||||
|
||||
|
@ -153,3 +154,28 @@ CWalletTx GetValidSproutSpend(ZCJoinSplit& params,
|
|||
CWalletTx wtx {NULL, tx};
|
||||
return wtx;
|
||||
}
|
||||
|
||||
CWalletTx GetValidSaplingTx(const Consensus::Params& consensusParams,
|
||||
const libzcash::SaplingExtendedSpendingKey &sk,
|
||||
CAmount value) {
|
||||
auto expsk = sk.expsk;
|
||||
auto fvk = expsk.full_viewing_key();
|
||||
auto pk = sk.DefaultAddress();
|
||||
|
||||
// Generate dummy Sapling note
|
||||
libzcash::SaplingNote note(pk, value);
|
||||
auto cm = note.cm().get();
|
||||
SaplingMerkleTree tree;
|
||||
tree.append(cm);
|
||||
auto anchor = tree.root();
|
||||
auto witness = tree.witness();
|
||||
|
||||
auto builder = TransactionBuilder(consensusParams, 1);
|
||||
builder.SetFee(0);
|
||||
assert(builder.AddSaplingSpend(expsk, note, anchor, witness));
|
||||
builder.AddSaplingOutput(fvk.ovk, pk, value, {});
|
||||
|
||||
CTransaction tx = builder.Build().get();
|
||||
CWalletTx wtx {NULL, tx};
|
||||
return wtx;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,9 @@
|
|||
#include "zcash/JoinSplit.hpp"
|
||||
#include "zcash/Note.hpp"
|
||||
#include "zcash/NoteEncryption.hpp"
|
||||
#include "zcash/zip32.h"
|
||||
|
||||
// Sprout
|
||||
CWalletTx GetValidSproutReceive(ZCJoinSplit& params,
|
||||
const libzcash::SproutSpendingKey& sk,
|
||||
CAmount value,
|
||||
|
@ -19,3 +21,8 @@ CWalletTx GetValidSproutSpend(ZCJoinSplit& params,
|
|||
const libzcash::SproutSpendingKey& sk,
|
||||
const libzcash::SproutNote& note,
|
||||
CAmount value);
|
||||
|
||||
// Sapling
|
||||
CWalletTx GetValidSaplingTx(const Consensus::Params& consensusParams,
|
||||
const libzcash::SaplingExtendedSpendingKey &sk,
|
||||
CAmount value);
|
||||
|
|
|
@ -2778,7 +2778,10 @@ UniValue zc_benchmark(const UniValue& params, bool fHelp)
|
|||
sample_times.push_back(benchmark_large_tx(nInputs));
|
||||
} else if (benchmarktype == "trydecryptnotes") {
|
||||
int nAddrs = params[2].get_int();
|
||||
sample_times.push_back(benchmark_try_decrypt_notes(nAddrs));
|
||||
sample_times.push_back(benchmark_try_decrypt_sprout_notes(nAddrs));
|
||||
} else if (benchmarktype == "trydecryptsaplingnotes") {
|
||||
int nAddrs = params[2].get_int();
|
||||
sample_times.push_back(benchmark_try_decrypt_sapling_notes(nAddrs));
|
||||
} else if (benchmarktype == "incnotewitnesses") {
|
||||
int nTxs = params[2].get_int();
|
||||
sample_times.push_back(benchmark_increment_note_witnesses(nTxs));
|
||||
|
|
|
@ -280,7 +280,7 @@ double benchmark_large_tx(size_t nInputs)
|
|||
return timer_stop(tv_start);
|
||||
}
|
||||
|
||||
double benchmark_try_decrypt_notes(size_t nAddrs)
|
||||
double benchmark_try_decrypt_sprout_notes(size_t nAddrs)
|
||||
{
|
||||
CWallet wallet;
|
||||
for (int i = 0; i < nAddrs; i++) {
|
||||
|
@ -297,6 +297,42 @@ double benchmark_try_decrypt_notes(size_t nAddrs)
|
|||
return timer_stop(tv_start);
|
||||
}
|
||||
|
||||
double benchmark_try_decrypt_sapling_notes(size_t nAddrs)
|
||||
{
|
||||
// Set params
|
||||
SelectParams(CBaseChainParams::REGTEST);
|
||||
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_OVERWINTER, Consensus::NetworkUpgrade::ALWAYS_ACTIVE);
|
||||
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_SAPLING, Consensus::NetworkUpgrade::ALWAYS_ACTIVE);
|
||||
auto consensusParams = Params().GetConsensus();
|
||||
|
||||
std::vector<unsigned char, secure_allocator<unsigned char>> rawSeed(32);
|
||||
HDSeed seed(rawSeed);
|
||||
auto masterKey = libzcash::SaplingExtendedSpendingKey::Master(seed);
|
||||
|
||||
CWallet wallet;
|
||||
wallet.AddSaplingSpendingKey(masterKey, masterKey.DefaultAddress());
|
||||
|
||||
int i;
|
||||
for (i = 0; i < nAddrs; i++) {
|
||||
auto sk = masterKey.Derive(i);
|
||||
wallet.AddSaplingSpendingKey(sk, sk.DefaultAddress());
|
||||
}
|
||||
|
||||
auto sk = masterKey.Derive(i);
|
||||
auto tx = GetValidSaplingTx(consensusParams, sk, 10);
|
||||
|
||||
struct timeval tv_start;
|
||||
timer_start(tv_start);
|
||||
auto saplingNoteDataAndAddressesToAdd = wallet.FindMySaplingNotes(tx);
|
||||
double tv_stop = timer_stop(tv_start);
|
||||
|
||||
// Revert to default
|
||||
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_SAPLING, Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT);
|
||||
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_OVERWINTER, Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT);
|
||||
|
||||
return tv_stop;
|
||||
}
|
||||
|
||||
double benchmark_increment_note_witnesses(size_t nTxs)
|
||||
{
|
||||
CWallet wallet;
|
||||
|
|
|
@ -13,7 +13,8 @@ extern std::vector<double> 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_try_decrypt_sprout_notes(size_t nAddrs);
|
||||
extern double benchmark_try_decrypt_sapling_notes(size_t nAddrs);
|
||||
extern double benchmark_increment_note_witnesses(size_t nTxs);
|
||||
extern double benchmark_connectblock_slow();
|
||||
extern double benchmark_sendtoaddress(CAmount amount);
|
||||
|
|
Loading…
Reference in New Issue