Deserialize mempool txs in a thread
This commit is contained in:
parent
9bd9476a54
commit
4b3ceff0d2
@ -175,22 +175,27 @@ class MemPool(object):
|
|||||||
'''Process the dictionary of raw transactions and return a dictionary
|
'''Process the dictionary of raw transactions and return a dictionary
|
||||||
of updates to apply to self.txs.
|
of updates to apply to self.txs.
|
||||||
'''
|
'''
|
||||||
script_hashX = self.coin.hashX_from_script
|
def deserialize_txs():
|
||||||
deserializer = self.coin.DESERIALIZER
|
script_hashX = self.coin.hashX_from_script
|
||||||
|
deserializer = self.coin.DESERIALIZER
|
||||||
|
|
||||||
# Deserialize each tx and put it in a pending list
|
# Deserialize each tx and put it in a pending list
|
||||||
for tx_hash, raw_tx in raw_tx_map.items():
|
for tx_hash, raw_tx in raw_tx_map.items():
|
||||||
tx, tx_size = deserializer(raw_tx).read_tx_and_vsize()
|
tx, tx_size = deserializer(raw_tx).read_tx_and_vsize()
|
||||||
|
|
||||||
# Convert the tx outputs into (hashX, value) pairs
|
# Convert the tx outputs into (hashX, value) pairs
|
||||||
txout_pairs = [(script_hashX(txout.pk_script), txout.value)
|
txout_pairs = [(script_hashX(txout.pk_script), txout.value)
|
||||||
for txout in tx.outputs]
|
for txout in tx.outputs]
|
||||||
|
|
||||||
# Convert the tx inputs to ([prev_hex_hash, prev_idx) pairs
|
# Convert the tx inputs to ([prev_hex_hash, prev_idx) pairs
|
||||||
txin_pairs = [(hash_to_hex_str(txin.prev_hash), txin.prev_idx)
|
txin_pairs = [(hash_to_hex_str(txin.prev_hash), txin.prev_idx)
|
||||||
for txin in tx.inputs]
|
for txin in tx.inputs]
|
||||||
|
|
||||||
pending.append((tx_hash, txin_pairs, txout_pairs, tx_size))
|
pending.append((tx_hash, txin_pairs, txout_pairs, tx_size))
|
||||||
|
|
||||||
|
# Do this potentially slow operation in a thread so as not to
|
||||||
|
# block
|
||||||
|
await self.tasks.run_in_thread(deserialize_txs)
|
||||||
|
|
||||||
# The transaction inputs can be from other mempool
|
# The transaction inputs can be from other mempool
|
||||||
# transactions (which may or may not be processed yet) or are
|
# transactions (which may or may not be processed yet) or are
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user