[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().
This commit is contained in:
parent
59b87a27ef
commit
470316c3bf
3 changed files with 7 additions and 13 deletions
|
@ -6,6 +6,7 @@
|
||||||
#include <chainparams.h>
|
#include <chainparams.h>
|
||||||
#include <init.h>
|
#include <init.h>
|
||||||
#include <net.h>
|
#include <net.h>
|
||||||
|
#include <scheduler.h>
|
||||||
#include <util.h>
|
#include <util.h>
|
||||||
#include <utilmoneystr.h>
|
#include <utilmoneystr.h>
|
||||||
#include <validation.h>
|
#include <validation.h>
|
||||||
|
@ -264,8 +265,11 @@ bool WalletInit::Open() const
|
||||||
void WalletInit::Start(CScheduler& scheduler) const
|
void WalletInit::Start(CScheduler& scheduler) const
|
||||||
{
|
{
|
||||||
for (CWallet* pwallet : GetWallets()) {
|
for (CWallet* pwallet : GetWallets()) {
|
||||||
pwallet->postInitProcess(scheduler);
|
pwallet->postInitProcess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run a thread to flush wallet periodically
|
||||||
|
scheduler.scheduleEvery(MaybeCompactWalletDB, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WalletInit::Flush() const
|
void WalletInit::Flush() const
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
#include <primitives/block.h>
|
#include <primitives/block.h>
|
||||||
#include <primitives/transaction.h>
|
#include <primitives/transaction.h>
|
||||||
#include <script/script.h>
|
#include <script/script.h>
|
||||||
#include <scheduler.h>
|
|
||||||
#include <timedata.h>
|
#include <timedata.h>
|
||||||
#include <txmempool.h>
|
#include <txmempool.h>
|
||||||
#include <utilmoneystr.h>
|
#include <utilmoneystr.h>
|
||||||
|
@ -4308,18 +4307,11 @@ CWallet* CWallet::CreateWalletFromFile(const std::string& name, const fs::path&
|
||||||
return walletInstance;
|
return walletInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::atomic<bool> CWallet::fFlushScheduled(false);
|
void CWallet::postInitProcess()
|
||||||
|
|
||||||
void CWallet::postInitProcess(CScheduler& scheduler)
|
|
||||||
{
|
{
|
||||||
// Add wallet transactions that aren't already in a block to mempool
|
// Add wallet transactions that aren't already in a block to mempool
|
||||||
// Do this here as mempool requires genesis block to be loaded
|
// Do this here as mempool requires genesis block to be loaded
|
||||||
ReacceptWalletTransactions();
|
ReacceptWalletTransactions();
|
||||||
|
|
||||||
// Run a thread to flush wallet periodically
|
|
||||||
if (!CWallet::fFlushScheduled.exchange(true)) {
|
|
||||||
scheduler.scheduleEvery(MaybeCompactWalletDB, 500);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::BackupWallet(const std::string& strDest)
|
bool CWallet::BackupWallet(const std::string& strDest)
|
||||||
|
|
|
@ -68,7 +68,6 @@ class CCoinControl;
|
||||||
class COutput;
|
class COutput;
|
||||||
class CReserveKey;
|
class CReserveKey;
|
||||||
class CScript;
|
class CScript;
|
||||||
class CScheduler;
|
|
||||||
class CTxMemPool;
|
class CTxMemPool;
|
||||||
class CBlockPolicyEstimator;
|
class CBlockPolicyEstimator;
|
||||||
class CWalletTx;
|
class CWalletTx;
|
||||||
|
@ -675,7 +674,6 @@ class WalletRescanReserver; //forward declarations for ScanForWalletTransactions
|
||||||
class CWallet final : public CCryptoKeyStore, public CValidationInterface
|
class CWallet final : public CCryptoKeyStore, public CValidationInterface
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static std::atomic<bool> fFlushScheduled;
|
|
||||||
std::atomic<bool> fAbortRescan{false};
|
std::atomic<bool> fAbortRescan{false};
|
||||||
std::atomic<bool> fScanningWallet{false}; // controlled by WalletRescanReserver
|
std::atomic<bool> fScanningWallet{false}; // controlled by WalletRescanReserver
|
||||||
std::mutex mutexScanning;
|
std::mutex mutexScanning;
|
||||||
|
@ -1127,7 +1125,7 @@ public:
|
||||||
* Wallet post-init setup
|
* Wallet post-init setup
|
||||||
* Gives the wallet a chance to register repetitive tasks and complete post-init tasks
|
* Gives the wallet a chance to register repetitive tasks and complete post-init tasks
|
||||||
*/
|
*/
|
||||||
void postInitProcess(CScheduler& scheduler);
|
void postInitProcess();
|
||||||
|
|
||||||
bool BackupWallet(const std::string& strDest);
|
bool BackupWallet(const std::string& strDest);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue