Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add report_error function for peer errors which can be overridden #52

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions contrib/fedpeg/blocksign.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions contrib/fedpeg/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

17 changes: 11 additions & 6 deletions contrib/fedpeg/rotating_consensus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -179,3 +181,6 @@ def round_done(self, peer_messages):

def round_failed(self):
return

def report_error(self, msg):
print("Error: %s" % msg)