routerrpc: adapt to changed interfaces of routing subsystem

This commit is contained in:
Joost Jager
2019-03-14 14:19:35 +01:00
parent 9f6a1403e9
commit 087de7cc4d
4 changed files with 59 additions and 40 deletions

View File

@@ -40,4 +40,8 @@ type Config struct {
//
// TODO(roasbeef): assumes router handles saving payment state
Router *routing.ChannelRouter
// RouterBackend contains shared logic between this sub server and the
// main rpc server.
RouterBackend *RouterBackend
}

View File

@@ -4,13 +4,13 @@ package routerrpc
import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd/lnrpc"
"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")
}
var destination routing.Vertex
copy(destination[:], payReq.Destination.SerializeCompressed())
// 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
// understand.
finalDelta := uint16(payReq.MinFinalCLTVExpiry())
payment := routing.LightningPayment{
Target: payReq.Destination,
Target: destination,
Amount: *payReq.MilliSat,
FeeLimit: lnwire.MilliSatoshi(req.FeeLimitSat),
PaymentHash: *payReq.PaymentHash,
@@ -226,22 +229,28 @@ func (s *Server) SendPayment(ctx context.Context,
func (s *Server) EstimateRouteFee(ctx context.Context,
req *RouteFeeRequest) (*RouteFeeResponse, error) {
// First we'll parse out the raw public key into a value that we can
// utilize.
destNode, err := btcec.ParsePubKey(req.Dest, btcec.S256())
if err != nil {
return nil, err
if len(req.Dest) != 33 {
return nil, errors.New("invalid length destination key")
}
var destNode routing.Vertex
copy(destNode[:], req.Dest)
// Next, we'll convert the amount in satoshis to mSAT, which are the
// native unit of LN.
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
// that target amount, we'll only request a single route.
routes, err := s.cfg.Router.FindRoutes(
destNode, amtMsat,
lnwire.NewMSatFromSatoshis(btcutil.SatoshiPerBitcoin), 1,
s.cfg.RouterBackend.SelfNode, destNode, amtMsat,
&routing.RestrictParams{
FeeLimit: feeLimit,
}, 1,
)
if err != nil {
return nil, err