Skip to content

Commit 470316c

Browse files
committed
[wallet] setup wallet background flushing in WalletInit directly
WalletInit::Start calls postInitProcess() for each wallet. Previously each call to postInitProcess() would attempt to schedule wallet background flushing. Just start wallet background flushing once from WalletInit::Start().
1 parent 59b87a2 commit 470316c

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

src/wallet/init.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <chainparams.h>
77
#include <init.h>
88
#include <net.h>
9+
#include <scheduler.h>
910
#include <util.h>
1011
#include <utilmoneystr.h>
1112
#include <validation.h>
@@ -264,8 +265,11 @@ bool WalletInit::Open() const
264265
void WalletInit::Start(CScheduler& scheduler) const
265266
{
266267
for (CWallet* pwallet : GetWallets()) {
267-
pwallet->postInitProcess(scheduler);
268+
pwallet->postInitProcess();
268269
}
270+
271+
// Run a thread to flush wallet periodically
272+
scheduler.scheduleEvery(MaybeCompactWalletDB, 500);
269273
}
270274

271275
void WalletInit::Flush() const

src/wallet/wallet.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <primitives/block.h>
2424
#include <primitives/transaction.h>
2525
#include <script/script.h>
26-
#include <scheduler.h>
2726
#include <timedata.h>
2827
#include <txmempool.h>
2928
#include <utilmoneystr.h>
@@ -4308,18 +4307,11 @@ CWallet* CWallet::CreateWalletFromFile(const std::string& name, const fs::path&
43084307
return walletInstance;
43094308
}
43104309

4311-
std::atomic<bool> CWallet::fFlushScheduled(false);
4312-
4313-
void CWallet::postInitProcess(CScheduler& scheduler)
4310+
void CWallet::postInitProcess()
43144311
{
43154312
// Add wallet transactions that aren't already in a block to mempool
43164313
// Do this here as mempool requires genesis block to be loaded
43174314
ReacceptWalletTransactions();
4318-
4319-
// Run a thread to flush wallet periodically
4320-
if (!CWallet::fFlushScheduled.exchange(true)) {
4321-
scheduler.scheduleEvery(MaybeCompactWalletDB, 500);
4322-
}
43234315
}
43244316

43254317
bool CWallet::BackupWallet(const std::string& strDest)

src/wallet/wallet.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ class CCoinControl;
6868
class COutput;
6969
class CReserveKey;
7070
class CScript;
71-
class CScheduler;
7271
class CTxMemPool;
7372
class CBlockPolicyEstimator;
7473
class CWalletTx;
@@ -675,7 +674,6 @@ class WalletRescanReserver; //forward declarations for ScanForWalletTransactions
675674
class CWallet final : public CCryptoKeyStore, public CValidationInterface
676675
{
677676
private:
678-
static std::atomic<bool> fFlushScheduled;
679677
std::atomic<bool> fAbortRescan{false};
680678
std::atomic<bool> fScanningWallet{false}; // controlled by WalletRescanReserver
681679
std::mutex mutexScanning;
@@ -1127,7 +1125,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
11271125
* Wallet post-init setup
11281126
* Gives the wallet a chance to register repetitive tasks and complete post-init tasks
11291127
*/
1130-
void postInitProcess(CScheduler& scheduler);
1128+
void postInitProcess();
11311129

11321130
bool BackupWallet(const std::string& strDest);
11331131

0 commit comments

Comments
 (0)