feat: dedupe and epoch-fence address/balance fetches against wallet changes - #87
Merged
Merged
Conversation
Contributor
Author
Contributor
|
#77 is merged. |
jonathunne
reviewed
Aug 18, 2026
nulllpc
force-pushed
the
npc/address-balance-request-coordinator-v2
branch
from
August 18, 2026 11:54
80b4904 to
5f360f1
Compare
4 tasks
changes - Add RequestCoordinator + a single global worklet epoch: dedupes concurrent fetches by cache key, and discards a result if the worklet's loaded wallet changed (switch/lock/delete) while the fetch was in flight - Wire the epoch bump into WorkletLifecycleService.reset() - the one choke point every wallet-changing flow already routes through, so no other lifecycle code needs to change - Fix AddressService: the loading flag could get stuck at `true` forever when a stale result was discarded, permanently blocking useAddressLoader from ever retrying that network/account - Fix BalanceService: updateBalance/updateLastBalanceUpdate now receive the wallet captured at fetch kickoff instead of re-resolving activeWalletId at write time, which could attribute a balance to the wrong wallet after a switch - Unify fetchBalance onto the same per-network fetch/commit path as fetchBalances so they dedupe against each other instead of risking a cache-key collision
nulllpc
force-pushed
the
npc/address-balance-request-coordinator-v2
branch
from
August 18, 2026 12:58
5f360f1 to
f3a2f18
Compare
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.
Build on top of #79 and #77
This PR inherits the idea of request deduplication from PR 79 but build on top of PR 77 with much more consideration and design so we can leverage the deduplication as a common feature for all services, not just address. This was built on top of PR 77 because that PR contained significant improvements to the lifecycle of wallet which the deduplication plays along nicely
Summary
Adds request de-duplication and staleness-fencing for address and balance fetches, so a fetch still in flight when the wallet is deleted, locked, or switched can't write stale (or wrong-wallet) data into the store once it resolves.
Credit for the idea goes to @ashaltykou-innowise
Why
The WDK worklet holds exactly one loaded wallet at a time and has no concept of
walletId- every RPC call is answered by whichever seed is currently loaded. That means:updateBalanceresolved the active wallet at write time rather than at fetch kickoff.What changed
RequestCoordinator(src/utils/requestCoordinator.ts): dedupes concurrent fetches by key, and only commits a result if a single global worklet epoch (src/utils/workletEpoch.ts) hasn't changed since the fetch started. The epoch is bumped from exactly one place -WorkletLifecycleService.reset()- which every wallet-changing flow (delete, lock, switch) already routes through on this branch, so it covers all three for free.AddressService/BalanceService: rebuilt on top of the coordinator. Also fixes two real bugs found along the way:walletLoadingflag that could permanently block retries once a result was discarded as stalefetchBalancenow shares the same per-network fetch/commit path asfetchBalances, so they dedupe against each other instead of risking a key collision.