feat(ensindexer): leverage SWR caches to achieve goals related to LocalPonderClient#1652
feat(ensindexer): leverage SWR caches to achieve goals related to LocalPonderClient#1652tk-o wants to merge 15 commits intofeat/indexing-status-builder-3from
LocalPonderClient#1652Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 3 Skipped Deployments
|
🦋 Changeset detectedLatest commit: f3ab127 The changes in this PR will be included in the next version bump. This PR includes changesets to release 19 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Pull request overview
This PR refactors ENSIndexer’s LocalPonderClient initialization to rely on SWR caches (with proactive revalidation) and extends the shared SWRCache utility to support a context object for cache loaders.
Changes:
- Extend
SWRCacheto accept an optionalcontextparameter infn()and add asetContext()API. - Refactor
LocalPonderClientto use new SWR-backed caches for Ponder indexing metrics/status (dynamic) and derived immutable chain metadata. - Update the Ponder API handler to use a singleton
LocalPonderClientinstance (no per-request initialization).
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/ensnode-sdk/src/shared/cache/swr-cache.ts | Adds context support and proactive revalidation stop API to the shared SWR cache implementation. |
| packages/ensnode-sdk/src/shared/cache/swr-cache.test.ts | Updates tests for the new (cachedResult, context) callback signature and adds context coverage. |
| apps/ensindexer/src/lib/ponder-api-client.ts | Switches singleton getter to synchronous construction and injects SWR caches into LocalPonderClient. |
| apps/ensindexer/ponder/src/api/lib/local-ponder-client.ts | Reworks LocalPonderClient to extend PonderClient and source metadata via SWR caches. |
| apps/ensindexer/ponder/src/api/lib/chains-indexing-metadata-immutable.ts | Introduces builder for immutable chain indexing metadata. |
| apps/ensindexer/ponder/src/api/lib/chains-indexing-metadata-dynamic.ts | Introduces builder for dynamic chain indexing metadata from metrics/status. |
| apps/ensindexer/ponder/src/api/lib/cache/ponder-client.cache.ts | Adds SWR cache for Ponder metrics/status with proactive revalidation. |
| apps/ensindexer/ponder/src/api/lib/cache/chains-indexing-metadata-immutable.cache.ts | Adds SWR cache for immutable chain metadata and stops revalidation after success. |
| apps/ensindexer/ponder/src/api/handlers/ensnode-api.ts | Uses a module-level singleton LocalPonderClient for request handling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
apps/ensindexer/ponder/src/api/lib/chains-indexing-metadata-dynamic.ts
Outdated
Show resolved
Hide resolved
apps/ensindexer/ponder/src/api/lib/chains-indexing-metadata-immutable.ts
Outdated
Show resolved
Hide resolved
apps/ensindexer/ponder/src/api/lib/cache/ponder-client.cache.ts
Outdated
Show resolved
Hide resolved
apps/ensindexer/ponder/src/api/lib/cache/chains-indexing-metadata-immutable.cache.ts
Outdated
Show resolved
Hide resolved
tk-o
left a comment
There was a problem hiding this comment.
Self-review completed.
apps/ensindexer/ponder/src/api/lib/cache/ponder-indexing-metrics.cache.ts
Outdated
Show resolved
Hide resolved
apps/ensindexer/ponder/src/api/lib/cache/ponder-indexing-status.cache.ts
Outdated
Show resolved
Hide resolved
apps/ensindexer/ponder/src/api/lib/cache/chains-indexing-metadata-immutable.cache.ts
Outdated
Show resolved
Hide resolved
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
34db972 to
b8b2f19
Compare
0999394 to
d314b5d
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
apps/ensindexer/ponder/src/api/lib/chains-indexing-metadata-immutable.ts
Show resolved
Hide resolved
apps/ensindexer/ponder/src/api/lib/cache/chains-indexing-metadata-immutable.cache.ts
Outdated
Show resolved
Hide resolved
apps/ensindexer/ponder/src/api/lib/cache/chains-indexing-metadata-immutable.cache.ts
Outdated
Show resolved
Hide resolved
Move logic from `LocalPonderClient` into a separate file.
Move logic from `LocalPonderClient` into a separate file.
9f9ca10 to
dc578eb
Compare
Replace `buildChainsIndexingMetadataImmutable` calls with `ChainsIndexingMetadataImmutableCache` reads while fetching `ChainsIndexingMetadataImmutable` data.
`LocalPonderClient` extends `PonderClient` now. This change allows setting up proper cache context for `this.#chainsIndexingMetadataImmutableCache`. Also, `LocalPonderClient` does not require any async initialization. The reremote data required by `LocalPonderClient` is now managed by two SWR cache instances: 1) `PonderClientCache`, and 2) `ChainsIndexingMetadataImmutableCache`. Ponder configuration and APIs are made avaialble via `LocalPonderClient` fields: `chainsConfigBlockrange`, `indexedChainIds`, `publicClients`; and methods: `getPublicClient`, `chainsIndexingMetadata`, plus all methods provided by `PonderClient` implementation.
Now, that async data fetching has been delegated to SWR caches, creating a singleton instnace for `LocalPonderClient` is way simpler, _and synchronous_!
Declares a top-level `localPonderClient` var that references the singleton `LocalPonderClient` instance. It is important to initialize singleton this way, as it also initializes SWR caches to perform data fetching in the background.
… with Ponder app configuration and data.
…into feat/indexing-status-builder-3-with-cache
1) `SWRCache` implementation has been reset to the current `main` branch version. 2) Caching `ChainsIndexingMetadataImmutable` value, which includes relevant block refs, has been moved from SWRCache implementation into the `chainsIndexingMetadataImmutable` field on `LocalPonderClient` class. The SWRCache for `ChainsIndexingMetadataImmutable` has been removed. 3) The `chainsIndexingMetadata()` method was replaced by more straightforward `getOmnichainIndexingStatusSnapshot` method, which can be called with no arguments from a caller's side. 4) SWRCache for `PonderClient`, called `PonderClientCache`, creates `PonderClient` instance directly now, so no cache context object is needed. 5) `PonderClientCache` is now initiated lazily. Its revalidation interval is set to 10 seconds. This gives time for Ponder app to load data needed for Ponder Client. 6) `LocalPonderClient` imports `PonderClientCache` directly, so there is no need to inject it with constructor params. 7) The Indexing Status API endpoint can now just call `omnichainSnapshot = await localPonderClient.getOmnichainIndexingStatusSnapshot();` to get the complete, fresh value for current omnichain indexing status snapshot.
44957b4 to
7559fb8
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
apps/ensindexer/ponder/src/api/lib/chains-indexing-metadata-immutable.ts
Outdated
Show resolved
Hide resolved
apps/ensindexer/ponder/src/api/lib/chains-indexing-metadata-dynamic.ts
Outdated
Show resolved
Hide resolved
|
@greptile review |
|
@greptile review |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| throw new Error( | ||
| `Ponder Indexing Metrics must be available in cache to build chains indexing metadata immutable: ${ponderClientCacheResult.message}`, | ||
| ); |
There was a problem hiding this comment.
The error message mentions only "Ponder Indexing Metrics" but the cache result actually contains both indexing metrics and indexing status. Consider updating the message to be more accurate, for example: "Ponder Client data (metrics and status) must be available in cache..."
Lite PR
Tip: Review docs on the ENSNode PR process
Summary
PonderClientLocalPonderClientto read data from aforementioned SWR cache to simplify how possible data loading failures are handled. Also,LocalPonderClientmaintains in-memory cache forChainsIndexingMetadataImmutableobject which includes relevant block refs for each indexed chain.getLocalPonderClient()function that returns aLocalPonderClientsingleton instance. Now, there's no need to await anything.Why
LocalPonderClientshould leverage it.Testing
/api/indexing-statusendpoint, including test logsNotes for Reviewer (Optional)
LocalPonderClientidea in a meaningful way.LocalPonderClient"knows" about Ponder APIs and configs, and allows caching data that can be later used to handle Indexing Status API requests.Pre-Review Checklist (Blocking)