Skip to content

Include hinted removals in CoinStateUpdate #18611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
13 changes: 11 additions & 2 deletions chia/full_node/full_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class PeakPostProcessingResult:
mempool_peak_result: List[NewPeakItem] # The new items from calling MempoolManager.new_peak
mempool_removals: List[MempoolRemoveInfo] # The removed mempool items from calling MempoolManager.new_peak
fns_peak_result: FullNodeStorePeakResult # The result of calling FullNodeStore.new_peak
hints: List[Tuple[bytes32, bytes]] # The hints added to the DB
hints: List[Tuple[bytes32, bytes]] # The hints for coins affected by the peak
lookup_coin_ids: List[bytes32] # The coin IDs that we need to look up to notify wallets of changes


Expand Down Expand Up @@ -1604,10 +1604,19 @@ async def peak_post_processing(
f"{len(block.transactions_generator_ref_list) if block.transactions_generator else 'No tx'}"
)

removal_hints = dict()

for coin_id, _ in state_change_summary.removals:
hints = await self.hint_store.get_hints([coin_id])
if len(hints) != 1:
continue
removal_hints[coin_id] = hints[0]

hints_to_add, lookup_coin_ids = get_hints_and_subscription_coin_ids(
state_change_summary,
self.subscriptions.has_coin_subscription,
self.subscriptions.has_puzzle_subscription,
removal_hints,
)
await self.hint_store.add_hints(hints_to_add)

Expand Down Expand Up @@ -1672,7 +1681,7 @@ async def peak_post_processing(
mempool_new_peak_result.items,
mempool_new_peak_result.removals,
fns_peak_result,
hints_to_add,
hints_to_add + [(coin_id, hint) for coin_id, hint in removal_hints.items()],
lookup_coin_ids,
)

Expand Down
8 changes: 7 additions & 1 deletion chia/full_node/hint_management.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Callable, List, Optional, Set, Tuple
from typing import Callable, Dict, List, Optional, Set, Tuple

from chia.consensus.blockchain import StateChangeSummary
from chia.types.blockchain_format.sized_bytes import bytes32
Expand All @@ -10,7 +10,11 @@ def get_hints_and_subscription_coin_ids(
state_change_summary: StateChangeSummary,
has_coin_subscription: Callable[[bytes32], bool],
has_puzzle_subscription: Callable[[bytes32], bool],
removal_hints: Optional[Dict[bytes32, bytes32]] = None,
) -> Tuple[List[Tuple[bytes32, bytes]], List[bytes32]]:
if removal_hints is None:
removal_hints = dict()

# Precondition: all hints passed in are max 32 bytes long
# Returns the hints that we need to add to the DB, and the coin ids that need to be looked up

Expand All @@ -33,6 +37,8 @@ def add_if_ph_subscription(puzzle_hash: bytes32, coin_id: bytes32) -> None:
# Record all coin_ids that we are interested in, that had changes
add_if_coin_subscription(spend_id)
add_if_ph_subscription(puzzle_hash, spend_id)
if spend_id in removal_hints:
add_if_ph_subscription(removal_hints[spend_id], spend_id)

for addition_coin, hint in state_change_summary.additions:
addition_coin_name = addition_coin.name()
Expand Down
Loading