Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions chia/full_node/coin_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -647,6 +656,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 "
Expand Down
Loading