diff --git a/src/Makefile.test.include b/src/Makefile.test.include
index 61d50f0a0b08..38553aced04c 100644
--- a/src/Makefile.test.include
+++ b/src/Makefile.test.include
@@ -206,6 +206,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 6474cbd708bb..0192ce5b7759 100644
--- a/src/coinjoin/client.cpp
+++ b/src/coinjoin/client.cpp
@@ -610,7 +610,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 161b148ea81d..e159c3f2aec1 100644
--- a/src/interfaces/wallet.h
+++ b/src/interfaces/wallet.h
@@ -115,6 +115,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 7f11fde0f9a8..380bc89766ce 100644
--- a/src/qt/overviewpage.cpp
+++ b/src/qt/overviewpage.cpp
@@ -520,9 +520,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;
@@ -617,7 +618,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!") + "
" +
@@ -661,7 +662,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();
@@ -671,7 +673,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);
@@ -776,7 +778,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 d769dbd055be..3ef5c4e925fe 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 08722d5f57bc..be5cfd24f056 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 7bb836c40083..9837179659ed 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 f6dd6f7a0a8b..0bbecd53c624 100644
--- a/src/wallet/interfaces.cpp
+++ b/src/wallet/interfaces.cpp
@@ -213,6 +213,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