Skip to content

Commit

Permalink
Merge branch 'staking-toggle-button'
Browse files Browse the repository at this point in the history
  • Loading branch information
barrystyle committed Jan 9, 2020
2 parents 8b3a172 + 95e8757 commit ee83a11
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ bool CheckProofOfStake(const CBlock &block, uint256& hashProofOfStake, CBlockInd
// Kernel (input 0) must match the stake hash target per coin age (nBits)
const CTxIn& txin = tx->vin[0];

// Transaction index is required to get to block header
if (!fTxIndex)
return error("CheckProofOfStake() : transaction index not available");

// Get transaction index for the previous transaction
CDiskTxPos postx;
if (!pblocktree->ReadTxIndex(txin.prevout.hash, postx))
Expand Down
27 changes: 22 additions & 5 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "consensus/merkle.h"
#include "consensus/validation.h"
#include "hash.h"
#include "init.h"
#include "validation.h"
#include "net.h"
#include "policy/policy.h"
Expand Down Expand Up @@ -576,7 +577,8 @@ void static BitcoinMiner(const CChainParams& chainparams, CConnman& connman, CWa
std::shared_ptr<CReserveScript> coinbaseScript;
pwallet->GetScriptForMining(coinbaseScript);

while (true) {
while (IsStakingEnabled())
{
try {

MilliSleep(1000);
Expand Down Expand Up @@ -735,18 +737,33 @@ void GenerateBitcoins(bool fGenerate,
minerThreads->create_thread(boost::bind(&BitcoinMiner, boost::cref(chainparams), boost::ref(connman), pwalletMain, false));
}

void ThreadStakeMinter(const CChainParams &chainparams, CConnman &connman)
void RunStakeMinter(const CChainParams &chainparams, CConnman &connman)
{
boost::this_thread::interruption_point();
LogPrintf("ThreadStakeMinter started\n");
try {
BitcoinMiner(chainparams, connman, pwalletMain, true);
boost::this_thread::interruption_point();
} catch (std::exception& e) {
}
catch (std::exception& e) {
LogPrintf("ThreadStakeMinter() exception %s\n", e.what());
} catch (...) {
}
catch (...) {
LogPrintf("ThreadStakeMinter() error \n");
}
LogPrintf("ThreadStakeMinter exiting,\n");
}

void ThreadStakeMinter(const CChainParams &chainparams, CConnman &connman)
{
while (true)
{
bool fStaking = IsStakingEnabled();

if (fStaking)
RunStakeMinter(chainparams, connman);

if (ShutdownRequested()) break;

sleep(1.5);
}
}
5 changes: 4 additions & 1 deletion src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "platformstyle.h"
#include "rpcconsole.h"
#include "utilitydialog.h"
#include "validation.h"

#ifdef ENABLE_WALLET
#include "privatesend-client.h"
Expand Down Expand Up @@ -137,6 +138,8 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *

GUIUtil::restoreWindowGeometry("nWindow", QSize(850, 550), this);

this->setFixedSize(QSize(1090,650));

QString windowTitle = tr(PACKAGE_NAME) + " - ";
#ifdef ENABLE_WALLET
enableWallet = WalletModel::isWalletEnabled();
Expand Down Expand Up @@ -1365,7 +1368,7 @@ void BitcoinGUI::setHDStatus(int hdEnabled)

void BitcoinGUI::setStakingStatus()
{
if (nLastCoinStakeSearchInterval) {
if (nLastCoinStakeSearchInterval && IsStakingEnabled()) {
labelStakingIcon->show();
labelStakingIcon->setPixmap(QIcon(QString(":/icons/staking_active")).pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
labelStakingIcon->setToolTip(tr("Staking is active\n"));
Expand Down
64 changes: 56 additions & 8 deletions src/qt/forms/overviewpage.ui
Original file line number Diff line number Diff line change
Expand Up @@ -730,21 +730,69 @@
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<widget class="QFrame" name="frame_3">
<property name="minimumSize">
<size>
<width>20</width>
<height>40</height>
<width>0</width>
<height>60</height>
</size>
</property>
</spacer>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>319</x>
<y>30</y>
<width>141</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Staking Disabled</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>318</x>
<y>10</y>
<width>141</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Toggle Staking</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</widget>
</item>
</layout>
</item>
Expand Down
17 changes: 17 additions & 0 deletions src/qt/overviewpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "transactiontablemodel.h"
#include "utilitydialog.h"
#include "walletmodel.h"
#include "validation.h"

#include "instantx.h"
#include "masternode-sync.h"
Expand Down Expand Up @@ -158,6 +159,9 @@ OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent)
// start with displaying the "out of sync" warnings
showOutOfSyncWarning(true);

// Hook the staking button to an event
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(stakingButtonPressed()));

// that's it for litemode
if(fLiteMode) return;

Expand Down Expand Up @@ -672,3 +676,16 @@ void OverviewPage::DisablePrivateSendCompletely() {
}
privateSendClient.fEnablePrivateSend = false;
}

void OverviewPage::stakingButtonPressed()
{
bool fStakingStatus = !IsStakingEnabled();
SetStakingEnabled(fStakingStatus);
LogPrintf("%s - event (fStakingStatus: %d)\n", __func__, fStakingStatus);

if (fStakingStatus) {
ui->pushButton->setText(tr("Staking Enabled"));
} else {
ui->pushButton->setText(tr("Staking Disabled"));
}
}
1 change: 1 addition & 0 deletions src/qt/overviewpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public Q_SLOTS:
void privateSendStatus();
void setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance, const CAmount& anonymizedBalance,
const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance);
void stakingButtonPressed();

Q_SIGNALS:
void transactionClicked(const QModelIndex &index);
Expand Down
6 changes: 5 additions & 1 deletion src/txdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,11 @@ bool CBlockTreeDB::HasTxIndex(const uint256& txid) {
}

bool CBlockTreeDB::ReadTxIndex(const uint256 &txid, CDiskTxPos &pos) {
return Read(std::make_pair(DB_TXINDEX, txid), pos);
bool fResult = Read(std::make_pair(DB_TXINDEX, txid), pos);
if (!fResult) {
LogPrintf("Couldn't retrieve %s\n", txid.ToString().c_str());
}
return fResult;
}

bool CBlockTreeDB::WriteTxIndex(const std::vector<std::pair<uint256, CDiskTxPos> >&vect) {
Expand Down
13 changes: 13 additions & 0 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ CWaitableCriticalSection csBestBlock;
CConditionVariable cvBlockChange;
int nScriptCheckThreads = 0;
std::atomic_bool fImporting(false);
bool fGlobalStakingToggle = false;
bool fReindex = false;
bool fTxIndex = true;
bool fAddressIndex = false;
Expand Down Expand Up @@ -4865,6 +4866,18 @@ bool FullDIP0003Mode() {
return (chainActive.Height() >= Params().GetConsensus().DIP0003EnforcementHeight);
}

//! Set whether staking is currently enabled
void SetStakingEnabled(bool fStaking)
{
fGlobalStakingToggle = fStaking;
}

//! Return if staking is enabled
bool IsStakingEnabled()
{
return fGlobalStakingToggle;
}

class CMainCleanup
{
public:
Expand Down
5 changes: 5 additions & 0 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ extern int64_t nMaxTipAge;
extern CFeeRate minRelayTxFee;
extern bool fLargeWorkForkFound;
extern bool fLargeWorkInvalidChainFound;
extern bool fGlobalStakingToggle;

extern std::map<uint256, int64_t> mapRejectedBlocks;

Expand Down Expand Up @@ -613,4 +614,8 @@ CFeeRate CurrentRelayFee();
//! Returns confirmations required to spend coinbase
int ConfirmationsPerNetwork();

//! Functions controlling the Staking toggle
void SetStakingEnabled(bool fStaking);
bool IsStakingEnabled();

#endif // BITCOIN_VALIDATION_H

0 comments on commit ee83a11

Please sign in to comment.