From c25fa7bdb560aa82a3a5bbbdf098d69e3e96c21c Mon Sep 17 00:00:00 2001 From: lateminer <9951982+lateminer@users.noreply.github.com> Date: Wed, 20 Sep 2023 22:19:58 +0200 Subject: [PATCH] refactor, pos: Use pwallet->m_last_coin_stake_search_interval instead of nLastCoinStakeSearchInterval --- src/interfaces/wallet.h | 3 +++ src/node/miner.cpp | 3 +-- src/node/miner.h | 2 -- src/qt/bitcoingui.cpp | 2 +- src/qt/walletmodel.cpp | 6 ------ src/qt/walletmodel.h | 1 - src/rpc/mining.cpp | 2 +- src/wallet/interfaces.cpp | 1 + src/wallet/rpc/staking.cpp | 6 ++++-- src/wallet/wallet.h | 1 + 10 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h index 54fd577457..c28502a316 100644 --- a/src/interfaces/wallet.h +++ b/src/interfaces/wallet.h @@ -254,6 +254,9 @@ class Wallet //! Get donation percentage virtual unsigned int getDonationPercentage() = 0; + //! Get last coin stake search interval + virtual int64_t getLastCoinStakeSearchInterval() = 0; + //! Get wallet unlock for staking only virtual bool getWalletUnlockStakingOnly() = 0; diff --git a/src/node/miner.cpp b/src/node/miner.cpp index 3fc76d201d..9a68f2b33b 100644 --- a/src/node/miner.cpp +++ b/src/node/miner.cpp @@ -48,7 +48,6 @@ using wallet::COutput; using wallet::CCoinControl; using wallet::ReserveDestination; -int64_t nLastCoinStakeSearchInterval = 0; std::thread m_minter_thread; namespace node { @@ -245,7 +244,7 @@ std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& sc *pfPoSCancel = false; } } - nLastCoinStakeSearchInterval = nSearchTime - nLastCoinStakeSearchTime; + pwallet->m_last_coin_stake_search_interval = nSearchTime - nLastCoinStakeSearchTime; nLastCoinStakeSearchTime = nSearchTime; } if (*pfPoSCancel) diff --git a/src/node/miner.h b/src/node/miner.h index e2e910e1cb..987460c32f 100644 --- a/src/node/miner.h +++ b/src/node/miner.h @@ -28,8 +28,6 @@ class CBlockIndex; class CChainParams; class CScript; -extern int64_t nLastCoinStakeSearchInterval; - namespace Consensus { struct Params; }; namespace node { diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 7f256baba2..5d8c4559d2 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -1531,7 +1531,7 @@ void BitcoinGUI::updateStakingIcon() WalletModel * const walletModel = walletView->getWalletModel(); uint64_t nWeight = walletModel->getStakeWeight(); - if (walletModel->getLastCoinStakeSearchInterval() && nWeight) + if (walletModel->wallet().getLastCoinStakeSearchInterval() && nWeight) { uint64_t nNetworkWeight = 1.1429 * walletModel->node().getPoSKernelPS(); const Consensus::Params& consensusParams = Params().GetConsensus(); diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 7eb5385562..2872a08c6e 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -22,7 +22,6 @@ #include #include #include -#include // nLastCoinStakeSearchInterval #include #include // for GetBoolArg #include @@ -616,11 +615,6 @@ uint64_t WalletModel::getStakeWeight() return nWeight; } -uint64_t WalletModel::getLastCoinStakeSearchInterval() -{ - return nLastCoinStakeSearchInterval; -} - bool WalletModel::getWalletUnlockStakingOnly() { return m_wallet->getWalletUnlockStakingOnly(); diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 2939ceed15..986fc7c353 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -154,7 +154,6 @@ class WalletModel : public QObject bool isMultiwallet() const; uint64_t getStakeWeight(); - uint64_t getLastCoinStakeSearchInterval(); void refresh(bool pk_hash_only = false); diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index e065ddfc33..186f02965c 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -1096,7 +1096,7 @@ static RPCHelpMan staking() if (!fGenerate) { node::InterruptStaking(); node::StopStaking(); - nLastCoinStakeSearchInterval = 0; + pwallet->m_last_coin_stake_search_interval = 0; } } } diff --git a/src/wallet/interfaces.cpp b/src/wallet/interfaces.cpp index 82a9f75361..0ee005fabc 100644 --- a/src/wallet/interfaces.cpp +++ b/src/wallet/interfaces.cpp @@ -485,6 +485,7 @@ class WalletImpl : public Wallet RemoveWallet(m_context, m_wallet, /*load_on_start=*/false); } unsigned int getDonationPercentage() override { return m_wallet->m_donation_percentage; } + int64_t getLastCoinStakeSearchInterval() override { return m_wallet->m_last_coin_stake_search_interval; } bool getWalletUnlockStakingOnly() override { return m_wallet->m_wallet_unlock_staking_only; } void setWalletUnlockStakingOnly(bool unlock) override { m_wallet->m_wallet_unlock_staking_only = unlock; } bool tryGetStakeWeight(uint64_t& nWeight) override diff --git a/src/wallet/rpc/staking.cpp b/src/wallet/rpc/staking.cpp index bb2405e120..fb79648bad 100644 --- a/src/wallet/rpc/staking.cpp +++ b/src/wallet/rpc/staking.cpp @@ -48,11 +48,13 @@ static RPCHelpMan getstakinginfo() if (!pwallet) return NullUniValue; uint64_t nWeight = 0; + uint64_t lastCoinStakeSearchInterval = 0; if (pwallet) { LOCK(pwallet->cs_wallet); nWeight = pwallet->GetStakeWeight(); + lastCoinStakeSearchInterval = pwallet->m_last_coin_stake_search_interval; } const CTxMemPool& mempool = pwallet->chain().mempool(); @@ -63,7 +65,7 @@ static RPCHelpMan getstakinginfo() UniValue obj(UniValue::VOBJ); uint64_t nNetworkWeight = 1.1429 * GetPoSKernelPS(chainman); - bool staking = nLastCoinStakeSearchInterval && nWeight; + bool staking = lastCoinStakeSearchInterval && nWeight; const Consensus::Params& consensusParams = Params().GetConsensus(); int64_t nTargetSpacing = consensusParams.nTargetSpacing; @@ -79,7 +81,7 @@ static RPCHelpMan getstakinginfo() obj.pushKV("difficulty", GetDifficulty(GetLastBlockIndex(chainman.m_best_header, true))); - obj.pushKV("search-interval", (uint64_t)nLastCoinStakeSearchInterval); + obj.pushKV("search-interval", (int)lastCoinStakeSearchInterval); obj.pushKV("weight", (uint64_t)nWeight); obj.pushKV("netstakeweight", (uint64_t)nNetworkWeight); obj.pushKV("expectedtime", nExpectedTime); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 6ae2760d46..14b1e6c7d6 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -666,6 +666,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati // serves to disable the trivial sendmoney when OS account compromised // provides no real security std::atomic m_wallet_unlock_staking_only{false}; + int64_t m_last_coin_stake_search_interval{0}; CAmount m_reserve_balance{DEFAULT_RESERVE_BALANCE}; unsigned int m_donation_percentage{DEFAULT_DONATION_PERCENTAGE};