Skip to content

perf(perps): add coherent bootstrap snapshots - #9815

Open
abretonc7s wants to merge 4 commits into
mainfrom
perf/3662-perps-bootstrap-snapshots
Open

perf(perps): add coherent bootstrap snapshots#9815
abretonc7s wants to merge 4 commits into
mainfrom
perf/3662-perps-bootstrap-snapshots

Conversation

@abretonc7s

@abretonc7s abretonc7s commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Explanation

Perps cold start currently assembles market and account data through independent provider requests. That makes first content sensitive to request ordering, stale cache identity, and WebSocket readiness.

This PR adds two opt-in, client-neutral bootstrap paths:

  • A strict schema-v2 Terminal market snapshot consumer under terminalApi.globalSnapshotUrl. It validates provider/network/DEX identity, freshness, completeness, units, trends, and payload size, then falls back exactly once to HyperLiquid.
  • PerpsController.getUserDataSnapshot(), which returns positions, open orders, and account state as one address/network/HIP-3/DEX-scoped result while reusing each DEX clearinghouse response.

It also makes market/account preloading independent, guards cache writes across account/provider/network/HIP-3 lifecycle changes, persists exact cache identity, and reuses provider DEX discovery for subscriptions. The existing terminalApiUrl remains supported as a deprecated legacy market-data URL. No production Terminal snapshot endpoint is enabled by this package change; client configuration is a separate adoption step.

PerpsController now consumes the modern RemoteFeatureFlagController:stateChanged event and reads the initial flag state during init(), avoiding messenger action calls in the constructor.

Validation

  • Perps focused Jest: 5 suites, 286 tests passed before review corrections; final affected suites: 280/280 passed; final controller suite: 108/108 passed.
  • Remote Feature Flag suite: 73 tests passed, 4 snapshots.
  • Targeted ESLint: passed with no new suppressions.
  • @metamask/remote-feature-flag-controller forced TypeScript build: passed.
  • @metamask/perps-controller build: passed.
  • Public-client Core recipe, provider path: passed; 210 provider markets and coherent user snapshot.
  • Public-client Core recipe, fresh v2: passed; trusted Terminal source, trend present, coherent user snapshot.
  • Public-client Core recipe, stale v2: passed; stale snapshot rejected and provider fallback returned 210 markets.

References

  • TAT-3662
  • Related Mobile consumer and on-device performance validation will follow separately.

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR; the Mobile consumer update will be prepared separately before this leaves draft

Note

High Risk
Touches Perps account/market caching and cold-start data paths, plus a breaking messenger/init change for remote feature flags that consumers must adopt correctly.

Overview
Adds opt-in coherent bootstrap paths so Perps cold start no longer depends on independently ordered market and account requests.

Market data: Prefer a schema-v2 Terminal global snapshot (terminalApi.globalSnapshotUrl) with strict provider/network/DEX identity, freshness, completeness, unit, and payload checks, then fall back once to HyperLiquid. Legacy terminalApiUrl remains as a deprecated market-data URL.

Account data: Add getUserDataSnapshot() to fetch and atomically cache positions, open orders, and account state as one address/network/HIP-3/DEX-scoped result. Market and user preloading now run independently, with race guards that discard stale writes across account, provider, network, and HIP-3 changes.

BREAKING: Subscribe to RemoteFeatureFlagController:stateChanged and read initial remote flags in init() instead of the constructor. Cached account reads also fail closed unless the selected EVM address and current HyperLiquid identity match.

Reviewed by Cursor Bugbot for commit ebb9f4f. Bugbot is set up for automated code reviews on this repo. Configure here.

@abretonc7s abretonc7s self-assigned this Aug 11, 2026
@abretonc7s
abretonc7s force-pushed the perf/3662-perps-bootstrap-snapshots branch from 4355de0 to a73cce2 Compare August 11, 2026 03:37
@abretonc7s
abretonc7s marked this pull request as ready for review August 11, 2026 07:58
@abretonc7s
abretonc7s requested review from a team as code owners August 11, 2026 07:58
@abretonc7s
abretonc7s deployed to default-branch August 11, 2026 07:58 — with GitHub Actions Active

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3378749. Configure here.

Comment thread packages/perps-controller/src/services/TerminalMarketService.ts
@abretonc7s
abretonc7s force-pushed the perf/3662-perps-bootstrap-snapshots branch from 3378749 to 9a75d43 Compare August 11, 2026 08:33
@abretonc7s
abretonc7s enabled auto-merge August 12, 2026 02:04

@geositta geositta left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes. The identity, freshness, completeness, and lifecycle guards are implemented and tested, but requesting that the snapshot path remain time bounded through body consumption.

Comment thread packages/perps-controller/src/services/TerminalMarketService.ts Outdated
@abretonc7s
abretonc7s requested a review from geositta August 12, 2026 05:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants