lnwallet: add concrete type for coin selection fail during funding workflow

This commit is contained in:
Olaoluwa Osuntokun 2016-09-26 12:16:12 -07:00
parent 6c51bc7cee
commit 85b2b52a5f
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
2 changed files with 17 additions and 9 deletions

@ -523,7 +523,7 @@ func testFundingTransactionLockedOutputs(miner *rpctest.Harness,
if err == nil {
t.Fatalf("not error returned, should fail on coin selection")
}
if err != lnwallet.ErrInsufficientFunds {
if _, ok := err.(*lnwallet.ErrInsufficientFunds); !ok {
t.Fatalf("error not coinselect error: %v", err)
}
if failedReservation != nil {
@ -545,7 +545,7 @@ func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness,
// Attempt to create another channel with 44 BTC, this should fail.
_, err = wallet.InitChannelReservation(fundingAmount,
fundingAmount, testHdSeed, numReqConfs, 4)
if err != lnwallet.ErrInsufficientFunds {
if _, ok := err.(*lnwallet.ErrInsufficientFunds); !ok {
t.Fatalf("coin selection succeded should have insufficient funds: %v",
err)
}

@ -1,7 +1,6 @@
package lnwallet
import (
"errors"
"fmt"
"sync"
"sync/atomic"
@ -40,9 +39,6 @@ const (
)
var (
// Error types
ErrInsufficientFunds = errors.New("not enough available outputs to " +
"create funding transaction")
// Namespace bucket keys.
lightningNamespaceKey = []byte("ln-wallet")
@ -50,6 +46,20 @@ var (
wtxmgrNamespaceKey = []byte("wtxmgr")
)
// ErrInsufficientFunds is a type matching the error interface which is
// returned when coin selection for a new funding transaction fails to due
// having an insufficient amount of confirmed funds.
type ErrInsufficientFunds struct {
amountAvailable btcutil.Amount
amountSelected btcutil.Amount
}
func (e *ErrInsufficientFunds) Error() string {
return fmt.Sprintf("not enough outputs to create funding transaction,"+
" need %v only have %v available", e.amountAvailable,
e.amountSelected)
}
// initFundingReserveReq is the first message sent to initiate the workflow
// required to open a payment channel with a remote peer. The initial required
// paramters are configurable accross channels. These paramters are to be chosen
@ -1283,9 +1293,7 @@ func selectInputs(amt btcutil.Amount, coins []*Utxo) (btcutil.Amount, []*wire.Ou
// If we're about to go past the number of available coins,
// then exit with an error.
if i > len(coins)-1 {
return 0, nil, fmt.Errorf("not enough outputs to create "+
"funding transaction, need %v only have %v "+
"available", amt, satSelected)
return 0, nil, &ErrInsufficientFunds{amt, satSelected}
}
// Otherwise, collect this new coin as it may be used for final