multi: move routing.TlvTrafficShaper => htlcswitch.AuxTrafficShaper
With this commit we move the traffic shaper definition from the routing package to the HTLC switch package as a preparation for being able to use it there as well. At the same time we rename it to AuxTrafficShaper to be more in line with the other auxiliary components.
This commit is contained in:
12 files changed
+167
-99
No files matched your search
+2
-2
@@ -36,6 +36,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/fn"
|
"github.com/lightningnetwork/lnd/fn"
|
||||||
"github.com/lightningnetwork/lnd/funding"
|
"github.com/lightningnetwork/lnd/funding"
|
||||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||||
|
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||||
"github.com/lightningnetwork/lnd/invoices"
|
"github.com/lightningnetwork/lnd/invoices"
|
||||||
"github.com/lightningnetwork/lnd/keychain"
|
"github.com/lightningnetwork/lnd/keychain"
|
||||||
"github.com/lightningnetwork/lnd/kvdb"
|
"github.com/lightningnetwork/lnd/kvdb"
|
||||||
@@ -47,7 +48,6 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lnwallet/rpcwallet"
|
"github.com/lightningnetwork/lnd/lnwallet/rpcwallet"
|
||||||
"github.com/lightningnetwork/lnd/macaroons"
|
"github.com/lightningnetwork/lnd/macaroons"
|
||||||
"github.com/lightningnetwork/lnd/msgmux"
|
"github.com/lightningnetwork/lnd/msgmux"
|
||||||
"github.com/lightningnetwork/lnd/routing"
|
|
||||||
"github.com/lightningnetwork/lnd/rpcperms"
|
"github.com/lightningnetwork/lnd/rpcperms"
|
||||||
"github.com/lightningnetwork/lnd/signal"
|
"github.com/lightningnetwork/lnd/signal"
|
||||||
"github.com/lightningnetwork/lnd/sqldb"
|
"github.com/lightningnetwork/lnd/sqldb"
|
||||||
@@ -166,7 +166,7 @@ type AuxComponents struct {
|
|||||||
|
|
||||||
// TrafficShaper is an optional traffic shaper that can be used to
|
// TrafficShaper is an optional traffic shaper that can be used to
|
||||||
// control the outgoing channel of a payment.
|
// control the outgoing channel of a payment.
|
||||||
TrafficShaper fn.Option[routing.TlvTrafficShaper]
|
TrafficShaper fn.Option[htlcswitch.AuxTrafficShaper]
|
||||||
|
|
||||||
// MsgRouter is an optional message router that if set will be used in
|
// MsgRouter is an optional message router that if set will be used in
|
||||||
// place of a new blank default message router.
|
// place of a new blank default message router.
|
||||||
|
|||||||
@@ -206,6 +206,11 @@ const (
|
|||||||
Outgoing LinkDirection = true
|
Outgoing LinkDirection = true
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 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]
|
||||||
|
|
||||||
// ChannelLink is an interface which represents the subsystem for managing the
|
// ChannelLink is an interface which represents the subsystem for managing the
|
||||||
// incoming htlc requests, applying the changes to the channel, and also
|
// incoming htlc requests, applying the changes to the channel, and also
|
||||||
// propagating/forwarding it to htlc switch.
|
// propagating/forwarding it to htlc switch.
|
||||||
@@ -284,8 +289,8 @@ type ChannelLink interface {
|
|||||||
// total sent/received milli-satoshis.
|
// total sent/received milli-satoshis.
|
||||||
Stats() (uint64, lnwire.MilliSatoshi, lnwire.MilliSatoshi)
|
Stats() (uint64, lnwire.MilliSatoshi, lnwire.MilliSatoshi)
|
||||||
|
|
||||||
// Peer returns the serialized public key of remote peer with which we
|
// PeerPubKey returns the serialized public key of remote peer with
|
||||||
// have the channel link opened.
|
// which we have the channel link opened.
|
||||||
PeerPubKey() [33]byte
|
PeerPubKey() [33]byte
|
||||||
|
|
||||||
// AttachMailBox delivers an active MailBox to the link. The MailBox may
|
// AttachMailBox delivers an active MailBox to the link. The MailBox may
|
||||||
@@ -302,9 +307,18 @@ type ChannelLink interface {
|
|||||||
// commitment of the channel that this link is associated with.
|
// commitment of the channel that this link is associated with.
|
||||||
CommitmentCustomBlob() fn.Option[tlv.Blob]
|
CommitmentCustomBlob() fn.Option[tlv.Blob]
|
||||||
|
|
||||||
// Start/Stop are used to initiate the start/stop of the channel link
|
// AuxBandwidth returns the bandwidth that can be used for a channel,
|
||||||
// functioning.
|
// expressed in milli-satoshi. This might be different from the regular
|
||||||
|
// BTC bandwidth for custom channels. This will always return fn.None()
|
||||||
|
// for a regular (non-custom) channel.
|
||||||
|
AuxBandwidth(amount lnwire.MilliSatoshi, cid lnwire.ShortChannelID,
|
||||||
|
htlcBlob fn.Option[tlv.Blob],
|
||||||
|
ts AuxTrafficShaper) fn.Result[OptionalBandwidth]
|
||||||
|
|
||||||
|
// Start starts the channel link.
|
||||||
Start() error
|
Start() error
|
||||||
|
|
||||||
|
// Stop requests the channel link to be shut down.
|
||||||
Stop()
|
Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -440,7 +454,7 @@ type htlcNotifier interface {
|
|||||||
NotifyForwardingEvent(key HtlcKey, info HtlcInfo,
|
NotifyForwardingEvent(key HtlcKey, info HtlcInfo,
|
||||||
eventType HtlcEventType)
|
eventType HtlcEventType)
|
||||||
|
|
||||||
// NotifyIncomingLinkFailEvent notifies that a htlc has failed on our
|
// NotifyLinkFailEvent notifies that a htlc has failed on our
|
||||||
// incoming link. It takes an isReceive bool to differentiate between
|
// incoming link. It takes an isReceive bool to differentiate between
|
||||||
// our node's receives and forwards.
|
// our node's receives and forwards.
|
||||||
NotifyLinkFailEvent(key HtlcKey, info HtlcInfo,
|
NotifyLinkFailEvent(key HtlcKey, info HtlcInfo,
|
||||||
@@ -461,3 +475,36 @@ type htlcNotifier interface {
|
|||||||
NotifyFinalHtlcEvent(key models.CircuitKey,
|
NotifyFinalHtlcEvent(key models.CircuitKey,
|
||||||
info channeldb.FinalHtlcInfo)
|
info channeldb.FinalHtlcInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AuxHtlcModifier is an interface that allows the sender to modify the outgoing
|
||||||
|
// HTLC of a payment by changing the amount or the wire message tlv records.
|
||||||
|
type AuxHtlcModifier interface {
|
||||||
|
// ProduceHtlcExtraData is a function that, based on the previous extra
|
||||||
|
// data blob of an HTLC, may produce a different blob or modify the
|
||||||
|
// amount of bitcoin this htlc should carry.
|
||||||
|
ProduceHtlcExtraData(totalAmount lnwire.MilliSatoshi,
|
||||||
|
htlcCustomRecords lnwire.CustomRecords) (lnwire.MilliSatoshi,
|
||||||
|
lnwire.CustomRecords, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuxTrafficShaper is an interface that allows the sender to determine if a
|
||||||
|
// payment should be carried by a channel based on the TLV records that may be
|
||||||
|
// present in the `update_add_htlc` message or the channel commitment itself.
|
||||||
|
type AuxTrafficShaper interface {
|
||||||
|
AuxHtlcModifier
|
||||||
|
|
||||||
|
// ShouldHandleTraffic is called in order to check if the channel
|
||||||
|
// identified by the provided channel ID may have external mechanisms
|
||||||
|
// that would allow it to carry out the payment.
|
||||||
|
ShouldHandleTraffic(cid lnwire.ShortChannelID,
|
||||||
|
fundingBlob fn.Option[tlv.Blob]) (bool, error)
|
||||||
|
|
||||||
|
// PaymentBandwidth returns the available bandwidth for a custom channel
|
||||||
|
// decided by the given channel aux blob and HTLC blob. A return value
|
||||||
|
// of 0 means there is no bandwidth available. To find out if a channel
|
||||||
|
// is a custom channel that should be handled by the traffic shaper, the
|
||||||
|
// ShouldHandleTraffic method should be called first.
|
||||||
|
PaymentBandwidth(htlcBlob, commitmentBlob fn.Option[tlv.Blob],
|
||||||
|
linkBandwidth,
|
||||||
|
htlcAmt lnwire.MilliSatoshi) (lnwire.MilliSatoshi, error)
|
||||||
|
}
|
||||||
@@ -3415,6 +3415,48 @@ func (l *channelLink) canSendHtlc(policy models.ForwardingPolicy,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AuxBandwidth returns the bandwidth that can be used for a channel, expressed
|
||||||
|
// in milli-satoshi. This might be different from the regular BTC bandwidth for
|
||||||
|
// custom channels. This will always return fn.None() for a regular (non-custom)
|
||||||
|
// channel.
|
||||||
|
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 {
|
||||||
|
return fn.Err[OptionalBandwidth](fmt.Errorf("traffic shaper "+
|
||||||
|
"failed to decide whether to handle traffic: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debugf("ShortChannelID=%v: aux traffic shaper is handling "+
|
||||||
|
"traffic: %v", cid, shouldHandle)
|
||||||
|
|
||||||
|
// If this channel isn't handled by the aux traffic shaper, we'll return
|
||||||
|
// early.
|
||||||
|
if !shouldHandle {
|
||||||
|
return fn.Ok(unknownBandwidth)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ask for a specific bandwidth to be used for the channel.
|
||||||
|
commitmentBlob := l.CommitmentCustomBlob()
|
||||||
|
auxBandwidth, err := ts.PaymentBandwidth(
|
||||||
|
htlcBlob, commitmentBlob, l.Bandwidth(), amount,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return fn.Err[OptionalBandwidth](fmt.Errorf("failed to get "+
|
||||||
|
"bandwidth from external traffic shaper: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debugf("ShortChannelID=%v: aux traffic shaper reported available "+
|
||||||
|
"bandwidth: %v", cid, auxBandwidth)
|
||||||
|
|
||||||
|
return fn.Ok(fn.Some(auxBandwidth))
|
||||||
|
}
|
||||||
|
|
||||||
// Stats returns the statistics of channel link.
|
// Stats returns the statistics of channel link.
|
||||||
//
|
//
|
||||||
// NOTE: Part of the ChannelLink interface.
|
// NOTE: Part of the ChannelLink interface.
|
||||||
|
|||||||
@@ -968,6 +968,17 @@ func (f *mockChannelLink) CommitmentCustomBlob() fn.Option[tlv.Blob] {
|
|||||||
return fn.None[tlv.Blob]()
|
return fn.None[tlv.Blob]()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AuxBandwidth returns the bandwidth that can be used for a channel,
|
||||||
|
// expressed in milli-satoshi. This might be different from the regular
|
||||||
|
// BTC bandwidth for custom channels. This will always return fn.None()
|
||||||
|
// for a regular (non-custom) channel.
|
||||||
|
func (f *mockChannelLink) AuxBandwidth(lnwire.MilliSatoshi,
|
||||||
|
lnwire.ShortChannelID,
|
||||||
|
fn.Option[tlv.Blob], AuxTrafficShaper) fn.Result[OptionalBandwidth] {
|
||||||
|
|
||||||
|
return fn.Ok(fn.None[lnwire.MilliSatoshi]())
|
||||||
|
}
|
||||||
|
|
||||||
var _ ChannelLink = (*mockChannelLink)(nil)
|
var _ ChannelLink = (*mockChannelLink)(nil)
|
||||||
|
|
||||||
const testInvoiceCltvExpiry = 6
|
const testInvoiceCltvExpiry = 6
|
||||||
|
|||||||
+10
-71
@@ -29,39 +29,6 @@ type bandwidthHints interface {
|
|||||||
firstHopCustomBlob() fn.Option[tlv.Blob]
|
firstHopCustomBlob() fn.Option[tlv.Blob]
|
||||||
}
|
}
|
||||||
|
|
||||||
// TlvTrafficShaper is an interface that allows the sender to determine if a
|
|
||||||
// payment should be carried by a channel based on the TLV records that may be
|
|
||||||
// present in the `update_add_htlc` message or the channel commitment itself.
|
|
||||||
type TlvTrafficShaper interface {
|
|
||||||
AuxHtlcModifier
|
|
||||||
|
|
||||||
// ShouldHandleTraffic is called in order to check if the channel
|
|
||||||
// identified by the provided channel ID may have external mechanisms
|
|
||||||
// that would allow it to carry out the payment.
|
|
||||||
ShouldHandleTraffic(cid lnwire.ShortChannelID,
|
|
||||||
fundingBlob fn.Option[tlv.Blob]) (bool, error)
|
|
||||||
|
|
||||||
// PaymentBandwidth returns the available bandwidth for a custom channel
|
|
||||||
// decided by the given channel aux blob and HTLC blob. A return value
|
|
||||||
// of 0 means there is no bandwidth available. To find out if a channel
|
|
||||||
// is a custom channel that should be handled by the traffic shaper, the
|
|
||||||
// HandleTraffic method should be called first.
|
|
||||||
PaymentBandwidth(htlcBlob, commitmentBlob fn.Option[tlv.Blob],
|
|
||||||
linkBandwidth,
|
|
||||||
htlcAmt lnwire.MilliSatoshi) (lnwire.MilliSatoshi, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AuxHtlcModifier is an interface that allows the sender to modify the outgoing
|
|
||||||
// HTLC of a payment by changing the amount or the wire message tlv records.
|
|
||||||
type AuxHtlcModifier interface {
|
|
||||||
// ProduceHtlcExtraData is a function that, based on the previous extra
|
|
||||||
// data blob of an HTLC, may produce a different blob or modify the
|
|
||||||
// amount of bitcoin this htlc should carry.
|
|
||||||
ProduceHtlcExtraData(totalAmount lnwire.MilliSatoshi,
|
|
||||||
htlcCustomRecords lnwire.CustomRecords) (lnwire.MilliSatoshi,
|
|
||||||
lnwire.CustomRecords, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// getLinkQuery is the function signature used to lookup a link.
|
// getLinkQuery is the function signature used to lookup a link.
|
||||||
type getLinkQuery func(lnwire.ShortChannelID) (
|
type getLinkQuery func(lnwire.ShortChannelID) (
|
||||||
htlcswitch.ChannelLink, error)
|
htlcswitch.ChannelLink, error)
|
||||||
@@ -73,7 +40,7 @@ type bandwidthManager struct {
|
|||||||
getLink getLinkQuery
|
getLink getLinkQuery
|
||||||
localChans map[lnwire.ShortChannelID]struct{}
|
localChans map[lnwire.ShortChannelID]struct{}
|
||||||
firstHopBlob fn.Option[tlv.Blob]
|
firstHopBlob fn.Option[tlv.Blob]
|
||||||
trafficShaper fn.Option[TlvTrafficShaper]
|
trafficShaper fn.Option[htlcswitch.AuxTrafficShaper]
|
||||||
}
|
}
|
||||||
|
|
||||||
// newBandwidthManager creates a bandwidth manager for the source node provided
|
// newBandwidthManager creates a bandwidth manager for the source node provided
|
||||||
@@ -84,13 +51,14 @@ type bandwidthManager struct {
|
|||||||
// that are inactive, or just don't have enough bandwidth to carry the payment.
|
// that are inactive, or just don't have enough bandwidth to carry the payment.
|
||||||
func newBandwidthManager(graph Graph, sourceNode route.Vertex,
|
func newBandwidthManager(graph Graph, sourceNode route.Vertex,
|
||||||
linkQuery getLinkQuery, firstHopBlob fn.Option[tlv.Blob],
|
linkQuery getLinkQuery, firstHopBlob fn.Option[tlv.Blob],
|
||||||
trafficShaper fn.Option[TlvTrafficShaper]) (*bandwidthManager, error) {
|
ts fn.Option[htlcswitch.AuxTrafficShaper]) (*bandwidthManager,
|
||||||
|
error) {
|
||||||
|
|
||||||
manager := &bandwidthManager{
|
manager := &bandwidthManager{
|
||||||
getLink: linkQuery,
|
getLink: linkQuery,
|
||||||
localChans: make(map[lnwire.ShortChannelID]struct{}),
|
localChans: make(map[lnwire.ShortChannelID]struct{}),
|
||||||
firstHopBlob: firstHopBlob,
|
firstHopBlob: firstHopBlob,
|
||||||
trafficShaper: trafficShaper,
|
trafficShaper: ts,
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, we'll collect the set of outbound edges from the target
|
// First, we'll collect the set of outbound edges from the target
|
||||||
@@ -166,44 +134,15 @@ func (b *bandwidthManager) getBandwidth(cid lnwire.ShortChannelID,
|
|||||||
|
|
||||||
result, err := fn.MapOptionZ(
|
result, err := fn.MapOptionZ(
|
||||||
b.trafficShaper,
|
b.trafficShaper,
|
||||||
func(ts TlvTrafficShaper) fn.Result[bandwidthResult] {
|
func(s htlcswitch.AuxTrafficShaper) fn.Result[bandwidthResult] {
|
||||||
fundingBlob := link.FundingCustomBlob()
|
auxBandwidth, err := link.AuxBandwidth(
|
||||||
shouldHandle, err := ts.ShouldHandleTraffic(
|
amount, cid, b.firstHopBlob, s,
|
||||||
cid, fundingBlob,
|
).Unpack()
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return bandwidthErr(fmt.Errorf("traffic "+
|
|
||||||
"shaper failed to decide whether to "+
|
|
||||||
"handle traffic: %w", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Debugf("ShortChannelID=%v: external traffic "+
|
|
||||||
"shaper is handling traffic: %v", cid,
|
|
||||||
shouldHandle)
|
|
||||||
|
|
||||||
// If this channel isn't handled by the external traffic
|
|
||||||
// shaper, we'll return early.
|
|
||||||
if !shouldHandle {
|
|
||||||
return fn.Ok(bandwidthResult{})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ask for a specific bandwidth to be used for the
|
|
||||||
// channel.
|
|
||||||
commitmentBlob := link.CommitmentCustomBlob()
|
|
||||||
auxBandwidth, err := ts.PaymentBandwidth(
|
|
||||||
b.firstHopBlob, commitmentBlob, linkBandwidth,
|
|
||||||
amount,
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return bandwidthErr(fmt.Errorf("failed to get "+
|
return bandwidthErr(fmt.Errorf("failed to get "+
|
||||||
"bandwidth from external traffic "+
|
"auxiliary bandwidth: %w", err))
|
||||||
"shaper: %w", err))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("ShortChannelID=%v: external traffic "+
|
|
||||||
"shaper reported available bandwidth: %v", cid,
|
|
||||||
auxBandwidth)
|
|
||||||
|
|
||||||
// We don't know the actual HTLC amount that will be
|
// We don't know the actual HTLC amount that will be
|
||||||
// sent using the custom channel. But we'll still want
|
// sent using the custom channel. But we'll still want
|
||||||
// to make sure we can add another HTLC, using the
|
// to make sure we can add another HTLC, using the
|
||||||
@@ -213,7 +152,7 @@ func (b *bandwidthManager) getBandwidth(cid lnwire.ShortChannelID,
|
|||||||
// the max number of HTLCs on the channel. A proper
|
// the max number of HTLCs on the channel. A proper
|
||||||
// balance check is done elsewhere.
|
// balance check is done elsewhere.
|
||||||
return fn.Ok(bandwidthResult{
|
return fn.Ok(bandwidthResult{
|
||||||
bandwidth: fn.Some(auxBandwidth),
|
bandwidth: auxBandwidth,
|
||||||
htlcAmount: fn.Some[lnwire.MilliSatoshi](0),
|
htlcAmount: fn.Some[lnwire.MilliSatoshi](0),
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -118,7 +118,9 @@ func TestBandwidthManager(t *testing.T) {
|
|||||||
m, err := newBandwidthManager(
|
m, err := newBandwidthManager(
|
||||||
g, sourceNode.pubkey, testCase.linkQuery,
|
g, sourceNode.pubkey, testCase.linkQuery,
|
||||||
fn.None[[]byte](),
|
fn.None[[]byte](),
|
||||||
fn.Some[TlvTrafficShaper](&mockTrafficShaper{}),
|
fn.Some[htlcswitch.AuxTrafficShaper](
|
||||||
|
&mockTrafficShaper{},
|
||||||
|
),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|||||||
+16
-2
@@ -107,7 +107,7 @@ var _ PaymentSessionSource = (*mockPaymentSessionSourceOld)(nil)
|
|||||||
|
|
||||||
func (m *mockPaymentSessionSourceOld) NewPaymentSession(
|
func (m *mockPaymentSessionSourceOld) NewPaymentSession(
|
||||||
_ *LightningPayment, _ fn.Option[tlv.Blob],
|
_ *LightningPayment, _ fn.Option[tlv.Blob],
|
||||||
_ fn.Option[TlvTrafficShaper]) (PaymentSession, error) {
|
_ fn.Option[htlcswitch.AuxTrafficShaper]) (PaymentSession, error) {
|
||||||
|
|
||||||
return &mockPaymentSessionOld{
|
return &mockPaymentSessionOld{
|
||||||
routes: m.routes,
|
routes: m.routes,
|
||||||
@@ -635,7 +635,8 @@ var _ PaymentSessionSource = (*mockPaymentSessionSource)(nil)
|
|||||||
|
|
||||||
func (m *mockPaymentSessionSource) NewPaymentSession(
|
func (m *mockPaymentSessionSource) NewPaymentSession(
|
||||||
payment *LightningPayment, firstHopBlob fn.Option[tlv.Blob],
|
payment *LightningPayment, firstHopBlob fn.Option[tlv.Blob],
|
||||||
tlvShaper fn.Option[TlvTrafficShaper]) (PaymentSession, error) {
|
tlvShaper fn.Option[htlcswitch.AuxTrafficShaper]) (PaymentSession,
|
||||||
|
error) {
|
||||||
|
|
||||||
args := m.Called(payment, firstHopBlob, tlvShaper)
|
args := m.Called(payment, firstHopBlob, tlvShaper)
|
||||||
return args.Get(0).(PaymentSession), args.Error(1)
|
return args.Get(0).(PaymentSession), args.Error(1)
|
||||||
@@ -895,6 +896,19 @@ func (m *mockLink) Bandwidth() lnwire.MilliSatoshi {
|
|||||||
return m.bandwidth
|
return m.bandwidth
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AuxBandwidth returns the bandwidth that can be used for a channel,
|
||||||
|
// expressed in milli-satoshi. This might be different from the regular
|
||||||
|
// BTC bandwidth for custom channels. This will always return fn.None()
|
||||||
|
// for a regular (non-custom) channel.
|
||||||
|
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](),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// EligibleToForward returns the mock's configured eligibility.
|
// EligibleToForward returns the mock's configured eligibility.
|
||||||
func (m *mockLink) EligibleToForward() bool {
|
func (m *mockLink) EligibleToForward() bool {
|
||||||
return !m.ineligible
|
return !m.ineligible
|
||||||
|
|||||||
@@ -761,7 +761,8 @@ func (p *paymentLifecycle) amendFirstHopData(rt *route.Route) error {
|
|||||||
// and apply its side effects to the UpdateAddHTLC message.
|
// and apply its side effects to the UpdateAddHTLC message.
|
||||||
result, err := fn.MapOptionZ(
|
result, err := fn.MapOptionZ(
|
||||||
p.router.cfg.TrafficShaper,
|
p.router.cfg.TrafficShaper,
|
||||||
func(ts TlvTrafficShaper) fn.Result[extraDataRequest] {
|
//nolint:ll
|
||||||
|
func(ts htlcswitch.AuxTrafficShaper) fn.Result[extraDataRequest] {
|
||||||
newAmt, newRecords, err := ts.ProduceHtlcExtraData(
|
newAmt, newRecords, err := ts.ProduceHtlcExtraData(
|
||||||
rt.TotalAmount, p.firstHopCustomRecords,
|
rt.TotalAmount, p.firstHopCustomRecords,
|
||||||
)
|
)
|
||||||
@@ -774,7 +775,7 @@ func (p *paymentLifecycle) amendFirstHopData(rt *route.Route) error {
|
|||||||
return fn.Err[extraDataRequest](err)
|
return fn.Err[extraDataRequest](err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("TLV traffic shaper returned custom "+
|
log.Debugf("Aux traffic shaper returned custom "+
|
||||||
"records %v and amount %d msat for HTLC",
|
"records %v and amount %d msat for HTLC",
|
||||||
spew.Sdump(newRecords), newAmt)
|
spew.Sdump(newRecords), newAmt)
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func createTestPaymentLifecycle() *paymentLifecycle {
|
|||||||
quitChan := make(chan struct{})
|
quitChan := make(chan struct{})
|
||||||
rt := &ChannelRouter{
|
rt := &ChannelRouter{
|
||||||
cfg: &Config{
|
cfg: &Config{
|
||||||
TrafficShaper: fn.Some[TlvTrafficShaper](
|
TrafficShaper: fn.Some[htlcswitch.AuxTrafficShaper](
|
||||||
&mockTrafficShaper{},
|
&mockTrafficShaper{},
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@@ -83,7 +83,7 @@ func newTestPaymentLifecycle(t *testing.T) (*paymentLifecycle, *mockers) {
|
|||||||
Payer: mockPayer,
|
Payer: mockPayer,
|
||||||
Clock: mockClock,
|
Clock: mockClock,
|
||||||
MissionControl: mockMissionControl,
|
MissionControl: mockMissionControl,
|
||||||
TrafficShaper: fn.Some[TlvTrafficShaper](
|
TrafficShaper: fn.Some[htlcswitch.AuxTrafficShaper](
|
||||||
&mockTrafficShaper{},
|
&mockTrafficShaper{},
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
"github.com/lightningnetwork/lnd/fn"
|
"github.com/lightningnetwork/lnd/fn"
|
||||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||||
|
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
"github.com/lightningnetwork/lnd/tlv"
|
"github.com/lightningnetwork/lnd/tlv"
|
||||||
@@ -52,7 +53,8 @@ type SessionSource struct {
|
|||||||
// payment's destination.
|
// payment's destination.
|
||||||
func (m *SessionSource) NewPaymentSession(p *LightningPayment,
|
func (m *SessionSource) NewPaymentSession(p *LightningPayment,
|
||||||
firstHopBlob fn.Option[tlv.Blob],
|
firstHopBlob fn.Option[tlv.Blob],
|
||||||
trafficShaper fn.Option[TlvTrafficShaper]) (PaymentSession, error) {
|
trafficShaper fn.Option[htlcswitch.AuxTrafficShaper]) (PaymentSession,
|
||||||
|
error) {
|
||||||
|
|
||||||
getBandwidthHints := func(graph Graph) (bandwidthHints, error) {
|
getBandwidthHints := func(graph Graph) (bandwidthHints, error) {
|
||||||
return newBandwidthManager(
|
return newBandwidthManager(
|
||||||
|
|||||||
+2
-2
@@ -157,7 +157,7 @@ type PaymentSessionSource interface {
|
|||||||
// finding a path to the payment's destination.
|
// finding a path to the payment's destination.
|
||||||
NewPaymentSession(p *LightningPayment,
|
NewPaymentSession(p *LightningPayment,
|
||||||
firstHopBlob fn.Option[tlv.Blob],
|
firstHopBlob fn.Option[tlv.Blob],
|
||||||
trafficShaper fn.Option[TlvTrafficShaper]) (PaymentSession,
|
ts fn.Option[htlcswitch.AuxTrafficShaper]) (PaymentSession,
|
||||||
error)
|
error)
|
||||||
|
|
||||||
// NewPaymentSessionEmpty creates a new paymentSession instance that is
|
// NewPaymentSessionEmpty creates a new paymentSession instance that is
|
||||||
@@ -297,7 +297,7 @@ type Config struct {
|
|||||||
|
|
||||||
// TrafficShaper is an optional traffic shaper that can be used to
|
// TrafficShaper is an optional traffic shaper that can be used to
|
||||||
// control the outgoing channel of a payment.
|
// control the outgoing channel of a payment.
|
||||||
TrafficShaper fn.Option[TlvTrafficShaper]
|
TrafficShaper fn.Option[htlcswitch.AuxTrafficShaper]
|
||||||
}
|
}
|
||||||
|
|
||||||
// EdgeLocator is a struct used to identify a specific edge.
|
// EdgeLocator is a struct used to identify a specific edge.
|
||||||
|
|||||||
+21
-11
@@ -170,7 +170,7 @@ func createTestCtxFromGraphInstanceAssumeValid(t *testing.T,
|
|||||||
Clock: clock.NewTestClock(time.Unix(1, 0)),
|
Clock: clock.NewTestClock(time.Unix(1, 0)),
|
||||||
ApplyChannelUpdate: graphBuilder.ApplyChannelUpdate,
|
ApplyChannelUpdate: graphBuilder.ApplyChannelUpdate,
|
||||||
ClosedSCIDs: mockClosedSCIDs,
|
ClosedSCIDs: mockClosedSCIDs,
|
||||||
TrafficShaper: fn.Some[TlvTrafficShaper](
|
TrafficShaper: fn.Some[htlcswitch.AuxTrafficShaper](
|
||||||
&mockTrafficShaper{},
|
&mockTrafficShaper{},
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
@@ -2206,8 +2206,10 @@ func TestSendToRouteSkipTempErrSuccess(t *testing.T) {
|
|||||||
NextPaymentID: func() (uint64, error) {
|
NextPaymentID: func() (uint64, error) {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
},
|
},
|
||||||
ClosedSCIDs: mockClosedSCIDs,
|
ClosedSCIDs: mockClosedSCIDs,
|
||||||
TrafficShaper: fn.Some[TlvTrafficShaper](&mockTrafficShaper{}),
|
TrafficShaper: fn.Some[htlcswitch.AuxTrafficShaper](
|
||||||
|
&mockTrafficShaper{},
|
||||||
|
),
|
||||||
}}
|
}}
|
||||||
|
|
||||||
// Register mockers with the expected method calls.
|
// Register mockers with the expected method calls.
|
||||||
@@ -2291,8 +2293,10 @@ func TestSendToRouteSkipTempErrNonMPP(t *testing.T) {
|
|||||||
NextPaymentID: func() (uint64, error) {
|
NextPaymentID: func() (uint64, error) {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
},
|
},
|
||||||
ClosedSCIDs: mockClosedSCIDs,
|
ClosedSCIDs: mockClosedSCIDs,
|
||||||
TrafficShaper: fn.Some[TlvTrafficShaper](&mockTrafficShaper{}),
|
TrafficShaper: fn.Some[htlcswitch.AuxTrafficShaper](
|
||||||
|
&mockTrafficShaper{},
|
||||||
|
),
|
||||||
}}
|
}}
|
||||||
|
|
||||||
// Expect an error to be returned.
|
// Expect an error to be returned.
|
||||||
@@ -2347,8 +2351,10 @@ func TestSendToRouteSkipTempErrTempFailure(t *testing.T) {
|
|||||||
NextPaymentID: func() (uint64, error) {
|
NextPaymentID: func() (uint64, error) {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
},
|
},
|
||||||
ClosedSCIDs: mockClosedSCIDs,
|
ClosedSCIDs: mockClosedSCIDs,
|
||||||
TrafficShaper: fn.Some[TlvTrafficShaper](&mockTrafficShaper{}),
|
TrafficShaper: fn.Some[htlcswitch.AuxTrafficShaper](
|
||||||
|
&mockTrafficShaper{},
|
||||||
|
),
|
||||||
}}
|
}}
|
||||||
|
|
||||||
// Create the error to be returned.
|
// Create the error to be returned.
|
||||||
@@ -2431,8 +2437,10 @@ func TestSendToRouteSkipTempErrPermanentFailure(t *testing.T) {
|
|||||||
NextPaymentID: func() (uint64, error) {
|
NextPaymentID: func() (uint64, error) {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
},
|
},
|
||||||
ClosedSCIDs: mockClosedSCIDs,
|
ClosedSCIDs: mockClosedSCIDs,
|
||||||
TrafficShaper: fn.Some[TlvTrafficShaper](&mockTrafficShaper{}),
|
TrafficShaper: fn.Some[htlcswitch.AuxTrafficShaper](
|
||||||
|
&mockTrafficShaper{},
|
||||||
|
),
|
||||||
}}
|
}}
|
||||||
|
|
||||||
// Create the error to be returned.
|
// Create the error to be returned.
|
||||||
@@ -2519,8 +2527,10 @@ func TestSendToRouteTempFailure(t *testing.T) {
|
|||||||
NextPaymentID: func() (uint64, error) {
|
NextPaymentID: func() (uint64, error) {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
},
|
},
|
||||||
ClosedSCIDs: mockClosedSCIDs,
|
ClosedSCIDs: mockClosedSCIDs,
|
||||||
TrafficShaper: fn.Some[TlvTrafficShaper](&mockTrafficShaper{}),
|
TrafficShaper: fn.Some[htlcswitch.AuxTrafficShaper](
|
||||||
|
&mockTrafficShaper{},
|
||||||
|
),
|
||||||
}}
|
}}
|
||||||
|
|
||||||
// Create the error to be returned.
|
// Create the error to be returned.
|
||||||
|
|||||||
Reference in new issue
Block a user