multi: add blinded path TLVs to onion payload / hops
This commit adds the encrypted_data, blinding_point and total_amt_msat tlvs to the known set of even tlvs for the onion payload. These TLVs are added in two places (the onion payload and hop struct) because lnd uses the same set of TLV types for both structs (and they inherently represent the same thing). Note: in some places, unit tests intentionally mimic the style of older tests, so as to be more consistently readable.
This commit is contained in:
1 parent
539a275faa
commit
fee0e05708
7 files changed
+392
-23
No files matched your search
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/record"
|
||||
@@ -94,9 +95,20 @@ type Payload struct {
|
||||
// were included in the payload.
|
||||
customRecords record.CustomSet
|
||||
|
||||
// encryptedData is a blob of data encrypted by the receiver for use
|
||||
// in blinded routes.
|
||||
encryptedData []byte
|
||||
|
||||
// blindingPoint is an ephemeral pubkey for use in blinded routes.
|
||||
blindingPoint *btcec.PublicKey
|
||||
|
||||
// metadata is additional data that is sent along with the payment to
|
||||
// the payee.
|
||||
metadata []byte
|
||||
|
||||
// totalAmtMsat holds the info provided in total_amount_msat when
|
||||
// parsed from a TLV onion payload.
|
||||
totalAmtMsat lnwire.MilliSatoshi
|
||||
}
|
||||
|
||||
// NewLegacyPayload builds a Payload from the amount, cltv, and next hop
|
||||
@@ -118,12 +130,15 @@ func NewLegacyPayload(f *sphinx.HopData) *Payload {
|
||||
// should correspond to the bytes encapsulated in a TLV onion payload.
|
||||
func NewPayloadFromReader(r io.Reader) (*Payload, error) {
|
||||
var (
|
||||
cid uint64
|
||||
amt uint64
|
||||
cltv uint32
|
||||
mpp = &record.MPP{}
|
||||
amp = &record.AMP{}
|
||||
metadata []byte
|
||||
cid uint64
|
||||
amt uint64
|
||||
totalAmtMsat uint64
|
||||
cltv uint32
|
||||
mpp = &record.MPP{}
|
||||
amp = &record.AMP{}
|
||||
encryptedData []byte
|
||||
blindingPoint *btcec.PublicKey
|
||||
metadata []byte
|
||||
)
|
||||
|
||||
tlvStream, err := tlv.NewStream(
|
||||
@@ -131,8 +146,11 @@ func NewPayloadFromReader(r io.Reader) (*Payload, error) {
|
||||
record.NewLockTimeRecord(&cltv),
|
||||
record.NewNextHopIDRecord(&cid),
|
||||
mpp.Record(),
|
||||
record.NewEncryptedDataRecord(&encryptedData),
|
||||
record.NewBlindingPointRecord(&blindingPoint),
|
||||
amp.Record(),
|
||||
record.NewMetadataRecord(&metadata),
|
||||
record.NewTotalAmtMsatBlinded(&totalAmtMsat),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -175,6 +193,12 @@ func NewPayloadFromReader(r io.Reader) (*Payload, error) {
|
||||
amp = nil
|
||||
}
|
||||
|
||||
// If no encrypted data was parsed, set the field on our resulting
|
||||
// payload to nil.
|
||||
if _, ok := parsedTypes[record.EncryptedDataOnionType]; !ok {
|
||||
encryptedData = nil
|
||||
}
|
||||
|
||||
// If no metadata field was parsed, set the metadata field on the
|
||||
// resulting payload to nil.
|
||||
if _, ok := parsedTypes[record.MetadataOnionType]; !ok {
|
||||
@@ -193,7 +217,10 @@ func NewPayloadFromReader(r io.Reader) (*Payload, error) {
|
||||
MPP: mpp,
|
||||
AMP: amp,
|
||||
metadata: metadata,
|
||||
encryptedData: encryptedData,
|
||||
blindingPoint: blindingPoint,
|
||||
customRecords: customRecords,
|
||||
totalAmtMsat: lnwire.MilliSatoshi(totalAmtMsat),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -297,12 +324,29 @@ func (h *Payload) CustomRecords() record.CustomSet {
|
||||
return h.customRecords
|
||||
}
|
||||
|
||||
// EncryptedData returns the route blinding encrypted data parsed from the
|
||||
// onion payload.
|
||||
func (h *Payload) EncryptedData() []byte {
|
||||
return h.encryptedData
|
||||
}
|
||||
|
||||
// BlindingPoint returns the route blinding point parsed from the onion payload.
|
||||
func (h *Payload) BlindingPoint() *btcec.PublicKey {
|
||||
return h.blindingPoint
|
||||
}
|
||||
|
||||
// Metadata returns the additional data that is sent along with the
|
||||
// payment to the payee.
|
||||
func (h *Payload) Metadata() []byte {
|
||||
return h.metadata
|
||||
}
|
||||
|
||||
// TotalAmtMsat returns the total amount sent to the final hop, as set by the
|
||||
// payee.
|
||||
func (h *Payload) TotalAmtMsat() lnwire.MilliSatoshi {
|
||||
return h.totalAmtMsat
|
||||
}
|
||||
|
||||
// getMinRequiredViolation checks for unrecognized required (even) fields in the
|
||||
// standard range and returns the lowest required type. Always returning the
|
||||
// lowest required type allows a failure message to be deterministic.
|
||||
|
||||
Reference in new issue
Block a user