diff --git a/src/wallet/db.h b/src/wallet/db.h --- a/src/wallet/db.h +++ b/src/wallet/db.h @@ -62,19 +62,7 @@ } fs::path Directory() const { return strPath; } - /** - * Verify that database file strFile is OK. If it is not, call the callback - * to try to recover. - * This must be called BEFORE strFile is opened. - * Returns true if strFile is OK. - */ - enum class VerifyResult { VERIFY_OK, RECOVER_OK, RECOVER_FAIL }; - typedef bool (*recoverFunc_type)(const fs::path &file_path, - std::string &out_backup_filename); - VerifyResult Verify(const std::string &strFile, - recoverFunc_type recoverFunc, - std::string &out_backup_filename); - + bool Verify(const std::string &strFile); /** * Salvage data from a file that Verify says is bad. * fAggressive sets the DB_AGGRESSIVE flag (see berkeley DB->verify() method @@ -275,11 +263,8 @@ static bool VerifyEnvironment(const fs::path &file_path, bilingual_str &errorStr); /* verifies the database file */ - static bool - VerifyDatabaseFile(const fs::path &file_path, - std::vector &warnings, - bilingual_str &errorStr, - BerkeleyEnvironment::recoverFunc_type recoverFunc); + static bool VerifyDatabaseFile(const fs::path &file_path, + bilingual_str &errorStr); template bool Read(const K &key, T &value) { if (!pdb) { diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp --- a/src/wallet/db.cpp +++ b/src/wallet/db.cpp @@ -298,25 +298,13 @@ fMockDb = true; } -BerkeleyEnvironment::VerifyResult -BerkeleyEnvironment::Verify(const std::string &strFile, - recoverFunc_type recoverFunc, - std::string &out_backup_filename) { +bool BerkeleyEnvironment::Verify(const std::string &strFile) { LOCK(cs_db); assert(mapFileUseCount.count(strFile) == 0); Db db(dbenv.get(), 0); int result = db.verify(strFile.c_str(), nullptr, nullptr, 0); - if (result == 0) { - return VerifyResult::VERIFY_OK; - } else if (recoverFunc == nullptr) { - return VerifyResult::RECOVER_FAIL; - } - - // Try to recover: - bool fRecovered = - (*recoverFunc)(fs::path(strPath) / strFile, out_backup_filename); - return (fRecovered ? VerifyResult::RECOVER_OK : VerifyResult::RECOVER_FAIL); + return result == 0; } BerkeleyBatch::SafeDbt::SafeDbt() { @@ -439,29 +427,19 @@ return true; } -bool BerkeleyBatch::VerifyDatabaseFile( - const fs::path &file_path, std::vector &warnings, - bilingual_str &errorStr, - BerkeleyEnvironment::recoverFunc_type recoverFunc) { +bool BerkeleyBatch::VerifyDatabaseFile(const fs::path &file_path, + bilingual_str &errorStr) { std::string walletFile; std::shared_ptr env = GetWalletEnv(file_path, walletFile); fs::path walletDir = env->Directory(); if (fs::exists(walletDir / walletFile)) { - std::string backup_filename; - BerkeleyEnvironment::VerifyResult r = - env->Verify(walletFile, recoverFunc, backup_filename); - if (r == BerkeleyEnvironment::VerifyResult::RECOVER_OK) { - warnings.push_back( - strprintf(_("Warning: Wallet file corrupt, data salvaged!" - " Original %s saved as %s in %s; if your balance " - "or transactions are incorrect you should restore " - "from a backup."), - walletFile, backup_filename, walletDir)); - } - if (r == BerkeleyEnvironment::VerifyResult::RECOVER_FAIL) { - errorStr = strprintf(_("%s corrupt, salvage failed"), walletFile); + if (!env->Verify(walletFile)) { + errorStr = + strprintf(_("%s corrupt. Try using the wallet tool " + "bitcoin-wallet to salvage or restoring a backup."), + walletFile); return false; } } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4154,7 +4154,7 @@ return false; } - return WalletBatch::VerifyDatabaseFile(wallet_path, warnings, error_string); + return WalletBatch::VerifyDatabaseFile(wallet_path, error_string); } std::shared_ptr CWallet::CreateWalletFromFile( diff --git a/src/wallet/walletdb.h b/src/wallet/walletdb.h --- a/src/wallet/walletdb.h +++ b/src/wallet/walletdb.h @@ -268,7 +268,6 @@ bilingual_str &errorStr); /* verifies the database file */ static bool VerifyDatabaseFile(const fs::path &wallet_path, - std::vector &warnings, bilingual_str &errorStr); //! write the hdchain model (external chain child index counter) diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -1008,10 +1008,8 @@ } bool WalletBatch::VerifyDatabaseFile(const fs::path &wallet_path, - std::vector &warnings, bilingual_str &errorStr) { - return BerkeleyBatch::VerifyDatabaseFile(wallet_path, warnings, errorStr, - WalletBatch::Recover); + return BerkeleyBatch::VerifyDatabaseFile(wallet_path, errorStr); } bool WalletBatch::WriteDestData(const CTxDestination &address,