Skip to content

Commit 52932c5

Browse files
committed
walletdb: Refactor wallet flags loading
Move wallet flags loading to its own function in WalletBatch The return value is changed to be TOO_NEW rather than CORRUPT when unknown flags are found.
1 parent 01b35b5 commit 52932c5

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/wallet/walletdb.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,19 @@ static DBErrors LoadMinVersion(CWallet* pwallet, DatabaseBatch& batch) EXCLUSIVE
803803
return DBErrors::LOAD_OK;
804804
}
805805

806+
static DBErrors LoadWalletFlags(CWallet* pwallet, DatabaseBatch& batch) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
807+
{
808+
AssertLockHeld(pwallet->cs_wallet);
809+
uint64_t flags;
810+
if (batch.Read(DBKeys::FLAGS, flags)) {
811+
if (!pwallet->LoadWalletFlags(flags)) {
812+
pwallet->WalletLogPrintf("Error reading wallet database: Unknown non-tolerable wallet flags found\n");
813+
return DBErrors::TOO_NEW;
814+
}
815+
}
816+
return DBErrors::LOAD_OK;
817+
}
818+
806819
DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
807820
{
808821
CWalletScanState wss;
@@ -822,13 +835,7 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
822835

823836
// Load wallet flags, so they are known when processing other records.
824837
// The FLAGS key is absent during wallet creation.
825-
uint64_t flags;
826-
if (m_batch->Read(DBKeys::FLAGS, flags)) {
827-
if (!pwallet->LoadWalletFlags(flags)) {
828-
pwallet->WalletLogPrintf("Error reading wallet database: Unknown non-tolerable wallet flags found\n");
829-
return DBErrors::CORRUPT;
830-
}
831-
}
838+
if ((result = LoadWalletFlags(pwallet, *m_batch)) != DBErrors::LOAD_OK) return result;
832839

833840
#ifndef ENABLE_EXTERNAL_SIGNER
834841
if (pwallet->IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER)) {
@@ -873,9 +880,6 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
873880
// we assume the user can live with:
874881
if (IsKeyType(strType) || strType == DBKeys::DEFAULTKEY) {
875882
result = DBErrors::CORRUPT;
876-
} else if (strType == DBKeys::FLAGS) {
877-
// reading the wallet flags can only fail if unknown flags are present
878-
result = DBErrors::TOO_NEW;
879883
} else if (wss.tx_corrupt) {
880884
pwallet->WalletLogPrintf("Error: Corrupt transaction found. This can be fixed by removing transactions from wallet and rescanning.\n");
881885
// Set tx_corrupt back to false so that the error is only printed once (per corrupt tx)

0 commit comments

Comments
 (0)