Merge pull request #2517 from roeierez/chain_control_cleanup
Proper cleanup neutrino database in case of error
This commit is contained in:
commit
c1ab49909f
@ -250,9 +250,14 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
|
|||||||
neutrino.BanDuration = 5 * time.Second
|
neutrino.BanDuration = 5 * time.Second
|
||||||
svc, err := neutrino.NewChainService(config)
|
svc, err := neutrino.NewChainService(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
nodeDatabase.Close()
|
||||||
return nil, nil, fmt.Errorf("unable to create neutrino: %v", err)
|
return nil, nil, fmt.Errorf("unable to create neutrino: %v", err)
|
||||||
}
|
}
|
||||||
svc.Start()
|
svc.Start()
|
||||||
|
cleanUp = func() {
|
||||||
|
svc.Stop()
|
||||||
|
nodeDatabase.Close()
|
||||||
|
}
|
||||||
|
|
||||||
// Next we'll create the instances of the ChainNotifier and
|
// Next we'll create the instances of the ChainNotifier and
|
||||||
// FilteredChainView interface which is backed by the neutrino
|
// 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.chainNotifier = neutrinonotify.New(svc, hintCache, hintCache)
|
||||||
cc.chainView, err = chainview.NewCfFilteredChainView(svc)
|
cc.chainView, err = chainview.NewCfFilteredChainView(svc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
cleanUp()
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,10 +275,6 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
|
|||||||
walletConfig.ChainSource = chain.NewNeutrinoClient(
|
walletConfig.ChainSource = chain.NewNeutrinoClient(
|
||||||
activeNetParams.Params, svc,
|
activeNetParams.Params, svc,
|
||||||
)
|
)
|
||||||
cleanUp = func() {
|
|
||||||
svc.Stop()
|
|
||||||
nodeDatabase.Close()
|
|
||||||
}
|
|
||||||
case "bitcoind", "litecoind":
|
case "bitcoind", "litecoind":
|
||||||
var bitcoindMode *bitcoindConfig
|
var bitcoindMode *bitcoindConfig
|
||||||
switch {
|
switch {
|
||||||
@ -496,6 +498,9 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
|
|||||||
wc, err := btcwallet.New(*walletConfig)
|
wc, err := btcwallet.New(*walletConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("unable to create wallet controller: %v\n", err)
|
fmt.Printf("unable to create wallet controller: %v\n", err)
|
||||||
|
if cleanUp != nil {
|
||||||
|
cleanUp()
|
||||||
|
}
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -531,10 +536,16 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
|
|||||||
lnWallet, err := lnwallet.NewLightningWallet(walletCfg)
|
lnWallet, err := lnwallet.NewLightningWallet(walletCfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("unable to create wallet: %v\n", err)
|
fmt.Printf("unable to create wallet: %v\n", err)
|
||||||
|
if cleanUp != nil {
|
||||||
|
cleanUp()
|
||||||
|
}
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
if err := lnWallet.Startup(); err != nil {
|
if err := lnWallet.Startup(); err != nil {
|
||||||
fmt.Printf("unable to start wallet: %v\n", err)
|
fmt.Printf("unable to start wallet: %v\n", err)
|
||||||
|
if cleanUp != nil {
|
||||||
|
cleanUp()
|
||||||
|
}
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user