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.
This commit is contained in:
Oliver Gugger 2021-09-23 16:54:31 +02:00
parent e79d59dd4c
commit d12154154a
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
2 changed files with 13 additions and 15 deletions

View File

@ -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

6
lnd.go
View File

@ -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()