Skip to content

Commit 374b659

Browse files
committed
routing: don't assume HTLC amount for custom channel
It seems like the amount given to the getBandwidth is 0 in some cases (keysend) and non-zero in other cases (invoice payment). If we use custom channels, then that amount will likely not be the actual HTLC amount we're going to put on chain. So we have to use a zero amount for the MayAddOutgoingHtlc check, otherwise we might seem to go below the local channel reserve even though we'll end up sending a very small amount only. And since the check here is just to find out we're not already at the maximum HTLC capacity for this channel, we can safely use the amount of 0 for the check, which is handled properly in the link logic.
1 parent 7ffadde commit 374b659

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

routing/bandwidth.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ func (b *bandwidthManager) getBandwidth(cid lnwire.ShortChannelID,
138138

139139
auxBandwidth lnwire.MilliSatoshi
140140
auxBandwidthDetermined bool
141+
142+
// htlcAmount is the amount we're going to use to check if we
143+
// can add another HTLC to the channel. If the external traffic
144+
// shaper is handling the channel, we'll use 0 to just sanity
145+
// check the number of HTLCs on the channel, since we don't know
146+
// the actual HTLC amount that will be sent.
147+
htlcAmount = amount
141148
)
142149
err = fn.MapOptionZ(b.trafficShaper, func(ts TlvTrafficShaper) error {
143150
fundingBlob := link.FundingCustomBlob()
@@ -171,6 +178,15 @@ func (b *bandwidthManager) getBandwidth(cid lnwire.ShortChannelID,
171178

172179
auxBandwidthDetermined = true
173180

181+
// We don't know the actual HTLC amount that will be sent using
182+
// the custom channel. But we'll still want to make sure we can
183+
// add another HTLC, using the MayAddOutgoingHtlc method below.
184+
// Passing 0 into that method will use the minimum HTLC value
185+
// for the channel, which is okay to just check we don't exceed
186+
// the max number of HTLCs on the channel. A proper balance
187+
// check is done elsewhere.
188+
htlcAmount = 0
189+
174190
return nil
175191
})
176192
if err != nil {
@@ -180,11 +196,11 @@ func (b *bandwidthManager) getBandwidth(cid lnwire.ShortChannelID,
180196
return 0
181197
}
182198

183-
// If our link isn't currently in a state where it can add
184-
// another outgoing htlc, treat the link as unusable.
185-
if err := link.MayAddOutgoingHtlc(amount); err != nil {
199+
// If our link isn't currently in a state where it can add another
200+
// outgoing htlc, treat the link as unusable.
201+
if err := link.MayAddOutgoingHtlc(htlcAmount); err != nil {
186202
log.Warnf("ShortChannelID=%v: cannot add outgoing "+
187-
"htlc: %v", cid, err)
203+
"htlc with amount %v: %v", cid, htlcAmount, err)
188204
return 0
189205
}
190206

0 commit comments

Comments
 (0)