routerrpc: adapt to changed interfaces of routing subsystem
This commit is contained in:
parent
9f6a1403e9
commit
087de7cc4d
@ -40,4 +40,8 @@ type Config struct {
|
|||||||
//
|
//
|
||||||
// TODO(roasbeef): assumes router handles saving payment state
|
// TODO(roasbeef): assumes router handles saving payment state
|
||||||
Router *routing.ChannelRouter
|
Router *routing.ChannelRouter
|
||||||
|
|
||||||
|
// RouterBackend contains shared logic between this sub server and the
|
||||||
|
// main rpc server.
|
||||||
|
RouterBackend *RouterBackend
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,13 @@ package routerrpc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec"
|
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
@ -190,12 +190,15 @@ func (s *Server) SendPayment(ctx context.Context,
|
|||||||
return nil, fmt.Errorf("zero value invoices are not supported")
|
return nil, fmt.Errorf("zero value invoices are not supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var destination routing.Vertex
|
||||||
|
copy(destination[:], payReq.Destination.SerializeCompressed())
|
||||||
|
|
||||||
// Now that all the information we need has been parsed, we'll map this
|
// Now that all the information we need has been parsed, we'll map this
|
||||||
// proto request into a proper request that our backing router can
|
// proto request into a proper request that our backing router can
|
||||||
// understand.
|
// understand.
|
||||||
finalDelta := uint16(payReq.MinFinalCLTVExpiry())
|
finalDelta := uint16(payReq.MinFinalCLTVExpiry())
|
||||||
payment := routing.LightningPayment{
|
payment := routing.LightningPayment{
|
||||||
Target: payReq.Destination,
|
Target: destination,
|
||||||
Amount: *payReq.MilliSat,
|
Amount: *payReq.MilliSat,
|
||||||
FeeLimit: lnwire.MilliSatoshi(req.FeeLimitSat),
|
FeeLimit: lnwire.MilliSatoshi(req.FeeLimitSat),
|
||||||
PaymentHash: *payReq.PaymentHash,
|
PaymentHash: *payReq.PaymentHash,
|
||||||
@ -226,22 +229,28 @@ func (s *Server) SendPayment(ctx context.Context,
|
|||||||
func (s *Server) EstimateRouteFee(ctx context.Context,
|
func (s *Server) EstimateRouteFee(ctx context.Context,
|
||||||
req *RouteFeeRequest) (*RouteFeeResponse, error) {
|
req *RouteFeeRequest) (*RouteFeeResponse, error) {
|
||||||
|
|
||||||
// First we'll parse out the raw public key into a value that we can
|
if len(req.Dest) != 33 {
|
||||||
// utilize.
|
return nil, errors.New("invalid length destination key")
|
||||||
destNode, err := btcec.ParsePubKey(req.Dest, btcec.S256())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
var destNode routing.Vertex
|
||||||
|
copy(destNode[:], req.Dest)
|
||||||
|
|
||||||
// Next, we'll convert the amount in satoshis to mSAT, which are the
|
// Next, we'll convert the amount in satoshis to mSAT, which are the
|
||||||
// native unit of LN.
|
// native unit of LN.
|
||||||
amtMsat := lnwire.NewMSatFromSatoshis(btcutil.Amount(req.AmtSat))
|
amtMsat := lnwire.NewMSatFromSatoshis(btcutil.Amount(req.AmtSat))
|
||||||
|
|
||||||
|
// Pick a fee limit
|
||||||
|
//
|
||||||
|
// TODO: Change this into behaviour that makes more sense.
|
||||||
|
feeLimit := lnwire.NewMSatFromSatoshis(btcutil.SatoshiPerBitcoin)
|
||||||
|
|
||||||
// Finally, we'll query for a route to the destination that can carry
|
// Finally, we'll query for a route to the destination that can carry
|
||||||
// that target amount, we'll only request a single route.
|
// that target amount, we'll only request a single route.
|
||||||
routes, err := s.cfg.Router.FindRoutes(
|
routes, err := s.cfg.Router.FindRoutes(
|
||||||
destNode, amtMsat,
|
s.cfg.RouterBackend.SelfNode, destNode, amtMsat,
|
||||||
lnwire.NewMSatFromSatoshis(btcutil.SatoshiPerBitcoin), 1,
|
&routing.RestrictParams{
|
||||||
|
FeeLimit: feeLimit,
|
||||||
|
}, 1,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
62
rpcserver.go
62
rpcserver.go
@ -395,9 +395,9 @@ type rpcServer struct {
|
|||||||
// connect to the main gRPC server to proxy all incoming requests.
|
// connect to the main gRPC server to proxy all incoming requests.
|
||||||
tlsCfg *tls.Config
|
tlsCfg *tls.Config
|
||||||
|
|
||||||
// RouterBackend contains the backend implementation of the router
|
// routerBackend contains the backend implementation of the router
|
||||||
// rpc sub server.
|
// rpc sub server.
|
||||||
RouterBackend *routerrpc.RouterBackend
|
routerBackend *routerrpc.RouterBackend
|
||||||
|
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
}
|
}
|
||||||
@ -417,6 +417,28 @@ func newRPCServer(s *server, macService *macaroons.Service,
|
|||||||
invoiceRegistry *invoices.InvoiceRegistry,
|
invoiceRegistry *invoices.InvoiceRegistry,
|
||||||
tlsCfg *tls.Config) (*rpcServer, error) {
|
tlsCfg *tls.Config) (*rpcServer, error) {
|
||||||
|
|
||||||
|
// Set up router rpc backend.
|
||||||
|
channelGraph := s.chanDB.ChannelGraph()
|
||||||
|
selfNode, err := channelGraph.SourceNode()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
graph := s.chanDB.ChannelGraph()
|
||||||
|
routerBackend := &routerrpc.RouterBackend{
|
||||||
|
MaxPaymentMSat: maxPaymentMSat,
|
||||||
|
SelfNode: selfNode.PubKeyBytes,
|
||||||
|
FetchChannelCapacity: func(chanID uint64) (btcutil.Amount,
|
||||||
|
error) {
|
||||||
|
|
||||||
|
info, _, _, err := graph.FetchChannelEdgesByID(chanID)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return info.Capacity, nil
|
||||||
|
},
|
||||||
|
FindRoutes: s.chanRouter.FindRoutes,
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
subServers []lnrpc.SubServer
|
subServers []lnrpc.SubServer
|
||||||
subServerPerms []lnrpc.MacaroonPerms
|
subServerPerms []lnrpc.MacaroonPerms
|
||||||
@ -425,10 +447,10 @@ func newRPCServer(s *server, macService *macaroons.Service,
|
|||||||
// Before we create any of the sub-servers, we need to ensure that all
|
// Before we create any of the sub-servers, we need to ensure that all
|
||||||
// the dependencies they need are properly populated within each sub
|
// the dependencies they need are properly populated within each sub
|
||||||
// server configuration struct.
|
// server configuration struct.
|
||||||
err := subServerCgs.PopulateDependencies(
|
err = subServerCgs.PopulateDependencies(
|
||||||
s.cc, networkDir, macService, atpl, invoiceRegistry,
|
s.cc, networkDir, macService, atpl, invoiceRegistry,
|
||||||
s.htlcSwitch, activeNetParams.Params, s.chanRouter,
|
s.htlcSwitch, activeNetParams.Params, s.chanRouter,
|
||||||
s.nodeSigner, s.chanDB,
|
routerBackend, s.nodeSigner, s.chanDB,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -483,28 +505,6 @@ func newRPCServer(s *server, macService *macaroons.Service,
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up router rpc backend.
|
|
||||||
channelGraph := s.chanDB.ChannelGraph()
|
|
||||||
selfNode, err := channelGraph.SourceNode()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
graph := s.chanDB.ChannelGraph()
|
|
||||||
RouterBackend := &routerrpc.RouterBackend{
|
|
||||||
MaxPaymentMSat: maxPaymentMSat,
|
|
||||||
SelfNode: selfNode.PubKeyBytes,
|
|
||||||
FetchChannelCapacity: func(chanID uint64) (btcutil.Amount,
|
|
||||||
error) {
|
|
||||||
|
|
||||||
info, _, _, err := graph.FetchChannelEdgesByID(chanID)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return info.Capacity, nil
|
|
||||||
},
|
|
||||||
FindRoutes: s.chanRouter.FindRoutes,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finally, with all the pre-set up complete, we can create the main
|
// Finally, with all the pre-set up complete, we can create the main
|
||||||
// gRPC server, and register the main lnrpc server along side.
|
// gRPC server, and register the main lnrpc server along side.
|
||||||
grpcServer := grpc.NewServer(serverOpts...)
|
grpcServer := grpc.NewServer(serverOpts...)
|
||||||
@ -514,7 +514,7 @@ func newRPCServer(s *server, macService *macaroons.Service,
|
|||||||
tlsCfg: tlsCfg,
|
tlsCfg: tlsCfg,
|
||||||
grpcServer: grpcServer,
|
grpcServer: grpcServer,
|
||||||
server: s,
|
server: s,
|
||||||
RouterBackend: RouterBackend,
|
routerBackend: routerBackend,
|
||||||
quit: make(chan struct{}, 1),
|
quit: make(chan struct{}, 1),
|
||||||
}
|
}
|
||||||
lnrpc.RegisterLightningServer(grpcServer, rootRPCServer)
|
lnrpc.RegisterLightningServer(grpcServer, rootRPCServer)
|
||||||
@ -3241,7 +3241,9 @@ func (r *rpcServer) sendPayment(stream *paymentStream) error {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
marshalledRouted := r.RouterBackend.MarshallRoute(resp.Route)
|
marshalledRouted := r.routerBackend.
|
||||||
|
MarshallRoute(resp.Route)
|
||||||
|
|
||||||
err := stream.send(&lnrpc.SendResponse{
|
err := stream.send(&lnrpc.SendResponse{
|
||||||
PaymentHash: payIntent.rHash[:],
|
PaymentHash: payIntent.rHash[:],
|
||||||
PaymentPreimage: resp.Preimage[:],
|
PaymentPreimage: resp.Preimage[:],
|
||||||
@ -3326,7 +3328,7 @@ func (r *rpcServer) sendPaymentSync(ctx context.Context,
|
|||||||
return &lnrpc.SendResponse{
|
return &lnrpc.SendResponse{
|
||||||
PaymentHash: payIntent.rHash[:],
|
PaymentHash: payIntent.rHash[:],
|
||||||
PaymentPreimage: resp.Preimage[:],
|
PaymentPreimage: resp.Preimage[:],
|
||||||
PaymentRoute: r.RouterBackend.MarshallRoute(resp.Route),
|
PaymentRoute: r.routerBackend.MarshallRoute(resp.Route),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3827,7 +3829,7 @@ func (r *rpcServer) GetNodeInfo(ctx context.Context,
|
|||||||
func (r *rpcServer) QueryRoutes(ctx context.Context,
|
func (r *rpcServer) QueryRoutes(ctx context.Context,
|
||||||
in *lnrpc.QueryRoutesRequest) (*lnrpc.QueryRoutesResponse, error) {
|
in *lnrpc.QueryRoutesRequest) (*lnrpc.QueryRoutesResponse, error) {
|
||||||
|
|
||||||
return r.RouterBackend.QueryRoutes(ctx, in)
|
return r.routerBackend.QueryRoutes(ctx, in)
|
||||||
}
|
}
|
||||||
|
|
||||||
// unmarshallHopByChannelLookup unmarshalls an rpc hop for which the pub key is
|
// unmarshallHopByChannelLookup unmarshalls an rpc hop for which the pub key is
|
||||||
|
@ -70,6 +70,7 @@ func (s *subRPCServerConfigs) PopulateDependencies(cc *chainControl,
|
|||||||
htlcSwitch *htlcswitch.Switch,
|
htlcSwitch *htlcswitch.Switch,
|
||||||
activeNetParams *chaincfg.Params,
|
activeNetParams *chaincfg.Params,
|
||||||
chanRouter *routing.ChannelRouter,
|
chanRouter *routing.ChannelRouter,
|
||||||
|
routerBackend *routerrpc.RouterBackend,
|
||||||
nodeSigner *netann.NodeSigner,
|
nodeSigner *netann.NodeSigner,
|
||||||
chanDB *channeldb.DB) error {
|
chanDB *channeldb.DB) error {
|
||||||
|
|
||||||
@ -185,7 +186,7 @@ func (s *subRPCServerConfigs) PopulateDependencies(cc *chainControl,
|
|||||||
)
|
)
|
||||||
|
|
||||||
case *routerrpc.Config:
|
case *routerrpc.Config:
|
||||||
subCfgValue := extractReflectValue(cfg)
|
subCfgValue := extractReflectValue(subCfg)
|
||||||
|
|
||||||
subCfgValue.FieldByName("NetworkDir").Set(
|
subCfgValue.FieldByName("NetworkDir").Set(
|
||||||
reflect.ValueOf(networkDir),
|
reflect.ValueOf(networkDir),
|
||||||
@ -199,6 +200,9 @@ func (s *subRPCServerConfigs) PopulateDependencies(cc *chainControl,
|
|||||||
subCfgValue.FieldByName("Router").Set(
|
subCfgValue.FieldByName("Router").Set(
|
||||||
reflect.ValueOf(chanRouter),
|
reflect.ValueOf(chanRouter),
|
||||||
)
|
)
|
||||||
|
subCfgValue.FieldByName("RouterBackend").Set(
|
||||||
|
reflect.ValueOf(routerBackend),
|
||||||
|
)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unknown field: %v, %T", fieldName,
|
return fmt.Errorf("unknown field: %v, %T", fieldName,
|
||||||
|
Loading…
Reference in New Issue
Block a user