Skip to content

Commit 94ffc35

Browse files
UdjinM6PastaPastaPasta
authored andcommitted
fix: remove duplicate global nWalletBackups variable
Remove the unused global nWalletBackups from util/system and use CWallet::nWalletBackups everywhere. Qt and CoinJoin code now access the backup status through the interfaces::Wallet::getWalletBackupStatus() method instead of directly accessing wallet internals. This fixes a bug where the global was never updated from its initial value of 10, causing Qt/CoinJoin to see incorrect backup status.
1 parent d7a5176 commit 94ffc35

File tree

6 files changed

+14
-17
lines changed

6 files changed

+14
-17
lines changed

src/coinjoin/client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ bool CCoinJoinClientManager::CheckAutomaticBackup()
724724
// We don't need auto-backups for descriptor wallets
725725
if (!m_wallet->IsLegacy()) return true;
726726

727-
switch (nWalletBackups) {
727+
switch (CWallet::nWalletBackups) {
728728
case 0:
729729
strAutoDenomResult = _("Automatic backups disabled") + Untranslated(", ") + _("no mixing available.");
730730
WalletCJLogPrint(m_wallet, "CCoinJoinClientManager::CheckAutomaticBackup -- %s\n", strAutoDenomResult.original);

src/interfaces/wallet.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ class Wallet
108108
//! Get the number of keys since the last auto backup
109109
virtual int64_t getKeysLeftSinceAutoBackup() = 0;
110110

111+
//! Get wallet backup status
112+
//! Returns: 1..20 = number of backups to keep, 0 = disabled, -1 = error, -2 = locked
113+
virtual int getWalletBackupStatus() = 0;
114+
111115
//! Get wallet name.
112116
virtual std::string getWalletName() = 0;
113117

src/qt/overviewpage.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,10 @@ void OverviewPage::coinJoinStatus(bool fForce)
498498
if (!fForce && (clientModel->node().shutdownRequested() || !clientModel->masternodeSync().isBlockchainSynced())) return;
499499

500500
// Disable any PS UI for masternode or when autobackup is disabled or failed for whatever reason
501-
if (clientModel->node().isMasternode() || nWalletBackups <= 0) {
501+
int backupStatus = walletModel->wallet().getWalletBackupStatus();
502+
if (clientModel->node().isMasternode() || backupStatus <= 0) {
502503
DisableCoinJoinCompletely();
503-
if (nWalletBackups <= 0) {
504+
if (backupStatus <= 0) {
504505
ui->labelCoinJoinEnabled->setToolTip(tr("Automatic backups are disabled, no mixing available!"));
505506
}
506507
return;
@@ -595,7 +596,7 @@ void OverviewPage::coinJoinStatus(bool fForce)
595596

596597
// Warn user that wallet is running out of keys
597598
// NOTE: we do NOT warn user and do NOT create autobackups if mixing is not running
598-
if (walletModel->wallet().isLegacy() && nWalletBackups > 0 && walletModel->getKeysLeftSinceAutoBackup() < COINJOIN_KEYS_THRESHOLD_WARNING) {
599+
if (walletModel->wallet().isLegacy() && walletModel->wallet().getWalletBackupStatus() > 0 && walletModel->getKeysLeftSinceAutoBackup() < COINJOIN_KEYS_THRESHOLD_WARNING) {
599600
QSettings settings;
600601
if(settings.value("fLowKeysWarning").toBool()) {
601602
QString strWarn = tr("Very low number of keys left since last automatic backup!") + "<br><br>" +
@@ -639,7 +640,8 @@ void OverviewPage::coinJoinStatus(bool fForce)
639640
ui->labelCoinJoinEnabled->setText(strEnabled);
640641

641642
if (walletModel->wallet().isLegacy()) {
642-
if(nWalletBackups == -1) {
643+
int backupStatus = walletModel->wallet().getWalletBackupStatus();
644+
if (backupStatus == -1) {
643645
// Automatic backup failed, nothing else we can do until user fixes the issue manually
644646
DisableCoinJoinCompletely();
645647

@@ -649,7 +651,7 @@ void OverviewPage::coinJoinStatus(bool fForce)
649651
ui->labelCoinJoinEnabled->setToolTip(strError);
650652

651653
return;
652-
} else if(nWalletBackups == -2) {
654+
} else if (backupStatus == -2) {
653655
// We were able to create automatic backup but keypool was not replenished because wallet is locked.
654656
QString strWarning = tr("WARNING! Failed to replenish keypool, please unlock your wallet to do so.");
655657
ui->labelCoinJoinEnabled->setToolTip(strWarning);
@@ -754,7 +756,7 @@ void OverviewPage::DisableCoinJoinCompletely()
754756

755757
ui->toggleCoinJoin->setText("(" + tr("Disabled") + ")");
756758
ui->frameCoinJoin->setEnabled(false);
757-
if (nWalletBackups <= 0) {
759+
if (walletModel && walletModel->wallet().getWalletBackupStatus() <= 0) {
758760
ui->labelCoinJoinEnabled->setText("<span style='" + GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_ERROR) + "'>(" + tr("Disabled") + ")</span>");
759761
}
760762
walletModel->coinJoin()->stopMixing();

src/util/system.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,6 @@ const int64_t nStartupTime = GetTime();
7878
//Dash only features
7979
const std::string gCoinJoinName = "CoinJoin";
8080

81-
/**
82-
nWalletBackups:
83-
1..10 - number of automatic backups to keep
84-
0 - disabled by command-line
85-
-1 - disabled because of some error during run-time
86-
-2 - disabled because wallet was locked and we were not able to replenish keypool
87-
*/
88-
int nWalletBackups = 10;
89-
9081
const char * const BITCOIN_CONF_FILENAME = "dash.conf";
9182
const char * const BITCOIN_SETTINGS_FILENAME = "settings.json";
9283

src/util/system.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
//Dash only features
3737

38-
extern int nWalletBackups;
3938
extern const std::string gCoinJoinName;
4039

4140
class UniValue;

src/wallet/interfaces.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ class WalletImpl : public Wallet
181181
return m_wallet->AutoBackupWallet(wallet_path, error_string, warnings);
182182
}
183183
int64_t getKeysLeftSinceAutoBackup() override { return m_wallet->nKeysLeftSinceAutoBackup; }
184+
int getWalletBackupStatus() override { return CWallet::nWalletBackups; }
184185
std::string getWalletName() override { return m_wallet->GetName(); }
185186
util::Result<CTxDestination> getNewDestination(const std::string& label) override
186187
{

0 commit comments

Comments
 (0)