diff --git a/src/Makefile.test.include b/src/Makefile.test.include
index dd6dda7178c3..906db74e1c06 100644
--- a/src/Makefile.test.include
+++ b/src/Makefile.test.include
@@ -207,6 +207,7 @@ BITCOIN_TESTS =\
if ENABLE_WALLET
BITCOIN_TESTS += \
+ wallet/test/backup_tests.cpp \
wallet/test/bip39_tests.cpp \
wallet/test/coinjoin_tests.cpp \
wallet/test/psbt_wallet_tests.cpp \
diff --git a/src/coinjoin/client.cpp b/src/coinjoin/client.cpp
index 79651d64e428..597e0042ae8a 100644
--- a/src/coinjoin/client.cpp
+++ b/src/coinjoin/client.cpp
@@ -724,7 +724,7 @@ bool CCoinJoinClientManager::CheckAutomaticBackup()
// We don't need auto-backups for descriptor wallets
if (!m_wallet->IsLegacy()) return true;
- switch (nWalletBackups) {
+ switch (CWallet::nWalletBackups) {
case 0:
strAutoDenomResult = _("Automatic backups disabled") + Untranslated(", ") + _("no mixing available.");
WalletCJLogPrint(m_wallet, "CCoinJoinClientManager::CheckAutomaticBackup -- %s\n", strAutoDenomResult.original);
diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h
index e9f209df28f4..a793b5ff9c4a 100644
--- a/src/interfaces/wallet.h
+++ b/src/interfaces/wallet.h
@@ -108,6 +108,10 @@ class Wallet
//! Get the number of keys since the last auto backup
virtual int64_t getKeysLeftSinceAutoBackup() = 0;
+ //! Get wallet backup status
+ //! Returns: 1..20 = number of backups to keep, 0 = disabled, -1 = error, -2 = locked
+ virtual int getWalletBackupStatus() = 0;
+
//! Get wallet name.
virtual std::string getWalletName() = 0;
diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp
index 80f399bd0328..a9e0b08e8384 100644
--- a/src/qt/overviewpage.cpp
+++ b/src/qt/overviewpage.cpp
@@ -498,9 +498,10 @@ void OverviewPage::coinJoinStatus(bool fForce)
if (!fForce && (clientModel->node().shutdownRequested() || !clientModel->masternodeSync().isBlockchainSynced())) return;
// Disable any PS UI for masternode or when autobackup is disabled or failed for whatever reason
- if (clientModel->node().isMasternode() || nWalletBackups <= 0) {
+ int backupStatus = walletModel->wallet().getWalletBackupStatus();
+ if (clientModel->node().isMasternode() || backupStatus <= 0) {
DisableCoinJoinCompletely();
- if (nWalletBackups <= 0) {
+ if (backupStatus <= 0) {
ui->labelCoinJoinEnabled->setToolTip(tr("Automatic backups are disabled, no mixing available!"));
}
return;
@@ -595,7 +596,7 @@ void OverviewPage::coinJoinStatus(bool fForce)
// Warn user that wallet is running out of keys
// NOTE: we do NOT warn user and do NOT create autobackups if mixing is not running
- if (walletModel->wallet().isLegacy() && nWalletBackups > 0 && walletModel->getKeysLeftSinceAutoBackup() < COINJOIN_KEYS_THRESHOLD_WARNING) {
+ if (walletModel->wallet().isLegacy() && walletModel->wallet().getWalletBackupStatus() > 0 && walletModel->getKeysLeftSinceAutoBackup() < COINJOIN_KEYS_THRESHOLD_WARNING) {
QSettings settings;
if(settings.value("fLowKeysWarning").toBool()) {
QString strWarn = tr("Very low number of keys left since last automatic backup!") + "
" +
@@ -639,7 +640,8 @@ void OverviewPage::coinJoinStatus(bool fForce)
ui->labelCoinJoinEnabled->setText(strEnabled);
if (walletModel->wallet().isLegacy()) {
- if(nWalletBackups == -1) {
+ int backupStatus = walletModel->wallet().getWalletBackupStatus();
+ if (backupStatus == -1) {
// Automatic backup failed, nothing else we can do until user fixes the issue manually
DisableCoinJoinCompletely();
@@ -649,7 +651,7 @@ void OverviewPage::coinJoinStatus(bool fForce)
ui->labelCoinJoinEnabled->setToolTip(strError);
return;
- } else if(nWalletBackups == -2) {
+ } else if (backupStatus == -2) {
// We were able to create automatic backup but keypool was not replenished because wallet is locked.
QString strWarning = tr("WARNING! Failed to replenish keypool, please unlock your wallet to do so.");
ui->labelCoinJoinEnabled->setToolTip(strWarning);
@@ -754,7 +756,7 @@ void OverviewPage::DisableCoinJoinCompletely()
ui->toggleCoinJoin->setText("(" + tr("Disabled") + ")");
ui->frameCoinJoin->setEnabled(false);
- if (nWalletBackups <= 0) {
+ if (walletModel && walletModel->wallet().getWalletBackupStatus() <= 0) {
ui->labelCoinJoinEnabled->setText("(" + tr("Disabled") + ")");
}
walletModel->coinJoin()->stopMixing();
diff --git a/src/util/system.cpp b/src/util/system.cpp
index c9e849b69229..ac9b1b5b82b9 100644
--- a/src/util/system.cpp
+++ b/src/util/system.cpp
@@ -78,15 +78,6 @@ const int64_t nStartupTime = GetTime();
//Dash only features
const std::string gCoinJoinName = "CoinJoin";
-/**
- nWalletBackups:
- 1..10 - number of automatic backups to keep
- 0 - disabled by command-line
- -1 - disabled because of some error during run-time
- -2 - disabled because wallet was locked and we were not able to replenish keypool
-*/
-int nWalletBackups = 10;
-
const char * const BITCOIN_CONF_FILENAME = "dash.conf";
const char * const BITCOIN_SETTINGS_FILENAME = "settings.json";
diff --git a/src/util/system.h b/src/util/system.h
index 0b228858047f..52a4e3640cd7 100644
--- a/src/util/system.h
+++ b/src/util/system.h
@@ -35,7 +35,6 @@
//Dash only features
-extern int nWalletBackups;
extern const std::string gCoinJoinName;
class UniValue;
diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp
index 444e066b0021..87e946102176 100644
--- a/src/wallet/init.cpp
+++ b/src/wallet/init.cpp
@@ -59,7 +59,8 @@ void WalletInit::AddWalletOptions(ArgsManager& argsman) const
{
argsman.AddArg("-avoidpartialspends", strprintf("Group outputs by address, selecting many (possibly all) or none, instead of selecting on a per-output basis. Privacy is improved as addresses are mostly swept with fewer transactions and outputs are aggregated in clean change addresses. It may result in higher fees due to less optimal coin selection caused by this added limitation and possibly a larger-than-necessary number of inputs being used. Always enabled for wallets with \"avoid_reuse\" enabled, otherwise default: %u.", DEFAULT_AVOIDPARTIALSPENDS), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
argsman.AddArg("-consolidatefeerate=", strprintf("The maximum feerate (in %s/kvB) at which transaction building may use more inputs than strictly necessary so that the wallet's UTXO pool can be reduced (default: %s).", CURRENCY_UNIT, FormatMoney(DEFAULT_CONSOLIDATE_FEERATE)), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
- argsman.AddArg("-createwalletbackups=", strprintf("Number of automatic wallet backups (default: %u)", nWalletBackups), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
+ argsman.AddArg("-createwalletbackups=", strprintf("Number of automatic wallet backups to keep most recent (default: %u, max: %u). Older backups are kept at exponentially spaced intervals.", DEFAULT_N_WALLET_BACKUPS, MAX_N_WALLET_BACKUPS), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
+ argsman.AddArg("-maxwalletbackups=", strprintf("Maximum total number of automatic wallet backups to keep (default: %u)", DEFAULT_MAX_BACKUPS), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
argsman.AddArg("-disablewallet", "Do not load the wallet and disable wallet RPC calls", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
#if HAVE_SYSTEM
argsman.AddArg("-instantsendnotify=", "Execute command when a wallet InstantSend transaction is successfully locked. %s in cmd is replaced by TxID and %w is replaced by wallet name. %w is not currently implemented on Windows. On systems where %w is supported, it should NOT be quoted because this would break shell escaping used to invoke the command.", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
diff --git a/src/wallet/interfaces.cpp b/src/wallet/interfaces.cpp
index 6d087a276594..526cdabe1797 100644
--- a/src/wallet/interfaces.cpp
+++ b/src/wallet/interfaces.cpp
@@ -181,6 +181,7 @@ class WalletImpl : public Wallet
return m_wallet->AutoBackupWallet(wallet_path, error_string, warnings);
}
int64_t getKeysLeftSinceAutoBackup() override { return m_wallet->nKeysLeftSinceAutoBackup; }
+ int getWalletBackupStatus() override { return CWallet::nWalletBackups; }
std::string getWalletName() override { return m_wallet->GetName(); }
util::Result getNewDestination(const std::string& label) override
{
diff --git a/src/wallet/test/backup_tests.cpp b/src/wallet/test/backup_tests.cpp
new file mode 100644
index 000000000000..8ea85d3fd6cc
--- /dev/null
+++ b/src/wallet/test/backup_tests.cpp
@@ -0,0 +1,302 @@
+#include
+#include
+
+#include
+
+#include
+#include
+#include