Difference between revisions of "Compacting Channel DB"

From PlebNet Wiki
Jump to navigation Jump to search
Line 17: Line 17:
Manual pruning is needed in case automated pruning could not sufficiently reduce the size of channel.db. Node operators can do manual pruning in a few different ways: identify and reset channels with the biggest disk footprint; manually remove payments from the channel.db.
Manual pruning is needed in case automated pruning could not sufficiently reduce the size of channel.db. Node operators can do manual pruning in a few different ways: identify and reset channels with the biggest disk footprint; manually remove payments from the channel.db.


Node operators can identify channels with the biggest footprint through [https://api.lightning.community/#listchannels lncli listchannels], the <code>num_updates</code> filed will indicate the number of channel state updates a particular channel did.  Node operators can also use <code>bos findalias</code> as part of [https://github.com/alexbosworth/balanceofsatoshis BalanceOfSatoshis] tool. [https://github.com/itsneski/lightning-jet Lightning Jet] provides way to monitor channel.db and receive warnings via <code>jet monitor</code> (including [https://github.com/itsneski/lightning-jet#telegram-bot telegram bot] notications).
Node operators can identify channels with the biggest footprint through [https://api.lightning.community/#listchannels lncli listchannels], the <code>num_updates</code> filed will indicate the number of channel state updates a particular channel did.  Node operators can also use <code>bos <alias/pubkey></code> as part of [https://github.com/alexbosworth/balanceofsatoshis BalanceOfSatoshis] tool. [https://github.com/itsneski/lightning-jet Lightning Jet] provides way to monitor channel.db and receive warnings via <code>jet monitor</code> (including [https://github.com/itsneski/lightning-jet#telegram-bot telegram bot] notications).


Once a channel with the biggest footprint is identified, the node operator can re-establish it by closing the channel and creating a new one. Please note that there is a cost associated with closing and creating channels, so node operators should use this option carefully.  
Once a channel with the biggest footprint is identified, the node operator can re-establish it by closing the channel and creating a new one. Please note that there is a cost associated with closing and creating channels, so node operators should use this option carefully.  


In addition, node operators can prune config.db manually by calling the [https://api.lightning.community/#deleteallpayments LND API DeleteAllPayments], with <code>failed_payments_only</code> and <code>failed_htlcs_only</code> set to true.  lncli does not currently support the call so you will need to write a script (in say Python or JavaScript) to call this method. [https://github.com/itsneski/lightning-jet/blob/main/tools/prune-payments Example of a JavaScript code]. There is also a hidden bos command <code>bos delete-payments-history</code> which can do the same. You can find the details [https://github.com/niteshbalusu11/BOS-Commands-Document#delete-payments-history here].
In addition, node operators can prune config.db manually by calling the [https://api.lightning.community/#deleteallpayments LND API DeleteAllPayments], with <code>failed_payments_only</code> and <code>failed_htlcs_only</code> set to true.  lncli does not currently support the call so you will need to write a script (in say Python or JavaScript) to call this method. [https://github.com/itsneski/lightning-jet/blob/main/tools/prune-payments Example of a JavaScript code]. There is also a hidden bos command <code>bos delete-payments-history</code> which will delete all payments, including successful ones. You can find the details [https://github.com/niteshbalusu11/BOS-Commands-Document#delete-payments-history here].


Manual pruning may take time to complete depending on the channel.db size. Make sure to wait until it completes and don't interrupt the process. Once pruning completes verify that the number of payments in the channel.db is zero by running <code>lncli listpayments | jq '.payments' | jq length</code>.  Delete <code>~/umbrel/lnd/data/graph/mainnet/channel.db.last-compacted</code> to trigger compaction on restart.  Next restart you node: <code>restart lnd cd ~/umbrel ; docker-compose restart lnd; docker-compose ps</code>
Manual pruning may take time to complete depending on the channel.db size. Make sure to wait until it completes and don't interrupt the process. Once pruning completes verify that the number of payments in the channel.db is zero by running <code>lncli listpayments | jq '.payments' | jq length</code>.  Delete <code>~/umbrel/lnd/data/graph/mainnet/channel.db.last-compacted</code> to trigger compaction on restart.  Next restart you node: <code>restart lnd cd ~/umbrel ; docker-compose restart lnd; docker-compose ps</code>
Line 27: Line 27:
== Upcoming lnd release ==
== Upcoming lnd release ==


[https://github.com/lightningnetwork/lnd/releases The next major lnd14 release] will introduce new ways to manage the channel.db size. It'll allow more granular deletion of records from the channel.db. [https://github.com/alexbosworth/balanceofsatoshis BalanceOfSatoshis] will automatically prune obsolete channel.db records generated as part of payment probes.
[https://github.com/lightningnetwork/lnd/releases The next major lnd14 release] will introduce new ways to manage the channel.db size. It'll allow more granular deletion of records from the channel.db. [https://github.com/alexbosworth/balanceofsatoshis BalanceOfSatoshis] will automatically prune obsolete channel.db records generated as part of payment probes. In addition, <code>bos clean-failed-payments</code> will take over as a visible command (currently in dry run mode).

Revision as of 20:17, 17 November 2021

The BOLT db, or channel.db, stores payments sent by your LND node, including failed payments, failed htlcs from payments and payment probes. The database is located under ~/umbrel/lnd/data/graph/mainnet/channel.db> on Umbrel.

The file continuously grows and may eventually exceed the available disk space and/or slow things down. 1GB or 2GB size is reasonable, but your node may begin to slow down when the file reaches 6 - 8Gb.

Compact & prune channel.db periodically. Pruning refers to marking payment records for deletion. Compaction refers to removing the marked records from the database and thus reducing its size.

Compaction

See configuration settings to enable compaction: enable compaction of channel.db.

Compaction makes a copy of channel.db during lnd restart, removes the marked records, and restores the file. Make sure to have enough disk space to support compaction, or lnd may fail to start.

Pruning

Pruning can be automated and manual. Automated pruning can be configured via the lnd.conf. Compaction will then delete channel.db pruned records.

Manual pruning is needed in case automated pruning could not sufficiently reduce the size of channel.db. Node operators can do manual pruning in a few different ways: identify and reset channels with the biggest disk footprint; manually remove payments from the channel.db.

Node operators can identify channels with the biggest footprint through lncli listchannels, the num_updates filed will indicate the number of channel state updates a particular channel did. Node operators can also use bos <alias/pubkey> as part of BalanceOfSatoshis tool. Lightning Jet provides way to monitor channel.db and receive warnings via jet monitor (including telegram bot notications).

Once a channel with the biggest footprint is identified, the node operator can re-establish it by closing the channel and creating a new one. Please note that there is a cost associated with closing and creating channels, so node operators should use this option carefully.

In addition, node operators can prune config.db manually by calling the LND API DeleteAllPayments, with failed_payments_only and failed_htlcs_only set to true. lncli does not currently support the call so you will need to write a script (in say Python or JavaScript) to call this method. Example of a JavaScript code. There is also a hidden bos command bos delete-payments-history which will delete all payments, including successful ones. You can find the details here.

Manual pruning may take time to complete depending on the channel.db size. Make sure to wait until it completes and don't interrupt the process. Once pruning completes verify that the number of payments in the channel.db is zero by running lncli listpayments | jq '.payments' | jq length. Delete ~/umbrel/lnd/data/graph/mainnet/channel.db.last-compacted to trigger compaction on restart. Next restart you node: restart lnd cd ~/umbrel ; docker-compose restart lnd; docker-compose ps

Upcoming lnd release

The next major lnd14 release will introduce new ways to manage the channel.db size. It'll allow more granular deletion of records from the channel.db. BalanceOfSatoshis will automatically prune obsolete channel.db records generated as part of payment probes. In addition, bos clean-failed-payments will take over as a visible command (currently in dry run mode).