Merge pull request #2896 from lbryio/first_on_ready

fix for startup issues when connecting to wallet servers
This commit is contained in:
Lex Berezhny 2020-03-30 17:41:14 -04:00 committed by GitHub
commit 6494754ab9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 15 deletions

View file

@ -316,11 +316,12 @@ class Ledger(metaclass=LedgerRegistry):
self.db.open(), self.db.open(),
self.headers.open() self.headers.open()
]) ])
first_connection = self.network.on_connected.first fully_synced = self.on_ready.first
asyncio.ensure_future(self.network.start()) asyncio.create_task(self.network.start())
await first_connection await self.network.on_connected.first
async with self._header_processing_lock: async with self._header_processing_lock:
await self._update_tasks.add(self.initial_headers_sync()) await self._update_tasks.add(self.initial_headers_sync())
await fully_synced
await asyncio.gather(*(a.maybe_migrate_certificates() for a in self.accounts)) await asyncio.gather(*(a.maybe_migrate_certificates() for a in self.accounts))
await asyncio.gather(*(a.save_max_gap() for a in self.accounts)) await asyncio.gather(*(a.save_max_gap() for a in self.accounts))
if len(self.accounts) > 10: if len(self.accounts) > 10:
@ -328,12 +329,9 @@ class Ledger(metaclass=LedgerRegistry):
else: else:
await self._report_state() await self._report_state()
self.on_transaction.listen(self._reset_balance_cache) self.on_transaction.listen(self._reset_balance_cache)
await self.on_ready.first
async def join_network(self, *_): async def join_network(self, *_):
log.info("Subscribing and updating accounts.") log.info("Subscribing and updating accounts.")
async with self._header_processing_lock:
await self._update_tasks.add(self.initial_headers_sync())
await self._update_tasks.add(self.subscribe_accounts()) await self._update_tasks.add(self.subscribe_accounts())
await self._update_tasks.done.wait() await self._update_tasks.done.wait()
self._on_ready_controller.add(True) self._on_ready_controller.add(True)

View file

@ -1,4 +1,3 @@
import logging
import asyncio import asyncio
import lbry import lbry

View file

@ -45,14 +45,6 @@ class TestSessions(IntegrationTestCase):
await self.ledger.network.broadcast('13370042004200') await self.ledger.network.broadcast('13370042004200')
class TestSegwitServer(IntegrationTestCase):
LEDGER = lbry.wallet
ENABLE_SEGWIT = True
async def test_at_least_it_starts(self):
await asyncio.wait_for(self.ledger.network.get_headers(0, 1), 1.0)
class TestUsagePayment(CommandTestCase): class TestUsagePayment(CommandTestCase):
async def test_single_server_payment(self): async def test_single_server_payment(self):
wallet_pay_service = self.daemon.component_manager.get_component('wallet_server_payments') wallet_pay_service = self.daemon.component_manager.get_component('wallet_server_payments')