mirror of
https://github.com/aljazceru/plugins.git
synced 2025-12-21 07:04:19 +01:00
autopilot: Avoid "ZeroDivisionError: float division by zero"
Adding checks that prevents num_channels to be zero (or negative) and by that avoiding zero division error.
This commit is contained in:
committed by
Christian Decker
parent
89a4fa3f59
commit
de1cd7314f
@@ -140,6 +140,15 @@ def run_once(plugin, dryrun=False):
|
||||
# Now we can look whether and how we'd like to open new channels. This
|
||||
# depends on available funds and the number of channels we were configured
|
||||
# to open
|
||||
|
||||
if available_funds < plugin.min_capacity_sat:
|
||||
print("Too low available funds: {} < {}".format(available_funds, plugin.min_capacity_sat))
|
||||
return False
|
||||
|
||||
if len(channels) >= plugin.num_channels:
|
||||
print("Already have {} channels. Aim is for {}.".format(len(channels), plugin.num_channels))
|
||||
return False
|
||||
|
||||
num_channels = min(
|
||||
int(available_funds / plugin.min_capacity_sat),
|
||||
plugin.num_channels - len(channels)
|
||||
|
||||
Reference in New Issue
Block a user