From 517c7f9cba306292e12e166b9dbc6c0838f05b27 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Tue, 24 Oct 2023 17:23:36 -0400 Subject: [PATCH] gui: Check for private keys disabled before attempting unlock Before trying to unlock a wallet, first check if it has private keys disabled. If so, there is no need to unlock. Note that such wallets are not expected to occur in typical usage. However bugs in previous versions allowed such wallets to be created, and so we need to handle them. --- src/qt/walletmodel.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index ee3327530c4..d564a1c83ec 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -449,6 +449,13 @@ void WalletModel::unsubscribeFromCoreSignals() // WalletModel::UnlockContext implementation WalletModel::UnlockContext WalletModel::requestUnlock() { + // Bugs in earlier versions may have resulted in wallets with private keys disabled to become "encrypted" + // (encryption keys are present, but not actually doing anything). + // To avoid issues with such wallets, check if the wallet has private keys disabled, and if so, return a context + // that indicates the wallet is not encrypted. + if (m_wallet->privateKeysDisabled()) { + return UnlockContext(this, /*valid=*/true, /*relock=*/false); + } bool was_locked = getEncryptionStatus() == Locked; if(was_locked) {