From 43fa9fe467fc00549d0fdc6ec32252f85e4b6d06 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 31 Jan 2018 14:07:42 -0800 Subject: [PATCH] lnwallet: avoid creating dust change outputs in funding txns Before this commit, if the remaining change was small enough, then it was possible for us to generate a non-std funding transaction. This is an issue as the txn would fail to propagate, meaning funds could potentially be stuck in limbo if users didn't manually drop their transaction history. To avoid this scenario, we won't create a change output that is dusty. Instead, we'll add these as miner fees. Fixes #690. --- lnwallet/wallet.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lnwallet/wallet.go b/lnwallet/wallet.go index e96e20a6..63bf1d09 100644 --- a/lnwallet/wallet.go +++ b/lnwallet/wallet.go @@ -1318,8 +1318,9 @@ func (l *LightningWallet) selectCoinsAndChange(feeRatePerWeight btcutil.Amount, } // Record any change output(s) generated as a result of the coin - // selection. - if changeAmt != 0 { + // selection, but only if the addition of the output won't lead to the + // creation of dust. + if changeAmt != 0 && changeAmt > DefaultDustLimit() { changeAddr, err := l.NewAddress(WitnessPubKey, true) if err != nil { return err