diff --git a/lbry/db/database.py b/lbry/db/database.py index 821f95915..b12678388 100644 --- a/lbry/db/database.py +++ b/lbry/db/database.py @@ -197,7 +197,7 @@ class Database: return await self.run(q.has_claims) async def has_supports(self): - return await self.run(q.has_claims) + return await self.run(q.has_supports) async def get_best_block_height(self) -> int: return await self.run(q.get_best_block_height) diff --git a/lbry/db/queries/txio.py b/lbry/db/queries/txio.py index fb6572145..aba8320ef 100644 --- a/lbry/db/queries/txio.py +++ b/lbry/db/queries/txio.py @@ -134,8 +134,11 @@ def distribute_unspent_txos( total = 0 buckets = [] for bucket in context().fetchall(sql): - if len(buckets) > 0 and buckets[-1][-1] == bucket['start_height']: - bucket['start_height'] += 1 + if len(buckets) > 0: + if buckets[-1][-1] == bucket['start_height']: + if bucket['start_height'] == bucket['end_height']: + continue + bucket['start_height'] += 1 total += bucket['items'] buckets.append((bucket['start_height'], bucket['end_height'])) return total, buckets diff --git a/tests/integration/blockchain/test_blockchain.py b/tests/integration/blockchain/test_blockchain.py index 041f440b6..a78ac1d72 100644 --- a/tests/integration/blockchain/test_blockchain.py +++ b/tests/integration/blockchain/test_blockchain.py @@ -429,19 +429,18 @@ class TestMultiBlockFileSyncing(BasicBlockchainTestCase): self.assertEqual(279, (await db.get_blocks_in_file(1, 251))[28]['height']) # get_takeover_count - self.assertEqual(0, await db.get_takeover_count(0, 101)) - self.assertEqual(2, await db.get_takeover_count(101, 102)) - self.assertEqual(1, await db.get_takeover_count(103, 251)) - self.assertEqual(0, await db.get_takeover_count(252, 291)) + self.assertEqual(0, await db.get_takeover_count(0, 100)) + self.assertEqual(3610, await db.get_takeover_count(101, 102)) + self.assertEqual(0, await db.get_takeover_count(103, 1000)) # get_takeovers self.assertEqual( [ - {'height': 102, 'name': b'one'}, - {'height': 102, 'name': b'two'}, - {'height': 250, 'name': b''} # normalization on regtest kicks-in + {'height': 250, 'name': ''}, # normalization on regtest kicks-in + {'height': 102, 'name': 'one'}, + {'height': 102, 'name': 'two'}, ], - [{'name': takeover['name'], 'height': takeover['height']} + [{'name': takeover['normalized'], 'height': takeover['height']} for takeover in await db.get_takeovers(0, 291)] ) @@ -449,18 +448,6 @@ class TestMultiBlockFileSyncing(BasicBlockchainTestCase): self.assertEqual(3610, await db.get_claim_metadata_count(0, 500)) self.assertEqual(0, await db.get_claim_metadata_count(500, 1000)) - # get_claim_metadata - self.assertEqual( - [ - {'name': b'one', 'activation_height': 102, 'takeover_height': 102, 'is_controlling': True}, - {'name': b'two', 'activation_height': 102, 'takeover_height': 102, 'is_controlling': True}, - ], - [{ - 'name': r['name'], 'is_controlling': bool(r['is_controlling']), - 'activation_height': r['activation_height'], 'takeover_height': r['takeover_height'], - } for r in sorted(await db.get_claim_metadata(102, 102), key=lambda r: r['name']) if r['is_controlling']] - ) - # get_support_metadata_count self.assertEqual(2, await db.get_support_metadata_count(0, 500)) self.assertEqual(0, await db.get_support_metadata_count(500, 1000))