diff --git a/routing/payment_lifecycle.go b/routing/payment_lifecycle.go index 9757afebd..847d2be42 100644 --- a/routing/payment_lifecycle.go +++ b/routing/payment_lifecycle.go @@ -6,6 +6,7 @@ import ( "time" "github.com/btcsuite/btcd/btcec/v2" + "github.com/btcsuite/btcd/btcutil" "github.com/davecgh/go-spew/spew" sphinx "github.com/lightningnetwork/lightning-onion" "github.com/lightningnetwork/lnd/channeldb" @@ -688,6 +689,26 @@ func (p *paymentLifecycle) sendAttempt( return nil, err } + // If a hook exists that may affect our outgoing message, we call it now + // and apply its side effects to the UpdateAddHTLC message. + var err error + + p.router.cfg.TrafficShaper.WhenSome(func(ts TlvTrafficShaper) { + var newAmt btcutil.Amount + var newData []byte + + newAmt, newData, err = ts.ProduceHtlcExtraData( + htlcAdd.ExtraData, uint64(htlcAdd.Amount.ToSatoshis()), + ) + + htlcAdd.ExtraData = newData + htlcAdd.Amount = lnwire.MilliSatoshi(newAmt * 1000) + }) + + if err != nil { + return nil, err + } + // Generate the raw encoded sphinx packet to be included along // with the htlcAdd message that we send directly to the // switch.