diff --git a/lbry/lbry/extras/daemon/Components.py b/lbry/lbry/extras/daemon/Components.py index ccbc83e5a..c5ee91813 100644 --- a/lbry/lbry/extras/daemon/Components.py +++ b/lbry/lbry/extras/daemon/Components.py @@ -107,7 +107,7 @@ class WalletComponent(Component): async def get_status(self): if self.wallet_manager and self.wallet_manager.ledger.network.remote_height: - local_height = self.wallet_manager.ledger.headers.height + local_height = self.wallet_manager.ledger.local_height_including_downloaded_height remote_height = self.wallet_manager.ledger.network.remote_height best_hash = self.wallet_manager.get_best_blockhash() return { diff --git a/torba/tests/client_tests/integration/test_network.py b/torba/tests/client_tests/integration/test_network.py index 9f0628301..b56734110 100644 --- a/torba/tests/client_tests/integration/test_network.py +++ b/torba/tests/client_tests/integration/test_network.py @@ -76,19 +76,18 @@ class ReconnectTests(IntegrationTestCase): async def test_direct_sync(self): await self.ledger.stop() - initial_height = self.ledger.headers.height + initial_height = self.ledger.local_height_including_downloaded_height await self.blockchain.generate(100) - while self.conductor.spv_node.server.bp.height < initial_height + 100: - print(self.conductor.spv_node.server.bp.height) + while self.conductor.spv_node.server.bp.height < initial_height + 99: # off by 1 await asyncio.sleep(0.1) - self.assertEqual(initial_height, self.ledger.headers.height) + self.assertEqual(initial_height, self.ledger.local_height_including_downloaded_height) # locks header processing so we make sure we are the only ones modifying it async with self.ledger._header_processing_lock: await self.ledger.headers.open() await self.ledger.network.start() await self.ledger.network.on_connected.first await self.ledger.initial_headers_sync() - self.assertEqual(initial_height + 100, self.ledger.headers.height) + self.assertEqual(initial_height + 99, self.ledger.local_height_including_downloaded_height) async def test_connection_drop_still_receives_events_after_reconnected(self): address1 = await self.account.receiving.get_or_create_usable_address() diff --git a/torba/torba/client/baseledger.py b/torba/torba/client/baseledger.py index 52e3b79ab..aff388473 100644 --- a/torba/torba/client/baseledger.py +++ b/torba/torba/client/baseledger.py @@ -138,6 +138,7 @@ class BaseLedger(metaclass=LedgerRegistry): self.get_id(), change, self.headers.height ) ) + self._download_height = 0 self._on_ready_controller = StreamController() self.on_ready = self._on_ready_controller.stream @@ -307,6 +308,10 @@ class BaseLedger(metaclass=LedgerRegistry): await self.db.close() await self.headers.close() + @property + def local_height_including_downloaded_height(self): + return max(self.headers.height, self._download_height) + async def initial_headers_sync(self): target = self.network.remote_height current = len(self.headers) @@ -321,8 +326,8 @@ class BaseLedger(metaclass=LedgerRegistry): len(self.headers), zlib.decompress(base64.b64decode(headers['base64']), wbits=-15, bufsize=600_000) ) - progress = connector.tell() // self.headers.header_size - log.info("Headers sync: %s / %s -- %s", progress, target, total) + self._download_height = len(self.headers) + connector.tell() // self.headers.header_size + log.info("Headers sync: %s / %s", self._download_height, target) async def update_headers(self, height=None, headers=None, subscription_update=False): rewound = 0