lnwallet+routing: modify BlockChainIO.GetUtxo to be light client friendly

This commit modifies the GetUtxo method of the BlockChainIO interface
to be more light client friendly by introducing a height hint which
gives light clients that don’t have UTXO set commitments a way in which
they can restrict their search space. Light clients will now be able to
have a concrete cut off point in the chain as they scan backwards for
spentness of an output.
This commit is contained in:
Olaoluwa Osuntokun 2017-05-10 16:37:14 -07:00
parent 333373f78f
commit a18d9b8449
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
3 changed files with 10 additions and 7 deletions

@ -26,8 +26,8 @@ func (b *BtcWallet) GetBestBlock() (*chainhash.Hash, int32, error) {
// GetUtxo returns the original output referenced by the passed outpoint.
//
// This method is a part of the lnwallet.BlockChainIO interface.
func (b *BtcWallet) GetUtxo(txid *chainhash.Hash, index uint32) (*wire.TxOut, error) {
txout, err := b.rpc.GetTxOut(txid, index, false)
func (b *BtcWallet) GetUtxo(op *wire.OutPoint, _ uint32) (*wire.TxOut, error) {
txout, err := b.rpc.GetTxOut(&op.Hash, op.Index, false)
if err != nil {
return nil, err
} else if txout == nil {

@ -209,9 +209,12 @@ type BlockChainIO interface {
// most-work chain the implementation is aware of.
GetBestBlock() (*chainhash.Hash, int32, error)
// GetTxOut returns the original output referenced by the passed
// outpoint.
GetUtxo(txid *chainhash.Hash, index uint32) (*wire.TxOut, error)
// GetUtxo attempts to return the passed outpoint if it's still a
// member of the utxo set. The passed height hint should be the "birth
// height" of the passed outpoint. In the case that the output is in
// the UTXO set, then the output corresponding to that output is
// returned. Otherwise, a non-nil error will be returned.
GetUtxo(op *wire.OutPoint, heightHint uint32) (*wire.TxOut, error)
// GetTransaction returns the full transaction identified by the passed
// transaction ID.

@ -978,8 +978,8 @@ func (l *LightningWallet) handleFundingCounterPartySigs(msg *addCounterPartySigs
// Fetch the alleged previous output along with the
// pkscript referenced by this input.
prevOut := txin.PreviousOutPoint
output, err := l.ChainIO.GetUtxo(&prevOut.Hash, prevOut.Index)
// TODO(roasbeef): when dual funder pass actual height-hint
output, err := l.ChainIO.GetUtxo(&txin.PreviousOutPoint, 0)
if output == nil {
msg.err <- fmt.Errorf("input to funding tx "+
"does not exist: %v", err)