Skip to content

Commit

Permalink
wallet: load flags before everything else
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjors committed Feb 9, 2021
1 parent b847f49 commit 9305862
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/wallet/walletdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,13 +551,6 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
CHDChain chain;
ssValue >> chain;
pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadHDChain(chain);
} else if (strType == DBKeys::FLAGS) {
uint64_t flags;
ssValue >> flags;
if (!pwallet->LoadWalletFlags(flags)) {
strErr = "Error reading wallet database: Unknown non-tolerable wallet flags found";
return false;
}
} else if (strType == DBKeys::OLD_KEY) {
strErr = "Found unsupported 'wkey' record, try loading with version 0.18";
return false;
Expand Down Expand Up @@ -662,7 +655,8 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
wss.fIsEncrypted = true;
} else if (strType != DBKeys::BESTBLOCK && strType != DBKeys::BESTBLOCK_NOMERKLE &&
strType != DBKeys::MINVERSION && strType != DBKeys::ACENTRY &&
strType != DBKeys::VERSION && strType != DBKeys::SETTINGS) {
strType != DBKeys::VERSION && strType != DBKeys::SETTINGS &&
strType != DBKeys::FLAGS) {
wss.m_unknown_records++;
}
} catch (const std::exception& e) {
Expand Down Expand Up @@ -707,6 +701,16 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
pwallet->LoadMinVersion(nMinVersion);
}

// Load wallet flags, so they are known when processing other records.
// The FLAGS key is absent during wallet creation.
uint64_t flags;
if (m_batch->Read(DBKeys::FLAGS, flags)) {
if (!pwallet->LoadWalletFlags(flags)) {
pwallet->WalletLogPrintf("Error reading wallet database: Unknown non-tolerable wallet flags found\n");
return DBErrors::CORRUPT;
}
}

// Get cursor
if (!m_batch->StartCursor())
{
Expand Down

0 comments on commit 9305862

Please sign in to comment.