proper cleanup neutrino database in case of error
This commit is contained in:
parent
6a78141a2d
commit
ff172bdd3a
@ -249,9 +249,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
|
||||
@ -259,6 +264,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
|
||||
}
|
||||
|
||||
@ -268,10 +274,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 {
|
||||
@ -495,6 +497,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
|
||||
}
|
||||
|
||||
@ -530,10 +535,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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user