From 473f29852477979adbb2a3d59a2146d3d484084c Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 26 Dec 2016 23:30:24 -0600 Subject: [PATCH] lnwallet/btcwallet: fix bug in GetUtxo for BlockChainIO implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes an unnoticed bug within btcwallet’s implementation of the BlockChainIO interface, specifically the GetUtxo method. In order to maintain compatibility with Bitcoin Core’s gettxout method, btcd doesn’t return an error if the targeted output is actually spent. We weren’t properly detecting this, but we do now by creating a new error which is returned in the case of a nil error but a nil return value. --- lnwallet/btcwallet/blockchain.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lnwallet/btcwallet/blockchain.go b/lnwallet/btcwallet/blockchain.go index 93411786..27b64e83 100644 --- a/lnwallet/btcwallet/blockchain.go +++ b/lnwallet/btcwallet/blockchain.go @@ -2,11 +2,18 @@ package btcwallet import ( "encoding/hex" + "errors" "github.com/lightningnetwork/lnd/lnwallet" "github.com/roasbeef/btcd/wire" ) +var ( + // ErrOutputSpent is returned by the GetUtxo method if the target output + // for lookup has already been spent. + ErrOutputSpent = errors.New("target output has been spent") +) + // GetBestBlock returns the current height and hash of the best known block // within the main chain. // @@ -22,6 +29,8 @@ func (b *BtcWallet) GetUtxo(txid *wire.ShaHash, index uint32) (*wire.TxOut, erro txout, err := b.rpc.GetTxOut(txid, index, false) if err != nil { return nil, err + } else if txout == nil { + return nil, ErrOutputSpent } pkScript, err := hex.DecodeString(txout.ScriptPubKey.Hex)