Skip to content

Commit

Permalink
Merge #880: [GUI] Update Staking Slider to be reflective of status
Browse files Browse the repository at this point in the history
cad2120 [GUI] Update Staking Slider to be reflective of status (Wet One)

Pull request description:

  ### Problem
  The staking slider does not always indicate the present state of staking.  There is a delay between when staking is enabled/disabled and when the actual enabling/disabling takes place.

  ### Root Cause
  The Qt indicates the state that the wallet is in.  Some amount of time is required to ensure that the state change has taken affect.  Additionally, staking is not performed while syncing.  When the user initially opens the user interface, staking is displayed as active while syncing.  Staking is initially active but will not be performed until syncing is complete.

  ### Solution
  * Text for the staking slider now shows the current state of actual staking (enabled, disable, disabled for sync, enabling ..., disabling...).
  * The staking slider is disabled (cannot be changed) until syncing is complete.
  * Once synchronization is complete, the staking slider will be changed to enabled with the state of "Enabling ...).  When finishing synchronization testing showed some thrashing between the states of "Enabling..." and "Staking Enabled" until a few blocks have gone by.  This is due to the way active staking is calculated.
  * RPC getwalletinfo updated to show the actual state of staking and the wallet status
  * Popup entering into staking disabled has been updated to indicate that some time is required prior to the state change taking effect.

  ### Issues Addressed
  245: #245
  504: #504

  ### Bounty Payment Address
  sv1qqphsvuwhk29xcn2q9gdth9x73qpm8kcktmuxyd8szl50sgt2nt47egpqwnxr83hfj7s6fnec2jr0cv5yc7r6s7nvxhd9969qrgy4cgnznwewqqqauut5m

Tree-SHA512: 73285595254c495afd804f422be993ba6f895643284210755a979535c8c0f0af31182b9bea0aa84705f69f15b2363ba7e14b6bcd7f454d300634483f24e3de65
  • Loading branch information
CaveSpectre11 committed Dec 19, 2020
2 parents 1194909 + cad2120 commit 83bd2bf
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,8 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
tooltip += tr("Transactions after this will not yet be visible.");
}

veilStatusBar->updateStakingCheckbox();

// Don't word-wrap this (fixed-width) tooltip
tooltip = QString("<nobr>") + tooltip + QString("</nobr>");

Expand Down
61 changes: 58 additions & 3 deletions src/qt/veil/veilstatusbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <qt/walletmodel.h>
#include <qt/veil/qtutils.h>
#include <iostream>
#include <timedata.h>
#ifdef ENABLE_WALLET
#include <wallet/wallet.h> // For DEFAULT_DISABLE_WALLET
#endif
Expand Down Expand Up @@ -51,6 +52,7 @@ void VeilStatusBar::updateSyncIndicator(int height){

void VeilStatusBar::setSyncStatusVisible(bool fVisible) {
ui->btnSync->setVisible(fVisible);
syncFlag = fVisible;
}

void VeilStatusBar::onBtnSyncClicked(){
Expand All @@ -59,6 +61,52 @@ void VeilStatusBar::onBtnSyncClicked(){

#ifdef ENABLE_WALLET
bool fBlockNextStakeCheckSignal = false;
void VeilStatusBar::setStakingText() {

// Determine if staking is recently active. Note that this is not immediate effect. Staking could be disabled and it could take some time (activeStakingMaxTime) update state.
int64_t nTimeLastHashing = 0;
if (!mapHashedBlocks.empty()) {
auto pindexBest = chainActive.Tip();
if (mapHashedBlocks.count(pindexBest->GetBlockHash())) {
nTimeLastHashing = mapHashedBlocks.at(pindexBest->GetBlockHash());
} else if (mapHashedBlocks.count(pindexBest->pprev->GetBlockHash())) {
nTimeLastHashing = mapHashedBlocks.at(pindexBest->pprev->GetBlockHash());
}
}
bool fStakingActive = false;
if (nTimeLastHashing)
fStakingActive = GetAdjustedTime() + MAX_FUTURE_BLOCK_TIME - nTimeLastHashing < ACTIVE_STAKING_MAX_TIME;

WalletModel::EncryptionStatus eStatus = this->walletModel->getEncryptionStatus();

if (syncFlag){
ui->checkStaking->setText("Staking Disabled while Syncing");
}else if (WalletModel::Locked == eStatus) {
ui->checkStaking->setText("Unlock wallet for Staking");
}else if (this->walletModel->isStakingEnabled()) {
if (fStakingActive) {
ui->checkStaking->setText("Staking Enabled");
}else{

interfaces::Wallet& wallet = walletModel->wallet();
interfaces::WalletBalances balances = wallet.getBalances();
int64_t zerocoin_balance = balances.zerocoin_balance;

if (0.0 < zerocoin_balance) {
ui->checkStaking->setText("Enabling...");
}else{
ui->checkStaking->setText("You need some zerocoin");
}
}
}else{
if (fStakingActive) {
ui->checkStaking->setText("Disabling...");
}else{
ui->checkStaking->setText("Staking Disabled");
}
}
}

void VeilStatusBar::onCheckStakingClicked(bool res) {
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET))
return;
Expand All @@ -77,16 +125,19 @@ void VeilStatusBar::onCheckStakingClicked(bool res) {
openToastDialog(dialogMsg, mainWindow);
fBlockNextStakeCheckSignal = true;
ui->checkStaking->setChecked(false);
setStakingText();
return;
}else{
this->walletModel->setStakingEnabled(true);
mainWindow->updateWalletStatus();
openToastDialog("Staking enabled", mainWindow);
setStakingText();
}
} else {
this->walletModel->setStakingEnabled(false);
mainWindow->updateWalletStatus();
openToastDialog("Staking disabled", mainWindow);
openToastDialog("Staking disabled - this may a few minutes", mainWindow);
setStakingText();
}

}
Expand Down Expand Up @@ -192,11 +243,15 @@ void VeilStatusBar::updateStakingCheckbox()

