Problem: Wallet encryption and passphrase changes update database records and live key state, but local database failures can leave them out of sync. Wallet encryption can report success after a master-key write fails, while a passphrase change can update only memory. A re-encryption failure can also leave a previously locked wallet unlocked. Descriptor key write failures can publish keys that were not persisted, and erase failures can commit both plaintext and encrypted records. A failed transaction commit instead aborts the node after publishing live encryption state. Wallet unlock and passphrase changes return only a boolean, forcing callers to duplicate or conflate error handling. The database failures cannot be triggered remotely.
Fix: For wallet encryption, publish the live master key and encrypted state of existing descriptors only after their database writes and erases succeed and the transaction commits. For passphrase changes, restore the original lock state after validating the old passphrase, encrypt a copy of the master key, and replace the live master key only after the database write succeeds. Return structured errors from wallet unlock and passphrase changes so callers can reuse messages and distinguish incorrect passphrases from encryption and database failures. Publish newly inserted descriptor keys only after their database records are written. The covered failures leave database and live key state unchanged, allowing each operation to be retried. Fresh descriptor setup after the encryption transaction remains unchanged. Fault-injection tests exercise these paths through the public wallet interface.