From 6702c79216b7c472624be6ba34303ad19d5426d7 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Thu, 18 Mar 2021 13:40:53 +0200 Subject: [PATCH] multi: add block cache size config This commit adds block cache size to the main lnd config along with the chainreg config. --- chainreg/chainregistry.go | 3 +++ config.go | 7 +++++++ lnd.go | 1 + sample-lnd.conf | 6 ++++++ 4 files changed, 17 insertions(+) diff --git a/chainreg/chainregistry.go b/chainreg/chainregistry.go index aec44b88..ff500820 100644 --- a/chainreg/chainregistry.go +++ b/chainreg/chainregistry.go @@ -73,6 +73,9 @@ type Config struct { // RemoteChanDB is a pointer to the remote backing channel database. RemoteChanDB *channeldb.DB + // BlockCacheSize is the size (in bytes) of blocks kept in memory. + BlockCacheSize uint64 + // PrivateWalletPw is the private wallet password to the underlying // btcwallet instance. PrivateWalletPw []byte diff --git a/config.go b/config.go index 2052acda..67abc61d 100644 --- a/config.go +++ b/config.go @@ -101,6 +101,10 @@ const ( // initiated the channel closure. defaultCoopCloseTargetConfs = 6 + // defaultBlockCacheSize is the size (in bytes) of blocks that will be + // keep in memory if no size is specified. + defaultBlockCacheSize uint64 = 20 * 1024 * 1024 // 20 MB + // defaultHostSampleInterval is the default amount of time that the // HostAnnouncer will wait between DNS resolutions to check if the // backing IP of a host has changed. @@ -273,6 +277,8 @@ type Config struct { LtcdMode *lncfg.Btcd `group:"ltcd" namespace:"ltcd"` LitecoindMode *lncfg.Bitcoind `group:"litecoind" namespace:"litecoind"` + BlockCacheSize uint64 `long:"blockcachesize" description:"The maximum capacity of the block cache"` + Autopilot *lncfg.AutoPilot `group:"Autopilot" namespace:"autopilot"` Tor *lncfg.Tor `group:"Tor" namespace:"tor"` @@ -434,6 +440,7 @@ func DefaultConfig() Config { UserAgentName: neutrino.UserAgentName, UserAgentVersion: neutrino.UserAgentVersion, }, + BlockCacheSize: defaultBlockCacheSize, UnsafeDisconnect: true, MaxPendingChannels: lncfg.DefaultMaxPendingChannels, NoSeedBackup: defaultNoSeedBackup, diff --git a/lnd.go b/lnd.go index b82d2f7c..8e05ee5d 100644 --- a/lnd.go +++ b/lnd.go @@ -546,6 +546,7 @@ 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, } activeChainControl, cleanup, err := chainreg.NewChainControl(chainControlCfg) diff --git a/sample-lnd.conf b/sample-lnd.conf index 4659c1ce..06158331 100644 --- a/sample-lnd.conf +++ b/sample-lnd.conf @@ -224,6 +224,12 @@ ; The target location of the channel backup file. ; backupfilepath=~/.lnd/data/chain/bitcoin/simnet/channel.backup +; The maximum capacity of the block cache in bytes. Increasing this will result +; in more blocks being kept in memory but will increase performance when the +; same block is required multiple times. +; The example value below is 40 MB (1024 * 1024 * 40) +; blockcachesize=41943040 + ; Optional URL for external fee estimation. If no URL is specified, the method ; for fee estimation will depend on the chosen backend and network. Must be set ; for neutrino on mainnet.