-
Notifications
You must be signed in to change notification settings - Fork 15
ENSDb data model #1660
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
Open
tk-o
wants to merge
10
commits into
main
Choose a base branch
from
feat/ensdb-data-model
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+336
−0
Open
ENSDb data model #1660
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
05a3763
Create ENSDb module in ENSNode SDK
tk-o 3505efa
docs(changeset): Introduces ENSDb module which includes data model de…
tk-o bb62856
Extend ENSIndexer module in ENSNode SDK
tk-o b1c25bc
docs(changeset): Extends ENSIndexer module with functionality allowin…
tk-o 8c44882
Introduce `ENSNode Metadata` schema
tk-o e92e72b
docs(changeset): Includes schema for `ENSNodeMetadata`.
tk-o 739f0d3
Apply AI PR feedback
tk-o 3f7be07
Fix typo
tk-o 8eaf978
Apply code formatting
tk-o 07033c5
Apply AI PR feedback
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@ensnode/ensnode-sdk": minor | ||
| --- | ||
|
|
||
| Introduces ENSDb module which includes data model definitions. |
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,5 @@ | ||
| --- | ||
| "@ensnode/ensnode-sdk": minor | ||
| --- | ||
|
|
||
| Extends ENSIndexer module with functionality allowing compatibility check between two instances of ENSIndexer public config. |
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,5 @@ | ||
| --- | ||
| "@ensnode/ensnode-schema": minor | ||
| --- | ||
|
|
||
| Includes schema for `ENSNodeMetadata`. |
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
37 changes: 37 additions & 0 deletions
37
packages/ensnode-schema/src/schemas/ensnode-metadata.schema.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,37 @@ | ||
| /** | ||
| * Schema Definitions that hold metadata about the ENSNode instance. | ||
| */ | ||
|
|
||
| import { onchainTable } from "ponder"; | ||
|
|
||
| /** | ||
| * ENSNode Metadata | ||
| * | ||
| * Possible key value pairs are defined by 'EnsNodeMetadata' type: | ||
| * - `EnsNodeMetadataEnsDbVersion` | ||
| * - `EnsNodeMetadataEnsIndexerPublicConfig` | ||
| * - `EnsNodeMetadataEnsIndexerIndexingStatus` | ||
| */ | ||
| export const ensNodeMetadata = onchainTable("ensnode_metadata", (t) => ({ | ||
| /** | ||
| * Key | ||
| * | ||
| * Allowed keys: | ||
| * - `EnsNodeMetadataEnsDbVersion['key']` | ||
| * - `EnsNodeMetadataEnsIndexerPublicConfig['key']` | ||
| * - `EnsNodeMetadataEnsIndexerIndexingStatus['key']` | ||
| */ | ||
| key: t.text().primaryKey(), | ||
|
|
||
| /** | ||
| * Value | ||
| * | ||
| * Allowed values: | ||
| * - `EnsNodeMetadataEnsDbVersion['value']` | ||
| * - `EnsNodeMetadataEnsIndexerPublicConfig['value']` | ||
| * - `EnsNodeMetadataEnsIndexerIndexingStatus['value']` | ||
| * | ||
| * Guaranteed to be a serialized representation of JSON object. | ||
| */ | ||
| value: t.jsonb().notNull(), | ||
| })); |
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,58 @@ | ||
| import type { EnsIndexerPublicConfig } from "../ensindexer/config"; | ||
| import type { CrossChainIndexingStatusSnapshot } from "../indexing-status/cross-chain-indexing-status-snapshot"; | ||
|
|
||
| /** | ||
| * ENSDb Client Query | ||
| * | ||
| * Includes methods for reading from ENSDb. | ||
| */ | ||
tk-o marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| export interface EnsDbClientQuery { | ||
| /** | ||
| * Get ENSDb Version | ||
| * | ||
| * @returns the existing record, or `undefined`. | ||
| */ | ||
| getEnsDbVersion(): Promise<string | undefined>; | ||
tk-o marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Get ENSIndexer Public Config | ||
| * | ||
| * @returns the existing record, or `undefined`. | ||
| */ | ||
| getEnsIndexerPublicConfig(): Promise<EnsIndexerPublicConfig | undefined>; | ||
|
|
||
| /** | ||
| * Get Indexing Status Snapshot | ||
| * | ||
| * @returns the existing record, or `undefined`. | ||
| */ | ||
| getIndexingStatusSnapshot(): Promise<CrossChainIndexingStatusSnapshot | undefined>; | ||
tk-o marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
| * ENSDb Client Mutation | ||
| * | ||
| * Includes methods for writing into ENSDb. | ||
| */ | ||
| export interface EnsDbClientMutation { | ||
| /** | ||
| * Upsert ENSDb Version | ||
| * | ||
| * @throws when upsert operation failed. | ||
| */ | ||
| upsertEnsDbVersion(ensDbVersion: string): Promise<void>; | ||
|
|
||
| /** | ||
| * Upsert ENSIndexer Public Config | ||
| * | ||
| * @throws when upsert operation failed. | ||
| */ | ||
| upsertEnsIndexerPublicConfig(ensIndexerPublicConfig: EnsIndexerPublicConfig): Promise<void>; | ||
|
|
||
| /** | ||
| * Upsert Indexing Status Snapshot | ||
| * | ||
| * @throws when upsert operation failed. | ||
| */ | ||
| upsertIndexingStatusSnapshot(indexingStatus: CrossChainIndexingStatusSnapshot): Promise<void>; | ||
| } | ||
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,38 @@ | ||
| import type { EnsIndexerPublicConfig } from "../ensindexer/config"; | ||
| import type { CrossChainIndexingStatusSnapshot } from "../indexing-status/cross-chain-indexing-status-snapshot"; | ||
|
|
||
| /** | ||
| * Keys used to distinguish records in `ensnode_metadata` table in the ENSDb. | ||
| */ | ||
| export const EnsNodeMetadataKeys = { | ||
| EnsDbVersion: "ensdb_version", | ||
| EnsIndexerPublicConfig: "ensindexer_public_config", | ||
| EnsIndexerIndexingStatus: "ensindexer_indexing_status", | ||
| } as const; | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export type EnsNodeMetadataKey = (typeof EnsNodeMetadataKeys)[keyof typeof EnsNodeMetadataKeys]; | ||
|
|
||
| export interface EnsNodeMetadataEnsDbVersion { | ||
| key: typeof EnsNodeMetadataKeys.EnsDbVersion; | ||
| value: string; | ||
| } | ||
|
|
||
| export interface EnsNodeMetadataEnsIndexerPublicConfig { | ||
| key: typeof EnsNodeMetadataKeys.EnsIndexerPublicConfig; | ||
| value: EnsIndexerPublicConfig; | ||
| } | ||
|
|
||
| export interface EnsNodeMetadataEnsIndexerIndexingStatus { | ||
| key: typeof EnsNodeMetadataKeys.EnsIndexerIndexingStatus; | ||
| value: CrossChainIndexingStatusSnapshot; | ||
| } | ||
|
|
||
| /** | ||
| * ENSNode Metadata | ||
| * | ||
| * Union type gathering all variants of ENSNode Metadata. | ||
| */ | ||
| export type EnsNodeMetadata = | ||
| | EnsNodeMetadataEnsDbVersion | ||
| | EnsNodeMetadataEnsIndexerPublicConfig | ||
| | EnsNodeMetadataEnsIndexerIndexingStatus; | ||
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,3 @@ | ||
| export * from "./client"; | ||
| export * from "./ensnode-metadata"; | ||
| export * from "./serialize/ensnode-metadata"; |
38 changes: 38 additions & 0 deletions
38
packages/ensnode-sdk/src/ensdb/serialize/ensnode-metadata.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,38 @@ | ||
| import type { SerializedEnsIndexerPublicConfig } from "../../ensindexer/config"; | ||
| import type { SerializedCrossChainIndexingStatusSnapshot } from "../../indexing-status/serialize/cross-chain-indexing-status-snapshot"; | ||
| import type { | ||
| EnsNodeMetadata, | ||
tk-o marked this conversation as resolved.
Show resolved
Hide resolved
tk-o marked this conversation as resolved.
Show resolved
Hide resolved
tk-o marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| EnsNodeMetadataEnsDbVersion, | ||
| EnsNodeMetadataEnsIndexerIndexingStatus, | ||
| EnsNodeMetadataEnsIndexerPublicConfig, | ||
| EnsNodeMetadataKeys, | ||
| } from "../ensnode-metadata"; | ||
|
|
||
| /** | ||
| * Serialized representation of {@link EnsNodeMetadataEnsDbVersion}. | ||
| */ | ||
| export type SerializedEnsNodeMetadataEnsDbVersion = EnsNodeMetadataEnsDbVersion; | ||
|
|
||
| /** | ||
| * Serialized representation of {@link EnsNodeMetadataEnsIndexerPublicConfig}. | ||
| */ | ||
| export interface SerializedEnsNodeMetadataEnsIndexerPublicConfig { | ||
| key: typeof EnsNodeMetadataKeys.EnsIndexerPublicConfig; | ||
| value: SerializedEnsIndexerPublicConfig; | ||
| } | ||
|
|
||
| /** | ||
| * Serialized representation of {@link EnsNodeMetadataEnsIndexerIndexingStatus}. | ||
| */ | ||
| export interface SerializedEnsNodeMetadataEnsIndexerIndexingStatus { | ||
| key: typeof EnsNodeMetadataKeys.EnsIndexerIndexingStatus; | ||
| value: SerializedCrossChainIndexingStatusSnapshot; | ||
| } | ||
|
|
||
| /** | ||
| * Serialized representation of {@link EnsNodeMetadata} | ||
| */ | ||
| export type SerializedEnsNodeMetadata = | ||
| | SerializedEnsNodeMetadataEnsDbVersion | ||
| | SerializedEnsNodeMetadataEnsIndexerPublicConfig | ||
| | SerializedEnsNodeMetadataEnsIndexerIndexingStatus; | ||
80 changes: 80 additions & 0 deletions
80
packages/ensnode-sdk/src/ensindexer/config/compatibility.test.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,80 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { ENSNamespaceIds } from "@ensnode/datasources"; | ||
| import { PluginName } from "@ensnode/ensnode-sdk"; | ||
|
|
||
| import { | ||
| type EnsIndexerPublicConfigCompatibilityCheck, | ||
| validateEnsIndexerPublicConfigCompatibility, | ||
| } from "./compatibility"; | ||
|
|
||
| describe("EnsIndexerConfig compatibility", () => { | ||
| describe("validateEnsIndexerPublicConfigCompatibility()", () => { | ||
| const config = { | ||
| indexedChainIds: new Set([1, 10, 8453]), | ||
| isSubgraphCompatible: false, | ||
| namespace: ENSNamespaceIds.Mainnet, | ||
| plugins: [PluginName.Subgraph, PluginName.Basenames, PluginName.ThreeDNS], | ||
| } satisfies EnsIndexerPublicConfigCompatibilityCheck; | ||
|
|
||
| it("does not throw error when 'configB' is compatible with 'configA' ('configA' is subset of 'configB')", () => { | ||
| const configA = structuredClone(config); | ||
|
|
||
| const configB = structuredClone(config); | ||
| configB.indexedChainIds.add(59144); | ||
| configB.plugins.push(PluginName.Lineanames); | ||
|
|
||
| expect(() => | ||
| validateEnsIndexerPublicConfigCompatibility(configA, configB), | ||
| ).not.toThrowError(); | ||
| }); | ||
tk-o marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| it("throws error when 'configA.indexedChainIds' are not subset of 'configB.indexedChainIds'", () => { | ||
| const configA = structuredClone(config); | ||
|
|
||
| const configB = structuredClone(config); | ||
| configB.indexedChainIds.delete(8453); | ||
|
|
||
| expect(() => validateEnsIndexerPublicConfigCompatibility(configA, configB)).toThrowError( | ||
| /'indexedChainIds' must be compatible. Stored Config 'indexedChainIds': '1, 10, 8453'. Current Config 'indexedChainIds': '1, 10'/i, | ||
| ); | ||
| }); | ||
|
|
||
| it("throws error when 'configA.isSubgraphCompatible' is not same as 'configB.isSubgraphCompatible'", () => { | ||
| const configA = structuredClone(config); | ||
|
|
||
| const configB = { | ||
| ...structuredClone(config), | ||
| isSubgraphCompatible: !configA.isSubgraphCompatible, | ||
| } satisfies EnsIndexerPublicConfigCompatibilityCheck; | ||
|
|
||
| expect(() => validateEnsIndexerPublicConfigCompatibility(configA, configB)).toThrowError( | ||
| /'isSubgraphCompatible' flag must be compatible. Stored Config 'isSubgraphCompatible' flag: 'false'. Current Config 'isSubgraphCompatible' flag: 'true'/i, | ||
| ); | ||
| }); | ||
|
|
||
| it("throws error when 'configA.namespace' is not same as 'configB.namespace'", () => { | ||
| const configA = structuredClone(config); | ||
|
|
||
| const configB = { | ||
| ...structuredClone(config), | ||
| namespace: ENSNamespaceIds.Sepolia, | ||
| } satisfies EnsIndexerPublicConfigCompatibilityCheck; | ||
|
|
||
| expect(() => validateEnsIndexerPublicConfigCompatibility(configA, configB)).toThrowError( | ||
| /'namespace' must be compatible. Stored Config 'namespace': 'mainnet'. Current Config 'namespace': 'sepolia'/i, | ||
| ); | ||
| }); | ||
|
|
||
| it("throws error when 'configA.plugins' are not subset of 'configB.plugins'", () => { | ||
| const configA = structuredClone(config); | ||
|
|
||
| const configB = structuredClone(config); | ||
| configB.plugins.pop(); | ||
|
|
||
| expect(() => validateEnsIndexerPublicConfigCompatibility(configA, configB)).toThrowError( | ||
| /'plugins' must be compatible. Stored Config 'plugins': 'subgraph, basenames, threedns'. Current Config 'plugins': 'subgraph, basenames'/i, | ||
| ); | ||
| }); | ||
| }); | ||
| }); | ||
63 changes: 63 additions & 0 deletions
63
packages/ensnode-sdk/src/ensindexer/config/compatibility.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,63 @@ | ||
| import type { EnsIndexerPublicConfig } from "./types"; | ||
|
|
||
| export type EnsIndexerPublicConfigCompatibilityCheck = Pick< | ||
| EnsIndexerPublicConfig, | ||
| "indexedChainIds" | "isSubgraphCompatible" | "namespace" | "plugins" | ||
| >; | ||
|
|
||
| /** | ||
| * Validate if `configB` is compatible with `configA`, such that `configA` is | ||
| * a subset of `configB`. | ||
| * | ||
| * @throws error if configs are incompatible. | ||
| */ | ||
| export function validateEnsIndexerPublicConfigCompatibility( | ||
| configA: EnsIndexerPublicConfigCompatibilityCheck, | ||
| configB: EnsIndexerPublicConfigCompatibilityCheck, | ||
| ): void { | ||
| const configAIndexedChainIds = Array.from(configA.indexedChainIds); | ||
| const configBIndexedChainIds = Array.from(configB.indexedChainIds); | ||
| if ( | ||
| !configAIndexedChainIds.every((configAChainId) => | ||
| configBIndexedChainIds.includes(configAChainId), | ||
| ) | ||
tk-o marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) { | ||
| throw new Error( | ||
| [ | ||
| `'indexedChainIds' must be compatible.`, | ||
| `Stored Config 'indexedChainIds': '${configAIndexedChainIds.join(", ")}'.`, | ||
| `Current Config 'indexedChainIds': '${configBIndexedChainIds.join(", ")}'.`, | ||
| ].join(" "), | ||
| ); | ||
| } | ||
|
|
||
| if (configA.isSubgraphCompatible !== configB.isSubgraphCompatible) { | ||
| throw new Error( | ||
| [ | ||
| `'isSubgraphCompatible' flag must be compatible.`, | ||
| `Stored Config 'isSubgraphCompatible' flag: '${configA.isSubgraphCompatible}'.`, | ||
| `Current Config 'isSubgraphCompatible' flag: '${configB.isSubgraphCompatible}'.`, | ||
| ].join(" "), | ||
| ); | ||
| } | ||
|
|
||
| if (configA.namespace !== configB.namespace) { | ||
| throw new Error( | ||
| [ | ||
| `'namespace' must be compatible.`, | ||
| `Stored Config 'namespace': '${configA.namespace}'.`, | ||
| `Current Config 'namespace': '${configB.namespace}'.`, | ||
| ].join(" "), | ||
| ); | ||
| } | ||
|
|
||
| if (!configA.plugins.every((configAPlugin) => configB.plugins.includes(configAPlugin))) { | ||
| throw new Error( | ||
| [ | ||
| `'plugins' must be compatible.`, | ||
| `Stored Config 'plugins': '${configA.plugins.join(", ")}'.`, | ||
| `Current Config 'plugins': '${configB.plugins.join(", ")}'.`, | ||
| ].join(" "), | ||
| ); | ||
| } | ||
tk-o marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.