routing: invoke htlc ExtraData producer on update_add_htlc

This commit is contained in:
George Tsagkarelis 2024-05-02 19:49:55 +02:00 committed by Oliver Gugger
parent 309a1564d0
commit 4c7d2d4e99
No known key found for this signature in database
GPG Key ID: 8E4256593F177720

View File

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