Skip to content

Commit

Permalink
htlcswitch+invoices: record payment metadata [TO BE REMOVED]
Browse files Browse the repository at this point in the history
  • Loading branch information
joostjager committed Jan 19, 2022
1 parent 04a129c commit 2ae37a0
Show file tree
Hide file tree
Showing 7 changed files with 1,053 additions and 1,004 deletions.
23 changes: 23 additions & 0 deletions channeldb/invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ const (
htlcAMPType tlv.Type = 19
htlcHashType tlv.Type = 21
htlcPreimageType tlv.Type = 23
metadataType tlv.Type = 25

// A set of tlv type definitions used to serialize invoice bodiees.
//
Expand Down Expand Up @@ -701,6 +702,10 @@ type InvoiceHTLC struct {
//
// NOTE: This value will only be set for AMP HTLCs.
AMP *InvoiceHtlcAMPData

// Metadata is additional data that is sent along with the payment to
// the payee.
Metadata []byte
}

// Copy makes a deep copy of the target InvoiceHTLC.
Expand Down Expand Up @@ -810,6 +815,10 @@ type HtlcAcceptDesc struct {
//
// NOTE: This value will only be set for AMP HTLCs.
AMP *InvoiceHtlcAMPData

// Metadata is additional data that is sent along with the payment to
// the payee.
Metadata []byte
}

// InvoiceUpdateDesc describes the changes that should be applied to the
Expand Down Expand Up @@ -1724,6 +1733,13 @@ func serializeHtlcs(w io.Writer, htlcs map[CircuitKey]*InvoiceHTLC) error {
}
}

if len(htlc.Metadata) > 0 {
records = append(
records,
tlv.MakePrimitiveRecord(metadataType, &htlc.Metadata),
)
}

// Convert the custom records to tlv.Record types that are ready
// for serialization.
customRecords := tlv.MapToRecords(htlc.CustomRecords)
Expand Down Expand Up @@ -2341,6 +2357,7 @@ func deserializeHtlcs(r io.Reader) (map[CircuitKey]*InvoiceHTLC, error) {
amp = &record.AMP{}
hash32 = &[32]byte{}
preimage32 = &[32]byte{}
metadata = &[]byte{}
)
tlvStream, err := tlv.NewStream(
tlv.MakePrimitiveRecord(chanIDType, &chanID),
Expand All @@ -2360,6 +2377,7 @@ func deserializeHtlcs(r io.Reader) (map[CircuitKey]*InvoiceHTLC, error) {
),
tlv.MakePrimitiveRecord(htlcHashType, hash32),
tlv.MakePrimitiveRecord(htlcPreimageType, preimage32),
tlv.MakePrimitiveRecord(metadataType, metadata),
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -2404,6 +2422,10 @@ func deserializeHtlcs(r io.Reader) (map[CircuitKey]*InvoiceHTLC, error) {
// map return from the tlv parser.
htlc.CustomRecords = hop.NewCustomRecords(parsedTypes)

if len(*metadata) > 0 {
htlc.Metadata = *metadata
}

htlcs[key] = &htlc
}

Expand Down Expand Up @@ -2704,6 +2726,7 @@ func (d *DB) updateInvoice(hash *lntypes.Hash, refSetID *SetID, invoices,
State: HtlcStateAccepted,
CustomRecords: htlcUpdate.CustomRecords,
AMP: htlcUpdate.AMP.Copy(),
Metadata: htlcUpdate.Metadata,
}

invoice.Htlcs[key] = htlc
Expand Down
1 change: 1 addition & 0 deletions invoices/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func updateMpp(ctx *invoiceUpdateCtx,
AcceptHeight: ctx.currentHeight,
MppTotalAmt: ctx.mpp.TotalMsat(),
CustomRecords: ctx.customRecords,
Metadata: ctx.metadata,
}

if ctx.amp != nil {
Expand Down
5 changes: 5 additions & 0 deletions lnrpc/invoicesrpc/invoices.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,11 @@
"amp": {
"$ref": "#/definitions/lnrpcAMP",
"description": "Details relevant to AMP HTLCs, only populated if this is an AMP HTLC."
},
"metadata": {
"type": "string",
"format": "byte",
"description": "The payment metadata to send along with the payment to the payee."
}
},
"title": "Details of an HTLC that paid to an invoice"
Expand Down
1 change: 1 addition & 0 deletions lnrpc/invoicesrpc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func CreateRPCInvoice(invoice *channeldb.Invoice,
State: state,
CustomRecords: htlc.CustomRecords,
MppTotalAmtMsat: uint64(htlc.MppTotalAmt),
Metadata: htlc.Metadata,
}

// Populate any fields relevant to AMP payments.
Expand Down
Loading

0 comments on commit 2ae37a0

Please sign in to comment.