From 1ef600a9dff5b90e0243c016045837088018991a Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Thu, 11 Aug 2022 20:51:41 +0100 Subject: [PATCH] Simplify variable names and reformat --- modules/chankeep.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/modules/chankeep.py b/modules/chankeep.py index 3133a98..7f7ce14 100644 --- a/modules/chankeep.py +++ b/modules/chankeep.py @@ -69,16 +69,27 @@ def emptyChanAllocate(net, flist, relay, new): chanfree[0][i] = chanfree[1] allocated = {} toalloc = len(flist) + # Used to correct allocations and provision additional relays + # if the math since the last LIST is a bit wrong # toalloc:2148 free:{1: 250} chanlimit:250 correction:2147 if toalloc > sum(chanfree[0].values()): - sum_free = sum(chanfree[0].values()) # 250 - chans_not_covered = toalloc - sum_free # 2148 - 250 = 1898 - relays_needed = chans_not_covered / chanfree[1] # 1898 / 250 = 7.592 - relays_needed_rounded = ceil(relays_needed) - debug(f"emptyChanAllocate() secondary allocation sum_free:{sum_free} chans_not_covered:{chans_not_covered} relays_needed:{relays_needed} relays_needed_rounded:{relays_needed_rounded}") - #correction = round(toalloc - sum(chanfree[0].values()) / chanfree[1]) - correction = relays_needed_rounded - debug(f"emptyChanAllocate() not enough free channels: toalloc:{toalloc} free:{chanfree[0]} chanlimit:{chanfree[1]} correction:{correction}") + sum_free = sum(chanfree[0].values()) # 250 + chans_not_covered = toalloc - sum_free # 2148 - 250 = 1898 + relays_needed = chans_not_covered / chanfree[1] # 1898 / 250 = 7.592 + correction = ceil(relays_needed) + debug( + ( + f"emptyChanAllocate() secondary allocation sum_free:{sum_free} " + f"chans_not_covered:{chans_not_covered} relays_needed:{relays_needed} " + f"correction:{correction}" + ) + ) + debug( + ( + f"emptyChanAllocate() not enough free channels: toalloc:{toalloc} " + f"free:{chanfree[0]} chanlimit:{chanfree[1]} correction:{correction}" + ) + ) warn("Ran out of channel spaces, provisioning additional %i relays for %s" % (correction, net)) modules.provision.provisionMultipleRelays(net, correction) return False