-
Notifications
You must be signed in to change notification settings - Fork 19
Add EnsRainbowBeam app with endpoint for submitting labels #2015
base: main
Are you sure you want to change the base?
Changes from 24 commits
19b42ed
c57108e
c0c013e
3537486
440023c
4b49138
912c16c
3021d5c
8c41088
4634cc4
0b5365b
ff194f9
2adbc92
74ff599
053913b
2005200
caf277d
a723be4
d643370
7597168
6e1f410
07c9d1f
33e3ed1
23b4eaa
b79863c
d01acae
2ae9acc
5cfdb4a
e8e4767
ba036a6
e7f9df5
5b92ad7
b9c41e3
beb896f
b411b6d
8ef9b72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| "ensrainbow", | ||
| "ensapi", | ||
| "fallback-ensapi", | ||
| "ensrainbowbeam", | ||
| "enssdk", | ||
| "enscli", | ||
| "enskit", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "ensapi": minor | ||
| --- | ||
|
|
||
| Omnigraph **`Query.labels`** improvements: add a **`LabelHash`** GraphQL scalar (`0x` + 64 lowercase hex, parsed via `parseLabelHash`), rename the input to **`LabelsByLabelHashesInput`** with field **`labelHashes`**, enforce stricter parsing/validation through the scalar layer, normalize mixed-case hex at parse time, cap batch size to **`100`** distinct LabelHashes per request (after deduplication) for a round-number limit aligned with the `inArray` workload, and keep development error masking aligned with Yoga defaults while ensuring intentional `GraphQLError`s still surface useful client messages where applicable. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@ensnode/ensrainbow-sdk": minor | ||
| --- | ||
|
|
||
| Add a light **EnsRainbowBeam** HTTP client (`EnsRainbowBeamClient`): `health()` and `discover()` against EnsRainbowBeam, client-side validation aligned with the server, `EnsRainbowBeamHttpError` for non-2xx responses with optional `{ message, details }` parsing, and subpath export `@ensnode/ensrainbow-sdk/ensrainbowbeam-client`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "ensrainbowbeam": minor | ||
| --- | ||
|
|
||
| Add **`EnsRainbowBeam`** (`apps/ensrainbowbeam`) exposing **`POST /api/discover`**, classifies each submitted label literal against ENSNode via **`labels(by: { labelHashes })`** (with client-side chunking aligned to ENSApi batch limits), emits structured JSON Lines to stdout for future sinks, mirrors other apps’ Dockerfile + Compose service patterns (`docker/services/ensrainbowbeam.yml`), and includes MIT **`LICENSE`** in the app directory ([issue \#2003](https://github.com/namehash/ensnode/issues/2003)). | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete this changeset |
||
| "enssdk": minor | ||
| --- | ||
|
|
||
| Regenerate `enssdk/omnigraph` artifacts for the Omnigraph **`LabelHash`** scalar, mapped in `OmnigraphScalars` for typed **`graphql`** documents. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| import { | ||
| asInterpretedLabel, | ||
| encodeLabelHash, | ||
| type InterpretedLabel, | ||
| type LabelHash, | ||
| labelhashInterpretedLabel, | ||
| parseLabelHash, | ||
| } from "enssdk"; | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { LABELS_BY_LABELHASH_MAX } from "@/omnigraph-api/schema/label"; | ||
| import { request } from "@/test/integration/graphql-utils"; | ||
| import { gql } from "@/test/integration/omnigraph-api-client"; | ||
|
|
||
| type LabelsByLabelHashResult = { | ||
| labels: Array<{ hash: LabelHash; interpreted: InterpretedLabel }>; | ||
| }; | ||
|
|
||
| const LabelsByLabelHash = gql` | ||
| query LabelsByLabelHash($labelHashes: [LabelHash!]!) { | ||
| labels(by: { labelHashes: $labelHashes }) { | ||
| hash | ||
| interpreted | ||
| } | ||
| } | ||
| `; | ||
|
|
||
| // 'eth' is always seeded in the devnet fixture as a healed label | ||
| const ETH_LABEL_HASH: LabelHash = labelhashInterpretedLabel(asInterpretedLabel("eth")); | ||
|
|
||
| // a LabelHash that should not exist in the index (deterministic dummy bytes) | ||
| const ABSENT_LABEL_HASH = parseLabelHash(`0x${"ff".repeat(32)}`); | ||
|
|
||
| describe("Query.labels", () => { | ||
|
djstrong marked this conversation as resolved.
|
||
| it("returns a healed label entry for a known LabelHash", async () => { | ||
| await expect( | ||
| request<LabelsByLabelHashResult>(LabelsByLabelHash, { labelHashes: [ETH_LABEL_HASH] }), | ||
| ).resolves.toMatchObject({ | ||
| labels: [{ hash: ETH_LABEL_HASH, interpreted: "eth" }], | ||
| }); | ||
| }); | ||
|
|
||
| it("accepts non-normalized (mixed-case hex digits) LabelHash variables and resolves matches", async () => { | ||
| // Lowercase `0x` prefix only; uppercase `0X` is rejected (see enssdk `parseLabelHash`). | ||
| const mixedCaseVariable = `0x${ETH_LABEL_HASH.slice(2) | ||
| .split("") | ||
| .map((c, i) => (i % 2 === 0 ? c.toUpperCase() : c)) | ||
| .join("")}` as LabelHash; | ||
| expect(parseLabelHash(mixedCaseVariable)).toBe(ETH_LABEL_HASH); | ||
|
|
||
| await expect( | ||
| request<LabelsByLabelHashResult>(LabelsByLabelHash, { | ||
| labelHashes: [mixedCaseVariable], | ||
| }), | ||
| ).resolves.toMatchObject({ | ||
| labels: [{ hash: ETH_LABEL_HASH, interpreted: "eth" }], | ||
| }); | ||
| }); | ||
|
|
||
| it("rejects uppercase 0X hex prefix", async () => { | ||
| const badPrefix = `0X${ETH_LABEL_HASH.slice(2)}`; | ||
| await expect(request(LabelsByLabelHash, { labelHashes: [badPrefix] })).rejects.toThrow( | ||
| /Invalid labelHash/i, | ||
| ); | ||
| }); | ||
|
|
||
| it("omits LabelHashes that are not present in the index", async () => { | ||
| await expect( | ||
| request<LabelsByLabelHashResult>(LabelsByLabelHash, { labelHashes: [ABSENT_LABEL_HASH] }), | ||
| ).resolves.toEqual({ labels: [] }); | ||
| }); | ||
|
|
||
| it("returns only the present labels when input mixes present and absent LabelHashes", async () => { | ||
| await expect( | ||
| request<LabelsByLabelHashResult>(LabelsByLabelHash, { | ||
| labelHashes: [ETH_LABEL_HASH, ABSENT_LABEL_HASH], | ||
| }), | ||
| ).resolves.toMatchObject({ | ||
| labels: [{ hash: ETH_LABEL_HASH }], | ||
| }); | ||
| }); | ||
|
|
||
| it("dedupes repeated input LabelHashes", async () => { | ||
| await expect( | ||
| request<LabelsByLabelHashResult>(LabelsByLabelHash, { | ||
| labelHashes: [ETH_LABEL_HASH, ETH_LABEL_HASH, ETH_LABEL_HASH], | ||
| }), | ||
| ).resolves.toMatchObject({ | ||
| labels: [{ hash: ETH_LABEL_HASH }], | ||
| }); | ||
| }); | ||
|
|
||
| it("returns an empty list when input is empty", async () => { | ||
| await expect(request(LabelsByLabelHash, { labelHashes: [] })).resolves.toEqual({ labels: [] }); | ||
| }); | ||
|
|
||
| it("classifies returned labels: 'eth' is healed (interpreted !== encodeLabelHash(hash))", async () => { | ||
| const { labels } = await request<LabelsByLabelHashResult>(LabelsByLabelHash, { | ||
| labelHashes: [ETH_LABEL_HASH], | ||
| }); | ||
|
|
||
| expect(labels).toHaveLength(1); | ||
| expect(labels[0].interpreted).not.toEqual(encodeLabelHash(ETH_LABEL_HASH)); | ||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| it("rejects junk strings that cannot be parsed as LabelHashes", async () => { | ||
| await expect( | ||
| request(LabelsByLabelHash, { | ||
| labelHashes: ["not-even-hex"], | ||
| }), | ||
| ).rejects.toThrow(/Invalid labelHash/i); | ||
| }); | ||
|
|
||
| it("rejects hex values that are not exactly 32 bytes", async () => { | ||
| await expect( | ||
| request(LabelsByLabelHash, { | ||
| labelHashes: ["0x00"], | ||
| }), | ||
| ).rejects.toThrow(/Invalid labelHash/i); | ||
| }); | ||
|
|
||
| it("rejects requests over the maximum allowed distinct LabelHash count", async () => { | ||
| const labelHashes: LabelHash[] = []; | ||
| for (let i = 0; i <= LABELS_BY_LABELHASH_MAX; i++) { | ||
| labelHashes.push(parseLabelHash(`0x${i.toString(16).padStart(64, "0")}`)); | ||
| } | ||
|
|
||
| await expect(request(LabelsByLabelHash, { labelHashes })).rejects.toThrow( | ||
| /Too many distinct LabelHashes/i, | ||
| ); | ||
| }); | ||
|
|
||
| it("allows input with duplicate LabelHashes when the distinct count is within the max", async () => { | ||
| await expect( | ||
| request<LabelsByLabelHashResult>(LabelsByLabelHash, { | ||
| labelHashes: [ETH_LABEL_HASH, ETH_LABEL_HASH, ETH_LABEL_HASH], | ||
| }), | ||
| ).resolves.toMatchObject({ | ||
| labels: [{ hash: ETH_LABEL_HASH, interpreted: "eth" }], | ||
| }); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| import config from "@/config"; | ||
|
|
||
| import { type ResolveCursorConnectionArgs, resolveCursorConnection } from "@pothos/plugin-relay"; | ||
| import { inArray } from "drizzle-orm"; | ||
| import { makeConcreteRegistryId, makePermissionsId, makeResolverId } from "enssdk"; | ||
| import { createGraphQLError } from "graphql-yoga"; | ||
|
|
||
| import { getRootRegistryId } from "@ensnode/ensnode-sdk"; | ||
|
|
||
|
|
@@ -25,6 +27,11 @@ import { | |
| DomainsOrderInput, | ||
| DomainsWhereInput, | ||
| } from "@/omnigraph-api/schema/domain"; | ||
| import { | ||
| LABELS_BY_LABELHASH_MAX, | ||
| LabelRef, | ||
| LabelsByLabelHashesInput, | ||
| } from "@/omnigraph-api/schema/label"; | ||
| import { PermissionsIdInput, PermissionsRef } from "@/omnigraph-api/schema/permissions"; | ||
| import { RegistrationInterfaceRef } from "@/omnigraph-api/schema/registration"; | ||
| import { RegistryIdInput, RegistryInterfaceRef } from "@/omnigraph-api/schema/registry"; | ||
|
|
@@ -140,6 +147,41 @@ builder.queryType({ | |
| }, | ||
| }), | ||
|
|
||
| ///////////////////////// | ||
| // Find Labels by Hashes | ||
| ///////////////////////// | ||
| labels: t.field({ | ||
|
djstrong marked this conversation as resolved.
|
||
| description: | ||
| "Look up Labels in the index by a batch of LabelHashes. " + | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use template string instead of string concatenation. |
||
| "Each returned Label exposes its `hash` and `interpreted` representation, where " + | ||
| "`interpreted` is the Encoded LabelHash for unhealed/unknown labels and a normalized " + | ||
| "literal for healed labels. LabelHashes that are not present in the index are simply " + | ||
| "omitted from the result.", | ||
| type: [LabelRef], | ||
| nullable: false, | ||
| args: { by: t.arg({ type: LabelsByLabelHashesInput, required: true }) }, | ||
| resolve: async (_parent, { by }) => { | ||
| if (by.labelHashes.length === 0) return []; | ||
|
|
||
| const dedupedHashes = Array.from(new Set(by.labelHashes)); | ||
|
|
||
| if (dedupedHashes.length > LABELS_BY_LABELHASH_MAX) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update this to check the argument length, not the deduplicated length. It doesn't make any sense to restrict on the deduplicated. The user should just only be able to pass the maximum of arguments. Then remove all discussion about the deduplication logic because it's just unnecessary, including in the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, surely this should be better implemented as a GraphQL argument zod validator, see rest of the codebase |
||
| // Use `createGraphQLError` so the client-facing validation message survives Yoga's | ||
| // default `maskError`, which (correctly) hides plain `Error` instances as | ||
| // "Unexpected error.". | ||
| throw createGraphQLError( | ||
| `Too many distinct LabelHashes: received ${dedupedHashes.length}, max ${LABELS_BY_LABELHASH_MAX}.`, | ||
| { extensions: { code: "BAD_USER_INPUT" } }, | ||
| ); | ||
| } | ||
|
|
||
| return ensDb | ||
| .select() | ||
| .from(ensIndexerSchema.label) | ||
| .where(inArray(ensIndexerSchema.label.labelHash, dedupedHashes)); | ||
| }, | ||
| }), | ||
|
|
||
| ///////////////////////////////////// | ||
| // Get Account by Id or Address | ||
| ///////////////////////////////////// | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,18 +7,21 @@ import { | |
| type Hex, | ||
| isInterpretedLabel, | ||
| isInterpretedName, | ||
| type LabelHash, | ||
| type Name, | ||
| type Node, | ||
| type NormalizedAddress, | ||
| type PermissionsId, | ||
| type PermissionsResourceId, | ||
| type PermissionsUserId, | ||
| parseLabelHash, | ||
| type RegistrationId, | ||
| type RegistryId, | ||
| type RenewalId, | ||
| type ResolverId, | ||
| type ResolverRecordsId, | ||
| } from "enssdk"; | ||
| import { createGraphQLError } from "graphql-yoga"; | ||
| import { isHex, size } from "viem"; | ||
| import { z } from "zod/v4"; | ||
|
|
||
|
|
@@ -61,6 +64,20 @@ builder.scalarType("Hex", { | |
| .parse(value), | ||
| }); | ||
|
|
||
| builder.scalarType("LabelHash", { | ||
| description: | ||
| "LabelHash represents enssdk#LabelHash: a 32-byte (64 hex digit) value, `0x`-prefixed and lowercased.", | ||
| serialize: (value: LabelHash) => value, | ||
| parseValue: (value) => { | ||
| try { | ||
| return parseLabelHash(z.coerce.string().parse(value)); | ||
| } catch (err) { | ||
| const message = err instanceof Error ? err.message : String(err); | ||
| throw createGraphQLError(message, { extensions: { code: "BAD_USER_INPUT" } }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This approach with catch + custom graphql error seems incorrect and unnecessary, see other scalars? |
||
| } | ||
| }, | ||
| }); | ||
|
|
||
| builder.scalarType("ChainId", { | ||
| description: "ChainId represents a enssdk#ChainId.", | ||
| serialize: (value: ChainId) => value, | ||
|
|
||
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.
Update this to be public facing. this is ai generated and leaks internals.