aboutsummaryrefslogtreecommitdiff
path: root/src/bench
diff options
context:
space:
mode:
Diffstat (limited to 'src/bench')
-rw-r--r--src/bench/bench.cpp2
-rw-r--r--src/bench/bip324_ecdh.cpp6
-rw-r--r--src/bench/ccoins_caching.cpp3
-rw-r--r--src/bench/checkqueue.cpp3
-rw-r--r--src/bench/descriptors.cpp4
-rw-r--r--src/bench/ellswift.cpp6
-rw-r--r--src/bench/index_blockfilter.cpp43
-rw-r--r--src/bench/parse_hex.cpp36
-rw-r--r--src/bench/verify_script.cpp17
-rw-r--r--src/bench/wallet_balance.cpp3
-rw-r--r--src/bench/wallet_create.cpp7
-rw-r--r--src/bench/wallet_ismine.cpp75
-rw-r--r--src/bench/wallet_loading.cpp2
13 files changed, 175 insertions, 32 deletions
diff --git a/src/bench/bench.cpp b/src/bench/bench.cpp
index 84b66bc4b2..a13a693ad7 100644
--- a/src/bench/bench.cpp
+++ b/src/bench/bench.cpp
@@ -23,6 +23,8 @@ const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
const std::function<std::vector<const char*>()> G_TEST_COMMAND_LINE_ARGUMENTS{};
+const std::function<std::string()> G_TEST_GET_FULL_NAME{};
+
namespace {
void GenerateTemplateResults(const std::vector<ankerl::nanobench::Result>& benchmarkResults, const fs::path& file, const char* tpl)
diff --git a/src/bench/bip324_ecdh.cpp b/src/bench/bip324_ecdh.cpp
index 659da0f08e..88f3932ad8 100644
--- a/src/bench/bip324_ecdh.cpp
+++ b/src/bench/bip324_ecdh.cpp
@@ -14,7 +14,7 @@
static void BIP324_ECDH(benchmark::Bench& bench)
{
- ECC_Start();
+ ECC_Context ecc_context{};
FastRandomContext rng;
std::array<std::byte, 32> key_data;
@@ -27,7 +27,7 @@ static void BIP324_ECDH(benchmark::Bench& bench)
bench.batch(1).unit("ecdh").run([&] {
CKey key;
- key.Set(UCharCast(key_data.data()), UCharCast(key_data.data()) + 32, true);
+ key.Set(key_data.data(), key_data.data() + 32, true);
EllSwiftPubKey our_ellswift(our_ellswift_data);
EllSwiftPubKey their_ellswift(their_ellswift_data);
@@ -44,8 +44,6 @@ static void BIP324_ECDH(benchmark::Bench& bench)
// - Copy 16 bytes from the resulting shared secret into the middle of their ellswift key.
std::copy(ret.begin() + 16, ret.end(), their_ellswift_data.begin() + 24);
});
-
- ECC_Stop();
}
BENCHMARK(BIP324_ECDH, benchmark::PriorityLevel::HIGH);
diff --git a/src/bench/ccoins_caching.cpp b/src/bench/ccoins_caching.cpp
index 4a3ec67c2b..05b2f5435c 100644
--- a/src/bench/ccoins_caching.cpp
+++ b/src/bench/ccoins_caching.cpp
@@ -18,7 +18,7 @@
// (https://github.com/bitcoin/bitcoin/issues/7883#issuecomment-224807484)
static void CCoinsCaching(benchmark::Bench& bench)
{
- ECC_Start();
+ ECC_Context ecc_context{};
FillableSigningProvider keystore;
CCoinsView coinsDummy;
@@ -47,7 +47,6 @@ static void CCoinsCaching(benchmark::Bench& bench)
bool success{AreInputsStandard(tx_1, coins)};
assert(success);
});
- ECC_Stop();
}
BENCHMARK(CCoinsCaching, benchmark::PriorityLevel::HIGH);
diff --git a/src/bench/checkqueue.cpp b/src/bench/checkqueue.cpp
index 114dd9d39c..c973fe9f71 100644
--- a/src/bench/checkqueue.cpp
+++ b/src/bench/checkqueue.cpp
@@ -25,7 +25,7 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::Bench& bench)
// We shouldn't ever be running with the checkqueue on a single core machine.
if (GetNumCores() <= 1) return;
- ECC_Start();
+ ECC_Context ecc_context{};
struct PrevectorJob {
prevector<PREVECTOR_SIZE, uint8_t> p;
@@ -62,6 +62,5 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::Bench& bench)
// it is done explicitly here for clarity
control.Wait();
});
- ECC_Stop();
}
BENCHMARK(CCheckQueueSpeedPrevectorJob, benchmark::PriorityLevel::HIGH);
diff --git a/src/bench/descriptors.cpp b/src/bench/descriptors.cpp
index fbef1395fb..5d6bcb8ce8 100644
--- a/src/bench/descriptors.cpp
+++ b/src/bench/descriptors.cpp
@@ -12,7 +12,7 @@
static void ExpandDescriptor(benchmark::Bench& bench)
{
- ECC_Start();
+ ECC_Context ecc_context{};
const auto desc_str = "sh(wsh(multi(16,03669b8afcec803a0d323e9a17f3ea8e68e8abe5a278020a929adbec52421adbd0,0260b2003c386519fc9eadf2b5cf124dd8eea4c4e68d5e154050a9346ea98ce600,0362a74e399c39ed5593852a30147f2959b56bb827dfa3e60e464b02ccf87dc5e8,0261345b53de74a4d721ef877c255429961b7e43714171ac06168d7e08c542a8b8,02da72e8b46901a65d4374fe6315538d8f368557dda3a1dcf9ea903f3afe7314c8,0318c82dd0b53fd3a932d16e0ba9e278fcc937c582d5781be626ff16e201f72286,0297ccef1ef99f9d73dec9ad37476ddb232f1238aff877af19e72ba04493361009,02e502cfd5c3f972fe9a3e2a18827820638f96b6f347e54d63deb839011fd5765d,03e687710f0e3ebe81c1037074da939d409c0025f17eb86adb9427d28f0f7ae0e9,02c04d3a5274952acdbc76987f3184b346a483d43be40874624b29e3692c1df5af,02ed06e0f418b5b43a7ec01d1d7d27290fa15f75771cb69b642a51471c29c84acd,036d46073cbb9ffee90473f3da429abc8de7f8751199da44485682a989a4bebb24,02f5d1ff7c9029a80a4e36b9a5497027ef7f3e73384a4a94fbfe7c4e9164eec8bc,02e41deffd1b7cce11cde209a781adcffdabd1b91c0ba0375857a2bfd9302419f3,02d76625f7956a7fc505ab02556c23ee72d832f1bac391bcd2d3abce5710a13d06,0399eb0a5487515802dc14544cf10b3666623762fbed2ec38a3975716e2c29c232)))";
const std::pair<int64_t, int64_t> range = {0, 1000};
@@ -27,8 +27,6 @@ static void ExpandDescriptor(benchmark::Bench& bench)
assert(success);
}
});
-
- ECC_Stop();
}
BENCHMARK(ExpandDescriptor, benchmark::PriorityLevel::HIGH);
diff --git a/src/bench/ellswift.cpp b/src/bench/ellswift.cpp
index 82e8dec982..4780db8e1c 100644
--- a/src/bench/ellswift.cpp
+++ b/src/bench/ellswift.cpp
@@ -9,7 +9,7 @@
static void EllSwiftCreate(benchmark::Bench& bench)
{
- ECC_Start();
+ ECC_Context ecc_context{};
CKey key = GenerateRandomKey();
uint256 entropy = GetRandHash();
@@ -17,13 +17,11 @@ static void EllSwiftCreate(benchmark::Bench& bench)
bench.batch(1).unit("pubkey").run([&] {
auto ret = key.EllSwiftCreate(MakeByteSpan(entropy));
/* Use the first 32 bytes of the ellswift encoded public key as next private key. */
- key.Set(UCharCast(ret.data()), UCharCast(ret.data()) + 32, true);
+ key.Set(ret.data(), ret.data() + 32, true);
assert(key.IsValid());
/* Use the last 32 bytes of the ellswift encoded public key as next entropy. */
std::copy(ret.begin() + 32, ret.begin() + 64, MakeWritableByteSpan(entropy).begin());
});
-
- ECC_Stop();
}
BENCHMARK(EllSwiftCreate, benchmark::PriorityLevel::HIGH);
diff --git a/src/bench/index_blockfilter.cpp b/src/bench/index_blockfilter.cpp
new file mode 100644
index 0000000000..5e0bfbfea6
--- /dev/null
+++ b/src/bench/index_blockfilter.cpp
@@ -0,0 +1,43 @@
+// Copyright (c) 2023-present The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or https://www.opensource.org/licenses/mit-license.php.
+
+#include <bench/bench.h>
+
+#include <addresstype.h>
+#include <index/blockfilterindex.h>
+#include <node/chainstate.h>
+#include <node/context.h>
+#include <test/util/setup_common.h>
+#include <util/strencodings.h>
+
+// Very simple block filter index sync benchmark, only using coinbase outputs.
+static void BlockFilterIndexSync(benchmark::Bench& bench)
+{
+ const auto test_setup = MakeNoLogFileContext<TestChain100Setup>();
+
+ // Create more blocks
+ int CHAIN_SIZE = 600;
+ CPubKey pubkey{ParseHex("02ed26169896db86ced4cbb7b3ecef9859b5952825adbeab998fb5b307e54949c9")};
+ CScript script = GetScriptForDestination(WitnessV0KeyHash(pubkey));
+ std::vector<CMutableTransaction> noTxns;
+ for (int i = 0; i < CHAIN_SIZE - 100; i++) {
+ test_setup->CreateAndProcessBlock(noTxns, script);
+ SetMockTime(GetTime() + 1);
+ }
+ assert(WITH_LOCK(::cs_main, return test_setup->m_node.chainman->ActiveHeight() == CHAIN_SIZE));
+
+ bench.minEpochIterations(5).run([&] {
+ BlockFilterIndex filter_index(interfaces::MakeChain(test_setup->m_node), BlockFilterType::BASIC,
+ /*n_cache_size=*/0, /*f_memory=*/false, /*f_wipe=*/true);
+ assert(filter_index.Init());
+ assert(!filter_index.BlockUntilSyncedToCurrentChain());
+ filter_index.Sync();
+
+ IndexSummary summary = filter_index.GetSummary();
+ assert(summary.synced);
+ assert(summary.best_block_hash == WITH_LOCK(::cs_main, return test_setup->m_node.chainman->ActiveTip()->GetBlockHash()));
+ });
+}
+
+BENCHMARK(BlockFilterIndexSync, benchmark::PriorityLevel::HIGH);
diff --git a/src/bench/parse_hex.cpp b/src/bench/parse_hex.cpp
new file mode 100644
index 0000000000..db3ead043c
--- /dev/null
+++ b/src/bench/parse_hex.cpp
@@ -0,0 +1,36 @@
+// Copyright (c) 2024- The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include <bench/bench.h>
+#include <random.h>
+#include <stddef.h>
+#include <util/strencodings.h>
+#include <cassert>
+#include <optional>
+#include <vector>
+
+std::string generateHexString(size_t length) {
+ const auto hex_digits = "0123456789ABCDEF";
+ FastRandomContext rng(/*fDeterministic=*/true);
+
+ std::string data;
+ while (data.size() < length) {
+ auto digit = hex_digits[rng.randbits(4)];
+ data.push_back(digit);
+ }
+ return data;
+}
+
+static void HexParse(benchmark::Bench& bench)
+{
+ auto data = generateHexString(130); // Generates 678B0EDA0A1FD30904D5A65E3568DB82DB2D918B0AD8DEA18A63FECCB877D07CAD1495C7157584D877420EF38B8DA473A6348B4F51811AC13C786B962BEE5668F9 by default
+
+ bench.batch(data.size()).unit("base16").run([&] {
+ auto result = TryParseHex(data);
+ assert(result != std::nullopt); // make sure we're measuring the successful case
+ ankerl::nanobench::doNotOptimizeAway(result);
+ });
+}
+
+BENCHMARK(HexParse, benchmark::PriorityLevel::HIGH);
diff --git a/src/bench/verify_script.cpp b/src/bench/verify_script.cpp
index 3682b33518..f38aa49a23 100644
--- a/src/bench/verify_script.cpp
+++ b/src/bench/verify_script.cpp
@@ -4,9 +4,6 @@
#include <bench/bench.h>
#include <key.h>
-#if defined(HAVE_CONSENSUS_LIB)
-#include <script/bitcoinconsensus.h>
-#endif
#include <script/script.h>
#include <script/interpreter.h>
#include <streams.h>
@@ -18,7 +15,7 @@
// modified to measure performance of other types of scripts.
static void VerifyScriptBench(benchmark::Bench& bench)
{
- ECC_Start();
+ ECC_Context ecc_context{};
const uint32_t flags{SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_P2SH};
const int witnessversion = 0;
@@ -59,19 +56,7 @@ static void VerifyScriptBench(benchmark::Bench& bench)
&err);
assert(err == SCRIPT_ERR_OK);
assert(success);
-
-#if defined(HAVE_CONSENSUS_LIB)
- DataStream stream;
- stream << TX_WITH_WITNESS(txSpend);
- int csuccess = bitcoinconsensus_verify_script_with_amount(
- txCredit.vout[0].scriptPubKey.data(),
- txCredit.vout[0].scriptPubKey.size(),
- txCredit.vout[0].nValue,
- (const unsigned char*)stream.data(), stream.size(), 0, flags, nullptr);
- assert(csuccess == 1);
-#endif
});
- ECC_Stop();
}
static void VerifyNestedIfScript(benchmark::Bench& bench)
diff --git a/src/bench/wallet_balance.cpp b/src/bench/wallet_balance.cpp
index bf2195293e..7a10b167a6 100644
--- a/src/bench/wallet_balance.cpp
+++ b/src/bench/wallet_balance.cpp
@@ -39,7 +39,8 @@ static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const b
generatetoaddress(test_setup->m_node, address_mine.value_or(ADDRESS_WATCHONLY));
generatetoaddress(test_setup->m_node, ADDRESS_WATCHONLY);
}
- SyncWithValidationInterfaceQueue();
+ // Calls SyncWithValidationInterfaceQueue
+ wallet.chain().waitForNotificationsIfTipChanged(uint256::ZERO);
auto bal = GetBalance(wallet); // Cache
diff --git a/src/bench/wallet_create.cpp b/src/bench/wallet_create.cpp
index 993c4c4b3f..618d5bc80c 100644
--- a/src/bench/wallet_create.cpp
+++ b/src/bench/wallet_create.cpp
@@ -2,6 +2,8 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or https://www.opensource.org/licenses/mit-license.php.
+#include <config/bitcoin-config.h> // IWYU pragma: keep
+
#include <bench/bench.h>
#include <node/context.h>
#include <random.h>
@@ -47,9 +49,14 @@ static void WalletCreate(benchmark::Bench& bench, bool encrypted)
static void WalletCreatePlain(benchmark::Bench& bench) { WalletCreate(bench, /*encrypted=*/false); }
static void WalletCreateEncrypted(benchmark::Bench& bench) { WalletCreate(bench, /*encrypted=*/true); }
+#ifndef _MSC_VER
+// TODO: Being built with MSVC, the fs::remove_all() call in
+// the WalletCreate() fails with the error "The process cannot
+// access the file because it is being used by another process."
#ifdef USE_SQLITE
BENCHMARK(WalletCreatePlain, benchmark::PriorityLevel::LOW);
BENCHMARK(WalletCreateEncrypted, benchmark::PriorityLevel::LOW);
#endif
+#endif
} // namespace wallet
diff --git a/src/bench/wallet_ismine.cpp b/src/bench/wallet_ismine.cpp
new file mode 100644
index 0000000000..753404b526
--- /dev/null
+++ b/src/bench/wallet_ismine.cpp
@@ -0,0 +1,75 @@
+// Copyright (c) 2022 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include <config/bitcoin-config.h> // IWYU pragma: keep
+#include <bench/bench.h>
+#include <interfaces/chain.h>
+#include <key.h>
+#include <key_io.h>
+#include <node/context.h>
+#include <test/util/setup_common.h>
+#include <util/translation.h>
+#include <validationinterface.h>
+#include <wallet/context.h>
+#include <wallet/test/util.h>
+#include <wallet/wallet.h>
+#include <wallet/walletutil.h>
+
+namespace wallet {
+static void WalletIsMine(benchmark::Bench& bench, bool legacy_wallet, int num_combo = 0)
+{
+ const auto test_setup = MakeNoLogFileContext<TestingSetup>();
+
+ WalletContext context;
+ context.args = &test_setup->m_args;
+ context.chain = test_setup->m_node.chain.get();
+
+ // Setup the wallet
+ // Loading the wallet will also create it
+ uint64_t create_flags = 0;
+ if (!legacy_wallet) {
+ create_flags = WALLET_FLAG_DESCRIPTORS;
+ }
+ auto database = CreateMockableWalletDatabase();
+ auto wallet = TestLoadWallet(std::move(database), context, create_flags);
+
+ // For a descriptor wallet, fill with num_combo combo descriptors with random keys
+ // This benchmarks a non-HD wallet migrated to descriptors
+ if (!legacy_wallet && num_combo > 0) {
+ LOCK(wallet->cs_wallet);
+ for (int i = 0; i < num_combo; ++i) {
+ CKey key;
+ key.MakeNewKey(/*fCompressed=*/true);
+ FlatSigningProvider keys;
+ std::string error;
+ std::unique_ptr<Descriptor> desc = Parse("combo(" + EncodeSecret(key) + ")", keys, error, /*require_checksum=*/false);
+ WalletDescriptor w_desc(std::move(desc), /*creation_time=*/0, /*range_start=*/0, /*range_end=*/0, /*next_index=*/0);
+ auto spkm = wallet->AddWalletDescriptor(w_desc, keys, /*label=*/"", /*internal=*/false);
+ assert(spkm);
+ }
+ }
+
+ const CScript script = GetScriptForDestination(DecodeDestination(ADDRESS_BCRT1_UNSPENDABLE));
+
+ bench.run([&] {
+ LOCK(wallet->cs_wallet);
+ isminetype mine = wallet->IsMine(script);
+ assert(mine == ISMINE_NO);
+ });
+
+ TestUnloadWallet(std::move(wallet));
+}
+
+#ifdef USE_BDB
+static void WalletIsMineLegacy(benchmark::Bench& bench) { WalletIsMine(bench, /*legacy_wallet=*/true); }
+BENCHMARK(WalletIsMineLegacy, benchmark::PriorityLevel::LOW);
+#endif
+
+#ifdef USE_SQLITE
+static void WalletIsMineDescriptors(benchmark::Bench& bench) { WalletIsMine(bench, /*legacy_wallet=*/false); }
+static void WalletIsMineMigratedDescriptors(benchmark::Bench& bench) { WalletIsMine(bench, /*legacy_wallet=*/false, /*num_combo=*/2000); }
+BENCHMARK(WalletIsMineDescriptors, benchmark::PriorityLevel::LOW);
+BENCHMARK(WalletIsMineMigratedDescriptors, benchmark::PriorityLevel::LOW);
+#endif
+} // namespace wallet
diff --git a/src/bench/wallet_loading.cpp b/src/bench/wallet_loading.cpp
index b17c7fe05a..02582deda4 100644
--- a/src/bench/wallet_loading.cpp
+++ b/src/bench/wallet_loading.cpp
@@ -2,6 +2,8 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#include <config/bitcoin-config.h> // IWYU pragma: keep
+
#include <bench/bench.h>
#include <interfaces/chain.h>
#include <node/context.h>