invoicesrpc: add HtlcModifier RPC endpoint and modifier RPC server

This commit introduces a singleton invoice HTLC modifier RPC server and
an endpoint to activate it. The server interfaces with the internal
invoice HTLC modifier interpreter, handling the marshalling between RPC
types and internal formats.
This commit is contained in:
ffranr 2024-04-23 14:58:29 +01:00 committed by Oliver Gugger
parent 73f52c8b11
commit 2580661acb
No known key found for this signature in database
GPG key ID: 8E4256593F177720
11 changed files with 2162 additions and 1342 deletions

View file

@ -0,0 +1,110 @@
package invoicesrpc
import (
"fmt"
"github.com/btcsuite/btcd/chaincfg"
"github.com/lightningnetwork/lnd/invoices"
"github.com/lightningnetwork/lnd/lnwire"
)
// htlcModifierConfig contains the configuration for an RPC invoice HTLC
// modifier server.
type htlcModifierConfig struct {
// chainParams is required to properly marshall an invoice for RPC.
chainParams *chaincfg.Params
// serverStream is a bidirectional RPC server stream to send invoices to
// a client and receive accept responses from the client.
serverStream Invoices_HtlcModifierServer
// modificationInterceptor is the HTLC modification interceptor that
// will be used to intercept and resolve invoice HTLCs.
modificationInterceptor invoices.HtlcModifier
}
// htlcModifier is a helper struct that handles the lifecycle of an RPC invoice
// HTLC modifier server instance.
//
// This struct handles passing send and receive RPC messages between the client
// and the invoice service.
type htlcModifier struct {
// cfg contains the configuration for the invoice HTLC modifier.
cfg htlcModifierConfig
}
// newHtlcModifier creates a new RPC invoice HTLC modifier handler.
func newHtlcModifier(cfg htlcModifierConfig) *htlcModifier {
return &htlcModifier{
cfg: cfg,
}
}
// run sends the intercepted invoice HTLCs to the client and receives the
// corresponding responses.
func (r *htlcModifier) run() error {
// Register our invoice modifier.
r.cfg.modificationInterceptor.SetClientCallback(r.onIntercept)
defer r.cfg.modificationInterceptor.SetClientCallback(nil)
// Listen for a response from the client in a loop.
for {
resp, err := r.cfg.serverStream.Recv()
if err != nil {
return err
}
log.Tracef("Received invoice HTLC modifier response %v", resp)
if err := r.resolveFromClient(resp); err != nil {
return err
}
}
}
// onIntercept is called when an invoice HTLC is intercepted by the invoice HTLC
// modifier. This method sends the invoice and the current HTLC to the client.
func (r *htlcModifier) onIntercept(req invoices.HtlcModifyRequest) error {
// Convert the circuit key to an RPC circuit key.
rpcCircuitKey := &CircuitKey{
ChanId: req.ExitHtlcCircuitKey.ChanID.ToUint64(),
HtlcId: req.ExitHtlcCircuitKey.HtlcID,
}
// Convert the invoice to an RPC invoice.
rpcInvoice, err := CreateRPCInvoice(&req.Invoice, r.cfg.chainParams)
if err != nil {
return err
}
return r.cfg.serverStream.Send(&HtlcModifyRequest{
Invoice: rpcInvoice,
ExitHtlcCircuitKey: rpcCircuitKey,
ExitHtlcAmt: uint64(req.ExitHtlcAmt),
ExitHtlcExpiry: req.ExitHtlcExpiry,
CurrentHeight: req.CurrentHeight,
ExitHtlcWireCustomRecords: req.WireCustomRecords,
})
}
// resolveFromClient handles an invoice HTLC modification received from the
// client.
func (r *htlcModifier) resolveFromClient(
in *HtlcModifyResponse) error {
log.Tracef("Resolving invoice HTLC modifier response %v", in)
if in.CircuitKey == nil {
return fmt.Errorf("missing circuit key")
}
circuitKey := invoices.CircuitKey{
ChanID: lnwire.NewShortChanIDFromInt(in.CircuitKey.ChanId),
HtlcID: in.CircuitKey.HtlcId,
}
// Pass the resolution to the modifier.
return r.cfg.modificationInterceptor.Modify(
circuitKey, lnwire.MilliSatoshi(in.AmtPaid),
)
}

View file

