Skip to content

Commit bec867e

Browse files
authored
checkpoint: into main from release/2.5.5 @ 6821c48 (#19993)
Source hash: 6821c48 Remaining commits: 1
2 parents eceecdd + 94b8bdf commit bec867e

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

@@ -647,6 +656,7 @@ async def get_unspent_lineage_info_for_puzzle_hash(self, puzzle_hash: bytes32) -
647656
"unspent.coin_parent, "
648657
"parent.coin_parent "
649658
"FROM coin_record AS unspent "
659+
f"INDEXED BY {self._unspent_lineage_for_ph_idx} "
650660
"LEFT JOIN coin_record AS parent ON unspent.coin_parent = parent.coin_name "
651661
"WHERE unspent.spent_index = -1 "
652662
"AND parent.spent_index > 0 "

0 commit comments

Comments
 (0)