mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-04 01:36:24 +01:00
htlcswitch+routing: return IsHandled from AuxBandwidth
To make it more clear whether the external traffic shaper is handling a channel or not, we return an explicit boolean.
This commit is contained in:
parent
d10ab03b75
commit
716db8b7d3
5 changed files with 36 additions and 14 deletions
|
@ -208,8 +208,18 @@ const (
|
|||
|
||||
// OptionalBandwidth is a type alias for the result of a bandwidth query that
|
||||
// may return a bandwidth value or fn.None if the bandwidth is not available or
|
||||
// not applicable.
|
||||
type OptionalBandwidth = fn.Option[lnwire.MilliSatoshi]
|
||||
// not applicable. IsHandled is set to false if the external traffic shaper does
|
||||
// not handle the channel in question.
|
||||
type OptionalBandwidth struct {
|
||||
// IsHandled is true if the external traffic shaper handles the channel.
|
||||
// If this is false, then the bandwidth value is not applicable.
|
||||
IsHandled bool
|
||||
|
||||
// Bandwidth is the available bandwidth for the channel, as determined
|
||||
// by the external traffic shaper. If the external traffic shaper is not
|
||||
// handling the channel, this value will be fn.None.
|
||||
Bandwidth fn.Option[lnwire.MilliSatoshi]
|
||||
}
|
||||
|
||||
// ChannelLink is an interface which represents the subsystem for managing the
|
||||
// incoming htlc requests, applying the changes to the channel, and also
|
||||
|
|
|
@ -3443,9 +3443,13 @@ func (l *channelLink) canSendHtlc(policy models.ForwardingPolicy,
|
|||
return NewLinkError(&lnwire.FailTemporaryNodeFailure{})
|
||||
}
|
||||
|
||||
auxBandwidth.WhenSome(func(bandwidth lnwire.MilliSatoshi) {
|
||||
availableBandwidth = bandwidth
|
||||
})
|
||||
if auxBandwidth.IsHandled && auxBandwidth.Bandwidth.IsSome() {
|
||||
auxBandwidth.Bandwidth.WhenSome(
|
||||
func(bandwidth lnwire.MilliSatoshi) {
|
||||
availableBandwidth = bandwidth
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// Check to see if there is enough balance in this channel.
|
||||
if amt > availableBandwidth {
|
||||
|
@ -3471,8 +3475,6 @@ func (l *channelLink) AuxBandwidth(amount lnwire.MilliSatoshi,
|
|||
cid lnwire.ShortChannelID, htlcBlob fn.Option[tlv.Blob],
|
||||
ts AuxTrafficShaper) fn.Result[OptionalBandwidth] {
|
||||
|
||||
unknownBandwidth := fn.None[lnwire.MilliSatoshi]()
|
||||
|
||||
fundingBlob := l.FundingCustomBlob()
|
||||
shouldHandle, err := ts.ShouldHandleTraffic(cid, fundingBlob)
|
||||
if err != nil {
|
||||
|
@ -3486,7 +3488,9 @@ func (l *channelLink) AuxBandwidth(amount lnwire.MilliSatoshi,
|
|||
// If this channel isn't handled by the aux traffic shaper, we'll return
|
||||
// early.
|
||||
if !shouldHandle {
|
||||
return fn.Ok(unknownBandwidth)
|
||||
return fn.Ok(OptionalBandwidth{
|
||||
IsHandled: false,
|
||||
})
|
||||
}
|
||||
|
||||
// Ask for a specific bandwidth to be used for the channel.
|
||||
|
@ -3502,7 +3506,10 @@ func (l *channelLink) AuxBandwidth(amount lnwire.MilliSatoshi,
|
|||
log.Debugf("ShortChannelID=%v: aux traffic shaper reported available "+
|
||||
"bandwidth: %v", cid, auxBandwidth)
|
||||
|
||||
return fn.Ok(fn.Some(auxBandwidth))
|
||||
return fn.Ok(OptionalBandwidth{
|
||||
IsHandled: true,
|
||||
Bandwidth: fn.Some(auxBandwidth),
|
||||
})
|
||||
}
|
||||
|
||||
// Stats returns the statistics of channel link.
|
||||
|
|
|
@ -976,7 +976,7 @@ func (f *mockChannelLink) AuxBandwidth(lnwire.MilliSatoshi,
|
|||
lnwire.ShortChannelID,
|
||||
fn.Option[tlv.Blob], AuxTrafficShaper) fn.Result[OptionalBandwidth] {
|
||||
|
||||
return fn.Ok(fn.None[lnwire.MilliSatoshi]())
|
||||
return fn.Ok(OptionalBandwidth{})
|
||||
}
|
||||
|
||||
var _ ChannelLink = (*mockChannelLink)(nil)
|
||||
|
|
|
@ -143,6 +143,13 @@ func (b *bandwidthManager) getBandwidth(cid lnwire.ShortChannelID,
|
|||
"auxiliary bandwidth: %w", err))
|
||||
}
|
||||
|
||||
// If the external traffic shaper is not handling the
|
||||
// channel, we'll just return the original bandwidth and
|
||||
// no custom amount.
|
||||
if !auxBandwidth.IsHandled {
|
||||
return fn.Ok(bandwidthResult{})
|
||||
}
|
||||
|
||||
// We don't know the actual HTLC amount that will be
|
||||
// sent using the custom channel. But we'll still want
|
||||
// to make sure we can add another HTLC, using the
|
||||
|
@ -152,7 +159,7 @@ func (b *bandwidthManager) getBandwidth(cid lnwire.ShortChannelID,
|
|||
// the max number of HTLCs on the channel. A proper
|
||||
// balance check is done elsewhere.
|
||||
return fn.Ok(bandwidthResult{
|
||||
bandwidth: auxBandwidth,
|
||||
bandwidth: auxBandwidth.Bandwidth,
|
||||
htlcAmount: fn.Some[lnwire.MilliSatoshi](0),
|
||||
})
|
||||
},
|
||||
|
|
|
@ -904,9 +904,7 @@ func (m *mockLink) AuxBandwidth(lnwire.MilliSatoshi, lnwire.ShortChannelID,
|
|||
fn.Option[tlv.Blob],
|
||||
htlcswitch.AuxTrafficShaper) fn.Result[htlcswitch.OptionalBandwidth] {
|
||||
|
||||
return fn.Ok[htlcswitch.OptionalBandwidth](
|
||||
fn.None[lnwire.MilliSatoshi](),
|
||||
)
|
||||
return fn.Ok(htlcswitch.OptionalBandwidth{})
|
||||
}
|
||||
|
||||
// EligibleToForward returns the mock's configured eligibility.
|
||||
|
|
Loading…
Add table
Reference in a new issue