From 6821c48d881547d4c97da9b766b77b68631efa85 Mon Sep 17 00:00:00 2001 From: Amine Khaldi Date: Thu, 7 Aug 2025 18:49:01 +0100 Subject: [PATCH] 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. --- chia/full_node/coin_store.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/chia/full_node/coin_store.py b/chia/full_node/coin_store.py index f2da3b66f644..f372be2756b1 100644 --- a/chia/full_node/coin_store.py +++ b/chia/full_node/coin_store.py @@ -30,6 +30,9 @@ class CoinStore: """ db_wrapper: DBWrapper2 + # Fall back to the `coin_puzzle_hash` index if the ff unspent index + # does not exist. + _unspent_lineage_for_ph_idx: str = "coin_puzzle_hash" @classmethod async def create(cls, db_wrapper: DBWrapper2) -> CoinStore: @@ -82,6 +85,12 @@ async def create(cls, db_wrapper: DBWrapper2) -> CoinStore: WHERE spent_index = -1 """ ) + async with conn.execute( + "SELECT 1 FROM sqlite_master WHERE type = 'index' AND name = 'coin_record_ph_ff_unspent_idx'" + ) as cursor: + has_ff_unspent_idx = await cursor.fetchone() is not None + if has_ff_unspent_idx: + self._unspent_lineage_for_ph_idx = "coin_record_ph_ff_unspent_idx" return self @@ -639,6 +648,7 @@ async def get_unspent_lineage_info_for_puzzle_hash(self, puzzle_hash: bytes32) - "unspent.coin_parent, " "parent.coin_parent " "FROM coin_record AS unspent " + f"INDEXED BY {self._unspent_lineage_for_ph_idx} " "LEFT JOIN coin_record AS parent ON unspent.coin_parent = parent.coin_name " "WHERE unspent.spent_index = -1 " "AND parent.spent_index > 0 "