htlcswitch: don't return negative value from Bandwidth()
This commits prevents the Bandwith() method from returning a negative value if the channel reserve is larger than the actual available balance.
This commit is contained in:
1 file changed
+12
-3
+12
-3
@@ -1261,12 +1261,21 @@ type getBandwidthCmd struct {
|
|||||||
//
|
//
|
||||||
// NOTE: Part of the ChannelLink interface.
|
// NOTE: Part of the ChannelLink interface.
|
||||||
func (l *channelLink) Bandwidth() lnwire.MilliSatoshi {
|
func (l *channelLink) Bandwidth() lnwire.MilliSatoshi {
|
||||||
// TODO(roasbeef): subtract reserve
|
|
||||||
channelBandwidth := l.channel.AvailableBalance()
|
channelBandwidth := l.channel.AvailableBalance()
|
||||||
overflowBandwidth := l.overflowQueue.TotalHtlcAmount()
|
overflowBandwidth := l.overflowQueue.TotalHtlcAmount()
|
||||||
reserve := lnwire.NewMSatFromSatoshis(l.channel.GetReserve())
|
linkBandwidth := channelBandwidth - overflowBandwidth
|
||||||
|
reserve := lnwire.NewMSatFromSatoshis(l.channel.LocalChanReserve())
|
||||||
|
|
||||||
return channelBandwidth - overflowBandwidth - reserve
|
// If the channel reserve is greater than the total available
|
||||||
|
// balance of the link, just return 0.
|
||||||
|
if linkBandwidth < reserve {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Else the amount that is available to flow through the link at
|
||||||
|
// this point is the available balance minus the reserve amount
|
||||||
|
// we are required to keep as collateral.
|
||||||
|
return linkBandwidth - reserve
|
||||||
}
|
}
|
||||||
|
|
||||||
// policyUpdate is a message sent to a channel link when an outside sub-system
|
// policyUpdate is a message sent to a channel link when an outside sub-system
|
||||||
|
|||||||
Reference in new issue
Block a user