Merge pull request #2719 from lbryio/refactor_header_progress

refactor header progress calculation, making it simpler to understand and not prone to division by zero
This commit is contained in:
Jack Robison 2020-01-12 16:16:23 -05:00 committed by GitHub
commit 563d76ff9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -135,11 +135,11 @@ class WalletComponent(Component):
local_height = self.wallet_manager.ledger.local_height_including_downloaded_height
disk_height = len(self.wallet_manager.ledger.headers)
remote_height = self.wallet_manager.ledger.network.remote_height
if disk_height != local_height != remote_height:
download_height, target_height = local_height - disk_height, remote_height - disk_height
download_height, target_height = local_height - disk_height, remote_height - disk_height
if target_height > 0:
progress = min(max(math.ceil(float(download_height) / float(target_height) * 100), 0), 100)
else:
download_height, target_height = local_height, remote_height
progress = min(max(math.ceil(float(download_height) / float(target_height) * 100), 0), 100)
progress = 100
best_hash = self.wallet_manager.get_best_blockhash()
result.update({
'headers_synchronization_progress': progress,