Skip to content

Commit 9305862

Browse files
committed
wallet: load flags before everything else
1 parent b847f49 commit 9305862

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/wallet/walletdb.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -551,13 +551,6 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
551551
CHDChain chain;
552552
ssValue >> chain;
553553
pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadHDChain(chain);
554-
} else if (strType == DBKeys::FLAGS) {
555-
uint64_t flags;
556-
ssValue >> flags;
557-
if (!pwallet->LoadWalletFlags(flags)) {
558-
strErr = "Error reading wallet database: Unknown non-tolerable wallet flags found";
559-
return false;
560-
}
561554
} else if (strType == DBKeys::OLD_KEY) {
562555
strErr = "Found unsupported 'wkey' record, try loading with version 0.18";
563556
return false;
@@ -662,7 +655,8 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
662655
wss.fIsEncrypted = true;
663656
} else if (strType != DBKeys::BESTBLOCK && strType != DBKeys::BESTBLOCK_NOMERKLE &&
664657
strType != DBKeys::MINVERSION && strType != DBKeys::ACENTRY &&
665-
strType != DBKeys::VERSION && strType != DBKeys::SETTINGS) {
658+
strType != DBKeys::VERSION && strType != DBKeys::SETTINGS &&
659+
strType != DBKeys::FLAGS) {
666660
wss.m_unknown_records++;
667661
}
668662
} catch (const std::exception& e) {
@@ -707,6 +701,16 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
707701
pwallet->LoadMinVersion(nMinVersion);
708702
}
709703

704+
// Load wallet flags, so they are known when processing other records.
705+
// The FLAGS key is absent during wallet creation.
706+
uint64_t flags;
707+
if (m_batch->Read(DBKeys::FLAGS, flags)) {
708+
if (!pwallet->LoadWalletFlags(flags)) {
709+
pwallet->WalletLogPrintf("Error reading wallet database: Unknown non-tolerable wallet flags found\n");
710+
return DBErrors::CORRUPT;
711+
}
712+
}
713+
710714
// Get cursor
711715
if (!m_batch->StartCursor())
712716
{

0 commit comments

Comments
 (0)