From 47f1b81a51631a4154b8c86a6559b5e18b234538 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 23 Sep 2021 16:54:37 +0200 Subject: [PATCH] walletunlocker+lnd: move WalletUnlockParams As a preparation for adding the wallet unlock params to the chain control, we first need to move them out of the main package. --- lnd.go | 47 ++++----------------------------------- walletunlocker/service.go | 39 ++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/lnd.go b/lnd.go index d8403d478..5f698cc3e 100644 --- a/lnd.go +++ b/lnd.go @@ -314,7 +314,7 @@ func Main(cfg *Config, lisCfg ListenerCfg, interceptor signal.Interceptor) error } var ( - walletInitParams = WalletUnlockParams{ + walletInitParams = walletunlocker.WalletUnlockParams{ // In case we do auto-unlock, we need to be able to send // into the channel without blocking so we buffer it. MacResponseChan: make(chan []byte, 1), @@ -1278,45 +1278,6 @@ func adminPermissions() []bakery.Op { return admin } -// WalletUnlockParams holds the variables used to parameterize the unlocking of -// lnd's wallet after it has already been created. -type WalletUnlockParams struct { - // Password is the public and private wallet passphrase. - Password []byte - - // Birthday specifies the approximate time that this wallet was created. - // This is used to bound any rescans on startup. - Birthday time.Time - - // RecoveryWindow specifies the address lookahead when entering recovery - // mode. A recovery will be attempted if this value is non-zero. - RecoveryWindow uint32 - - // Wallet is the loaded and unlocked Wallet. This is returned - // from the unlocker service to avoid it being unlocked twice (once in - // the unlocker service to check if the password is correct and again - // later when lnd actually uses it). Because unlocking involves scrypt - // which is resource intensive, we want to avoid doing it twice. - Wallet *wallet.Wallet - - // ChansToRestore a set of static channel backups that should be - // restored before the main server instance starts up. - ChansToRestore walletunlocker.ChannelsToRecover - - // UnloadWallet is a function for unloading the wallet, which should - // be called on shutdown. - UnloadWallet func() error - - // StatelessInit signals that the user requested the daemon to be - // initialized stateless, which means no unencrypted macaroons should be - // written to disk. - StatelessInit bool - - // MacResponseChan is the channel for sending back the admin macaroon to - // the WalletUnlocker service. - MacResponseChan chan []byte -} - // createWalletUnlockerService creates a WalletUnlockerService from the passed // config. func createWalletUnlockerService(cfg *Config) *walletunlocker.UnlockerService { @@ -1499,7 +1460,7 @@ func startRestProxy(cfg *Config, rpcServer *rpcServer, restDialOpts []grpc.DialO func waitForWalletPassword(cfg *Config, pwService *walletunlocker.UnlockerService, loaderOpts []btcwallet.LoaderOption, shutdownChan <-chan struct{}) ( - *WalletUnlockParams, error) { + *walletunlocker.WalletUnlockParams, error) { // Wait for user to provide the password. ltndLog.Infof("Waiting for wallet encryption password. Use `lncli " + @@ -1591,7 +1552,7 @@ func waitForWalletPassword(cfg *Config, "flag for new wallet as it has no effect") } - return &WalletUnlockParams{ + return &walletunlocker.WalletUnlockParams{ Password: password, Birthday: birthday, RecoveryWindow: recoveryWindow, @@ -1616,7 +1577,7 @@ func waitForWalletPassword(cfg *Config, "start of lnd") } - return &WalletUnlockParams{ + return &walletunlocker.WalletUnlockParams{ Password: unlockMsg.Passphrase, RecoveryWindow: unlockMsg.RecoveryWindow, Wallet: unlockMsg.Wallet, diff --git a/walletunlocker/service.go b/walletunlocker/service.go index 5e6c5466a..beb5b6a51 100644 --- a/walletunlocker/service.go +++ b/walletunlocker/service.go @@ -27,6 +27,45 @@ var ( ErrUnlockTimeout = errors.New("got no unlock message before timeout") ) +// WalletUnlockParams holds the variables used to parameterize the unlocking of +// lnd's wallet after it has already been created. +type WalletUnlockParams struct { + // Password is the public and private wallet passphrase. + Password []byte + + // Birthday specifies the approximate time that this wallet was created. + // This is used to bound any rescans on startup. + Birthday time.Time + + // RecoveryWindow specifies the address lookahead when entering recovery + // mode. A recovery will be attempted if this value is non-zero. + RecoveryWindow uint32 + + // Wallet is the loaded and unlocked Wallet. This is returned + // from the unlocker service to avoid it being unlocked twice (once in + // the unlocker service to check if the password is correct and again + // later when lnd actually uses it). Because unlocking involves scrypt + // which is resource intensive, we want to avoid doing it twice. + Wallet *wallet.Wallet + + // ChansToRestore a set of static channel backups that should be + // restored before the main server instance starts up. + ChansToRestore ChannelsToRecover + + // UnloadWallet is a function for unloading the wallet, which should + // be called on shutdown. + UnloadWallet func() error + + // StatelessInit signals that the user requested the daemon to be + // initialized stateless, which means no unencrypted macaroons should be + // written to disk. + StatelessInit bool + + // MacResponseChan is the channel for sending back the admin macaroon to + // the WalletUnlocker service. + MacResponseChan chan []byte +} + // ChannelsToRecover wraps any set of packed (serialized+encrypted) channel // back ups together. These can be passed in when unlocking the wallet, or // creating a new wallet for the first time with an existing seed.