Skip to content

Commit 355e2d3

Browse files
committed
Update zPIV stake set more frequently.
1 parent 6c3bc8c commit 355e2d3

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/wallet.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,9 +2114,15 @@ bool CWallet::SelectStakeCoins(std::list<std::unique_ptr<CStakeInput> >& listInp
21142114

21152115
//zPIV
21162116
if (GetBoolArg("-zpivstake", true) && chainActive.Height() > Params().Zerocoin_Block_V2_Start() && !IsSporkActive(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) {
2117-
//Add zPIV
2118-
set<CMintMeta> setMints = zpivTracker->ListMints(true, true, true);
2117+
//Only update zPIV set once per update interval
2118+
bool fUpdate = false;
2119+
static int64_t nTimeLastUpdate = 0;
2120+
if (GetAdjustedTime() - nTimeLastUpdate > nStakeSetUpdateTime) {
2121+
fUpdate = true;
2122+
nTimeLastUpdate = GetAdjustedTime();
2123+
}
21192124

2125+
set<CMintMeta> setMints = zpivTracker->ListMints(true, true, fUpdate);
21202126
for (auto meta : setMints) {
21212127
if (meta.hashStake == 0) {
21222128
CZerocoinMint mint;
@@ -2943,16 +2949,10 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
29432949
if (nBalance > 0 && nBalance <= nReserveBalance)
29442950
return false;
29452951

2946-
// Initialize as static and don't update the set on every run of CreateCoinStake() in order to lighten resource use
2947-
static int nLastStakeSetUpdate = 0;
2948-
static list<std::unique_ptr<CStakeInput> > listInputs;
2949-
if (GetTime() - nLastStakeSetUpdate > nStakeSetUpdateTime) {
2950-
listInputs.clear();
2951-
if (!SelectStakeCoins(listInputs, nBalance - nReserveBalance))
2952-
return false;
2953-
2954-
nLastStakeSetUpdate = GetTime();
2955-
}
2952+
// Get the list of stakable inputs
2953+
std::list<std::unique_ptr<CStakeInput> > listInputs;
2954+
if (!SelectStakeCoins(listInputs, nBalance - nReserveBalance))
2955+
return false;
29562956

29572957
if (listInputs.empty())
29582958
return false;
@@ -3083,7 +3083,6 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
30833083
}
30843084

30853085
// Successfully generated coinstake
3086-
nLastStakeSetUpdate = 0; //this will trigger stake set to repopulate next round
30873086
return true;
30883087
}
30893088

0 commit comments

Comments
 (0)