From 3ffba5c6bc48628b27f4ff8dad57b5f960a13538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=BA=C3=B1ez?= Date: Thu, 15 Oct 2020 01:58:13 +0200 Subject: [PATCH 1/3] When handling failed TXs, don't crash if you can't get a nice error message --- nucypher/blockchain/eth/interfaces.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/nucypher/blockchain/eth/interfaces.py b/nucypher/blockchain/eth/interfaces.py index 738ce7c95..28c4c15f8 100644 --- a/nucypher/blockchain/eth/interfaces.py +++ b/nucypher/blockchain/eth/interfaces.py @@ -143,10 +143,15 @@ class BlockchainInterface: @property def insufficient_eth(self) -> str: - gas = (self.payload.get('gas', 1) * self.payload['gasPrice']) # FIXME: If gas is not included... - cost = gas + self.payload.get('value', 0) - message = f'{self.payload} from {self.payload["from"][:8]} - {self.base_message}.' \ - f'Calculated cost is {cost} but sender only has {self.get_balance()}.' + try: + transaction_fee = self.payload['gas'] * self.payload['gasPrice'] + except KeyError: + return self.default + else: + cost = transaction_fee + self.payload.get('value', 0) + message = f'{self.name} from {self.payload["from"][:8]} - {self.base_message}.' \ + f'Calculated cost is {prettify_eth_amount(cost)},' \ + f'but sender only has {prettify_eth_amount(self.get_balance())}.' return message def __init__(self, From 06d32b496dbf37d5e8391933adfddca6ee2bd9dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=BA=C3=B1ez?= Date: Fri, 16 Oct 2020 16:37:46 +0200 Subject: [PATCH 2/3] Using node.serving_domain as a workaround for #2356 --- nucypher/network/nodes.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nucypher/network/nodes.py b/nucypher/network/nodes.py index 26321f6f4..481bcf975 100644 --- a/nucypher/network/nodes.py +++ b/nucypher/network/nodes.py @@ -350,7 +350,10 @@ class Learner: restored_from_disk = [] invalid_nodes = defaultdict(list) for node in stored_nodes: - node_domain = node.domain.decode('utf-8') + try: # Workaround until #2356 is fixed + node_domain = node.domain.decode('utf-8') + except: + node_domain = node.serving_domain if node_domain != self.learning_domain: invalid_nodes[node_domain].append(node) continue @@ -520,7 +523,7 @@ class Learner: except IndexError: error = "Not enough nodes to select a good teacher, Check your network connection then node configuration" raise self.NotEnoughTeachers(error) - self.log.info("Cycled teachers; New teacher is {}".format(self._current_teacher_node)) + self.log.debug("Cycled teachers; New teacher is {}".format(self._current_teacher_node)) def current_teacher_node(self, cycle=False): if cycle: @@ -1359,7 +1362,7 @@ class Teacher: "last_seen": last_seen, "fleet_state": node.fleet_state_checksum or 'unknown', "fleet_state_icon": fleet_icon, - "domain": node.learning_domain, + "domain": node.serving_domain, 'version': nucypher.__version__} return payload From d7315f7c504154751eff3ef1814ca13395048227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=BA=C3=B1ez?= Date: Fri, 16 Oct 2020 16:49:32 +0200 Subject: [PATCH 3/3] Reduce some annoying learning messages (thinking of you, Damon) --- nucypher/network/nodes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nucypher/network/nodes.py b/nucypher/network/nodes.py index 481bcf975..7981c921f 100644 --- a/nucypher/network/nodes.py +++ b/nucypher/network/nodes.py @@ -386,7 +386,7 @@ class Learner: with suppress(KeyError): already_known_node = self.known_nodes[node.checksum_address] if not node.timestamp > already_known_node.timestamp: - self.log.debug("Skipping already known node {}".format(already_known_node)) + # self.log.debug("Skipping already known node {}".format(already_known_node)) # FIXME: ""OMG, enough with the learning already!" – @vepkenez (#1712) # This node is already known. We can safely return. return False @@ -784,7 +784,7 @@ class Learner: # These except clauses apply to the current_teacher itself, not the learned-about nodes. except NodeSeemsToBeDown as e: unresponsive_nodes.add(current_teacher) - self.log.info(f"Teacher {str(current_teacher)} is perhaps down: {bytes(current_teacher)}:{e}.") + self.log.info(f"Teacher {str(current_teacher)} is perhaps down:{e}.") # FIXME: This was printing the node bytestring. Is this really necessary? #1712 return except current_teacher.InvalidNode as e: # Ugh. The teacher is invalid. Rough.