diff --git a/src/cutecoin/core/graph.py b/src/cutecoin/core/graph.py index 8a7cdbd00f6b5fcdcb7207fa46886e8f0ddef4ee..54db4f9d49f81bf33325714a4dfa4404e4ee2815 100644 --- a/src/cutecoin/core/graph.py +++ b/src/cutecoin/core/graph.py @@ -170,6 +170,7 @@ class Graph(object): arc_status = ARC_STATUS_WEAK else: arc_status = ARC_STATUS_STRONG + arc = { 'id': identity.pubkey, 'status': arc_status, @@ -180,6 +181,11 @@ class Graph(object): ), 'cert_time': certifier['cert_time'] } + + if certifier['identity'].blockchain_state == BlockchainState.VALIDATED: + arc['current_validation'] = self.community.network.latest_block_number - certifier['block_number'] + arc['max_validation'] = self.community.network.fork_window(self.community.members_pubkeys()) + #  add arc to certifier self._graph[certifier['identity'].pubkey]['arcs'].append(arc) # if certifier node not in identity nodes @@ -230,6 +236,10 @@ class Graph(object): 'cert_time': certified['cert_time'] } + if certified['identity'].blockchain_state == BlockchainState.VALIDATED: + arc['current_validation'] = self.community.network.latest_block_number - certified['block_number'] + arc['max_validation'] = self.community.network.fork_window(self.community.members_pubkeys()) + # 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 ffac7223e416559da8f25a1429391727d21ee16f..78c0c2940b75f576d76bb373601f9bfa5c427eb9 100644 --- a/src/cutecoin/core/net/network.py +++ b/src/cutecoin/core/net/network.py @@ -6,6 +6,7 @@ Created on 24 févr. 2015 from cutecoin.core.net.node import Node import logging +import statistics import time import asyncio from ucoinpy.documents.peer import Peer @@ -177,6 +178,14 @@ class Network(QObject): else: return Block.Empty_Hash + def fork_window(self, members_pubkeys): + """ + 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]) + def add_node(self, node): """ Add a node to the network. diff --git a/src/cutecoin/core/net/node.py b/src/cutecoin/core/net/node.py index 2e681bbaf11f8d3ee95aebad3383a05260839c1a..bf7fe9a6c2e552d5c6fb3f3a3a66eef721a1ee03 100644 --- a/src/cutecoin/core/net/node.py +++ b/src/cutecoin/core/net/node.py @@ -39,7 +39,7 @@ class Node(QObject): neighbour_found = pyqtSignal(Peer, str) def __init__(self, network_manager, currency, endpoints, uid, pubkey, block_number, block_hash, - state, last_change, last_merkle, software, version): + state, last_change, last_merkle, software, version, fork_window): """ Constructor """ @@ -57,6 +57,7 @@ class Node(QObject): self._last_merkle = last_merkle self._software = software self._version = version + self._fork_window = fork_window @classmethod @asyncio.coroutine @@ -95,7 +96,7 @@ class Node(QObject): node = cls(network_manager, peer.currency, [Endpoint.from_inline(e.inline()) for e in peer.endpoints], "", peer.pubkey, 0, Block.Empty_Hash, Node.ONLINE, time.time(), - {'root': "", 'leaves': []}, "", "") + {'root': "", 'leaves': []}, "", "", 0) logging.debug("Node from address : {:}".format(str(node))) return node else: @@ -119,7 +120,7 @@ class Node(QObject): "", pubkey, 0, Block.Empty_Hash, Node.ONLINE, time.time(), {'root': "", 'leaves': []}, - "", "") + "", "", 0) logging.debug("Node from peer : {:}".format(str(node))) return node @@ -130,6 +131,7 @@ class Node(QObject): pubkey = "" software = "" version = "" + fork_window = 0 block_number = 0 block_hash = Block.Empty_Hash last_change = time.time() @@ -164,14 +166,15 @@ class Node(QObject): if 'version' in data: version = data['version'] - else: - logging.debug("Error : no state in node") + + if 'fork_window' in data: + fork_window = data['fork_window'] node = cls(network_manager, currency, endpoints, uid, pubkey, block_number, block_hash, state, last_change, {'root': "", 'leaves': []}, - software, version) + software, version, fork_window) logging.debug("Node from json : {:}".format(str(node))) return node @@ -197,6 +200,7 @@ class Node(QObject): 'block_hash': self.block_hash, 'software': self._software, 'version': self._version, + 'fork_window': self._fork_window } endpoints = [] for e in self._endpoints: @@ -278,6 +282,16 @@ class Node(QObject): self.last_change = time.time() self._state = new_state + @property + def fork_window(self): + return self._fork_window + + @fork_window.setter + def fork_window(self, new_fork_window): + if self._fork_window != new_fork_window: + self._fork_window = new_fork_window + self.changed.emit() + def check_sync(self, block_hash): logging.debug("Check sync") if self.block_hash != block_hash: @@ -388,6 +402,10 @@ class Node(QObject): summary_data = json.loads(strdata) self.software = summary_data["ucoin"]["software"] self.version = summary_data["ucoin"]["version"] + if "forkWindowSize" in summary_data["ucoin"]: + self.fork_window = summary_data["ucoin"]["forkWindowSize"] + else: + self.fork_window = 0 else: self.changed.emit() diff --git a/src/cutecoin/core/registry/identity.py b/src/cutecoin/core/registry/identity.py index 30ab91f1b196cc903fa4abf8f7e9620fe681c5b0..95ff92cd6e7c8194a6bbc389bdb863c0ff0e48cb 100644 --- a/src/cutecoin/core/registry/identity.py +++ b/src/cutecoin/core/registry/identity.py @@ -242,6 +242,8 @@ class Identity(QObject): block = community.bma_access.get(self, qtbma.blockchain.Block, {'number': certifier_data['meta']['block_number']}) certifier['cert_time'] = block['medianTime'] + certifier['block_number'] = None + certifiers.append(certifier) else: for certifier_data in data['certifications']: @@ -250,6 +252,7 @@ class Identity(QObject): certifier_data['pubkey'], BlockchainState.VALIDATED) certifier['cert_time'] = certifier_data['cert_time']['medianTime'] + certifier['block_number'] = certifier_data['cert_time']['block'] certifiers.append(certifier) return certifiers @@ -295,6 +298,7 @@ class Identity(QObject): certified_data['pubkey'], BlockchainState.BUFFERED) certified['cert_time'] = certified_data['meta']['timestamp'] + certified['block_number'] = None certified_list.append(certified) else: for certified_data in data['certifications']: @@ -303,6 +307,7 @@ class Identity(QObject): certified_data['pubkey'], BlockchainState.VALIDATED) certified['cert_time'] = certified_data['cert_time']['medianTime'] + certified['block_number'] = certified_data['cert_time']['block'] certified_list.append(certified) return certified_list diff --git a/src/cutecoin/core/txhistory.py b/src/cutecoin/core/txhistory.py index 8c60a80bdd31bbe4eaf393cac83d3ed4bc6433c6..c801a10b3e5c683c094044cdb8123d2af4c5af42 100644 --- a/src/cutecoin/core/txhistory.py +++ b/src/cutecoin/core/txhistory.py @@ -164,7 +164,7 @@ 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'] - self.app.preferences['data_validation']) + parsed_block = min(self.latest_block, current_block['number'] - community.network.fork_window(community.members_pubkeys())) 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/gui/currency_tab.py b/src/cutecoin/gui/currency_tab.py index 5d4883073187ae4ca1f8350eaa4e3f164e95f223..973b675e00de6b623abb97300dfd0e4d3e4a973c 100644 --- a/src/cutecoin/gui/currency_tab.py +++ b/src/cutecoin/gui/currency_tab.py @@ -181,6 +181,9 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): if status_infotext != "": label_text += " - {0}".format(status_infotext) + if self.app.preferences['expert_mode']: + label_text += " - Median fork window : {0}".format(self.community.network.fork_window(self.community.members_pubkeys())) + self.status_label.setText(label_text) def showEvent(self, event): diff --git a/src/cutecoin/gui/views/wot.py b/src/cutecoin/gui/views/wot.py index 07bc810edb480fc90e48edb1db6a63f915b0afc5..f5206211db03c8900ea7cc4f080c171d89ab8b9b 100644 --- a/src/cutecoin/gui/views/wot.py +++ b/src/cutecoin/gui/views/wot.py @@ -471,3 +471,9 @@ class Arc(QGraphicsLineItem): painter.setBrush(color) painter.drawPolygon(QPolygonF([head_point, destination_arrow_p1, destination_arrow_p2])) + if 'current_validation' in self.metadata: + if self.metadata['current_validation'] < self.metadata['max_validation']: + validation = self.metadata['current_validation'] / self.metadata['max_validation'] * 100 + painter.drawText(head_point, "{0} %".format(validation)) + else: + painter.drawText(head_point, "0%")