mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-23 14:40:30 +01:00
lnwallet: add concrete type for coin selection fail during funding workflow
This commit is contained in:
parent
6c51bc7cee
commit
85b2b52a5f
2 changed files with 17 additions and 9 deletions
|
@ -523,7 +523,7 @@ func testFundingTransactionLockedOutputs(miner *rpctest.Harness,
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("not error returned, should fail on coin selection")
|
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)
|
t.Fatalf("error not coinselect error: %v", err)
|
||||||
}
|
}
|
||||||
if failedReservation != nil {
|
if failedReservation != nil {
|
||||||
|
@ -545,7 +545,7 @@ func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness,
|
||||||
// Attempt to create another channel with 44 BTC, this should fail.
|
// Attempt to create another channel with 44 BTC, this should fail.
|
||||||
_, err = wallet.InitChannelReservation(fundingAmount,
|
_, err = wallet.InitChannelReservation(fundingAmount,
|
||||||
fundingAmount, testHdSeed, numReqConfs, 4)
|
fundingAmount, testHdSeed, numReqConfs, 4)
|
||||||
if err != lnwallet.ErrInsufficientFunds {
|
if _, ok := err.(*lnwallet.ErrInsufficientFunds); !ok {
|
||||||
t.Fatalf("coin selection succeded should have insufficient funds: %v",
|
t.Fatalf("coin selection succeded should have insufficient funds: %v",
|
||||||
err)
|
err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package lnwallet
|
package lnwallet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
@ -40,9 +39,6 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// Error types
|
|
||||||
ErrInsufficientFunds = errors.New("not enough available outputs to " +
|
|
||||||
"create funding transaction")
|
|
||||||
|
|
||||||
// Namespace bucket keys.
|
// Namespace bucket keys.
|
||||||
lightningNamespaceKey = []byte("ln-wallet")
|
lightningNamespaceKey = []byte("ln-wallet")
|
||||||
|
@ -50,6 +46,20 @@ var (
|
||||||
wtxmgrNamespaceKey = []byte("wtxmgr")
|
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
|
// initFundingReserveReq is the first message sent to initiate the workflow
|
||||||
// required to open a payment channel with a remote peer. The initial required
|
// required to open a payment channel with a remote peer. The initial required
|
||||||
// paramters are configurable accross channels. These paramters are to be chosen
|
// 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,
|
// If we're about to go past the number of available coins,
|
||||||
// then exit with an error.
|
// then exit with an error.
|
||||||
if i > len(coins)-1 {
|
if i > len(coins)-1 {
|
||||||
return 0, nil, fmt.Errorf("not enough outputs to create "+
|
return 0, nil, &ErrInsufficientFunds{amt, satSelected}
|
||||||
"funding transaction, need %v only have %v "+
|
|
||||||
"available", amt, satSelected)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, collect this new coin as it may be used for final
|
// Otherwise, collect this new coin as it may be used for final
|
||||||
|
|
Loading…
Add table
Reference in a new issue