lnwallet: fix infinite loop in coin selection

Fix wrong calculation of overshot amount which causes coin select
function to go into infinite loop. If overshoot amount is calculated
by subtraction of totalSatoshis and amtNeeded than on the second
iteration of loop amtNeeded already include required fee inside, which
causes continuation of the coin selection loop.
This commit is contained in:
andrew.shvv 2017-11-18 00:15:50 +03:00 committed by Olaoluwa Osuntokun
parent b31e94573b
commit 4168c97a27

@ -1425,7 +1425,7 @@ func coinSelect(feeRatePerWeight uint64, amt btcutil.Amount,
// The difference between the selected amount and the amount
// requested will be used to pay fees, and generate a change
// output with the remaining.
overShootAmt := totalSat - amtNeeded
overShootAmt := totalSat - amt
// Based on the estimated size and fee rate, if the excess
// amount isn't enough to pay fees, then increase the requested