Skip to content

Commit 8a65f03

Browse files
committed
Merge bitcoin/bitcoin#32488: fuzz: Properly setup wallet in wallet_fees target
fa427ff fuzz: Properly setup wallet in wallet_fees target (MarcoFalke) Pull request description: `g_wallet_ptr` is destructed after the `testing_setup`. This is not supported and will lead to issues such as bitcoin/bitcoin#30221 (comment) or bitcoin/bitcoin#32409 (comment). This could be fixed by fixing the initialization order. However, the global wallet is also modified in the fuzz target, which is bad fuzzing practise. So instead fix it by constructing a fresh wallet for each fuzz iteration. ACKs for top commit: brunoerg: code review ACK fa427ff hebasto: ACK fa427ff, this change fixes the issue when building the "Debug" configuration with MSVC on Windows. marcofleon: Code review ACK fa427ff Tree-SHA512: 161b93fc39a609cb16d9ffea7366c5e339bd01712577f0782aedff46c00f79edd2a907807ac83f9fcec687b4bbbe0fd6e6f75e32169639a310e4e7b771078b3b
2 parents f9d8910 + fa427ff commit 8a65f03

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/wallet/test/fuzz/fees.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
// Copyright (c) 2022 The Bitcoin Core developers
1+
// Copyright (c) 2022-present The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <test/fuzz/FuzzedDataProvider.h>
66
#include <test/fuzz/fuzz.h>
77
#include <test/fuzz/util.h>
88
#include <test/util/setup_common.h>
9+
#include <validation.h>
910
#include <wallet/coincontrol.h>
1011
#include <wallet/fees.h>
11-
#include <wallet/wallet.h>
1212
#include <wallet/test/util.h>
13-
#include <validation.h>
13+
#include <wallet/wallet.h>
1414

1515
namespace wallet {
1616
namespace {
1717
const TestingSetup* g_setup;
18-
static std::unique_ptr<CWallet> g_wallet_ptr;
1918

2019
void initialize_setup()
2120
{
2221
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
2322
g_setup = testing_setup.get();
24-
const auto& node{g_setup->m_node};
25-
g_wallet_ptr = std::make_unique<CWallet>(node.chain.get(), "", CreateMockableWalletDatabase());
2623
}
2724

2825
FUZZ_TARGET(wallet_fees, .init = initialize_setup)
2926
{
27+
SeedRandomStateForTest(SeedRand::ZEROS);
3028
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
29+
SetMockTime(ConsumeTime(fuzzed_data_provider));
3130
const auto& node{g_setup->m_node};
3231
Chainstate* chainstate = &node.chainman->ActiveChainstate();
33-
CWallet& wallet = *g_wallet_ptr;
32+
std::unique_ptr<CWallet> wallet_ptr{std::make_unique<CWallet>(node.chain.get(), "", CreateMockableWalletDatabase())};
33+
CWallet& wallet{*wallet_ptr};
3434
{
3535
LOCK(wallet.cs_wallet);
3636
wallet.SetLastBlockProcessed(chainstate->m_chain.Height(), chainstate->m_chain.Tip()->GetBlockHash());

0 commit comments

Comments
 (0)