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.
This commit is contained in:
Olaoluwa Osuntokun 2018-01-31 14:07:42 -08:00
parent b4e280eb15
commit 43fa9fe467
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
1 changed files with 3 additions and 2 deletions

View File

@ -1318,8 +1318,9 @@ func (l *LightningWallet) selectCoinsAndChange(feeRatePerWeight btcutil.Amount,
} }
// Record any change output(s) generated as a result of the coin // Record any change output(s) generated as a result of the coin
// selection. // selection, but only if the addition of the output won't lead to the
if changeAmt != 0 { // creation of dust.
if changeAmt != 0 && changeAmt > DefaultDustLimit() {
changeAddr, err := l.NewAddress(WitnessPubKey, true) changeAddr, err := l.NewAddress(WitnessPubKey, true)
if err != nil { if err != nil {
return err return err