mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-23 06:35:07 +01:00
lnrpc: add wire records fields to SendPayment & HtlcInterceptor
This commit is contained in:
parent
25b4066b17
commit
a5fcf33082
6 changed files with 760 additions and 668 deletions
|
@ -410,10 +410,10 @@ func testForwardInterceptorModifiedHtlc(ht *lntest.HarnessTest) {
|
|||
newOutgoingAmountMsat := packet.OutgoingAmountMsat + 4000
|
||||
|
||||
err := bobInterceptor.Send(&routerrpc.ForwardHtlcInterceptResponse{
|
||||
IncomingCircuitKey: packet.IncomingCircuitKey,
|
||||
OutgoingAmountMsat: newOutgoingAmountMsat,
|
||||
CustomRecords: customRecords,
|
||||
Action: action,
|
||||
IncomingCircuitKey: packet.IncomingCircuitKey,
|
||||
OutgoingAmountMsat: newOutgoingAmountMsat,
|
||||
OutgoingHtlcWireCustomRecords: customRecords,
|
||||
Action: action,
|
||||
})
|
||||
require.NoError(ht, err, "failed to send request")
|
||||
|
||||
|
|
|
@ -84,15 +84,16 @@ func (r *forwardInterceptor) onIntercept(
|
|||
ChanId: inKey.ChanID.ToUint64(),
|
||||
HtlcId: inKey.HtlcID,
|
||||
},
|
||||
OutgoingRequestedChanId: htlc.OutgoingChanID.ToUint64(),
|
||||
PaymentHash: htlc.Hash[:],
|
||||
OutgoingAmountMsat: uint64(htlc.OutgoingAmount),
|
||||
OutgoingExpiry: htlc.OutgoingExpiry,
|
||||
IncomingAmountMsat: uint64(htlc.IncomingAmount),
|
||||
IncomingExpiry: htlc.IncomingExpiry,
|
||||
CustomRecords: htlc.CustomRecords,
|
||||
OnionBlob: htlc.OnionBlob[:],
|
||||
AutoFailHeight: htlc.AutoFailHeight,
|
||||
OutgoingRequestedChanId: htlc.OutgoingChanID.ToUint64(),
|
||||
PaymentHash: htlc.Hash[:],
|
||||
OutgoingAmountMsat: uint64(htlc.OutgoingAmount),
|
||||
OutgoingExpiry: htlc.OutgoingExpiry,
|
||||
IncomingAmountMsat: uint64(htlc.IncomingAmount),
|
||||
IncomingExpiry: htlc.IncomingExpiry,
|
||||
CustomRecords: htlc.CustomRecords,
|
||||
OnionBlob: htlc.OnionBlob[:],
|
||||
AutoFailHeight: htlc.AutoFailHeight,
|
||||
IncomingHtlcWireCustomRecords: htlc.IncomingWireCustomRecords,
|
||||
}
|
||||
|
||||
return r.stream.Send(interceptionRequest)
|
||||
|
@ -138,9 +139,9 @@ func (r *forwardInterceptor) resolveFromClient(
|
|||
}
|
||||
|
||||
customRecords := fn.None[record.CustomSet]()
|
||||
if len(in.CustomRecords) > 0 {
|
||||
if len(in.OutgoingHtlcWireCustomRecords) > 0 {
|
||||
// Validate custom records.
|
||||
cr := record.CustomSet(in.CustomRecords)
|
||||
cr := record.CustomSet(in.OutgoingHtlcWireCustomRecords)
|
||||
if err := cr.Validate(); err != nil {
|
||||
return status.Errorf(
|
||||
codes.InvalidArgument,
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -347,6 +347,15 @@ message SendPaymentRequest {
|
|||
only, to 1 to optimize for reliability only or a value inbetween for a mix.
|
||||
*/
|
||||
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 {
|
||||
|
@ -971,6 +980,9 @@ message ForwardHtlcInterceptRequest {
|
|||
// The block height at which this htlc will be auto-failed to prevent the
|
||||
// channel from force-closing.
|
||||
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.
|
||||
uint64 outgoing_amount_msat = 7;
|
||||
|
||||
// custom_records is used to set the p2p message custom records field for
|
||||
// resuming a HTLC.
|
||||
map<uint64, bytes> custom_records = 8;
|
||||
// Outgoing htlc wire custom records is used to set the p2p message custom
|
||||
// records field for resuming a HTLC.
|
||||
map<uint64, bytes> outgoing_htlc_wire_custom_records = 8;
|
||||
}
|
||||
|
||||
enum ResolveHoldForwardAction {
|
||||
|
|
|
@ -1444,6 +1444,14 @@
|
|||
"type": "integer",
|
||||
"format": "int32",
|
||||
"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",
|
||||
"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",
|
||||
"additionalProperties": {
|
||||
"type": "string",
|
||||
"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."
|
||||
|
@ -1950,6 +1958,14 @@
|
|||
"type": "number",
|
||||
"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."
|
||||
},
|
||||
"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."
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -858,6 +858,12 @@ func (r *RouterBackend) extractIntentFromSendRequest(
|
|||
}
|
||||
payIntent.DestCustomRecords = customRecords
|
||||
|
||||
firstHopRecords := record.CustomSet(rpcPayReq.FirstHopCustomRecords)
|
||||
if err := firstHopRecords.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
payIntent.FirstHopCustomRecords = firstHopRecords
|
||||
|
||||
payIntent.PayAttemptTimeout = time.Second *
|
||||
time.Duration(rpcPayReq.TimeoutSeconds)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue