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 performance of address subscriptions and transaction proofs #3221

Merged
merged 2 commits into from
Mar 10, 2021
Merged
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
10 changes: 4 additions & 6 deletions lbry/wallet/server/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1275,10 +1275,9 @@ async def address_subscribe(self, *addresses):
address: the address to subscribe to"""
if len(addresses) > 1000:
raise RPCError(BAD_REQUEST, f'too many addresses in subscription request: {len(addresses)}')
hashXes = [
(self.address_to_hashX(address), address) for address in addresses
return [
await self.hashX_subscribe(self.address_to_hashX(address), address) for address in addresses
]
return [await self.hashX_subscribe(*args) for args in hashXes]

async def address_unsubscribe(self, address):
"""Unsubscribe an address.
Expand Down Expand Up @@ -1553,15 +1552,14 @@ async def transaction_get_batch(self, *tx_hashes):
else:
batch_result[tx_hash] = [raw_tx, {'block_height': -1}]

def threaded_get_merkle():
if needed_merkles:
for tx_hash, (raw_tx, block_txs, pos, block_height) in needed_merkles.items():
batch_result[tx_hash] = raw_tx, {
'merkle': self._get_merkle_branch(block_txs, pos),
'pos': pos,
'block_height': block_height
}
if needed_merkles:
await asyncio.get_running_loop().run_in_executor(self.db.executor, threaded_get_merkle)
await asyncio.sleep(0) # heavy call, give other tasks a chance

self.session_mgr.tx_replied_count_metric.inc(len(tx_hashes))
return batch_result
Expand Down