From 1179895d2093d9f156549897d312e76454db89df Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Wed, 10 Apr 2019 17:32:41 -0700 Subject: [PATCH] chainregistry+lnd: remove unused cleanUp variable --- chainregistry.go | 70 ++++++++++++++++++++---------------------------- lnd.go | 5 +--- 2 files changed, 30 insertions(+), 45 deletions(-) diff --git a/chainregistry.go b/chainregistry.go index 80a6dde3c..b18733156 100644 --- a/chainregistry.go +++ b/chainregistry.go @@ -132,7 +132,7 @@ type chainControl struct { func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB, privateWalletPw, publicWalletPw []byte, birthday time.Time, 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 // 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, ) default: - return nil, nil, fmt.Errorf("Default routing policy for "+ - "chain %v is unknown", registeredChains.PrimaryChain()) + return nil, fmt.Errorf("Default routing policy for chain %v is "+ + "unknown", registeredChains.PrimaryChain()) } walletConfig := &btcwallet.Config{ @@ -183,15 +183,12 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB, Wallet: wallet, } - var ( - err error - cleanUp func() - ) + var err error // Initialize the height hint cache within the chain directory. hintCache, err := chainntnfs.NewHeightHintCache(chanDB) 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) } @@ -208,9 +205,9 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB, ) cc.chainView, err = chainview.NewCfFilteredChainView(neutrinoCS) if err != nil { - cleanUp() - return nil, nil, err + return nil, err } + walletConfig.ChainSource = chain.NewNeutrinoClient( activeNetParams.Params, neutrinoCS, ) @@ -238,7 +235,7 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB, // this back to the btcwallet/bitcoind port. rpcPort, err := strconv.Atoi(activeNetParams.rpcPort) if err != nil { - return nil, nil, err + return nil, err } rpcPort -= 2 bitcoindHost = fmt.Sprintf("%v:%d", @@ -265,12 +262,12 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB, 100*time.Millisecond, ) if err != nil { - return nil, nil, err + return nil, err } if err := bitcoindConn.Start(); err != nil { - return nil, nil, fmt.Errorf("unable to connect to "+ - "bitcoind: %v", err) + return nil, fmt.Errorf("unable to connect to bitcoind: "+ + "%v", err) } cc.chainNotifier = bitcoindnotify.New( @@ -302,10 +299,10 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB, *rpcConfig, fallBackFeeRate.FeePerKWeight(), ) if err != nil { - return nil, nil, err + return nil, err } if err := cc.feeEstimator.Start(); err != nil { - return nil, nil, err + return nil, err } } else if cfg.Litecoin.Active { ltndLog.Infof("Initializing litecoind backed fee estimator") @@ -319,10 +316,10 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB, *rpcConfig, fallBackFeeRate.FeePerKWeight(), ) if err != nil { - return nil, nil, err + return nil, err } if err := cc.feeEstimator.Start(); err != nil { - return nil, nil, err + return nil, err } } case "btcd", "ltcd": @@ -343,19 +340,19 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB, if btcdMode.RawRPCCert != "" { rpcCert, err = hex.DecodeString(btcdMode.RawRPCCert) if err != nil { - return nil, nil, err + return nil, err } } else { certFile, err := os.Open(btcdMode.RPCCert) if err != nil { - return nil, nil, err + return nil, err } rpcCert, err = ioutil.ReadAll(certFile) if err != nil { - return nil, nil, err + return nil, err } 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, ) if err != nil { - return nil, nil, err + return nil, err } // 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) if err != nil { 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 @@ -403,7 +400,7 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB, chainRPC, err := chain.NewRPCClient(activeNetParams.Params, btcdHost, btcdUser, btcdPass, rpcCert, false, 20) if err != nil { - return nil, nil, err + return nil, err } walletConfig.ChainSource = chainRPC @@ -424,24 +421,21 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB, *rpcConfig, fallBackFeeRate.FeePerKWeight(), ) if err != nil { - return nil, nil, err + return nil, err } if err := cc.feeEstimator.Start(); err != nil { - return nil, nil, err + return nil, err } } default: - return nil, nil, fmt.Errorf("unknown node type: %s", + return nil, fmt.Errorf("unknown node type: %s", homeChainConfig.Node) } 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 + return nil, err } cc.msgSigner = wc @@ -476,24 +470,18 @@ 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 + return 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 + return nil, err } ltndLog.Info("LightningWallet opened") cc.wallet = lnWallet - return cc, cleanUp, nil + return cc, nil } var ( diff --git a/lnd.go b/lnd.go index 56ab23c5c..c140c15ab 100644 --- a/lnd.go +++ b/lnd.go @@ -278,7 +278,7 @@ func lndMain() error { // With the information parsed from the configuration, create valid // instances of the pertinent interfaces required to operate the // Lightning Network Daemon. - activeChainControl, chainCleanUp, err := newChainControlFromConfig( + activeChainControl, err := newChainControlFromConfig( cfg, chanDB, privateWalletPw, publicWalletPw, walletInitParams.Birthday, walletInitParams.RecoveryWindow, walletInitParams.Wallet, neutrinoCS, @@ -287,9 +287,6 @@ func lndMain() error { fmt.Printf("unable to create chain control: %v\n", err) return err } - if chainCleanUp != nil { - defer chainCleanUp() - } // Finally before we start the server, we'll register the "holy // trinity" of interface for our current "home chain" with the active