From 6ab625d69bc4eb6f7238549e67acdc1511c265fa Mon Sep 17 00:00:00 2001 From: Bjarne Magnussen Date: Sun, 11 Apr 2021 21:38:42 +0200 Subject: [PATCH] chanfunding: factor out sanity check for change that is dust --- lnwallet/chanfunding/wallet_assembler.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lnwallet/chanfunding/wallet_assembler.go b/lnwallet/chanfunding/wallet_assembler.go index 446e35ac..ee335f32 100644 --- a/lnwallet/chanfunding/wallet_assembler.go +++ b/lnwallet/chanfunding/wallet_assembler.go @@ -1,6 +1,7 @@ package chanfunding import ( + "fmt" "math" "github.com/btcsuite/btcd/btcec" @@ -299,11 +300,18 @@ func (w *WalletAssembler) ProvisionChannel(r *Request) (Intent, error) { } } + // Sanity check: The addition of the outputs should not lead to the + // creation of dust. + if changeAmt != 0 && changeAmt <= w.cfg.DustLimit { + return fmt.Errorf("change amount(%v) after coin "+ + "select is below dust limit(%v)", changeAmt, + w.cfg.DustLimit) + } + // Record any change output(s) generated as a result of the - // coin selection, but only if the addition of the output won't - // lead to the creation of dust. + // coin selection. var changeOutput *wire.TxOut - if changeAmt != 0 && changeAmt > w.cfg.DustLimit { + if changeAmt != 0 { changeAddr, err := r.ChangeAddr() if err != nil { return err