fix block_txs iterator stop condition

This commit is contained in:
Jack Robison 2020-12-01 17:00:19 -05:00
parent 68a97b0e61
commit c03b1b5a93
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
2 changed files with 3 additions and 2 deletions

View file

@ -280,6 +280,7 @@ def tx_merkle(tx_num, tx_height):
return ctx.merkle_tx_cache[(tx_num, tx_height)]
if tx_height not in ctx.block_txs_cache:
block_txs = list(db.iterator(
prefix=TX_HASH_PREFIX,
start=TX_HASH_PREFIX + util.pack_be_uint64(tx_counts[tx_height - 1]),
stop=None if tx_height + 1 == len(tx_counts) else
TX_HASH_PREFIX + util.pack_be_uint64(tx_counts[tx_height]), include_key=False
@ -288,6 +289,7 @@ def tx_merkle(tx_num, tx_height):
ctx.block_txs_cache[tx_height] = block_txs
else:
block_txs = ctx.block_txs_cache.get(tx_height, uncached)
branch, root = ctx.merkle.branch_and_root(block_txs, tx_pos)
merkle = {
'block_height': tx_height,

View file

@ -153,12 +153,11 @@ class RocksDBIterator:
]
def __init__(self, db, prefix=None, start=None, stop=None, include_key=True, include_value=True, reverse=False):
assert (start is None and stop is None) or (prefix is None), 'cannot use start/stop and prefix'
self.start = start
self.prefix = prefix
self.stop = stop
self.iterator = db.iteritems() if not reverse else reversed(db.iteritems())
if prefix is not None:
if prefix is not None and start is None:
self.iterator.seek(prefix)
elif start is not None:
self.iterator.seek(start)