fix iterator lower bound
This commit is contained in:
parent
5a4e8210f5
commit
6ccddb8670
6 changed files with 43 additions and 10 deletions
|
@ -143,6 +143,8 @@ class BlockchainReaderServer(BlockchainReader):
|
|||
|
||||
async def poll_for_changes(self):
|
||||
await super().poll_for_changes()
|
||||
if self.db.fs_height <= 0:
|
||||
return
|
||||
self.status_server.set_height(self.db.fs_height, self.db.db_tip)
|
||||
if self.notifications_to_send:
|
||||
for (touched, height) in self.notifications_to_send:
|
||||
|
|
|
@ -116,7 +116,7 @@ class PrefixDB:
|
|||
def iterator(self, start: bytes, column_family: 'rocksdb.ColumnFamilyHandle' = None,
|
||||
iterate_lower_bound: bytes = None, iterate_upper_bound: bytes = None,
|
||||
reverse: bool = False, include_key: bool = True, include_value: bool = True,
|
||||
fill_cache: bool = True, prefix_same_as_start: bool = True, auto_prefix_mode: bool = True):
|
||||
fill_cache: bool = True, prefix_same_as_start: bool = False, auto_prefix_mode: bool = False):
|
||||
return self._db.iterator(
|
||||
start=start, column_family=column_family, iterate_lower_bound=iterate_lower_bound,
|
||||
iterate_upper_bound=iterate_upper_bound, reverse=reverse, include_key=include_key,
|
||||
|
|
|
@ -77,10 +77,13 @@ class PrefixRow(metaclass=PrefixRowType):
|
|||
else:
|
||||
value_getter = lambda v: v
|
||||
|
||||
lower_bound = None if not (start or prefix) else (
|
||||
int.from_bytes(start or prefix, byteorder='big') - 1
|
||||
).to_bytes(len(start or prefix), byteorder='big')
|
||||
it = self._db.iterator(
|
||||
start or prefix, self._column_family, iterate_lower_bound=None,
|
||||
start or prefix, self._column_family, iterate_lower_bound=lower_bound,
|
||||
iterate_upper_bound=stop, reverse=reverse, include_key=include_key,
|
||||
include_value=include_value, fill_cache=fill_cache, prefix_same_as_start=True
|
||||
include_value=include_value, fill_cache=fill_cache, prefix_same_as_start=False
|
||||
)
|
||||
|
||||
if include_key and include_value:
|
||||
|
|
|
@ -166,7 +166,7 @@ class UDPServerFailDiscoveryTest(AsyncioTestCase):
|
|||
self.addCleanup(conductor.stop_lbcwallet)
|
||||
await conductor.start_spv()
|
||||
self.addCleanup(conductor.stop_spv)
|
||||
self.assertFalse(conductor.spv_node.server.reader.status_server.is_running)
|
||||
self.assertFalse(conductor.spv_node.server.status_server.is_running)
|
||||
await asyncio.wait_for(conductor.start_wallet(), timeout=5)
|
||||
self.addCleanup(conductor.stop_wallet)
|
||||
self.assertTrue(conductor.wallet_node.ledger.network.is_connected)
|
||||
|
|
|
@ -1352,14 +1352,15 @@ class ResolveClaimTakeovers(BaseResolveTestCase):
|
|||
await self.generate(8)
|
||||
await self.assertMatchClaimIsWinning(name, first_claim_id)
|
||||
# abandon the support that causes the winning claim to have the highest staked
|
||||
tx = await self.daemon.jsonrpc_txo_spend(type='support', txid=controlling_support_tx.id)
|
||||
tx = await self.daemon.jsonrpc_txo_spend(type='support', txid=controlling_support_tx.id, blocking=True)
|
||||
await self.generate(1)
|
||||
await self.assertMatchClaim(name, second_claim_id, is_active_in_lbrycrd=False)
|
||||
await self.assertMatchClaimIsWinning(name, first_claim_id)
|
||||
await self.assertNameState(538, name, first_claim_id, last_takeover_height=207, non_winning_claims=[
|
||||
ClaimStateValue(second_claim_id, activation_height=539, active_in_lbrycrd=False)
|
||||
])
|
||||
await self.generate(1)
|
||||
|
||||
await self.assertMatchClaim(name, first_claim_id)
|
||||
await self.assertMatchClaimIsWinning(name, second_claim_id)
|
||||
await self.assertNameState(539, name, second_claim_id, last_takeover_height=539, non_winning_claims=[
|
||||
ClaimStateValue(first_claim_id, activation_height=207, active_in_lbrycrd=True)
|
||||
])
|
||||
|
||||
async def test_remove_controlling_support(self):
|
||||
name = 'derp'
|
||||
|
|
|
@ -209,3 +209,30 @@ class TestRevertablePrefixDB(unittest.TestCase):
|
|||
((overflow_value, 1004, 0), (claim_hash3, name))
|
||||
], list(self.db.claim_expiration.iterate(prefix=(overflow_value,)))
|
||||
)
|
||||
|
||||
def test_hub_db_iterator_start_stop(self):
|
||||
tx_num = 101
|
||||
for x in range(255):
|
||||
claim_hash = 20 * chr(x).encode()
|
||||
self.db.active_amount.stage_put((claim_hash, 1, 200, tx_num, 1), (100000,))
|
||||
self.db.active_amount.stage_put((claim_hash, 1, 201, tx_num + 1, 1), (200000,))
|
||||
self.db.active_amount.stage_put((claim_hash, 1, 202, tx_num + 2, 1), (300000,))
|
||||
tx_num += 3
|
||||
self.db.unsafe_commit()
|
||||
|
||||
def get_active_amount_as_of_height(claim_hash: bytes, height: int) -> int:
|
||||
print(f"\t\tget_active_amount_as_of_height {claim_hash.hex()} @ {height}")
|
||||
for v in self.db.active_amount.iterate(
|
||||
start=(claim_hash, 1, 0), stop=(claim_hash, 1, height + 1),
|
||||
include_key=False, reverse=True):
|
||||
return v.amount
|
||||
return 0
|
||||
|
||||
for x in range(255):
|
||||
claim_hash = 20 * chr(x).encode()
|
||||
self.assertEqual(300000, get_active_amount_as_of_height(claim_hash, 300))
|
||||
self.assertEqual(300000, get_active_amount_as_of_height(claim_hash, 203))
|
||||
self.assertEqual(300000, get_active_amount_as_of_height(claim_hash, 202))
|
||||
self.assertEqual(200000, get_active_amount_as_of_height(claim_hash, 201))
|
||||
self.assertEqual(100000, get_active_amount_as_of_height(claim_hash, 200))
|
||||
self.assertEqual(0, get_active_amount_as_of_height(claim_hash, 199))
|
||||
|
|
Loading…
Reference in a new issue