diff --git a/README.md b/README.md index aa71729..71ad7fd 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/charge_lnd/strategy.py b/charge_lnd/strategy.py index 2b2e1fc..565aef7 100644 --- a/charge_lnd/strategy.py +++ b/charge_lnd/strategy.py @@ -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 = {} @@ -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)) diff --git a/examples/max-htlc-proportional.config b/examples/max-htlc-proportional.config new file mode 100644 index 0000000..936dd7c --- /dev/null +++ b/examples/max-htlc-proportional.config @@ -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 \ No newline at end of file