Skip to content

Commit ac14dc0

Browse files
ZZiigguurraattZZiigguurraatt
authored andcommitted
printChannels: don't print a negative spendable amount if the channel was funded by the peer and the balance is less than the reserve because not enough payments were received yet
1 parent cafb54c commit ac14dc0

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

itest/assets_test.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,10 +2057,17 @@ func printChannels(t *testing.T, node *HarnessNode, peer *HarnessNode,
20572057
// note: the only field of the response is `channels`
20582058
for _, channel := range channelResp.Channels {
20592059

2060-
LocalSpendable := uint64(channel.LocalBalance) -
2061-
channel.LocalConstraints.ChanReserveSat
2062-
RemoteSpendable := uint64(channel.RemoteBalance) -
2063-
channel.RemoteConstraints.ChanReserveSat
2060+
LocalSpendable := channel.LocalBalance -
2061+
int64(channel.LocalConstraints.ChanReserveSat)
2062+
2063+
RemoteSpendable := channel.RemoteBalance -
2064+
int64(channel.RemoteConstraints.ChanReserveSat)
2065+
2066+
// Balance can be less than the reserve if funded by the peer and
2067+
// not enough payments received yet, so limit to 0 and don't let
2068+
// the Spendable value go negative.
2069+
if (LocalSpendable < 0) {LocalSpendable = 0}
2070+
if (RemoteSpendable < 0) {RemoteSpendable = 0}
20642071

20652072
var state string
20662073
var satsBalanceStatus string
@@ -2069,7 +2076,7 @@ func printChannels(t *testing.T, node *HarnessNode, peer *HarnessNode,
20692076
// make the sats payment
20702077
if satsToSend == 0 {
20712078
satsBalanceStatus = ""
2072-
} else if LocalSpendable >= satsToSend {
2079+
} else if LocalSpendable >= int64(satsToSend) {
20732080
satsBalanceStatus = "(✔) "
20742081
} else {
20752082
satsBalanceStatus = "(x) "

0 commit comments

Comments
 (0)