routing: update TLV traffic shaper interface

This commit is contained in:
Oliver Gugger 2024-05-24 17:18:29 +02:00
parent 1404468299
commit b628483120
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
2 changed files with 9 additions and 15 deletions

View File

@ -3,7 +3,6 @@ package routing
import ( import (
"fmt" "fmt"
"github.com/btcsuite/btcd/btcutil"
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/fn" "github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/htlcswitch" "github.com/lightningnetwork/lnd/htlcswitch"
@ -55,7 +54,8 @@ 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,
htlcBlob tlv.Blob) (btcutil.Amount, tlv.Blob, error) htlcCustomRecords lnwire.CustomRecords) (lnwire.MilliSatoshi,
tlv.Blob, error)
} }
// getLinkQuery is the function signature used to lookup a link. // getLinkQuery is the function signature used to lookup a link.

View File

@ -679,23 +679,13 @@ func (p *paymentLifecycle) sendAttempt(
CustomRecords: lnwire.CustomRecords(p.firstHopTLVs), CustomRecords: lnwire.CustomRecords(p.firstHopTLVs),
} }
// If we had custom records in the HTLC, then we'll encode that here
// now. We allow the traffic shaper (if there is one) to overwrite the
// custom records below. But if there is no traffic shaper, we still
// want to forward these custom records.
encodedRecords, err := htlcAdd.CustomRecords.Serialize()
if err != nil {
return nil, fmt.Errorf("unable to encode first hop TLVs: %w",
err)
}
// If a hook exists that may affect our outgoing message, we call it now // If a hook exists that may affect our outgoing message, we call it now
// and apply its side effects to the UpdateAddHTLC message. // and apply its side effects to the UpdateAddHTLC message.
err = fn.MapOptionZ( err := fn.MapOptionZ(
p.router.cfg.TrafficShaper, p.router.cfg.TrafficShaper,
func(ts TlvTrafficShaper) error { func(ts TlvTrafficShaper) error {
newAmt, newData, err := ts.ProduceHtlcExtraData( newAmt, newData, err := ts.ProduceHtlcExtraData(
rt.TotalAmount, encodedRecords, rt.TotalAmount, htlcAdd.CustomRecords,
) )
if err != nil { if err != nil {
return err return err
@ -706,8 +696,12 @@ func (p *paymentLifecycle) sendAttempt(
return err return err
} }
log.Debugf("TLV traffic shaper returned custom "+
"records %v and amount %d msat for HTLC",
spew.Sdump(customRecords), newAmt)
htlcAdd.CustomRecords = customRecords htlcAdd.CustomRecords = customRecords
htlcAdd.Amount = lnwire.NewMSatFromSatoshis(newAmt) htlcAdd.Amount = newAmt
return nil return nil
}, },