Bitcoin Core  0.20.99
P2P Digital Currency
ccoins_caching.cpp
Go to the documentation of this file.
1 // Copyright (c) 2016-2020 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <bench/bench.h>
6 #include <coins.h>
7 #include <policy/policy.h>
9 #include <test/util/transaction_utils.h>
10 
11 #include <vector>
12 
13 // Microbenchmark for simple accesses to a CCoinsViewCache database. Note from
14 // laanwj, "replicating the actual usage patterns of the client is hard though,
15 // many times micro-benchmarks of the database showed completely different
16 // characteristics than e.g. reindex timings. But that's not a requirement of
17 // every benchmark."
18 // (https://github.com/bitcoin/bitcoin/issues/7883#issuecomment-224807484)
19 static void CCoinsCaching(benchmark::Bench& bench)
20 {
21  const ECCVerifyHandle verify_handle;
22  ECC_Start();
23 
24  FillableSigningProvider keystore;
25  CCoinsView coinsDummy;
26  CCoinsViewCache coins(&coinsDummy);
27  std::vector<CMutableTransaction> dummyTransactions =
28  SetupDummyInputs(keystore, coins, {11 * COIN, 50 * COIN, 21 * COIN, 22 * COIN});
29 
31  t1.vin.resize(3);
32  t1.vin[0].prevout.hash = dummyTransactions[0].GetHash();
33  t1.vin[0].prevout.n = 1;
34  t1.vin[0].scriptSig << std::vector<unsigned char>(65, 0);
35  t1.vin[1].prevout.hash = dummyTransactions[1].GetHash();
36  t1.vin[1].prevout.n = 0;
37  t1.vin[1].scriptSig << std::vector<unsigned char>(65, 0) << std::vector<unsigned char>(33, 4);
38  t1.vin[2].prevout.hash = dummyTransactions[1].GetHash();
39  t1.vin[2].prevout.n = 1;
40  t1.vin[2].scriptSig << std::vector<unsigned char>(65, 0) << std::vector<unsigned char>(33, 4);
41  t1.vout.resize(2);
42  t1.vout[0].nValue = 90 * COIN;
43  t1.vout[0].scriptPubKey << OP_1;
44 
45  // Benchmark.
46  const CTransaction tx_1(t1);
47  bench.run([&] {
48  bool success = AreInputsStandard(tx_1, coins);
49  assert(success);
50  });
51  ECC_Stop();
52 }
53 
void ECC_Start()
Initialize the elliptic curve support.
Definition: key.cpp:348
std::vector< CTxIn > vin
Definition: transaction.h:355
static const CAmount COIN
Definition: amount.h:14
static void CCoinsCaching(benchmark::Bench &bench)
bool AreInputsStandard(const CTransaction &tx, const CCoinsViewCache &mapInputs)
Check transaction inputs to mitigate two potential denial-of-service attacks:
Definition: policy.cpp:158
Users of this module must hold an ECCVerifyHandle.
Definition: pubkey.h:259
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1134
BENCHMARK(CCoinsCaching)
Abstract view on the open txout dataset.
Definition: coins.h:180
void ECC_Stop()
Deinitialize the elliptic curve support.
Definition: key.cpp:365
Fillable signing provider that keeps keys in an address->secret map.
Definition: script.h:75
A mutable version of CTransaction.
Definition: transaction.h:353
Main entry point to nanobench&#39;s benchmarking facility.
Definition: nanobench.h:583
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:259
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:236