blockchain: Fix bogus error message.

In the presence of overflow, the actual output sum is still not
negative and should not be reported as so.
This commit is contained in:
Josh Rickmar 2015-11-06 17:16:07 -05:00
parent 756f58b581
commit 23bcb367b2

View file

@ -240,13 +240,14 @@ func CheckTransactionSanity(tx *btcutil.Tx) error {
return ruleError(ErrBadTxOutValue, str) return ruleError(ErrBadTxOutValue, str)
} }
// TODO(davec): No need to check < 0 here as satoshi is // Two's complement int64 overflow guarantees that any overflow
// guaranteed to be positive per the above check. Also need // is detected and reported. This is impossible for Bitcoin, but
// to add overflow checks. // perhaps possible if an alt increases the total money supply.
totalSatoshi += satoshi totalSatoshi += satoshi
if totalSatoshi < 0 { if totalSatoshi < 0 {
str := fmt.Sprintf("total value of all transaction "+ str := fmt.Sprintf("total value of all transaction "+
"outputs has negative value of %v", totalSatoshi) "outputs exceeds max allowed value of %v",
btcutil.MaxSatoshi)
return ruleError(ErrBadTxOutValue, str) return ruleError(ErrBadTxOutValue, str)
} }
if totalSatoshi > btcutil.MaxSatoshi { if totalSatoshi > btcutil.MaxSatoshi {