Search unconfirmed txs when finding prev credits.

If a transaction is added that debits from previous transaction
outputs, and those outputs are still unconfirmed, it is possible that
if the credits were not already known (as is the case with
transactions notified after a sendrawtransaction), only mined unspent
transaction outputs would be searched and the unconfirmed unspent
credits would be missed.  This results in spent outputs still being
marked unspent.

This change fixes the above by also searching through unconfirmed
transactions when the previous credits must be lookup up, rather than
being pass from an AddDebits call.

Fixes issue #91.
This commit is contained in:
Josh Rickmar 2014-06-19 11:39:43 -05:00
parent 632148ed55
commit 3b436402e0

View file

@ -639,7 +639,26 @@ func (s *Store) findPreviousCredits(tx *btcutil.Tx) ([]Credit, error) {
go func(i int, op btcwire.OutPoint) {
key, ok := s.unspent[op]
if !ok {
close(creditChans[i])
// Does this input spend an unconfirmed output?
r, ok := s.unconfirmed.txs[op.Hash]
switch {
// Not an unconfirmed tx.
case !ok:
fallthrough
// Output isn't a credit.
case len(r.credits) <= int(op.Index):
fallthrough
// Output isn't a credit.
case r.credits[op.Index] == nil:
fallthrough
// Credit already spent.
case s.unconfirmed.spentUnconfirmed[op] != nil:
close(creditChans[i])
return
}
t := &TxRecord{BlockTxKey{BlockHeight: -1}, r, s}
c := Credit{t, op.Index}
creditChans[i] <- createdCredit{credit: c}
return
}
r, err := s.lookupBlockTx(key)