diff --git a/lbry/wallet/server/chain_reader.py b/lbry/wallet/server/chain_reader.py index 27f30e9d6..15cdffe0e 100644 --- a/lbry/wallet/server/chain_reader.py +++ b/lbry/wallet/server/chain_reader.py @@ -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: diff --git a/lbry/wallet/server/db/interface.py b/lbry/wallet/server/db/interface.py index 41899e392..1452b16ca 100644 --- a/lbry/wallet/server/db/interface.py +++ b/lbry/wallet/server/db/interface.py @@ -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, diff --git a/lbry/wallet/server/db/prefixes.py b/lbry/wallet/server/db/prefixes.py index 82758f56f..f555e83dd 100644 --- a/lbry/wallet/server/db/prefixes.py +++ b/lbry/wallet/server/db/prefixes.py @@ -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: diff --git a/tests/integration/blockchain/test_network.py b/tests/integration/blockchain/test_network.py index 32f169394..879693d4c 100644 --- a/tests/integration/blockchain/test_network.py +++ b/tests/integration/blockchain/test_network.py @@ -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) diff --git a/tests/integration/takeovers/test_resolve_command.py b/tests/integration/takeovers/test_resolve_command.py index 78072722b..4270249e6 100644 --- a/tests/integration/takeovers/test_resolve_command.py +++ b/tests/integration/takeovers/test_resolve_command.py @@ -1353,14 +1353,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' diff --git a/tests/unit/wallet/server/test_revertable.py b/tests/unit/wallet/server/test_revertable.py index db9e1d0e9..2c9e04f26 100644 --- a/tests/unit/wallet/server/test_revertable.py +++ b/tests/unit/wallet/server/test_revertable.py @@ -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))