From efadb28129a1840f484d9cca261df27a4742bb08 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Fri, 11 Sep 2015 12:15:52 -0700 Subject: [PATCH] Add `report_error` function for peer errors which can be overridden --- contrib/fedpeg/blocksign.py | 3 +++ contrib/fedpeg/constants.py | 4 ++++ contrib/fedpeg/rotating_consensus.py | 17 +++++++++++------ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/contrib/fedpeg/blocksign.py b/contrib/fedpeg/blocksign.py index 4bb97027b7..3946b81bec 100755 --- a/contrib/fedpeg/blocksign.py +++ b/contrib/fedpeg/blocksign.py @@ -52,6 +52,9 @@ def round_failed(self): self.round_local_block_hex = "" return + def report_error(self, msg): + settings.report_error(msg) + sidechain.importprivkey(settings.blocksigning_private_key) settings.nodes.remove(settings.my_node) diff --git a/contrib/fedpeg/constants.py b/contrib/fedpeg/constants.py index e7f84ed7f7..bb173bb358 100755 --- a/contrib/fedpeg/constants.py +++ b/contrib/fedpeg/constants.py @@ -44,3 +44,7 @@ def __init__(self): self.sigs_required = int(self.redeem_script[:2], 16) - 0x50 self.inverse_bitcoin_genesis_hash = "".join(reversed([self.bitcoin_genesis_hash[i:i+2] for i in range(0, len(self.bitcoin_genesis_hash), 2)])) + + def report_error(self, msg): + print("Error: %s" % msg) + diff --git a/contrib/fedpeg/rotating_consensus.py b/contrib/fedpeg/rotating_consensus.py index 048e36d514..19f27a5e98 100644 --- a/contrib/fedpeg/rotating_consensus.py +++ b/contrib/fedpeg/rotating_consensus.py @@ -82,11 +82,11 @@ def main_loop(self): sleep(self.interval / 10) msg = self._gen_master_msg() if msg == None: - print("gen_master_msg threw or returned None") + self.report_error("gen_master_msg threw or returned None") self._round_failed() continue if time() - start_time > self.interval / 5: - print("gen_master_msg took longer than interval/5: Skipping round!") + self.report_error("gen_master_msg took longer than interval/5: Skipping round!") self._round_failed() continue self.publisher.send_message(msg) @@ -98,17 +98,17 @@ def main_loop(self): msg = self.nodes[step].read_message() if msg == None: - print("Missed message from master") + self.report_error("Missed message from master") self._round_failed() continue broadcast_msg = self._recv_master_msg(msg) if broadcast_msg == None: - print("recv_master_msg threw or returned None") + self.report_error("recv_master_msg threw or returned None") self._round_failed() continue if time() - start_time > self.interval / 2: - print("recv_master_msg took longer than interval/4: Skipping round!") + self.report_error("recv_master_msg took longer than interval/4: Skipping round!") self._round_failed() continue self.publisher.send_message(broadcast_msg) @@ -120,10 +120,12 @@ def main_loop(self): msg = node.read_message() if msg != None: msgs.append((node.host, msg)) + elif node != self.nodes[step] and not node.isSelf: + self.report_error("Missed message from %s" % node.host) self._round_done(msgs) if time() > start_time + self.interval: - print("round_done took longer than interval/2: We skipped a round!") + self.report_error("round_done took longer than interval/2: We skipped a round!") def _gen_master_msg(self): try: @@ -179,3 +181,6 @@ def round_done(self, peer_messages): def round_failed(self): return + + def report_error(self, msg): + print("Error: %s" % msg)