Skip to content

Commit c4a77d1

Browse files
authored
Merge pull request #9502 from guggero/bandwidth-manager-fix
routing: don't set custom amount if manager isn't handling
2 parents 6531d45 + 0044975 commit c4a77d1

File tree

6 files changed

+39
-14
lines changed

6 files changed

+39
-14
lines changed

docs/release-notes/release-notes-0.19.0.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@
8585
* [Fixed a bug](https://github.com/lightningnetwork/lnd/pull/9595) where the
8686
initial graph sync query may be failed due to inconsistent state.
8787

88+
* [The aux bandwidth calculation was fixed for non-asset
89+
channels](https://github.com/lightningnetwork/lnd/pull/9502).
90+
8891
# New Features
8992

9093
* [Support](https://github.com/lightningnetwork/lnd/pull/8390) for

htlcswitch/interfaces.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,18 @@ const (
208208

209209
// OptionalBandwidth is a type alias for the result of a bandwidth query that
210210
// may return a bandwidth value or fn.None if the bandwidth is not available or
211-
// not applicable.
212-
type OptionalBandwidth = fn.Option[lnwire.MilliSatoshi]
211+
// not applicable. IsHandled is set to false if the external traffic shaper does
212+
// not handle the channel in question.
213+
type OptionalBandwidth struct {
214+
// IsHandled is true if the external traffic shaper handles the channel.
215+
// If this is false, then the bandwidth value is not applicable.
216+
IsHandled bool
217+
218+
// Bandwidth is the available bandwidth for the channel, as determined
219+
// by the external traffic shaper. If the external traffic shaper is not
220+
// handling the channel, this value will be fn.None.
221+
Bandwidth fn.Option[lnwire.MilliSatoshi]
222+
}
213223

214224
// ChannelLink is an interface which represents the subsystem for managing the
215225
// incoming htlc requests, applying the changes to the channel, and also

htlcswitch/link.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3443,9 +3443,13 @@ func (l *channelLink) canSendHtlc(policy models.ForwardingPolicy,
34433443
return NewLinkError(&lnwire.FailTemporaryNodeFailure{})
34443444
}
34453445

3446-
auxBandwidth.WhenSome(func(bandwidth lnwire.MilliSatoshi) {
3447-
availableBandwidth = bandwidth
3448-
})
3446+
if auxBandwidth.IsHandled && auxBandwidth.Bandwidth.IsSome() {
3447+
auxBandwidth.Bandwidth.WhenSome(
3448+
func(bandwidth lnwire.MilliSatoshi) {
3449+
availableBandwidth = bandwidth
3450+
},
3451+
)
3452+
}
34493453

34503454
// Check to see if there is enough balance in this channel.
34513455
if amt > availableBandwidth {
@@ -3471,8 +3475,6 @@ func (l *channelLink) AuxBandwidth(amount lnwire.MilliSatoshi,
34713475
cid lnwire.ShortChannelID, htlcBlob fn.Option[tlv.Blob],
34723476
ts AuxTrafficShaper) fn.Result[OptionalBandwidth] {
34733477

3474-
unknownBandwidth := fn.None[lnwire.MilliSatoshi]()
3475-
34763478
fundingBlob := l.FundingCustomBlob()
34773479
shouldHandle, err := ts.ShouldHandleTraffic(cid, fundingBlob)
34783480
if err != nil {
@@ -3486,7 +3488,9 @@ func (l *channelLink) AuxBandwidth(amount lnwire.MilliSatoshi,
34863488
// If this channel isn't handled by the aux traffic shaper, we'll return
34873489
// early.
34883490
if !shouldHandle {
3489-
return fn.Ok(unknownBandwidth)
3491+
return fn.Ok(OptionalBandwidth{
3492+
IsHandled: false,
3493+
})
34903494
}
34913495

34923496
// Ask for a specific bandwidth to be used for the channel.
@@ -3502,7 +3506,10 @@ func (l *channelLink) AuxBandwidth(amount lnwire.MilliSatoshi,
35023506
log.Debugf("ShortChannelID=%v: aux traffic shaper reported available "+
35033507
"bandwidth: %v", cid, auxBandwidth)
35043508

3505-
return fn.Ok(fn.Some(auxBandwidth))
3509+
return fn.Ok(OptionalBandwidth{
3510+
IsHandled: true,
3511+
Bandwidth: fn.Some(auxBandwidth),
3512+
})
35063513
}
35073514

35083515
// Stats returns the statistics of channel link.

htlcswitch/mock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ func (f *mockChannelLink) AuxBandwidth(lnwire.MilliSatoshi,
976976
lnwire.ShortChannelID,
977977
fn.Option[tlv.Blob], AuxTrafficShaper) fn.Result[OptionalBandwidth] {
978978

979-
return fn.Ok(fn.None[lnwire.MilliSatoshi]())
979+
return fn.Ok(OptionalBandwidth{})
980980
}
981981

982982
var _ ChannelLink = (*mockChannelLink)(nil)

routing/bandwidth.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ func (b *bandwidthManager) getBandwidth(cid lnwire.ShortChannelID,
143143
"auxiliary bandwidth: %w", err))
144144
}
145145

146+
// If the external traffic shaper is not handling the
147+
// channel, we'll just return the original bandwidth and
148+
// no custom amount.
149+
if !auxBandwidth.IsHandled {
150+
return fn.Ok(bandwidthResult{})
151+
}
152+
146153
// We don't know the actual HTLC amount that will be
147154
// sent using the custom channel. But we'll still want
148155
// to make sure we can add another HTLC, using the
@@ -152,7 +159,7 @@ func (b *bandwidthManager) getBandwidth(cid lnwire.ShortChannelID,
152159
// the max number of HTLCs on the channel. A proper
153160
// balance check is done elsewhere.
154161
return fn.Ok(bandwidthResult{
155-
bandwidth: auxBandwidth,
162+
bandwidth: auxBandwidth.Bandwidth,
156163
htlcAmount: fn.Some[lnwire.MilliSatoshi](0),
157164
})
158165
},

routing/mock_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,9 +904,7 @@ func (m *mockLink) AuxBandwidth(lnwire.MilliSatoshi, lnwire.ShortChannelID,
904904
fn.Option[tlv.Blob],
905905
htlcswitch.AuxTrafficShaper) fn.Result[htlcswitch.OptionalBandwidth] {
906906

907-
return fn.Ok[htlcswitch.OptionalBandwidth](
908-
fn.None[lnwire.MilliSatoshi](),
909-
)
907+
return fn.Ok(htlcswitch.OptionalBandwidth{})
910908
}
911909

912910
// EligibleToForward returns the mock's configured eligibility.

0 commit comments

Comments
 (0)