2020-04-16 13:14:08 -04:00
|
|
|
// Copyright (c) 2016-2020 The Bitcoin Core developers
|
2016-10-02 18:38:48 -03:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <bench/bench.h>
|
|
|
|
#include <coins.h>
|
|
|
|
#include <policy/policy.h>
|
2019-06-06 16:52:24 -04:00
|
|
|
#include <script/signingprovider.h>
|
2020-02-18 13:11:16 -03:00
|
|
|
#include <test/util/transaction_utils.h>
|
2016-10-02 18:38:48 -03:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
// Microbenchmark for simple accesses to a CCoinsViewCache database. Note from
|
|
|
|
// laanwj, "replicating the actual usage patterns of the client is hard though,
|
|
|
|
// many times micro-benchmarks of the database showed completely different
|
|
|
|
// characteristics than e.g. reindex timings. But that's not a requirement of
|
|
|
|
// every benchmark."
|
|
|
|
// (https://github.com/bitcoin/bitcoin/issues/7883#issuecomment-224807484)
|
|
|
|
static void CCoinsCaching(benchmark::State& state)
|
|
|
|
{
|
2019-06-06 10:33:23 -04:00
|
|
|
FillableSigningProvider keystore;
|
2016-10-02 18:38:48 -03:00
|
|
|
CCoinsView coinsDummy;
|
|
|
|
CCoinsViewCache coins(&coinsDummy);
|
2020-02-18 13:11:16 -03:00
|
|
|
std::vector<CMutableTransaction> dummyTransactions =
|
|
|
|
SetupDummyInputs(keystore, coins, {11 * COIN, 50 * COIN, 21 * COIN, 22 * COIN});
|
2016-10-02 18:38:48 -03:00
|
|
|
|
|
|
|
CMutableTransaction t1;
|
|
|
|
t1.vin.resize(3);
|
|
|
|
t1.vin[0].prevout.hash = dummyTransactions[0].GetHash();
|
|
|
|
t1.vin[0].prevout.n = 1;
|
|
|
|
t1.vin[0].scriptSig << std::vector<unsigned char>(65, 0);
|
|
|
|
t1.vin[1].prevout.hash = dummyTransactions[1].GetHash();
|
|
|
|
t1.vin[1].prevout.n = 0;
|
|
|
|
t1.vin[1].scriptSig << std::vector<unsigned char>(65, 0) << std::vector<unsigned char>(33, 4);
|
|
|
|
t1.vin[2].prevout.hash = dummyTransactions[1].GetHash();
|
|
|
|
t1.vin[2].prevout.n = 1;
|
|
|
|
t1.vin[2].scriptSig << std::vector<unsigned char>(65, 0) << std::vector<unsigned char>(33, 4);
|
|
|
|
t1.vout.resize(2);
|
2018-09-17 15:33:52 -03:00
|
|
|
t1.vout[0].nValue = 90 * COIN;
|
2016-10-02 18:38:48 -03:00
|
|
|
t1.vout[0].scriptPubKey << OP_1;
|
|
|
|
|
|
|
|
// Benchmark.
|
2018-12-08 21:30:55 -03:00
|
|
|
const CTransaction tx_1(t1);
|
2016-10-02 18:38:48 -03:00
|
|
|
while (state.KeepRunning()) {
|
2018-12-08 21:30:55 -03:00
|
|
|
bool success = AreInputsStandard(tx_1, coins);
|
2016-10-02 18:38:48 -03:00
|
|
|
assert(success);
|
2018-12-08 21:30:55 -03:00
|
|
|
CAmount value = coins.GetValueIn(tx_1);
|
2018-09-17 15:33:52 -03:00
|
|
|
assert(value == (50 + 21 + 22) * COIN);
|
2016-10-02 18:38:48 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-17 11:48:02 -03:00
|
|
|
BENCHMARK(CCoinsCaching, 170 * 1000);
|