This PR fixes #30620.
As outlined in the issue, creating two wallets with load_on_startup=true
simultaneously results in only one wallet being added to the startup file.
The current issue arises because the wallet settings update process involves:
- Obtaining the settings value while acquiring the settings lock.
- Modifying the settings value.
- Overwriting the settings value while acquiring the settings lock again.
This sequence is not thread-safe. Different threads could modify the same base value simultaneously, overwriting data from other workers without realizing it.
The PR attempts to fix this by modifying the chain interface’s updateRwSetting
method to accept a function that will be called with the settings reference. This function will either update or delete the setting and return an enum indicating whether the settings need to be overwritten in this or not.
Additionally, this PR introduces two new methods to the chain interface:
overwriteRwSetting
: This method replaces the setting with a new value. Used inVerifyWallets
deleteRwSettings
: This method completely erases a specified setting. This method is currently used only inoverwriteRwSetting
.
These changes ensure that updates are race-free across all clients.