Merge branch 'beta' into mergemaster
# Conflicts: # src/main.cpp
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
#include <cstdio>
|
||||
#include <future>
|
||||
#include <map>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
#include <boost/filesystem.hpp>
|
||||
@@ -9,14 +11,18 @@
|
||||
#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 "rpcserver.h"
|
||||
#include "script/sign.h"
|
||||
#include "sodium.h"
|
||||
#include "streams.h"
|
||||
#include "txdb.h"
|
||||
#include "utiltest.h"
|
||||
#include "wallet/wallet.h"
|
||||
|
||||
@@ -26,6 +32,39 @@
|
||||
#include "zcash/IncrementalMerkleTree.hpp"
|
||||
|
||||
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 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)
|
||||
{
|
||||
@@ -59,11 +98,7 @@ double benchmark_parameter_loading()
|
||||
struct timeval tv_start;
|
||||
timer_start(tv_start);
|
||||
|
||||
auto newParams = ZCJoinSplit::Unopened();
|
||||
|
||||
newParams->loadVerifyingKey(vk_path.string());
|
||||
newParams->setProvingKeyPath(pk_path.string());
|
||||
newParams->loadProvingKey();
|
||||
auto newParams = ZCJoinSplit::Prepared(vk_path.string(), pk_path.string());
|
||||
|
||||
double ret = timer_stop(tv_start);
|
||||
|
||||
@@ -187,11 +222,8 @@ double benchmark_verify_equihash()
|
||||
return timer_stop(tv_start);
|
||||
}
|
||||
|
||||
double benchmark_large_tx()
|
||||
double benchmark_large_tx(size_t nInputs)
|
||||
{
|
||||
// Number of inputs in the spending transaction that we will simulate
|
||||
const size_t NUM_INPUTS = 555;
|
||||
|
||||
// Create priv/pub key
|
||||
CKey priv;
|
||||
priv.MakeNewKey(false);
|
||||
@@ -210,26 +242,20 @@ double benchmark_large_tx()
|
||||
auto orig_tx = CTransaction(m_orig_tx);
|
||||
|
||||
CMutableTransaction spending_tx;
|
||||
spending_tx.fOverwintered = true;
|
||||
spending_tx.nVersion = 3;
|
||||
spending_tx.nVersionGroupId = OVERWINTER_VERSION_GROUP_ID;
|
||||
|
||||
auto input_hash = orig_tx.GetHash();
|
||||
// Add NUM_INPUTS inputs
|
||||
for (size_t i = 0; i < NUM_INPUTS; i++) {
|
||||
// Add nInputs inputs
|
||||
for (size_t i = 0; i < nInputs; i++) {
|
||||
spending_tx.vin.emplace_back(input_hash, 0);
|
||||
}
|
||||
|
||||
// Sign for all the inputs
|
||||
for (size_t i = 0; i < NUM_INPUTS; i++) {
|
||||
SignSignature(tempKeystore, prevPubKey, spending_tx, i, SIGHASH_ALL);
|
||||
}
|
||||
|
||||
// Serialize:
|
||||
{
|
||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ss << spending_tx;
|
||||
//std::cout << "SIZE OF SPENDING TX: " << ss.size() << std::endl;
|
||||
|
||||
auto error = MAX_TX_SIZE / 20; // 5% error
|
||||
assert(ss.size() < MAX_TX_SIZE + error);
|
||||
assert(ss.size() > MAX_TX_SIZE - error);
|
||||
auto consensusBranchId = NetworkUpgradeInfo[Consensus::UPGRADE_OVERWINTER].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
|
||||
@@ -238,12 +264,14 @@ double benchmark_large_tx()
|
||||
// Benchmark signature verification costs:
|
||||
struct timeval tv_start;
|
||||
timer_start(tv_start);
|
||||
for (size_t i = 0; i < NUM_INPUTS; i++) {
|
||||
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),
|
||||
TransactionSignatureChecker(&final_spending_tx, i, 1000000, txdata),
|
||||
consensusBranchId,
|
||||
&serror));
|
||||
}
|
||||
return timer_stop(tv_start);
|
||||
@@ -322,3 +350,117 @@ double benchmark_increment_note_witnesses(size_t nTxs)
|
||||
return timer_stop(tv_start);
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user