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

improve code quality #3245

Merged
merged 7 commits into from
Apr 7, 2021
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
6 changes: 4 additions & 2 deletions lbry/extras/daemon/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lbry/stream/descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions lbry/wallet/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions lbry/wallet/rpc/jsonrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions lbry/wallet/server/block_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions lbry/wallet/server/db/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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')
Expand Down
4 changes: 1 addition & 3 deletions lbry/wallet/server/leveldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion lbry/wallet/server/mempool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion scripts/checktrie.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: <db_file_path> <lbrycrd_url>")
sys.exit(1)
db_path, lbrycrd_url = sys.argv[1:] # pylint: disable=W0632
Expand Down