Skip to content

Commit 9393666

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#19833: wallet: Avoid locking cs_wallet recursively
5fabde6 wallet: AddWalletDescriptor requires cs_wallet lock (João Barbosa) 32d036e wallet: GetLabelAddresses requires cs_wallet lock (João Barbosa) Pull request description: This is another small change towards non recursive wallet lock. ACKs for top commit: hebasto: ACK 5fabde6, I have reviewed the code and it looks OK, I agree it can be merged. Tree-SHA512: 00506f0159c56854a171e58a451db8dd9b9f735039697b1cf2ca7f54de61fb51cc1e5eff42265233e041b4b1bfd29c2247496dc4456578e1a23c323bdec2901b
2 parents 503194d + 5fabde6 commit 9393666

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/wallet/wallet.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,7 +2191,7 @@ void CWallet::MarkDestinationsDirty(const std::set<CTxDestination>& destinations
21912191

21922192
std::set<CTxDestination> CWallet::GetLabelAddresses(const std::string& label) const
21932193
{
2194-
LOCK(cs_wallet);
2194+
AssertLockHeld(cs_wallet);
21952195
std::set<CTxDestination> result;
21962196
for (const std::pair<const CTxDestination, CAddressBookData>& item : m_address_book)
21972197
{
@@ -3252,12 +3252,13 @@ DescriptorScriptPubKeyMan* CWallet::GetDescriptorScriptPubKeyMan(const WalletDes
32523252

32533253
ScriptPubKeyMan* CWallet::AddWalletDescriptor(WalletDescriptor& desc, const FlatSigningProvider& signing_provider, const std::string& label, bool internal)
32543254
{
3255+
AssertLockHeld(cs_wallet);
3256+
32553257
if (!IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
32563258
WalletLogPrintf("Cannot add WalletDescriptor to a non-descriptor wallet\n");
32573259
return nullptr;
32583260
}
32593261

3260-
LOCK(cs_wallet);
32613262
auto spk_man = GetDescriptorScriptPubKeyMan(desc);
32623263
if (spk_man) {
32633264
WalletLogPrintf("Update existing descriptor: %s\n", desc.descriptor->ToString());

src/wallet/wallet.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
630630

631631
int64_t GetOldestKeyPoolTime() const;
632632

633-
std::set<CTxDestination> GetLabelAddresses(const std::string& label) const;
633+
std::set<CTxDestination> GetLabelAddresses(const std::string& label) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
634634

635635
/**
636636
* Marks all outputs in each one of the destinations dirty, so their cache is
@@ -876,7 +876,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
876876
DescriptorScriptPubKeyMan* GetDescriptorScriptPubKeyMan(const WalletDescriptor& desc) const;
877877

878878
//! Add a descriptor to the wallet, return a ScriptPubKeyMan & associated output type
879-
ScriptPubKeyMan* AddWalletDescriptor(WalletDescriptor& desc, const FlatSigningProvider& signing_provider, const std::string& label, bool internal);
879+
ScriptPubKeyMan* AddWalletDescriptor(WalletDescriptor& desc, const FlatSigningProvider& signing_provider, const std::string& label, bool internal) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
880880
};
881881

882882
/**

0 commit comments

Comments
 (0)