Compacting Channel DB
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
orjet 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
:
- 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
andfailed_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:
- call lncli listchannels, the
num_updates
field indicates the number of channel state updates for a channel. - BalanceOfSatoshis
bos <alias/pubkey>
. - Lightning Jet
jet list-channels
returns top 10 channels based on 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:
- 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.
- Delete
~/umbrel/lnd/data/graph/mainnet/channel.db.last-compacted
to trigger compaction on restart. - Restart lnd:
cd ~/umbrel ; docker-compose restart lnd; docker-compose ps
.