Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion chia-blockchain-gui
2 changes: 1 addition & 1 deletion chia/_tests/core/mempool/test_singleton_fast_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,4 +663,4 @@ async def test_double_spend_ff_spend_no_latest_unspent() -> None:
status, error = await make_and_send_spend_bundle(sim, sim_client, [singleton_coin_spend], aggsig=sig)
# It fails validation because it doesn't currently have a latest unspent
assert status == MempoolInclusionStatus.FAILED
assert error == Err.DOUBLE_SPEND
assert error == Err.UNKNOWN_UNSPENT
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 @@ -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 "
Expand Down
2 changes: 1 addition & 1 deletion chia/full_node/mempool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ async def validate_spend_bundle(
assert eligibility_info.ff_puzzle_hash is not None
lineage_info = await get_unspent_lineage_info_for_puzzle_hash(eligibility_info.ff_puzzle_hash)
if lineage_info is None:
return Err.DOUBLE_SPEND, None, []
mark_as_fast_forward = False
bundle_coin_spends[coin_id] = BundleCoinSpend(
coin_spend=coin_spend,
eligible_for_dedup=supports_dedup,
Expand Down
Loading