Skip to content

Commit

Permalink
Update zPIV stake set more frequently.
Browse files Browse the repository at this point in the history
  • Loading branch information
presstab committed May 15, 2018
1 parent 6c3bc8c commit 355e2d3
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2114,9 +2114,15 @@ bool CWallet::SelectStakeCoins(std::list<std::unique_ptr<CStakeInput> >& listInp

//zPIV
if (GetBoolArg("-zpivstake", true) && chainActive.Height() > Params().Zerocoin_Block_V2_Start() && !IsSporkActive(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) {
//Add zPIV
set<CMintMeta> 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<CMintMeta> setMints = zpivTracker->ListMints(true, true, fUpdate);
for (auto meta : setMints) {
if (meta.hashStake == 0) {
CZerocoinMint mint;
Expand Down Expand Up @@ -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<std::unique_ptr<CStakeInput> > listInputs;
if (GetTime() - nLastStakeSetUpdate > nStakeSetUpdateTime) {
listInputs.clear();
if (!SelectStakeCoins(listInputs, nBalance - nReserveBalance))
return false;

nLastStakeSetUpdate = GetTime();
}
// Get the list of stakable inputs
std::list<std::unique_ptr<CStakeInput> > listInputs;
if (!SelectStakeCoins(listInputs, nBalance - nReserveBalance))
return false;

if (listInputs.empty())
return false;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 355e2d3

Please sign in to comment.