Skip to content

Commit

Permalink
Begin Merge bitcoin#10740: [wallet] setup wallet background flushing …
Browse files Browse the repository at this point in the history
…in WalletInit directly

Also move PS maintenance into wallet/init.cpp

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().

Signed-off-by: Pasta <pasta@dashboost.org>
  • Loading branch information
John Newbery authored and PastaPastaPasta committed Apr 16, 2020
1 parent af06fb5 commit 63d6252
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
6 changes: 5 additions & 1 deletion src/wallet/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <keepass.h>
#include <net.h>
#include <scheduler.h>
#include <util.h>
#include <utilmoneystr.h>
#include <validation.h>
Expand Down Expand Up @@ -321,8 +322,11 @@ bool WalletInit::Open()
void WalletInit::Start(CScheduler& scheduler)
{
for (CWallet* pwallet : GetWallets()) {
pwallet->postInitProcess(scheduler);
pwallet->postInitProcess();
}

// Run a thread to flush wallet periodically
scheduler.scheduleEvery(MaybeCompactWalletDB, 500);
// Only do this once
GetWallets()[0]->schedulePrivateSendClientMaintenance(scheduler);

Expand Down
10 changes: 1 addition & 9 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <primitives/transaction.h>
#include <script/script.h>
#include <script/sign.h>
#include <scheduler.h>
#include <timedata.h>
#include <txmempool.h>
#include <util.h>
Expand Down Expand Up @@ -5233,18 +5232,11 @@ CWallet* CWallet::CreateWalletFromFile(const std::string& name, const fs::path&
return walletInstance;
}

std::atomic<bool> CWallet::fFlushScheduled(false);

void CWallet::postInitProcess(CScheduler& scheduler)
void CWallet::postInitProcess()
{
// Add wallet transactions that aren't already in a block to mempool
// Do this here as mempool requires genesis block to be loaded
ReacceptWalletTransactions();

// Run a thread to flush wallet periodically
if (!CWallet::fFlushScheduled.exchange(true)) {
scheduler.scheduleEvery(MaybeCompactWalletDB, 500);
}
}

void CWallet::schedulePrivateSendClientMaintenance(CScheduler& scheduler)
Expand Down
16 changes: 7 additions & 9 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class CCoinControl;
class COutput;
class CReserveKey;
class CScript;
class CScheduler;
class CTxMemPool;
class CBlockPolicyEstimator;
class CWalletTx;
Expand Down Expand Up @@ -276,7 +275,7 @@ class CMerkleTx
bool IsCoinBase() const { return tx->IsCoinBase(); }
};

/**
/**
* A transaction with a bunch of additional info that only the owner cares about.
* It includes any unrecorded transactions needed to link it back to the block chain.
*/
Expand Down Expand Up @@ -708,7 +707,6 @@ class WalletRescanReserver; //forward declarations for ScanForWalletTransactions
class CWallet final : public CCryptoKeyStore, public CValidationInterface
{
private:
static std::atomic<bool> fFlushScheduled;
std::atomic<bool> fAbortRescan;
std::atomic<bool> fScanningWallet; //controlled by WalletRescanReserver
std::mutex mutexScanning;
Expand Down Expand Up @@ -1022,7 +1020,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
void GetKeyBirthTimes(std::map<CTxDestination, int64_t> &mapKeyBirth) const;
unsigned int ComputeTimeSmart(const CWalletTx& wtx) const;

/**
/**
* Increment the next transaction order id
* @return next transaction order id
*/
Expand Down Expand Up @@ -1150,7 +1148,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
}

void GetScriptForMining(std::shared_ptr<CReserveScript> &script);

unsigned int GetKeyPoolSize()
{
AssertLockHeld(cs_wallet); // set{Ex,In}ternalKeyPool
Expand All @@ -1172,7 +1170,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
//! Flush wallet (bitdb flush)
void Flush(bool shutdown=false);

/**
/**
* Address book entry changed.
* @note called with lock cs_wallet held.
*/
Expand All @@ -1181,7 +1179,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
const std::string &purpose,
ChangeType status)> NotifyAddressBookChanged;

/**
/**
* Wallet transaction added, removed or updated.
* @note called with lock cs_wallet held.
*/
Expand Down Expand Up @@ -1218,7 +1216,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
* Wallet post-init setup
* Gives the wallet a chance to register repetitive tasks and complete post-init tasks
*/
void postInitProcess(CScheduler& scheduler);
void postInitProcess();

void schedulePrivateSendClientMaintenance(CScheduler& scheduler);

Expand Down Expand Up @@ -1291,7 +1289,7 @@ class CReserveKey final : public CReserveScript
};


/**
/**
* Account information.
* Stored in wallet with key "acc"+string account name.
*/
Expand Down

0 comments on commit 63d6252

Please sign in to comment.