@@ -471,7 +471,6 @@ ReadKeyValue(CWallet* pwallet, DataStream& ssKey, CDataStream& ssValue,
471
471
} else if (strType == DBKeys::WATCHS) {
472
472
} else if (strType == DBKeys::KEY) {
473
473
} else if (strType == DBKeys::MASTER_KEY) {
474
- if (!LoadEncryptionKey (pwallet, ssKey, ssValue, strErr)) return false ;
475
474
} else if (strType == DBKeys::CRYPTED_KEY) {
476
475
} else if (strType == DBKeys::KEYMETA) {
477
476
} else if (strType == DBKeys::WATCHMETA) {
@@ -1182,6 +1181,21 @@ static DBErrors LoadActiveSPKMs(CWallet* pwallet, DatabaseBatch& batch) EXCLUSIV
1182
1181
return result;
1183
1182
}
1184
1183
1184
+ static DBErrors LoadDecryptionKeys (CWallet* pwallet, DatabaseBatch& batch) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
1185
+ {
1186
+ AssertLockHeld (pwallet->cs_wallet );
1187
+
1188
+ // Load decryption key (mkey) records
1189
+ LoadResult mkey_res = LoadRecords (pwallet, batch, DBKeys::MASTER_KEY,
1190
+ [] (CWallet* pwallet, DataStream& key, CDataStream& value, std::string& err) {
1191
+ if (!LoadEncryptionKey (pwallet, key, value, err)) {
1192
+ return DBErrors::CORRUPT;
1193
+ }
1194
+ return DBErrors::LOAD_OK;
1195
+ });
1196
+ return mkey_res.m_result ;
1197
+ }
1198
+
1185
1199
DBErrors WalletBatch::LoadWallet (CWallet* pwallet)
1186
1200
{
1187
1201
CWalletScanState wss;
@@ -1230,6 +1244,9 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
1230
1244
// Load SPKMs
1231
1245
result = std::max (LoadActiveSPKMs (pwallet, *m_batch), result);
1232
1246
1247
+ // Load decryption keys
1248
+ result = std::max (LoadDecryptionKeys (pwallet, *m_batch), result);
1249
+
1233
1250
// Get cursor
1234
1251
std::unique_ptr<DatabaseCursor> cursor = m_batch->GetNewCursor ();
1235
1252
if (!cursor)
@@ -1256,14 +1273,8 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
1256
1273
std::string strType, strErr;
1257
1274
if (!ReadKeyValue (pwallet, ssKey, ssValue, wss, strType, strErr))
1258
1275
{
1259
- // losing keys is considered a catastrophic error, anything else
1260
- // we assume the user can live with:
1261
- if (strType == DBKeys::MASTER_KEY) {
1262
- result = DBErrors::CORRUPT;
1263
- } else {
1264
- // Leave other errors alone, if we try to fix them we might make things worse.
1265
- fNoncriticalErrors = true ; // ... but do warn the user there is something wrong.
1266
- }
1276
+ // Leave other errors alone, if we try to fix them we might make things worse.
1277
+ fNoncriticalErrors = true ; // ... but do warn the user there is something wrong.
1267
1278
}
1268
1279
if (!strErr.empty ())
1269
1280
pwallet->WalletLogPrintf (" %s\n " , strErr);
0 commit comments