read history in one loop

This commit is contained in:
Jack Robison 2020-06-15 15:57:51 -04:00
parent fc9023386c
commit 6c28713a4c
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2

View file

@ -454,9 +454,20 @@ class LevelDB:
limit to None to get them all. limit to None to get them all.
""" """
def read_history(): def read_history():
tx_nums = list(self.history.get_txnums(hashX, limit)) hashx_history = []
fs_tx_hash = self.fs_tx_hash for key, hist in self.history.db.iterator(prefix=hashX):
return [fs_tx_hash(tx_num) for tx_num in tx_nums] a = array.array('I')
a.frombytes(hist)
for tx_num in a:
tx_height = bisect_right(self.tx_counts, tx_num)
if tx_height > self.db_height:
tx_hash = None
else:
tx_hash = self.hashes_db.get(TX_HASH_PREFIX + util.pack_be_uint64(tx_num))
hashx_history.append((tx_hash, tx_height))
if limit and len(hashx_history) >= limit:
return hashx_history
return hashx_history
while True: while True:
history = await asyncio.get_event_loop().run_in_executor(self.executor, read_history) history = await asyncio.get_event_loop().run_in_executor(self.executor, read_history)