diff --git a/torba/baseledger.py b/torba/baseledger.py index a19347518..692610668 100644 --- a/torba/baseledger.py +++ b/torba/baseledger.py @@ -223,8 +223,13 @@ class BaseLedger(metaclass=LedgerRegistry): self.headers.open() ]) first_connection = self.network.on_connected.first + self.network.on_connected.listen(self.join_network) self.network.start() yield first_connection + + @defer.inlineCallbacks + def join_network(self, *args): + log.info("Subscribing and updating accounts.") yield self.update_headers() yield self.network.subscribe_headers() yield self.update_accounts() diff --git a/torba/basenetwork.py b/torba/basenetwork.py index dc1397a64..eec68577d 100644 --- a/torba/basenetwork.py +++ b/torba/basenetwork.py @@ -167,6 +167,8 @@ class BaseNetwork: log.exception("Connecting to %s raised an exception:", connection_string) finally: self.client = None + if self.service is not None: + self.service.stopService() if not self.running: return