From de1cd7314f77d82a5e938e080ea7efa561916a3a Mon Sep 17 00:00:00 2001 From: Moller40 Date: Tue, 29 Sep 2020 12:12:16 +0200 Subject: [PATCH] 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. --- autopilot/autopilot.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/autopilot/autopilot.py b/autopilot/autopilot.py index 5c96cb7..f429282 100755 --- a/autopilot/autopilot.py +++ b/autopilot/autopilot.py @@ -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)