Skip to content

Commit cfc06ed

Browse files
committed
[Core] Don't add zerocoin mints to the coins cache
1 parent e8a782c commit cfc06ed

File tree

2 files changed

+34
-35
lines changed

2 files changed

+34
-35
lines changed

src/coins.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ bool CCoinsViewCache::GetCoin(const COutPoint& outpoint, Coin& coin) const
6565
void CCoinsViewCache::AddCoin(const COutPoint& outpoint, Coin&& coin, bool possible_overwrite) {
6666
assert(!coin.IsSpent());
6767
if (coin.out.scriptPubKey.IsUnspendable()) return;
68+
if (coin.out.IsZerocoinMint()) return;
6869
CCoinsMap::iterator it;
6970
bool inserted;
7071
std::tie(it, inserted) = cacheCoins.emplace(std::piecewise_construct, std::forward_as_tuple(outpoint), std::tuple<>());

src/miner.cpp

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -271,47 +271,45 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
271271
double dPriority = 0;
272272
CAmount nTotalIn = 0;
273273
bool fMissingInputs = false;
274-
bool hasZerocoinSpends = tx.HasZerocoinSpendInputs();
275-
if (hasZerocoinSpends)
274+
275+
if (tx.HasZerocoinSpendInputs()) {
276276
nTotalIn = tx.GetZerocoinSpent();
277+
} else {
278+
for (const CTxIn& txin : tx.vin) {
279+
// Read prev transaction
280+
if (!view.HaveCoin(txin.prevout)) {
281+
// This should never happen; all transactions in the memory
282+
// pool should connect to either transactions in the chain
283+
// or other transactions in the memory pool.
284+
if (!mempool.mapTx.count(txin.prevout.hash)) {
285+
LogPrintf("ERROR: mempool transaction missing input\n");
286+
fMissingInputs = true;
287+
if (porphan)
288+
vOrphan.pop_back();
289+
break;
290+
}
277291

278-
for (const CTxIn& txin : tx.vin) {
279-
// Read prev transaction
280-
if (!view.HaveCoin(txin.prevout)) {
281-
// This should never happen; all transactions in the memory
282-
// pool should connect to either transactions in the chain
283-
// or other transactions in the memory pool.
284-
if (!mempool.mapTx.count(txin.prevout.hash)) {
285-
LogPrintf("ERROR: mempool transaction missing input\n");
286-
fMissingInputs = true;
287-
if (porphan)
288-
vOrphan.pop_back();
289-
break;
292+
// Has to wait for dependencies
293+
if (!porphan) {
294+
// Use list for automatic deletion
295+
vOrphan.push_back(COrphan(&tx));
296+
porphan = &vOrphan.back();
297+
}
298+
mapDependers[txin.prevout.hash].push_back(porphan);
299+
porphan->setDependsOn.insert(txin.prevout.hash);
300+
nTotalIn += mempool.mapTx.find(txin.prevout.hash)->GetTx().vout[txin.prevout.n].nValue;
301+
continue;
290302
}
291303

292-
// Has to wait for dependencies
293-
if (!porphan) {
294-
// Use list for automatic deletion
295-
vOrphan.push_back(COrphan(&tx));
296-
porphan = &vOrphan.back();
297-
}
298-
mapDependers[txin.prevout.hash].push_back(porphan);
299-
porphan->setDependsOn.insert(txin.prevout.hash);
300-
nTotalIn += mempool.mapTx.find(txin.prevout.hash)->GetTx().vout[txin.prevout.n].nValue;
301-
continue;
302-
}
304+
const Coin& coin = view.AccessCoin(txin.prevout);
305+
assert(!coin.IsSpent());
303306

304-
const Coin& coin = view.AccessCoin(txin.prevout);
305-
assert(hasZerocoinSpends || !coin.IsSpent());
306-
307-
CAmount nValueIn = coin.out.nValue;
308-
nTotalIn += nValueIn;
309-
310-
int nConf = nHeight - coin.nHeight;
311-
312-
// zPIV spends can have very large priority, use non-overflowing safe functions
313-
dPriority = double_safe_addition(dPriority, ((double)nValueIn * nConf));
307+
CAmount nValueIn = coin.out.nValue;
308+
nTotalIn += nValueIn;
314309

310+
int nConf = nHeight - coin.nHeight;
311+
dPriority = double_safe_addition(dPriority, ((double)nValueIn * nConf));
312+
}
315313
}
316314
if (fMissingInputs) continue;
317315

0 commit comments

Comments
 (0)