Skip to content

Commit 24ad076

Browse files
committed
fix: ensure that globals are set and checks present to avoid bench errs
* ECDSA benchmarks require ECC initialization, which was missing * CheckBlock() internally calls `g_stats_client` and without a testing setup, it'll be a nullptr. * Wallet benchmarks assume that TestingSetup will setup the CoinJoin loader but that is not guaranteed. We should check that the loader is available before attempting registration with it.
1 parent 1c54997 commit 24ad076

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

src/bench/bench_bitcoin.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
#include <clientversion.h>
88
#include <crypto/sha256.h>
99
#include <fs.h>
10-
#include <stacktraces.h>
1110
#include <util/strencodings.h>
1211
#include <util/system.h>
1312

14-
#include <bls/bls.h>
1513
#include <chrono>
1614
#include <cstdint>
1715
#include <iostream>

src/bench/checkblock.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <chainparams.h>
99
#include <consensus/validation.h>
10+
#include <stats/client.h>
1011
#include <streams.h>
1112
#include <validation.h>
1213

@@ -36,6 +37,9 @@ static void DeserializeAndCheckBlockTest(benchmark::Bench& bench)
3637

3738
ArgsManager bench_args;
3839
const auto chainParams = CreateChainParams(bench_args, CBaseChainParams::MAIN);
40+
// CheckBlock calls g_stats_client internally, we aren't using a testing setup
41+
// so we need to do this manually.
42+
::g_stats_client = InitStatsClient(bench_args);
3943

4044
bench.unit("block").run([&] {
4145
CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here

src/bench/ecdsa.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
static void ECDSASign(benchmark::Bench& bench)
1010
{
11+
ECC_Start();
12+
1113
std::vector<CKey> keys;
1214
std::vector<uint256> hashes;
1315
for (size_t i = 0; i < 100; i++) {
@@ -24,10 +26,14 @@ static void ECDSASign(benchmark::Bench& bench)
2426
keys[i].Sign(hashes[i], sig);
2527
i = (i + 1) % keys.size();
2628
});
29+
30+
ECC_Stop();
2731
}
2832

2933
static void ECDSAVerify(benchmark::Bench& bench)
3034
{
35+
ECC_Start();
36+
3137
std::vector<CPubKey> keys;
3238
std::vector<uint256> hashes;
3339
std::vector<std::vector<unsigned char>> sigs;
@@ -47,10 +53,14 @@ static void ECDSAVerify(benchmark::Bench& bench)
4753
keys[i].Verify(hashes[i], sigs[i]);
4854
i = (i + 1) % keys.size();
4955
});
56+
57+
ECC_Stop();
5058
}
5159

5260
static void ECDSAVerify_LargeBlock(benchmark::Bench& bench)
5361
{
62+
ECC_Start();
63+
5464
std::vector<CPubKey> keys;
5565
std::vector<uint256> hashes;
5666
std::vector<std::vector<unsigned char>> sigs;
@@ -70,6 +80,8 @@ static void ECDSAVerify_LargeBlock(benchmark::Bench& bench)
7080
keys[i].Verify(hashes[i], sigs[i]);
7181
}
7282
});
83+
84+
ECC_Stop();
7385
}
7486

7587
BENCHMARK(ECDSASign)

src/wallet/load.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ void FlushWallets(WalletContext& context)
161161
{
162162
for (const std::shared_ptr<CWallet>& pwallet : GetWallets(context)) {
163163
if (CCoinJoinClientOptions::IsEnabled()) {
164+
assert(pwallet->coinjoin_available());
164165
// Stop CoinJoin, release keys
165166
pwallet->coinjoin_loader().FlushWallet(pwallet->GetName());
166167
}

src/wallet/wallet.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ bool AddWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet)
127127
}
128128
wallet->ConnectScriptPubKeyManNotifiers();
129129
wallet->AutoLockMasternodeCollaterals();
130-
wallet->coinjoin_loader().AddWallet(wallet);
130+
if (wallet->coinjoin_available()) {
131+
wallet->coinjoin_loader().AddWallet(wallet);
132+
}
131133
wallet->NotifyCanGetAddressesChanged();
132134
return true;
133135
}
@@ -148,7 +150,9 @@ bool RemoveWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet
148150
context.wallets.erase(i);
149151
}
150152

151-
wallet->coinjoin_loader().RemoveWallet(name);
153+
if (wallet->coinjoin_available()) {
154+
wallet->coinjoin_loader().RemoveWallet(name);
155+
}
152156

153157
// Write the wallet setting
154158
UpdateWalletSetting(chain, name, load_on_start, warnings);

0 commit comments

Comments
 (0)