Skip to content

Commit b5c84ea

Browse files
authored
Merge pull request #9980 from GeorgeTsagk/enhance-aux-modifier
AuxTrafficShaper methods use first hop pub key
2 parents 1d2e547 + 9ef92d9 commit b5c84ea

File tree

6 files changed

+37
-9
lines changed

6 files changed

+37
-9
lines changed

docs/release-notes/release-notes-0.19.2.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@
5757
- [Improved](https://github.com/lightningnetwork/lnd/pull/9880) the connection
5858
restriction logic enforced by `accessman`. In addition, the restriction placed
5959
on outbound connections is now lifted.
60-
60+
- [Enhanced](https://github.com/lightningnetwork/lnd/pull/9980) the aux traffic
61+
shaper to now accept the first hop peer pub key as an argument. This can
62+
affect the reported aux bandwidth and also the custom records that are
63+
produced.
6164
## RPC Updates
6265

6366
## lncli Updates

htlcswitch/interfaces.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
1515
"github.com/lightningnetwork/lnd/lnwire"
1616
"github.com/lightningnetwork/lnd/record"
17+
"github.com/lightningnetwork/lnd/routing/route"
1718
"github.com/lightningnetwork/lnd/tlv"
1819
)
1920

@@ -495,8 +496,9 @@ type AuxHtlcModifier interface {
495496
// data blob of an HTLC, may produce a different blob or modify the
496497
// amount of bitcoin this htlc should carry.
497498
ProduceHtlcExtraData(totalAmount lnwire.MilliSatoshi,
498-
htlcCustomRecords lnwire.CustomRecords) (lnwire.MilliSatoshi,
499-
lnwire.CustomRecords, error)
499+
htlcCustomRecords lnwire.CustomRecords,
500+
peer route.Vertex) (lnwire.MilliSatoshi, lnwire.CustomRecords,
501+
error)
500502
}
501503

502504
// AuxTrafficShaper is an interface that allows the sender to determine if a
@@ -520,7 +522,8 @@ type AuxTrafficShaper interface {
520522
PaymentBandwidth(fundingBlob, htlcBlob,
521523
commitmentBlob fn.Option[tlv.Blob],
522524
linkBandwidth, htlcAmt lnwire.MilliSatoshi,
523-
htlcView lnwallet.AuxHtlcView) (lnwire.MilliSatoshi, error)
525+
htlcView lnwallet.AuxHtlcView,
526+
peer route.Vertex) (lnwire.MilliSatoshi, error)
524527

525528
// IsCustomHTLC returns true if the HTLC carries the set of relevant
526529
// custom records to put it under the purview of the traffic shaper,

htlcswitch/link.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/lightningnetwork/lnd/lnwire"
3232
"github.com/lightningnetwork/lnd/queue"
3333
"github.com/lightningnetwork/lnd/record"
34+
"github.com/lightningnetwork/lnd/routing/route"
3435
"github.com/lightningnetwork/lnd/ticker"
3536
"github.com/lightningnetwork/lnd/tlv"
3637
)
@@ -3503,11 +3504,19 @@ func (l *channelLink) AuxBandwidth(amount lnwire.MilliSatoshi,
35033504
})
35043505
}
35053506

3507+
peerBytes := l.cfg.Peer.PubKey()
3508+
3509+
peer, err := route.NewVertexFromBytes(peerBytes[:])
3510+
if err != nil {
3511+
return fn.Err[OptionalBandwidth](fmt.Errorf("failed to decode "+
3512+
"peer pub key: %v", err))
3513+
}
3514+
35063515
// Ask for a specific bandwidth to be used for the channel.
35073516
commitmentBlob := l.CommitmentCustomBlob()
35083517
auxBandwidth, err := ts.PaymentBandwidth(
35093518
fundingBlob, htlcBlob, commitmentBlob, l.Bandwidth(), amount,
3510-
l.channel.FetchLatestAuxHTLCView(),
3519+
l.channel.FetchLatestAuxHTLCView(), peer,
35113520
)
35123521
if err != nil {
35133522
return fn.Err[OptionalBandwidth](fmt.Errorf("failed to get "+

routing/bandwidth_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/lightningnetwork/lnd/htlcswitch"
1010
"github.com/lightningnetwork/lnd/lnwallet"
1111
"github.com/lightningnetwork/lnd/lnwire"
12+
"github.com/lightningnetwork/lnd/routing/route"
1213
"github.com/lightningnetwork/lnd/tlv"
1314
"github.com/stretchr/testify/require"
1415
)
@@ -152,7 +153,7 @@ func (*mockTrafficShaper) ShouldHandleTraffic(_ lnwire.ShortChannelID,
152153
// ShouldHandleTraffic method should be called first.
153154
func (*mockTrafficShaper) PaymentBandwidth(_, _, _ fn.Option[tlv.Blob],
154155
linkBandwidth, _ lnwire.MilliSatoshi,
155-
_ lnwallet.AuxHtlcView) (lnwire.MilliSatoshi, error) {
156+
_ lnwallet.AuxHtlcView, _ route.Vertex) (lnwire.MilliSatoshi, error) {
156157

157158
return linkBandwidth, nil
158159
}
@@ -161,8 +162,8 @@ func (*mockTrafficShaper) PaymentBandwidth(_, _, _ fn.Option[tlv.Blob],
161162
// data blob of an HTLC, may produce a different blob or modify the
162163
// amount of bitcoin this htlc should carry.
163164
func (*mockTrafficShaper) ProduceHtlcExtraData(totalAmount lnwire.MilliSatoshi,
164-
_ lnwire.CustomRecords) (lnwire.MilliSatoshi, lnwire.CustomRecords,
165-
error) {
165+
_ lnwire.CustomRecords, _ route.Vertex) (lnwire.MilliSatoshi,
166+
lnwire.CustomRecords, error) {
166167

167168
return totalAmount, nil, nil
168169
}

routing/payment_lifecycle.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,13 @@ func (p *paymentLifecycle) amendFirstHopData(rt *route.Route) error {
724724
// value.
725725
rt.FirstHopWireCustomRecords = p.firstHopCustomRecords
726726

727+
if len(rt.Hops) == 0 {
728+
return fmt.Errorf("cannot amend first hop data, route length " +
729+
"is zero")
730+
}
731+
732+
firstHopPK := rt.Hops[0].PubKeyBytes
733+
727734
// extraDataRequest is a helper struct to pass the custom records and
728735
// amount back from the traffic shaper.
729736
type extraDataRequest struct {
@@ -740,6 +747,7 @@ func (p *paymentLifecycle) amendFirstHopData(rt *route.Route) error {
740747
func(ts htlcswitch.AuxTrafficShaper) fn.Result[extraDataRequest] {
741748
newAmt, newRecords, err := ts.ProduceHtlcExtraData(
742749
rt.TotalAmount, p.firstHopCustomRecords,
750+
firstHopPK,
743751
)
744752
if err != nil {
745753
return fn.Err[extraDataRequest](err)

routing/payment_lifecycle_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,11 @@ func TestRequestRouteSucceed(t *testing.T) {
368368

369369
// Create a mock payment session and a dummy route.
370370
paySession := &mockPaymentSession{}
371-
dummyRoute := &route.Route{}
371+
dummyRoute := &route.Route{
372+
Hops: []*route.Hop{
373+
testHop,
374+
},
375+
}
372376

373377
// Mount the mocked payment session.
374378
p.paySession = paySession

0 commit comments

Comments
 (0)