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.
This commit is contained in:
parent
9787f46f6a
commit
b282678d9a
1 changed files with 8 additions and 5 deletions
13
validate.go
13
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
|
// checkTransactionInputs performs a series of checks on the inputs to a
|
||||||
// transaction to ensure they are valid. An example of some of the checks
|
// transaction to ensure they are valid. An example of some of the checks
|
||||||
// include verifying all inputs exist, ensuring the coinbase seasoning
|
// include verifying all inputs exist, ensuring the coinbase seasoning
|
||||||
// requirements are met, validating all values and fees are in the legal range
|
// requirements are met, detecting double spends, validating all values and fees
|
||||||
// and the total output amount doesn't exceed the input amount, and verifying
|
// are in the legal range and the total output amount doesn't exceed the input
|
||||||
// the signatures to prove the spender was the owner of the bitcoins and
|
// amount, and verifying the signatures to prove the spender was the owner of
|
||||||
// therefore allowed to spend them. As it checks the inputs, it also calculates
|
// the bitcoins and therefore allowed to spend them. As it checks the inputs,
|
||||||
// the total fees for the transaction and returns that value.
|
// 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) {
|
func checkTransactionInputs(tx *btcwire.MsgTx, txHeight int64, txStore map[btcwire.ShaHash]*txData) (int64, error) {
|
||||||
// Coinbase transactions have no inputs.
|
// Coinbase transactions have no inputs.
|
||||||
if isCoinBase(tx) {
|
if isCoinBase(tx) {
|
||||||
|
@ -693,6 +693,9 @@ func checkTransactionInputs(tx *btcwire.MsgTx, txHeight int64, txStore map[btcwi
|
||||||
maxSatoshi)
|
maxSatoshi)
|
||||||
return 0, RuleError(str)
|
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
|
// Calculate the total output amount for this transaction. It is safe
|
||||||
|
|
Loading…
Reference in a new issue