Skip to content
Snippets Groups Projects
Commit 70f8ea93 authored by inso's avatar inso
Browse files

Fix multiple bugs :

- Crash if no window fork could be found
- AWAITING and VALIDATING transaction could not be checked again
if the fork size did reduce too much and they were too far from it
parent ca3620e5
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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):
"""
......
......@@ -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:
......
......@@ -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
......
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