Wallet: skip parent fetch in determine_coin_type for locally-known DL coins#20844
Draft
TheLastCicada wants to merge 2 commits into
Draft
Wallet: skip parent fetch in determine_coin_type for locally-known DL coins#20844TheLastCicada wants to merge 2 commits into
TheLastCicada wants to merge 2 commits into
Conversation
… coins Moves the post-determine_coin_type DataLayer override from _add_coin_states into determine_coin_type itself so DL mirror coins and previously-tracked singletons are classified without the request_puzzle_solution + parent get_coin_state round-trip. Helps the bulk-subscription case (e.g. CADT replaying tens of thousands of DL singleton coin states for a tracked launcher) on trusted-peer wallet sync. Removes the now-redundant post-call DL override block (same predicate, strictly later in the per-coin pipeline).
Coverage Report for CI Build 25130365079Coverage increased (+0.03%) to 91.241%Details
Uncovered ChangesNo uncovered changes found. Coverage Regressions13 previously-covered lines in 7 files lost coverage.
Coverage Stats💛 - Coveralls |
Replace monkeypatched async helper functions with AsyncMock and exercise the timestamp mock explicitly so Coveralls diff coverage includes the new test-only paths deterministically.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose:
Speed up wallet sync of DataLayer singletons (the CADT-style bulk-subscription case) by classifying tracked DL coins from local metadata before paying the parent
get_coin_state+request_puzzle_solutionround-trip inWalletStateManager.determine_coin_type.Current Behavior:
For DataLayer mirror coins and previously-tracked singletons,
WalletStateManager._add_coin_statesfalls through todetermine_coin_type, which fetches the parent coin state and the puzzle solution and runs CLVM uncurry. None of the CAT/NFT/DID/Clawback/VC patterns match for these coins; the function returns and a subsequent block in_add_coin_statesre-queriesdl_store(or compares againstMIRROR_PUZZLE_HASH) and re-classifies the coin to the DL wallet. The two RPCs and the CLVM uncurry are wasted work for every DL-classified coin, and the worst case (a heavily-used DL launcher being replayed against a freshly-tracking wallet) is ten of thousands of singleton coin states each paying that tax.New Behavior:
A new
WalletStateManager._data_layer_identifier_for_coinhelper performs the same predicate (puzzle_hash == MIRROR_PUZZLE_HASH or dl_store.get_singleton_record(coin.name()) is not None) using only local data.determine_coin_typecalls it after the existing pool / farmer reward early-return and returns the DLWalletIdentifierimmediately when it matches, skipping the parent fetch and the CLVM uncurry. The post-call DL override block in_add_coin_statesis removed because the helper covers the same predicate strictly earlier in the per-coin pipeline.Invariants unchanged:
coin_datafor DL-classified coins isNoneon this path, matching what the old post-call override produced.determine_coin_type.request_puzzle_solutionand parentget_coin_stateround-trip are still performed for all other classifications (CAT, NFT, DID, Clawback, VC, notifications).Testing Notes:
New unit tests in
chia/_tests/wallet/test_wallet_state_manager.pypin each branch of the helper:test_data_layer_identifier_for_coin_returns_none_without_dl_wallettest_data_layer_identifier_for_coin_mirror_puzzle_hashtest_data_layer_identifier_for_coin_tracked_singletontest_data_layer_identifier_for_coin_no_match_with_dl_walletNew integration test
test_add_coin_states_skips_parent_fetch_for_tracked_dl_singletondrives a tracked DL singleton through the production entry point (WalletStateManager.add_coin_states, the same one used byadd_states_from_peerin trusted mode atwallet_node.py:999) withWalletNode.get_coin_statemonkeypatched as a recorder. It asserts thatparent_fetch_calls == []and that the coin is owned by the DL wallet.Mutation-verified locally: temporarily disabling the short-circuit makes the integration test fail with
parent_fetch_calls != [], then re-enabling it restores the pass.Local validation pipeline (skipping benchmarks, will run in CI):
chia/_tests/wallet/test_wallet_state_manager.py(39 selected),chia/_tests/wallet/db_wallet/test_dl_wallet.py(mirror, lifecycle, reorg, ownership-rollback),chia/_tests/wallet/test_wallet_node.py(41 selected),chia/_tests/wallet/sync/test_wallet_sync.py(sync, long_sync, reorgs, dusted wallet) — 120+ tests passing.pre-commit run --all-files): clean.