From b282678d9a49091b75a1c26cff7ff16703c528d2 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 26 Jul 2013 11:50:20 -0500 Subject: [PATCH] Spend outputs while checking transaction inputs. This commit modifies the double spend detection to handle double spends within the same block as well as side chains when doing the checks before reorganizing the chain. --- validate.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/validate.go b/validate.go index d5936a00..114dd19b 100644 --- a/validate.go +++ b/validate.go @@ -605,11 +605,11 @@ func (b *BlockChain) checkBIP0030(node *blockNode, block *btcutil.Block) error { // checkTransactionInputs performs a series of checks on the inputs to a // transaction to ensure they are valid. An example of some of the checks // include verifying all inputs exist, ensuring the coinbase seasoning -// requirements are met, validating all values and fees are in the legal range -// and the total output amount doesn't exceed the input amount, and verifying -// the signatures to prove the spender was the owner of the bitcoins and -// therefore allowed to spend them. As it checks the inputs, it also calculates -// the total fees for the transaction and returns that value. +// requirements are met, detecting double spends, validating all values and fees +// are in the legal range and the total output amount doesn't exceed the input +// amount, and verifying the signatures to prove the spender was the owner of +// the bitcoins and therefore allowed to spend them. As it checks the inputs, +// it also calculates the total fees for the transaction and returns that value. func checkTransactionInputs(tx *btcwire.MsgTx, txHeight int64, txStore map[btcwire.ShaHash]*txData) (int64, error) { // Coinbase transactions have no inputs. if isCoinBase(tx) { @@ -693,6 +693,9 @@ func checkTransactionInputs(tx *btcwire.MsgTx, txHeight int64, txStore map[btcwi maxSatoshi) return 0, RuleError(str) } + + // Mark the referenced output as spent. + originTx.spent[originTxIndex] = true } // Calculate the total output amount for this transaction. It is safe