From 64d88ba83b1f906b65fc3852aee6f3f04640e4f9 Mon Sep 17 00:00:00 2001 From: squid Date: Sun, 24 Sep 2023 19:41:27 -0400 Subject: [PATCH 1/2] this should fix autobackups --- src/wallet/wallet.cpp | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index f37c55f39d92..5b61520c84cb 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -5036,20 +5036,18 @@ bool CWallet::Verify(interfaces::Chain& chain, const WalletLocation& location, b // Keep same database environment instance across Verify/Recover calls below. std::unique_ptr database = CreateWalletDatabase(wallet_path); - try { - return database->Verify(error_string); - } catch (const fs::filesystem_error& e) { - error_string = Untranslated(strprintf("Error loading wallet %s. %s", location.GetName(), fsbridge::get_filesystem_error_message(e))); - return false; - } - // Let tempWallet hold the pointer to the corresponding wallet database. std::unique_ptr tempWallet = MakeUnique(chain, location, std::move(database)); if (!tempWallet->AutoBackupWallet(wallet_path, error_string, warnings) && !error_string.original.empty()) { return false; } - return true; + try { + return database->Verify(error_string); + } catch (const fs::filesystem_error& e) { + error_string = Untranslated(strprintf("Error loading wallet %s. %s", location.GetName(), fsbridge::get_filesystem_error_message(e))); + return false; + } } std::shared_ptr CWallet::CreateWalletFromFile(interfaces::Chain& chain, const WalletLocation& location, bilingual_str& error, std::vector& warnings, uint64_t wallet_creation_flags) @@ -5074,7 +5072,6 @@ std::shared_ptr CWallet::CreateWalletFromFile(interfaces::Chain& chain, int64_t nStart = GetTimeMillis(); bool fFirstRun = true; - bool fBackupCreated = false; // TODO: Can't use std::make_shared because we need a custom deleter but // should be possible to use std::allocate_shared. std::shared_ptr walletInstance(new CWallet(chain, location, CreateWalletDatabase(location.GetPath())), ReleaseWallet); @@ -5191,8 +5188,6 @@ std::shared_ptr CWallet::CreateWalletFromFile(interfaces::Chain& chain, if (!strBackupError.original.empty()) { return unload_wallet(strBackupError); } - } else { - fBackupCreated = true; } } else if (wallet_creation_flags & WALLET_FLAG_DISABLE_PRIVATE_KEYS) { // Make it impossible to disable private keys after creation @@ -5410,16 +5405,6 @@ std::shared_ptr CWallet::CreateWalletFromFile(interfaces::Chain& chain, walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->nTimeFirstKey); } - if (!fBackupCreated) { - // Try to create wallet backup after a wallet was loaded - bilingual_str strBackupError; - if (!walletInstance->AutoBackupWallet("", strBackupError, warnings)) { - if (!strBackupError.original.empty()) { - return unload_wallet(strBackupError); - } - } - } - return walletInstance; } From 8faf11552b631454d4b6394d4e5e6f3f90be0f5e Mon Sep 17 00:00:00 2001 From: squid Date: Sun, 24 Sep 2023 19:55:39 -0400 Subject: [PATCH 2/2] adjustments; verify then backup --- src/wallet/wallet.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 5b61520c84cb..523c453d1f79 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -5036,18 +5036,22 @@ bool CWallet::Verify(interfaces::Chain& chain, const WalletLocation& location, b // Keep same database environment instance across Verify/Recover calls below. std::unique_ptr database = CreateWalletDatabase(wallet_path); + try { + if (!database->Verify(error_string)) { + return false; + } + } catch (const fs::filesystem_error& e) { + error_string = Untranslated(strprintf("Error loading wallet %s. %s", location.GetName(), fsbridge::get_filesystem_error_message(e))); + return false; + } + // Let tempWallet hold the pointer to the corresponding wallet database. std::unique_ptr tempWallet = MakeUnique(chain, location, std::move(database)); if (!tempWallet->AutoBackupWallet(wallet_path, error_string, warnings) && !error_string.original.empty()) { return false; } - try { - return database->Verify(error_string); - } catch (const fs::filesystem_error& e) { - error_string = Untranslated(strprintf("Error loading wallet %s. %s", location.GetName(), fsbridge::get_filesystem_error_message(e))); - return false; - } + return true; } std::shared_ptr CWallet::CreateWalletFromFile(interfaces::Chain& chain, const WalletLocation& location, bilingual_str& error, std::vector& warnings, uint64_t wallet_creation_flags)