-
Notifications
You must be signed in to change notification settings - Fork 17
feat(ensapi): DomainResolver.effective (ENSv1 + ENSv2) #2265
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
7 commits
Select commit
Hold shift + click to select a range
aee85b6
feat(ensapi): add DomainResolver.effective to Omnigraph API
shrugs 1cbb34f
docs: trim DomainResolver.effective descriptions (loop 1)
shrugs 3a10e0a
Merge branch 'main' into feat/domain-effective-resolver
shrugs d68631e
feat(ensapi): resolve DomainResolver.effective for ENSv1 and ENSv2
shrugs c4da2b2
docs: note forward-walk-namegraph reads Unigraph data (fold marker)
shrugs f709cbc
fix(ensapi): reject over-depth paths in forwardWalkDisjointNamegraph
shrugs 277717d
refactor(ensapi): rename forward-walk-namegraph module to forward-wal…
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": patch | ||
| --- | ||
|
|
||
| **Omnigraph API:** Adds `DomainResolver.effective`, the Resolver that ENS Forward Resolution (ENSIP-10) lands on for a Domain. Complements the existing `DomainResolver.assigned` (the Domain's directly-assigned Resolver). |
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
90 changes: 90 additions & 0 deletions
90
apps/ensapi/src/lib/protocol-acceleration/forward-walk-disjoint-namegraph.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,90 @@ | ||
| import { trace } from "@opentelemetry/api"; | ||
| import { Param, sql } from "drizzle-orm"; | ||
| import type { Address, ChainId, DomainId, LabelHashPath, RegistryId } from "enssdk"; | ||
|
|
||
| import type { RequiredAndNotNull } from "@ensnode/ensnode-sdk"; | ||
|
|
||
| import di from "@/di"; | ||
| import { withSpanAsync } from "@/lib/instrumentation/auto-span"; | ||
| import { MAX_SUPPORTED_NAME_DEPTH } from "@/omnigraph-api/lib/constants"; | ||
|
|
||
| const tracer = trace.getTracer("forward-walk-disjoint-namegraph"); | ||
|
|
||
| // TODO(fold-protocol-acceleration): this walk reads the Unigraph-maintained `domain` table (the | ||
| // Registry hierarchy), not Protocol Acceleration tables. Once the plugins are folded it can move to | ||
| // omnigraph-api/lib/ alongside its other consumer (get-domain-by-interpreted-name.ts). | ||
| export interface WalkResultRow { | ||
| domainId: DomainId; | ||
| depth: number; | ||
| address: Address | null; | ||
| chainId: ChainId | null; | ||
| } | ||
|
|
||
| /** | ||
| * Determines whether the WalkResultRow has a resolver set. | ||
| */ | ||
| export const hasResolver = ( | ||
| row: WalkResultRow, | ||
| ): row is RequiredAndNotNull<WalkResultRow, "address" | "chainId"> => | ||
| row.address !== null && row.chainId !== null; | ||
|
|
||
| /** | ||
| * Walks a disjoint namegraph from `registryId` through `path` to identify each ancestor Domain, | ||
| * then LEFT JOINs each Domain to its Resolver via DRR and returns the full path ordered by depth | ||
| * DESC (deepest first). Resolver-less Domains are kept in the result with `resolver`/`chainId` set | ||
| * to NULL. Recursion terminates when the path is exhausted. | ||
| */ | ||
| export async function forwardWalkDisjointNamegraph(registryId: RegistryId, path: LabelHashPath) { | ||
| if (path.length === 0) return []; | ||
|
shrugs marked this conversation as resolved.
|
||
|
|
||
| // Invariant: reject over-depth paths rather than silently truncating at MAX_SUPPORTED_NAME_DEPTH | ||
| // (the recursive CTE stops there), which would resolve against a truncated ancestor path. | ||
| if (path.length > MAX_SUPPORTED_NAME_DEPTH) { | ||
| throw new Error( | ||
| `Invariant(forwardWalkDisjointNamegraph): path length ${path.length} exceeds maximum depth ${MAX_SUPPORTED_NAME_DEPTH}.`, | ||
| ); | ||
| } | ||
|
|
||
| // NOTE: using new Param as per https://github.com/drizzle-team/drizzle-orm/issues/1289#issuecomment-2688581070 | ||
|
shrugs marked this conversation as resolved.
|
||
| const rawLabelHashPathArray = sql`${new Param(path)}::text[]`; | ||
|
|
||
| const { ensDb, ensIndexerSchema } = di.context; | ||
|
|
||
| const result = await withSpanAsync(tracer, "forward-walk", { registryId, path }, () => | ||
| ensDb.execute(sql` | ||
| WITH RECURSIVE path AS ( | ||
| SELECT | ||
| ${registryId}::text AS next_registry_id, | ||
| NULL::text AS "domainId", | ||
| 0 AS depth | ||
|
|
||
| UNION ALL | ||
|
|
||
| SELECT | ||
| -- NOTE: this walk specifically addresses non-canonical Domains as well, so it follows the | ||
| -- raw on-chain forward pointer domain.subregistry_id directly, without canonical edge authentication | ||
| d.subregistry_id AS next_registry_id, | ||
| d.id AS "domainId", | ||
| path.depth + 1 | ||
| FROM path | ||
| JOIN ${ensIndexerSchema.domain} d | ||
| ON d.registry_id = path.next_registry_id | ||
| WHERE d.label_hash = (${rawLabelHashPathArray})[path.depth + 1] | ||
| AND path.depth + 1 <= array_length(${rawLabelHashPathArray}, 1) | ||
| AND path.depth < ${MAX_SUPPORTED_NAME_DEPTH} | ||
| ) | ||
| SELECT | ||
| path."domainId", | ||
| drr.resolver AS "address", | ||
| drr.chain_id AS "chainId", | ||
| path.depth | ||
| FROM path | ||
| LEFT JOIN ${ensIndexerSchema.domainResolverRelation} drr | ||
| ON drr.domain_id = path."domainId" | ||
| WHERE path."domainId" IS NOT NULL | ||
| ORDER BY path.depth DESC; | ||
| `), | ||
| ); | ||
|
|
||
| return result.rows as unknown as WalkResultRow[]; | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.