aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2020-05-07 14:30:04 -0400
committerAndrew Chow <achow101-github@achow101.com>2020-07-13 11:00:54 -0400
commitd0ea9bab2804928c9f40def61fd99064d2d8f9b8 (patch)
treeee3edf72d9ff4f22542850bb66fc3fd667288e33 /src
parent160800ac105568a59e343411d21a90e9530e1b9e (diff)
downloadbitcoin-d0ea9bab2804928c9f40def61fd99064d2d8f9b8.tar.xz
walletdb: Don't remove database transaction logs and instead error
Instead of removing the database transaction logs and retrying the wallet loading, just return an error message to the user. Additionally, specifically for DB_RUNRECOVERY, notify the user that this could be due to different BDB versions. This error is pretty much only caused by compiling with a newer version of BDB and then trying to open the wallet with a version compiled with an older version of BDB.
Diffstat (limited to 'src')
-rw-r--r--src/wallet/bdb.cpp32
-rw-r--r--src/wallet/bdb.h2
-rw-r--r--src/wallet/salvage.cpp6
3 files changed, 16 insertions, 24 deletions
diff --git a/src/wallet/bdb.cpp b/src/wallet/bdb.cpp
index 54a9aa34e0..5227013be2 100644
--- a/src/wallet/bdb.cpp
+++ b/src/wallet/bdb.cpp
@@ -139,7 +139,7 @@ BerkeleyEnvironment::~BerkeleyEnvironment()
Close();
}
-bool BerkeleyEnvironment::Open(bool retry)
+bool BerkeleyEnvironment::Open(bilingual_str& err)
{
if (fDbEnvInit) {
return true;
@@ -149,6 +149,7 @@ bool BerkeleyEnvironment::Open(bool retry)
TryCreateDirectories(pathIn);
if (!LockDirectory(pathIn, ".walletlock")) {
LogPrintf("Cannot obtain a lock on wallet directory %s. Another instance of bitcoin may be using it.\n", strPath);
+ err = strprintf(_("Error initializing wallet database environment %s!"), Directory());
return false;
}
@@ -188,23 +189,11 @@ bool BerkeleyEnvironment::Open(bool retry)
LogPrintf("BerkeleyEnvironment::Open: Error %d closing failed database environment: %s\n", ret2, DbEnv::strerror(ret2));
}
Reset();
- if (retry) {
- // try moving the database env out of the way
- fs::path pathDatabaseBak = pathIn / strprintf("database.%d.bak", GetTime());
- try {
- fs::rename(pathLogDir, pathDatabaseBak);
- LogPrintf("Moved old %s to %s. Retrying.\n", pathLogDir.string(), pathDatabaseBak.string());
- } catch (const fs::filesystem_error&) {
- // failure is ok (well, not really, but it's not worse than what we started with)
- }
- // try opening it again one more time
- if (!Open(false /* retry */)) {
- // if it still fails, it probably means we can't even create the database env
- return false;
- }
- } else {
- return false;
+ err = strprintf(_("Error initializing wallet database environment %s!"), Directory());
+ if (ret == DB_RUNRECOVERY) {
+ err += Untranslated(" ") + _("This error could occur if this wallet was not shutdown cleanly and was last loaded using a build with a newer version of Berkeley DB. If so, please use the software that last loaded this wallet");
}
+ return false;
}
fDbEnvInit = true;
@@ -300,8 +289,7 @@ bool BerkeleyDatabase::Verify(bilingual_str& errorStr)
LogPrintf("Using BerkeleyDB version %s\n", BerkeleyDatabaseVersion());
LogPrintf("Using wallet %s\n", file_path.string());
- if (!env->Open(true /* retry */)) {
- errorStr = strprintf(_("Error initializing wallet database environment %s!"), walletDir);
+ if (!env->Open(errorStr)) {
return false;
}
@@ -342,7 +330,8 @@ BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase& database, const char* pszMode, bo
{
LOCK(cs_db);
- if (!env->Open(false /* retry */))
+ bilingual_str open_err;
+ if (!env->Open(open_err))
throw std::runtime_error("BerkeleyBatch: Failed to open database environment.");
pdb = database.m_db.get();
@@ -482,7 +471,8 @@ void BerkeleyEnvironment::ReloadDbEnv()
// Reset the environment
Flush(true); // This will flush and close the environment
Reset();
- Open(true);
+ bilingual_str open_err;
+ Open(open_err);
}
bool BerkeleyDatabase::Rewrite(const char* pszSkip)
diff --git a/src/wallet/bdb.h b/src/wallet/bdb.h
index 599319482b..9c1a5553c6 100644
--- a/src/wallet/bdb.h
+++ b/src/wallet/bdb.h
@@ -69,7 +69,7 @@ public:
bool Verify(const std::string& strFile);
- bool Open(bool retry);
+ bool Open(bilingual_str& error);
void Close();
void Flush(bool fShutdown);
void CheckpointLSN(const std::string& strFile);
diff --git a/src/wallet/salvage.cpp b/src/wallet/salvage.cpp
index e6e62332c0..af57210f01 100644
--- a/src/wallet/salvage.cpp
+++ b/src/wallet/salvage.cpp
@@ -5,6 +5,7 @@
#include <fs.h>
#include <streams.h>
+#include <util/translation.h>
#include <wallet/salvage.h>
#include <wallet/wallet.h>
#include <wallet/walletdb.h>
@@ -20,8 +21,9 @@ bool RecoverDatabaseFile(const fs::path& file_path)
std::string filename;
std::shared_ptr<BerkeleyEnvironment> env = GetWalletEnv(file_path, filename);
- if (!env->Open(true /* retry */)) {
- tfm::format(std::cerr, "Error initializing wallet database environment %s!", env->Directory());
+ bilingual_str open_err;
+ if (!env->Open(open_err)) {
+ tfm::format(std::cerr, "%s\n", open_err.original);
return false;
}