Difference between revisions of "Using Charge-Lnd to Adjust HTLC Limits"

From PlebNet Wiki
Jump to navigation Jump to search
Line 1: Line 1:
A maximum htlc setting can be used to limit the size of transactions that can pass through a channel, depending on the channel liquidity. This can be a good thing, because when someone tries to forward a payment through one of your channels, but that channel doesn't have enough liquidity, it will cause a payment failure at your node. If your node gets a lot of payment failures it may effect your node's reliability reputation in the network. By setting max-htlc limits so that your channels are only considered when they have enough liquidity to handle the payment, this can reduce the number of failures your node experiences, and improve the network as a whole.
A maximum htlc setting can be used to limit the amount of outbound liquidity that can pass through a channel, depending on the channel liquidity. This can be a good thing, because when someone tries to forward a payment through one of your channels, but that channel doesn't have enough liquidity, it will cause a payment failure at your node. If your node gets a lot of payment failures it may effect your node's reliability reputation in the network. By setting max-htlc limits so that your channels are only considered when they have enough liquidity to handle the payment, it can reduce the number of failures your node experiences, and improve the lightning network as a whole.
 
Note that max-htlc settings don't limit the amount of incoming liquidity a channel can receive, which is good. Incoming liquidity is not what causes failures on your node, and it also allows for your locally depleted channels to have liquidity flow back into them without any issue, despite low maximum htlcs.


Charge-Lnd can be used to automatically adjust your max-htlc limits on your channels. It's not the most concise option, but it is quite easy to set up if you already have experience with Charge-Lnd.
Charge-Lnd can be used to automatically adjust your max-htlc limits on your channels. It's not the most concise option, but it is quite easy to set up if you already have experience with Charge-Lnd.

Revision as of 06:15, 6 October 2021

A maximum htlc setting can be used to limit the amount of outbound liquidity that can pass through a channel, depending on the channel liquidity. This can be a good thing, because when someone tries to forward a payment through one of your channels, but that channel doesn't have enough liquidity, it will cause a payment failure at your node. If your node gets a lot of payment failures it may effect your node's reliability reputation in the network. By setting max-htlc limits so that your channels are only considered when they have enough liquidity to handle the payment, it can reduce the number of failures your node experiences, and improve the lightning network as a whole.

Note that max-htlc settings don't limit the amount of incoming liquidity a channel can receive, which is good. Incoming liquidity is not what causes failures on your node, and it also allows for your locally depleted channels to have liquidity flow back into them without any issue, despite low maximum htlcs.

Charge-Lnd can be used to automatically adjust your max-htlc limits on your channels. It's not the most concise option, but it is quite easy to set up if you already have experience with Charge-Lnd.

Getting Started

If you don't already have Charge-Lnd, please see the installation instructions near the bottom of Fees And Profitability, and familiarize yourself with how it works before following the rest of this guide.

Ok, you should have already created a Charge-Lnd config file for your fee policy. Now let's make a new config file for our max-htlc policy.

nano ~/charge-lnd/maxhtlc

Now you are ready to input your max-htlc settings. It's very wordy since we are using Charge-Lnd. Paste in the following and adjust as you wish.

#When your channel is full of outbound liquity, aka local balance, you allow any size transaction to go through.
[100]
strategy = static
chan.min_ratio = 1
max_htlc_msat_ratio = 1

#When your channel is above 90% outbound liquity, you allow any size transaction to flow through your channel that is 90% of your channel size or less.
[90]
strategy = static
chan.min_ratio = 0.9
max_htlc_msat_ratio = 0.9

#And so on...
[80]
strategy = static
chan.min_ratio = 0.8
max_htlc_msat_ratio = 0.8

[70]
strategy = static
chan.min_ratio = 0.7
max_htlc_msat_ratio = 0.7

[60]
strategy = static
chan.min_ratio = 0.6
max_htlc_msat_ratio = 0.6

[50]
strategy = static
chan.min_ratio = 0.5
max_htlc_msat_ratio = 0.5

#As your channel outbound liquidity depletes, the max htlc limit becomes more and more relevant. So it makes sense to increase the intervals of adjustment.
[45]
strategy = static
chan.min_ratio = 0.45
max_htlc_msat_ratio = 0.45

[40]
strategy = static
chan.min_ratio = 0.4
max_htlc_msat_ratio = 0.4

[35]
strategy = static
chan.min_ratio = 0.35
max_htlc_msat_ratio = 0.35

[30]
strategy = static
chan.min_ratio = 0.3
max_htlc_msat_ratio = 0.3

[25]
strategy = static
chan.min_ratio = 0.25
max_htlc_msat_ratio = 0.25

[20]
strategy = static
chan.min_ratio = 0.2
max_htlc_msat_ratio = 0.2

[15]
strategy = static
chan.min_ratio = 0.15
max_htlc_msat_ratio = 0.15

#Now the intervals will be increased further.
[12.5]
strategy = static
chan.min_ratio = 0.125
max_htlc_msat_ratio = 0.125

[10]
strategy = static
chan.min_ratio = 0.1
max_htlc_msat_ratio = 0.1

[7.5]
strategy = static
chan.min_ratio = 0.075
max_htlc_msat_ratio = 0.075

[5]
strategy = static
chan.min_ratio = 0.05
max_htlc_msat_ratio = 0.05

[2.5]
strategy = static
chan.min_ratio = 0.025
max_htlc_msat_ratio = 0.025

[1]
strategy = static
chan.min_ratio = 0.01
max_htlc_msat_ratio = 0.01

#If your channel outbound liquidity is less than 1% of the channel size, it may be time to stop routing and rebalance.
[0]
strategy = static
max_htlc_msat = 1_000

To exit the new maxhtlc policy config file, Ctrl+X then Y then Enter

To run a test of how it will affect your channels, you can do a dry-run.

~/.local/bin/charge-lnd --lnddir ~/umbrel/lnd -c ~/charge-lnd/maxhtlc --dry-run

If you are happy with how it is operating, you can remove --dry-run and it will be applied to your channels.

Auto-Adjust

To make it run every so often and update the max-htlc setting for a channel shortly after liquidity moves, you can add it to your crontab.

crontab -e

Then paste in the following job:

33 * * * * /home/umbrel/.local/bin/charge-lnd --lnddir /home/umbrel/umbrel/lnd -c /home/umbrel/charge-lnd/maxhtlc > /tmp/charge-lnd.log 2>&1; date >> /tmp/charge-lnd.log

Replace the number "33" with a random number between 0 and 59. This will be the minute of each hour when it updates. We don't want everyone to pick the same minute which could theoretically harm the gossip network.

You could also have it run even more often than every hour... the problem with changing fees too often is that your node can receive payment failures if it tries to forward a payment while the fee is being updated. But changing max-htlcs too often isn't as big of an issue. If your node tries to forward a payment while your channel is in the process of lowering its max-htlc limit, you may similarly receive a payment failure... but you would have received it anyway most likely, because you probably don't have enough outbound liquidity for the payment.

Since we want to be cautious about the gossip network, unless you operate a large node with lots of channels and capacity, you should consider sticking with once per hour.

To exit cron, Ctrl+X then Y then Enter