From ec84e81e8383b3b1e1ef4a6dbcb088193d8de5d7 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Mon, 24 Jun 2013 20:51:08 +0200 Subject: Prune provably-unspendable outputs --- src/core.h | 8 +++++++- src/script.h | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/core.h b/src/core.h index 1b9d4dd765..a8828324fa 100644 --- a/src/core.h +++ b/src/core.h @@ -389,7 +389,13 @@ public: int nVersion; // construct a CCoins from a CTransaction, at a given height - CCoins(const CTransaction &tx, int nHeightIn) : fCoinBase(tx.IsCoinBase()), vout(tx.vout), nHeight(nHeightIn), nVersion(tx.nVersion) { } + CCoins(const CTransaction &tx, int nHeightIn) : fCoinBase(tx.IsCoinBase()), vout(tx.vout), nHeight(nHeightIn), nVersion(tx.nVersion) { + BOOST_FOREACH(CTxOut &txout, vout) { + if (txout.scriptPubKey.IsUnspendable()) + txout.SetNull(); + } + Cleanup(); + } // empty constructor CCoins() : fCoinBase(false), vout(0), nHeight(0), nVersion(0) { } diff --git a/src/script.h b/src/script.h index 03afe8b652..2dc0697ade 100644 --- a/src/script.h +++ b/src/script.h @@ -548,6 +548,13 @@ public: return true; } + // Returns whether the script is guaranteed to fail at execution, + // regardless of the initial stack. This allows outputs to be pruned + // instantly when entering the UTXO set. + bool IsUnspendable() const + { + return (size() > 0 && *begin() == OP_RETURN); + } void SetDestination(const CTxDestination& address); void SetMultisig(int nRequired, const std::vector& keys); -- cgit v1.2.3