diff --git a/lbry/wallet/account.py b/lbry/wallet/account.py index 06af360d38..c939d7ee91 100644 --- a/lbry/wallet/account.py +++ b/lbry/wallet/account.py @@ -39,9 +39,14 @@ def __init__(self, account: 'Account'): self.account = account self.last_known = 0 self.cache = {} - self.private_key: Optional[PrivateKey] = None - if account.private_key is not None: - self.private_key = account.private_key.child(KeyPath.CHANNEL) + self._private_key: Optional[PrivateKey] = None + + @property + def private_key(self): + if self._private_key is None: + if self.account.private_key is not None: + self._private_key = self.account.private_key.child(KeyPath.CHANNEL) + return self._private_key def maybe_generate_deterministic_key_for_channel(self, txo): if self.private_key is None: diff --git a/tests/integration/blockchain/test_wallet_commands.py b/tests/integration/blockchain/test_wallet_commands.py index ab11d930db..81c98865fb 100644 --- a/tests/integration/blockchain/test_wallet_commands.py +++ b/tests/integration/blockchain/test_wallet_commands.py @@ -365,6 +365,13 @@ async def test_encryption_with_imported_channel(self): self.assertEqual(daemon2.jsonrpc_wallet_status(), {'is_locked': False, 'is_encrypted': True, 'is_syncing': False}) + async def test_locking_unlocking_does_not_break_deterministic_channels(self): + self.assertTrue(self.daemon.jsonrpc_wallet_encrypt("password")) + self.assertTrue(self.daemon.jsonrpc_wallet_lock()) + self.account.deterministic_channel_keys._private_key = None + self.assertTrue(self.daemon.jsonrpc_wallet_unlock("password")) + await self.channel_create() + async def test_sync_with_encryption_and_password_change(self): daemon, daemon2 = self.daemon, self.daemon2 wallet, wallet2 = daemon.wallet_manager.default_wallet, daemon2.wallet_manager.default_wallet