Skip to content

Commit

Permalink
Merge bitcoin#21127: wallet: load flags before everything else
Browse files Browse the repository at this point in the history
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#16546 (comment)

ACKs for top commit:
  laanwj:
    Code review ACK 9305862
  gruve-p:
    ACK bitcoin@9305862
  achow101:
    ACK 9305862

Tree-SHA512: 7104523e369ce3c670571fe5e8b52c67b9ca92b8e36a2da5eb6f9f8bf8ed0544897007257204b68f6f371d682b3ef0d0635d36e6e8416ac74af1999d9fbc869c
  • Loading branch information
laanwj authored and knst committed May 8, 2024
1 parent 40f09be commit e3968fa
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/wallet/walletdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,8 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
} else if (strType != DBKeys::BESTBLOCK && strType != DBKeys::BESTBLOCK_NOMERKLE &&
strType != DBKeys::MINVERSION && strType != DBKeys::ACENTRY &&
strType != DBKeys::VERSION && strType != DBKeys::SETTINGS &&
strType != DBKeys::PRIVATESEND_SALT && strType != DBKeys::COINJOIN_SALT) {
strType != DBKeys::PRIVATESEND_SALT && strType != DBKeys::COINJOIN_SALT &&
strType != DBKeys::FLAGS) {
wss.m_unknown_records++;
}
} catch (const std::exception& e) {
Expand Down Expand Up @@ -711,6 +712,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 e3968fa

Please sign in to comment.