From a2ad533136d16b75107fbf62f98d26d9f8664d3b Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 21 Oct 2021 13:55:18 +0200 Subject: [PATCH] docs+lncfg+sample-lnd.conf: add no-graph-cache option --- docs/release-notes/release-notes-0.14.0.md | 8 ++++ lncfg/db.go | 19 +++++++++- sample-lnd.conf | 44 ++++++++++++---------- 3 files changed, 49 insertions(+), 22 deletions(-) diff --git a/docs/release-notes/release-notes-0.14.0.md b/docs/release-notes/release-notes-0.14.0.md index 221051680..3bdbfb838 100644 --- a/docs/release-notes/release-notes-0.14.0.md +++ b/docs/release-notes/release-notes-0.14.0.md @@ -92,6 +92,14 @@ usage. Users running `lnd` on low-memory systems are advised to run with the removes zombie channels from the graph, reducing the number of channels that need to be kept in memory. +There is a [fallback option](https://github.com/lightningnetwork/lnd/pull/5840) +`db.no-graph-cache=true` that can be used when running a Bolt (`bbolt`) based +database backend. Using the database for path finding is considerably slower +than using the in-memory graph cache but uses less RAM. The fallback option is +not available for `etcd` or Postgres database backends because of the way they +handle long-running database transactions that are required for the path finding +operations. + ## Protocol Extensions ### Explicit Channel Negotiation diff --git a/lncfg/db.go b/lncfg/db.go index 8ff929f5d..7c0004776 100644 --- a/lncfg/db.go +++ b/lncfg/db.go @@ -57,6 +57,8 @@ type DB struct { Bolt *kvdb.BoltConfig `group:"bolt" namespace:"bolt" description:"Bolt settings."` Postgres *postgres.Config `group:"postgres" namespace:"postgres" description:"Postgres settings."` + + NoGraphCache bool `long:"no-graph-cache" description:"Don't use the in-memory graph cache for path finding. Much slower but uses less RAM. Can only be used with a bolt database backend."` } // DefaultDB creates and returns a new default DB config. @@ -87,8 +89,21 @@ func (db *DB) Validate() error { } default: - return fmt.Errorf("unknown backend, must be either \"%v\" or \"%v\"", - BoltBackend, EtcdBackend) + return fmt.Errorf("unknown backend, must be either '%v' or "+ + "'%v'", BoltBackend, EtcdBackend) + } + + // The path finding uses a manual read transaction that's open for a + // potentially long time. That works fine with the locking model of + // bbolt but can lead to locks or rolled back transactions with etcd or + // postgres. And since we already have a smaller memory footprint for + // remote database setups (due to not needing to memory-map the bbolt DB + // files), we can keep the graph in memory instead. But for mobile + // devices the tradeoff between a smaller memory footprint and the + // longer time needed for path finding might be a desirable one. + if db.NoGraphCache && db.Backend != BoltBackend { + return fmt.Errorf("cannot use no-graph-cache with database "+ + "backend '%v'", db.Backend) } return nil diff --git a/sample-lnd.conf b/sample-lnd.conf index 2bcbe10c0..69533d338 100644 --- a/sample-lnd.conf +++ b/sample-lnd.conf @@ -1118,6 +1118,9 @@ litecoin.node=ltcd ; a batch of modifications to disk. Defaults to 500 milliseconds. ; db.batch-commit-interval=500ms +; Don't use the in-memory graph cache for path finding. Much slower but uses +; less RAM. Can only be used with a bolt database backend. +; db.no-graph-cache=true [etcd] @@ -1170,6 +1173,27 @@ litecoin.node=ltcd ; disable. ; db.postgres.timeout= +[bolt] + +; If true, prevents the database from syncing its freelist to disk. +; db.bolt.nofreelistsync=1 + +; Whether the databases used within lnd should automatically be compacted on +; every startup (and if the database has the configured minimum age). This is +; disabled by default because it requires additional disk space to be available +; during the compaction that is freed afterwards. In general compaction leads to +; smaller database files. +; db.bolt.auto-compact=true + +; How long ago the last compaction of a database file must be for it to be +; considered for auto compaction again. Can be set to 0 to compact on every +; startup. (default: 168h) +; db.bolt.auto-compact-min-age=0 + +; Specify the timeout to be used when opening the database. +; db.bolt.dbtimeout=60s + + [cluster] ; Enables leader election if set. @@ -1217,26 +1241,6 @@ litecoin.node=ltcd ; The TLS certificate to use for establishing the remote signer's identity. ; remotesigner.tlscertpath=/path/to/remote/signer/tls.cert -[bolt] - -; If true, prevents the database from syncing its freelist to disk. -; db.bolt.nofreelistsync=1 - -; Whether the databases used within lnd should automatically be compacted on -; every startup (and if the database has the configured minimum age). This is -; disabled by default because it requires additional disk space to be available -; during the compaction that is freed afterwards. In general compaction leads to -; smaller database files. -; db.bolt.auto-compact=true - -; How long ago the last compaction of a database file must be for it to be -; considered for auto compaction again. Can be set to 0 to compact on every -; startup. (default: 168h) -; db.bolt.auto-compact-min-age=0 - -; Specify the timeout to be used when opening the database. -; db.bolt.dbtimeout=60s - [gossip]