Bitcoin Core
32.99.0
P2P Digital Currency
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 <
consensus/validation.h
>
9
#include <
key.h
>
10
#include <
policy/policy.h
>
11
#include <
primitives/transaction.h
>
12
#include <
script/script.h
>
13
#include <
script/signingprovider.h
>
14
#include <
test/util/transaction_utils.h
>
15
#include <
util/check.h
>
16
17
#include <array>
18
#include <span>
19
#include <vector>
20
21
// Microbenchmark for simple accesses to a CCoinsViewCache database. Note from
22
// laanwj, "replicating the actual usage patterns of the client is hard though,
23
// many times micro-benchmarks of the database showed completely different
24
// characteristics than e.g. reindex timings. But that's not a requirement of
25
// every benchmark."
26
// (https://github.com/bitcoin/bitcoin/issues/7883#issuecomment-224807484)
27
static
void
CCoinsCaching
(
benchmark::Bench
&
bench
)
28
{
29
ECC_Context
ecc_context
{};
30
31
FillableSigningProvider
keystore
;
32
CCoinsViewCache
coins{&
CoinsViewEmpty::Get
()};
33
std::vector<CMutableTransaction>
dummyTransactions
=
34
SetupDummyInputs
(
keystore
, coins, {11 *
COIN
, 50 *
COIN
, 21 *
COIN
, 22 *
COIN
});
35
36
CMutableTransaction
t1
;
37
t1
.
vin
= {
38
CTxIn
{
COutPoint
{
dummyTransactions
[0].GetHash(), 1},
CScript
{} << std::vector<unsigned char>(65, 0)},
39
CTxIn
{
COutPoint
{
dummyTransactions
[1].GetHash(), 0},
CScript
{} << std::vector<unsigned char>(65, 0) << std::vector<unsigned char>(33, 4)},
40
CTxIn
{
COutPoint
{
dummyTransactions
[1].GetHash(), 1},
CScript
{} << std::vector<unsigned char>(65, 0) << std::vector<unsigned char>(33, 4)},
41
};
42
t1
.vout = {
43
CTxOut
{90 *
COIN
,
CScript
{} <<
OP_1
},
44
CTxOut
{},
45
};
46
47
// Benchmark.
48
const
CTransaction
tx_1
(
t1
);
49
bench
.run([&] {
50
assert
(
ValidateInputsStandardness
(
tx_1
, coins).IsValid());
51
});
52
}
53
54
BENCHMARK
(
CCoinsCaching
);
amount.h
COIN
constexpr CAmount COIN
The amount of satoshis in one BTC.
Definition
amount.h:15
bench.h
BENCHMARK
#define BENCHMARK(n)
Definition
bench.h:69
ecc_context
ECC_Context ecc_context
Definition
bitcoin-wallet.cpp:129
CCoinsCaching
static void CCoinsCaching(benchmark::Bench &bench)
Definition
ccoins_caching.cpp:27
check.h
CCoinsViewCache
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition
coins.h:437
COutPoint
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition
transaction.h:30
CScript
Serialized script, used inside transaction inputs and outputs.
Definition
script.h:406
CTransaction
The basic transaction that is broadcasted on the network and contained in blocks.
Definition
transaction.h:287
CTxIn
An input of a transaction.
Definition
transaction.h:63
CTxOut
An output of a transaction.
Definition
transaction.h:141
CoinsViewEmpty::Get
static CoinsViewEmpty & Get()
Definition
coins.cpp:29
ECC_Context
RAII class initializing and deinitializing global state for elliptic curve support.
Definition
key.h:364
FillableSigningProvider
Fillable signing provider that keeps keys in an address->secret map.
Definition
signingprovider.h:262
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition
nanobench.h:649
validation.h
key.h
ValidateInputsStandardness
TxValidationState ValidateInputsStandardness(const CTransaction &tx, const CCoinsViewCache &mapInputs)
Check transaction inputs.
Definition
policy.cpp:214
policy.h
transaction.h
script.h
OP_1
@ OP_1
Definition
script.h:84
signingprovider.h
CMutableTransaction
A mutable version of CTransaction.
Definition
transaction.h:372
CMutableTransaction::vin
std::vector< CTxIn > vin
Definition
transaction.h:373
SetupDummyInputs
std::vector< CMutableTransaction > SetupDummyInputs(FillableSigningProvider &keystoreRet, CCoinsViewCache &coinsRet, const std::array< CAmount, 4 > &nValues)
Definition
transaction_utils.cpp:41
transaction_utils.h
Ticks
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition
time.h:82
assert
assert(!tx.IsCoinBase())
Generated on Mon Nov 2 2026 20:00:25 for Bitcoin Core by
1.9.8