rpcsercer+subservercfg: populate autopilot RPC config

This commit is contained in:
Johan T. Halseth 2018-12-13 12:26:30 +01:00
parent 28a92185cc
commit 8754635de5
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
3 changed files with 14 additions and 4 deletions

2
lnd.go
View File

@ -332,7 +332,7 @@ func lndMain() error {
// exported by the rpcServer.
rpcServer, err := newRPCServer(
server, macaroonService, cfg.SubRPCServers, serverOpts,
proxyOpts, tlsConf,
proxyOpts, atplManager, tlsConf,
)
if err != nil {
srvrLog.Errorf("unable to start RPC server: %v", err)

View File

@ -27,6 +27,7 @@ import (
"github.com/coreos/bbolt"
"github.com/davecgh/go-spew/spew"
proxy "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/lightningnetwork/lnd/autopilot"
"github.com/lightningnetwork/lnd/build"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/htlcswitch"
@ -392,7 +393,7 @@ var _ lnrpc.LightningServer = (*rpcServer)(nil)
// like requiring TLS, etc.
func newRPCServer(s *server, macService *macaroons.Service,
subServerCgs *subRPCServerConfigs, serverOpts []grpc.ServerOption,
restServerOpts []grpc.DialOption,
restServerOpts []grpc.DialOption, atpl *autopilot.Manager,
tlsCfg *tls.Config) (*rpcServer, error) {
var (
@ -404,7 +405,7 @@ func newRPCServer(s *server, macService *macaroons.Service,
// the dependencies they need are properly populated within each sub
// server configuration struct.
err := subServerCgs.PopulateDependencies(
s.cc, networkDir, macService,
s.cc, networkDir, macService, atpl,
)
if err != nil {
return nil, err

View File

@ -4,6 +4,7 @@ import (
"fmt"
"reflect"
"github.com/lightningnetwork/lnd/autopilot"
"github.com/lightningnetwork/lnd/lnrpc/autopilotrpc"
"github.com/lightningnetwork/lnd/lnrpc/signrpc"
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
@ -39,7 +40,8 @@ type subRPCServerConfigs struct {
// NOTE: This MUST be called before any callers are permitted to execute the
// FetchConfig method.
func (s *subRPCServerConfigs) PopulateDependencies(cc *chainControl,
networkDir string, macService *macaroons.Service) error {
networkDir string, macService *macaroons.Service,
atpl *autopilot.Manager) error {
// First, we'll use reflect to obtain a version of the config struct
// that allows us to programmatically inspect its fields.
@ -97,6 +99,13 @@ func (s *subRPCServerConfigs) PopulateDependencies(cc *chainControl,
reflect.ValueOf(cc.keyRing),
)
case *autopilotrpc.Config:
subCfgValue := extractReflectValue(cfg)
subCfgValue.FieldByName("Manager").Set(
reflect.ValueOf(atpl),
)
default:
return fmt.Errorf("unknown field: %v, %T", fieldName,
cfg)