From 6e93c5bc0d026dfdaa988f782afec7ffc97ac61e Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Thu, 16 Sep 2021 17:54:59 -0400 Subject: [PATCH] fix update that initiates takeover not being delayed --- lbry/wallet/server/block_processor.py | 10 +- .../blockchain/test_resolve_command.py | 93 ++++++++++++++++--- 2 files changed, 89 insertions(+), 14 deletions(-) diff --git a/lbry/wallet/server/block_processor.py b/lbry/wallet/server/block_processor.py index e72716408..5c74c9996 100644 --- a/lbry/wallet/server/block_processor.py +++ b/lbry/wallet/server/block_processor.py @@ -712,9 +712,13 @@ class BlockProcessor: if (claim_hash, txo_type, height) in self.amount_cache: return self.amount_cache[(claim_hash, txo_type, height)] if txo_type == ACTIVATED_CLAIM_TXO_TYPE: - self.amount_cache[(claim_hash, txo_type, height)] = amount = self.db.get_active_amount_as_of_height( - claim_hash, height - ) + if claim_hash in self.claim_hash_to_txo: + amount = self.txo_to_claim[self.claim_hash_to_txo[claim_hash]].amount + else: + amount = self.db.get_active_amount_as_of_height( + claim_hash, height + ) + self.amount_cache[(claim_hash, txo_type, height)] = amount else: self.amount_cache[(claim_hash, txo_type, height)] = amount = self.db._get_active_amount( claim_hash, txo_type, height diff --git a/tests/integration/blockchain/test_resolve_command.py b/tests/integration/blockchain/test_resolve_command.py index 637dec6cd..f850fcb99 100644 --- a/tests/integration/blockchain/test_resolve_command.py +++ b/tests/integration/blockchain/test_resolve_command.py @@ -64,24 +64,37 @@ class BaseResolveTestCase(CommandTestCase): self.assertEqual(expected['effectiveAmount'], claim.effective_amount) return claim - async def assertMatchClaim(self, claim_id): + async def assertMatchClaim(self, claim_id, is_active_in_lbrycrd=True): expected = json.loads(await self.blockchain._cli_cmnd('getclaimbyid', claim_id)) claim = await self.conductor.spv_node.server.bp.db.fs_getclaimbyid(claim_id) - if not expected: - self.assertIsNone(claim) - return + if is_active_in_lbrycrd: + if not expected: + self.assertIsNone(claim) + return + self.assertEqual(expected['claimId'], claim.claim_hash.hex()) + self.assertEqual(expected['validAtHeight'], claim.activation_height) + self.assertEqual(expected['lastTakeoverHeight'], claim.last_takeover_height) + self.assertEqual(expected['txId'], claim.tx_hash[::-1].hex()) + self.assertEqual(expected['n'], claim.position) + self.assertEqual(expected['amount'], claim.amount) + self.assertEqual(expected['effectiveAmount'], claim.effective_amount) + else: + self.assertDictEqual({}, expected) + claim_from_es = await self.conductor.spv_node.server.bp.db.search_index.search( claim_id=claim.claim_hash.hex() ) self.assertEqual(len(claim_from_es[0]), 1) self.assertEqual(claim_from_es[0][0]['claim_hash'][::-1].hex(), claim.claim_hash.hex()) - self.assertEqual(expected['claimId'], claim.claim_hash.hex()) - self.assertEqual(expected['validAtHeight'], claim.activation_height) - self.assertEqual(expected['lastTakeoverHeight'], claim.last_takeover_height) - self.assertEqual(expected['txId'], claim.tx_hash[::-1].hex()) - self.assertEqual(expected['n'], claim.position) - self.assertEqual(expected['amount'], claim.amount) - self.assertEqual(expected['effectiveAmount'], claim.effective_amount) + + + self.assertEqual(claim_from_es[0][0]['claim_id'], claim.claim_hash.hex()) + self.assertEqual(claim_from_es[0][0]['activation_height'], claim.activation_height) + self.assertEqual(claim_from_es[0][0]['last_take_over_height'], claim.last_takeover_height) + self.assertEqual(claim_from_es[0][0]['tx_id'], claim.tx_hash[::-1].hex()) + self.assertEqual(claim_from_es[0][0]['tx_nout'], claim.position) + self.assertEqual(claim_from_es[0][0]['amount'], claim.amount) + self.assertEqual(claim_from_es[0][0]['effective_amount'], claim.effective_amount) return claim async def assertMatchClaimIsWinning(self, name, claim_id): @@ -594,6 +607,64 @@ class ResolveClaimTakeovers(BaseResolveTestCase): await self.assertNoClaimForName(name) await self._test_activation_delay() + async def test_claim_and_update_delays(self): + name = 'derp' + first_claim_id = (await self.stream_create(name, '0.2', allow_duplicate_name=True))['outputs'][0]['claim_id'] + await self.assertMatchClaimIsWinning(name, first_claim_id) + await self.generate(320) + second_claim_id = (await self.stream_create(name, '0.1', allow_duplicate_name=True))['outputs'][0]['claim_id'] + third_claim_id = (await self.stream_create(name, '0.1', allow_duplicate_name=True))['outputs'][0]['claim_id'] + + await self.generate(8) + + self.assertEqual(537, self.conductor.spv_node.server.bp.db.db_height) + await self.assertMatchClaimIsWinning(name, first_claim_id) + second_claim = await self.assertMatchClaim(second_claim_id, is_active_in_lbrycrd=False) + self.assertEqual(538, second_claim.activation_height) + self.assertEqual(207, second_claim.last_takeover_height) + third_claim = await self.assertMatchClaim(third_claim_id, is_active_in_lbrycrd=False) + self.assertEqual(539, third_claim.activation_height) + self.assertEqual(207, third_claim.last_takeover_height) + + await self.generate(1) + + self.assertEqual(538, self.conductor.spv_node.server.bp.db.db_height) + await self.assertMatchClaimIsWinning(name, first_claim_id) + second_claim = await self.assertMatchClaim(second_claim_id) + self.assertEqual(538, second_claim.activation_height) + self.assertEqual(207, second_claim.last_takeover_height) + third_claim = await self.assertMatchClaim(third_claim_id, is_active_in_lbrycrd=False) + self.assertEqual(539, third_claim.activation_height) + self.assertEqual(207, third_claim.last_takeover_height) + + await self.generate(1) + + self.assertEqual(539, self.conductor.spv_node.server.bp.db.db_height) + await self.assertMatchClaimIsWinning(name, first_claim_id) + second_claim = await self.assertMatchClaim(second_claim_id) + self.assertEqual(538, second_claim.activation_height) + self.assertEqual(207, second_claim.last_takeover_height) + third_claim = await self.assertMatchClaim(third_claim_id) + self.assertEqual(539, third_claim.activation_height) + self.assertEqual(207, third_claim.last_takeover_height) + + await self.daemon.jsonrpc_stream_update(third_claim_id, '0.21') + await self.generate(1) + + self.assertEqual(540, self.conductor.spv_node.server.bp.db.db_height) + + await self.assertMatchClaimIsWinning(name, first_claim_id) + second_claim = await self.assertMatchClaim(second_claim_id) + self.assertEqual(538, second_claim.activation_height) + self.assertEqual(207, second_claim.last_takeover_height) + third_claim = await self.assertMatchClaim(third_claim_id, is_active_in_lbrycrd=False) + self.assertEqual(550, third_claim.activation_height) + self.assertEqual(207, third_claim.last_takeover_height) + + await self.generate(10) + self.assertEqual(550, self.conductor.spv_node.server.bp.db.db_height) + await self.assertMatchClaimIsWinning(name, third_claim_id) + async def test_resolve_signed_claims_with_fees(self): channel_name = '@abc' channel_id = self.get_claim_id(