Merge #21127: wallet: load flags before everything else

9305862f71189d47c873d366bf976622447e18af 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:
  https://github.com/bitcoin/bitcoin/pull/16546#discussion_r572334983

ACKs for top commit:
  laanwj:
    Code review ACK 9305862f71189d47c873d366bf976622447e18af
  gruve-p:
    ACK 9305862f71
  achow101:
    ACK 9305862f71189d47c873d366bf976622447e18af

Tree-SHA512: 7104523e369ce3c670571fe5e8b52c67b9ca92b8e36a2da5eb6f9f8bf8ed0544897007257204b68f6f371d682b3ef0d0635d36e6e8416ac74af1999d9fbc869c
This commit is contained in:
Wladimir J. van der Laan 2021-02-13 23:30:46 +01:00 committed by Konstantin Akimov
parent 19b2b27785
commit 14ac2b77f3
No known key found for this signature in database
GPG Key ID: 2176C4A5D01EA524

View File

@ -554,13 +554,6 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
strErr = "Invalid governance object: LoadGovernanceObject"; strErr = "Invalid governance object: LoadGovernanceObject";
return false; return false;
} }
} 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) { } else if (strType == DBKeys::OLD_KEY) {
strErr = "Found unsupported 'wkey' record, try loading with version 0.17"; strErr = "Found unsupported 'wkey' record, try loading with version 0.17";
return false; return false;
@ -665,7 +658,8 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
} else if (strType != DBKeys::BESTBLOCK && strType != DBKeys::BESTBLOCK_NOMERKLE && } else if (strType != DBKeys::BESTBLOCK && strType != DBKeys::BESTBLOCK_NOMERKLE &&
strType != DBKeys::MINVERSION && strType != DBKeys::ACENTRY && strType != DBKeys::MINVERSION && strType != DBKeys::ACENTRY &&
strType != DBKeys::VERSION && strType != DBKeys::SETTINGS && 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++; wss.m_unknown_records++;
} }
} catch (const std::exception& e) { } catch (const std::exception& e) {
@ -711,6 +705,16 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
pwallet->LoadMinVersion(nMinVersion); 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 // Get cursor
if (!m_batch->StartCursor()) if (!m_batch->StartCursor())
{ {