def consensus_most_common(self): """Consensus vote""" try: return most_common_dict(self.peer_opinion_dict) except: # no consensus yet return 0
def consensus_add(self, peer_ip, consensus_blockheight, sdef, last_block): # obviously too old blocks, we have half a day worth of validated blocks after them # no ban, they can (should) be syncing but they can't possibly be in consensus list. too_old = last_block - 720 try: if peer_ip not in self.peer_opinion_dict: if consensus_blockheight < too_old: self.app_log.warning(f"{peer_ip} received block too old ({consensus_blockheight}) for consensus") return self.app_log.info(f"Updating {peer_ip} in consensus") self.peer_opinion_dict[peer_ip] = consensus_blockheight self.consensus = most_common_dict(self.peer_opinion_dict) self.consensus_percentage = percentage_in(self.peer_opinion_dict[peer_ip],self.peer_opinion_dict.values()) if int(consensus_blockheight) > int(self.consensus) + 30 and self.consensus_percentage > 50 and len(self.peer_opinion_dict) > 10: if self.warning(sdef, peer_ip, f"Consensus deviation too high, {peer_ip} banned", 10): return except Exception as e: self.app_log.warning(e) exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno) raise