From b1860a95e0075a30c0d427833db50a0559e500dc Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Tue, 13 Nov 2018 20:07:54 -0800 Subject: [PATCH] lnwallet/btcwallet: add lightning addr scope before wallet start In this commit, we add the lightning address scope before the wallet starts to prevent a race condition between the wallet syncing and adding the scope itself. This became more apparent with the recent btcwallet fixes, as several database transactions now occur between the wallet being started and it syncing. --- lnwallet/btcwallet/btcwallet.go | 34 ++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lnwallet/btcwallet/btcwallet.go b/lnwallet/btcwallet/btcwallet.go index 74364ec0..b60ccb54 100644 --- a/lnwallet/btcwallet/btcwallet.go +++ b/lnwallet/btcwallet/btcwallet.go @@ -153,26 +153,13 @@ func (b *BtcWallet) InternalWallet() *base.Wallet { // // This is a part of the WalletController interface. func (b *BtcWallet) Start() error { - // Establish an RPC connection in addition to starting the goroutines - // in the underlying wallet. - if err := b.chain.Start(); err != nil { - return err - } - - // Start the underlying btcwallet core. - b.wallet.Start() - - // Pass the rpc client into the wallet so it can sync up to the - // current main chain. - b.wallet.SynchronizeRPC(b.chain) - + // We'll start by unlocking the wallet and ensuring that the KeyScope: + // (1017, 1) exists within the internal waddrmgr. We'll need this in + // order to properly generate the keys required for signing various + // contracts. if err := b.wallet.Unlock(b.cfg.PrivatePass, nil); err != nil { return err } - - // We'll now ensure that the KeyScope: (1017, 1) exists within the - // internal waddrmgr. We'll need this in order to properly generate the - // keys required for signing various contracts. _, err := b.wallet.Manager.FetchScopedKeyManager(b.chainKeyScope) if err != nil { // If the scope hasn't yet been created (it wouldn't been @@ -191,6 +178,19 @@ func (b *BtcWallet) Start() error { } } + // Establish an RPC connection in addition to starting the goroutines + // in the underlying wallet. + if err := b.chain.Start(); err != nil { + return err + } + + // Start the underlying btcwallet core. + b.wallet.Start() + + // Pass the rpc client into the wallet so it can sync up to the + // current main chain. + b.wallet.SynchronizeRPC(b.chain) + return nil }