2017-05-11 18:00:15 -07:00
|
|
|
#include <cstdio>
|
2016-08-10 05:45:31 -07:00
|
|
|
#include <future>
|
2017-05-11 18:00:15 -07:00
|
|
|
#include <map>
|
2016-08-10 05:45:31 -07:00
|
|
|
#include <thread>
|
2016-04-07 14:37:39 -07:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <boost/filesystem.hpp>
|
2016-08-10 05:45:31 -07:00
|
|
|
|
2016-04-07 14:37:39 -07:00
|
|
|
#include "coins.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "init.h"
|
|
|
|
#include "primitives/transaction.h"
|
2016-06-07 16:28:12 -07:00
|
|
|
#include "base58.h"
|
2016-04-11 07:05:13 -07:00
|
|
|
#include "crypto/equihash.h"
|
2017-05-11 18:00:15 -07:00
|
|
|
#include "chain.h"
|
2016-04-11 07:05:13 -07:00
|
|
|
#include "chainparams.h"
|
2018-02-01 17:49:42 -08:00
|
|
|
#include "consensus/upgrades.h"
|
2016-06-07 16:28:12 -07:00
|
|
|
#include "consensus/validation.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "miner.h"
|
2016-04-11 09:02:09 -07:00
|
|
|
#include "pow.h"
|
2017-08-17 02:31:47 -07:00
|
|
|
#include "rpcserver.h"
|
2016-06-07 16:28:12 -07:00
|
|
|
#include "script/sign.h"
|
2016-04-11 10:51:12 -07:00
|
|
|
#include "sodium.h"
|
|
|
|
#include "streams.h"
|
2017-05-11 18:00:15 -07:00
|
|
|
#include "txdb.h"
|
2016-11-17 01:26:46 -08:00
|
|
|
#include "utiltest.h"
|
2016-06-07 16:28:12 -07:00
|
|
|
#include "wallet/wallet.h"
|
2016-04-07 14:37:39 -07:00
|
|
|
|
|
|
|
#include "zcbenchmarks.h"
|
|
|
|
|
2016-05-04 17:26:21 -07:00
|
|
|
#include "zcash/Zcash.h"
|
|
|
|
#include "zcash/IncrementalMerkleTree.hpp"
|
|
|
|
|
|
|
|
using namespace libzcash;
|
2017-09-18 12:54:53 -07:00
|
|
|
// 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 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
|
|
|
|
}
|
|
|
|
|
2016-05-04 17:26:21 -07:00
|
|
|
|
2016-08-10 05:45:31 -07:00
|
|
|
void timer_start(timeval &tv_start)
|
2016-04-07 14:37:39 -07:00
|
|
|
{
|
|
|
|
gettimeofday(&tv_start, 0);
|
|
|
|
}
|
|
|
|
|
2016-08-10 05:45:31 -07:00
|
|
|
double timer_stop(timeval &tv_start)
|
2016-04-07 14:37:39 -07:00
|
|
|
{
|
|
|
|
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()
|
|
|
|
{
|
2016-08-10 05:45:31 -07:00
|
|
|
struct timeval tv_start;
|
|
|
|
timer_start(tv_start);
|
2016-04-07 14:37:39 -07:00
|
|
|
sleep(1);
|
2016-08-10 05:45:31 -07:00
|
|
|
return timer_stop(tv_start);
|
2016-04-07 14:37:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
double benchmark_parameter_loading()
|
|
|
|
{
|
|
|
|
// FIXME: this is duplicated with the actual loading code
|
2016-10-24 10:22:39 -07:00
|
|
|
boost::filesystem::path pk_path = ZC_GetParamsDir() / "sprout-proving.key";
|
|
|
|
boost::filesystem::path vk_path = ZC_GetParamsDir() / "sprout-verifying.key";
|
2016-04-07 14:37:39 -07:00
|
|
|
|
2016-08-10 05:45:31 -07:00
|
|
|
struct timeval tv_start;
|
|
|
|
timer_start(tv_start);
|
2016-05-04 17:26:21 -07:00
|
|
|
|
2017-04-07 09:24:53 -07:00
|
|
|
auto newParams = ZCJoinSplit::Prepared(vk_path.string(), pk_path.string());
|
2016-05-04 17:26:21 -07:00
|
|
|
|
2016-08-10 05:45:31 -07:00
|
|
|
double ret = timer_stop(tv_start);
|
2016-05-04 17:26:21 -07:00
|
|
|
|
|
|
|
delete newParams;
|
|
|
|
|
|
|
|
return ret;
|
2016-04-07 14:37:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
double benchmark_create_joinsplit()
|
|
|
|
{
|
2016-05-04 17:26:19 -07:00
|
|
|
uint256 pubKeyHash;
|
2016-04-07 14:37:39 -07:00
|
|
|
|
|
|
|
/* Get the anchor of an empty commitment tree. */
|
2016-05-04 17:25:38 -07:00
|
|
|
uint256 anchor = ZCIncrementalMerkleTree().root();
|
2016-04-07 14:37:39 -07:00
|
|
|
|
2016-08-10 05:45:31 -07:00
|
|
|
struct timeval tv_start;
|
|
|
|
timer_start(tv_start);
|
2016-07-16 15:45:41 -07:00
|
|
|
JSDescription jsdesc(*pzcashParams,
|
|
|
|
pubKeyHash,
|
|
|
|
anchor,
|
|
|
|
{JSInput(), JSInput()},
|
|
|
|
{JSOutput(), JSOutput()},
|
|
|
|
0,
|
|
|
|
0);
|
2016-08-10 05:45:31 -07:00
|
|
|
double ret = timer_stop(tv_start);
|
2016-05-04 17:26:19 -07:00
|
|
|
|
2016-11-23 23:03:12 -08:00
|
|
|
auto verifier = libzcash::ProofVerifier::Strict();
|
|
|
|
assert(jsdesc.Verify(*pzcashParams, verifier, pubKeyHash));
|
2016-04-07 14:37:39 -07:00
|
|
|
return ret;
|
|
|
|
}
|
2016-04-11 07:05:13 -07:00
|
|
|
|
2016-12-13 18:26:02 -08:00
|
|
|
std::vector<double> benchmark_create_joinsplit_threaded(int nThreads)
|
|
|
|
{
|
|
|
|
std::vector<double> ret;
|
|
|
|
std::vector<std::future<double>> tasks;
|
|
|
|
std::vector<std::thread> threads;
|
|
|
|
for (int i = 0; i < nThreads; i++) {
|
|
|
|
std::packaged_task<double(void)> task(&benchmark_create_joinsplit);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-07-10 22:02:10 -07:00
|
|
|
double benchmark_verify_joinsplit(const JSDescription &joinsplit)
|
2016-04-11 09:02:09 -07:00
|
|
|
{
|
2016-08-10 05:45:31 -07:00
|
|
|
struct timeval tv_start;
|
|
|
|
timer_start(tv_start);
|
2016-05-04 17:26:19 -07:00
|
|
|
uint256 pubKeyHash;
|
2016-11-23 23:03:12 -08:00
|
|
|
auto verifier = libzcash::ProofVerifier::Strict();
|
|
|
|
joinsplit.Verify(*pzcashParams, verifier, pubKeyHash);
|
2016-08-10 05:45:31 -07:00
|
|
|
return timer_stop(tv_start);
|
2016-04-11 09:02:09 -07:00
|
|
|
}
|
|
|
|
|
2016-11-06 11:40:34 -08:00
|
|
|
#ifdef ENABLE_MINING
|
2016-08-10 05:45:31 -07:00
|
|
|
double benchmark_solve_equihash()
|
2016-04-11 07:05:13 -07:00
|
|
|
{
|
2016-04-11 10:51:12 -07:00
|
|
|
CBlock pblock;
|
|
|
|
CEquihashInput I{pblock};
|
|
|
|
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
|
|
|
ss << I;
|
|
|
|
|
2016-05-04 20:00:44 -07:00
|
|
|
unsigned int n = Params(CBaseChainParams::MAIN).EquihashN();
|
|
|
|
unsigned int k = Params(CBaseChainParams::MAIN).EquihashK();
|
2016-04-11 07:05:13 -07:00
|
|
|
crypto_generichash_blake2b_state eh_state;
|
2016-05-04 20:00:44 -07:00
|
|
|
EhInitialiseState(n, k, eh_state);
|
2016-04-11 10:51:12 -07:00
|
|
|
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());
|
|
|
|
|
2016-08-10 05:45:31 -07:00
|
|
|
struct timeval tv_start;
|
|
|
|
timer_start(tv_start);
|
2016-05-04 20:00:44 -07:00
|
|
|
std::set<std::vector<unsigned int>> solns;
|
2016-07-27 00:15:49 -07:00
|
|
|
EhOptimisedSolveUncancellable(n, k, eh_state,
|
2016-08-13 20:04:13 -07:00
|
|
|
[](std::vector<unsigned char> soln) { return false; });
|
2016-08-10 05:45:31 -07:00
|
|
|
return timer_stop(tv_start);
|
2016-08-04 20:05:38 -07:00
|
|
|
}
|
|
|
|
|
2016-08-10 05:45:31 -07:00
|
|
|
std::vector<double> benchmark_solve_equihash_threaded(int nThreads)
|
2016-08-04 20:05:38 -07:00
|
|
|
{
|
2016-08-10 05:45:31 -07:00
|
|
|
std::vector<double> ret;
|
|
|
|
std::vector<std::future<double>> tasks;
|
|
|
|
std::vector<std::thread> threads;
|
|
|
|
for (int i = 0; i < nThreads; i++) {
|
|
|
|
std::packaged_task<double(void)> 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;
|
2016-04-11 07:05:13 -07:00
|
|
|
}
|
2016-11-06 11:40:34 -08:00
|
|
|
#endif // ENABLE_MINING
|
2016-04-11 08:17:02 -07:00
|
|
|
|
2016-04-11 09:02:09 -07:00
|
|
|
double benchmark_verify_equihash()
|
2016-04-11 08:17:02 -07:00
|
|
|
{
|
2016-04-11 09:02:09 -07:00
|
|
|
CChainParams params = Params(CBaseChainParams::MAIN);
|
|
|
|
CBlock genesis = Params(CBaseChainParams::MAIN).GenesisBlock();
|
|
|
|
CBlockHeader genesis_header = genesis.GetBlockHeader();
|
2016-08-10 05:45:31 -07:00
|
|
|
struct timeval tv_start;
|
|
|
|
timer_start(tv_start);
|
2016-04-11 09:02:09 -07:00
|
|
|
CheckEquihashSolution(&genesis_header, params);
|
2016-08-10 05:45:31 -07:00
|
|
|
return timer_stop(tv_start);
|
2016-04-11 08:17:02 -07:00
|
|
|
}
|
2016-04-11 09:02:09 -07:00
|
|
|
|
2018-02-07 14:56:22 -08:00
|
|
|
double benchmark_large_tx(size_t nInputs)
|
2016-06-07 16:28:12 -07:00
|
|
|
{
|
2016-07-06 11:07:50 -07:00
|
|
|
// 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;
|
2018-02-03 13:02:25 -08:00
|
|
|
spending_tx.fOverwintered = true;
|
|
|
|
spending_tx.nVersion = 3;
|
|
|
|
spending_tx.nVersionGroupId = OVERWINTER_VERSION_GROUP_ID;
|
|
|
|
|
2016-08-30 12:49:38 -07:00
|
|
|
auto input_hash = orig_tx.GetHash();
|
2018-02-07 14:56:22 -08:00
|
|
|
// Add nInputs inputs
|
|
|
|
for (size_t i = 0; i < nInputs; i++) {
|
2016-07-06 11:07:50 -07:00
|
|
|
spending_tx.vin.emplace_back(input_hash, 0);
|
2016-06-07 16:28:12 -07:00
|
|
|
}
|
|
|
|
|
2016-07-06 11:07:50 -07:00
|
|
|
// Sign for all the inputs
|
2018-02-01 17:49:42 -08:00
|
|
|
auto consensusBranchId = NetworkUpgradeInfo[Consensus::UPGRADE_OVERWINTER].nBranchId;
|
2018-02-07 14:56:22 -08:00
|
|
|
for (size_t i = 0; i < nInputs; i++) {
|
2018-02-01 17:49:42 -08:00
|
|
|
SignSignature(tempKeystore, prevPubKey, spending_tx, i, 1000000, SIGHASH_ALL, consensusBranchId);
|
2016-06-07 16:28:12 -07:00
|
|
|
}
|
|
|
|
|
2016-08-07 23:54:50 -07:00
|
|
|
// Spending tx has all its inputs signed and does not need to be mutated anymore
|
|
|
|
CTransaction final_spending_tx(spending_tx);
|
|
|
|
|
2016-07-06 11:07:50 -07:00
|
|
|
// Benchmark signature verification costs:
|
2016-08-10 05:45:31 -07:00
|
|
|
struct timeval tv_start;
|
|
|
|
timer_start(tv_start);
|
2018-02-03 13:02:25 -08:00
|
|
|
PrecomputedTransactionData txdata(final_spending_tx);
|
2018-02-07 14:56:22 -08:00
|
|
|
for (size_t i = 0; i < nInputs; i++) {
|
2016-07-06 11:07:50 -07:00
|
|
|
ScriptError serror = SCRIPT_ERR_OK;
|
2016-08-08 00:51:27 -07:00
|
|
|
assert(VerifyScript(final_spending_tx.vin[i].scriptSig,
|
2016-07-06 11:07:50 -07:00
|
|
|
prevPubKey,
|
|
|
|
STANDARD_SCRIPT_VERIFY_FLAGS,
|
2018-02-03 13:02:25 -08:00
|
|
|
TransactionSignatureChecker(&final_spending_tx, i, 1000000, txdata),
|
2018-02-01 17:49:42 -08:00
|
|
|
consensusBranchId,
|
2016-07-06 11:07:50 -07:00
|
|
|
&serror));
|
|
|
|
}
|
2016-08-10 05:45:31 -07:00
|
|
|
return timer_stop(tv_start);
|
2016-06-07 16:28:12 -07:00
|
|
|
}
|
|
|
|
|
2016-12-08 19:55:01 -08:00
|
|
|
double benchmark_try_decrypt_notes(size_t nAddrs)
|
2016-11-16 22:09:45 -08:00
|
|
|
{
|
|
|
|
CWallet wallet;
|
2016-12-08 19:55:01 -08:00
|
|
|
for (int i = 0; i < nAddrs; i++) {
|
2016-11-16 22:09:45 -08:00
|
|
|
auto sk = libzcash::SpendingKey::random();
|
|
|
|
wallet.AddSpendingKey(sk);
|
|
|
|
}
|
|
|
|
|
2016-12-08 19:55:01 -08:00
|
|
|
auto sk = libzcash::SpendingKey::random();
|
|
|
|
auto tx = GetValidReceive(*pzcashParams, sk, 10, true);
|
2016-11-16 22:09:45 -08:00
|
|
|
|
|
|
|
struct timeval tv_start;
|
|
|
|
timer_start(tv_start);
|
|
|
|
auto nd = wallet.FindMyNotes(tx);
|
|
|
|
return timer_stop(tv_start);
|
|
|
|
}
|
|
|
|
|
2016-11-17 01:26:46 -08:00
|
|
|
double benchmark_increment_note_witnesses(size_t nTxs)
|
|
|
|
{
|
|
|
|
CWallet wallet;
|
|
|
|
ZCIncrementalMerkleTree tree;
|
|
|
|
|
|
|
|
auto sk = libzcash::SpendingKey::random();
|
|
|
|
wallet.AddSpendingKey(sk);
|
|
|
|
|
|
|
|
// First block
|
|
|
|
CBlock block1;
|
|
|
|
for (int i = 0; i < nTxs; i++) {
|
|
|
|
auto wtx = GetValidReceive(*pzcashParams, sk, 10, true);
|
|
|
|
auto note = GetNote(*pzcashParams, sk, wtx, 0, 1);
|
|
|
|
auto nullifier = note.nullifier(sk);
|
|
|
|
|
|
|
|
mapNoteData_t noteData;
|
|
|
|
JSOutPoint jsoutpt {wtx.GetHash(), 0, 1};
|
|
|
|
CNoteData nd {sk.address(), nullifier};
|
|
|
|
noteData[jsoutpt] = nd;
|
|
|
|
|
|
|
|
wtx.SetNoteData(noteData);
|
|
|
|
wallet.AddToWallet(wtx, true, NULL);
|
|
|
|
block1.vtx.push_back(wtx);
|
|
|
|
}
|
|
|
|
CBlockIndex index1(block1);
|
|
|
|
index1.nHeight = 1;
|
|
|
|
|
|
|
|
// Increment to get transactions witnessed
|
|
|
|
wallet.ChainTip(&index1, &block1, tree, true);
|
|
|
|
|
|
|
|
// Second block
|
|
|
|
CBlock block2;
|
|
|
|
block2.hashPrevBlock = block1.GetHash();
|
2016-12-08 19:55:55 -08:00
|
|
|
{
|
|
|
|
auto wtx = GetValidReceive(*pzcashParams, sk, 10, true);
|
|
|
|
auto note = GetNote(*pzcashParams, sk, wtx, 0, 1);
|
|
|
|
auto nullifier = note.nullifier(sk);
|
|
|
|
|
|
|
|
mapNoteData_t noteData;
|
|
|
|
JSOutPoint jsoutpt {wtx.GetHash(), 0, 1};
|
|
|
|
CNoteData nd {sk.address(), nullifier};
|
|
|
|
noteData[jsoutpt] = nd;
|
|
|
|
|
|
|
|
wtx.SetNoteData(noteData);
|
|
|
|
wallet.AddToWallet(wtx, true, NULL);
|
|
|
|
block2.vtx.push_back(wtx);
|
|
|
|
}
|
2016-11-17 01:26:46 -08:00
|
|
|
CBlockIndex index2(block2);
|
|
|
|
index2.nHeight = 2;
|
|
|
|
|
|
|
|
struct timeval tv_start;
|
|
|
|
timer_start(tv_start);
|
|
|
|
wallet.ChainTip(&index2, &block2, tree, true);
|
|
|
|
return timer_stop(tv_start);
|
|
|
|
}
|
|
|
|
|
2017-05-11 18:00:15 -07:00
|
|
|
// Fake the input of a given block
|
|
|
|
class FakeCoinsViewDB : public CCoinsViewDB {
|
|
|
|
uint256 hash;
|
|
|
|
ZCIncrementalMerkleTree t;
|
|
|
|
|
|
|
|
public:
|
|
|
|
FakeCoinsViewDB(std::string dbName, uint256& hash) : CCoinsViewDB(dbName, 100, false, false), hash(hash) {}
|
|
|
|
|
|
|
|
bool GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const {
|
|
|
|
if (rt == t.root()) {
|
|
|
|
tree = t;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetNullifier(const uint256 &nf) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint256 GetBestBlock() const {
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint256 GetBestAnchor() const {
|
|
|
|
return t.root();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BatchWrite(CCoinsMap &mapCoins,
|
|
|
|
const uint256 &hashBlock,
|
|
|
|
const uint256 &hashAnchor,
|
|
|
|
CAnchorsMap &mapAnchors,
|
|
|
|
CNullifiersMap &mapNullifiers) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetStats(CCoinsStats &stats) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
double benchmark_connectblock_slow()
|
|
|
|
{
|
|
|
|
// Test for issue 2017-05-01.a
|
|
|
|
SelectParams(CBaseChainParams::MAIN);
|
|
|
|
CBlock block;
|
|
|
|
FILE* fp = fopen((GetDataDir() / "benchmark/block-107134.dat").string().c_str(), "rb");
|
|
|
|
if (!fp) throw new std::runtime_error("Failed to open block data file");
|
|
|
|
CAutoFile blkFile(fp, SER_DISK, CLIENT_VERSION);
|
|
|
|
blkFile >> block;
|
|
|
|
blkFile.fclose();
|
|
|
|
|
|
|
|
// Fake its inputs
|
|
|
|
auto hashPrev = uint256S("00000000159a41f468e22135942a567781c3f3dc7ad62257993eb3c69c3f95ef");
|
|
|
|
FakeCoinsViewDB fakeDB("benchmark/block-107134-inputs", hashPrev);
|
|
|
|
CCoinsViewCache view(&fakeDB);
|
|
|
|
|
|
|
|
// Fake the chain
|
|
|
|
CBlockIndex index(block);
|
|
|
|
index.nHeight = 107134;
|
|
|
|
CBlockIndex indexPrev;
|
|
|
|
indexPrev.phashBlock = &hashPrev;
|
|
|
|
indexPrev.nHeight = index.nHeight - 1;
|
|
|
|
index.pprev = &indexPrev;
|
|
|
|
mapBlockIndex.insert(std::make_pair(hashPrev, &indexPrev));
|
|
|
|
|
|
|
|
CValidationState state;
|
|
|
|
struct timeval tv_start;
|
|
|
|
timer_start(tv_start);
|
|
|
|
assert(ConnectBlock(block, state, &index, view, true));
|
|
|
|
auto duration = timer_stop(tv_start);
|
|
|
|
|
|
|
|
// Undo alterations to global state
|
|
|
|
mapBlockIndex.erase(hashPrev);
|
|
|
|
SelectParamsFromCommandLine();
|
|
|
|
|
|
|
|
return duration;
|
|
|
|
}
|
|
|
|
|
2017-08-17 02:31:47 -07:00
|
|
|
double benchmark_sendtoaddress(CAmount amount)
|
|
|
|
{
|
|
|
|
UniValue params(UniValue::VARR);
|
|
|
|
auto addr = getnewaddress(params, false);
|
|
|
|
|
|
|
|
params.push_back(addr);
|
|
|
|
params.push_back(ValueFromAmount(amount));
|
|
|
|
|
|
|
|
struct timeval tv_start;
|
|
|
|
timer_start(tv_start);
|
|
|
|
auto txid = sendtoaddress(params, false);
|
|
|
|
return timer_stop(tv_start);
|
|
|
|
}
|
|
|
|
|
2017-09-18 12:54:53 -07:00
|
|
|
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;
|
|
|
|
}
|
2017-10-04 04:48:50 -07:00
|
|
|
|
|
|
|
double benchmark_listunspent()
|
|
|
|
{
|
|
|
|
UniValue params(UniValue::VARR);
|
|
|
|
struct timeval tv_start;
|
|
|
|
timer_start(tv_start);
|
|
|
|
auto unspent = listunspent(params, false);
|
|
|
|
return timer_stop(tv_start);
|
|
|
|
}
|