From 637864114102b397e325d97e5b818c35d856fc5d Mon Sep 17 00:00:00 2001 From: shubhendra Date: Fri, 26 Mar 2021 18:45:37 +0530 Subject: [PATCH 1/7] Remove unnecessary comprehension Signed-off-by: shubhendra --- lbry/extras/daemon/components.py | 4 ++-- lbry/stream/descriptor.py | 4 ++-- lbry/wallet/ledger.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lbry/extras/daemon/components.py b/lbry/extras/daemon/components.py index fed656572f..674d9c53ed 100644 --- a/lbry/extras/daemon/components.py +++ b/lbry/extras/daemon/components.py @@ -539,8 +539,8 @@ async def start(self): success = False await self._maintain_redirects() if self.upnp: - if not self.upnp_redirects and not all([x in self.component_manager.skip_components for x in - (DHT_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT)]): + if not self.upnp_redirects and not all(x in self.component_manager.skip_components for x in + (DHT_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT)): log.error("failed to setup upnp") else: success = True diff --git a/lbry/stream/descriptor.py b/lbry/stream/descriptor.py index 2e2626b9be..fadabf29c1 100644 --- a/lbry/stream/descriptor.py +++ b/lbry/stream/descriptor.py @@ -183,11 +183,11 @@ def _from_stream_descriptor_blob(cls, loop: asyncio.AbstractEventLoop, blob_dir: raise InvalidStreamDescriptorError("Does not decode as valid JSON") if decoded['blobs'][-1]['length'] != 0: raise InvalidStreamDescriptorError("Does not end with a zero-length blob.") - if any([blob_info['length'] == 0 for blob_info in decoded['blobs'][:-1]]): + if any(blob_info['length'] == 0 for blob_info in decoded['blobs'][:-1]): raise InvalidStreamDescriptorError("Contains zero-length data blob") if 'blob_hash' in decoded['blobs'][-1]: raise InvalidStreamDescriptorError("Stream terminator blob should not have a hash") - if any([i != blob_info['blob_num'] for i, blob_info in enumerate(decoded['blobs'])]): + if any(i != blob_info['blob_num'] for i, blob_info in enumerate(decoded['blobs'])): raise InvalidStreamDescriptorError("Stream contains out of order or skipped blobs") descriptor = cls( loop, blob_dir, diff --git a/lbry/wallet/ledger.py b/lbry/wallet/ledger.py index 04ed2808c5..ab10e72012 100644 --- a/lbry/wallet/ledger.py +++ b/lbry/wallet/ledger.py @@ -1060,7 +1060,7 @@ async def get_transaction_history(self, read_only=False, **constraints): 'abandon_info': [], 'purchase_info': [] } - is_my_inputs = all([txi.is_my_input for txi in tx.inputs]) + is_my_inputs = all(txi.is_my_input for txi in tx.inputs) if is_my_inputs: # fees only matter if we are the ones paying them item['value'] = dewies_to_lbc(tx.net_account_balance + tx.fee) From 6da87d36bb31c86bba5c312878aae42f9366a250 Mon Sep 17 00:00:00 2001 From: shubhendra Date: Fri, 26 Mar 2021 18:45:38 +0530 Subject: [PATCH 2/7] Remove unnecessary use of comprehension Signed-off-by: shubhendra --- lbry/wallet/server/block_processor.py | 3 +-- lbry/wallet/server/leveldb.py | 4 +--- lbry/wallet/server/mempool.py | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lbry/wallet/server/block_processor.py b/lbry/wallet/server/block_processor.py index 8558afe5ce..4391736d0d 100644 --- a/lbry/wallet/server/block_processor.py +++ b/lbry/wallet/server/block_processor.py @@ -605,8 +605,7 @@ def spend_utxo(self, tx_hash, tx_idx): # Key: b'h' + compressed_tx_hash + tx_idx + tx_num # Value: hashX prefix = b'h' + tx_hash[:4] + idx_packed - candidates = {db_key: hashX for db_key, hashX - in self.db.utxo_db.iterator(prefix=prefix)} + candidates = dict(self.db.utxo_db.iterator(prefix=prefix)) for hdb_key, hashX in candidates.items(): tx_num_packed = hdb_key[-4:] if len(candidates) > 1: diff --git a/lbry/wallet/server/leveldb.py b/lbry/wallet/server/leveldb.py index 7c023ee2ec..5498706bde 100644 --- a/lbry/wallet/server/leveldb.py +++ b/lbry/wallet/server/leveldb.py @@ -137,9 +137,7 @@ async def _read_headers(self): return def get_headers(): - return [ - header for header in self.headers_db.iterator(prefix=HEADER_PREFIX, include_key=False) - ] + return list(self.headers_db.iterator(prefix=HEADER_PREFIX, include_key=False)) headers = await asyncio.get_event_loop().run_in_executor(self.executor, get_headers) assert len(headers) - 1 == self.db_height, f"{len(headers)} vs {self.db_height}" diff --git a/lbry/wallet/server/mempool.py b/lbry/wallet/server/mempool.py index ce08f74467..276fcf66cf 100644 --- a/lbry/wallet/server/mempool.py +++ b/lbry/wallet/server/mempool.py @@ -324,7 +324,7 @@ async def _fetch_and_accept(self, hashes, all_hashes, touched): for prevout in tx.prevouts if prevout[0] not in all_hashes) utxos = await self.api.lookup_utxos(prevouts) - utxo_map = {prevout: utxo for prevout, utxo in zip(prevouts, utxos)} + utxo_map = dict(zip(prevouts, utxos)) return self._accept_transactions(tx_map, utxo_map, touched) From 1bb23d1c02a618ac3b6687955360ef158780a469 Mon Sep 17 00:00:00 2001 From: shubhendra Date: Fri, 26 Mar 2021 18:45:39 +0530 Subject: [PATCH 3/7] Remove methods with unnecessary super delegation. Signed-off-by: shubhendra --- lbry/wallet/rpc/jsonrpc.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/lbry/wallet/rpc/jsonrpc.py b/lbry/wallet/rpc/jsonrpc.py index 61de3f3661..ca20c459b2 100644 --- a/lbry/wallet/rpc/jsonrpc.py +++ b/lbry/wallet/rpc/jsonrpc.py @@ -108,9 +108,6 @@ def __init__(self, result): class CodeMessageError(Exception): - def __init__(self, code, message): - super().__init__(code, message) - @property def code(self): return self.args[0] From 3fcb32280bb874ddcdd9423a219562e639bf7a5b Mon Sep 17 00:00:00 2001 From: shubhendra Date: Fri, 26 Mar 2021 18:45:40 +0530 Subject: [PATCH 4/7] Iterate dictionary directly Signed-off-by: shubhendra --- lbry/wallet/server/db/writer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lbry/wallet/server/db/writer.py b/lbry/wallet/server/db/writer.py index f7d30fd859..8c739a0e83 100644 --- a/lbry/wallet/server/db/writer.py +++ b/lbry/wallet/server/db/writer.py @@ -714,7 +714,7 @@ def validate_channel_signatures(self, height, new_claims, updated_claims, spent_ claim_in_channel.channel_hash=claim.claim_hash ) WHERE claim_hash = ? - """, [(channel_hash,) for channel_hash in all_channel_keys.keys()]) + """, [(channel_hash,) for channel_hash in all_channel_keys]) sub_timer.stop() sub_timer = timer.add_timer('update blocked claims list') From f42795d2549b863e71668c9cbccac4ab180fc3f8 Mon Sep 17 00:00:00 2001 From: shubhendra Date: Fri, 26 Mar 2021 18:45:41 +0530 Subject: [PATCH 5/7] Refactor the comparison involving `not` Signed-off-by: shubhendra --- scripts/checktrie.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/checktrie.py b/scripts/checktrie.py index 4431f524c8..4fa4743c0e 100644 --- a/scripts/checktrie.py +++ b/scripts/checktrie.py @@ -64,7 +64,7 @@ async def checkcontrolling(daemon: Daemon, db: SQLDB): if __name__ == '__main__': - if not len(sys.argv) == 3: + if len(sys.argv) != 3: print("usage: ") sys.exit(1) db_path, lbrycrd_url = sys.argv[1:] # pylint: disable=W0632 From 9f4b7159ca2652448696dfc5a9107e80d790d6ca Mon Sep 17 00:00:00 2001 From: shubhendra Date: Fri, 26 Mar 2021 18:45:41 +0530 Subject: [PATCH 6/7] Remove unnecessary generator Signed-off-by: shubhendra --- lbry/wallet/ledger.py | 2 +- lbry/wallet/server/db/writer.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lbry/wallet/ledger.py b/lbry/wallet/ledger.py index ab10e72012..244a7eace6 100644 --- a/lbry/wallet/ledger.py +++ b/lbry/wallet/ledger.py @@ -538,7 +538,7 @@ async def update_history(self, address, remote_status, address_manager: AddressM "request %i transactions, %i/%i for %s are already synced", len(to_request), len(already_synced), len(remote_history), address ) - remote_history_txids = set(txid for txid, _ in remote_history) + remote_history_txids = {txid for txid, _ in remote_history} async for tx in self.request_synced_transactions(to_request, remote_history_txids, address): pending_synced_history[tx_indexes[tx.id]] = f"{tx.id}:{tx.height}:" if len(pending_synced_history) % 100 == 0: diff --git a/lbry/wallet/server/db/writer.py b/lbry/wallet/server/db/writer.py index 8c739a0e83..aa8faae70a 100644 --- a/lbry/wallet/server/db/writer.py +++ b/lbry/wallet/server/db/writer.py @@ -547,7 +547,7 @@ def calculate_reposts(self, txos: List[Output]): WHERE claim_hash = ? """, targets ) - return set(target[0] for target in targets) + return {target[0] for target in targets} def validate_channel_signatures(self, height, new_claims, updated_claims, spent_claims, affected_channels, timer): if not new_claims and not updated_claims and not spent_claims: From 2006ac2163e6c4acdb7a0b5de029965dce47e08c Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Tue, 6 Apr 2021 20:48:10 -0400 Subject: [PATCH 7/7] lint --- lbry/extras/daemon/components.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lbry/extras/daemon/components.py b/lbry/extras/daemon/components.py index 674d9c53ed..37a4955462 100644 --- a/lbry/extras/daemon/components.py +++ b/lbry/extras/daemon/components.py @@ -539,8 +539,10 @@ async def start(self): success = False await self._maintain_redirects() if self.upnp: - if not self.upnp_redirects and not all(x in self.component_manager.skip_components for x in - (DHT_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT)): + if not self.upnp_redirects and not all( + x in self.component_manager.skip_components + for x in (DHT_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT) + ): log.error("failed to setup upnp") else: success = True