mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-10 07:18:45 +02:00
Merge pull request #9980 from GeorgeTsagk/enhance-aux-modifier
AuxTrafficShaper methods use first hop pub key
This commit is contained in:
@@ -57,7 +57,10 @@
|
|||||||
- [Improved](https://github.com/lightningnetwork/lnd/pull/9880) the connection
|
- [Improved](https://github.com/lightningnetwork/lnd/pull/9880) the connection
|
||||||
restriction logic enforced by `accessman`. In addition, the restriction placed
|
restriction logic enforced by `accessman`. In addition, the restriction placed
|
||||||
on outbound connections is now lifted.
|
on outbound connections is now lifted.
|
||||||
|
- [Enhanced](https://github.com/lightningnetwork/lnd/pull/9980) the aux traffic
|
||||||
|
shaper to now accept the first hop peer pub key as an argument. This can
|
||||||
|
affect the reported aux bandwidth and also the custom records that are
|
||||||
|
produced.
|
||||||
## RPC Updates
|
## RPC Updates
|
||||||
|
|
||||||
## lncli Updates
|
## lncli Updates
|
||||||
|
@@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/record"
|
"github.com/lightningnetwork/lnd/record"
|
||||||
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
"github.com/lightningnetwork/lnd/tlv"
|
"github.com/lightningnetwork/lnd/tlv"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -495,8 +496,9 @@ type AuxHtlcModifier interface {
|
|||||||
// data blob of an HTLC, may produce a different blob or modify the
|
// data blob of an HTLC, may produce a different blob or modify the
|
||||||
// amount of bitcoin this htlc should carry.
|
// amount of bitcoin this htlc should carry.
|
||||||
ProduceHtlcExtraData(totalAmount lnwire.MilliSatoshi,
|
ProduceHtlcExtraData(totalAmount lnwire.MilliSatoshi,
|
||||||
htlcCustomRecords lnwire.CustomRecords) (lnwire.MilliSatoshi,
|
htlcCustomRecords lnwire.CustomRecords,
|
||||||
lnwire.CustomRecords, error)
|
peer route.Vertex) (lnwire.MilliSatoshi, lnwire.CustomRecords,
|
||||||
|
error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuxTrafficShaper is an interface that allows the sender to determine if a
|
// AuxTrafficShaper is an interface that allows the sender to determine if a
|
||||||
@@ -520,7 +522,8 @@ type AuxTrafficShaper interface {
|
|||||||
PaymentBandwidth(fundingBlob, htlcBlob,
|
PaymentBandwidth(fundingBlob, htlcBlob,
|
||||||
commitmentBlob fn.Option[tlv.Blob],
|
commitmentBlob fn.Option[tlv.Blob],
|
||||||
linkBandwidth, htlcAmt lnwire.MilliSatoshi,
|
linkBandwidth, htlcAmt lnwire.MilliSatoshi,
|
||||||
htlcView lnwallet.AuxHtlcView) (lnwire.MilliSatoshi, error)
|
htlcView lnwallet.AuxHtlcView,
|
||||||
|
peer route.Vertex) (lnwire.MilliSatoshi, error)
|
||||||
|
|
||||||
// IsCustomHTLC returns true if the HTLC carries the set of relevant
|
// IsCustomHTLC returns true if the HTLC carries the set of relevant
|
||||||
// custom records to put it under the purview of the traffic shaper,
|
// custom records to put it under the purview of the traffic shaper,
|
||||||
|
@@ -31,6 +31,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/queue"
|
"github.com/lightningnetwork/lnd/queue"
|
||||||
"github.com/lightningnetwork/lnd/record"
|
"github.com/lightningnetwork/lnd/record"
|
||||||
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
"github.com/lightningnetwork/lnd/ticker"
|
"github.com/lightningnetwork/lnd/ticker"
|
||||||
"github.com/lightningnetwork/lnd/tlv"
|
"github.com/lightningnetwork/lnd/tlv"
|
||||||
)
|
)
|
||||||
@@ -3503,11 +3504,19 @@ func (l *channelLink) AuxBandwidth(amount lnwire.MilliSatoshi,
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
peerBytes := l.cfg.Peer.PubKey()
|
||||||
|
|
||||||
|
peer, err := route.NewVertexFromBytes(peerBytes[:])
|
||||||
|
if err != nil {
|
||||||
|
return fn.Err[OptionalBandwidth](fmt.Errorf("failed to decode "+
|
||||||
|
"peer pub key: %v", err))
|
||||||
|
}
|
||||||
|
|
||||||
// Ask for a specific bandwidth to be used for the channel.
|
// Ask for a specific bandwidth to be used for the channel.
|
||||||
commitmentBlob := l.CommitmentCustomBlob()
|
commitmentBlob := l.CommitmentCustomBlob()
|
||||||
auxBandwidth, err := ts.PaymentBandwidth(
|
auxBandwidth, err := ts.PaymentBandwidth(
|
||||||
fundingBlob, htlcBlob, commitmentBlob, l.Bandwidth(), amount,
|
fundingBlob, htlcBlob, commitmentBlob, l.Bandwidth(), amount,
|
||||||
l.channel.FetchLatestAuxHTLCView(),
|
l.channel.FetchLatestAuxHTLCView(), peer,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fn.Err[OptionalBandwidth](fmt.Errorf("failed to get "+
|
return fn.Err[OptionalBandwidth](fmt.Errorf("failed to get "+
|
||||||
|
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
"github.com/lightningnetwork/lnd/tlv"
|
"github.com/lightningnetwork/lnd/tlv"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@@ -152,7 +153,7 @@ func (*mockTrafficShaper) ShouldHandleTraffic(_ lnwire.ShortChannelID,
|
|||||||
// ShouldHandleTraffic method should be called first.
|
// ShouldHandleTraffic method should be called first.
|
||||||
func (*mockTrafficShaper) PaymentBandwidth(_, _, _ fn.Option[tlv.Blob],
|
func (*mockTrafficShaper) PaymentBandwidth(_, _, _ fn.Option[tlv.Blob],
|
||||||
linkBandwidth, _ lnwire.MilliSatoshi,
|
linkBandwidth, _ lnwire.MilliSatoshi,
|
||||||
_ lnwallet.AuxHtlcView) (lnwire.MilliSatoshi, error) {
|
_ lnwallet.AuxHtlcView, _ route.Vertex) (lnwire.MilliSatoshi, error) {
|
||||||
|
|
||||||
return linkBandwidth, nil
|
return linkBandwidth, nil
|
||||||
}
|
}
|
||||||
@@ -161,8 +162,8 @@ func (*mockTrafficShaper) PaymentBandwidth(_, _, _ fn.Option[tlv.Blob],
|
|||||||
// data blob of an HTLC, may produce a different blob or modify the
|
// data blob of an HTLC, may produce a different blob or modify the
|
||||||
// amount of bitcoin this htlc should carry.
|
// amount of bitcoin this htlc should carry.
|
||||||
func (*mockTrafficShaper) ProduceHtlcExtraData(totalAmount lnwire.MilliSatoshi,
|
func (*mockTrafficShaper) ProduceHtlcExtraData(totalAmount lnwire.MilliSatoshi,
|
||||||
_ lnwire.CustomRecords) (lnwire.MilliSatoshi, lnwire.CustomRecords,
|
_ lnwire.CustomRecords, _ route.Vertex) (lnwire.MilliSatoshi,
|
||||||
error) {
|
lnwire.CustomRecords, error) {
|
||||||
|
|
||||||
return totalAmount, nil, nil
|
return totalAmount, nil, nil
|
||||||
}
|
}
|
||||||
|
@@ -724,6 +724,13 @@ func (p *paymentLifecycle) amendFirstHopData(rt *route.Route) error {
|
|||||||
// value.
|
// value.
|
||||||
rt.FirstHopWireCustomRecords = p.firstHopCustomRecords
|
rt.FirstHopWireCustomRecords = p.firstHopCustomRecords
|
||||||
|
|
||||||
|
if len(rt.Hops) == 0 {
|
||||||
|
return fmt.Errorf("cannot amend first hop data, route length " +
|
||||||
|
"is zero")
|
||||||
|
}
|
||||||
|
|
||||||
|
firstHopPK := rt.Hops[0].PubKeyBytes
|
||||||
|
|
||||||
// extraDataRequest is a helper struct to pass the custom records and
|
// extraDataRequest is a helper struct to pass the custom records and
|
||||||
// amount back from the traffic shaper.
|
// amount back from the traffic shaper.
|
||||||
type extraDataRequest struct {
|
type extraDataRequest struct {
|
||||||
@@ -740,6 +747,7 @@ func (p *paymentLifecycle) amendFirstHopData(rt *route.Route) error {
|
|||||||
func(ts htlcswitch.AuxTrafficShaper) fn.Result[extraDataRequest] {
|
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,
|
||||||
|
firstHopPK,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fn.Err[extraDataRequest](err)
|
return fn.Err[extraDataRequest](err)
|
||||||
|
@@ -368,7 +368,11 @@ func TestRequestRouteSucceed(t *testing.T) {
|
|||||||
|
|
||||||
// Create a mock payment session and a dummy route.
|
// Create a mock payment session and a dummy route.
|
||||||
paySession := &mockPaymentSession{}
|
paySession := &mockPaymentSession{}
|
||||||
dummyRoute := &route.Route{}
|
dummyRoute := &route.Route{
|
||||||
|
Hops: []*route.Hop{
|
||||||
|
testHop,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
// Mount the mocked payment session.
|
// Mount the mocked payment session.
|
||||||
p.paySession = paySession
|
p.paySession = paySession
|
||||||
|
Reference in New Issue
Block a user