From d12154154a89e9d3cce85c7e0a0b41108074730a Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 23 Sep 2021 16:54:31 +0200 Subject: [PATCH] chainreg+lnd: add block cache to chainreg config The block cache size in the chainreg.Config previously wasn't used but instead the block cache was passed in as a separate parameter. We replace the cache size with the actual cache in the config to streamline things somewhat. --- chainreg/chainregistry.go | 22 ++++++++++------------ lnd.go | 6 +++--- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/chainreg/chainregistry.go b/chainreg/chainregistry.go index c7ad2a8d5..2694995b7 100644 --- a/chainreg/chainregistry.go +++ b/chainreg/chainregistry.go @@ -77,8 +77,8 @@ type Config struct { // state. ChanStateDB *channeldb.ChannelStateDB - // BlockCacheSize is the size (in bytes) of blocks kept in memory. - BlockCacheSize uint64 + // BlockCache is the main cache for storing block information. + BlockCache *blockcache.BlockCache // PrivateWalletPw is the private wallet password to the underlying // btcwallet instance. @@ -245,9 +245,7 @@ func GenDefaultBtcConstraints() channeldb.ChannelConstraints { // full-node, another backed by a running bitcoind full-node, and the other // backed by a running neutrino light client instance. When running with a // neutrino light client instance, `neutrinoCS` must be non-nil. -func NewChainControl(cfg *Config, blockCache *blockcache.BlockCache) ( - *ChainControl, func(), error) { - +func NewChainControl(cfg *Config) (*ChainControl, func(), 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. homeChainConfig := cfg.Bitcoin @@ -327,10 +325,10 @@ func NewChainControl(cfg *Config, blockCache *blockcache.BlockCache) ( // along with the wallet's ChainSource, which are all backed by // the neutrino light client. cc.ChainNotifier = neutrinonotify.New( - cfg.NeutrinoCS, hintCache, hintCache, blockCache, + cfg.NeutrinoCS, hintCache, hintCache, cfg.BlockCache, ) cc.ChainView, err = chainview.NewCfFilteredChainView( - cfg.NeutrinoCS, blockCache, + cfg.NeutrinoCS, cfg.BlockCache, ) if err != nil { return nil, nil, err @@ -432,10 +430,10 @@ func NewChainControl(cfg *Config, blockCache *blockcache.BlockCache) ( cc.ChainNotifier = bitcoindnotify.New( bitcoindConn, cfg.ActiveNetParams.Params, hintCache, - hintCache, blockCache, + hintCache, cfg.BlockCache, ) cc.ChainView = chainview.NewBitcoindFilteredChainView( - bitcoindConn, blockCache, + bitcoindConn, cfg.BlockCache, ) walletConfig.ChainSource = bitcoindConn.NewBitcoindClient() @@ -564,7 +562,7 @@ func NewChainControl(cfg *Config, blockCache *blockcache.BlockCache) ( } cc.ChainNotifier, err = btcdnotify.New( rpcConfig, cfg.ActiveNetParams.Params, hintCache, - hintCache, blockCache, + hintCache, cfg.BlockCache, ) if err != nil { return nil, nil, err @@ -573,7 +571,7 @@ func NewChainControl(cfg *Config, blockCache *blockcache.BlockCache) ( // Finally, we'll create an instance of the default chain view to be // used within the routing layer. cc.ChainView, err = chainview.NewBtcdFilteredChainView( - *rpcConfig, blockCache, + *rpcConfig, cfg.BlockCache, ) if err != nil { log.Errorf("unable to create chain view: %v", err) @@ -666,7 +664,7 @@ func NewChainControl(cfg *Config, blockCache *blockcache.BlockCache) ( return nil, nil, err } - wc, err := btcwallet.New(*walletConfig, blockCache) + wc, err := btcwallet.New(*walletConfig, cfg.BlockCache) if err != nil { fmt.Printf("unable to create wallet controller: %v\n", err) return nil, ccCleanup, err diff --git a/lnd.go b/lnd.go index d5e431e85..61f6d2b98 100644 --- a/lnd.go +++ b/lnd.go @@ -729,8 +729,8 @@ func Main(cfg *Config, lisCfg ListenerCfg, interceptor signal.Interceptor) error Dialer: func(addr string) (net.Conn, error) { return cfg.net.Dial("tcp", addr, cfg.ConnectionTimeout) }, - BlockCacheSize: cfg.BlockCacheSize, - LoaderOptions: []btcwallet.LoaderOption{dbs.walletDB}, + BlockCache: blockCache, + LoaderOptions: []btcwallet.LoaderOption{dbs.walletDB}, } // Parse coin selection strategy. @@ -747,7 +747,7 @@ func Main(cfg *Config, lisCfg ListenerCfg, interceptor signal.Interceptor) error } activeChainControl, cleanup, err := chainreg.NewChainControl( - chainControlCfg, blockCache, + chainControlCfg, ) if cleanup != nil { defer cleanup()