From 4168c97a27c867693f3b941e056b474ebbbe45f4 Mon Sep 17 00:00:00 2001 From: "andrew.shvv" Date: Sat, 18 Nov 2017 00:15:50 +0300 Subject: [PATCH] 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. --- lnwallet/wallet.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lnwallet/wallet.go b/lnwallet/wallet.go index 7fd6d90a..8933a90f 100644 --- a/lnwallet/wallet.go +++ b/lnwallet/wallet.go @@ -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