Skip to content
Snippets Groups Projects
Commit 6c6db2ac authored by inso's avatar inso
Browse files

Fix problems in network parsing

- Check sync only with online or desynced nodes
- New nodes should be offline before contacting them
parent 453b3b6a
No related branches found
No related tags found
No related merge requests found
...@@ -198,18 +198,18 @@ class Network(QObject): ...@@ -198,18 +198,18 @@ class Network(QObject):
4 : The biggest number or timestamp 4 : The biggest number or timestamp
""" """
# rule number 1 : block of the majority # rule number 1 : block of the majority
blocks = [n.block['hash'] for n in self.nodes if n.block] blocks = [n.block['hash'] for n in self.online_nodes if n.block]
blocks_occurences = Counter(blocks) blocks_occurences = Counter(blocks)
blocks_by_occurences = {} blocks_by_occurences = {}
for key, value in blocks_occurences.items(): for key, value in blocks_occurences.items():
the_block = [n.block for n in self.nodes if n.block and n.block['hash'] == key][0] the_block = [n.block for n in self.online_nodes if n.block and n.block['hash'] == key][0]
if value not in blocks_by_occurences: if value not in blocks_by_occurences:
blocks_by_occurences[value] = [the_block] blocks_by_occurences[value] = [the_block]
else: else:
blocks_by_occurences[value].append(the_block) blocks_by_occurences[value].append(the_block)
if len(blocks_by_occurences) == 0: if len(blocks_by_occurences) == 0:
for n in [n for n in self._nodes if n.state in (Node.ONLINE, Node.DESYNCED)]: for n in [n for n in self.online_nodes if n.state in (Node.ONLINE, Node.DESYNCED)]:
n.state = Node.ONLINE n.state = Node.ONLINE
return return
...@@ -243,7 +243,7 @@ class Network(QObject): ...@@ -243,7 +243,7 @@ class Network(QObject):
else: else:
synced_block_hash = blocks_by_occurences[most_present][0]['hash'] synced_block_hash = blocks_by_occurences[most_present][0]['hash']
for n in [n for n in self._nodes if n.state in (Node.ONLINE, Node.DESYNCED)]: for n in self.online_nodes:
if n.block and n.block['hash'] == synced_block_hash: if n.block and n.block['hash'] == synced_block_hash:
n.state = Node.ONLINE n.state = Node.ONLINE
else: else:
......
...@@ -104,7 +104,7 @@ class Node(QObject): ...@@ -104,7 +104,7 @@ class Node(QObject):
node = cls(peer.currency, peer.endpoints, node = cls(peer.currency, peer.endpoints,
"", pubkey, None, "", pubkey, None,
Node.ONLINE, time.time(), Node.OFFLINE, time.time(),
{'root': "", 'leaves': []}, {'root': "", 'leaves': []},
"", "", 0) "", "", 0)
logging.debug("Node from peer : {:}".format(str(node))) logging.debug("Node from peer : {:}".format(str(node)))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment