lnwire: add blinding point to update_add_htlc TLVs
Add blinding points to update_add_htlc. This TLV will be set for nodes that are relaying payments in blinded routes that are _not_ the introduction node.
This commit is contained in:
5 files changed
+111
-17
No files matched your search
@@ -3,6 +3,9 @@ package lnwire
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/lightningnetwork/lnd/tlv"
|
||||
)
|
||||
|
||||
// OnionPacketSize is the size of the serialized Sphinx onion packet included
|
||||
@@ -11,6 +14,17 @@ import (
|
||||
// of per-hop data, and a 32-byte HMAC over the entire packet.
|
||||
const OnionPacketSize = 1366
|
||||
|
||||
type (
|
||||
// BlindingPointTlvType is the type for ephemeral pubkeys used in
|
||||
// route blinding.
|
||||
BlindingPointTlvType = tlv.TlvType0
|
||||
|
||||
// BlindingPointRecord holds an optional blinding point on update add
|
||||
// htlc.
|
||||
//nolint:lll
|
||||
BlindingPointRecord = tlv.OptionalRecordT[BlindingPointTlvType, *btcec.PublicKey]
|
||||
)
|
||||
|
||||
// UpdateAddHTLC is the message sent by Alice to Bob when she wishes to add an
|
||||
// HTLC to his remote commitment transaction. In addition to information
|
||||
// detailing the value, the ID, expiry, and the onion blob is also included
|
||||
@@ -54,6 +68,10 @@ type UpdateAddHTLC struct {
|
||||
// used in the subsequent UpdateAddHTLC message.
|
||||
OnionBlob [OnionPacketSize]byte
|
||||
|
||||
// BlindingPoint is the ephemeral pubkey used to optionally blind the
|
||||
// next hop for this htlc.
|
||||
BlindingPoint BlindingPointRecord
|
||||
|
||||
// ExtraData is the set of data that was appended to this message to
|
||||
// fill out the full maximum transport message size. These fields can
|
||||
// be used to specify optional data such as custom TLV fields.
|
||||
@@ -74,7 +92,7 @@ var _ Message = (*UpdateAddHTLC)(nil)
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *UpdateAddHTLC) Decode(r io.Reader, pver uint32) error {
|
||||
return ReadElements(r,
|
||||
if err := ReadElements(r,
|
||||
&c.ChanID,
|
||||
&c.ID,
|
||||
&c.Amount,
|
||||
@@ -82,7 +100,27 @@ func (c *UpdateAddHTLC) Decode(r io.Reader, pver uint32) error {
|
||||
&c.Expiry,
|
||||
c.OnionBlob[:],
|
||||
&c.ExtraData,
|
||||
)
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
blindingRecord := c.BlindingPoint.Zero()
|
||||
tlvMap, err := c.ExtraData.ExtractRecords(&blindingRecord)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if val, ok := tlvMap[c.BlindingPoint.TlvType()]; ok && val == nil {
|
||||
c.BlindingPoint = tlv.SomeRecordT(blindingRecord)
|
||||
}
|
||||
|
||||
// Set extra data to nil if we didn't parse anything out of it so that
|
||||
// we can use assert.Equal in tests.
|
||||
if len(tlvMap) == 0 {
|
||||
c.ExtraData = nil
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Encode serializes the target UpdateAddHTLC into the passed io.Writer
|
||||
@@ -114,6 +152,20 @@ func (c *UpdateAddHTLC) Encode(w *bytes.Buffer, pver uint32) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Only include blinding point in extra data if present.
|
||||
var records []tlv.RecordProducer
|
||||
|
||||
c.BlindingPoint.WhenSome(func(b tlv.RecordT[BlindingPointTlvType,
|
||||
*btcec.PublicKey]) {
|
||||
|
||||
records = append(records, &b)
|
||||
})
|
||||
|
||||
err := EncodeMessageExtraData(&c.ExtraData, records...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return WriteBytes(w, c.ExtraData)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user