From 6eeabb1a1a4b2d56a416f8682420bcd15255a2f7 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Wed, 27 Oct 2021 20:19:08 -0400 Subject: [PATCH] use mempool cache in transaction_get_batch --- lbry/wallet/server/db/elasticsearch/sync.py | 2 +- lbry/wallet/server/mempool.py | 3 ++- lbry/wallet/server/session.py | 11 ++++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lbry/wallet/server/db/elasticsearch/sync.py b/lbry/wallet/server/db/elasticsearch/sync.py index 79331102d..74c0865e6 100644 --- a/lbry/wallet/server/db/elasticsearch/sync.py +++ b/lbry/wallet/server/db/elasticsearch/sync.py @@ -56,7 +56,7 @@ async def get_recent_claims(env, index_name='claims', db=None): db.prefix_db.unsafe_commit() db.assert_db_state() - logging.info("finished sending %i claims to ES, deleted %i", cnt, len(touched_claims), len(deleted_claims)) + logging.info("finished sending %i claims to ES, deleted %i", cnt, len(deleted_claims)) finally: if need_open: db.close() diff --git a/lbry/wallet/server/mempool.py b/lbry/wallet/server/mempool.py index 146378233..27d7a2352 100644 --- a/lbry/wallet/server/mempool.py +++ b/lbry/wallet/server/mempool.py @@ -29,6 +29,7 @@ class MemPoolTx: out_pairs = attr.ib() fee = attr.ib() size = attr.ib() + raw_tx = attr.ib() @attr.s(slots=True) @@ -230,7 +231,7 @@ class MemPool: txout_pairs = tuple((to_hashX(txout.pk_script), txout.value) for txout in tx.outputs) tx_map[hash] = MemPoolTx(txin_pairs, None, txout_pairs, - 0, tx_size) + 0, tx_size, raw_tx) # Determine all prevouts not in the mempool, and fetch the # UTXO information from the database. Failed prevout lookups diff --git a/lbry/wallet/server/session.py b/lbry/wallet/server/session.py index 2d564cf29..da78a7661 100644 --- a/lbry/wallet/server/session.py +++ b/lbry/wallet/server/session.py @@ -1461,9 +1461,14 @@ class LBRYElectrumX(SessionBase): for tx_hash in tx_hashes: if tx_hash in batch_result and batch_result[tx_hash][0]: continue - tx_info = await self.daemon_request('getrawtransaction', tx_hash, True) - raw_tx = tx_info['hex'] - block_hash = tx_info.get('blockhash') + tx_hash_bytes = bytes.fromhex(tx_hash)[::-1] + mempool_tx = self.mempool.txs.get(tx_hash_bytes, None) + if mempool_tx: + raw_tx, block_hash = mempool_tx.raw_tx.hex(), None + else: + tx_info = await self.daemon_request('getrawtransaction', tx_hash, True) + raw_tx = tx_info['hex'] + block_hash = tx_info.get('blockhash') if block_hash: block = await self.daemon.deserialised_block(block_hash) height = block['height']