From 71ba2a8e6049ab06e819aaee8717fd0bd58beeaf Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Tue, 6 Oct 2020 17:23:34 +0200 Subject: [PATCH] lnd: prepare for proper wallet unlocker cleanup As a preparation for the next commit where we add proper wallet unlocker shutdown handling, we move the calls that require cleanup down after the creation of the wallet unlocker service itself. --- lnd.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lnd.go b/lnd.go index 1a3066b8..c7986dad 100644 --- a/lnd.go +++ b/lnd.go @@ -1043,19 +1043,6 @@ func waitForWalletPassword(cfg *Config, restEndpoints []net.Addr, restProxyDest string, tlsConf *tls.Config, getListeners rpcListeners) (*WalletUnlockParams, error) { - // Start a gRPC server listening for HTTP/2 connections, solely used - // for getting the encryption password from the client. - listeners, cleanup, err := getListeners() - if err != nil { - return nil, err - } - defer cleanup() - - // Set up a new PasswordService, which will listen for passwords - // provided over RPC. - grpcServer := grpc.NewServer(serverOpts...) - defer grpcServer.GracefulStop() - chainConfig := cfg.Bitcoin if cfg.registeredChains.PrimaryChain() == chainreg.LitecoinChain { chainConfig = cfg.Litecoin @@ -1070,11 +1057,24 @@ func waitForWalletPassword(cfg *Config, restEndpoints []net.Addr, cfg.AdminMacPath, cfg.ReadMacPath, cfg.InvoiceMacPath, } pwService := walletunlocker.New( - chainConfig.ChainDir, cfg.ActiveNetParams.Params, !cfg.SyncFreelist, - macaroonFiles, + chainConfig.ChainDir, cfg.ActiveNetParams.Params, + !cfg.SyncFreelist, macaroonFiles, ) + + // Set up a new PasswordService, which will listen for passwords + // provided over RPC. + grpcServer := grpc.NewServer(serverOpts...) + defer grpcServer.GracefulStop() lnrpc.RegisterWalletUnlockerServer(grpcServer, pwService) + // Start a gRPC server listening for HTTP/2 connections, solely used + // for getting the encryption password from the client. + listeners, cleanup, err := getListeners() + if err != nil { + return nil, err + } + defer cleanup() + // Use a WaitGroup so we can be sure the instructions on how to input the // password is the last thing to be printed to the console. var wg sync.WaitGroup