1628- mapAddressBook[address].name = strName;
1629- if (!strPurpose.empty()) /* update purpose only if requested */
1630- mapAddressBook[address].purpose = strPurpose;
1631+ bool fUpdated = false;
1632+ {
1633+ LOCK(cs_wallet); // mapAddressBook
I’ve never known the specific reason why some methods in CWallet acquire the lock and others such as address book manipulation do not (and assume the caller already holds it). But it’s always been that way.
Ideally cs_wallet and mapWallet would be private members, and all methods would acquire the lock themselves. But ideally we’d completely rewrite the wallet with deterministic key support, multisig/off-device-signing support, etc.
I’m not speaking about ideally, just about the way things are implemented now :) Will it have effect in any of the caller sites that the locking behavior of SetAddressBook changed? After all the caller sites (if they’re correct) already acquire the locks. I recently fixed some UI functions that forgot to acquire the wallet lock (28352af). I suppose this is not an issue due to the use of recursive mutexes so it doesn’t matter that it acquires/releases another instance of the lock.