chainregistry+lnd: remove unused cleanUp variable

This commit is contained in:
Valentine Wallace 2019-04-10 17:32:41 -07:00
parent c6b653457b
commit 1179895d20
2 changed files with 30 additions and 45 deletions

@ -132,7 +132,7 @@ type chainControl struct {
func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB, func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
privateWalletPw, publicWalletPw []byte, birthday time.Time, privateWalletPw, publicWalletPw []byte, birthday time.Time,
recoveryWindow uint32, wallet *wallet.Wallet, recoveryWindow uint32, wallet *wallet.Wallet,
neutrinoCS *neutrino.ChainService) (*chainControl, func(), error) { neutrinoCS *neutrino.ChainService) (*chainControl, error) {
// Set the RPC config from the "home" chain. Multi-chain isn't yet // Set the RPC config from the "home" chain. Multi-chain isn't yet
// active, so we'll restrict usage to a particular chain for now. // active, so we'll restrict usage to a particular chain for now.
@ -167,8 +167,8 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
defaultLitecoinStaticFeePerKW, 0, defaultLitecoinStaticFeePerKW, 0,
) )
default: default:
return nil, nil, fmt.Errorf("Default routing policy for "+ return nil, fmt.Errorf("Default routing policy for chain %v is "+
"chain %v is unknown", registeredChains.PrimaryChain()) "unknown", registeredChains.PrimaryChain())
} }
walletConfig := &btcwallet.Config{ walletConfig := &btcwallet.Config{
@ -183,15 +183,12 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
Wallet: wallet, Wallet: wallet,
} }
var ( var err error
err error
cleanUp func()
)
// Initialize the height hint cache within the chain directory. // Initialize the height hint cache within the chain directory.
hintCache, err := chainntnfs.NewHeightHintCache(chanDB) hintCache, err := chainntnfs.NewHeightHintCache(chanDB)
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("unable to initialize height hint "+ return nil, fmt.Errorf("unable to initialize height hint "+
"cache: %v", err) "cache: %v", err)
} }
@ -208,9 +205,9 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
) )
cc.chainView, err = chainview.NewCfFilteredChainView(neutrinoCS) cc.chainView, err = chainview.NewCfFilteredChainView(neutrinoCS)
if err != nil { if err != nil {
cleanUp() return nil, err
return nil, nil, err
} }
walletConfig.ChainSource = chain.NewNeutrinoClient( walletConfig.ChainSource = chain.NewNeutrinoClient(
activeNetParams.Params, neutrinoCS, activeNetParams.Params, neutrinoCS,
) )
@ -238,7 +235,7 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
// this back to the btcwallet/bitcoind port. // this back to the btcwallet/bitcoind port.
rpcPort, err := strconv.Atoi(activeNetParams.rpcPort) rpcPort, err := strconv.Atoi(activeNetParams.rpcPort)
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
rpcPort -= 2 rpcPort -= 2
bitcoindHost = fmt.Sprintf("%v:%d", bitcoindHost = fmt.Sprintf("%v:%d",
@ -265,12 +262,12 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
100*time.Millisecond, 100*time.Millisecond,
) )
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
if err := bitcoindConn.Start(); err != nil { if err := bitcoindConn.Start(); err != nil {
return nil, nil, fmt.Errorf("unable to connect to "+ return nil, fmt.Errorf("unable to connect to bitcoind: "+
"bitcoind: %v", err) "%v", err)
} }
cc.chainNotifier = bitcoindnotify.New( cc.chainNotifier = bitcoindnotify.New(
@ -302,10 +299,10 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
*rpcConfig, fallBackFeeRate.FeePerKWeight(), *rpcConfig, fallBackFeeRate.FeePerKWeight(),
) )
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
if err := cc.feeEstimator.Start(); err != nil { if err := cc.feeEstimator.Start(); err != nil {
return nil, nil, err return nil, err
} }
} else if cfg.Litecoin.Active { } else if cfg.Litecoin.Active {
ltndLog.Infof("Initializing litecoind backed fee estimator") ltndLog.Infof("Initializing litecoind backed fee estimator")
@ -319,10 +316,10 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
*rpcConfig, fallBackFeeRate.FeePerKWeight(), *rpcConfig, fallBackFeeRate.FeePerKWeight(),
) )
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
if err := cc.feeEstimator.Start(); err != nil { if err := cc.feeEstimator.Start(); err != nil {
return nil, nil, err return nil, err
} }
} }
case "btcd", "ltcd": case "btcd", "ltcd":
@ -343,19 +340,19 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
if btcdMode.RawRPCCert != "" { if btcdMode.RawRPCCert != "" {
rpcCert, err = hex.DecodeString(btcdMode.RawRPCCert) rpcCert, err = hex.DecodeString(btcdMode.RawRPCCert)
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
} else { } else {
certFile, err := os.Open(btcdMode.RPCCert) certFile, err := os.Open(btcdMode.RPCCert)
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
rpcCert, err = ioutil.ReadAll(certFile) rpcCert, err = ioutil.ReadAll(certFile)
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
if err := certFile.Close(); err != nil { if err := certFile.Close(); err != nil {
return nil, nil, err return nil, err
} }
} }
@ -387,7 +384,7 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
rpcConfig, activeNetParams.Params, hintCache, hintCache, rpcConfig, activeNetParams.Params, hintCache, hintCache,
) )
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
// Finally, we'll create an instance of the default chain view to be // Finally, we'll create an instance of the default chain view to be
@ -395,7 +392,7 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
cc.chainView, err = chainview.NewBtcdFilteredChainView(*rpcConfig) cc.chainView, err = chainview.NewBtcdFilteredChainView(*rpcConfig)
if err != nil { if err != nil {
srvrLog.Errorf("unable to create chain view: %v", err) srvrLog.Errorf("unable to create chain view: %v", err)
return nil, nil, err return nil, err
} }
// Create a special websockets rpc client for btcd which will be used // Create a special websockets rpc client for btcd which will be used
@ -403,7 +400,7 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
chainRPC, err := chain.NewRPCClient(activeNetParams.Params, btcdHost, chainRPC, err := chain.NewRPCClient(activeNetParams.Params, btcdHost,
btcdUser, btcdPass, rpcCert, false, 20) btcdUser, btcdPass, rpcCert, false, 20)
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
walletConfig.ChainSource = chainRPC walletConfig.ChainSource = chainRPC
@ -424,24 +421,21 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
*rpcConfig, fallBackFeeRate.FeePerKWeight(), *rpcConfig, fallBackFeeRate.FeePerKWeight(),
) )
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
if err := cc.feeEstimator.Start(); err != nil { if err := cc.feeEstimator.Start(); err != nil {
return nil, nil, err return nil, err
} }
} }
default: default:
return nil, nil, fmt.Errorf("unknown node type: %s", return nil, fmt.Errorf("unknown node type: %s",
homeChainConfig.Node) homeChainConfig.Node)
} }
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 { return nil, err
cleanUp()
}
return nil, nil, err
} }
cc.msgSigner = wc cc.msgSigner = wc
@ -476,24 +470,18 @@ 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 { return nil, err
cleanUp()
}
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 { return nil, err
cleanUp()
}
return nil, nil, err
} }
ltndLog.Info("LightningWallet opened") ltndLog.Info("LightningWallet opened")
cc.wallet = lnWallet cc.wallet = lnWallet
return cc, cleanUp, nil return cc, nil
} }
var ( var (

5
lnd.go

@ -278,7 +278,7 @@ func lndMain() error {
// With the information parsed from the configuration, create valid // With the information parsed from the configuration, create valid
// instances of the pertinent interfaces required to operate the // instances of the pertinent interfaces required to operate the
// Lightning Network Daemon. // Lightning Network Daemon.
activeChainControl, chainCleanUp, err := newChainControlFromConfig( activeChainControl, err := newChainControlFromConfig(
cfg, chanDB, privateWalletPw, publicWalletPw, cfg, chanDB, privateWalletPw, publicWalletPw,
walletInitParams.Birthday, walletInitParams.RecoveryWindow, walletInitParams.Birthday, walletInitParams.RecoveryWindow,
walletInitParams.Wallet, neutrinoCS, walletInitParams.Wallet, neutrinoCS,
@ -287,9 +287,6 @@ func lndMain() error {
fmt.Printf("unable to create chain control: %v\n", err) fmt.Printf("unable to create chain control: %v\n", err)
return err return err
} }
if chainCleanUp != nil {
defer chainCleanUp()
}
// Finally before we start the server, we'll register the "holy // Finally before we start the server, we'll register the "holy
// trinity" of interface for our current "home chain" with the active // trinity" of interface for our current "home chain" with the active