Skip to content

Commit b4a8f9b

Browse files
presstabFuzzbawls
authored andcommitted
zpivTracker better check for orphans. Also no redundant adding wtx's.
1 parent d8dac2e commit b4a8f9b

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/zpivtracker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ std::list<CMintMeta> CzPIVTracker::ListMints(bool fUnusedOnly, bool fMatureOnly,
377377

378378
if (fMatureOnly || fUpdateStatus) {
379379
//if there is not a record of the block height, then look it up and assign it
380-
if (!mint.nHeight) {
380+
if (!mint.nHeight || !mapBlockIndex.count(mint.hashSerial) || !chainActive.Contains(mapBlockIndex.at(mint.hashSerial))) {
381381
CTransaction tx;
382382
uint256 hashBlock;
383383

src/zpivwallet.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ void CzPIVWallet::SyncWithChain(bool fGenerateMintPool)
119119
CWalletDB walletdb(strWalletFile);
120120
CzPIVTracker* zpivTracker = pwalletMain->zpivTracker;
121121
std::set<uint256> setChecked;
122+
set<uint256> setAddedTx;
122123
while (found) {
123124
found = false;
124125
if (fGenerateMintPool)
@@ -190,24 +191,23 @@ void CzPIVWallet::SyncWithChain(bool fGenerateMintPool)
190191
break;
191192
}
192193

193-
CBlock block;
194-
CWalletTx wtx(pwalletMain, tx);
195-
if (mapBlockIndex.count(hashBlock) && ReadBlockFromDisk(block, mapBlockIndex.at(hashBlock)))
196-
wtx.SetMerkleBranch(block);
197-
198-
//The mint was found in the chain, so recalculate the randomness and serial and DB it
199-
int nHeight = 0;
200-
int nTimeReceived = 0;
201-
if (mapBlockIndex.count(hashBlock)) {
202-
nHeight = mapBlockIndex.at(hashBlock)->nHeight;
203-
nTimeReceived = mapBlockIndex.at(hashBlock)->nTime;
204-
}
194+
CBlockIndex* pindex;
195+
if (mapBlockIndex.count(hashBlock))
196+
pindex = mapBlockIndex.at(hashBlock);
197+
198+
if (!setAddedTx.count(txHash)) {
199+
CBlock block;
200+
CWalletTx wtx(pwalletMain, tx);
201+
if (pindex && ReadBlockFromDisk(block, pindex))
202+
wtx.SetMerkleBranch(block);
205203

206-
//Fill out wtx so that a transaction record can be created
207-
wtx.nTimeReceived = nTimeReceived;
208-
pwalletMain->AddToWallet(wtx);
204+
//Fill out wtx so that a transaction record can be created
205+
wtx.nTimeReceived = pindex->GetBlockTime();
206+
pwalletMain->AddToWallet(wtx);
207+
setAddedTx.insert(txHash);
208+
}
209209

210-
SetMintSeen(bnValue, nHeight, txHash, denomination);
210+
SetMintSeen(bnValue, pindex->nHeight, txHash, denomination);
211211
nLastCountUsed = std::max(pMint.second, nLastCountUsed);
212212
nCountLastUsed = std::max(nLastCountUsed, nCountLastUsed);
213213
LogPrint("zero", "%s: updated count to %d\n", __func__, nCountLastUsed);

0 commit comments

Comments
 (0)