Difference between revisions of "Compacting Channel DB"

From PlebNet Wiki
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
The BOLT db, or channel.db, stores the entire history of payments processed by your LND node, including failed payments, failed htlcs from payments, and payment probes. The database is located at <code>~/umbrel/lnd/data/graph/mainnet/channel.db></code> on Umbrel.
The BOLT db, or channel.db, stores the entire history of payments processed by your LND node, including failed payments, failed htlcs from payments, and payment probes. The database is located at <code>~/umbrel/lnd/data/graph/mainnet/channel.db</code> 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.
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.
Line 29: Line 29:
=== Clean failed payments ===
=== Clean failed payments ===


Ways to clean failed payments based on lnd version, <code>lncli -v</code>:
Ways to clean failed payments based on lnd version, <code>lncli -v</code>. Note: use this with caution and only when there is no other choice. Make sure to identify your version of lnd prior to calling any of the methods. Do not call a method multiple times in case of a failure. Message on Plebnet Noderunnes or Plebnet Advanced telegram groups in case of a failure.


* lnd13: [https://github.com/alexbosworth/balanceofsatoshis BalanceOfSatoshis] <code>bos delete-payments-history</code>. This command will delete all payments, including successful ones, use it with caution. Details [https://github.com/niteshbalusu11/BOS-Commands-Document#delete-payments-history here].
* lnd13: [https://github.com/alexbosworth/balanceofsatoshis BalanceOfSatoshis] <code>bos delete-payments-history</code>. This command will delete all payments, including successful ones, use it with caution. Details [https://github.com/niteshbalusu11/BOS-Commands-Document#delete-payments-history here].
Line 50: Line 50:
Steps to enable and trigger compaction:
Steps to enable and trigger compaction:


# Update lnd.conf to [[Special:MyLanguage/LND_Configuration_Settings#BOLT_Database_optimizations_.28channel.db.29|enable compaction]].
# [[Special:MyLanguage/LND_Configuration_Settings#BOLT_Database_optimizations_.28channel.db.29|Update lnd.conf]] to enable compaction.
# Make sure to have enough disk space to support compaction, or lnd may fail to start. Compaction makes a copy of channel.db during lnd restart.
# Make sure to have enough disk space to support compaction, or lnd may fail to start. Compaction makes a copy of channel.db during lnd restart.
# Delete <code>~/umbrel/lnd/data/graph/mainnet/channel.db.last-compacted</code> to trigger compaction on restart.
# Delete <code>~/umbrel/lnd/data/graph/mainnet/channel.db.last-compacted</code> to trigger compaction on restart.
# Restart lnd: <code>cd ~/umbrel ; docker-compose restart lnd; docker-compose ps</code>.
# Restart lnd: <code>cd ~/umbrel ; docker-compose restart lnd; docker-compose ps</code>.

Latest revision as of 18:39, 30 December 2021

The BOLT db, or channel.db, stores the entire history of payments processed by your LND node, including failed payments, failed htlcs from payments, and payment probes. The database is located at ~/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.

Monitor channel.db, compact & prune it when needed. Pruning refers to marking payment records for deletion. Compaction refers to removing the marked records from the database and thus reducing its size.

Monitor channel.db size

Ways to monitor channel.db:

  • periodically check the channel.db size by ls -l <channel.db path>.
  • install Lightning Jet telegram bot; the bot will notify when channel.db grows over the threshold.
  • run Lightning Jet jet monitor or jet channeldb tools; the tools will show a warning when channel db grows over the threshold.

Create a backup

Backup channel.db payments prior to pruning and compaction: lncli listpayments > listpayments.bak. Place listpayments.bak in a backup folder under your home directory, e.g. ~/listpayments_backup. Indicate current date in the file name, e.g. listpayments.bak.2021.12.29.

Enable pruning

Update lnd.conf to enable automated pruning.

Note: in lnd14 BalanceOfSatoshis automatically prunes the obsolete channel.db records generated as part of payment probes.

Prune manually

Prune manually when automated pruning is not able to sufficiently reduce the size of channel.db.

Clean failed payments

Ways to clean failed payments based on lnd version, lncli -v. Note: use this with caution and only when there is no other choice. Make sure to identify your version of lnd prior to calling any of the methods. Do not call a method multiple times in case of a failure. Message on Plebnet Noderunnes or Plebnet Advanced telegram groups in case of a failure.

  • lnd13: BalanceOfSatoshis bos delete-payments-history. This command will delete all payments, including successful ones, use it with caution. Details here.
  • lnd14: BalanceOfSatoshis bos clean-failed-payments. The command is safe to use as it only cleans failed payments.
  • lnd13+: call Lightning Jet tools/prune-payments tool; the tool will only remove failed payments & htlcs (lnd13 and up).
  • lnd13+: write a script to call LND API DeleteAllPayments (example of a JavaScript code), with failed_payments_only and failed_htlcs_only set to true. Please note that the flags are supported in lnd13 and up, and are not supported in lnd12. Take extra caution before calling this method, as if called in lnd12 it'll remove all payments, including good ones.

Re-establish channels with the biggest footprint

Ways to identify channels with the biggest footprint:

Re-establish a channel(s) with the biggest footprint 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.

Compact

Steps to enable and trigger compaction:

  1. Update lnd.conf to enable compaction.
  2. Make sure to have enough disk space to support compaction, or lnd may fail to start. Compaction makes a copy of channel.db during lnd restart.
  3. Delete ~/umbrel/lnd/data/graph/mainnet/channel.db.last-compacted to trigger compaction on restart.
  4. Restart lnd: cd ~/umbrel ; docker-compose restart lnd; docker-compose ps.