From 85b306bb488cfcb5b77f1e68ceb5048a93376a8a Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sun, 23 Apr 2017 19:15:26 -0700 Subject: [PATCH] lnwallet: fetch the root key during startup rather than on creation This commit modifies the initialization logic of the LightningWallet to fetch the root key during startup rather than during creation. We make this change in order to give enough time for the underlying WalletController to properly boot up before we ask it to do any work. --- lnwallet/wallet.go | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/lnwallet/wallet.go b/lnwallet/wallet.go index 50bc8d349..8999e3a3c 100644 --- a/lnwallet/wallet.go +++ b/lnwallet/wallet.go @@ -322,24 +322,7 @@ func NewLightningWallet(cdb *channeldb.DB, notifier chainntnfs.ChainNotifier, wallet WalletController, signer Signer, bio BlockChainIO, netParams *chaincfg.Params) (*LightningWallet, error) { - // TODO(roasbeef): need a another wallet level config - - // Fetch the root derivation key from the wallet's HD chain. We'll use - // this to generate specific Lightning related secrets on the fly. - rootKey, err := wallet.FetchRootKey() - if err != nil { - return nil, err - } - - // TODO(roasbeef): always re-derive on the fly? - rootKeyRaw := rootKey.Serialize() - rootMasterKey, err := hdkeychain.NewMaster(rootKeyRaw, netParams) - if err != nil { - return nil, err - } - return &LightningWallet{ - rootKey: rootMasterKey, chainNotifier: notifier, Signer: signer, WalletController: wallet, @@ -367,6 +350,20 @@ func (l *LightningWallet) Startup() error { return err } + // Fetch the root derivation key from the wallet's HD chain. We'll use + // this to generate specific Lightning related secrets on the fly. + rootKey, err := l.FetchRootKey() + if err != nil { + return err + } + + // TODO(roasbeef): always re-derive on the fly? + rootKeyRaw := rootKey.Serialize() + l.rootKey, err = hdkeychain.NewMaster(rootKeyRaw, l.netParams) + if err != nil { + return err + } + l.wg.Add(1) // TODO(roasbeef): multiple request handlers? go l.requestHandler()