lnd+rpcserver: don't use global cfg

This commit is contained in:
Oliver Gugger committed 2020-05-14 16:18:01 +02:00
1 parent 7ce70321ac
commit 7e4d0aba2f
2 files changed
+19 -16

No files matched your search

+1 -1
View File
@@ -669,7 +669,7 @@ func Main(config *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) erro
// Initialize, and register our implementation of the gRPC interface // Initialize, and register our implementation of the gRPC interface
// exported by the rpcServer. // exported by the rpcServer.
rpcServer, err := newRPCServer( rpcServer, err := newRPCServer(
server, macaroonService, cfg.SubRPCServers, serverOpts, cfg, server, macaroonService, cfg.SubRPCServers, serverOpts,
restDialOpts, restProxyDest, atplManager, server.invoices, restDialOpts, restProxyDest, atplManager, server.invoices,
tower, tlsCfg, rpcListeners, chainedAcceptor, tower, tlsCfg, rpcListeners, chainedAcceptor,
) )
+18 -15
View File
@@ -461,6 +461,8 @@ type rpcServer struct {
server *server server *server
cfg *Config
// subServers are a set of sub-RPC servers that use the same gRPC and // subServers are a set of sub-RPC servers that use the same gRPC and
// listening sockets as the main RPC server, but which maintain their // listening sockets as the main RPC server, but which maintain their
// own independent service. This allows us to expose a set of // own independent service. This allows us to expose a set of
@@ -521,7 +523,7 @@ var _ lnrpc.LightningServer = (*rpcServer)(nil)
// of the sub-servers that it maintains. The set of serverOpts should be the // of the sub-servers that it maintains. The set of serverOpts should be the
// base level options passed to the grPC server. This typically includes things // base level options passed to the grPC server. This typically includes things
// like requiring TLS, etc. // like requiring TLS, etc.
func newRPCServer(s *server, macService *macaroons.Service, func newRPCServer(cfg *Config, s *server, macService *macaroons.Service,
subServerCgs *subRPCServerConfigs, serverOpts []grpc.ServerOption, subServerCgs *subRPCServerConfigs, serverOpts []grpc.ServerOption,
restDialOpts []grpc.DialOption, restProxyDest string, restDialOpts []grpc.DialOption, restProxyDest string,
atpl *autopilot.Manager, invoiceRegistry *invoices.InvoiceRegistry, atpl *autopilot.Manager, invoiceRegistry *invoices.InvoiceRegistry,
@@ -700,6 +702,7 @@ func newRPCServer(s *server, macService *macaroons.Service,
// 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...)
rootRPCServer := &rpcServer{ rootRPCServer := &rpcServer{
cfg: cfg,
restDialOpts: restDialOpts, restDialOpts: restDialOpts,
listeners: listeners, listeners: listeners,
listenerCleanUp: []func(){cleanup}, listenerCleanUp: []func(){cleanup},
@@ -783,9 +786,9 @@ func (r *rpcServer) Start() error {
} }
// If Prometheus monitoring is enabled, start the Prometheus exporter. // If Prometheus monitoring is enabled, start the Prometheus exporter.
if cfg.Prometheus.Enabled() { if r.cfg.Prometheus.Enabled() {
err := monitoring.ExportPrometheusMetrics( err := monitoring.ExportPrometheusMetrics(
r.grpcServer, cfg.Prometheus, r.grpcServer, r.cfg.Prometheus,
) )
if err != nil { if err != nil {
return err return err
@@ -839,7 +842,7 @@ func (r *rpcServer) Start() error {
// Now spin up a network listener for each requested port and start a // Now spin up a network listener for each requested port and start a
// goroutine that serves REST with the created mux there. // goroutine that serves REST with the created mux there.
for _, restEndpoint := range cfg.RESTListeners { for _, restEndpoint := range r.cfg.RESTListeners {
lis, err := lncfg.TLSListenOnAddress(restEndpoint, r.tlsCfg) lis, err := lncfg.TLSListenOnAddress(restEndpoint, r.tlsCfg)
if err != nil { if err != nil {
ltndLog.Errorf("gRPC proxy unable to listen on %s", ltndLog.Errorf("gRPC proxy unable to listen on %s",
@@ -1477,7 +1480,7 @@ func (r *rpcServer) DisconnectPeer(ctx context.Context,
// In order to avoid erroneously disconnecting from a peer that we have // In order to avoid erroneously disconnecting from a peer that we have
// an active channel with, if we have any channels active with this // an active channel with, if we have any channels active with this
// peer, then we'll disallow disconnecting from them. // peer, then we'll disallow disconnecting from them.
if len(nodeChannels) > 0 && !cfg.UnsafeDisconnect { if len(nodeChannels) > 0 && !r.cfg.UnsafeDisconnect {
return nil, fmt.Errorf("cannot disconnect from peer(%x), "+ return nil, fmt.Errorf("cannot disconnect from peer(%x), "+
"all active channels with the peer need to be closed "+ "all active channels with the peer need to be closed "+
"first", pubKeyBytes) "first", pubKeyBytes)
@@ -2404,8 +2407,8 @@ func (r *rpcServer) GetInfo(ctx context.Context,
} }
network := normalizeNetwork(activeNetParams.Name) network := normalizeNetwork(activeNetParams.Name)
activeChains := make([]*lnrpc.Chain, cfg.registeredChains.NumActiveChains()) activeChains := make([]*lnrpc.Chain, r.cfg.registeredChains.NumActiveChains())
for i, chain := range cfg.registeredChains.ActiveChains() { for i, chain := range r.cfg.registeredChains.ActiveChains() {
activeChains[i] = &lnrpc.Chain{ activeChains[i] = &lnrpc.Chain{
Chain: chain.String(), Chain: chain.String(),
Network: network, Network: network,
@@ -3813,7 +3816,7 @@ func (r *rpcServer) extractPaymentIntent(rpcPayReq *rpcPaymentRequest) (rpcPayme
// Take the CLTV limit from the request if set, otherwise use the max. // Take the CLTV limit from the request if set, otherwise use the max.
cltvLimit, err := routerrpc.ValidateCLTVLimit( cltvLimit, err := routerrpc.ValidateCLTVLimit(
rpcPayReq.CltvLimit, cfg.MaxOutgoingCltvExpiry, rpcPayReq.CltvLimit, r.cfg.MaxOutgoingCltvExpiry,
) )
if err != nil { if err != nil {
return payIntent, err return payIntent, err
@@ -3942,7 +3945,7 @@ func (r *rpcServer) extractPaymentIntent(rpcPayReq *rpcPaymentRequest) (rpcPayme
// use when creating an invoice. We do not assume the default of // use when creating an invoice. We do not assume the default of
// 9 blocks that is defined in BOLT-11, because this is never // 9 blocks that is defined in BOLT-11, because this is never
// enough for other lnd nodes. // enough for other lnd nodes.
payIntent.cltvDelta = uint16(cfg.Bitcoin.TimeLockDelta) payIntent.cltvDelta = uint16(r.cfg.Bitcoin.TimeLockDelta)
} }
// If the user is manually specifying payment details, then the payment // If the user is manually specifying payment details, then the payment
@@ -4364,9 +4367,9 @@ func (r *rpcServer) sendPaymentSync(ctx context.Context,
func (r *rpcServer) AddInvoice(ctx context.Context, func (r *rpcServer) AddInvoice(ctx context.Context,
invoice *lnrpc.Invoice) (*lnrpc.AddInvoiceResponse, error) { invoice *lnrpc.Invoice) (*lnrpc.AddInvoiceResponse, error) {
defaultDelta := cfg.Bitcoin.TimeLockDelta defaultDelta := r.cfg.Bitcoin.TimeLockDelta
if cfg.registeredChains.PrimaryChain() == litecoinChain { if r.cfg.registeredChains.PrimaryChain() == litecoinChain {
defaultDelta = cfg.Litecoin.TimeLockDelta defaultDelta = r.cfg.Litecoin.TimeLockDelta
} }
addInvoiceCfg := &invoicesrpc.AddInvoiceConfig{ addInvoiceCfg := &invoicesrpc.AddInvoiceConfig{
@@ -6070,14 +6073,14 @@ func (r *rpcServer) ChannelAcceptor(stream lnrpc.Lightning_ChannelAcceptorServer
} }
// timeout is the time after which ChannelAcceptRequests expire. // timeout is the time after which ChannelAcceptRequests expire.
timeout := time.After(cfg.AcceptorTimeout) timeout := time.After(r.cfg.AcceptorTimeout)
// Send the request to the newRequests channel. // Send the request to the newRequests channel.
select { select {
case newRequests <- newRequest: case newRequests <- newRequest:
case <-timeout: case <-timeout:
rpcsLog.Errorf("RPCAcceptor returned false - reached timeout of %d", rpcsLog.Errorf("RPCAcceptor returned false - reached timeout of %d",
cfg.AcceptorTimeout) r.cfg.AcceptorTimeout)
return false return false
case <-quit: case <-quit:
return false return false
@@ -6092,7 +6095,7 @@ func (r *rpcServer) ChannelAcceptor(stream lnrpc.Lightning_ChannelAcceptorServer
return resp return resp
case <-timeout: case <-timeout:
rpcsLog.Errorf("RPCAcceptor returned false - reached timeout of %d", rpcsLog.Errorf("RPCAcceptor returned false - reached timeout of %d",
cfg.AcceptorTimeout) r.cfg.AcceptorTimeout)
return false return false
case <-quit: case <-quit:
return false return false