routing+htlcswitch: ProduceHtlcExtraData uses first hop pub key

This commit is contained in:
George Tsagkarelis
2025-06-23 13:01:01 +02:00
committed by Oliver Gugger
parent c91753eda1
commit ab036990b5
4 changed files with 20 additions and 5 deletions

View File

@@ -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

View File

@@ -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"
) )
@@ -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
} }

View File

@@ -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)

View File

@@ -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