diff --git a/lbry/extras/daemon/components.py b/lbry/extras/daemon/components.py index 5271c1558..8a08be97a 100644 --- a/lbry/extras/daemon/components.py +++ b/lbry/extras/daemon/components.py @@ -146,6 +146,7 @@ class WalletComponent(Component): best_hash = await self.wallet_manager.get_best_blockhash() result.update({ 'headers_synchronization_progress': progress, + 'wallet_syncing': len(self.wallet_manager.ledger._update_tasks) > 0, 'blocks': max(local_height, 0), 'blocks_behind': max(remote_height - local_height, 0), 'best_blockhash': best_hash, diff --git a/lbry/wallet/ledger.py b/lbry/wallet/ledger.py index cfd89b6ee..6e9607b58 100644 --- a/lbry/wallet/ledger.py +++ b/lbry/wallet/ledger.py @@ -334,7 +334,7 @@ class Ledger(metaclass=LedgerRegistry): log.info("Subscribing and updating accounts.") async with self._header_processing_lock: await self._update_tasks.add(self.initial_headers_sync()) - await self.subscribe_accounts() + await self._update_tasks.add(self.subscribe_accounts()) await self._update_tasks.done.wait() self._on_ready_controller.add(True) diff --git a/lbry/wallet/tasks.py b/lbry/wallet/tasks.py index 05bf9af83..f57b55f5f 100644 --- a/lbry/wallet/tasks.py +++ b/lbry/wallet/tasks.py @@ -8,6 +8,9 @@ class TaskGroup: self._tasks = set() self.done = Event() + def __len__(self): + return len(self._tasks) + def add(self, coro): task = self._loop.create_task(coro) self._tasks.add(task) diff --git a/tests/integration/blockchain/test_wallet_commands.py b/tests/integration/blockchain/test_wallet_commands.py index c65fdfb10..6bb98c324 100644 --- a/tests/integration/blockchain/test_wallet_commands.py +++ b/tests/integration/blockchain/test_wallet_commands.py @@ -1,5 +1,6 @@ import asyncio import json +import os from lbry.wallet import ENCRYPT_ON_DISK from lbry.error import InvalidPasswordError @@ -19,6 +20,17 @@ class WalletCommands(CommandTestCase): await self.daemon.jsonrpc_wallet_add(wallet.id) self.assertEqual(len(session.hashX_subs), 28) + async def test_wallet_syncing_status(self): + address = await self.daemon.jsonrpc_address_unused() + sendtxid = await self.blockchain.send_to_address(address, 1) + + async def eventually_will_sync(): + while not (await self.daemon.jsonrpc_status())['wallet']['wallet_syncing']: + pass + check_sync = asyncio.create_task(eventually_will_sync()) + await self.confirm_tx(sendtxid, self.ledger) + await asyncio.wait_for(check_sync, timeout=10) + async def test_wallet_reconnect(self): await self.conductor.spv_node.stop(True) self.conductor.spv_node.port = 54320