Skip to content

Commit 6821c48

Browse files
authored
CHIA-3595 Be explicit about falling back to coin_puzzle_hash index in get_unspent_lineage_info_for_puzzle_hash (#19909)
Be explicit about falling back to coin_puzzle_hash index in get_unspent_lineage_info_for_puzzle_hash.
1 parent b1cc0a5 commit 6821c48

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

chia/full_node/coin_store.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class CoinStore:
3030
"""
3131

3232
db_wrapper: DBWrapper2
33+
# Fall back to the `coin_puzzle_hash` index if the ff unspent index
34+
# does not exist.
35+
_unspent_lineage_for_ph_idx: str = "coin_puzzle_hash"
3336

3437
@classmethod
3538
async def create(cls, db_wrapper: DBWrapper2) -> CoinStore:
@@ -82,6 +85,12 @@ async def create(cls, db_wrapper: DBWrapper2) -> CoinStore:
8285
WHERE spent_index = -1
8386
"""
8487
)
88+
async with conn.execute(
89+
"SELECT 1 FROM sqlite_master WHERE type = 'index' AND name = 'coin_record_ph_ff_unspent_idx'"
90+
) as cursor:
91+
has_ff_unspent_idx = await cursor.fetchone() is not None
92+
if has_ff_unspent_idx:
93+
self._unspent_lineage_for_ph_idx = "coin_record_ph_ff_unspent_idx"
8594

8695
return self
8796

@@ -639,6 +648,7 @@ async def get_unspent_lineage_info_for_puzzle_hash(self, puzzle_hash: bytes32) -
639648
"unspent.coin_parent, "
640649
"parent.coin_parent "
641650
"FROM coin_record AS unspent "
651+
f"INDEXED BY {self._unspent_lineage_for_ph_idx} "
642652
"LEFT JOIN coin_record AS parent ON unspent.coin_parent = parent.coin_name "
643653
"WHERE unspent.spent_index = -1 "
644654
"AND parent.spent_index > 0 "

0 commit comments

Comments
 (0)