multi: thread through and use AuxTrafficShaper
This commit is contained in:
3 files changed
+41
-1
No files matched your search
+35
-1
@@ -293,6 +293,10 @@ type ChannelLinkConfig struct {
|
|||||||
// ShouldFwdExpEndorsement is a closure that indicates whether the link
|
// ShouldFwdExpEndorsement is a closure that indicates whether the link
|
||||||
// should forward experimental endorsement signals.
|
// should forward experimental endorsement signals.
|
||||||
ShouldFwdExpEndorsement func() bool
|
ShouldFwdExpEndorsement func() bool
|
||||||
|
|
||||||
|
// AuxTrafficShaper is an optional auxiliary traffic shaper that can be
|
||||||
|
// used to manage the bandwidth of the link.
|
||||||
|
AuxTrafficShaper fn.Option[AuxTrafficShaper]
|
||||||
}
|
}
|
||||||
|
|
||||||
// channelLink is the service which drives a channel's commitment update
|
// channelLink is the service which drives a channel's commitment update
|
||||||
@@ -3401,8 +3405,38 @@ func (l *channelLink) canSendHtlc(policy models.ForwardingPolicy,
|
|||||||
return NewLinkError(&lnwire.FailExpiryTooFar{})
|
return NewLinkError(&lnwire.FailExpiryTooFar{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We now check the available bandwidth to see if this HTLC can be
|
||||||
|
// forwarded.
|
||||||
|
availableBandwidth := l.Bandwidth()
|
||||||
|
auxBandwidth, err := fn.MapOptionZ(
|
||||||
|
l.cfg.AuxTrafficShaper,
|
||||||
|
func(ts AuxTrafficShaper) fn.Result[OptionalBandwidth] {
|
||||||
|
var htlcBlob fn.Option[tlv.Blob]
|
||||||
|
blob, err := customRecords.Serialize()
|
||||||
|
if err != nil {
|
||||||
|
return fn.Err[OptionalBandwidth](
|
||||||
|
fmt.Errorf("unable to serialize "+
|
||||||
|
"custom records: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(blob) > 0 {
|
||||||
|
htlcBlob = fn.Some(blob)
|
||||||
|
}
|
||||||
|
|
||||||
|
return l.AuxBandwidth(amt, originalScid, htlcBlob, ts)
|
||||||
|
},
|
||||||
|
).Unpack()
|
||||||
|
if err != nil {
|
||||||
|
l.log.Errorf("Unable to determine aux bandwidth: %v", err)
|
||||||
|
return NewLinkError(&lnwire.FailTemporaryNodeFailure{})
|
||||||
|
}
|
||||||
|
|
||||||
|
auxBandwidth.WhenSome(func(bandwidth lnwire.MilliSatoshi) {
|
||||||
|
availableBandwidth = bandwidth
|
||||||
|
})
|
||||||
|
|
||||||
// Check to see if there is enough balance in this channel.
|
// Check to see if there is enough balance in this channel.
|
||||||
if amt > l.Bandwidth() {
|
if amt > availableBandwidth {
|
||||||
l.log.Warnf("insufficient bandwidth to route htlc: %v is "+
|
l.log.Warnf("insufficient bandwidth to route htlc: %v is "+
|
||||||
"larger than %v", amt, l.Bandwidth())
|
"larger than %v", amt, l.Bandwidth())
|
||||||
cb := func(upd *lnwire.ChannelUpdate1) lnwire.FailureMessage {
|
cb := func(upd *lnwire.ChannelUpdate1) lnwire.FailureMessage {
|
||||||
|
|||||||
@@ -400,6 +400,10 @@ type Config struct {
|
|||||||
// way contracts are resolved.
|
// way contracts are resolved.
|
||||||
AuxResolver fn.Option[lnwallet.AuxContractResolver]
|
AuxResolver fn.Option[lnwallet.AuxContractResolver]
|
||||||
|
|
||||||
|
// AuxTrafficShaper is an optional auxiliary traffic shaper that can be
|
||||||
|
// used to manage the bandwidth of peer links.
|
||||||
|
AuxTrafficShaper fn.Option[htlcswitch.AuxTrafficShaper]
|
||||||
|
|
||||||
// PongBuf is a slice we'll reuse instead of allocating memory on the
|
// PongBuf is a slice we'll reuse instead of allocating memory on the
|
||||||
// heap. Since only reads will occur and no writes, there is no need
|
// heap. Since only reads will occur and no writes, there is no need
|
||||||
// for any synchronization primitives. As a result, it's safe to share
|
// for any synchronization primitives. As a result, it's safe to share
|
||||||
@@ -1330,6 +1334,7 @@ func (p *Brontide) addLink(chanPoint *wire.OutPoint,
|
|||||||
ShouldFwdExpEndorsement: p.cfg.ShouldFwdExpEndorsement,
|
ShouldFwdExpEndorsement: p.cfg.ShouldFwdExpEndorsement,
|
||||||
DisallowQuiescence: p.cfg.DisallowQuiescence ||
|
DisallowQuiescence: p.cfg.DisallowQuiescence ||
|
||||||
!p.remoteFeatures.HasFeature(lnwire.QuiescenceOptional),
|
!p.remoteFeatures.HasFeature(lnwire.QuiescenceOptional),
|
||||||
|
AuxTrafficShaper: p.cfg.AuxTrafficShaper,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Before adding our new link, purge the switch of any pending or live
|
// Before adding our new link, purge the switch of any pending or live
|
||||||
|
|||||||
@@ -4222,6 +4222,7 @@ func (s *server) peerConnected(conn net.Conn, connReq *connmgr.ConnReq,
|
|||||||
MsgRouter: s.implCfg.MsgRouter,
|
MsgRouter: s.implCfg.MsgRouter,
|
||||||
AuxChanCloser: s.implCfg.AuxChanCloser,
|
AuxChanCloser: s.implCfg.AuxChanCloser,
|
||||||
AuxResolver: s.implCfg.AuxContractResolver,
|
AuxResolver: s.implCfg.AuxContractResolver,
|
||||||
|
AuxTrafficShaper: s.implCfg.TrafficShaper,
|
||||||
ShouldFwdExpEndorsement: func() bool {
|
ShouldFwdExpEndorsement: func() bool {
|
||||||
if s.cfg.ProtocolOptions.NoExperimentalEndorsement() {
|
if s.cfg.ProtocolOptions.NoExperimentalEndorsement() {
|
||||||
return false
|
return false
|
||||||
|
|||||||
Reference in new issue
Block a user