Skip to content

Commit 0e7921e

Browse files
committed
[DB] Also prune invalid/fraudulent/frozen outputs from the coins view
1 parent b8647bd commit 0e7921e

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/coins.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "coins.h"
77

88
#include "consensus/consensus.h"
9+
#include "invalid.h"
910
#include "memusage.h"
1011
#include "random.h"
1112

@@ -293,14 +294,16 @@ CAmount CCoinsViewCache::GetTotalAmount() const
293294
return nTotal;
294295
}
295296

296-
void CCoinsViewCache::PruneZerocoinMints()
297+
void CCoinsViewCache::PruneInvalidEntries()
297298
{
299+
// Prune zerocoin Mints and fraudulent/frozen outputs
298300
std::unique_ptr<CCoinsViewCursor> pcursor(Cursor());
299301
while (pcursor->Valid()) {
300302
COutPoint key;
301303
Coin coin;
302-
if (pcursor->GetKey(key) && pcursor->GetValue(coin) && coin.out.IsZerocoinMint()) {
303-
SpendCoin(key);
304+
if (pcursor->GetKey(key) && pcursor->GetValue(coin)) {
305+
if (coin.out.IsZerocoinMint() || invalid_out::ContainsOutPoint(key))
306+
SpendCoin(key);
304307
}
305308
pcursor->Next();
306309
}

src/coins.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ class CCoinsViewCache : public CCoinsViewBacked
296296
CAmount GetTotalAmount() const;
297297

298298
/*
299-
* Prune zerocoin mints - do it once, after initialization
299+
* Prune zerocoin mints and frozen outputs - do it once, after initialization
300300
*/
301-
void PruneZerocoinMints();
301+
void PruneInvalidEntries();
302302

303303

304304
private:

src/init.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,8 +1565,8 @@ bool AppInit2()
15651565
// Do it only once, when removing money supply (key 'M') from the DB. Can be skipped in future versions.
15661566
int64_t nDummySupply;
15671567
if (fZerocoinActive && pblocktree->Read('M', nDummySupply)) {
1568-
LogPrintf("Pruning zerocoin mints at height %d\n", chainHeight);
1569-
pcoinsTip->PruneZerocoinMints();
1568+
LogPrintf("Pruning zerocoin mints / invalid outs, at height %d\n", chainHeight);
1569+
pcoinsTip->PruneInvalidEntries();
15701570
pblocktree->Erase('M');
15711571
}
15721572

0 commit comments

Comments
 (0)