-
Notifications
You must be signed in to change notification settings - Fork 16
feat: implement canonical filter for findDomains #1654
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 all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
62be41c
feat: implement canonical filter for findDomains
shrugs d6a57fa
docs(changeset): Adds a `canonical?: boolean` filter to the where fil…
shrugs 61bc9be
fix: correct traversal to avoid loops
shrugs a0d2a36
fix: test mock
shrugs 094ab2a
notes from bots
shrugs ecd3a73
feat: partial subregistry index, refactor canonical registries cte to…
shrugs e35d443
Merge branch 'main' into feat/find-canonical-domains
shrugs 14f4e83
docs(changeset): ENSv2 GraphQL API: BREAKING: Removes Account.domains…
shrugs 7177f5e
fix: remove Account.domains to reduce api surface area
shrugs 29f873b
fix: default grapql canonical to false
shrugs 5682d37
fix: union for distinct cte
shrugs 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 @@ | ||
| --- | ||
| "ensapi": minor | ||
shrugs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| --- | ||
|
|
||
| ENSv2 GraphQL API: BREAKING: Removes Account.domains in favor of `Query.domains` with `owner` specified. | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "ensapi": minor | ||
| --- | ||
|
|
||
| Adds a `canonical?: boolean` filter to the where filter in `Query.domains`. When specified, the resulting set of Domains is composed exclusively of Canonical Domains. |
49 changes: 49 additions & 0 deletions
49
apps/ensapi/src/graphql-api/lib/canonical-registries-cte.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,49 @@ | ||
| import config from "@/config"; | ||
|
|
||
| import { sql } from "drizzle-orm"; | ||
|
|
||
| import * as schema from "@ensnode/ensnode-schema"; | ||
| import { getENSv2RootRegistryId } from "@ensnode/ensnode-sdk"; | ||
|
|
||
| import { db } from "@/lib/db"; | ||
|
|
||
| /** | ||
| * The maximum depth to traverse the ENSv2 namegraph in order to construct the set of Canonical | ||
| * Registries. | ||
| * | ||
| * Note that the set of Canonical Registries in the ENSv2 Namegraph is a _tree_, enforced by the | ||
| * requirement that each Registry maintain a reverse-pointer to its Canonical Domain, a form of | ||
| * 'edge authentication': if the reverse-pointer doesn't agree with the forward-pointer, the edge | ||
| * is not traversed, making cycles within the direced graph impossible. | ||
| * | ||
| * So while technically not necessary, including the depth constraint avoids the possibility of an | ||
| * infinite runaway query in the event that the indexed namegraph is somehow corrupted or otherwise | ||
| * introduces a canonical cycle. | ||
| */ | ||
| const CANONICAL_REGISTRIES_MAX_DEPTH = 16; | ||
|
|
||
| /** | ||
| * Builds a recursive CTE that traverses from the ENSv2 Root Registry to construct a set of all | ||
| * Canonical Registries. A Canonical Registry is an ENSv2 Registry that is the Root Registry or the | ||
| * (sub)Registry of a Domain in a Canonical Registry. | ||
| * | ||
| * TODO: could this be optimized further, perhaps as a materialized view? | ||
| */ | ||
| export const getCanonicalRegistriesCTE = () => | ||
| db | ||
| .select({ registryId: sql<string>`registry_id`.as("registryId") }) | ||
| .from( | ||
| sql`( | ||
| WITH RECURSIVE canonical_registries AS ( | ||
| SELECT ${getENSv2RootRegistryId(config.namespace)}::text AS registry_id, 0 AS depth | ||
| UNION ALL | ||
| SELECT rcd.registry_id, cr.depth + 1 | ||
| FROM ${schema.registryCanonicalDomain} rcd | ||
| JOIN ${schema.v2Domain} parent ON parent.id = rcd.domain_id AND parent.subregistry_id = rcd.registry_id | ||
| JOIN canonical_registries cr ON cr.registry_id = parent.registry_id | ||
| WHERE cr.depth < ${CANONICAL_REGISTRIES_MAX_DEPTH} | ||
| ) | ||
| SELECT registry_id FROM canonical_registries | ||
| ) AS canonical_registries_cte`, | ||
shrugs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| .as("canonical_registries"); | ||
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
1 change: 1 addition & 0 deletions
1
apps/ensapi/src/graphql-api/lib/find-domains/find-domains.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
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
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
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.