From 0ad2de38c26da5a9e4955de43c6a459cfbb2b796 Mon Sep 17 00:00:00 2001 From: Tim Horie Date: Thu, 7 Dec 2023 17:03:31 +0900 Subject: [PATCH 1/4] Set the max_htlc based on local balance --- examples/max-htlc-proportional.config | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 examples/max-htlc-proportional.config diff --git a/examples/max-htlc-proportional.config b/examples/max-htlc-proportional.config new file mode 100644 index 0000000..f8264b8 --- /dev/null +++ b/examples/max-htlc-proportional.config @@ -0,0 +1,19 @@ +# 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] +max_htlc_proportional_slices = 6 \ No newline at end of file From 91f29983f19c92b19602dc148008b5b6fc3b7b8e Mon Sep 17 00:00:00 2001 From: Tim Horie Date: Thu, 7 Dec 2023 17:54:03 +0900 Subject: [PATCH 2/4] Added proportional max_htlc strategy --- README.md | 1 + charge_lnd/charge_lnd.py | 2 ++ charge_lnd/strategy.py | 19 +++++++++++++++++++ charge_lnd/test1.py | 21 +++++++++++++++++++++ examples/max-htlc-proportional.config | 5 +++++ 5 files changed, 48 insertions(+) create mode 100644 charge_lnd/test1.py 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/charge_lnd.py b/charge_lnd/charge_lnd.py index acf64b2..059f8fa 100755 --- a/charge_lnd/charge_lnd.py +++ b/charge_lnd/charge_lnd.py @@ -123,6 +123,8 @@ def main(): if time_lock_delta_changed: s = ' ➜ ' + fmt.col_hi(new_time_lock_delta) print(" time_lock_delta: %s%s" % (fmt.col_hi(my_policy.time_lock_delta), s) ) + #debugging - just exit after one + return True return True diff --git a/charge_lnd/strategy.py b/charge_lnd/strategy.py index 2b2e1fc..ebae832 100644 --- a/charge_lnd/strategy.py +++ b/charge_lnd/strategy.py @@ -19,6 +19,20 @@ 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) + + print(f"max: {max_value}, current: {current_value}, slices: {num_slices}") + print(f"slice_point: {slice_point}") + + return slice_point class StrategyDelegate: STRATEGIES = {} @@ -48,6 +62,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/charge_lnd/test1.py b/charge_lnd/test1.py new file mode 100644 index 0000000..b33a1ae --- /dev/null +++ b/charge_lnd/test1.py @@ -0,0 +1,21 @@ +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 + +# Example usage +max_value = 1000000 +current_value = 1000000 +num_slices = 10 + +slice_point = calculate_slices(max_value, current_value, num_slices) + +print(f"max: {max_value}, current: {current_value}, slices: {num_slices}") +print(f"slice_point: {slice_point}") \ No newline at end of file diff --git a/examples/max-htlc-proportional.config b/examples/max-htlc-proportional.config index f8264b8..936dd7c 100644 --- a/examples/max-htlc-proportional.config +++ b/examples/max-htlc-proportional.config @@ -16,4 +16,9 @@ # 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 From 06982ad6db4857b73b831fe8228a969e92381947 Mon Sep 17 00:00:00 2001 From: Tim Horie Date: Thu, 7 Dec 2023 17:55:50 +0900 Subject: [PATCH 3/4] Remove debugging --- charge_lnd/charge_lnd.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/charge_lnd/charge_lnd.py b/charge_lnd/charge_lnd.py index 059f8fa..acf64b2 100755 --- a/charge_lnd/charge_lnd.py +++ b/charge_lnd/charge_lnd.py @@ -123,8 +123,6 @@ def main(): if time_lock_delta_changed: s = ' ➜ ' + fmt.col_hi(new_time_lock_delta) print(" time_lock_delta: %s%s" % (fmt.col_hi(my_policy.time_lock_delta), s) ) - #debugging - just exit after one - return True return True From 595315be4386868034f57e73569165057bfbfd64 Mon Sep 17 00:00:00 2001 From: Tim Horie Date: Thu, 7 Dec 2023 17:56:30 +0900 Subject: [PATCH 4/4] Remove debugging --- charge_lnd/strategy.py | 3 --- charge_lnd/test1.py | 21 --------------------- 2 files changed, 24 deletions(-) delete mode 100644 charge_lnd/test1.py diff --git a/charge_lnd/strategy.py b/charge_lnd/strategy.py index ebae832..565aef7 100644 --- a/charge_lnd/strategy.py +++ b/charge_lnd/strategy.py @@ -29,9 +29,6 @@ def calculate_slices(max_value, current_value, num_slices): # Determine the upper value of the slice closest to current without going over slice_point = min((current_slice + 1) * slice_size - 1, max_value) - print(f"max: {max_value}, current: {current_value}, slices: {num_slices}") - print(f"slice_point: {slice_point}") - return slice_point class StrategyDelegate: diff --git a/charge_lnd/test1.py b/charge_lnd/test1.py deleted file mode 100644 index b33a1ae..0000000 --- a/charge_lnd/test1.py +++ /dev/null @@ -1,21 +0,0 @@ -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 - -# Example usage -max_value = 1000000 -current_value = 1000000 -num_slices = 10 - -slice_point = calculate_slices(max_value, current_value, num_slices) - -print(f"max: {max_value}, current: {current_value}, slices: {num_slices}") -print(f"slice_point: {slice_point}") \ No newline at end of file