@@ -314,6 +314,7 @@ class CWalletScanState {
314
314
std::map<std::pair<uint256, CKeyID>, std::pair<CPubKey, std::vector<unsigned char >>> m_descriptor_crypt_keys;
315
315
std::map<uint160, CHDChain> m_hd_chains;
316
316
bool tx_corrupt{false };
317
+ bool descriptor_unknown{false };
317
318
318
319
CWalletScanState () = default ;
319
320
};
@@ -627,7 +628,13 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
627
628
uint256 id;
628
629
ssKey >> id;
629
630
WalletDescriptor desc;
630
- ssValue >> desc;
631
+ try {
632
+ ssValue >> desc;
633
+ } catch (const std::ios_base::failure& e) {
634
+ strErr = e.what ();
635
+ wss.descriptor_unknown = true ;
636
+ return false ;
637
+ }
631
638
if (wss.m_descriptor_caches .count (id) == 0 ) {
632
639
wss.m_descriptor_caches [id] = DescriptorCache ();
633
640
}
@@ -767,6 +774,12 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
767
774
DBErrors result = DBErrors::LOAD_OK;
768
775
769
776
LOCK (pwallet->cs_wallet );
777
+
778
+ // Last client version to open this wallet
779
+ int last_client = CLIENT_VERSION;
780
+ bool has_last_client = m_batch->Read (DBKeys::VERSION, last_client);
781
+ pwallet->WalletLogPrintf (" Wallet file version = %d, last client version = %d\n " , pwallet->GetVersion (), last_client);
782
+
770
783
try {
771
784
int nMinVersion = 0 ;
772
785
if (m_batch->Read (DBKeys::MINVERSION, nMinVersion)) {
@@ -832,6 +845,13 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
832
845
// Set tx_corrupt back to false so that the error is only printed once (per corrupt tx)
833
846
wss.tx_corrupt = false ;
834
847
result = DBErrors::CORRUPT;
848
+ } else if (wss.descriptor_unknown ) {
849
+ strErr = strprintf (" Error: Unrecognized descriptor found in wallet %s. " , pwallet->GetName ());
850
+ strErr += (last_client > CLIENT_VERSION) ? " The wallet might had been created on a newer version. " :
851
+ " The database might be corrupted or the software version is not compatible with one of your wallet descriptors. " ;
852
+ strErr += " Please try running the latest software version" ;
853
+ pwallet->WalletLogPrintf (" %s\n " , strErr);
854
+ return DBErrors::UNKNOWN_DESCRIPTOR;
835
855
} else {
836
856
// Leave other errors alone, if we try to fix them we might make things worse.
837
857
fNoncriticalErrors = true ; // ... but do warn the user there is something wrong.
@@ -884,11 +904,6 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
884
904
if (result != DBErrors::LOAD_OK)
885
905
return result;
886
906
887
- // Last client version to open this wallet
888
- int last_client = CLIENT_VERSION;
889
- bool has_last_client = m_batch->Read (DBKeys::VERSION, last_client);
890
- pwallet->WalletLogPrintf (" Wallet file version = %d, last client version = %d\n " , pwallet->GetVersion (), last_client);
891
-
892
907
pwallet->WalletLogPrintf (" Keys: %u plaintext, %u encrypted, %u w/ metadata, %u total. Unknown wallet records: %u\n " ,
893
908
wss.nKeys , wss.nCKeys , wss.nKeyMeta , wss.nKeys + wss.nCKeys , wss.m_unknown_records );
894
909
0 commit comments