Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ All strategies (except the ignore strategy) will apply the following properties
| **min_htlc_msat** | Minimum size (in msat) of HTLC to allow | # msat |
| **max_htlc_msat** | Maximum size (in msat) of HTLC to allow | # msat |
| **max_htlc_msat_ratio** | Maximum size of HTLC to allow as a fraction of total channel capacity | 0..1 |
| **max_htlc_proportional_slices** | Maximum size of HTLC set proportionally to local balance with slices number of steps | # slices |
| **time_lock_delta** | Time Lock Delta | # blocks |
| **min_fee_ppm_delta** | Minimum change in fees (ppm) before updating channel | ppm delta |

Expand Down
16 changes: 16 additions & 0 deletions charge_lnd/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ def call_strategy(*args, **kwargs):
return call_strategy
return register_strategy

def calculate_slices(max_value, current_value, num_slices):
# Calculate the size of each slice
slice_size = max_value // num_slices

# Find the slice number containing the current_value
current_slice = min(current_value // slice_size, num_slices - 1)

# Determine the upper value of the slice closest to current without going over
slice_point = min((current_slice + 1) * slice_size - 1, max_value)

return slice_point

class StrategyDelegate:
STRATEGIES = {}
Expand Down Expand Up @@ -48,6 +59,11 @@ def execute(self, channel):

def effective_max_htlc_msat(self, channel):
result = self.policy.getint('max_htlc_msat')

slices = self.policy.getint('max_htlc_proportional_slices')
if slices:
result = calculate_slices(channel.capacity, channel.local_balance, slices)

ratio = self.policy.getfloat('max_htlc_msat_ratio')
if ratio:
ratio = max(0,min(1,ratio))
Expand Down
24 changes: 24 additions & 0 deletions examples/max-htlc-proportional.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# all channels max_htlc set to a value proportional to
# local balance, with specified number of divisions
# e.g.
# slices = 10
# channel_size = 1_000_000 sats
# max_htlc values:
# 100_000, 200_000, 300_000, 400_000, 500_000
# 600_000, 700_000, 800_000, 900_000, 1_000_000
#
# slices = 2
# channel_size = 800_000_sats
# max_htlc values:
# 400_000, 800_000
#
# Rationale: avoid insufficient local balance failures
# to improve your node's reputation of successful forwarding.

[default]
strategy = ignore

[proportional_htlc]
chan.max_local_balance = 30_000_000
strategy = static
max_htlc_proportional_slices = 6