def _update_message_fault_tolerance(self): for message in self.view.justified_messages.values(): if message not in self.bet_fault_tolerance: oracle = CliqueOracle(message, self.view, self.validator_set) fault_tolerance, num_node_ft = oracle.check_estimate_safety() if fault_tolerance > 0: self.bet_fault_tolerance[message] = num_node_ft
def _update_block_fault_tolerance(self): tip = self.view.estimate() while tip and self.block_fault_tolerance.get(tip, 0) != len(self.validator_set) - 1: oracle = CliqueOracle(tip, self.view, self.validator_set) fault_tolerance, num_node_ft = oracle.check_estimate_safety() if fault_tolerance > 0: self.block_fault_tolerance[tip] = num_node_ft tip = tip.estimate
def update_safe_estimates(self, validator_set): """Checks safety on most recent created by this view""" # check estimate safety on the most for bet in self.latest_messages.values(): oracle = CliqueOracle(bet, self, validator_set) fault_tolerance, _ = oracle.check_estimate_safety() if fault_tolerance > 0: if self.last_finalized_estimate: assert not self.last_finalized_estimate.conflicts_with(bet) self.last_finalized_estimate = bet break
def _update_message_fault_tolerance(self): for validator in self.view.latest_messages: latest_message = self.view.latest_messages[validator] if latest_message in self.bet_fault_tolerance: continue oracle = CliqueOracle(latest_message, validator.view, self.validator_set) fault_tolerance, num_node_ft = oracle.check_estimate_safety() if fault_tolerance > 0: self.bet_fault_tolerance[latest_message] = num_node_ft
def update_safe_estimates(self, validator_set): """Checks safety on messages in views forkchoice, and updates last_finalized_block""" tip = self.estimate() while tip and tip != self.last_finalized_block: oracle = CliqueOracle(tip, self, validator_set) fault_tolerance, _ = oracle.check_estimate_safety() if fault_tolerance > 0: self.last_finalized_block = tip self._update_when_finalized_cache(tip) return self.last_finalized_block tip = tip.estimate
def report(self, num, name): """Display the view graph of the current global_view""" assert num == name and num == '', "...no validator or number needed to report!" if not self.display: return # Update the safe blocks! tip = self.network.global_view.estimate() while tip and self.block_fault_tolerance.get( tip, 0) != len(self.validator_set) - 1: oracle = CliqueOracle(tip, self.network.global_view, self.validator_set) fault_tolerance, num_node_ft = oracle.check_estimate_safety() if fault_tolerance > 0: self.block_fault_tolerance[tip] = num_node_ft tip = tip.estimate edgelist = [] best_chain = utils.build_chain(self.network.global_view.estimate(), None) edgelist.append(utils.edge(best_chain, 5, 'red', 'solid')) for validator in self.validator_set: chain = utils.build_chain(validator.my_latest_message(), None) edgelist.append(utils.edge(chain, 2, 'blue', 'solid')) edgelist.append(utils.edge(self.blockchain, 2, 'grey', 'solid')) edgelist.append(utils.edge(self.communications, 1, 'black', 'dotted')) message_labels = {} for block in self.network.global_view.messages: message_labels[block] = block.sequence_number self.plot_tool.next_viewgraph( self.network.global_view, self.validator_set, edges=edgelist, message_colors=self.block_fault_tolerance, message_labels=message_labels)
def update_safe_estimates(self, validator_set): """Checks safety on messages in views forkchoice, and updates last_finalized_block""" tip = self.estimate() prev_last_finalized_block = self.last_finalized_block while tip and tip != prev_last_finalized_block: oracle = CliqueOracle(tip, self, validator_set) fault_tolerance, _ = oracle.check_estimate_safety() if fault_tolerance > 0: self.last_finalized_block = tip # then, a sanity check! if prev_last_finalized_block: assert prev_last_finalized_block.is_in_blockchain(self.last_finalized_block) # cache when_finalized while tip and tip not in self.when_finalized: self.when_finalized[tip] = len(self.messages) tip = tip.estimate return self.last_finalized_block tip = tip.estimate