lnrpc: add wire records fields to SendPayment & HtlcInterceptor

This commit is contained in:
George Tsagkarelis 2024-04-16 11:03:59 +02:00 committed by Oliver Gugger
parent 25b4066b17
commit a5fcf33082
No known key found for this signature in database
GPG key ID: 8E4256593F177720
6 changed files with 760 additions and 668 deletions

View file

@ -410,10 +410,10 @@ func testForwardInterceptorModifiedHtlc(ht *lntest.HarnessTest) {
newOutgoingAmountMsat := packet.OutgoingAmountMsat + 4000 newOutgoingAmountMsat := packet.OutgoingAmountMsat + 4000
err := bobInterceptor.Send(&routerrpc.ForwardHtlcInterceptResponse{ err := bobInterceptor.Send(&routerrpc.ForwardHtlcInterceptResponse{
IncomingCircuitKey: packet.IncomingCircuitKey, IncomingCircuitKey: packet.IncomingCircuitKey,
OutgoingAmountMsat: newOutgoingAmountMsat, OutgoingAmountMsat: newOutgoingAmountMsat,
CustomRecords: customRecords, OutgoingHtlcWireCustomRecords: customRecords,
Action: action, Action: action,
}) })
require.NoError(ht, err, "failed to send request") require.NoError(ht, err, "failed to send request")

View file

@ -84,15 +84,16 @@ func (r *forwardInterceptor) onIntercept(
ChanId: inKey.ChanID.ToUint64(), ChanId: inKey.ChanID.ToUint64(),
HtlcId: inKey.HtlcID, HtlcId: inKey.HtlcID,
}, },
OutgoingRequestedChanId: htlc.OutgoingChanID.ToUint64(), OutgoingRequestedChanId: htlc.OutgoingChanID.ToUint64(),
PaymentHash: htlc.Hash[:], PaymentHash: htlc.Hash[:],
OutgoingAmountMsat: uint64(htlc.OutgoingAmount), OutgoingAmountMsat: uint64(htlc.OutgoingAmount),
OutgoingExpiry: htlc.OutgoingExpiry, OutgoingExpiry: htlc.OutgoingExpiry,
IncomingAmountMsat: uint64(htlc.IncomingAmount), IncomingAmountMsat: uint64(htlc.IncomingAmount),
IncomingExpiry: htlc.IncomingExpiry, IncomingExpiry: htlc.IncomingExpiry,
CustomRecords: htlc.CustomRecords, CustomRecords: htlc.CustomRecords,
OnionBlob: htlc.OnionBlob[:], OnionBlob: htlc.OnionBlob[:],
AutoFailHeight: htlc.AutoFailHeight, AutoFailHeight: htlc.AutoFailHeight,
IncomingHtlcWireCustomRecords: htlc.IncomingWireCustomRecords,
} }
return r.stream.Send(interceptionRequest) return r.stream.Send(interceptionRequest)
@ -138,9 +139,9 @@ func (r *forwardInterceptor) resolveFromClient(
} }
customRecords := fn.None[record.CustomSet]() customRecords := fn.None[record.CustomSet]()
if len(in.CustomRecords) > 0 { if len(in.OutgoingHtlcWireCustomRecords) > 0 {
// Validate custom records. // Validate custom records.
cr := record.CustomSet(in.CustomRecords) cr := record.CustomSet(in.OutgoingHtlcWireCustomRecords)
if err := cr.Validate(); err != nil { if err := cr.Validate(); err != nil {
return status.Errorf( return status.Errorf(
codes.InvalidArgument, codes.InvalidArgument,

File diff suppressed because it is too large Load diff

View file

@ -347,6 +347,15 @@ message SendPaymentRequest {
only, to 1 to optimize for reliability only or a value inbetween for a mix. only, to 1 to optimize for reliability only or a value inbetween for a mix.
*/ */
double time_pref = 23; double time_pref = 23;
/*
An optional field that can be used to pass an arbitrary set of TLV records
to the first hop peer of this payment. This can be used to pass application
specific data during the payment attempt. Record types are required to be in
the custom range >= 65536. When using REST, the values must be encoded as
base64.
*/
map<uint64, bytes> first_hop_custom_records = 24;
} }
message TrackPaymentRequest { message TrackPaymentRequest {
@ -971,6 +980,9 @@ message ForwardHtlcInterceptRequest {
// The block height at which this htlc will be auto-failed to prevent the // The block height at which this htlc will be auto-failed to prevent the
// channel from force-closing. // channel from force-closing.
int32 auto_fail_height = 10; int32 auto_fail_height = 10;
// The custom records of the peer's incoming wire message.
map<uint64, bytes> incoming_htlc_wire_custom_records = 11;
} }
/** /**
@ -1018,9 +1030,9 @@ message ForwardHtlcInterceptResponse {
// for resuming a HTLC. // for resuming a HTLC.
uint64 outgoing_amount_msat = 7; uint64 outgoing_amount_msat = 7;
// custom_records is used to set the p2p message custom records field for // Outgoing htlc wire custom records is used to set the p2p message custom
// resuming a HTLC. // records field for resuming a HTLC.
map<uint64, bytes> custom_records = 8; map<uint64, bytes> outgoing_htlc_wire_custom_records = 8;
} }
enum ResolveHoldForwardAction { enum ResolveHoldForwardAction {

View file

@ -1444,6 +1444,14 @@
"type": "integer", "type": "integer",
"format": "int32", "format": "int32",
"description": "The block height at which this htlc will be auto-failed to prevent the\nchannel from force-closing." "description": "The block height at which this htlc will be auto-failed to prevent the\nchannel from force-closing."
},
"incoming_htlc_wire_custom_records": {
"type": "object",
"additionalProperties": {
"type": "string",
"format": "byte"
},
"description": "The custom records of the peer's incoming wire message."
} }
} }
}, },
@ -1482,13 +1490,13 @@
"format": "uint64", "format": "uint64",
"description": "outgoing_amount_msat is used to set the p2p message outgoing amount field\nfor resuming a HTLC." "description": "outgoing_amount_msat is used to set the p2p message outgoing amount field\nfor resuming a HTLC."
}, },
"custom_records": { "outgoing_htlc_wire_custom_records": {
"type": "object", "type": "object",
"additionalProperties": { "additionalProperties": {
"type": "string", "type": "string",
"format": "byte" "format": "byte"
}, },
"description": "custom_records is used to set the p2p message custom records field for\nresuming a HTLC." "description": "Outgoing htlc wire custom records is used to set the p2p message custom\nrecords field for resuming a HTLC."
} }
}, },
"description": "*\nForwardHtlcInterceptResponse enables the caller to resolve a previously hold\nforward. The caller can choose either to:\n- `Resume`: Execute the default behavior (usually forward).\n- `ResumeModified`: Execute the default behavior (usually forward) with HTLC\nfield modifications.\n- `Reject`: Fail the htlc backwards.\n- `Settle`: Settle this htlc with a given preimage." "description": "*\nForwardHtlcInterceptResponse enables the caller to resolve a previously hold\nforward. The caller can choose either to:\n- `Resume`: Execute the default behavior (usually forward).\n- `ResumeModified`: Execute the default behavior (usually forward) with HTLC\nfield modifications.\n- `Reject`: Fail the htlc backwards.\n- `Settle`: Settle this htlc with a given preimage."
@ -1950,6 +1958,14 @@
"type": "number", "type": "number",
"format": "double", "format": "double",
"description": "The time preference for this payment. Set to -1 to optimize for fees\nonly, to 1 to optimize for reliability only or a value inbetween for a mix." "description": "The time preference for this payment. Set to -1 to optimize for fees\nonly, to 1 to optimize for reliability only or a value inbetween for a mix."
},
"first_hop_custom_records": {
"type": "object",
"additionalProperties": {
"type": "string",
"format": "byte"
},
"description": "An optional field that can be used to pass an arbitrary set of TLV records\nto the first hop peer of this payment. This can be used to pass application\nspecific data during the payment attempt. Record types are required to be in\nthe custom range \u003e= 65536. When using REST, the values must be encoded as\nbase64."
} }
} }
}, },

View file

@ -858,6 +858,12 @@ func (r *RouterBackend) extractIntentFromSendRequest(
} }
payIntent.DestCustomRecords = customRecords payIntent.DestCustomRecords = customRecords
firstHopRecords := record.CustomSet(rpcPayReq.FirstHopCustomRecords)
if err := firstHopRecords.Validate(); err != nil {
return nil, err
}
payIntent.FirstHopCustomRecords = firstHopRecords
payIntent.PayAttemptTimeout = time.Second * payIntent.PayAttemptTimeout = time.Second *
time.Duration(rpcPayReq.TimeoutSeconds) time.Duration(rpcPayReq.TimeoutSeconds)