Skip to content

Commit bea9c16

Browse files
APosselliFuzzbawls
authored andcommitted
Make zPiv wallet consistently use nCount as the last count used and remove comparison against nCountLastGenerated that resulted in adding to the mintpool every time the wallet got opened.
1 parent 85e8a14 commit bea9c16

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/zpivwallet.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ CzPIVWallet::CzPIVWallet(std::string strWalletFile, bool fFirstRun)
2626
seed = CBigNum::randBignum(CBigNum(~uint256(0))).getuint256();
2727

2828
SetMasterSeed(seed);
29-
this->mintPool = CMintPool(nCount);
29+
this->mintPool = CMintPool(nCountLastUsed);
3030
}
3131

3232
bool CzPIVWallet::SetMasterSeed(const uint256& seedMaster, bool fResetCount)
@@ -37,11 +37,11 @@ bool CzPIVWallet::SetMasterSeed(const uint256& seedMaster, bool fResetCount)
3737
if (!walletdb.WriteZPIVSeed(seedMaster))
3838
return false;
3939

40-
nCount = 0;
40+
nCountLastUsed = 0;
4141
if (fResetCount)
42-
walletdb.WriteZPIVCount(nCount);
43-
else if (!walletdb.ReadZPIVCount(nCount))
44-
nCount = 0;
42+
walletdb.WriteZPIVCount(nCountLastUsed);
43+
else if (!walletdb.ReadZPIVCount(nCountLastUsed))
44+
nCountLastUsed = 0;
4545

4646
//todo fix to sync with count above
4747
mintPool.Reset();
@@ -52,7 +52,7 @@ bool CzPIVWallet::SetMasterSeed(const uint256& seedMaster, bool fResetCount)
5252
//Add the next 10 mints to the mint pool
5353
void CzPIVWallet::GenerateMintPool(int nCountStart, int nCountEnd)
5454
{
55-
int n = std::max(mintPool.CountOfLastGenerated() + 1, nCount);
55+
int n = nCountLastUsed + 1;
5656
if (nCountStart > 0)
5757
n = nCountStart;
5858

@@ -199,8 +199,8 @@ void CzPIVWallet::SyncWithChain(bool fGenerateMintPool)
199199

200200
SetMintSeen(bnValue, nHeight, txHash, denomination);
201201
nLastCountUsed = std::max(pMint.second, nLastCountUsed);
202-
nCount = std::max(nLastCountUsed + 1, nCount);
203-
LogPrint("zero", "%s: updated count to %d\n", __func__, nCount);
202+
nCountLastUsed = std::max(nLastCountUsed, nCountLastUsed);
203+
LogPrint("zero", "%s: updated count to %d\n", __func__, nCountLastUsed);
204204
}
205205
}
206206
}
@@ -272,10 +272,10 @@ bool CzPIVWallet::SetMintSeen(const CBigNum& bnValue, const int& nHeight, const
272272
pwalletMain->zpivTracker->Add(dMint, true);
273273

274274
//Update the count if it is less than the mint's count
275-
if (nCount <= pMint.second) {
275+
if (nCountLastUsed < pMint.second) {
276276
CWalletDB walletdb(strWalletFile);
277-
nCount = pMint.second + 1;
278-
walletdb.WriteZPIVCount(nCount);
277+
nCountLastUsed = pMint.second;
278+
walletdb.WriteZPIVCount(nCountLastUsed);
279279
}
280280

281281
//remove from the pool
@@ -341,7 +341,7 @@ void CzPIVWallet::SeedToZPIV(const uint512& seedZerocoin, CBigNum& bnSerial, CBi
341341

342342
uint512 CzPIVWallet::GetNextZerocoinSeed()
343343
{
344-
return GetZerocoinSeed(nCount);
344+
return GetZerocoinSeed(nCountLastUsed + 1);
345345
}
346346

347347
uint512 CzPIVWallet::GetZerocoinSeed(uint32_t n)
@@ -354,14 +354,14 @@ uint512 CzPIVWallet::GetZerocoinSeed(uint32_t n)
354354

355355
void CzPIVWallet::UpdateCount()
356356
{
357-
nCount++;
357+
nCountLastUsed++;
358358
CWalletDB walletdb(strWalletFile);
359-
walletdb.WriteZPIVCount(nCount);
359+
walletdb.WriteZPIVCount(nCountLastUsed);
360360
}
361361

362362
void CzPIVWallet::GenerateDeterministicZPIV(CoinDenomination denom, PrivateCoin& coin, CDeterministicMint& dMint, bool fGenerateOnly)
363363
{
364-
GenerateMint(nCount, denom, coin, dMint);
364+
GenerateMint(nCountLastUsed + 1, denom, coin, dMint);
365365
if (fGenerateOnly)
366366
return;
367367

src/zpivwallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class CzPIVWallet
1717
{
1818
private:
1919
uint256 seedMaster;
20-
uint32_t nCount;
20+
uint32_t nCountLastUsed;
2121
std::string strWalletFile;
2222
CMintPool mintPool;
2323

0 commit comments

Comments
 (0)