if(walletModel) {
WalletModel::EncryptionStatus lockState = walletModel->getEncryptionStatus();
bool stakingStatus = walletModel->isStakingEnabled() && lockState != WalletModel::Locked;

ui->checkStaking->setEnabled(!syncFlag);
setStakingText();

bool stakingStatus = walletModel->isStakingEnabled() && lockState != WalletModel::Locked && !syncFlag;
if (ui->checkStaking->isChecked() != stakingStatus) {
fBlockNextStakeCheckSignal = true;
ui->checkStaking->setChecked(stakingStatus);
return;
return;
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/qt/veil/veilstatusbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ private Q_SLOTS:
WalletModel *walletModel = nullptr;
ClientModel *clientModel = nullptr;
UnlockPasswordDialog *unlockPasswordDialog = nullptr;
#ifdef ENABLE_WALLET
void setStakingText();
#endif

bool preparingFlag = false;
bool syncFlag = true;
static const int64_t ACTIVE_STAKING_MAX_TIME = 70;
};

#endif // VEILSTATUSBAR_H
2 changes: 1 addition & 1 deletion src/veil/mnemonic/mnemonicwalletinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ bool MnemonicWalletInit::Open() const
return false;
}

if (gArgs.GetBoolArg("-exchangesandservicesmode", false))
if (gArgs.GetBoolArg("-exchangesandservicesmode", false) || !gArgs.GetBoolArg("-staking",true))
pwallet->SetStakingEnabled(false);

AddWallet(pwallet);
Expand Down
3 changes: 3 additions & 0 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3389,6 +3389,7 @@ static UniValue getwalletinfo(const JSONRPCRequest& request)
" \"hdseedid\": \"<hash160>\" (string, optional) the Hash160 of the HD seed (only present when HD is enabled)\n"
" \"hdmasterkeyid\": \"<hash160>\" (string, optional) alias for hdseedid retained for backwards-compatibility. Will be removed in V0.18.\n"
" \"private_keys_enabled\": true|false (boolean) false if privatekeys are disabled for this wallet (enforced watch-only wallet)\n"
" \"staking_enabled\" : true|false (boolean) true if staking is enabled\n"
" \"staking_active\": true|false (boolean) true if wallet is actively trying to create new blocks using proof of stake\n"
"}\n"
"\nExamples:\n"
Expand Down Expand Up @@ -3427,6 +3428,8 @@ static UniValue getwalletinfo(const JSONRPCRequest& request)
}
obj.pushKV("private_keys_enabled", !pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS));

obj.pushKV("staking_enabled", pwallet->IsStakingEnabled());

// Determine if staking is recently active. Note that this is not immediate effect. Staking could be disabled and it could take up to 70 seconds to update state.
int64_t nTimeLastHashing = 0;
if (!mapHashedBlocks.empty()) {
Expand Down

0 comments on commit 83bd2bf

Please sign in to comment.