Skip to content

Commit b7d78e6

Browse files
committed
Merge bitcoin/bitcoin#24711: wallet: Postpone wallet loading notification for encrypted wallets
0c12f01 wallet: Postpone NotifyWalletLoaded() for encrypted wallets (Hennadii Stepanov) aeee419 wallet, refactor: Add wallet::NotifyWalletLoaded() function (Hennadii Stepanov) Pull request description: Fixes #571. `CWallet::Create()` notifies about wallet loading too early, that results the notification goes before `DescriptorScriptPubKeyMan`s were created and added to an encrypted wallet. And `interfaces::Wallet::taprootEnabled()` in https://github.com/bitcoin/bitcoin/blob/ecf692b466860f44334a1da967fc2559da913bec/src/qt/receivecoinsdialog.cpp#L100-L102 erroneously returns `false` for just created encrypted descriptor wallets. ACKs for top commit: Sjors: utACK 0c12f01 achow101: ACK 0c12f01 Tree-SHA512: 2694bacd12748cd5f6c95d9d3bf8bcf4502ee67fecd8d057f33236b72069c61401b08f49deb013fc71c3f1e51ae16bdfd827ddcbc2a083d7044589be7a78982e
2 parents 243197b + 0c12f01 commit b7d78e6

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

src/wallet/load.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ bool LoadWallets(WalletContext& context)
130130
chain.initError(error);
131131
return false;
132132
}
133+
134+
NotifyWalletLoaded(context, pwallet);
133135
AddWallet(context, pwallet);
134136
}
135137
return true;

src/wallet/test/wallet_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ static const std::shared_ptr<CWallet> TestLoadWallet(WalletContext& context)
5454
std::vector<bilingual_str> warnings;
5555
auto database = MakeWalletDatabase("", options, status, error);
5656
auto wallet = CWallet::Create(context, "", std::move(database), options.create_flags, error, warnings);
57+
NotifyWalletLoaded(context, wallet);
5758
if (context.chain) {
5859
wallet->postInitProcess();
5960
}

src/wallet/wallet.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ std::unique_ptr<interfaces::Handler> HandleLoadWallet(WalletContext& context, Lo
167167
return interfaces::MakeHandler([&context, it] { LOCK(context.wallets_mutex); context.wallet_load_fns.erase(it); });
168168
}
169169

170+
void NotifyWalletLoaded(WalletContext& context, const std::shared_ptr<CWallet>& wallet)
171+
{
172+
LOCK(context.wallets_mutex);
173+
for (auto& load_wallet : context.wallet_load_fns) {
174+
load_wallet(interfaces::MakeWallet(context, wallet));
175+
}
176+
}
177+
170178
static Mutex g_loading_wallet_mutex;
171179
static Mutex g_wallet_release_mutex;
172180
static std::condition_variable g_wallet_release_cv;
@@ -232,6 +240,8 @@ std::shared_ptr<CWallet> LoadWalletInternal(WalletContext& context, const std::s
232240
status = DatabaseStatus::FAILED_LOAD;
233241
return nullptr;
234242
}
243+
244+
NotifyWalletLoaded(context, wallet);
235245
AddWallet(context, wallet);
236246
wallet->postInitProcess();
237247

@@ -348,6 +358,8 @@ std::shared_ptr<CWallet> CreateWallet(WalletContext& context, const std::string&
348358
wallet->Lock();
349359
}
350360
}
361+
362+
NotifyWalletLoaded(context, wallet);
351363
AddWallet(context, wallet);
352364
wallet->postInitProcess();
353365

@@ -2904,13 +2916,6 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
29042916
return nullptr;
29052917
}
29062918

2907-
{
2908-
LOCK(context.wallets_mutex);
2909-
for (auto& load_wallet : context.wallet_load_fns) {
2910-
load_wallet(interfaces::MakeWallet(context, walletInstance));
2911-
}
2912-
}
2913-
29142919
{
29152920
LOCK(walletInstance->cs_wallet);
29162921
walletInstance->SetBroadcastTransactions(args.GetBoolArg("-walletbroadcast", DEFAULT_WALLETBROADCAST));

src/wallet/wallet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ std::shared_ptr<CWallet> LoadWallet(WalletContext& context, const std::string& n
6767
std::shared_ptr<CWallet> CreateWallet(WalletContext& context, const std::string& name, std::optional<bool> load_on_start, DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error, std::vector<bilingual_str>& warnings);
6868
std::shared_ptr<CWallet> RestoreWallet(WalletContext& context, const fs::path& backup_file, const std::string& wallet_name, std::optional<bool> load_on_start, DatabaseStatus& status, bilingual_str& error, std::vector<bilingual_str>& warnings);
6969
std::unique_ptr<interfaces::Handler> HandleLoadWallet(WalletContext& context, LoadWalletFn load_wallet);
70+
void NotifyWalletLoaded(WalletContext& context, const std::shared_ptr<CWallet>& wallet);
7071
std::unique_ptr<WalletDatabase> MakeWalletDatabase(const std::string& name, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error);
7172

7273
//! -paytxfee default

0 commit comments

Comments
 (0)