Skip to content

Commit 43981ee

Browse files
committed
Merge #21127: wallet: load flags before everything else
9305862 wallet: load flags before everything else (Sjors Provoost) Pull request description: Load and set wallet flags before processing other records. That way we can take them into account while processing those other records. Suggested here: bitcoin/bitcoin#16546 (comment) ACKs for top commit: laanwj: Code review ACK 9305862 gruve-p: ACK bitcoin/bitcoin@9305862 achow101: ACK 9305862 Tree-SHA512: 7104523e369ce3c670571fe5e8b52c67b9ca92b8e36a2da5eb6f9f8bf8ed0544897007257204b68f6f371d682b3ef0d0635d36e6e8416ac74af1999d9fbc869c
2 parents b08cbd0 + 9305862 commit 43981ee

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)