From f0390786d6e3a520b3bc5cef6b86ed5f1bb8c802 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Sun, 17 Nov 2019 22:29:22 -0300 Subject: [PATCH] avoid trapping errors on client --- lbry/lbry/wallet/manager.py | 4 ++-- torba/tests/client_tests/integration/test_transactions.py | 2 -- torba/torba/client/baseledger.py | 8 ++------ torba/torba/client/basenetwork.py | 3 --- 4 files changed, 4 insertions(+), 13 deletions(-) diff --git a/lbry/lbry/wallet/manager.py b/lbry/lbry/wallet/manager.py index a076e4ca5..c936a2140 100644 --- a/lbry/lbry/wallet/manager.py +++ b/lbry/lbry/wallet/manager.py @@ -176,10 +176,10 @@ class LbryWalletManager(BaseWalletManager): if not tx: try: raw = await self.ledger.network.get_transaction(txid) - if not raw: - return {'success': False, 'code': 404, 'message': 'transaction not found'} height = await self.ledger.network.get_transaction_height(txid) except CodeMessageError as e: + if 'No such mempool or blockchain transaction.' in e.message: + return {'success': False, 'code': 404, 'message': 'transaction not found'} return {'success': False, 'code': e.code, 'message': e.message} tx = self.ledger.transaction_class(unhexlify(raw)) await self.ledger.maybe_verify_transaction(tx, height) diff --git a/torba/tests/client_tests/integration/test_transactions.py b/torba/tests/client_tests/integration/test_transactions.py index 54a44d937..00730ccca 100644 --- a/torba/tests/client_tests/integration/test_transactions.py +++ b/torba/tests/client_tests/integration/test_transactions.py @@ -175,5 +175,3 @@ class BasicTransactionTests(IntegrationTestCase): self.assertTrue(await self.ledger.update_history(address, remote_status)) self.assertEqual(21, len((await self.ledger.get_local_status_and_history(address))[1])) self.assertEqual(0, len(self.ledger._known_addresses_out_of_sync)) - # should be another test, but it would be too much to setup just for that and it affects sync - self.assertIsNone(await self.ledger.network.retriable_call(self.ledger.network.get_transaction, '1'*64)) diff --git a/torba/torba/client/baseledger.py b/torba/torba/client/baseledger.py index f19a35d58..922fb2021 100644 --- a/torba/torba/client/baseledger.py +++ b/torba/torba/client/baseledger.py @@ -550,12 +550,8 @@ class BaseLedger(metaclass=LedgerRegistry): if tx is None: # fetch from network _raw = await self.network.retriable_call(self.network.get_transaction, txid, remote_height) - if _raw: - tx = self.transaction_class(unhexlify(_raw)) - cache_item.tx = tx # make sure it's saved before caching it - - if tx is None: - raise ValueError(f'Transaction {txid} was not in database and not on network.') + tx = self.transaction_class(unhexlify(_raw)) + cache_item.tx = tx # make sure it's saved before caching it await self.maybe_verify_transaction(tx, remote_height) return tx diff --git a/torba/torba/client/basenetwork.py b/torba/torba/client/basenetwork.py index b2a5b6878..3d7e155e8 100644 --- a/torba/torba/client/basenetwork.py +++ b/torba/torba/client/basenetwork.py @@ -72,9 +72,6 @@ class ClientSession(BaseClientSession): log.debug("got reply for %s from %s:%i", method, *self.server) return reply except (RPCError, ProtocolError) as e: - if str(e).find('.*no such .*transaction.*'): - # shouldn't the server return none instead? - return None log.warning("Wallet server (%s:%i) returned an error. Code: %s Message: %s", *self.server, *e.args) raise e