-
Notifications
You must be signed in to change notification settings - Fork 17
Introduce indexing metadata context data model #1997
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
4b125d0
Introduce `IndexingMetadataContext` data model to ENSNode SDK
tk-o dcad533
Create `init*` functions for running event handlers preconditions
tk-o a5a8bd6
Execute `migrateEnsNodeSchema` from inside of `initIndexingSetup` fun…
tk-o c57c2ac
Use `EnsIndexerStackInfo` for `stackInfo` field in `IndexingMetadataC…
tk-o a28b0de
Add `getIndexingMetadataContext` method to `EnsDbReader` class
tk-o e91bd13
Add `upsertIndexingMetadataContext` method to `EnsDbWriter` class
tk-o 8892dd5
Update `EnsDbWriterWorker` class to serve a new limited role
tk-o ee1190e
Fix ponder build issue
tk-o 4954e21
Fix typos
tk-o 2f8532e
Implement full tasks sequence for `initIndexingOnchainEvents`
tk-o 361e99d
Merge `initIndexingSetup` function into `initIndexingOnchainEvents`
tk-o 7595a41
Update unit tests
tk-o 1902bfb
Use `getIndexingMetadataContext` for all ENSNode Metadata reads from …
tk-o 6bda3d6
Merge remote-tracking branch 'origin/main' into feat/indexing-metadat…
tk-o e3ddda0
Simplify `EnsDbReader` class and `EnsDbWriter` class
tk-o 4684fb4
Fix tests
tk-o 1ff960e
Apply AI PR feedback
tk-o 41060d0
Simplify `initIndexingOnchainEvents` logic
tk-o e1d6d04
Update unit tests
tk-o 98e6c45
Simplify `initIndexingOnchainEvents` function
tk-o eebe386
Simplify logic in ENSIndexer HTTP endpoints
tk-o 11711ca
Improve naming
tk-o 89c974a
Make indexing status cache and stack info cache for ENSApi to use the…
tk-o 292ed35
Merge remote-tracking branch 'origin/main' into feat/indexing-metadat…
tk-o 159c4ff
Improve code docs
tk-o b36418b
Create a mock file for config.schema.ts
tk-o f3355ef
Integrate ENSDb health check and readiness check into `initIndexingOn…
tk-o 40961af
Update code docs
tk-o 6279dea
Apply AI PR feedback
tk-o 43ef45b
Merge remote-tracking branch 'origin/main' into feat/indexing-metadat…
tk-o ad1564f
Apply AI PR feedback
tk-o 110927d
Add changeset
tk-o bcd81fe
Merge remote-tracking branch 'origin/main' into feat/indexing-metadat…
tk-o 698191f
Apply AI PR feedback
tk-o 725901f
Fix re-exports
tk-o 55ae265
Merge remote-tracking branch 'origin/main' into feat/indexing-metadat…
tk-o 84b52e1
Create ENSRainbow readiness logic inline in ENSIndexer
tk-o 5cc44ea
Fix typo
tk-o File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
29 changes: 29 additions & 0 deletions
29
apps/ensindexer/src/lib/indexing-engines/init-indexing-onchain-events.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { waitForEnsRainbowToBeReady } from "@/lib/ensrainbow/singleton"; | ||
|
|
||
| /** | ||
| * Prepare for executing the "onchain" event handlers. | ||
| * | ||
| * During Ponder startup, the "onchain" event handlers are executed | ||
| * after all "setup" event handlers have completed. | ||
| * | ||
| * This function is useful to make sure any long-running preconditions for | ||
| * onchain event handlers are met, for example, waiting for | ||
| * the ENSRainbow instance to be ready before processing any onchain events | ||
| * that require data from ENSRainbow. | ||
| * | ||
| * @example A single blocking precondition | ||
| * ```ts | ||
| * await waitForEnsRainbowToBeReady(); | ||
| * ``` | ||
| * | ||
| * @example Multiple blocking preconditions | ||
| * ```ts | ||
| * await Promise.all([ | ||
| * waitForEnsRainbowToBeReady(), | ||
| * waitForAnotherPrecondition(), | ||
| * ]); | ||
| * ``` | ||
| */ | ||
| export async function initIndexingOnchainEvents(): Promise<void> { | ||
| await waitForEnsRainbowToBeReady(); | ||
| } |
53 changes: 53 additions & 0 deletions
53
apps/ensindexer/src/lib/indexing-engines/init-indexing-setup.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /** | ||
| * This module defines the initialization logic for the setup handlers of | ||
| * the Ponder indexing engine executed in an ENSIndexer instance. | ||
| * | ||
| * Setup handlers are executed by Ponder once per ENSIndexer instance lifetime, | ||
| * at the start of the omnichain indexing process. | ||
| * | ||
| * ENSIndexer startup sequence executed by Ponder: | ||
| * 1. Connect to the database and initialize required database objects. | ||
| * 2. Start the omnichain indexing process. | ||
| * 3. Check whether Ponder Checkpoints are already initialized. | ||
| * 4. If not: | ||
| * a) Execute setup handlers. | ||
| * b) Initialize Ponder Checkpoints. | ||
| * 5. a) Make Ponder HTTP API usable. | ||
| * 5. b) Start executing "onchain" event handlers. | ||
| * | ||
| * Step 4 is skipped on ENSIndexer instance restart if Ponder Checkpoints were | ||
| * already initialized in a previous run. | ||
| */ | ||
|
|
||
| import { logger } from "@/lib/logger"; | ||
|
|
||
| /** | ||
| * Initialize indexing setup | ||
| * | ||
| * Runs once per ENSIndexer instance lifetime to initialize indexing setup. | ||
| * | ||
| * Since multiple ENSIndexer instances may run concurrently against the same | ||
| * ENSDb instance, this function MUST BE idempotent and race-condition-safe. | ||
| * | ||
| * Completion of this function unblocks the following sequence of events | ||
| * during ENSIndexer startup: | ||
| * 1. "setup" event handlers execute | ||
| * 2. Ponder Checkpoints initialize | ||
| * 3. IndexingStatusBuilder can build OmnichainIndexingStatusSnapshot | ||
| * via LocalPonderClient (which queries the Ponder HTTP API) | ||
| * | ||
| * @throws Error if any precondition is not satisfied. | ||
| */ | ||
| export async function initIndexingSetup(): Promise<void> { | ||
| const { migrateEnsNodeSchema } = await import("@/lib/ensdb/migrate-ensnode-schema"); | ||
|
tk-o marked this conversation as resolved.
Outdated
|
||
| // Ensure the ENSNode Schema in ENSDb is up to date by running any pending migrations. | ||
| await migrateEnsNodeSchema().catch((error) => { | ||
| logger.error({ | ||
| msg: "Failed to initialize ENSNode metadata", | ||
| error, | ||
| module: "ponder-api", | ||
|
tk-o marked this conversation as resolved.
Outdated
vercel[bot] marked this conversation as resolved.
Outdated
tk-o marked this conversation as resolved.
Outdated
|
||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| process.exitCode = 1; | ||
| throw error; | ||
| }); | ||
| } | ||
|
tk-o marked this conversation as resolved.
Outdated
|
||
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
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
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
74 changes: 74 additions & 0 deletions
74
packages/ensnode-sdk/src/ensnode/metadata/deserialize/indexing-metadata-context.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { prettifyError } from "zod/v4"; | ||
|
|
||
| import { buildUnvalidatedCrossChainIndexingStatusSnapshot } from "../../../indexing-status"; | ||
| import type { Unvalidated } from "../../../shared/types"; | ||
| import { buildUnvalidatedEnsNodeStackInfo } from "../../../stack-info"; | ||
| import { | ||
| type IndexingMetadataContext, | ||
| type IndexingMetadataContextInitialized, | ||
| IndexingMetadataContextStatusCodes, | ||
| } from "../indexing-metadata-context"; | ||
| import type { | ||
| SerializedIndexingMetadataContext, | ||
| SerializedIndexingMetadataContextInitialized, | ||
| } from "../serialize/indexing-metadata-context"; | ||
| import { | ||
| makeIndexingMetadataContextSchema, | ||
| makeSerializedIndexingMetadataContextSchema, | ||
| } from "../zod-schemas/indexing-metadata-context"; | ||
|
|
||
| /** | ||
| * Builds an unvalidated {@link IndexingMetadataContextInitialized} object. | ||
| */ | ||
| function buildUnvalidatedIndexingMetadataContextInitializedSchema( | ||
| serializedIndexingMetadataContext: SerializedIndexingMetadataContextInitialized, | ||
| ): Unvalidated<IndexingMetadataContextInitialized> { | ||
| return { | ||
|
tk-o marked this conversation as resolved.
tk-o marked this conversation as resolved.
|
||
| statusCode: serializedIndexingMetadataContext.statusCode, | ||
| indexingStatus: buildUnvalidatedCrossChainIndexingStatusSnapshot( | ||
| serializedIndexingMetadataContext.indexingStatus, | ||
| ), | ||
| stackInfo: buildUnvalidatedEnsNodeStackInfo(serializedIndexingMetadataContext.stackInfo), | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Builds an unvalidated {@link IndexingMetadataContext} object to be | ||
| * validated with {@link makeIndexingMetadataContextSchema}. | ||
| * | ||
| * @param serializedIndexingMetadataContext - The serialized indexing metadata context to build from. | ||
| * @return An unvalidated {@link IndexingMetadataContextInitialized} object. | ||
|
vercel[bot] marked this conversation as resolved.
Outdated
|
||
| */ | ||
| function buildUnvalidatedIndexingMetadataContextSchema( | ||
| serializedIndexingMetadataContext: SerializedIndexingMetadataContext, | ||
| ): Unvalidated<IndexingMetadataContext> { | ||
|
tk-o marked this conversation as resolved.
coderabbitai[bot] marked this conversation as resolved.
tk-o marked this conversation as resolved.
|
||
| switch (serializedIndexingMetadataContext.statusCode) { | ||
| case IndexingMetadataContextStatusCodes.Uninitialized: | ||
| return serializedIndexingMetadataContext; | ||
|
|
||
| case IndexingMetadataContextStatusCodes.Initialized: | ||
| return buildUnvalidatedIndexingMetadataContextInitializedSchema( | ||
| serializedIndexingMetadataContext, | ||
| ); | ||
| } | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
tk-o marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Deserialize a serialized {@link IndexingMetadataContext} object. | ||
| */ | ||
| export function deserializeIndexingMetadataContext( | ||
| serializedIndexingMetadataContext: Unvalidated<SerializedIndexingMetadataContext>, | ||
| valueLabel?: string, | ||
| ): IndexingMetadataContext { | ||
| const label = valueLabel ?? "IndexingMetadataContext"; | ||
|
|
||
| const parsed = makeSerializedIndexingMetadataContextSchema(label) | ||
| .transform(buildUnvalidatedIndexingMetadataContextSchema) | ||
| .pipe(makeIndexingMetadataContextSchema(label)) | ||
| .safeParse(serializedIndexingMetadataContext); | ||
|
|
||
| if (parsed.error) { | ||
| throw new Error(`Cannot validate IndexingMetadataContext:\n${prettifyError(parsed.error)}\n`); | ||
|
tk-o marked this conversation as resolved.
Outdated
vercel[bot] marked this conversation as resolved.
Outdated
|
||
| } | ||
| return parsed.data; | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export * from "./deserialize/indexing-metadata-context"; | ||
| export * from "./indexing-metadata-context"; | ||
| export * from "./serialize/indexing-metadata-context"; | ||
| export * from "./validate/indexing-metadata-context"; |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Should we rename this? It seems strange to call it an "ENSNode API".