From e45c6fe42c1037f571c2158c0fb119cc3e476ec2 Mon Sep 17 00:00:00 2001 From: hackrush Date: Mon, 20 May 2019 12:59:48 +0530 Subject: [PATCH] Only store pubkey-private key pairs --- lbrynet/extras/daemon/Daemon.py | 4 ++-- lbrynet/wallet/account.py | 14 ++------------ tests/integration/test_claim_commands.py | 2 -- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/lbrynet/extras/daemon/Daemon.py b/lbrynet/extras/daemon/Daemon.py index aacdeb80e..6949b4eaa 100644 --- a/lbrynet/extras/daemon/Daemon.py +++ b/lbrynet/extras/daemon/Daemon.py @@ -1903,7 +1903,7 @@ class Daemon(metaclass=JSONRPCServerType): channel_pubkey_hash = account.ledger.public_key_to_address( txo.claim.channel.public_key_bytes ) - account.add_channel_private_key(txo.claim_name, channel_pubkey_hash, txo.id, txo.private_key) + account.add_channel_private_key(txo.claim_name, channel_pubkey_hash, txo.private_key) self.default_wallet.save() await self.storage.save_claims([self._old_get_temp_claim_info( tx, txo, claim_address, claim, name, dewies_to_lbc(amount) @@ -2044,7 +2044,7 @@ class Daemon(metaclass=JSONRPCServerType): channel_pubkey_hash = account.ledger.public_key_to_address( new_txo.claim.channel.public_key_bytes ) - account.add_channel_private_key(new_txo.claim_name, channel_pubkey_hash, new_txo.id, new_txo.private_key) + account.add_channel_private_key(new_txo.claim_name, channel_pubkey_hash, new_txo.private_key) self.default_wallet.save() await self.storage.save_claims([self._old_get_temp_claim_info( tx, new_txo, claim_address, new_txo.claim, new_txo.claim_name, dewies_to_lbc(amount) diff --git a/lbrynet/wallet/account.py b/lbrynet/wallet/account.py index 886de453b..23b8babda 100644 --- a/lbrynet/wallet/account.py +++ b/lbrynet/wallet/account.py @@ -38,9 +38,7 @@ class Account(BaseAccount): super().apply(d) self.channel_keys.update(d.get('certificates', {})) - def add_channel_private_key(self, channel_name, channel_pubkey_hash, ref_id, private_key): - assert ref_id not in self.channel_keys, 'Trying to add a duplicate channel private key.' - self.channel_keys[ref_id] = private_key + def add_channel_private_key(self, channel_name, channel_pubkey_hash, private_key): if channel_pubkey_hash not in self.channel_keys: self.channel_keys[channel_pubkey_hash] = private_key else: @@ -53,10 +51,8 @@ class Account(BaseAccount): if not self.channel_keys: return - addresses = {} results = { 'total': 0, - 'old-tx-pri-key-map': 0, 'migrate-success': 0, 'migrate-failed': 0, 'previous-success': 0, @@ -68,7 +64,6 @@ class Account(BaseAccount): for maybe_outpoint in self.channel_keys: results['total'] += 1 if ':' in maybe_outpoint: - results['old-tx-pri-key-map'] += 1 try: private_key_pem = self.channel_keys[maybe_outpoint] pubkey_hash = self._get_pubkey_address_from_private_key_pem(private_key_pem) @@ -91,18 +86,13 @@ class Account(BaseAccount): log.warning("Corrupt public:private key-pair: %s", str(e)) results['previous-corrupted'] += 1 + self.channel_keys.clear() for key in new_channel_keys: self.channel_keys[key] = new_channel_keys[key] self.wallet.save() log.info('verifying and possibly migrating certificates:') log.info(json.dumps(results, indent=2)) - if addresses: - log.warning('failed for addresses:') - log.warning(json.dumps( - [{'address': a, 'number of certificates': c} for a, c in addresses.items()], - indent=2 - )) async def save_max_gap(self): if issubclass(self.address_generator, HierarchicalDeterministic): diff --git a/tests/integration/test_claim_commands.py b/tests/integration/test_claim_commands.py index 7f30dcdb0..ba77ba5b3 100644 --- a/tests/integration/test_claim_commands.py +++ b/tests/integration/test_claim_commands.py @@ -299,8 +299,6 @@ class ChannelCommands(CommandTestCase): self.assertIsNone(txo.private_key) # send the private key too - txoid = f"{tx['outputs'][0]['txid']}:{tx['outputs'][0]['nout']}" - account2.channel_keys[txoid] = self.account.channel_keys[txoid] channel_pubkey_address_hash = self.account.ledger.public_key_to_address(unhexlify(channel['public_key'])) account2.channel_keys[channel_pubkey_address_hash] = self.account.channel_keys[channel_pubkey_address_hash]