Merge pull request #2517 from roeierez/chain_control_cleanup

Proper cleanup neutrino database in case of error
This commit is contained in:
Johan T. Halseth 2019-02-07 17:26:44 +01:00 committed by GitHub
commit c1ab49909f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -250,9 +250,14 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
neutrino.BanDuration = 5 * time.Second
svc, err := neutrino.NewChainService(config)
if err != nil {
nodeDatabase.Close()
return nil, nil, fmt.Errorf("unable to create neutrino: %v", err)
}
svc.Start()
cleanUp = func() {
svc.Stop()
nodeDatabase.Close()
}
// Next we'll create the instances of the ChainNotifier and
// FilteredChainView interface which is backed by the neutrino
@ -260,6 +265,7 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
cc.chainNotifier = neutrinonotify.New(svc, hintCache, hintCache)
cc.chainView, err = chainview.NewCfFilteredChainView(svc)
if err != nil {
cleanUp()
return nil, nil, err
}
@ -269,10 +275,6 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
walletConfig.ChainSource = chain.NewNeutrinoClient(
activeNetParams.Params, svc,
)
cleanUp = func() {
svc.Stop()
nodeDatabase.Close()
}
case "bitcoind", "litecoind":
var bitcoindMode *bitcoindConfig
switch {
@ -496,6 +498,9 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
wc, err := btcwallet.New(*walletConfig)
if err != nil {
fmt.Printf("unable to create wallet controller: %v\n", err)
if cleanUp != nil {
cleanUp()
}
return nil, nil, err
}
@ -531,10 +536,16 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
lnWallet, err := lnwallet.NewLightningWallet(walletCfg)
if err != nil {
fmt.Printf("unable to create wallet: %v\n", err)
if cleanUp != nil {
cleanUp()
}
return nil, nil, err
}
if err := lnWallet.Startup(); err != nil {
fmt.Printf("unable to start wallet: %v\n", err)
if cleanUp != nil {
cleanUp()
}
return nil, nil, err
}