From 3a496902f8c64ef7593376321c781377eb9ce968 Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Mon, 24 Jan 2022 09:45:08 -0500 Subject: [PATCH] wallet locking/unlocking no longer breaks deterministic channel keys --- lbry/wallet/account.py | 11 ++++++++--- tests/integration/blockchain/test_wallet_commands.py | 7 +++++++ 2 files changed, 15 insertions(+), 3 deletions(-) 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