Skip to content

Commit 1793b1a

Browse files
committed
routing+htlcswitch: ProduceHtlcExtraData uses first hop pub key
1 parent 01dfee6 commit 1793b1a

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

htlcswitch/interfaces.go

Lines changed: 4 additions & 2 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

routing/bandwidth_test.go

Lines changed: 3 additions & 2 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
)
@@ -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)