diff --git a/src/cutecoin/core/graph.py b/src/cutecoin/core/graph.py index d29e66ed098eca787dd690f7821ff7c172c79c8f..48c0a2bd899b3181f6dc88cc345b0572fea767cb 100644 --- a/src/cutecoin/core/graph.py +++ b/src/cutecoin/core/graph.py @@ -252,19 +252,19 @@ class Graph(object): current_validations = self.community.network.latest_block_number - certified['block_number'] else: current_validations = 0 - max_validation = self.community.network.fork_window(self.community.members_pubkeys()) + max_validations = self.community.network.fork_window(self.community.members_pubkeys()) + 1 - if current_validations < max_validation: + if current_validations < max_validations: if self.app.preferences['expert_mode']: arc['validation_text'] = "{0}/{1}".format(current_validations, - max_validation) + max_validations) else: - validation = current_validations / max_validation * 100 + validation = current_validations / max_validations * 100 + validation = 100 if validation > 100 else validation arc['validation_text'] = "{0} %".format(QLocale().toString(float(validation), 'f', 0)) else: arc['validation_text'] = None - # replace old arc if this one is more recent new_arc = True index = 0 diff --git a/src/cutecoin/core/net/network.py b/src/cutecoin/core/net/network.py index 3ba01a0c5e83d3ef37868283680168f35ffda533..9369afe5420f426af0058bb07184f867ca40031d 100644 --- a/src/cutecoin/core/net/network.py +++ b/src/cutecoin/core/net/network.py @@ -183,8 +183,12 @@ class Network(QObject): Get the medium of the fork window of the nodes members of a community :return: the medium fork window of knew network """ - return statistics.median([n.fork_window for n in self.nodes if n.software != "" - and n.pubkey in members_pubkeys]) + fork_windows = [n.fork_window for n in self.nodes if n.software != "" + and n.pubkey in members_pubkeys] + if len(fork_windows) > 0: + return statistics.median(fork_windows) + else: + return 0 def add_node(self, node): """ diff --git a/src/cutecoin/core/txhistory.py b/src/cutecoin/core/txhistory.py index 43023613f39a5ae5845b864dc69a3887ceb8c5af..a268190bf66f68530d3bd4d4e2a62c35c6e0d189 100644 --- a/src/cutecoin/core/txhistory.py +++ b/src/cutecoin/core/txhistory.py @@ -72,7 +72,7 @@ class TxHistory(): @staticmethod def _validation_state(community, block_number, current_block): - if block_number + community.network.fork_window(community.members_pubkeys()) < current_block["number"]: + if block_number + community.network.fork_window(community.members_pubkeys()) + 1 < current_block["number"]: state = Transfer.VALIDATED else: state = Transfer.VALIDATING @@ -154,7 +154,7 @@ class TxHistory(): else: transfer = [t for t in awaiting if t.hash == txdata['hash']][0] transfer.check_registered(txdata['hash'], current_block['number'], mediantime, - community.network.fork_window(community.members_pubkeys())) + community.network.fork_window(community.members_pubkeys()) + 1) return None @asyncio.coroutine @@ -168,7 +168,13 @@ class TxHistory(): current_block = yield from community.bma_access.future_request(qtbma.blockchain.Block, req_args={'number': community.network.latest_block_number}) - parsed_block = min(self.latest_block, current_block['number'] - community.network.fork_window(community.members_pubkeys())) + # We look for the first block to parse, depending on awaiting and validating transfers and ud... + blocks = [tx.metadata['block_number'] for tx in self._transfers + if tx.state in (Transfer.AWAITING, Transfer.VALIDATING)] +\ + [ud['block_number'] for ud in self._dividends + if ud['state'] in (Transfer.AWAITING, Transfer.VALIDATING)] +\ + [self.latest_block] + parsed_block = min(set(blocks)) logging.debug("Refresh from : {0} to {1}".format(self.latest_block, current_block['number'])) dividends_data = qtbma.ud.History.null_value while dividends_data == qtbma.ud.History.null_value: diff --git a/src/cutecoin/models/txhistory.py b/src/cutecoin/models/txhistory.py index 6f0e897209d468a5cb0134a199db0e5247341dd7..4576cdaf82905efdca9e996902fb27b9f441d944 100644 --- a/src/cutecoin/models/txhistory.py +++ b/src/cutecoin/models/txhistory.py @@ -153,12 +153,13 @@ class TxFilterProxyModel(QSortFilterProxyModel): current_validations = self.community.network.latest_block_number - block_data else: current_validations = 0 - max_validations = self.community.network.fork_window(self.community.members_pubkeys()) + max_validations = self.community.network.fork_window(self.community.members_pubkeys()) + 1 if self.app.preferences['expert_mode']: return self.tr("{0} / {1} validations").format(current_validations, max_validations) else: validation = current_validations / max_validations * 100 + validation = 100 if validation > 100 else validation return self.tr("Validating... {0} %").format(QLocale().toString(float(validation), 'f', 0)) return None