Skip to content

Commit 60f6773

Browse files
committed
Merge bitcoin#29055: tests, bench: Fix issue with CWallet::LoadWallet() being called in the wrong places
bd7f5d3 wallet: Assert that the wallet is not initialized in LoadWallet (Andrew Chow) fb0b6ca tests, bench: Remove incorrect LoadWallet() calls (Andrew Chow) Pull request description: `CWallet::LoadWallet()` expects to be called after a `CWallet` is constructed, but before any of its member functions called. Doing so invalidates pointers which causes issues with some PRs and branches that I am working on. This was being used incorrectly in a few tests and benchmarks, resulting in segfaults. As a precaution for this kind of issue in the future, I've also added a few asserts to `LoadWallet()` so that developers will notice when it is used incorrectly. As similar issue was fixed in bitcoin#27666 ACKs for top commit: S3RK: ACK bd7f5d3 furszy: ACK bd7f5d3 Tree-SHA512: 7664f12b8452994e7fc4d7d4f77697fb5f75edb0dba95ba99a4a23ec03d5b8e0ecbdcb7635547a0e8b4f89f708f98dcb5d039df0559e24b1ae411ed630e16e14
2 parents 7a28383 + bd7f5d3 commit 60f6773

File tree

3 files changed

+2
-4
lines changed

3 files changed

+2
-4
lines changed

src/bench/wallet_create_tx.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
using wallet::CWallet;
1818
using wallet::CreateMockableWalletDatabase;
19-
using wallet::DBErrors;
2019
using wallet::WALLET_FLAG_DESCRIPTORS;
2120

2221
struct TipBlock
@@ -90,7 +89,6 @@ static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type
9089
LOCK(wallet.cs_wallet);
9190
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
9291
wallet.SetupDescriptorScriptPubKeyMans();
93-
if (wallet.LoadWallet() != DBErrors::LOAD_OK) assert(false);
9492
}
9593

9694
// Generate destinations
@@ -146,7 +144,6 @@ static void AvailableCoins(benchmark::Bench& bench, const std::vector<OutputType
146144
LOCK(wallet.cs_wallet);
147145
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
148146
wallet.SetupDescriptorScriptPubKeyMans();
149-
if (wallet.LoadWallet() != DBErrors::LOAD_OK) assert(false);
150147
}
151148

152149
// Generate destinations

src/wallet/test/util.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cc
2424
LOCK2(wallet->cs_wallet, ::cs_main);
2525
wallet->SetLastBlockProcessed(cchain.Height(), cchain.Tip()->GetBlockHash());
2626
}
27-
wallet->LoadWallet();
2827
{
2928
LOCK(wallet->cs_wallet);
3029
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);

src/wallet/wallet.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,6 +2292,8 @@ DBErrors CWallet::LoadWallet()
22922292
{
22932293
LOCK(cs_wallet);
22942294

2295+
Assert(m_spk_managers.empty());
2296+
Assert(m_wallet_flags == 0);
22952297
DBErrors nLoadWalletRet = WalletBatch(GetDatabase()).LoadWallet(this);
22962298
if (nLoadWalletRet == DBErrors::NEED_REWRITE)
22972299
{

0 commit comments

Comments
 (0)