Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
bench
ccoins_caching.cpp
Go to the documentation of this file.
1
// Copyright (c) 2016-present 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 <
consensus/amount.h
>
8
#include <
key.h
>
9
#include <
policy/policy.h
>
10
#include <
primitives/transaction.h
>
11
#include <
script/script.h
>
12
#include <
script/signingprovider.h
>
13
#include <
test/util/transaction_utils.h
>
14
15
#include <cassert>
16
#include <vector>
17
18
// Microbenchmark for simple accesses to a CCoinsViewCache database. Note from
19
// laanwj, "replicating the actual usage patterns of the client is hard though,
20
// many times micro-benchmarks of the database showed completely different
21
// characteristics than e.g. reindex timings. But that's not a requirement of
22
// every benchmark."
23
// (https://github.com/bitcoin/bitcoin/issues/7883#issuecomment-224807484)
24
static
void
CCoinsCaching
(
benchmark::Bench
& bench)
25
{
26
ECC_Context
ecc_context
{};
27
28
FillableSigningProvider
keystore;
29
CCoinsView
coinsDummy;
30
CCoinsViewCache
coins(&coinsDummy);
31
std::vector<CMutableTransaction> dummyTransactions =
32
SetupDummyInputs
(keystore, coins, {11 *
COIN
, 50 *
COIN
, 21 *
COIN
, 22 *
COIN
});
33
34
CMutableTransaction
t1;
35
t1.
vin
.resize(3);
36
t1.vin[0].prevout.hash = dummyTransactions[0].GetHash();
37
t1.vin[0].prevout.n = 1;
38
t1.vin[0].scriptSig << std::vector<unsigned char>(65, 0);
39
t1.vin[1].prevout.hash = dummyTransactions[1].GetHash();
40
t1.vin[1].prevout.n = 0;
41
t1.vin[1].scriptSig << std::vector<unsigned char>(65, 0) << std::vector<unsigned char>(33, 4);
42
t1.vin[2].prevout.hash = dummyTransactions[1].GetHash();
43
t1.vin[2].prevout.n = 1;
44
t1.vin[2].scriptSig << std::vector<unsigned char>(65, 0) << std::vector<unsigned char>(33, 4);
45
t1.vout.resize(2);
46
t1.vout[0].nValue = 90 *
COIN
;
47
t1.vout[0].scriptPubKey <<
OP_1
;
48
49
// Benchmark.
50
const
CTransaction
tx_1(t1);
51
bench.
run
([&] {
52
bool
success{
AreInputsStandard
(tx_1, coins)};
53
assert
(success);
54
});
55
}
56
57
BENCHMARK
(
CCoinsCaching
);
amount.h
COIN
static constexpr CAmount COIN
The amount of satoshis in one BTC.
Definition
amount.h:15
bench.h
BENCHMARK
#define BENCHMARK(n)
Definition
bench.h:68
ecc_context
ECC_Context ecc_context
Definition
bitcoin-wallet.cpp:126
CCoinsCaching
static void CCoinsCaching(benchmark::Bench &bench)
Definition
ccoins_caching.cpp:24
CCoinsViewCache
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition
coins.h:368
CCoinsView
Abstract view on the open txout dataset.
Definition
coins.h:308
CTransaction
The basic transaction that is broadcasted on the network and contained in blocks.
Definition
transaction.h:281
ECC_Context
RAII class initializing and deinitializing global state for elliptic curve support.
Definition
key.h:326
FillableSigningProvider
Fillable signing provider that keeps keys in an address->secret map.
Definition
signingprovider.h:251
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition
nanobench.h:627
ankerl::nanobench::Bench::run
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition
nanobench.h:1234
key.h
AreInputsStandard
bool AreInputsStandard(const CTransaction &tx, const CCoinsViewCache &mapInputs)
Check transaction inputs.
Definition
policy.cpp:213
policy.h
transaction.h
script.h
OP_1
@ OP_1
Definition
script.h:83
signingprovider.h
CMutableTransaction
A mutable version of CTransaction.
Definition
transaction.h:358
CMutableTransaction::vin
std::vector< CTxIn > vin
Definition
transaction.h:359
SetupDummyInputs
std::vector< CMutableTransaction > SetupDummyInputs(FillableSigningProvider &keystoreRet, CCoinsViewCache &coinsRet, const std::array< CAmount, 4 > &nValues)
Definition
transaction_utils.cpp:44
transaction_utils.h
assert
assert(!tx.IsCoinBase())
Generated on
for Bitcoin Core by
1.17.0