mirror of
https://github.com/lightningd/plugins.git
synced 2026-08-19 13:18:19 +02: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:
parent
89a4fa3f59
commit
de1cd7314f
1 changed files with 9 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue