Skip to content

Commit 8ebcbc8

Browse files
committed
walletdb: don't automatically salvage when corruption is detected
1 parent d321046 commit 8ebcbc8

File tree

5 files changed

+11
-39
lines changed

5 files changed

+11
-39
lines changed

src/wallet/db.cpp

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -268,21 +268,14 @@ BerkeleyEnvironment::BerkeleyEnvironment()
268268
fMockDb = true;
269269
}
270270

271-
BerkeleyEnvironment::VerifyResult BerkeleyEnvironment::Verify(const std::string& strFile, recoverFunc_type recoverFunc, std::string& out_backup_filename)
271+
bool BerkeleyEnvironment::Verify(const std::string& strFile)
272272
{
273273
LOCK(cs_db);
274274
assert(mapFileUseCount.count(strFile) == 0);
275275

276276
Db db(dbenv.get(), 0);
277277
int result = db.verify(strFile.c_str(), nullptr, nullptr, 0);
278-
if (result == 0)
279-
return VerifyResult::VERIFY_OK;
280-
else if (recoverFunc == nullptr)
281-
return VerifyResult::RECOVER_FAIL;
282-
283-
// Try to recover:
284-
bool fRecovered = (*recoverFunc)(fs::path(strPath) / strFile, out_backup_filename);
285-
return (fRecovered ? VerifyResult::RECOVER_OK : VerifyResult::RECOVER_FAIL);
278+
return result == 0;
286279
}
287280

288281
BerkeleyBatch::SafeDbt::SafeDbt()
@@ -410,27 +403,16 @@ bool BerkeleyBatch::VerifyEnvironment(const fs::path& file_path, bilingual_str&
410403
return true;
411404
}
412405

413-
bool BerkeleyBatch::VerifyDatabaseFile(const fs::path& file_path, std::vector<bilingual_str>& warnings, bilingual_str& errorStr, BerkeleyEnvironment::recoverFunc_type recoverFunc)
406+
bool BerkeleyBatch::VerifyDatabaseFile(const fs::path& file_path, bilingual_str& errorStr)
414407
{
415408
std::string walletFile;
416409
std::shared_ptr<BerkeleyEnvironment> env = GetWalletEnv(file_path, walletFile);
417410
fs::path walletDir = env->Directory();
418411

419412
if (fs::exists(walletDir / walletFile))
420413
{
421-
std::string backup_filename;
422-
BerkeleyEnvironment::VerifyResult r = env->Verify(walletFile, recoverFunc, backup_filename);
423-
if (r == BerkeleyEnvironment::VerifyResult::RECOVER_OK)
424-
{
425-
warnings.push_back(strprintf(_("Warning: Wallet file corrupt, data salvaged!"
426-
" Original %s saved as %s in %s; if"
427-
" your balance or transactions are incorrect you should"
428-
" restore from a backup."),
429-
walletFile, backup_filename, walletDir));
430-
}
431-
if (r == BerkeleyEnvironment::VerifyResult::RECOVER_FAIL)
432-
{
433-
errorStr = strprintf(_("%s corrupt, salvage failed"), walletFile);
414+
if (!env->Verify(walletFile)) {
415+
errorStr = strprintf(_("%s corrupt. Try using the wallet tool bitcoin-wallet to salvage or restoring a backup."), walletFile);
434416
return false;
435417
}
436418
}

src/wallet/db.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,7 @@ class BerkeleyEnvironment
6666
bool IsDatabaseLoaded(const std::string& db_filename) const { return m_databases.find(db_filename) != m_databases.end(); }
6767
fs::path Directory() const { return strPath; }
6868

69-
/**
70-
* Verify that database file strFile is OK. If it is not,
71-
* call the callback to try to recover.
72-
* This must be called BEFORE strFile is opened.
73-
* Returns true if strFile is OK.
74-
*/
75-
enum class VerifyResult { VERIFY_OK,
76-
RECOVER_OK,
77-
RECOVER_FAIL };
78-
typedef bool (*recoverFunc_type)(const fs::path& file_path, std::string& out_backup_filename);
79-
VerifyResult Verify(const std::string& strFile, recoverFunc_type recoverFunc, std::string& out_backup_filename);
69+
bool Verify(const std::string& strFile);
8070
/**
8171
* Salvage data from a file that Verify says is bad.
8272
* fAggressive sets the DB_AGGRESSIVE flag (see berkeley DB->verify() method documentation).
@@ -253,7 +243,7 @@ class BerkeleyBatch
253243
/* verifies the database environment */
254244
static bool VerifyEnvironment(const fs::path& file_path, bilingual_str& errorStr);
255245
/* verifies the database file */
256-
static bool VerifyDatabaseFile(const fs::path& file_path, std::vector<bilingual_str>& warnings, bilingual_str& errorStr, BerkeleyEnvironment::recoverFunc_type recoverFunc);
246+
static bool VerifyDatabaseFile(const fs::path& file_path, bilingual_str& errorStr);
257247

258248
template <typename K, typename T>
259249
bool Read(const K& key, T& value)

src/wallet/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3694,7 +3694,7 @@ bool CWallet::Verify(interfaces::Chain& chain, const WalletLocation& location, b
36943694
return false;
36953695
}
36963696

3697-
return WalletBatch::VerifyDatabaseFile(wallet_path, warnings, error_string);
3697+
return WalletBatch::VerifyDatabaseFile(wallet_path, error_string);
36983698
}
36993699

37003700
std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain, const WalletLocation& location, bilingual_str& error, std::vector<bilingual_str>& warnings, uint64_t wallet_creation_flags)

src/wallet/walletdb.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -922,9 +922,9 @@ bool WalletBatch::VerifyEnvironment(const fs::path& wallet_path, bilingual_str&
922922
return BerkeleyBatch::VerifyEnvironment(wallet_path, errorStr);
923923
}
924924

925-
bool WalletBatch::VerifyDatabaseFile(const fs::path& wallet_path, std::vector<bilingual_str>& warnings, bilingual_str& errorStr)
925+
bool WalletBatch::VerifyDatabaseFile(const fs::path& wallet_path, bilingual_str& errorStr)
926926
{
927-
return BerkeleyBatch::VerifyDatabaseFile(wallet_path, warnings, errorStr, WalletBatch::Recover);
927+
return BerkeleyBatch::VerifyDatabaseFile(wallet_path, errorStr);
928928
}
929929

930930
bool WalletBatch::WriteDestData(const std::string &address, const std::string &key, const std::string &value)

src/wallet/walletdb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ class WalletBatch
274274
/* verifies the database environment */
275275
static bool VerifyEnvironment(const fs::path& wallet_path, bilingual_str& errorStr);
276276
/* verifies the database file */
277-
static bool VerifyDatabaseFile(const fs::path& wallet_path, std::vector<bilingual_str>& warnings, bilingual_str& errorStr);
277+
static bool VerifyDatabaseFile(const fs::path& wallet_path, bilingual_str& errorStr);
278278

279279
//! write the hdchain model (external chain child index counter)
280280
bool WriteHDChain(const CHDChain& chain);

0 commit comments

Comments
 (0)