mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-04-07 03:28:05 +02:00
Merge pull request #1662 from joostjager/raw
lnrpc: better payment failure reporting
This commit is contained in:
commit
863bf2f91b
@ -2476,9 +2476,18 @@ func sendToRoute(ctx *cli.Context) error {
|
||||
"from incoming array of routes: %v", err)
|
||||
}
|
||||
|
||||
if len(routes.Routes) == 0 {
|
||||
return fmt.Errorf("no routes provided")
|
||||
}
|
||||
|
||||
if len(routes.Routes) != 1 {
|
||||
return fmt.Errorf("expected a single route, but got %v",
|
||||
len(routes.Routes))
|
||||
}
|
||||
|
||||
req := &lnrpc.SendToRouteRequest{
|
||||
PaymentHash: rHash,
|
||||
Routes: routes.Routes,
|
||||
Route: routes.Routes[0],
|
||||
}
|
||||
|
||||
return sendToRouteRequest(ctx, req)
|
||||
|
10
lnd_test.go
10
lnd_test.go
@ -1491,7 +1491,7 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
}
|
||||
sendReq := &lnrpc.SendToRouteRequest{
|
||||
PaymentHash: resp.RHash,
|
||||
Routes: routes.Routes,
|
||||
Route: routes.Routes[0],
|
||||
}
|
||||
|
||||
err = alicePayStream.Send(sendReq)
|
||||
@ -1529,7 +1529,7 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
|
||||
sendReq = &lnrpc.SendToRouteRequest{
|
||||
PaymentHash: resp.RHash,
|
||||
Routes: routes.Routes,
|
||||
Route: routes.Routes[0],
|
||||
}
|
||||
|
||||
err = alicePayStream.Send(sendReq)
|
||||
@ -4308,7 +4308,7 @@ func testSingleHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
for _, rHash := range rHashes {
|
||||
sendReq := &lnrpc.SendToRouteRequest{
|
||||
PaymentHash: rHash,
|
||||
Routes: routes.Routes,
|
||||
Route: routes.Routes[0],
|
||||
}
|
||||
err := alicePayStream.Send(sendReq)
|
||||
|
||||
@ -4479,7 +4479,7 @@ func testMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
for _, rHash := range rHashes {
|
||||
sendReq := &lnrpc.SendToRouteRequest{
|
||||
PaymentHash: rHash,
|
||||
Routes: routes.Routes,
|
||||
Route: routes.Routes[0],
|
||||
}
|
||||
err := alicePayStream.Send(sendReq)
|
||||
|
||||
@ -4634,7 +4634,7 @@ func testSendToRouteErrorPropagation(net *lntest.NetworkHarness, t *harnessTest)
|
||||
|
||||
sendReq := &lnrpc.SendToRouteRequest{
|
||||
PaymentHash: rHash,
|
||||
Routes: fakeRoute.Routes,
|
||||
Route: fakeRoute.Routes[0],
|
||||
}
|
||||
|
||||
if err := alicePayStream.Send(sendReq); err != nil {
|
||||
|
@ -1,11 +1,12 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// source: routerrpc/router.proto
|
||||
|
||||
package routerrpc
|
||||
package routerrpc // import "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
|
||||
|
||||
import proto "github.com/golang/protobuf/proto"
|
||||
import fmt "fmt"
|
||||
import math "math"
|
||||
import lnrpc "github.com/lightningnetwork/lnd/lnrpc"
|
||||
|
||||
import (
|
||||
context "golang.org/x/net/context"
|
||||
@ -23,6 +24,93 @@ var _ = math.Inf
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
type Failure_FailureCode int32
|
||||
|
||||
const (
|
||||
// *
|
||||
// The numbers assigned in this enumeration match the failure codes as
|
||||
// defined in BOLT #4. Because protobuf 3 requires enums to start with 0,
|
||||
// a RESERVED value is added.
|
||||
Failure_RESERVED Failure_FailureCode = 0
|
||||
Failure_UNKNOWN_PAYMENT_HASH Failure_FailureCode = 1
|
||||
Failure_INCORRECT_PAYMENT_AMOUNT Failure_FailureCode = 2
|
||||
Failure_FINAL_INCORRECT_CLTV_EXPIRY Failure_FailureCode = 3
|
||||
Failure_FINAL_INCORRECT_HTLC_AMOUNT Failure_FailureCode = 4
|
||||
Failure_FINAL_EXPIRY_TOO_SOON Failure_FailureCode = 5
|
||||
Failure_INVALID_REALM Failure_FailureCode = 6
|
||||
Failure_EXPIRY_TOO_SOON Failure_FailureCode = 7
|
||||
Failure_INVALID_ONION_VERSION Failure_FailureCode = 8
|
||||
Failure_INVALID_ONION_HMAC Failure_FailureCode = 9
|
||||
Failure_INVALID_ONION_KEY Failure_FailureCode = 10
|
||||
Failure_AMOUNT_BELOW_MINIMUM Failure_FailureCode = 11
|
||||
Failure_FEE_INSUFFICIENT Failure_FailureCode = 12
|
||||
Failure_INCORRECT_CLTV_EXPIRY Failure_FailureCode = 13
|
||||
Failure_CHANNEL_DISABLED Failure_FailureCode = 14
|
||||
Failure_TEMPORARY_CHANNEL_FAILURE Failure_FailureCode = 15
|
||||
Failure_REQUIRED_NODE_FEATURE_MISSING Failure_FailureCode = 16
|
||||
Failure_REQUIRED_CHANNEL_FEATURE_MISSING Failure_FailureCode = 17
|
||||
Failure_UNKNOWN_NEXT_PEER Failure_FailureCode = 18
|
||||
Failure_TEMPORARY_NODE_FAILURE Failure_FailureCode = 19
|
||||
Failure_PERMANENT_NODE_FAILURE Failure_FailureCode = 20
|
||||
Failure_PERMANENT_CHANNEL_FAILURE Failure_FailureCode = 21
|
||||
)
|
||||
|
||||
var Failure_FailureCode_name = map[int32]string{
|
||||
0: "RESERVED",
|
||||
1: "UNKNOWN_PAYMENT_HASH",
|
||||
2: "INCORRECT_PAYMENT_AMOUNT",
|
||||
3: "FINAL_INCORRECT_CLTV_EXPIRY",
|
||||
4: "FINAL_INCORRECT_HTLC_AMOUNT",
|
||||
5: "FINAL_EXPIRY_TOO_SOON",
|
||||
6: "INVALID_REALM",
|
||||
7: "EXPIRY_TOO_SOON",
|
||||
8: "INVALID_ONION_VERSION",
|
||||
9: "INVALID_ONION_HMAC",
|
||||
10: "INVALID_ONION_KEY",
|
||||
11: "AMOUNT_BELOW_MINIMUM",
|
||||
12: "FEE_INSUFFICIENT",
|
||||
13: "INCORRECT_CLTV_EXPIRY",
|
||||
14: "CHANNEL_DISABLED",
|
||||
15: "TEMPORARY_CHANNEL_FAILURE",
|
||||
16: "REQUIRED_NODE_FEATURE_MISSING",
|
||||
17: "REQUIRED_CHANNEL_FEATURE_MISSING",
|
||||
18: "UNKNOWN_NEXT_PEER",
|
||||
19: "TEMPORARY_NODE_FAILURE",
|
||||
20: "PERMANENT_NODE_FAILURE",
|
||||
21: "PERMANENT_CHANNEL_FAILURE",
|
||||
}
|
||||
var Failure_FailureCode_value = map[string]int32{
|
||||
"RESERVED": 0,
|
||||
"UNKNOWN_PAYMENT_HASH": 1,
|
||||
"INCORRECT_PAYMENT_AMOUNT": 2,
|
||||
"FINAL_INCORRECT_CLTV_EXPIRY": 3,
|
||||
"FINAL_INCORRECT_HTLC_AMOUNT": 4,
|
||||
"FINAL_EXPIRY_TOO_SOON": 5,
|
||||
"INVALID_REALM": 6,
|
||||
"EXPIRY_TOO_SOON": 7,
|
||||
"INVALID_ONION_VERSION": 8,
|
||||
"INVALID_ONION_HMAC": 9,
|
||||
"INVALID_ONION_KEY": 10,
|
||||
"AMOUNT_BELOW_MINIMUM": 11,
|
||||
"FEE_INSUFFICIENT": 12,
|
||||
"INCORRECT_CLTV_EXPIRY": 13,
|
||||
"CHANNEL_DISABLED": 14,
|
||||
"TEMPORARY_CHANNEL_FAILURE": 15,
|
||||
"REQUIRED_NODE_FEATURE_MISSING": 16,
|
||||
"REQUIRED_CHANNEL_FEATURE_MISSING": 17,
|
||||
"UNKNOWN_NEXT_PEER": 18,
|
||||
"TEMPORARY_NODE_FAILURE": 19,
|
||||
"PERMANENT_NODE_FAILURE": 20,
|
||||
"PERMANENT_CHANNEL_FAILURE": 21,
|
||||
}
|
||||
|
||||
func (x Failure_FailureCode) String() string {
|
||||
return proto.EnumName(Failure_FailureCode_name, int32(x))
|
||||
}
|
||||
func (Failure_FailureCode) EnumDescriptor() ([]byte, []int) {
|
||||
return fileDescriptor_router_111acc30110a7cf6, []int{6, 0}
|
||||
}
|
||||
|
||||
type PaymentRequest struct {
|
||||
// *
|
||||
// A serialized BOLT-11 payment request that contains all information
|
||||
@ -59,7 +147,7 @@ func (m *PaymentRequest) Reset() { *m = PaymentRequest{} }
|
||||
func (m *PaymentRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*PaymentRequest) ProtoMessage() {}
|
||||
func (*PaymentRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_router_e218e7c710fe8172, []int{0}
|
||||
return fileDescriptor_router_111acc30110a7cf6, []int{0}
|
||||
}
|
||||
func (m *PaymentRequest) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_PaymentRequest.Unmarshal(m, b)
|
||||
@ -134,7 +222,7 @@ func (m *PaymentResponse) Reset() { *m = PaymentResponse{} }
|
||||
func (m *PaymentResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*PaymentResponse) ProtoMessage() {}
|
||||
func (*PaymentResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_router_e218e7c710fe8172, []int{1}
|
||||
return fileDescriptor_router_111acc30110a7cf6, []int{1}
|
||||
}
|
||||
func (m *PaymentResponse) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_PaymentResponse.Unmarshal(m, b)
|
||||
@ -191,7 +279,7 @@ func (m *RouteFeeRequest) Reset() { *m = RouteFeeRequest{} }
|
||||
func (m *RouteFeeRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*RouteFeeRequest) ProtoMessage() {}
|
||||
func (*RouteFeeRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_router_e218e7c710fe8172, []int{2}
|
||||
return fileDescriptor_router_111acc30110a7cf6, []int{2}
|
||||
}
|
||||
func (m *RouteFeeRequest) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_RouteFeeRequest.Unmarshal(m, b)
|
||||
@ -244,7 +332,7 @@ func (m *RouteFeeResponse) Reset() { *m = RouteFeeResponse{} }
|
||||
func (m *RouteFeeResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*RouteFeeResponse) ProtoMessage() {}
|
||||
func (*RouteFeeResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_router_e218e7c710fe8172, []int{3}
|
||||
return fileDescriptor_router_111acc30110a7cf6, []int{3}
|
||||
}
|
||||
func (m *RouteFeeResponse) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_RouteFeeResponse.Unmarshal(m, b)
|
||||
@ -278,11 +366,336 @@ func (m *RouteFeeResponse) GetTimeLockDelay() int64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
type SendToRouteRequest struct {
|
||||
// / The payment hash to use for the HTLC.
|
||||
PaymentHash []byte `protobuf:"bytes,1,opt,name=payment_hash,json=paymentHash,proto3" json:"payment_hash,omitempty"`
|
||||
// / Route that should be used to attempt to complete the payment.
|
||||
Route *lnrpc.Route `protobuf:"bytes,2,opt,name=route,proto3" json:"route,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *SendToRouteRequest) Reset() { *m = SendToRouteRequest{} }
|
||||
func (m *SendToRouteRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*SendToRouteRequest) ProtoMessage() {}
|
||||
func (*SendToRouteRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_router_111acc30110a7cf6, []int{4}
|
||||
}
|
||||
func (m *SendToRouteRequest) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_SendToRouteRequest.Unmarshal(m, b)
|
||||
}
|
||||
func (m *SendToRouteRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_SendToRouteRequest.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (dst *SendToRouteRequest) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_SendToRouteRequest.Merge(dst, src)
|
||||
}
|
||||
func (m *SendToRouteRequest) XXX_Size() int {
|
||||
return xxx_messageInfo_SendToRouteRequest.Size(m)
|
||||
}
|
||||
func (m *SendToRouteRequest) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_SendToRouteRequest.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_SendToRouteRequest proto.InternalMessageInfo
|
||||
|
||||
func (m *SendToRouteRequest) GetPaymentHash() []byte {
|
||||
if m != nil {
|
||||
return m.PaymentHash
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *SendToRouteRequest) GetRoute() *lnrpc.Route {
|
||||
if m != nil {
|
||||
return m.Route
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type SendToRouteResponse struct {
|
||||
// / The preimage obtained by making the payment.
|
||||
Preimage []byte `protobuf:"bytes,1,opt,name=preimage,proto3" json:"preimage,omitempty"`
|
||||
// / The failure message in case the payment failed.
|
||||
Failure *Failure `protobuf:"bytes,2,opt,name=failure,proto3" json:"failure,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *SendToRouteResponse) Reset() { *m = SendToRouteResponse{} }
|
||||
func (m *SendToRouteResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*SendToRouteResponse) ProtoMessage() {}
|
||||
func (*SendToRouteResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_router_111acc30110a7cf6, []int{5}
|
||||
}
|
||||
func (m *SendToRouteResponse) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_SendToRouteResponse.Unmarshal(m, b)
|
||||
}
|
||||
func (m *SendToRouteResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_SendToRouteResponse.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (dst *SendToRouteResponse) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_SendToRouteResponse.Merge(dst, src)
|
||||
}
|
||||
func (m *SendToRouteResponse) XXX_Size() int {
|
||||
return xxx_messageInfo_SendToRouteResponse.Size(m)
|
||||
}
|
||||
func (m *SendToRouteResponse) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_SendToRouteResponse.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_SendToRouteResponse proto.InternalMessageInfo
|
||||
|
||||
func (m *SendToRouteResponse) GetPreimage() []byte {
|
||||
if m != nil {
|
||||
return m.Preimage
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *SendToRouteResponse) GetFailure() *Failure {
|
||||
if m != nil {
|
||||
return m.Failure
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Failure struct {
|
||||
// / Failure code as defined in the Lightning spec
|
||||
Code Failure_FailureCode `protobuf:"varint,1,opt,name=code,proto3,enum=routerrpc.Failure_FailureCode" json:"code,omitempty"`
|
||||
// *
|
||||
// The node pubkey of the intermediate or final node that generated the failure
|
||||
// message.
|
||||
FailureSourcePubkey []byte `protobuf:"bytes,2,opt,name=failure_source_pubkey,json=failureSourcePubkey,proto3" json:"failure_source_pubkey,omitempty"`
|
||||
// / An optional channel update message.
|
||||
ChannelUpdate *ChannelUpdate `protobuf:"bytes,3,opt,name=channel_update,json=channelUpdate,proto3" json:"channel_update,omitempty"`
|
||||
// / A failure type-dependent htlc value.
|
||||
HtlcMsat uint64 `protobuf:"varint,4,opt,name=htlc_msat,json=htlcMsat,proto3" json:"htlc_msat,omitempty"`
|
||||
// / The sha256 sum of the onion payload.
|
||||
OnionSha_256 []byte `protobuf:"bytes,5,opt,name=onion_sha_256,json=onionSha256,proto3" json:"onion_sha_256,omitempty"`
|
||||
// / A failure type-dependent cltv expiry value.
|
||||
CltvExpiry uint32 `protobuf:"varint,6,opt,name=cltv_expiry,json=cltvExpiry,proto3" json:"cltv_expiry,omitempty"`
|
||||
// / A failure type-dependent flags value.
|
||||
Flags uint32 `protobuf:"varint,7,opt,name=flags,proto3" json:"flags,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Failure) Reset() { *m = Failure{} }
|
||||
func (m *Failure) String() string { return proto.CompactTextString(m) }
|
||||
func (*Failure) ProtoMessage() {}
|
||||
func (*Failure) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_router_111acc30110a7cf6, []int{6}
|
||||
}
|
||||
func (m *Failure) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_Failure.Unmarshal(m, b)
|
||||
}
|
||||
func (m *Failure) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_Failure.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (dst *Failure) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_Failure.Merge(dst, src)
|
||||
}
|
||||
func (m *Failure) XXX_Size() int {
|
||||
return xxx_messageInfo_Failure.Size(m)
|
||||
}
|
||||
func (m *Failure) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_Failure.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_Failure proto.InternalMessageInfo
|
||||
|
||||
func (m *Failure) GetCode() Failure_FailureCode {
|
||||
if m != nil {
|
||||
return m.Code
|
||||
}
|
||||
return Failure_RESERVED
|
||||
}
|
||||
|
||||
func (m *Failure) GetFailureSourcePubkey() []byte {
|
||||
if m != nil {
|
||||
return m.FailureSourcePubkey
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Failure) GetChannelUpdate() *ChannelUpdate {
|
||||
if m != nil {
|
||||
return m.ChannelUpdate
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Failure) GetHtlcMsat() uint64 {
|
||||
if m != nil {
|
||||
return m.HtlcMsat
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *Failure) GetOnionSha_256() []byte {
|
||||
if m != nil {
|
||||
return m.OnionSha_256
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Failure) GetCltvExpiry() uint32 {
|
||||
if m != nil {
|
||||
return m.CltvExpiry
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *Failure) GetFlags() uint32 {
|
||||
if m != nil {
|
||||
return m.Flags
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type ChannelUpdate struct {
|
||||
// Signature is used to validate the announced data and prove the
|
||||
// ownership of node id.
|
||||
Signature []byte `protobuf:"bytes,1,opt,name=signature,proto3" json:"signature,omitempty"`
|
||||
// ChainHash denotes the target chain that this channel was opened
|
||||
// within. This value should be the genesis hash of the target chain.
|
||||
// Along with the short channel ID, this uniquely identifies the
|
||||
// channel globally in a blockchain.
|
||||
ChainHash []byte `protobuf:"bytes,2,opt,name=chain_hash,json=chainHash,proto3" json:"chain_hash,omitempty"`
|
||||
// ShortChannelID is the unique description of the funding transaction.
|
||||
ChanId uint64 `protobuf:"varint,3,opt,name=chan_id,json=chanId,proto3" json:"chan_id,omitempty"`
|
||||
// Timestamp allows ordering in the case of multiple announcements. We
|
||||
// should ignore the message if timestamp is not greater than
|
||||
// the last-received.
|
||||
Timestamp uint32 `protobuf:"varint,4,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
|
||||
// Flags is a bitfield that describes additional meta-data concerning
|
||||
// how the update is to be interpreted. Currently, the
|
||||
// least-significant bit must be set to 0 if the creating node
|
||||
// corresponds to the first node in the previously sent channel
|
||||
// announcement and 1 otherwise. If the second bit is set, then the
|
||||
// channel is set to be disabled.
|
||||
ChannelFlags uint32 `protobuf:"varint,5,opt,name=channel_flags,json=channelFlags,proto3" json:"channel_flags,omitempty"`
|
||||
// TimeLockDelta is the minimum number of blocks this node requires to
|
||||
// be added to the expiry of HTLCs. This is a security parameter
|
||||
// determined by the node operator. This value represents the required
|
||||
// gap between the time locks of the incoming and outgoing HTLC's set
|
||||
// to this node.
|
||||
TimeLockDelta uint32 `protobuf:"varint,6,opt,name=time_lock_delta,json=timeLockDelta,proto3" json:"time_lock_delta,omitempty"`
|
||||
// HtlcMinimumMsat is the minimum HTLC value which will be accepted.
|
||||
HtlcMinimumMsat uint64 `protobuf:"varint,7,opt,name=htlc_minimum_msat,json=htlcMinimumMsat,proto3" json:"htlc_minimum_msat,omitempty"`
|
||||
// BaseFee is the base fee that must be used for incoming HTLC's to
|
||||
// this particular channel. This value will be tacked onto the required
|
||||
// for a payment independent of the size of the payment.
|
||||
BaseFee uint32 `protobuf:"varint,8,opt,name=base_fee,json=baseFee,proto3" json:"base_fee,omitempty"`
|
||||
// FeeRate is the fee rate that will be charged per millionth of a
|
||||
// satoshi.
|
||||
FeeRate uint32 `protobuf:"varint,9,opt,name=fee_rate,json=feeRate,proto3" json:"fee_rate,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *ChannelUpdate) Reset() { *m = ChannelUpdate{} }
|
||||
func (m *ChannelUpdate) String() string { return proto.CompactTextString(m) }
|
||||
func (*ChannelUpdate) ProtoMessage() {}
|
||||
func (*ChannelUpdate) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_router_111acc30110a7cf6, []int{7}
|
||||
}
|
||||
func (m *ChannelUpdate) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_ChannelUpdate.Unmarshal(m, b)
|
||||
}
|
||||
func (m *ChannelUpdate) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_ChannelUpdate.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (dst *ChannelUpdate) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_ChannelUpdate.Merge(dst, src)
|
||||
}
|
||||
func (m *ChannelUpdate) XXX_Size() int {
|
||||
return xxx_messageInfo_ChannelUpdate.Size(m)
|
||||
}
|
||||
func (m *ChannelUpdate) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_ChannelUpdate.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_ChannelUpdate proto.InternalMessageInfo
|
||||
|
||||
func (m *ChannelUpdate) GetSignature() []byte {
|
||||
if m != nil {
|
||||
return m.Signature
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ChannelUpdate) GetChainHash() []byte {
|
||||
if m != nil {
|
||||
return m.ChainHash
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ChannelUpdate) GetChanId() uint64 {
|
||||
if m != nil {
|
||||
return m.ChanId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *ChannelUpdate) GetTimestamp() uint32 {
|
||||
if m != nil {
|
||||
return m.Timestamp
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *ChannelUpdate) GetChannelFlags() uint32 {
|
||||
if m != nil {
|
||||
return m.ChannelFlags
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *ChannelUpdate) GetTimeLockDelta() uint32 {
|
||||
if m != nil {
|
||||
return m.TimeLockDelta
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *ChannelUpdate) GetHtlcMinimumMsat() uint64 {
|
||||
if m != nil {
|
||||
return m.HtlcMinimumMsat
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *ChannelUpdate) GetBaseFee() uint32 {
|
||||
if m != nil {
|
||||
return m.BaseFee
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *ChannelUpdate) GetFeeRate() uint32 {
|
||||
if m != nil {
|
||||
return m.FeeRate
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*PaymentRequest)(nil), "routerrpc.PaymentRequest")
|
||||
proto.RegisterType((*PaymentResponse)(nil), "routerrpc.PaymentResponse")
|
||||
proto.RegisterType((*RouteFeeRequest)(nil), "routerrpc.RouteFeeRequest")
|
||||
proto.RegisterType((*RouteFeeResponse)(nil), "routerrpc.RouteFeeResponse")
|
||||
proto.RegisterType((*SendToRouteRequest)(nil), "routerrpc.SendToRouteRequest")
|
||||
proto.RegisterType((*SendToRouteResponse)(nil), "routerrpc.SendToRouteResponse")
|
||||
proto.RegisterType((*Failure)(nil), "routerrpc.Failure")
|
||||
proto.RegisterType((*ChannelUpdate)(nil), "routerrpc.ChannelUpdate")
|
||||
proto.RegisterEnum("routerrpc.Failure_FailureCode", Failure_FailureCode_name, Failure_FailureCode_value)
|
||||
}
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
@ -308,6 +721,11 @@ type RouterClient interface {
|
||||
// EstimateRouteFee allows callers to obtain a lower bound w.r.t how much it
|
||||
// may cost to send an HTLC to the target end destination.
|
||||
EstimateRouteFee(ctx context.Context, in *RouteFeeRequest, opts ...grpc.CallOption) (*RouteFeeResponse, error)
|
||||
// *
|
||||
// SendToRoute attempts to make a payment via the specified route. This method
|
||||
// differs from SendPayment in that it allows users to specify a full route
|
||||
// manually. This can be used for things like rebalancing, and atomic swaps.
|
||||
SendToRoute(ctx context.Context, in *SendToRouteRequest, opts ...grpc.CallOption) (*SendToRouteResponse, error)
|
||||
}
|
||||
|
||||
type routerClient struct {
|
||||
@ -336,6 +754,15 @@ func (c *routerClient) EstimateRouteFee(ctx context.Context, in *RouteFeeRequest
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *routerClient) SendToRoute(ctx context.Context, in *SendToRouteRequest, opts ...grpc.CallOption) (*SendToRouteResponse, error) {
|
||||
out := new(SendToRouteResponse)
|
||||
err := c.cc.Invoke(ctx, "/routerrpc.Router/SendToRoute", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// RouterServer is the server API for Router service.
|
||||
type RouterServer interface {
|
||||
// *
|
||||
@ -349,6 +776,11 @@ type RouterServer interface {
|
||||
// EstimateRouteFee allows callers to obtain a lower bound w.r.t how much it
|
||||
// may cost to send an HTLC to the target end destination.
|
||||
EstimateRouteFee(context.Context, *RouteFeeRequest) (*RouteFeeResponse, error)
|
||||
// *
|
||||
// SendToRoute attempts to make a payment via the specified route. This method
|
||||
// differs from SendPayment in that it allows users to specify a full route
|
||||
// manually. This can be used for things like rebalancing, and atomic swaps.
|
||||
SendToRoute(context.Context, *SendToRouteRequest) (*SendToRouteResponse, error)
|
||||
}
|
||||
|
||||
func RegisterRouterServer(s *grpc.Server, srv RouterServer) {
|
||||
@ -391,6 +823,24 @@ func _Router_EstimateRouteFee_Handler(srv interface{}, ctx context.Context, dec
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Router_SendToRoute_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(SendToRouteRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(RouterServer).SendToRoute(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/routerrpc.Router/SendToRoute",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(RouterServer).SendToRoute(ctx, req.(*SendToRouteRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
var _Router_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "routerrpc.Router",
|
||||
HandlerType: (*RouterServer)(nil),
|
||||
@ -403,39 +853,91 @@ var _Router_serviceDesc = grpc.ServiceDesc{
|
||||
MethodName: "EstimateRouteFee",
|
||||
Handler: _Router_EstimateRouteFee_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "SendToRoute",
|
||||
Handler: _Router_SendToRoute_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "routerrpc/router.proto",
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("routerrpc/router.proto", fileDescriptor_router_e218e7c710fe8172) }
|
||||
func init() { proto.RegisterFile("routerrpc/router.proto", fileDescriptor_router_111acc30110a7cf6) }
|
||||
|
||||
var fileDescriptor_router_e218e7c710fe8172 = []byte{
|
||||
// 409 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x92, 0xdf, 0x6e, 0xd3, 0x30,
|
||||
0x14, 0xc6, 0x15, 0xb6, 0x85, 0xe5, 0x74, 0x6b, 0x8b, 0x91, 0x20, 0xeb, 0x84, 0xa8, 0x72, 0x01,
|
||||
0xb9, 0x0a, 0x12, 0xdc, 0x73, 0xc3, 0x36, 0x31, 0x31, 0x24, 0xe4, 0x3e, 0x80, 0x65, 0x92, 0xb3,
|
||||
0x26, 0x34, 0x8e, 0x5d, 0xdb, 0x41, 0xca, 0xb3, 0xf0, 0x3c, 0xbc, 0x17, 0xb2, 0xe3, 0x96, 0x82,
|
||||
0x7a, 0xe7, 0x7c, 0xe7, 0xef, 0xf7, 0x3b, 0x81, 0x17, 0x5a, 0xf6, 0x16, 0xb5, 0x56, 0xe5, 0xbb,
|
||||
0xf1, 0x55, 0x28, 0x2d, 0xad, 0x24, 0xc9, 0x5e, 0xcf, 0x7e, 0x47, 0x30, 0xfd, 0xc6, 0x07, 0x81,
|
||||
0x9d, 0xa5, 0xb8, 0xed, 0xd1, 0x58, 0xf2, 0x12, 0x9e, 0x2a, 0x3e, 0x30, 0x8d, 0xdb, 0x34, 0x5a,
|
||||
0x46, 0x79, 0x42, 0x63, 0xc5, 0x07, 0x8a, 0x5b, 0x92, 0xc1, 0xe5, 0x23, 0x22, 0x6b, 0x1b, 0xd1,
|
||||
0x58, 0x66, 0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
||||
0x28, 0xce, 0xae, 0x63, 0x2c, 0x5c, 0x55, 0xe4, 0xab, 0xa6, 0x41, 0xbf, 0x43, 0xfc, 0x6a, 0xb8,
|
||||
0x25, 0x6f, 0x46, 0x84, 0xac, 0x95, 0xe5, 0x86, 0x55, 0xd8, 0xf2, 0x21, 0xb4, 0xbf, 0x74, 0xf2,
|
||||
0x83, 0x2c, 0x37, 0x37, 0x4e, 0x7c, 0xff, 0x2b, 0x82, 0xd8, 0x8f, 0xd1, 0xe4, 0x06, 0x26, 0x2b,
|
||||
0xec, 0xaa, 0x00, 0x88, 0x5c, 0x15, 0xfb, 0xfb, 0x17, 0xff, 0xde, 0x7e, 0xb1, 0x38, 0x16, 0x0a,
|
||||
0x2b, 0x7e, 0x81, 0xf9, 0xad, 0xb1, 0x8d, 0xe0, 0x16, 0x77, 0xeb, 0x93, 0xc3, 0xfc, 0xff, 0x98,
|
||||
0x2c, 0xae, 0x8f, 0xc6, 0xc6, 0x66, 0xdf, 0x63, 0xff, 0x27, 0x7e, 0xf8, 0x13, 0x00, 0x00, 0xff,
|
||||
0xff, 0x95, 0xc2, 0xf8, 0xec, 0xa3, 0x02, 0x00, 0x00,
|
||||
var fileDescriptor_router_111acc30110a7cf6 = []byte{
|
||||
// 1172 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x56, 0xdd, 0x72, 0x1a, 0x37,
|
||||
0x14, 0x2e, 0xb1, 0xcd, 0xcf, 0x01, 0xec, 0xb5, 0x6c, 0x27, 0x98, 0xc4, 0x89, 0x43, 0x3b, 0xad,
|
||||
0xa7, 0xd3, 0xb1, 0xa7, 0x74, 0x92, 0xcb, 0x76, 0x36, 0x20, 0xea, 0x9d, 0xc0, 0x2e, 0xd5, 0x82,
|
||||
0x13, 0xb7, 0x17, 0x1a, 0x99, 0x95, 0x61, 0x6b, 0xf6, 0x27, 0xbb, 0xa2, 0xad, 0x5f, 0xa0, 0x0f,
|
||||
0xd4, 0x77, 0xe8, 0x43, 0xf4, 0x11, 0xfa, 0x16, 0x1d, 0x49, 0xbb, 0x18, 0x6c, 0xf7, 0x8a, 0xd5,
|
||||
0xf7, 0x1d, 0x7d, 0xd2, 0x39, 0x3a, 0x3f, 0xc0, 0xd3, 0x24, 0x5a, 0x08, 0x9e, 0x24, 0xf1, 0xe4,
|
||||
0x4c, 0x7f, 0x9d, 0xc6, 0x49, 0x24, 0x22, 0x54, 0x59, 0xe2, 0xcd, 0x4a, 0x12, 0x4f, 0x34, 0xda,
|
||||
0xfa, 0xbb, 0x00, 0xdb, 0x43, 0x76, 0x1b, 0xf0, 0x50, 0x10, 0xfe, 0x69, 0xc1, 0x53, 0x81, 0x9e,
|
||||
0x41, 0x29, 0x66, 0xb7, 0x34, 0xe1, 0x9f, 0x1a, 0x85, 0xe3, 0xc2, 0x49, 0x85, 0x14, 0x63, 0x76,
|
||||
0x4b, 0xf8, 0x27, 0xd4, 0x82, 0xfa, 0x35, 0xe7, 0x74, 0xee, 0x07, 0xbe, 0xa0, 0x29, 0x13, 0x8d,
|
||||
0x27, 0xc7, 0x85, 0x93, 0x0d, 0x52, 0xbd, 0xe6, 0xbc, 0x2f, 0x31, 0x97, 0x09, 0x74, 0x04, 0x30,
|
||||
0x99, 0x8b, 0xdf, 0xb4, 0x51, 0x63, 0xe3, 0xb8, 0x70, 0xb2, 0x45, 0x2a, 0x12, 0x51, 0x16, 0xe8,
|
||||
0x2b, 0xd8, 0x11, 0x7e, 0xc0, 0xa3, 0x85, 0xa0, 0x29, 0x9f, 0x44, 0xa1, 0x97, 0x36, 0x36, 0x95,
|
||||
0xcd, 0x76, 0x06, 0xbb, 0x1a, 0x45, 0xa7, 0xb0, 0x17, 0x2d, 0xc4, 0x34, 0xf2, 0xc3, 0x29, 0x9d,
|
||||
0xcc, 0x58, 0x18, 0xf2, 0x39, 0xf5, 0xbd, 0xc6, 0x96, 0x3a, 0x71, 0x37, 0x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 0xdb, 0x87, 0x13, 0xa3, 0xf9, 0xf2, 0xff, 0x68, 0xad, 0xf6, 0xee, 0xdb, 0x9f, 0xcf,
|
||||
0xa6, 0xbe, 0x98, 0x2d, 0xae, 0x4e, 0x27, 0x51, 0x70, 0x36, 0xf7, 0xa7, 0x33, 0x11, 0xfa, 0xe1,
|
||||
0x34, 0xe4, 0xe2, 0xf7, 0x28, 0xb9, 0x39, 0x9b, 0x87, 0xde, 0x99, 0x1a, 0x20, 0x67, 0x4b, 0x99,
|
||||
0xab, 0xa2, 0xfa, 0xef, 0xf1, 0xdd, 0x7f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x6d, 0x7d, 0x2a, 0xf5,
|
||||
0xab, 0x08, 0x00, 0x00,
|
||||
}
|
||||
|
@ -1,7 +1,11 @@
|
||||
syntax = "proto3";
|
||||
|
||||
import "rpc.proto";
|
||||
|
||||
package routerrpc;
|
||||
|
||||
option go_package = "github.com/lightningnetwork/lnd/lnrpc/routerrpc";
|
||||
|
||||
message PaymentRequest {
|
||||
/**
|
||||
A serialized BOLT-11 payment request that contains all information
|
||||
@ -85,6 +89,127 @@ message RouteFeeResponse {
|
||||
int64 time_lock_delay = 2;
|
||||
}
|
||||
|
||||
message SendToRouteRequest {
|
||||
/// The payment hash to use for the HTLC.
|
||||
bytes payment_hash = 1;
|
||||
|
||||
/// Route that should be used to attempt to complete the payment.
|
||||
lnrpc.Route route = 2;
|
||||
}
|
||||
|
||||
message SendToRouteResponse {
|
||||
/// The preimage obtained by making the payment.
|
||||
bytes preimage = 1;
|
||||
|
||||
/// The failure message in case the payment failed.
|
||||
Failure failure = 2;
|
||||
}
|
||||
|
||||
message Failure {
|
||||
enum FailureCode {
|
||||
/**
|
||||
The numbers assigned in this enumeration match the failure codes as
|
||||
defined in BOLT #4. Because protobuf 3 requires enums to start with 0,
|
||||
a RESERVED value is added.
|
||||
*/
|
||||
RESERVED = 0;
|
||||
|
||||
UNKNOWN_PAYMENT_HASH = 1;
|
||||
INCORRECT_PAYMENT_AMOUNT = 2;
|
||||
FINAL_INCORRECT_CLTV_EXPIRY = 3;
|
||||
FINAL_INCORRECT_HTLC_AMOUNT = 4;
|
||||
FINAL_EXPIRY_TOO_SOON = 5;
|
||||
INVALID_REALM = 6;
|
||||
EXPIRY_TOO_SOON = 7;
|
||||
INVALID_ONION_VERSION = 8;
|
||||
INVALID_ONION_HMAC = 9;
|
||||
INVALID_ONION_KEY = 10;
|
||||
AMOUNT_BELOW_MINIMUM = 11;
|
||||
FEE_INSUFFICIENT = 12;
|
||||
INCORRECT_CLTV_EXPIRY = 13;
|
||||
CHANNEL_DISABLED = 14;
|
||||
TEMPORARY_CHANNEL_FAILURE = 15;
|
||||
REQUIRED_NODE_FEATURE_MISSING = 16;
|
||||
REQUIRED_CHANNEL_FEATURE_MISSING = 17;
|
||||
UNKNOWN_NEXT_PEER = 18;
|
||||
TEMPORARY_NODE_FAILURE = 19;
|
||||
PERMANENT_NODE_FAILURE = 20;
|
||||
PERMANENT_CHANNEL_FAILURE = 21;
|
||||
}
|
||||
|
||||
/// Failure code as defined in the Lightning spec
|
||||
FailureCode code = 1;
|
||||
|
||||
/**
|
||||
The node pubkey of the intermediate or final node that generated the failure
|
||||
message.
|
||||
**/
|
||||
bytes failure_source_pubkey = 2;
|
||||
|
||||
/// An optional channel update message.
|
||||
ChannelUpdate channel_update = 3;
|
||||
|
||||
/// A failure type-dependent htlc value.
|
||||
uint64 htlc_msat = 4;
|
||||
|
||||
/// The sha256 sum of the onion payload.
|
||||
bytes onion_sha_256 = 5;
|
||||
|
||||
/// A failure type-dependent cltv expiry value.
|
||||
uint32 cltv_expiry = 6;
|
||||
|
||||
/// A failure type-dependent flags value.
|
||||
uint32 flags = 7;
|
||||
}
|
||||
|
||||
|
||||
message ChannelUpdate {
|
||||
// Signature is used to validate the announced data and prove the
|
||||
// ownership of node id.
|
||||
bytes signature = 1;
|
||||
|
||||
// ChainHash denotes the target chain that this channel was opened
|
||||
// within. This value should be the genesis hash of the target chain.
|
||||
// Along with the short channel ID, this uniquely identifies the
|
||||
// channel globally in a blockchain.
|
||||
bytes chain_hash = 2;
|
||||
|
||||
// ShortChannelID is the unique description of the funding transaction.
|
||||
uint64 chan_id = 3;
|
||||
|
||||
// Timestamp allows ordering in the case of multiple announcements. We
|
||||
// should ignore the message if timestamp is not greater than
|
||||
// the last-received.
|
||||
uint32 timestamp = 4;
|
||||
|
||||
// Flags is a bitfield that describes additional meta-data concerning
|
||||
// how the update is to be interpreted. Currently, the
|
||||
// least-significant bit must be set to 0 if the creating node
|
||||
// corresponds to the first node in the previously sent channel
|
||||
// announcement and 1 otherwise. If the second bit is set, then the
|
||||
// channel is set to be disabled.
|
||||
uint32 channel_flags = 5;
|
||||
|
||||
// TimeLockDelta is the minimum number of blocks this node requires to
|
||||
// be added to the expiry of HTLCs. This is a security parameter
|
||||
// determined by the node operator. This value represents the required
|
||||
// gap between the time locks of the incoming and outgoing HTLC's set
|
||||
// to this node.
|
||||
uint32 time_lock_delta = 6;
|
||||
|
||||
// HtlcMinimumMsat is the minimum HTLC value which will be accepted.
|
||||
uint64 htlc_minimum_msat = 7;
|
||||
|
||||
// BaseFee is the base fee that must be used for incoming HTLC's to
|
||||
// this particular channel. This value will be tacked onto the required
|
||||
// for a payment independent of the size of the payment.
|
||||
uint32 base_fee = 8;
|
||||
|
||||
// FeeRate is the fee rate that will be charged per millionth of a
|
||||
// satoshi.
|
||||
uint32 fee_rate = 9;
|
||||
}
|
||||
|
||||
service Router {
|
||||
/**
|
||||
SendPayment attempts to route a payment described by the passed
|
||||
@ -100,4 +225,11 @@ service Router {
|
||||
may cost to send an HTLC to the target end destination.
|
||||
*/
|
||||
rpc EstimateRouteFee(RouteFeeRequest) returns (RouteFeeResponse);
|
||||
|
||||
/**
|
||||
SendToRoute attempts to make a payment via the specified route. This method
|
||||
differs from SendPayment in that it allows users to specify a full route
|
||||
manually. This can be used for things like rebalancing, and atomic swaps.
|
||||
*/
|
||||
rpc SendToRoute(SendToRouteRequest) returns (SendToRouteResponse);
|
||||
}
|
||||
|
@ -26,6 +26,11 @@ type RouterBackend struct {
|
||||
// capacity of a channel to populate in responses.
|
||||
FetchChannelCapacity func(chanID uint64) (btcutil.Amount, error)
|
||||
|
||||
// FetchChannelEndpoints returns the pubkeys of both endpoints of the
|
||||
// given channel id.
|
||||
FetchChannelEndpoints func(chanID uint64) (route.Vertex,
|
||||
route.Vertex, error)
|
||||
|
||||
// FindRoutes is a closure that abstracts away how we locate/query for
|
||||
// routes.
|
||||
FindRoute func(source, target route.Vertex,
|
||||
@ -218,3 +223,101 @@ func (r *RouterBackend) MarshallRoute(route *route.Route) *lnrpc.Route {
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
// UnmarshallHopByChannelLookup unmarshalls an rpc hop for which the pub key is
|
||||
// not known. This function will query the channel graph with channel id to
|
||||
// retrieve both endpoints and determine the hop pubkey using the previous hop
|
||||
// pubkey. If the channel is unknown, an error is returned.
|
||||
func (r *RouterBackend) UnmarshallHopByChannelLookup(hop *lnrpc.Hop,
|
||||
prevPubKeyBytes [33]byte) (*route.Hop, error) {
|
||||
|
||||
// Discard edge policies, because they may be nil.
|
||||
node1, node2, err := r.FetchChannelEndpoints(hop.ChanId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var pubKeyBytes [33]byte
|
||||
switch {
|
||||
case prevPubKeyBytes == node1:
|
||||
pubKeyBytes = node2
|
||||
case prevPubKeyBytes == node2:
|
||||
pubKeyBytes = node1
|
||||
default:
|
||||
return nil, fmt.Errorf("channel edge does not match expected node")
|
||||
}
|
||||
|
||||
return &route.Hop{
|
||||
OutgoingTimeLock: hop.Expiry,
|
||||
AmtToForward: lnwire.MilliSatoshi(hop.AmtToForwardMsat),
|
||||
PubKeyBytes: pubKeyBytes,
|
||||
ChannelID: hop.ChanId,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UnmarshallKnownPubkeyHop unmarshalls an rpc hop that contains the hop pubkey.
|
||||
// The channel graph doesn't need to be queried because all information required
|
||||
// for sending the payment is present.
|
||||
func UnmarshallKnownPubkeyHop(hop *lnrpc.Hop) (*route.Hop, error) {
|
||||
pubKey, err := hex.DecodeString(hop.PubKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot decode pubkey %s", hop.PubKey)
|
||||
}
|
||||
|
||||
var pubKeyBytes [33]byte
|
||||
copy(pubKeyBytes[:], pubKey)
|
||||
|
||||
return &route.Hop{
|
||||
OutgoingTimeLock: hop.Expiry,
|
||||
AmtToForward: lnwire.MilliSatoshi(hop.AmtToForwardMsat),
|
||||
PubKeyBytes: pubKeyBytes,
|
||||
ChannelID: hop.ChanId,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UnmarshallHop unmarshalls an rpc hop that may or may not contain a node
|
||||
// pubkey.
|
||||
func (r *RouterBackend) UnmarshallHop(hop *lnrpc.Hop,
|
||||
prevNodePubKey [33]byte) (*route.Hop, error) {
|
||||
|
||||
if hop.PubKey == "" {
|
||||
// If no pub key is given of the hop, the local channel
|
||||
// graph needs to be queried to complete the information
|
||||
// necessary for routing.
|
||||
return r.UnmarshallHopByChannelLookup(hop, prevNodePubKey)
|
||||
}
|
||||
|
||||
return UnmarshallKnownPubkeyHop(hop)
|
||||
}
|
||||
|
||||
// UnmarshallRoute unmarshalls an rpc route. For hops that don't specify a
|
||||
// pubkey, the channel graph is queried.
|
||||
func (r *RouterBackend) UnmarshallRoute(rpcroute *lnrpc.Route) (
|
||||
*route.Route, error) {
|
||||
|
||||
prevNodePubKey := r.SelfNode
|
||||
|
||||
hops := make([]*route.Hop, len(rpcroute.Hops))
|
||||
for i, hop := range rpcroute.Hops {
|
||||
routeHop, err := r.UnmarshallHop(hop, prevNodePubKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
hops[i] = routeHop
|
||||
|
||||
prevNodePubKey = routeHop.PubKeyBytes
|
||||
}
|
||||
|
||||
route, err := route.NewRouteFromHops(
|
||||
lnwire.MilliSatoshi(rpcroute.TotalAmtMsat),
|
||||
rpcroute.TotalTimeLock,
|
||||
r.SelfNode,
|
||||
hops,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return route, nil
|
||||
}
|
||||
|
@ -11,6 +11,9 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
@ -32,6 +35,10 @@ var (
|
||||
// macaroonOps are the set of capabilities that our minted macaroon (if
|
||||
// it doesn't already exist) will have.
|
||||
macaroonOps = []bakery.Op{
|
||||
{
|
||||
Entity: "offchain",
|
||||
Action: "read",
|
||||
},
|
||||
{
|
||||
Entity: "offchain",
|
||||
Action: "write",
|
||||
@ -40,11 +47,15 @@ var (
|
||||
|
||||
// macPermissions maps RPC calls to the permissions they require.
|
||||
macPermissions = map[string][]bakery.Op{
|
||||
"/routerpc.Router/SendPayment": {{
|
||||
"/routerrpc.Router/SendPayment": {{
|
||||
Entity: "offchain",
|
||||
Action: "write",
|
||||
}},
|
||||
"/routerpc.Router/EstimateRouteFee": {{
|
||||
"/routerrpc.Router/SendToRoute": {{
|
||||
Entity: "offchain",
|
||||
Action: "write",
|
||||
}},
|
||||
"/routerrpc.Router/EstimateRouteFee": {{
|
||||
Entity: "offchain",
|
||||
Action: "read",
|
||||
}},
|
||||
@ -262,3 +273,166 @@ func (s *Server) EstimateRouteFee(ctx context.Context,
|
||||
TimeLockDelay: int64(route.TotalTimeLock),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// SendToRoute sends a payment through a predefined route. The response of this
|
||||
// call contains structured error information.
|
||||
func (s *Server) SendToRoute(ctx context.Context,
|
||||
req *SendToRouteRequest) (*SendToRouteResponse, error) {
|
||||
|
||||
if req.Route == nil {
|
||||
return nil, fmt.Errorf("unable to send, no routes provided")
|
||||
}
|
||||
|
||||
route, err := s.cfg.RouterBackend.UnmarshallRoute(req.Route)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
hash, err := lntypes.MakeHash(req.PaymentHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
preimage, err := s.cfg.Router.SendToRoute(hash, route)
|
||||
|
||||
// In the success case, return the preimage.
|
||||
if err == nil {
|
||||
return &SendToRouteResponse{
|
||||
Preimage: preimage[:],
|
||||
}, nil
|
||||
}
|
||||
|
||||
// In the failure case, marshall the failure message to the rpc format
|
||||
// before returning it to the caller.
|
||||
rpcErr, err := marshallError(err)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &SendToRouteResponse{
|
||||
Failure: rpcErr,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// marshallError marshall an error as received from the switch to rpc structs
|
||||
// suitable for returning to the caller of an rpc method.
|
||||
//
|
||||
// Because of difficulties with using protobuf oneof constructs in some
|
||||
// languages, the decision was made here to use a single message format for all
|
||||
// failure messages with some fields left empty depending on the failure type.
|
||||
func marshallError(sendError error) (*Failure, error) {
|
||||
response := &Failure{}
|
||||
|
||||
fErr, ok := sendError.(*htlcswitch.ForwardingError)
|
||||
if !ok {
|
||||
return nil, sendError
|
||||
}
|
||||
|
||||
switch onionErr := fErr.FailureMessage.(type) {
|
||||
|
||||
case *lnwire.FailUnknownPaymentHash:
|
||||
response.Code = Failure_UNKNOWN_PAYMENT_HASH
|
||||
|
||||
case *lnwire.FailIncorrectPaymentAmount:
|
||||
response.Code = Failure_INCORRECT_PAYMENT_AMOUNT
|
||||
|
||||
case *lnwire.FailFinalIncorrectCltvExpiry:
|
||||
response.Code = Failure_FINAL_INCORRECT_CLTV_EXPIRY
|
||||
response.CltvExpiry = onionErr.CltvExpiry
|
||||
|
||||
case *lnwire.FailFinalIncorrectHtlcAmount:
|
||||
response.Code = Failure_FINAL_INCORRECT_HTLC_AMOUNT
|
||||
response.HtlcMsat = uint64(onionErr.IncomingHTLCAmount)
|
||||
|
||||
case *lnwire.FailFinalExpiryTooSoon:
|
||||
response.Code = Failure_FINAL_EXPIRY_TOO_SOON
|
||||
|
||||
case *lnwire.FailInvalidRealm:
|
||||
response.Code = Failure_INVALID_REALM
|
||||
|
||||
case *lnwire.FailExpiryTooSoon:
|
||||
response.Code = Failure_EXPIRY_TOO_SOON
|
||||
response.ChannelUpdate = marshallChannelUpdate(&onionErr.Update)
|
||||
|
||||
case *lnwire.FailInvalidOnionVersion:
|
||||
response.Code = Failure_INVALID_ONION_VERSION
|
||||
response.OnionSha_256 = onionErr.OnionSHA256[:]
|
||||
|
||||
case *lnwire.FailInvalidOnionHmac:
|
||||
response.Code = Failure_INVALID_ONION_HMAC
|
||||
response.OnionSha_256 = onionErr.OnionSHA256[:]
|
||||
|
||||
case *lnwire.FailInvalidOnionKey:
|
||||
response.Code = Failure_INVALID_ONION_KEY
|
||||
response.OnionSha_256 = onionErr.OnionSHA256[:]
|
||||
|
||||
case *lnwire.FailAmountBelowMinimum:
|
||||
response.Code = Failure_AMOUNT_BELOW_MINIMUM
|
||||
response.ChannelUpdate = marshallChannelUpdate(&onionErr.Update)
|
||||
response.HtlcMsat = uint64(onionErr.HtlcMsat)
|
||||
|
||||
case *lnwire.FailFeeInsufficient:
|
||||
response.Code = Failure_FEE_INSUFFICIENT
|
||||
response.ChannelUpdate = marshallChannelUpdate(&onionErr.Update)
|
||||
response.HtlcMsat = uint64(onionErr.HtlcMsat)
|
||||
|
||||
case *lnwire.FailIncorrectCltvExpiry:
|
||||
response.Code = Failure_INCORRECT_CLTV_EXPIRY
|
||||
response.ChannelUpdate = marshallChannelUpdate(&onionErr.Update)
|
||||
response.CltvExpiry = onionErr.CltvExpiry
|
||||
|
||||
case *lnwire.FailChannelDisabled:
|
||||
response.Code = Failure_CHANNEL_DISABLED
|
||||
response.ChannelUpdate = marshallChannelUpdate(&onionErr.Update)
|
||||
response.Flags = uint32(onionErr.Flags)
|
||||
|
||||
case *lnwire.FailTemporaryChannelFailure:
|
||||
response.Code = Failure_TEMPORARY_CHANNEL_FAILURE
|
||||
response.ChannelUpdate = marshallChannelUpdate(onionErr.Update)
|
||||
|
||||
case *lnwire.FailRequiredNodeFeatureMissing:
|
||||
response.Code = Failure_REQUIRED_NODE_FEATURE_MISSING
|
||||
|
||||
case *lnwire.FailRequiredChannelFeatureMissing:
|
||||
response.Code = Failure_REQUIRED_CHANNEL_FEATURE_MISSING
|
||||
|
||||
case *lnwire.FailUnknownNextPeer:
|
||||
response.Code = Failure_UNKNOWN_NEXT_PEER
|
||||
|
||||
case *lnwire.FailTemporaryNodeFailure:
|
||||
response.Code = Failure_TEMPORARY_NODE_FAILURE
|
||||
|
||||
case *lnwire.FailPermanentNodeFailure:
|
||||
response.Code = Failure_PERMANENT_NODE_FAILURE
|
||||
|
||||
case *lnwire.FailPermanentChannelFailure:
|
||||
response.Code = Failure_PERMANENT_CHANNEL_FAILURE
|
||||
|
||||
default:
|
||||
return nil, errors.New("unknown wire error")
|
||||
}
|
||||
|
||||
response.FailureSourcePubkey = fErr.ErrorSource.SerializeCompressed()
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
||||
// marshallChannelUpdate marshalls a channel update as received over the wire to
|
||||
// the router rpc format.
|
||||
func marshallChannelUpdate(update *lnwire.ChannelUpdate) *ChannelUpdate {
|
||||
if update == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &ChannelUpdate{
|
||||
Signature: update.Signature[:],
|
||||
ChainHash: update.ChainHash[:],
|
||||
ChanId: update.ShortChannelID.ToUint64(),
|
||||
Timestamp: update.Timestamp,
|
||||
ChannelFlags: uint32(update.ChannelFlags),
|
||||
TimeLockDelta: uint32(update.TimeLockDelta),
|
||||
HtlcMinimumMsat: uint64(update.HtlcMinimumMsat),
|
||||
BaseFee: update.BaseFee,
|
||||
FeeRate: update.FeeRate,
|
||||
}
|
||||
}
|
||||
|
1260
lnrpc/rpc.pb.go
1260
lnrpc/rpc.pb.go
File diff suppressed because it is too large
Load Diff
@ -896,13 +896,7 @@ message SendToRouteRequest {
|
||||
/// An optional hex-encoded payment hash to be used for the HTLC.
|
||||
string payment_hash_string = 2;
|
||||
|
||||
/**
|
||||
Deprecated. The set of routes that should be used to attempt to complete the
|
||||
payment. The possibility to pass in multiple routes is deprecated and
|
||||
instead the single route field below should be used in combination with the
|
||||
streaming variant of SendToRoute.
|
||||
*/
|
||||
repeated Route routes = 3 [deprecated = true];
|
||||
reserved 3;
|
||||
|
||||
/// Route that should be used to attempt to complete the payment.
|
||||
Route route = 4;
|
||||
|
@ -3216,13 +3216,6 @@
|
||||
"type": "string",
|
||||
"description": "/ An optional hex-encoded payment hash to be used for the HTLC."
|
||||
},
|
||||
"routes": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/lnrpcRoute"
|
||||
},
|
||||
"description": "*\nDeprecated. The set of routes that should be used to attempt to complete the\npayment. The possibility to pass in multiple routes is deprecated and \ninstead the single route field below should be used in combination with the \nstreaming variant of SendToRoute."
|
||||
},
|
||||
"route": {
|
||||
"$ref": "#/definitions/lnrpcRoute",
|
||||
"description": "/ Route that should be used to attempt to complete the payment."
|
||||
|
@ -231,18 +231,14 @@ func (m *missionControl) NewPaymentSession(routeHints [][]zpay32.HopHint,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// NewPaymentSessionFromRoutes creates a new paymentSession instance that will
|
||||
// skip all path finding, and will instead utilize a set of pre-built routes.
|
||||
// This constructor allows callers to specify their own routes which can be
|
||||
// used for things like channel rebalancing, and swaps.
|
||||
func (m *missionControl) NewPaymentSessionFromRoutes(routes []*route.Route) *paymentSession {
|
||||
// NewPaymentSessionForRoute creates a new paymentSession instance that is just
|
||||
// used for failure reporting to missioncontrol.
|
||||
func (m *missionControl) NewPaymentSessionForRoute(preBuiltRoute *route.Route) *paymentSession {
|
||||
return &paymentSession{
|
||||
pruneViewSnapshot: m.GraphPruneView(),
|
||||
haveRoutes: true,
|
||||
preBuiltRoutes: routes,
|
||||
errFailedPolicyChans: make(map[EdgeLocator]struct{}),
|
||||
mc: m,
|
||||
pathFinder: findPath,
|
||||
preBuiltRoute: preBuiltRoute,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,8 @@ type paymentSession struct {
|
||||
|
||||
mc *missionControl
|
||||
|
||||
haveRoutes bool
|
||||
preBuiltRoutes []*route.Route
|
||||
preBuiltRoute *route.Route
|
||||
preBuiltRouteTried bool
|
||||
|
||||
pathFinder pathFinder
|
||||
}
|
||||
@ -115,19 +115,17 @@ func (p *paymentSession) RequestRoute(payment *LightningPayment,
|
||||
height uint32, finalCltvDelta uint16) (*route.Route, error) {
|
||||
|
||||
switch {
|
||||
// If we have a set of pre-built routes, then we'll just pop off the
|
||||
// next route from the queue, and use it directly.
|
||||
case p.haveRoutes && len(p.preBuiltRoutes) > 0:
|
||||
nextRoute := p.preBuiltRoutes[0]
|
||||
p.preBuiltRoutes[0] = nil // Set to nil to avoid GC leak.
|
||||
p.preBuiltRoutes = p.preBuiltRoutes[1:]
|
||||
|
||||
return nextRoute, nil
|
||||
// If we have a pre-built route, use that directly.
|
||||
case p.preBuiltRoute != nil && !p.preBuiltRouteTried:
|
||||
p.preBuiltRouteTried = true
|
||||
|
||||
// If we were instantiated with a set of pre-built routes, and we've
|
||||
// run out, then we'll return a terminal error.
|
||||
case p.haveRoutes && len(p.preBuiltRoutes) == 0:
|
||||
return nil, fmt.Errorf("pre-built routes exhausted")
|
||||
return p.preBuiltRoute, nil
|
||||
|
||||
// If the pre-built route has been tried already, the payment session is
|
||||
// over.
|
||||
case p.preBuiltRoute != nil:
|
||||
return nil, fmt.Errorf("pre-built route already tried")
|
||||
}
|
||||
|
||||
// Otherwise we actually need to perform path finding, so we'll obtain
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/multimutex"
|
||||
@ -1523,21 +1524,24 @@ func (r *ChannelRouter) SendPayment(payment *LightningPayment) ([32]byte, *route
|
||||
return r.sendPayment(payment, paySession)
|
||||
}
|
||||
|
||||
// SendToRoute attempts to send a payment as described within the passed
|
||||
// LightningPayment through the provided routes. This function is blocking
|
||||
// and will return either: when the payment is successful, or all routes
|
||||
// have been attempted and resulted in a failed payment. If the payment
|
||||
// succeeds, then a non-nil Route will be returned which describes the
|
||||
// path the successful payment traversed within the network to reach the
|
||||
// destination. Additionally, the payment preimage will also be returned.
|
||||
func (r *ChannelRouter) SendToRoute(routes []*route.Route,
|
||||
payment *LightningPayment) ([32]byte, *route.Route, error) {
|
||||
// SendToRoute attempts to send a payment with the given hash through the
|
||||
// provided route. This function is blocking and will return the obtained
|
||||
// preimage if the payment is successful or the full error in case of a failure.
|
||||
func (r *ChannelRouter) SendToRoute(hash lntypes.Hash, route *route.Route) (
|
||||
lntypes.Preimage, error) {
|
||||
|
||||
paySession := r.missionControl.NewPaymentSessionFromRoutes(
|
||||
routes,
|
||||
)
|
||||
// Create a payment session for just this route.
|
||||
paySession := r.missionControl.NewPaymentSessionForRoute(route)
|
||||
|
||||
return r.sendPayment(payment, paySession)
|
||||
// Create a (mostly) dummy payment, as the created payment session is
|
||||
// not going to do path finding.
|
||||
payment := &LightningPayment{
|
||||
PaymentHash: hash,
|
||||
}
|
||||
|
||||
preimage, _, err := r.sendPayment(payment, paySession)
|
||||
|
||||
return preimage, err
|
||||
}
|
||||
|
||||
// sendPayment attempts to send a payment as described within the passed
|
||||
|
@ -18,6 +18,7 @@ import (
|
||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
"github.com/lightningnetwork/lnd/zpay32"
|
||||
@ -407,12 +408,12 @@ func TestChannelUpdateValidation(t *testing.T) {
|
||||
|
||||
// The payment parameter is mostly redundant in SendToRoute. Can be left
|
||||
// empty for this test.
|
||||
payment := &LightningPayment{}
|
||||
var payment lntypes.Hash
|
||||
|
||||
// Send off the payment request to the router. The specified route
|
||||
// should be attempted and the channel update should be received by
|
||||
// router and ignored because it is missing a valid signature.
|
||||
_, _, err = ctx.router.SendToRoute([]*route.Route{rt}, payment)
|
||||
_, err = ctx.router.SendToRoute(payment, rt)
|
||||
if err == nil {
|
||||
t.Fatalf("expected route to fail with channel update")
|
||||
}
|
||||
@ -445,7 +446,7 @@ func TestChannelUpdateValidation(t *testing.T) {
|
||||
}
|
||||
|
||||
// Retry the payment using the same route as before.
|
||||
_, _, err = ctx.router.SendToRoute([]*route.Route{rt}, payment)
|
||||
_, err = ctx.router.SendToRoute(payment, rt)
|
||||
if err == nil {
|
||||
t.Fatalf("expected route to fail with channel update")
|
||||
}
|
||||
|
193
rpcserver.go
193
rpcserver.go
@ -462,6 +462,21 @@ func newRPCServer(s *server, macService *macaroons.Service,
|
||||
}
|
||||
return info.Capacity, nil
|
||||
},
|
||||
FetchChannelEndpoints: func(chanID uint64) (route.Vertex,
|
||||
route.Vertex, error) {
|
||||
|
||||
info, _, _, err := graph.FetchChannelEdgesByID(
|
||||
chanID,
|
||||
)
|
||||
if err != nil {
|
||||
return route.Vertex{}, route.Vertex{},
|
||||
fmt.Errorf("unable to fetch channel "+
|
||||
"edges by channel ID %d: %v",
|
||||
chanID, err)
|
||||
}
|
||||
|
||||
return info.NodeKey1Bytes, info.NodeKey2Bytes, nil
|
||||
},
|
||||
FindRoute: s.chanRouter.FindRoute,
|
||||
}
|
||||
|
||||
@ -2771,7 +2786,7 @@ type paymentStream struct {
|
||||
// lnrpc.SendToRouteRequest can be passed to sendPayment.
|
||||
type rpcPaymentRequest struct {
|
||||
*lnrpc.SendRequest
|
||||
routes []*route.Route
|
||||
route *route.Route
|
||||
}
|
||||
|
||||
// calculateFeeLimit returns the fee limit in millisatoshis. If a percentage
|
||||
@ -2837,9 +2852,7 @@ func (r *rpcServer) SendToRoute(stream lnrpc.Lightning_SendToRouteServer) error
|
||||
return nil, err
|
||||
}
|
||||
|
||||
graph := r.server.chanDB.ChannelGraph()
|
||||
|
||||
return unmarshallSendToRouteRequest(req, graph)
|
||||
return r.unmarshallSendToRouteRequest(req)
|
||||
},
|
||||
send: func(r *lnrpc.SendResponse) error {
|
||||
// Calling stream.Send concurrently is not safe.
|
||||
@ -2851,32 +2864,16 @@ func (r *rpcServer) SendToRoute(stream lnrpc.Lightning_SendToRouteServer) error
|
||||
}
|
||||
|
||||
// unmarshallSendToRouteRequest unmarshalls an rpc sendtoroute request
|
||||
func unmarshallSendToRouteRequest(req *lnrpc.SendToRouteRequest,
|
||||
graph *channeldb.ChannelGraph) (*rpcPaymentRequest, error) {
|
||||
func (r *rpcServer) unmarshallSendToRouteRequest(
|
||||
req *lnrpc.SendToRouteRequest) (*rpcPaymentRequest, error) {
|
||||
|
||||
switch {
|
||||
case len(req.Routes) == 0 && req.Route == nil:
|
||||
return nil, fmt.Errorf("unable to send, no routes provided")
|
||||
case len(req.Routes) > 0 && req.Route != nil:
|
||||
return nil, fmt.Errorf("cannot use both route and routes field")
|
||||
if req.Route == nil {
|
||||
return nil, fmt.Errorf("unable to send, no route provided")
|
||||
}
|
||||
|
||||
var routes []*route.Route
|
||||
if len(req.Routes) > 0 {
|
||||
routes = make([]*route.Route, len(req.Routes))
|
||||
for i, rpcroute := range req.Routes {
|
||||
route, err := unmarshallRoute(rpcroute, graph)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
routes[i] = route
|
||||
}
|
||||
} else {
|
||||
rt, err := unmarshallRoute(req.Route, graph)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
routes = []*route.Route{rt}
|
||||
route, err := r.routerBackend.UnmarshallRoute(req.Route)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &rpcPaymentRequest{
|
||||
@ -2884,7 +2881,7 @@ func unmarshallSendToRouteRequest(req *lnrpc.SendToRouteRequest,
|
||||
PaymentHash: req.PaymentHash,
|
||||
PaymentHashString: req.PaymentHashString,
|
||||
},
|
||||
routes: routes,
|
||||
route: route,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -2903,7 +2900,7 @@ type rpcPaymentIntent struct {
|
||||
routeHints [][]zpay32.HopHint
|
||||
outgoingChannelID *uint64
|
||||
|
||||
routes []*route.Route
|
||||
route *route.Route
|
||||
}
|
||||
|
||||
// extractPaymentIntent attempts to parse the complete details required to
|
||||
@ -2914,7 +2911,7 @@ func extractPaymentIntent(rpcPayReq *rpcPaymentRequest) (rpcPaymentIntent, error
|
||||
payIntent := rpcPaymentIntent{}
|
||||
|
||||
// If a route was specified, then we can use that directly.
|
||||
if len(rpcPayReq.routes) != 0 {
|
||||
if rpcPayReq.route != nil {
|
||||
// If the user is using the REST interface, then they'll be
|
||||
// passing the payment hash as a hex encoded string.
|
||||
if rpcPayReq.PaymentHashString != "" {
|
||||
@ -2930,7 +2927,7 @@ func extractPaymentIntent(rpcPayReq *rpcPaymentRequest) (rpcPaymentIntent, error
|
||||
copy(payIntent.rHash[:], rpcPayReq.PaymentHash)
|
||||
}
|
||||
|
||||
payIntent.routes = rpcPayReq.routes
|
||||
payIntent.route = rpcPayReq.route
|
||||
return payIntent, nil
|
||||
}
|
||||
|
||||
@ -3089,7 +3086,7 @@ func (r *rpcServer) dispatchPaymentIntent(
|
||||
|
||||
// If a route was specified, then we'll pass the route directly to the
|
||||
// router, otherwise we'll create a payment session to execute it.
|
||||
if len(payIntent.routes) == 0 {
|
||||
if payIntent.route == nil {
|
||||
payment := &routing.LightningPayment{
|
||||
Target: payIntent.dest,
|
||||
Amount: payIntent.msat,
|
||||
@ -3110,13 +3107,11 @@ func (r *rpcServer) dispatchPaymentIntent(
|
||||
payment,
|
||||
)
|
||||
} else {
|
||||
payment := &routing.LightningPayment{
|
||||
PaymentHash: payIntent.rHash,
|
||||
}
|
||||
|
||||
preImage, route, routerErr = r.server.chanRouter.SendToRoute(
|
||||
payIntent.routes, payment,
|
||||
preImage, routerErr = r.server.chanRouter.SendToRoute(
|
||||
payIntent.rHash, payIntent.route,
|
||||
)
|
||||
|
||||
route = payIntent.route
|
||||
}
|
||||
|
||||
// If the route failed, then we'll return a nil save err, but a non-nil
|
||||
@ -3127,14 +3122,8 @@ func (r *rpcServer) dispatchPaymentIntent(
|
||||
}, nil
|
||||
}
|
||||
|
||||
// If a route was used to complete this payment, then we'll need to
|
||||
// compute the final amount sent
|
||||
var amt lnwire.MilliSatoshi
|
||||
if len(payIntent.routes) > 0 {
|
||||
amt = route.TotalAmount - route.TotalFees
|
||||
} else {
|
||||
amt = payIntent.msat
|
||||
}
|
||||
// Calculate amount paid to receiver.
|
||||
amt := route.TotalAmount - route.TotalFees
|
||||
|
||||
// Save the completed payment to the database for record keeping
|
||||
// purposes.
|
||||
@ -3328,13 +3317,11 @@ func (r *rpcServer) SendPaymentSync(ctx context.Context,
|
||||
func (r *rpcServer) SendToRouteSync(ctx context.Context,
|
||||
req *lnrpc.SendToRouteRequest) (*lnrpc.SendResponse, error) {
|
||||
|
||||
if len(req.Routes) == 0 {
|
||||
if req.Route == nil {
|
||||
return nil, fmt.Errorf("unable to send, no routes provided")
|
||||
}
|
||||
|
||||
graph := r.server.chanDB.ChannelGraph()
|
||||
|
||||
paymentRequest, err := unmarshallSendToRouteRequest(req, graph)
|
||||
paymentRequest, err := r.unmarshallSendToRouteRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -3883,112 +3870,6 @@ func (r *rpcServer) QueryRoutes(ctx context.Context,
|
||||
return r.routerBackend.QueryRoutes(ctx, in)
|
||||
}
|
||||
|
||||
// unmarshallHopByChannelLookup unmarshalls an rpc hop for which the pub key is
|
||||
// not known. This function will query the channel graph with channel id to
|
||||
// retrieve both endpoints and determine the hop pubkey using the previous hop
|
||||
// pubkey. If the channel is unknown, an error is returned.
|
||||
func unmarshallHopByChannelLookup(graph *channeldb.ChannelGraph, hop *lnrpc.Hop,
|
||||
prevPubKeyBytes [33]byte) (*route.Hop, error) {
|
||||
|
||||
// Discard edge policies, because they may be nil.
|
||||
edgeInfo, _, _, err := graph.FetchChannelEdgesByID(hop.ChanId)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to fetch channel edges by "+
|
||||
"channel ID %d: %v", hop.ChanId, err)
|
||||
}
|
||||
|
||||
var pubKeyBytes [33]byte
|
||||
switch {
|
||||
case prevPubKeyBytes == edgeInfo.NodeKey1Bytes:
|
||||
pubKeyBytes = edgeInfo.NodeKey2Bytes
|
||||
case prevPubKeyBytes == edgeInfo.NodeKey2Bytes:
|
||||
pubKeyBytes = edgeInfo.NodeKey1Bytes
|
||||
default:
|
||||
return nil, fmt.Errorf("channel edge does not match expected node")
|
||||
}
|
||||
|
||||
return &route.Hop{
|
||||
OutgoingTimeLock: hop.Expiry,
|
||||
AmtToForward: lnwire.MilliSatoshi(hop.AmtToForwardMsat),
|
||||
PubKeyBytes: pubKeyBytes,
|
||||
ChannelID: edgeInfo.ChannelID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// unmarshallKnownPubkeyHop unmarshalls an rpc hop that contains the hop pubkey.
|
||||
// The channel graph doesn't need to be queried because all information required
|
||||
// for sending the payment is present.
|
||||
func unmarshallKnownPubkeyHop(hop *lnrpc.Hop) (*route.Hop, error) {
|
||||
pubKey, err := hex.DecodeString(hop.PubKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot decode pubkey %s", hop.PubKey)
|
||||
}
|
||||
|
||||
var pubKeyBytes [33]byte
|
||||
copy(pubKeyBytes[:], pubKey)
|
||||
|
||||
return &route.Hop{
|
||||
OutgoingTimeLock: hop.Expiry,
|
||||
AmtToForward: lnwire.MilliSatoshi(hop.AmtToForwardMsat),
|
||||
PubKeyBytes: pubKeyBytes,
|
||||
ChannelID: hop.ChanId,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// unmarshallHop unmarshalls an rpc hop that may or may not contain a node
|
||||
// pubkey.
|
||||
func unmarshallHop(graph *channeldb.ChannelGraph, hop *lnrpc.Hop,
|
||||
prevNodePubKey [33]byte) (*route.Hop, error) {
|
||||
|
||||
if hop.PubKey == "" {
|
||||
// If no pub key is given of the hop, the local channel
|
||||
// graph needs to be queried to complete the information
|
||||
// necessary for routing.
|
||||
return unmarshallHopByChannelLookup(graph, hop, prevNodePubKey)
|
||||
}
|
||||
|
||||
return unmarshallKnownPubkeyHop(hop)
|
||||
}
|
||||
|
||||
// unmarshallRoute unmarshalls an rpc route. For hops that don't specify a
|
||||
// pubkey, the channel graph is queried.
|
||||
func unmarshallRoute(rpcroute *lnrpc.Route,
|
||||
graph *channeldb.ChannelGraph) (*route.Route, error) {
|
||||
|
||||
sourceNode, err := graph.SourceNode()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to fetch source node from graph "+
|
||||
"while unmarshaling route. %v", err)
|
||||
}
|
||||
|
||||
prevNodePubKey := sourceNode.PubKeyBytes
|
||||
|
||||
hops := make([]*route.Hop, len(rpcroute.Hops))
|
||||
for i, hop := range rpcroute.Hops {
|
||||
routeHop, err := unmarshallHop(graph,
|
||||
hop, prevNodePubKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
hops[i] = routeHop
|
||||
|
||||
prevNodePubKey = routeHop.PubKeyBytes
|
||||
}
|
||||
|
||||
route, err := route.NewRouteFromHops(
|
||||
lnwire.MilliSatoshi(rpcroute.TotalAmtMsat),
|
||||
rpcroute.TotalTimeLock,
|
||||
sourceNode.PubKeyBytes,
|
||||
hops,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return route, nil
|
||||
}
|
||||
|
||||
// GetNetworkInfo returns some basic stats about the known channel graph from
|
||||
// the PoV of the node.
|
||||
func (r *rpcServer) GetNetworkInfo(ctx context.Context,
|
||||
|
Loading…
x
Reference in New Issue
Block a user