@ -617,6 +617,219 @@ func (*LookupInvoiceMsg_PaymentAddr) isLookupInvoiceMsg_InvoiceRef() {}
func (*LookupInvoiceMsg_SetId) isLookupInvoiceMsg_InvoiceRef() {} func (*LookupInvoiceMsg_SetId) isLookupInvoiceMsg_InvoiceRef() {}
// CircuitKey is a unique identifier for an HTLC.
type CircuitKey struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// / The id of the channel that the is part of this circuit.
ChanId uint64 `protobuf:"varint,1,opt,name=chan_id,json=chanId,proto3" json:"chan_id,omitempty"`
// / The index of the incoming htlc in the incoming channel.
HtlcId uint64 `protobuf:"varint,2,opt,name=htlc_id,json=htlcId,proto3" json:"htlc_id,omitempty"`
}
func (x *CircuitKey) Reset() {
*x = CircuitKey{}
if protoimpl.UnsafeEnabled {
mi := &file_invoicesrpc_invoices_proto_msgTypes[8]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *CircuitKey) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*CircuitKey) ProtoMessage() {}
func (x *CircuitKey) ProtoReflect() protoreflect.Message {
mi := &file_invoicesrpc_invoices_proto_msgTypes[8]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use CircuitKey.ProtoReflect.Descriptor instead.
func (*CircuitKey) Descriptor() ([]byte, []int) {
return file_invoicesrpc_invoices_proto_rawDescGZIP(), []int{8}
}
func (x *CircuitKey) GetChanId() uint64 {
if x != nil {
return x.ChanId
}
return 0
}
func (x *CircuitKey) GetHtlcId() uint64 {
if x != nil {
return x.HtlcId
}
return 0
}
type HtlcModifyRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// The invoice the intercepted HTLC is attempting to settle. The HTLCs in
// the invoice are only HTLCs that have already been accepted or settled,
// not including the current intercepted HTLC.
Invoice *lnrpc.Invoice `protobuf:"bytes,1,opt,name=invoice,proto3" json:"invoice,omitempty"`
// The unique identifier of the HTLC of this intercepted HTLC.
ExitHtlcCircuitKey *CircuitKey `protobuf:"bytes,2,opt,name=exit_htlc_circuit_key,json=exitHtlcCircuitKey,proto3" json:"exit_htlc_circuit_key,omitempty"`
// The amount in milli-satoshi that the exit HTLC is attempting to pay.
ExitHtlcAmt uint64 `protobuf:"varint,3,opt,name=exit_htlc_amt,json=exitHtlcAmt,proto3" json:"exit_htlc_amt,omitempty"`
// The absolute expiry height of the exit HTLC.
ExitHtlcExpiry uint32 `protobuf:"varint,4,opt,name=exit_htlc_expiry,json=exitHtlcExpiry,proto3" json:"exit_htlc_expiry,omitempty"`
// The current block height.
CurrentHeight uint32 `protobuf:"varint,5,opt,name=current_height,json=currentHeight,proto3" json:"current_height,omitempty"`
// The wire message custom records of the exit HTLC.
ExitHtlcWireCustomRecords map[uint64][]byte `protobuf:"bytes,6,rep,name=exit_htlc_wire_custom_records,json=exitHtlcWireCustomRecords,proto3" json:"exit_htlc_wire_custom_records,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
}
func (x *HtlcModifyRequest) Reset() {
*x = HtlcModifyRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_invoicesrpc_invoices_proto_msgTypes[9]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *HtlcModifyRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*HtlcModifyRequest) ProtoMessage() {}
func (x *HtlcModifyRequest) ProtoReflect() protoreflect.Message {
mi := &file_invoicesrpc_invoices_proto_msgTypes[9]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use HtlcModifyRequest.ProtoReflect.Descriptor instead.
func (*HtlcModifyRequest) Descriptor() ([]byte, []int) {
return file_invoicesrpc_invoices_proto_rawDescGZIP(), []int{9}
}
func (x *HtlcModifyRequest) GetInvoice() *lnrpc.Invoice {
if x != nil {
return x.Invoice
}
return nil
}
func (x *HtlcModifyRequest) GetExitHtlcCircuitKey() *CircuitKey {
if x != nil {
return x.ExitHtlcCircuitKey
}
return nil
}
func (x *HtlcModifyRequest) GetExitHtlcAmt() uint64 {
if x != nil {
return x.ExitHtlcAmt
}
return 0
}
func (x *HtlcModifyRequest) GetExitHtlcExpiry() uint32 {
if x != nil {
return x.ExitHtlcExpiry
}
return 0
}
func (x *HtlcModifyRequest) GetCurrentHeight() uint32 {
if x != nil {
return x.CurrentHeight
}
return 0
}
func (x *HtlcModifyRequest) GetExitHtlcWireCustomRecords() map[uint64][]byte {
if x != nil {
return x.ExitHtlcWireCustomRecords
}
return nil
}
type HtlcModifyResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// The circuit key of the HTLC that the client wants to modify.
CircuitKey *CircuitKey `protobuf:"bytes,1,opt,name=circuit_key,json=circuitKey,proto3" json:"circuit_key,omitempty"`
// The modified amount in milli-satoshi that the exit HTLC is paying. This
// value can be different from the actual on-chain HTLC amount, in case the
// HTLC carries other valuable items, as can be the case with custom channel
// types. In order to not modify this value, the client should set it zero.
AmtPaid uint64 `protobuf:"varint,2,opt,name=amt_paid,json=amtPaid,proto3" json:"amt_paid,omitempty"`
}
func (x *HtlcModifyResponse) Reset() {
*x = HtlcModifyResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_invoicesrpc_invoices_proto_msgTypes[10]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *HtlcModifyResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*HtlcModifyResponse) ProtoMessage() {}
func (x *HtlcModifyResponse) ProtoReflect() protoreflect.Message {
mi := &file_invoicesrpc_invoices_proto_msgTypes[10]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use HtlcModifyResponse.ProtoReflect.Descriptor instead.
func (*HtlcModifyResponse) Descriptor() ([]byte, []int) {
return file_invoicesrpc_invoices_proto_rawDescGZIP(), []int{10}
}
func (x *HtlcModifyResponse) GetCircuitKey() *CircuitKey {
if x != nil {
return x.CircuitKey
}
return nil
}
func (x *HtlcModifyResponse) GetAmtPaid() uint64 {
if x != nil {
return x.AmtPaid
}
return 0
}
var File_invoicesrpc_invoices_proto protoreflect.FileDescriptor var File_invoicesrpc_invoices_proto protoreflect.FileDescriptor
var file_invoicesrpc_invoices_proto_rawDesc = []byte{ var file_invoicesrpc_invoices_proto_rawDesc = []byte{
@ -678,37 +891,82 @@ var file_invoicesrpc_invoices_proto_rawDesc = []byte{
0x73, 0x72, 0x70, 0x63, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x73, 0x72, 0x70, 0x63, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x4d, 0x6f, 0x64, 0x69, 0x66,
0x69, 0x65, 0x72, 0x52, 0x0e, 0x6c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65, 0x72, 0x52, 0x0e, 0x6c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x4d, 0x6f, 0x64, 0x69, 0x66,
0x69, 0x65, 0x72, 0x42, 0x0d, 0x0a, 0x0b, 0x69, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x5f, 0x72, 0x69, 0x65, 0x72, 0x42, 0x0d, 0x0a, 0x0b, 0x69, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x5f, 0x72,
0x65, 0x66, 0x2a, 0x44, 0x0a, 0x0e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x4d, 0x6f, 0x64, 0x69, 0x65, 0x66, 0x22, 0x3e, 0x0a, 0x0a, 0x43, 0x69, 0x72, 0x63, 0x75, 0x69, 0x74, 0x4b, 0x65, 0x79,
0x66, 0x69, 0x65, 0x72, 0x12, 0x0b, 0x0a, 0x07, 0x44, 0x45, 0x46, 0x41, 0x55, 0x4c, 0x54, 0x10, 0x12, 0x17, 0x0a, 0x07, 0x63, 0x68, 0x61, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
0x00, 0x12, 0x11, 0x0a, 0x0d, 0x48, 0x54, 0x4c, 0x43, 0x5f, 0x53, 0x45, 0x54, 0x5f, 0x4f, 0x4e, 0x04, 0x52, 0x06, 0x63, 0x68, 0x61, 0x6e, 0x49, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x68, 0x74, 0x6c,
0x4c, 0x59, 0x10, 0x01, 0x12, 0x12, 0x0a, 0x0e, 0x48, 0x54, 0x4c, 0x43, 0x5f, 0x53, 0x45, 0x54, 0x63, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x68, 0x74, 0x6c, 0x63,
0x5f, 0x42, 0x4c, 0x41, 0x4e, 0x4b, 0x10, 0x02, 0x32, 0x9b, 0x03, 0x0a, 0x08, 0x49, 0x6e, 0x76, 0x49, 0x64, 0x22, 0xcd, 0x03, 0x0a, 0x11, 0x48, 0x74, 0x6c, 0x63, 0x4d, 0x6f, 0x64, 0x69, 0x66,
0x6f, 0x69, 0x63, 0x65, 0x73, 0x12, 0x56, 0x0a, 0x16, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x28, 0x0a, 0x07, 0x69, 0x6e, 0x76, 0x6f,
0x62, 0x65, 0x53, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x12, 0x69, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x6c, 0x6e, 0x72, 0x70,
0x2a, 0x2e, 0x69, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x73, 0x72, 0x70, 0x63, 0x2e, 0x53, 0x75, 0x63, 0x2e, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x52, 0x07, 0x69, 0x6e, 0x76, 0x6f, 0x69,
0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x53, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x49, 0x6e, 0x76, 0x63, 0x65, 0x12, 0x4a, 0x0a, 0x15, 0x65, 0x78, 0x69, 0x74, 0x5f, 0x68, 0x74, 0x6c, 0x63, 0x5f,
0x6f, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0e, 0x2e, 0x6c, 0x6e, 0x63, 0x69, 0x72, 0x63, 0x75, 0x69, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28,
0x72, 0x70, 0x63, 0x2e, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x30, 0x01, 0x12, 0x4e, 0x0a, 0x0b, 0x32, 0x17, 0x2e, 0x69, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x73, 0x72, 0x70, 0x63, 0x2e,
0x0d, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x12, 0x1d, 0x43, 0x69, 0x72, 0x63, 0x75, 0x69, 0x74, 0x4b, 0x65, 0x79, 0x52, 0x12, 0x65, 0x78, 0x69, 0x74,
0x2e, 0x69, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x73, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x61, 0x6e, 0x48, 0x74, 0x6c, 0x63, 0x43, 0x69, 0x72, 0x63, 0x75, 0x69, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x22,
0x63, 0x65, 0x6c, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x4d, 0x73, 0x67, 0x1a, 0x1e, 0x2e, 0x0a, 0x0d, 0x65, 0x78, 0x69, 0x74, 0x5f, 0x68, 0x74, 0x6c, 0x63, 0x5f, 0x61, 0x6d, 0x74, 0x18,
0x69, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x73, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x61, 0x6e, 0x63, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x65, 0x78, 0x69, 0x74, 0x48, 0x74, 0x6c, 0x63, 0x41,
0x65, 0x6c, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x55, 0x0a, 0x6d, 0x74, 0x12, 0x28, 0x0a, 0x10, 0x65, 0x78, 0x69, 0x74, 0x5f, 0x68, 0x74, 0x6c, 0x63, 0x5f,
0x0e, 0x41, 0x64, 0x64, 0x48, 0x6f, 0x6c, 0x64, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x12, 0x65, 0x78, 0x70, 0x69, 0x72, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0e, 0x65, 0x78,
0x22, 0x2e, 0x69, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x73, 0x72, 0x70, 0x63, 0x2e, 0x41, 0x64, 0x69, 0x74, 0x48, 0x74, 0x6c, 0x63, 0x45, 0x78, 0x70, 0x69, 0x72, 0x79, 0x12, 0x25, 0x0a, 0x0e,
0x64, 0x48, 0x6f, 0x6c, 0x64, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x05,
0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x69, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x73, 0x72, 0x70, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0d, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x48, 0x65, 0x69,
0x63, 0x2e, 0x41, 0x64, 0x64, 0x48, 0x6f, 0x6c, 0x64, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x67, 0x68, 0x74, 0x12, 0x7f, 0x0a, 0x1d, 0x65, 0x78, 0x69, 0x74, 0x5f, 0x68, 0x74, 0x6c, 0x63,
0x52, 0x65, 0x73, 0x70, 0x12, 0x4e, 0x0a, 0x0d, 0x53, 0x65, 0x74, 0x74, 0x6c, 0x65, 0x49, 0x6e, 0x5f, 0x77, 0x69, 0x72, 0x65, 0x5f, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x5f, 0x72, 0x65, 0x63,
0x76, 0x6f, 0x69, 0x63, 0x65, 0x12, 0x1d, 0x2e, 0x69, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x73, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x3d, 0x2e, 0x69, 0x6e, 0x76,
0x72, 0x70, 0x63, 0x2e, 0x53, 0x65, 0x74, 0x74, 0x6c, 0x65, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x6f, 0x69, 0x63, 0x65, 0x73, 0x72, 0x70, 0x63, 0x2e, 0x48, 0x74, 0x6c, 0x63, 0x4d, 0x6f, 0x64,
0x65, 0x4d, 0x73, 0x67, 0x1a, 0x1e, 0x2e, 0x69, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x73, 0x72, 0x69, 0x66, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x45, 0x78, 0x69, 0x74, 0x48,
0x70, 0x63, 0x2e, 0x53, 0x65, 0x74, 0x74, 0x6c, 0x65, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x74, 0x6c, 0x63, 0x57, 0x69, 0x72, 0x65, 0x43, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x52, 0x65, 0x63,
0x52, 0x65, 0x73, 0x70, 0x12, 0x40, 0x0a, 0x0f, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x49, 0x6e, 0x6f, 0x72, 0x64, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x19, 0x65, 0x78, 0x69, 0x74, 0x48,
0x76, 0x6f, 0x69, 0x63, 0x65, 0x56, 0x32, 0x12, 0x1d, 0x2e, 0x69, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x74, 0x6c, 0x63, 0x57, 0x69, 0x72, 0x65, 0x43, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x52, 0x65, 0x63,
0x65, 0x73, 0x72, 0x70, 0x63, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x49, 0x6e, 0x76, 0x6f, 0x6f, 0x72, 0x64, 0x73, 0x1a, 0x4c, 0x0a, 0x1e, 0x45, 0x78, 0x69, 0x74, 0x48, 0x74, 0x6c, 0x63,
0x69, 0x63, 0x65, 0x4d, 0x73, 0x67, 0x1a, 0x0e, 0x2e, 0x6c, 0x6e, 0x72, 0x70, 0x63, 0x2e, 0x49, 0x57, 0x69, 0x72, 0x65, 0x43, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64,
0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x42, 0x33, 0x5a, 0x31, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20,
0x01, 0x28, 0x04, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75,
0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02,
0x38, 0x01, 0x22, 0x69, 0x0a, 0x12, 0x48, 0x74, 0x6c, 0x63, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79,
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x38, 0x0a, 0x0b, 0x63, 0x69, 0x72, 0x63,
0x75, 0x69, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e,
0x69, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x73, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x69, 0x72, 0x63,
0x75, 0x69, 0x74, 0x4b, 0x65, 0x79, 0x52, 0x0a, 0x63, 0x69, 0x72, 0x63, 0x75, 0x69, 0x74, 0x4b,
0x65, 0x79, 0x12, 0x19, 0x0a, 0x08, 0x61, 0x6d, 0x74, 0x5f, 0x70, 0x61, 0x69, 0x64, 0x18, 0x02,
0x20, 0x01, 0x28, 0x04, 0x52, 0x07, 0x61, 0x6d, 0x74, 0x50, 0x61, 0x69, 0x64, 0x2a, 0x44, 0x0a,
0x0e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65, 0x72, 0x12,
0x0b, 0x0a, 0x07, 0x44, 0x45, 0x46, 0x41, 0x55, 0x4c, 0x54, 0x10, 0x00, 0x12, 0x11, 0x0a, 0x0d,
0x48, 0x54, 0x4c, 0x43, 0x5f, 0x53, 0x45, 0x54, 0x5f, 0x4f, 0x4e, 0x4c, 0x59, 0x10, 0x01, 0x12,
0x12, 0x0a, 0x0e, 0x48, 0x54, 0x4c, 0x43, 0x5f, 0x53, 0x45, 0x54, 0x5f, 0x42, 0x4c, 0x41, 0x4e,
0x4b, 0x10, 0x02, 0x32, 0xf0, 0x03, 0x0a, 0x08, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x73,
0x12, 0x56, 0x0a, 0x16, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x53, 0x69, 0x6e,
0x67, 0x6c, 0x65, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x12, 0x2a, 0x2e, 0x69, 0x6e, 0x76,
0x6f, 0x69, 0x63, 0x65, 0x73, 0x72, 0x70, 0x63, 0x2e, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69,
0x62, 0x65, 0x53, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0e, 0x2e, 0x6c, 0x6e, 0x72, 0x70, 0x63, 0x2e, 0x49,
0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x30, 0x01, 0x12, 0x4e, 0x0a, 0x0d, 0x43, 0x61, 0x6e, 0x63,
0x65, 0x6c, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x12, 0x1d, 0x2e, 0x69, 0x6e, 0x76, 0x6f,
0x69, 0x63, 0x65, 0x73, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x49, 0x6e,
0x76, 0x6f, 0x69, 0x63, 0x65, 0x4d, 0x73, 0x67, 0x1a, 0x1e, 0x2e, 0x69, 0x6e, 0x76, 0x6f, 0x69,
0x63, 0x65, 0x73, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x49, 0x6e, 0x76,
0x6f, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x55, 0x0a, 0x0e, 0x41, 0x64, 0x64, 0x48,
0x6f, 0x6c, 0x64, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x12, 0x22, 0x2e, 0x69, 0x6e, 0x76,
0x6f, 0x69, 0x63, 0x65, 0x73, 0x72, 0x70, 0x63, 0x2e, 0x41, 0x64, 0x64, 0x48, 0x6f, 0x6c, 0x64,
0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f,
0x2e, 0x69, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x73, 0x72, 0x70, 0x63, 0x2e, 0x41, 0x64, 0x64,
0x48, 0x6f, 0x6c, 0x64, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12,
0x4e, 0x0a, 0x0d, 0x53, 0x65, 0x74, 0x74, 0x6c, 0x65, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65,
0x12, 0x1d, 0x2e, 0x69, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x73, 0x72, 0x70, 0x63, 0x2e, 0x53,
0x65, 0x74, 0x74, 0x6c, 0x65, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x4d, 0x73, 0x67, 0x1a,
0x1e, 0x2e, 0x69, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x73, 0x72, 0x70, 0x63, 0x2e, 0x53, 0x65,
0x74, 0x74, 0x6c, 0x65, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12,
0x40, 0x0a, 0x0f, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65,
0x56, 0x32, 0x12, 0x1d, 0x2e, 0x69, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x73, 0x72, 0x70, 0x63,
0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x4d, 0x73,
0x67, 0x1a, 0x0e, 0x2e, 0x6c, 0x6e, 0x72, 0x70, 0x63, 0x2e, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63,
0x65, 0x12, 0x53, 0x0a, 0x0c, 0x48, 0x74, 0x6c, 0x63, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65,
0x72, 0x12, 0x1f, 0x2e, 0x69, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x73, 0x72, 0x70, 0x63, 0x2e,
0x48, 0x74, 0x6c, 0x63, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
0x73, 0x65, 0x1a, 0x1e, 0x2e, 0x69, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x73, 0x72, 0x70, 0x63,
0x2e, 0x48, 0x74, 0x6c, 0x63, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x28, 0x01, 0x30, 0x01, 0x42, 0x33, 0x5a, 0x31, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62,
0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x6e, 0x69, 0x6e, 0x67, 0x6e, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x6e, 0x69, 0x6e, 0x67, 0x6e, 0x65,
0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2f, 0x6c, 0x6e, 0x64, 0x2f, 0x6c, 0x6e, 0x72, 0x70, 0x63, 0x2f, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2f, 0x6c, 0x6e, 0x64, 0x2f, 0x6c, 0x6e, 0x72, 0x70, 0x63, 0x2f,
0x69, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x73, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x69, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x73, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f,
@ -728,7 +986,7 @@ func file_invoicesrpc_invoices_proto_rawDescGZIP() []byte {
} }
var file_invoicesrpc_invoices_proto_enumTypes = make([]protoimpl.EnumInfo, 1) var file_invoicesrpc_invoices_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_invoicesrpc_invoices_proto_msgTypes = make([]protoimpl.MessageInfo, 8) var file_invoicesrpc_invoices_proto_msgTypes = make([]protoimpl.MessageInfo, 12)
var file_invoicesrpc_invoices_proto_goTypes = []interface{}{ var file_invoicesrpc_invoices_proto_goTypes = []interface{}{
(LookupModifier)(0), // 0: invoicesrpc.LookupModifier (LookupModifier)(0), // 0: invoicesrpc.LookupModifier
(*CancelInvoiceMsg)(nil), // 1: invoicesrpc.CancelInvoiceMsg (*CancelInvoiceMsg)(nil), // 1: invoicesrpc.CancelInvoiceMsg
@ -739,27 +997,37 @@ var file_invoicesrpc_invoices_proto_goTypes = []interface{}{
(*SettleInvoiceResp)(nil), // 6: invoicesrpc.SettleInvoiceResp (*SettleInvoiceResp)(nil), // 6: invoicesrpc.SettleInvoiceResp
(*SubscribeSingleInvoiceRequest)(nil), // 7: invoicesrpc.SubscribeSingleInvoiceRequest (*SubscribeSingleInvoiceRequest)(nil), // 7: invoicesrpc.SubscribeSingleInvoiceRequest
(*LookupInvoiceMsg)(nil), // 8: invoicesrpc.LookupInvoiceMsg (*LookupInvoiceMsg)(nil), // 8: invoicesrpc.LookupInvoiceMsg
(*lnrpc.RouteHint)(nil), // 9: lnrpc.RouteHint (*CircuitKey)(nil), // 9: invoicesrpc.CircuitKey
(*lnrpc.Invoice)(nil), // 10: lnrpc.Invoice (*HtlcModifyRequest)(nil), // 10: invoicesrpc.HtlcModifyRequest
(*HtlcModifyResponse)(nil), // 11: invoicesrpc.HtlcModifyResponse
nil, // 12: invoicesrpc.HtlcModifyRequest.ExitHtlcWireCustomRecordsEntry
(*lnrpc.RouteHint)(nil), // 13: lnrpc.RouteHint
(*lnrpc.Invoice)(nil), // 14: lnrpc.Invoice
} }
var file_invoicesrpc_invoices_proto_depIdxs = []int32{ var file_invoicesrpc_invoices_proto_depIdxs = []int32{
9, // 0: invoicesrpc.AddHoldInvoiceRequest.route_hints:type_name -> lnrpc.RouteHint 13, // 0: invoicesrpc.AddHoldInvoiceRequest.route_hints:type_name -> lnrpc.RouteHint
0, // 1: invoicesrpc.LookupInvoiceMsg.lookup_modifier:type_name -> invoicesrpc.LookupModifier 0, // 1: invoicesrpc.LookupInvoiceMsg.lookup_modifier:type_name -> invoicesrpc.LookupModifier
7, // 2: invoicesrpc.Invoices.SubscribeSingleInvoice:input_type -> invoicesrpc.SubscribeSingleInvoiceRequest 14, // 2: invoicesrpc.HtlcModifyRequest.invoice:type_name -> lnrpc.Invoice
1, // 3: invoicesrpc.Invoices.CancelInvoice:input_type -> invoicesrpc.CancelInvoiceMsg 9, // 3: invoicesrpc.HtlcModifyRequest.exit_htlc_circuit_key:type_name -> invoicesrpc.CircuitKey
3, // 4: invoicesrpc.Invoices.AddHoldInvoice:input_type -> invoicesrpc.AddHoldInvoiceRequest 12, // 4: invoicesrpc.HtlcModifyRequest.exit_htlc_wire_custom_records:type_name -> invoicesrpc.HtlcModifyRequest.ExitHtlcWireCustomRecordsEntry
5, // 5: invoicesrpc.Invoices.SettleInvoice:input_type -> invoicesrpc.SettleInvoiceMsg 9, // 5: invoicesrpc.HtlcModifyResponse.circuit_key:type_name -> invoicesrpc.CircuitKey
8, // 6: invoicesrpc.Invoices.LookupInvoiceV2:input_type -> invoicesrpc.LookupInvoiceMsg 7, // 6: invoicesrpc.Invoices.SubscribeSingleInvoice:input_type -> invoicesrpc.SubscribeSingleInvoiceRequest
10, // 7: invoicesrpc.Invoices.SubscribeSingleInvoice:output_type -> lnrpc.Invoice 1, // 7: invoicesrpc.Invoices.CancelInvoice:input_type -> invoicesrpc.CancelInvoiceMsg
2, // 8: invoicesrpc.Invoices.CancelInvoice:output_type -> invoicesrpc.CancelInvoiceResp 3, // 8: invoicesrpc.Invoices.AddHoldInvoice:input_type -> invoicesrpc.AddHoldInvoiceRequest
4, // 9: invoicesrpc.Invoices.AddHoldInvoice:output_type -> invoicesrpc.AddHoldInvoiceResp 5, // 9: invoicesrpc.Invoices.SettleInvoice:input_type -> invoicesrpc.SettleInvoiceMsg
6, // 10: invoicesrpc.Invoices.SettleInvoice:output_type -> invoicesrpc.SettleInvoiceResp 8, // 10: invoicesrpc.Invoices.LookupInvoiceV2:input_type -> invoicesrpc.LookupInvoiceMsg
10, // 11: invoicesrpc.Invoices.LookupInvoiceV2:output_type -> lnrpc.Invoice 11, // 11: invoicesrpc.Invoices.HtlcModifier:input_type -> invoicesrpc.HtlcModifyResponse
7, // [7:12] is the sub-list for method output_type 14, // 12: invoicesrpc.Invoices.SubscribeSingleInvoice:output_type -> lnrpc.Invoice
2, // [2:7] is the sub-list for method input_type 2, // 13: invoicesrpc.Invoices.CancelInvoice:output_type -> invoicesrpc.CancelInvoiceResp
2, // [2:2] is the sub-list for extension type_name 4, // 14: invoicesrpc.Invoices.AddHoldInvoice:output_type -> invoicesrpc.AddHoldInvoiceResp
2, // [2:2] is the sub-list for extension extendee 6, // 15: invoicesrpc.Invoices.SettleInvoice:output_type -> invoicesrpc.SettleInvoiceResp
0, // [0:2] is the sub-list for field type_name 14, // 16: invoicesrpc.Invoices.LookupInvoiceV2:output_type -> lnrpc.Invoice
10, // 17: invoicesrpc.Invoices.HtlcModifier:output_type -> invoicesrpc.HtlcModifyRequest
12, // [12:18] is the sub-list for method output_type
6, // [6:12] is the sub-list for method input_type
6, // [6:6] is the sub-list for extension type_name
6, // [6:6] is the sub-list for extension extendee
0, // [0:6] is the sub-list for field type_name
} }
func init() { file_invoicesrpc_invoices_proto_init() } func init() { file_invoicesrpc_invoices_proto_init() }
@ -864,6 +1132,42 @@ func file_invoicesrpc_invoices_proto_init() {
return nil return nil
} }
} }
file_invoicesrpc_invoices_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*CircuitKey); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_invoicesrpc_invoices_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*HtlcModifyRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_invoicesrpc_invoices_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*HtlcModifyResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
} }
file_invoicesrpc_invoices_proto_msgTypes[7].OneofWrappers = []interface{}{ file_invoicesrpc_invoices_proto_msgTypes[7].OneofWrappers = []interface{}{
(*LookupInvoiceMsg_PaymentHash)(nil), (*LookupInvoiceMsg_PaymentHash)(nil),
@ -876,7 +1180,7 @@ func file_invoicesrpc_invoices_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_invoicesrpc_invoices_proto_rawDesc, RawDescriptor: file_invoicesrpc_invoices_proto_rawDesc,
NumEnums: 1, NumEnums: 1,
NumMessages: 8, NumMessages: 12,
NumExtensions: 0, NumExtensions: 0,
NumServices: 1, NumServices: 1,
}, },

View file

@ -203,6 +203,58 @@ func local_request_Invoices_LookupInvoiceV2_0(ctx context.Context, marshaler run
} }
func request_Invoices_HtlcModifier_0(ctx context.Context, marshaler runtime.Marshaler, client InvoicesClient, req *http.Request, pathParams map[string]string) (Invoices_HtlcModifierClient, runtime.ServerMetadata, error) {
var metadata runtime.ServerMetadata
stream, err := client.HtlcModifier(ctx)
if err != nil {
grpclog.Infof("Failed to start streaming: %v", err)
return nil, metadata, err
}
dec := marshaler.NewDecoder(req.Body)
handleSend := func() error {
var protoReq HtlcModifyResponse
err := dec.Decode(&protoReq)
if err == io.EOF {
return err
}
if err != nil {
grpclog.Infof("Failed to decode request: %v", err)
return err
}
if err := stream.Send(&protoReq); err != nil {
grpclog.Infof("Failed to send request: %v", err)
return err
}
return nil
}
if err := handleSend(); err != nil {
if cerr := stream.CloseSend(); cerr != nil {
grpclog.Infof("Failed to terminate client stream: %v", cerr)
}
if err == io.EOF {
return stream, metadata, nil
}
return nil, metadata, err
}
go func() {
for {
if err := handleSend(); err != nil {
break
}
}
if err := stream.CloseSend(); err != nil {
grpclog.Infof("Failed to terminate client stream: %v", err)
}
}()
header, err := stream.Header()
if err != nil {
grpclog.Infof("Failed to get header from client: %v", err)
return nil, metadata, err
}
metadata.HeaderMD = header
return stream, metadata, nil
}
// RegisterInvoicesHandlerServer registers the http handlers for service Invoices to "mux". // RegisterInvoicesHandlerServer registers the http handlers for service Invoices to "mux".
// UnaryRPC :call InvoicesServer directly. // UnaryRPC :call InvoicesServer directly.
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
@ -308,6 +360,13 @@ func RegisterInvoicesHandlerServer(ctx context.Context, mux *runtime.ServeMux, s
}) })
mux.Handle("POST", pattern_Invoices_HtlcModifier_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
err := status.Error(codes.Unimplemented, "streaming calls are not yet supported in the in-process transport")
_, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
})
return nil return nil
} }
@ -449,6 +508,26 @@ func RegisterInvoicesHandlerClient(ctx context.Context, mux *runtime.ServeMux, c
}) })
mux.Handle("POST", pattern_Invoices_HtlcModifier_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req, "/invoicesrpc.Invoices/HtlcModifier", runtime.WithHTTPPathPattern("/v2/invoices/htlcmodifier"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Invoices_HtlcModifier_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Invoices_HtlcModifier_0(ctx, mux, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...)
})
return nil return nil
} }
@ -462,6 +541,8 @@ var (
pattern_Invoices_SettleInvoice_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v2", "invoices", "settle"}, "")) pattern_Invoices_SettleInvoice_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v2", "invoices", "settle"}, ""))
pattern_Invoices_LookupInvoiceV2_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v2", "invoices", "lookup"}, "")) pattern_Invoices_LookupInvoiceV2_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v2", "invoices", "lookup"}, ""))
pattern_Invoices_HtlcModifier_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v2", "invoices", "htlcmodifier"}, ""))
) )
var ( var (
@ -474,4 +555,6 @@ var (
forward_Invoices_SettleInvoice_0 = runtime.ForwardResponseMessage forward_Invoices_SettleInvoice_0 = runtime.ForwardResponseMessage
forward_Invoices_LookupInvoiceV2_0 = runtime.ForwardResponseMessage forward_Invoices_LookupInvoiceV2_0 = runtime.ForwardResponseMessage
forward_Invoices_HtlcModifier_0 = runtime.ForwardResponseStream
) )

View file

@ -55,10 +55,19 @@ service Invoices {
rpc SettleInvoice (SettleInvoiceMsg) returns (SettleInvoiceResp); rpc SettleInvoice (SettleInvoiceMsg) returns (SettleInvoiceResp);
/* /*
LookupInvoiceV2 attempts to look up at invoice. An invoice can be refrenced LookupInvoiceV2 attempts to look up at invoice. An invoice can be referenced
using either its payment hash, payment address, or set ID. using either its payment hash, payment address, or set ID.
*/ */
rpc LookupInvoiceV2 (LookupInvoiceMsg) returns (lnrpc.Invoice); rpc LookupInvoiceV2 (LookupInvoiceMsg) returns (lnrpc.Invoice);
/*
HtlcModifier is a bidirectional streaming RPC that allows a client to
intercept and modify the HTLCs that attempt to settle the given invoice. The
server will send HTLCs of invoices to the client and the client can modify
some aspects of the HTLC in order to pass the invoice acceptance tests.
*/
rpc HtlcModifier (stream HtlcModifyResponse)
returns (stream HtlcModifyRequest);
} }
message CancelInvoiceMsg { message CancelInvoiceMsg {
@ -192,3 +201,45 @@ message LookupInvoiceMsg {
LookupModifier lookup_modifier = 4; LookupModifier lookup_modifier = 4;
} }
// CircuitKey is a unique identifier for an HTLC.
message CircuitKey {
/// The id of the channel that the is part of this circuit.
uint64 chan_id = 1;
/// The index of the incoming htlc in the incoming channel.
uint64 htlc_id = 2;
}
message HtlcModifyRequest {
// The invoice the intercepted HTLC is attempting to settle. The HTLCs in
// the invoice are only HTLCs that have already been accepted or settled,
// not including the current intercepted HTLC.
lnrpc.Invoice invoice = 1;
// The unique identifier of the HTLC of this intercepted HTLC.
CircuitKey exit_htlc_circuit_key = 2;
// The amount in milli-satoshi that the exit HTLC is attempting to pay.
uint64 exit_htlc_amt = 3;
// The absolute expiry height of the exit HTLC.
uint32 exit_htlc_expiry = 4;
// The current block height.
uint32 current_height = 5;
// The wire message custom records of the exit HTLC.
map<uint64, bytes> exit_htlc_wire_custom_records = 6;
}
message HtlcModifyResponse {
// The circuit key of the HTLC that the client wants to modify.
CircuitKey circuit_key = 1;
// The modified amount in milli-satoshi that the exit HTLC is paying. This
// value can be different from the actual on-chain HTLC amount, in case the
// HTLC carries other valuable items, as can be the case with custom channel
// types. In order to not modify this value, the client should set it zero.
uint64 amt_paid = 2;
}

View file

@ -82,9 +82,52 @@
] ]
} }
}, },
"/v2/invoices/htlcmodifier": {
"post": {
"summary": "HtlcModifier is a bidirectional streaming RPC that allows a client to\nintercept and modify the HTLCs that attempt to settle the given invoice. The\nserver will send HTLCs of invoices to the client and the client can modify\nsome aspects of the HTLC in order to pass the invoice acceptance tests.",
"operationId": "Invoices_HtlcModifier",
"responses": {
"200": {
"description": "A successful response.(streaming responses)",
"schema": {
"type": "object",
"properties": {
"result": {
"$ref": "#/definitions/invoicesrpcHtlcModifyRequest"
},
"error": {
"$ref": "#/definitions/rpcStatus"
}
},
"title": "Stream result of invoicesrpcHtlcModifyRequest"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "body",
"description": " (streaming inputs)",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/invoicesrpcHtlcModifyResponse"
}
}
],
"tags": [
"Invoices"
]
}
},
"/v2/invoices/lookup": { "/v2/invoices/lookup": {
"get": { "get": {
"summary": "LookupInvoiceV2 attempts to look up at invoice. An invoice can be refrenced\nusing either its payment hash, payment address, or set ID.", "summary": "LookupInvoiceV2 attempts to look up at invoice. An invoice can be referenced\nusing either its payment hash, payment address, or set ID.",
"operationId": "Invoices_LookupInvoiceV2", "operationId": "Invoices_LookupInvoiceV2",
"responses": { "responses": {
"200": { "200": {
@ -317,6 +360,72 @@
"invoicesrpcCancelInvoiceResp": { "invoicesrpcCancelInvoiceResp": {
"type": "object" "type": "object"
}, },
"invoicesrpcCircuitKey": {
"type": "object",
"properties": {
"chan_id": {
"type": "string",
"format": "uint64",
"description": "/ The id of the channel that the is part of this circuit."
},
"htlc_id": {
"type": "string",
"format": "uint64",
"description": "/ The index of the incoming htlc in the incoming channel."
}
},
"description": "CircuitKey is a unique identifier for an HTLC."
},
"invoicesrpcHtlcModifyRequest": {
"type": "object",
"properties": {
"invoice": {
"$ref": "#/definitions/lnrpcInvoice",
"description": "The invoice the intercepted HTLC is attempting to settle. The HTLCs in\nthe invoice are only HTLCs that have already been accepted or settled,\nnot including the current intercepted HTLC."
},
"exit_htlc_circuit_key": {
"$ref": "#/definitions/invoicesrpcCircuitKey",
"description": "The unique identifier of the HTLC of this intercepted HTLC."
},
"exit_htlc_amt": {
"type": "string",
"format": "uint64",
"description": "The amount in milli-satoshi that the exit HTLC is attempting to pay."
},
"exit_htlc_expiry": {
"type": "integer",
"format": "int64",
"description": "The absolute expiry height of the exit HTLC."
},
"current_height": {
"type": "integer",
"format": "int64",
"description": "The current block height."
},
"exit_htlc_wire_custom_records": {
"type": "object",
"additionalProperties": {
"type": "string",
"format": "byte"
},
"description": "The wire message custom records of the exit HTLC."
}
}
},
"invoicesrpcHtlcModifyResponse": {
"type": "object",
"properties": {
"circuit_key": {
"$ref": "#/definitions/invoicesrpcCircuitKey",
"description": "The circuit key of the HTLC that the client wants to modify."
},
"amt_paid": {
"type": "string",
"format": "uint64",
"description": "The modified amount in milli-satoshi that the exit HTLC is paying. This\nvalue can be different from the actual on-chain HTLC amount, in case the\nHTLC carries other valuable items, as can be the case with custom channel\ntypes. In order to not modify this value, the client should set it zero."
}
}
},
"invoicesrpcLookupModifier": { "invoicesrpcLookupModifier": {
"type": "string", "type": "string",
"enum": [ "enum": [
@ -639,6 +748,14 @@
"amp": { "amp": {
"$ref": "#/definitions/lnrpcAMP", "$ref": "#/definitions/lnrpcAMP",
"description": "Details relevant to AMP HTLCs, only populated if this is an AMP HTLC." "description": "Details relevant to AMP HTLCs, only populated if this is an AMP HTLC."
},
"wire_custom_records": {
"type": "object",
"additionalProperties": {
"type": "string",
"format": "byte"
},
"description": "Custom tlv records that were only sent on the p2p wire message, not in\nthe onion."
} }
}, },
"title": "Details of an HTLC that paid to an invoice" "title": "Details of an HTLC that paid to an invoice"

View file

@ -16,3 +16,6 @@ http:
body: "*" body: "*"
- selector: invoicesrpc.Invoices.LookupInvoiceV2 - selector: invoicesrpc.Invoices.LookupInvoiceV2
get: "/v2/invoices/lookup" get: "/v2/invoices/lookup"
- selector: invoicesrpc.Invoices.HtlcModifier
post: "/v2/invoices/htlcmodifier"
body: "*"

View file

@ -36,9 +36,14 @@ type InvoicesClient interface {
// SettleInvoice settles an accepted invoice. If the invoice is already // SettleInvoice settles an accepted invoice. If the invoice is already
// settled, this call will succeed. // settled, this call will succeed.
SettleInvoice(ctx context.Context, in *SettleInvoiceMsg, opts ...grpc.CallOption) (*SettleInvoiceResp, error) SettleInvoice(ctx context.Context, in *SettleInvoiceMsg, opts ...grpc.CallOption) (*SettleInvoiceResp, error)
// LookupInvoiceV2 attempts to look up at invoice. An invoice can be refrenced // LookupInvoiceV2 attempts to look up at invoice. An invoice can be referenced
// using either its payment hash, payment address, or set ID. // using either its payment hash, payment address, or set ID.
LookupInvoiceV2(ctx context.Context, in *LookupInvoiceMsg, opts ...grpc.CallOption) (*lnrpc.Invoice, error) LookupInvoiceV2(ctx context.Context, in *LookupInvoiceMsg, opts ...grpc.CallOption) (*lnrpc.Invoice, error)
// HtlcModifier is a bidirectional streaming RPC that allows a client to
// intercept and modify the HTLCs that attempt to settle the given invoice. The
// server will send HTLCs of invoices to the client and the client can modify
// some aspects of the HTLC in order to pass the invoice acceptance tests.
HtlcModifier(ctx context.Context, opts ...grpc.CallOption) (Invoices_HtlcModifierClient, error)
} }
type invoicesClient struct { type invoicesClient struct {
@ -117,6 +122,37 @@ func (c *invoicesClient) LookupInvoiceV2(ctx context.Context, in *LookupInvoiceM
return out, nil return out, nil
} }
func (c *invoicesClient) HtlcModifier(ctx context.Context, opts ...grpc.CallOption) (Invoices_HtlcModifierClient, error) {
stream, err := c.cc.NewStream(ctx, &Invoices_ServiceDesc.Streams[1], "/invoicesrpc.Invoices/HtlcModifier", opts...)
if err != nil {
return nil, err
}
x := &invoicesHtlcModifierClient{stream}
return x, nil
}
type Invoices_HtlcModifierClient interface {
Send(*HtlcModifyResponse) error
Recv() (*HtlcModifyRequest, error)
grpc.ClientStream
}
type invoicesHtlcModifierClient struct {
grpc.ClientStream
}
func (x *invoicesHtlcModifierClient) Send(m *HtlcModifyResponse) error {
return x.ClientStream.SendMsg(m)
}
func (x *invoicesHtlcModifierClient) Recv() (*HtlcModifyRequest, error) {
m := new(HtlcModifyRequest)
if err := x.ClientStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
// InvoicesServer is the server API for Invoices service. // InvoicesServer is the server API for Invoices service.
// All implementations must embed UnimplementedInvoicesServer // All implementations must embed UnimplementedInvoicesServer
// for forward compatibility // for forward compatibility
@ -138,9 +174,14 @@ type InvoicesServer interface {
// SettleInvoice settles an accepted invoice. If the invoice is already // SettleInvoice settles an accepted invoice. If the invoice is already
// settled, this call will succeed. // settled, this call will succeed.
SettleInvoice(context.Context, *SettleInvoiceMsg) (*SettleInvoiceResp, error) SettleInvoice(context.Context, *SettleInvoiceMsg) (*SettleInvoiceResp, error)
// LookupInvoiceV2 attempts to look up at invoice. An invoice can be refrenced // LookupInvoiceV2 attempts to look up at invoice. An invoice can be referenced
// using either its payment hash, payment address, or set ID. // using either its payment hash, payment address, or set ID.
LookupInvoiceV2(context.Context, *LookupInvoiceMsg) (*lnrpc.Invoice, error) LookupInvoiceV2(context.Context, *LookupInvoiceMsg) (*lnrpc.Invoice, error)
// HtlcModifier is a bidirectional streaming RPC that allows a client to
// intercept and modify the HTLCs that attempt to settle the given invoice. The
// server will send HTLCs of invoices to the client and the client can modify
// some aspects of the HTLC in order to pass the invoice acceptance tests.
HtlcModifier(Invoices_HtlcModifierServer) error
mustEmbedUnimplementedInvoicesServer() mustEmbedUnimplementedInvoicesServer()
} }
@ -163,6 +204,9 @@ func (UnimplementedInvoicesServer) SettleInvoice(context.Context, *SettleInvoice
func (UnimplementedInvoicesServer) LookupInvoiceV2(context.Context, *LookupInvoiceMsg) (*lnrpc.Invoice, error) { func (UnimplementedInvoicesServer) LookupInvoiceV2(context.Context, *LookupInvoiceMsg) (*lnrpc.Invoice, error) {
return nil, status.Errorf(codes.Unimplemented, "method LookupInvoiceV2 not implemented") return nil, status.Errorf(codes.Unimplemented, "method LookupInvoiceV2 not implemented")
} }
func (UnimplementedInvoicesServer) HtlcModifier(Invoices_HtlcModifierServer) error {
return status.Errorf(codes.Unimplemented, "method HtlcModifier not implemented")
}
func (UnimplementedInvoicesServer) mustEmbedUnimplementedInvoicesServer() {} func (UnimplementedInvoicesServer) mustEmbedUnimplementedInvoicesServer() {}
// UnsafeInvoicesServer may be embedded to opt out of forward compatibility for this service. // UnsafeInvoicesServer may be embedded to opt out of forward compatibility for this service.
@ -269,6 +313,32 @@ func _Invoices_LookupInvoiceV2_Handler(srv interface{}, ctx context.Context, dec
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
func _Invoices_HtlcModifier_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(InvoicesServer).HtlcModifier(&invoicesHtlcModifierServer{stream})
}
type Invoices_HtlcModifierServer interface {
Send(*HtlcModifyRequest) error
Recv() (*HtlcModifyResponse, error)
grpc.ServerStream
}
type invoicesHtlcModifierServer struct {
grpc.ServerStream
}
func (x *invoicesHtlcModifierServer) Send(m *HtlcModifyRequest) error {
return x.ServerStream.SendMsg(m)
}
func (x *invoicesHtlcModifierServer) Recv() (*HtlcModifyResponse, error) {
m := new(HtlcModifyResponse)
if err := x.ServerStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
// Invoices_ServiceDesc is the grpc.ServiceDesc for Invoices service. // Invoices_ServiceDesc is the grpc.ServiceDesc for Invoices service.
// It's only intended for direct use with grpc.RegisterService, // It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy) // and not to be introspected or modified (even as a copy)
@ -299,6 +369,12 @@ var Invoices_ServiceDesc = grpc.ServiceDesc{
Handler: _Invoices_SubscribeSingleInvoice_Handler, Handler: _Invoices_SubscribeSingleInvoice_Handler,
ServerStreams: true, ServerStreams: true,
}, },
{
StreamName: "HtlcModifier",
Handler: _Invoices_HtlcModifier_Handler,
ServerStreams: true,
ClientStreams: true,
},
}, },
Metadata: "invoicesrpc/invoices.proto", Metadata: "invoicesrpc/invoices.proto",
} }

View file

@ -10,6 +10,7 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"sync/atomic"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime" "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/lightningnetwork/lnd/invoices" "github.com/lightningnetwork/lnd/invoices"
@ -31,6 +32,13 @@ const (
) )
var ( var (
// ErrInvoiceHtlcModifierAlreadyExists signals that an invoice HTLC
// modifier already exists. The user must disconnect an existing invoice
// HTLC modifier prior to opening another stream.
ErrInvoiceHtlcModifierAlreadyExists = errors.New(
"invoice HTLC modifier already exists",
)
// macaroonOps are the set of capabilities that our minted macaroon (if // macaroonOps are the set of capabilities that our minted macaroon (if
// it doesn't already exist) will have. // it doesn't already exist) will have.
macaroonOps = []bakery.Op{ macaroonOps = []bakery.Op{
@ -66,6 +74,10 @@ var (
Entity: "invoices", Entity: "invoices",
Action: "write", Action: "write",
}}, }},
"/invoicesrpc.Invoices/HtlcModifier": {{
Entity: "invoices",
Action: "write",
}},
} }
// DefaultInvoicesMacFilename is the default name of the invoices // DefaultInvoicesMacFilename is the default name of the invoices
@ -88,6 +100,12 @@ type Server struct {
// Required by the grpc-gateway/v2 library for forward compatibility. // Required by the grpc-gateway/v2 library for forward compatibility.
UnimplementedInvoicesServer UnimplementedInvoicesServer
// invoiceHtlcModifierActive is an atomic flag that indicates whether an
// invoice HTLC modifier RPC server is currently active. It is used to
// ensure that only one invoice HTLC modifier RPC server instance is
// running at a time.
invoiceHtlcModifierActive atomic.Int32
quit chan struct{} quit chan struct{}
cfg *Config cfg *Config
@ -447,3 +465,27 @@ func (s *Server) LookupInvoiceV2(ctx context.Context,
return CreateRPCInvoice(&invoice, s.cfg.ChainParams) return CreateRPCInvoice(&invoice, s.cfg.ChainParams)
} }
// HtlcModifier is a bidirectional streaming RPC that allows a client to
// intercept and modify the HTLCs that attempt to settle the given invoice. The
// server will send HTLCs of invoices to the client and the client can modify
// some aspects of the HTLC in order to pass the invoice acceptance tests.
func (s *Server) HtlcModifier(
modifierServer Invoices_HtlcModifierServer) error {
// Ensure that there is only one invoice HTLC modifier RPC server
// instance.
if !s.invoiceHtlcModifierActive.CompareAndSwap(0, 1) {
return ErrInvoiceHtlcModifierAlreadyExists
}
defer s.invoiceHtlcModifierActive.CompareAndSwap(1, 0)
// Run the invoice HTLC modifier.
log.Debugf("Invoice HTLC modifier client connected")
return newHtlcModifier(htlcModifierConfig{
chainParams: s.cfg.ChainParams,
modificationInterceptor: s.cfg.HtlcModifier,
serverStream: modifierServer,
}).run()
}

File diff suppressed because it is too large Load diff

View file

@ -3890,6 +3890,10 @@ message InvoiceHTLC {
// Details relevant to AMP HTLCs, only populated if this is an AMP HTLC. // Details relevant to AMP HTLCs, only populated if this is an AMP HTLC.
AMP amp = 11; AMP amp = 11;
// Custom tlv records that were only sent on the p2p wire message, not in
// the onion.
map<uint64, bytes> wire_custom_records = 12;
} }
// Details specific to AMP HTLCs. // Details specific to AMP HTLCs.

View file

@ -5533,6 +5533,14 @@
"amp": { "amp": {
"$ref": "#/definitions/lnrpcAMP", "$ref": "#/definitions/lnrpcAMP",
"description": "Details relevant to AMP HTLCs, only populated if this is an AMP HTLC." "description": "Details relevant to AMP HTLCs, only populated if this is an AMP HTLC."
},
"wire_custom_records": {
"type": "object",
"additionalProperties": {
"type": "string",
"format": "byte"
},
"description": "Custom tlv records that were only sent on the p2p wire message, not in\nthe onion."
} }
}, },
"title": "Details of an HTLC that paid to an invoice" "title": "Details of an HTLC that paid to an invoice"