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.
This commit is contained in:
parent
c4ea5e1e2c
commit
85b306bb48
@ -322,24 +322,7 @@ func NewLightningWallet(cdb *channeldb.DB, notifier chainntnfs.ChainNotifier,
|
|||||||
wallet WalletController, signer Signer, bio BlockChainIO,
|
wallet WalletController, signer Signer, bio BlockChainIO,
|
||||||
netParams *chaincfg.Params) (*LightningWallet, error) {
|
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{
|
return &LightningWallet{
|
||||||
rootKey: rootMasterKey,
|
|
||||||
chainNotifier: notifier,
|
chainNotifier: notifier,
|
||||||
Signer: signer,
|
Signer: signer,
|
||||||
WalletController: wallet,
|
WalletController: wallet,
|
||||||
@ -367,6 +350,20 @@ func (l *LightningWallet) Startup() error {
|
|||||||
return err
|
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)
|
l.wg.Add(1)
|
||||||
// TODO(roasbeef): multiple request handlers?
|
// TODO(roasbeef): multiple request handlers?
|
||||||
go l.requestHandler()
|
go l.requestHandler()
|
||||||
|
Loading…
Reference in New Issue
Block a user