get merkles outside thread cooperatively

This commit is contained in:
Victor Shyba 2021-03-10 13:05:17 -03:00
parent 9ae30ac08e
commit ae337807f5

View file

@ -1552,15 +1552,14 @@ class LBRYElectrumX(SessionBase):
else: else:
batch_result[tx_hash] = [raw_tx, {'block_height': -1}] 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(): for tx_hash, (raw_tx, block_txs, pos, block_height) in needed_merkles.items():
batch_result[tx_hash] = raw_tx, { batch_result[tx_hash] = raw_tx, {
'merkle': self._get_merkle_branch(block_txs, pos), 'merkle': self._get_merkle_branch(block_txs, pos),
'pos': pos, 'pos': pos,
'block_height': block_height 'block_height': block_height
} }
if needed_merkles: await asyncio.sleep(0) # heavy call, give other tasks a chance
await asyncio.get_running_loop().run_in_executor(self.db.executor, threaded_get_merkle)
self.session_mgr.tx_replied_count_metric.inc(len(tx_hashes)) self.session_mgr.tx_replied_count_metric.inc(len(tx_hashes))
return batch_result return batch_result