From ad6673c21d2720e42b06d86c64fb0a6f9ed4ae89 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Tue, 16 Mar 2021 14:41:21 +0100 Subject: [PATCH] lnd: close MacResponseChan when wallet is unlocked After unification of the WalletUnlocker and RPC services on the same gRPC server, the WalletUnlocker will no longer be shut down after the wallet has been unlocked. In case --no-macaroons was used, this lead to the caller getting stuck after unlocking the wallet, since we would wait for a response on the MacResponseChan. Earlier we would close the MacResponseChan always when shutting down the WalletUnlocker, but this is no longer done. To fix this we close this channel after the wallet is unlocked, regardless of which combination of --no-macaroons and --noseedbackup that is being used. --- lnd.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lnd.go b/lnd.go index f1aedc5b..bd0c6d03 100644 --- a/lnd.go +++ b/lnd.go @@ -297,9 +297,11 @@ func Main(cfg *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) error { } var ( - walletInitParams WalletUnlockParams - privateWalletPw = lnwallet.DefaultPrivatePassphrase - publicWalletPw = lnwallet.DefaultPublicPassphrase + walletInitParams = WalletUnlockParams{ + MacResponseChan: make(chan []byte), + } + privateWalletPw = lnwallet.DefaultPrivatePassphrase + publicWalletPw = lnwallet.DefaultPublicPassphrase ) // If the user didn't request a seed, then we'll manually assume a @@ -415,10 +417,6 @@ func Main(cfg *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) error { } } - // Now that the wallet password has been provided, transition the RPC - // state into Unlocked. - interceptorChain.SetWalletUnlocked() - var macaroonService *macaroons.Service if !cfg.NoMacaroons { // Create the macaroon authentication/authorization service. @@ -511,6 +509,16 @@ func Main(cfg *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) error { interceptorChain.AddMacaroonService(macaroonService) } + // Now that the wallet password has been provided, transition the RPC + // state into Unlocked. + interceptorChain.SetWalletUnlocked() + + // Since calls to the WalletUnlocker service wait for a response on the + // macaroon channel, we close it here to make sure they return in case + // we did not return the admin macaroon above. This will be the case if + // --no-macaroons is used. + close(walletInitParams.MacResponseChan) + // With the information parsed from the configuration, create valid // instances of the pertinent interfaces required to operate the // Lightning Network Daemon.