You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
wallet: close pre-existing races around CWallet::EncryptWallet #179
These races are in CWallet::EncryptWallet and code near it. They were found while reviewing #178 (asynchronous Encrypt Wallet for #172). They predate that PR, and it does not change wallet code. #178 does make the GUI and RPC paths overlap more easily, because the GUI no longer blocks while encryption runs.
IsCrypted() is checked before LOCK2.EncryptWallet returns early if the wallet is already crypted, but it reads that state without holding cs_wallet. An encryptwallet RPC that overlaps the GUI worker during the key-derivation window can therefore pass the check twice, double-encrypt, and hit assert(false).
mapMasterKeys stays populated when TxnBegin fails. If the database transaction cannot begin, the new master key has already been inserted in memory. The wallet is left reporting IsCrypted() although nothing was written.
IsHDEnabled / GetActiveScriptPubKeyMans read the SPKM maps without cs_wallet. Encryption replaces those managers under the lock, so an unlocked reader can see them half-replaced. qt: keep Encrypt Wallet responsive during existing-wallet encryption #178 works around this in the GUI by skipping the HD-status query while encrypting.
Expected
The already-crypted check and the encryption run under one lock acquisition, so a second concurrent caller fails cleanly with "already encrypted".
A failed TxnBegin leaves no in-memory master key behind.
The SPKM accessors hold, or assert, the wallet lock.
Scope / acceptance
Wallet-layer fixes only. Add a unit or functional test for each item that can be reproduced deterministically; for example, the overlapping encryptwallet calls can be driven by a test hook or sync point.
No change to the wallet format or to encryption semantics.
Release tracking
This is not a v1.0.1 blocker unless the maintainer decides otherwise (#174). Each item needs a concurrent encrypt call, a DB error, or an unlocked reader during encryption.
Activity
kiwidream commentedon Sep 25, 2026
Added to the v1.0.1 scope in #174. Work is in progress; the PR will link back here.
wallet: close races around CWallet::EncryptWallet (#183)
wallet: close races around CWallet::EncryptWallet (#183)