From 6267fa84276458f6d178ea95c4d719a1fb2ae3c0 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Mon, 9 May 2022 16:20:36 +0530 Subject: [PATCH] partial bitcoin#18923: Never schedule MaybeCompactWalletDB when -flushwallet is off Excludes faf8401c195f52470d1ca6e2c94cb3820e57ee41 and fa28a618972911239a119248ab1194702a5c36d8 --- src/qt/test/apptests.cpp | 8 +++++--- src/wallet/bdb.cpp | 4 ++-- src/wallet/load.cpp | 5 ++++- src/wallet/walletdb.cpp | 3 --- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/qt/test/apptests.cpp b/src/qt/test/apptests.cpp index ceec2db755..6766a83970 100644 --- a/src/qt/test/apptests.cpp +++ b/src/qt/test/apptests.cpp @@ -63,9 +63,10 @@ void AppTests::appTests() } #endif - BasicTestingSetup test{CBaseChainParams::REGTEST}; // Create a temp data directory to backup the gui settings to - ECC_Stop(); // Already started by the common test setup, so stop it to avoid interference - LogInstance().DisconnectTestLogger(); + fs::create_directories([] { + BasicTestingSetup test{CBaseChainParams::REGTEST}; // Create a temp data directory to backup the gui settings to + return GetDataDir() / "blocks"; + }()); m_app.parameterSetup(); GUIUtil::loadFonts(); @@ -83,6 +84,7 @@ void AppTests::appTests() m_app.exec(); // Reset global state to avoid interfering with later tests. + LogInstance().DisconnectTestLogger(); AbortShutdown(); UnloadBlockIndex(); } diff --git a/src/wallet/bdb.cpp b/src/wallet/bdb.cpp index daaf5d205c..2046144a60 100644 --- a/src/wallet/bdb.cpp +++ b/src/wallet/bdb.cpp @@ -614,8 +614,8 @@ bool BerkeleyDatabase::PeriodicFlush() if (!lockDb) return false; // Don't flush if any databases are in use - for (auto it = env->mapFileUseCount.begin() ; it != env->mapFileUseCount.end(); it++) { - if ((*it).second > 0) return false; + for (const auto& use_count : env->mapFileUseCount) { + if (use_count.second > 0) return false; } // Don't flush if there haven't been any batch writes for this database. diff --git a/src/wallet/load.cpp b/src/wallet/load.cpp index 3248ddd2cb..57d19ee83d 100644 --- a/src/wallet/load.cpp +++ b/src/wallet/load.cpp @@ -14,6 +14,7 @@ #include #include #include +#include bool VerifyWallets(interfaces::Chain& chain, const std::vector& wallet_files) { @@ -92,7 +93,9 @@ void StartWallets(CScheduler& scheduler) } // Schedule periodic wallet flushes and tx rebroadcasts - scheduler.scheduleEvery(MaybeCompactWalletDB, 500); + if (gArgs.GetBoolArg("-flushwallet", DEFAULT_FLUSHWALLET)) { + scheduler.scheduleEvery(MaybeCompactWalletDB, 500); + } scheduler.scheduleEvery(MaybeResendWalletTxs, 1000); } diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 61e9c0a7a7..e0739d2633 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -737,9 +737,6 @@ void MaybeCompactWalletDB() if (fOneThread.exchange(true)) { return; } - if (!gArgs.GetBoolArg("-flushwallet", DEFAULT_FLUSHWALLET)) { - return; - } for (const std::shared_ptr& pwallet : GetWallets()) { WalletDatabase& dbh = pwallet->GetDBHandle();