Skip to content

Commit 170e02d

Browse files
committed
Generalize the remove-outputs check for fully-prunable transactions.
Instead of explicitly testing for the presence of any output, and dealing with this case specially, just interpret it as an empty CCoins. The case previously caught using the HaveCoins check, is now handled by the generic outs != outsBlock test.
1 parent 7ae4540 commit 170e02d

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ class CCoins
421421

422422
// equality test
423423
friend bool operator==(const CCoins &a, const CCoins &b) {
424+
// Empty CCoins objects are always equal.
425+
if (a.IsPruned() && b.IsPruned())
426+
return true;
424427
return a.fCoinBase == b.fCoinBase &&
425428
a.nHeight == b.nHeight &&
426429
a.nVersion == b.nVersion &&

src/main.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,12 +1750,12 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
17501750
const CTransaction &tx = block.vtx[i];
17511751
uint256 hash = tx.GetHash();
17521752

1753-
// check that all outputs are available
1754-
if (!view.HaveCoins(hash)) {
1755-
fClean = fClean && error("DisconnectBlock() : outputs still spent? database corrupted");
1756-
view.SetCoins(hash, CCoins());
1757-
}
1758-
CCoins &outs = view.GetCoins(hash);
1753+
// Check that all outputs are available and match the outputs in the block itself
1754+
// exactly. Note that transactions with only provably unspendable outputs won't
1755+
// have outputs available even in the block itself, so we handle that case
1756+
// specially with outsEmpty.
1757+
CCoins outsEmpty;
1758+
CCoins &outs = view.HaveCoins(hash) ? view.GetCoins(hash) : outsEmpty;
17591759
outs.ClearUnspendable();
17601760

17611761
CCoins outsBlock = CCoins(tx, pindex->nHeight);

0 commit comments

Comments
 (0)