@@ -314,6 +314,7 @@ class CWalletScanState {
314314 std::map<std::pair<uint256, CKeyID>, std::pair<CPubKey, std::vector<unsigned char >>> m_descriptor_crypt_keys;
315315 std::map<uint160, CHDChain> m_hd_chains;
316316 bool tx_corrupt{false };
317+ bool descriptor_unknown{false };
317318
318319 CWalletScanState () = default ;
319320};
@@ -627,7 +628,13 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
627628 uint256 id;
628629 ssKey >> id;
629630 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+ }
631638 if (wss.m_descriptor_caches .count (id) == 0 ) {
632639 wss.m_descriptor_caches [id] = DescriptorCache ();
633640 }
@@ -767,6 +774,12 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
767774 DBErrors result = DBErrors::LOAD_OK;
768775
769776 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+
770783 try {
771784 int nMinVersion = 0 ;
772785 if (m_batch->Read (DBKeys::MINVERSION, nMinVersion)) {
@@ -832,6 +845,13 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
832845 // Set tx_corrupt back to false so that the error is only printed once (per corrupt tx)
833846 wss.tx_corrupt = false ;
834847 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;
835855 } else {
836856 // Leave other errors alone, if we try to fix them we might make things worse.
837857 fNoncriticalErrors = true ; // ... but do warn the user there is something wrong.
@@ -884,11 +904,6 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
884904 if (result != DBErrors::LOAD_OK)
885905 return result;
886906
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-
892907 pwallet->WalletLogPrintf (" Keys: %u plaintext, %u encrypted, %u w/ metadata, %u total. Unknown wallet records: %u\n " ,
893908 wss.nKeys , wss.nCKeys , wss.nKeyMeta , wss.nKeys + wss.nCKeys , wss.m_unknown_records );
894909
0 commit comments