diff --git a/src/wallet.cpp b/src/wallet.cpp index 1f09ea00c0274..089b2c296dfa9 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -2114,9 +2114,15 @@ bool CWallet::SelectStakeCoins(std::list >& listInp //zPIV if (GetBoolArg("-zpivstake", true) && chainActive.Height() > Params().Zerocoin_Block_V2_Start() && !IsSporkActive(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) { - //Add zPIV - set setMints = zpivTracker->ListMints(true, true, true); + //Only update zPIV set once per update interval + bool fUpdate = false; + static int64_t nTimeLastUpdate = 0; + if (GetAdjustedTime() - nTimeLastUpdate > nStakeSetUpdateTime) { + fUpdate = true; + nTimeLastUpdate = GetAdjustedTime(); + } + set setMints = zpivTracker->ListMints(true, true, fUpdate); for (auto meta : setMints) { if (meta.hashStake == 0) { CZerocoinMint mint; @@ -2943,16 +2949,10 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int if (nBalance > 0 && nBalance <= nReserveBalance) return false; - // Initialize as static and don't update the set on every run of CreateCoinStake() in order to lighten resource use - static int nLastStakeSetUpdate = 0; - static list > listInputs; - if (GetTime() - nLastStakeSetUpdate > nStakeSetUpdateTime) { - listInputs.clear(); - if (!SelectStakeCoins(listInputs, nBalance - nReserveBalance)) - return false; - - nLastStakeSetUpdate = GetTime(); - } + // Get the list of stakable inputs + std::list > listInputs; + if (!SelectStakeCoins(listInputs, nBalance - nReserveBalance)) + return false; if (listInputs.empty()) return false; @@ -3083,7 +3083,6 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int } // Successfully generated coinstake - nLastStakeSetUpdate = 0; //this will trigger stake set to repopulate next round return true; }