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 15, 2020
1 parent 36cbfd6 commit a7f55b3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 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 @@ -5196,18 +5195,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
18 changes: 8 additions & 10 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 @@ -700,14 +699,13 @@ class CAccountingEntry
};


/**
/**
* A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,
* and provides the ability to create new transactions.
*/
class CWallet final : public CCryptoKeyStore, public CValidationInterface
{
private:
static std::atomic<bool> fFlushScheduled;
std::atomic<bool> fAbortRescan;
std::atomic<bool> fScanningWallet;

Expand Down Expand Up @@ -1018,7 +1016,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 @@ -1146,7 +1144,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 @@ -1168,7 +1166,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 @@ -1177,7 +1175,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 @@ -1214,7 +1212,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 @@ -1287,7 +1285,7 @@ class CReserveKey final : public CReserveScript
};


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

0 comments on commit a7f55b3

Please sign in to comment.