Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eagerly load deterministic channel keys immediately after wallet is unlocked #3581

Merged
merged 2 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lbry/wallet/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,12 @@ def is_locked(self) -> bool:
return True
return False

def unlock(self, password):
async def unlock(self, password):
for account in self.accounts:
if account.encrypted:
if not account.decrypt(password):
return False
await account.deterministic_channel_keys.ensure_cache_primed()
self.encryption_password = password
return True

Expand Down
14 changes: 7 additions & 7 deletions tests/integration/blockchain/test_wallet_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ async def test_encryption_and_locking(self):
with self.assertRaisesRegex(AssertionError, "Cannot lock an unencrypted wallet, encrypt first."):
daemon.jsonrpc_wallet_lock()
# safe to call unlock and decrypt, they are no-ops at this point
daemon.jsonrpc_wallet_unlock('password') # already unlocked
await daemon.jsonrpc_wallet_unlock('password') # already unlocked
daemon.jsonrpc_wallet_decrypt() # already not encrypted

daemon.jsonrpc_wallet_encrypt('password')
Expand All @@ -343,7 +343,7 @@ async def test_encryption_and_locking(self):
# can't sign transactions with locked wallet
with self.assertRaises(AssertionError):
await daemon.jsonrpc_channel_create('@foo', '1.0')
daemon.jsonrpc_wallet_unlock('password')
await daemon.jsonrpc_wallet_unlock('password')
self.assertEqual(daemon.jsonrpc_wallet_status(), {'is_locked': False, 'is_encrypted': True,
'is_syncing': False})
await daemon.jsonrpc_channel_create('@foo', '1.0')
Expand All @@ -361,15 +361,15 @@ async def test_encryption_with_imported_channel(self):
await daemon2.jsonrpc_channel_import(exported)
self.assertTrue(daemon2.jsonrpc_wallet_encrypt('password'))
self.assertTrue(daemon2.jsonrpc_wallet_lock())
self.assertTrue(daemon2.jsonrpc_wallet_unlock("password"))
self.assertTrue(await daemon2.jsonrpc_wallet_unlock("password"))
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"))
self.assertTrue(await self.daemon.jsonrpc_wallet_unlock("password"))
await self.channel_create()

async def test_sync_with_encryption_and_password_change(self):
Expand Down Expand Up @@ -398,8 +398,8 @@ async def test_sync_with_encryption_and_password_change(self):

# check new password is active
daemon.jsonrpc_wallet_lock()
self.assertFalse(daemon.jsonrpc_wallet_unlock('password'))
self.assertTrue(daemon.jsonrpc_wallet_unlock('password2'))
self.assertFalse(await daemon.jsonrpc_wallet_unlock('password'))
self.assertTrue(await daemon.jsonrpc_wallet_unlock('password2'))

# propagate disk encryption to daemon2
data = await daemon.jsonrpc_sync_apply('password3')
Expand All @@ -415,4 +415,4 @@ async def test_sync_with_encryption_and_password_change(self):
self.assertWalletEncrypted(wallet2.storage.path, True)

daemon2.jsonrpc_wallet_lock()
self.assertTrue(daemon2.jsonrpc_wallet_unlock('password3'))
self.assertTrue(await daemon2.jsonrpc_wallet_unlock('password3'))