-
Notifications
You must be signed in to change notification settings - Fork 16
Update ENSDb schema definitions #1752
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
Changes from 1 commit
6acbea0
eed4800
16c5584
92afddf
b5bd5ca
3f7f0e8
c1964a2
b4fb135
6b6f805
9c05883
f13b6af
1791217
03fecc1
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 | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,66 @@ | ||||||
| /** | ||||||
| * ENSNode Schema | ||||||
| * | ||||||
| * Defines the database objects describing the ENSNode services state. | ||||||
|
Member
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.
Suggested change
|
||||||
| */ | ||||||
|
|
||||||
| import { primaryKey } from "drizzle-orm/pg-core"; | ||||||
|
|
||||||
| import { ENSNODE_SCHEMA } from "./schema"; | ||||||
|
|
||||||
| export { ENSNODE_SCHEMA_NAME } from "./schema"; | ||||||
|
|
||||||
| /** | ||||||
| * ENSNode Metadata | ||||||
| * | ||||||
| * Possible key value pairs are defined by 'EnsNodeMetadata' type: | ||||||
| * - `EnsNodeMetadataEnsDbVersion` | ||||||
| * - `EnsNodeMetadataEnsIndexerPublicConfig` | ||||||
| * - `EnsNodeMetadataEnsIndexerIndexingStatus` | ||||||
| */ | ||||||
| export const ensNodeMetadata = ENSNODE_SCHEMA.table( | ||||||
| "ensnode_metadata", | ||||||
| (t) => ({ | ||||||
| /** | ||||||
| * ENSIndexer Reference | ||||||
|
Member
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. Why is this introducing another terminology? That sounds unnecessary and creates space for confusion. Why not call this the "ensIndexerSchemaName"? Why not reuse our existing terminology?
Member
Author
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. @lightwalker-eth Thanks for providing alternative option, this really makes feedback item actionable. I appreciate that you saw many opportunities for naming improvements, while sharing less clear feedback, for example, "bad naming". It's great for me to know what requires improvements, but it's even better to learn examples of acceptable altenatives. |
||||||
| * | ||||||
| * References the ENSIndexer instance by a unique ENSIndexer schema name | ||||||
| * that a metadata record is associated with. This allows us to support | ||||||
| * multiple ENSIndexer instances using the same database, while ensuring | ||||||
|
Member
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.
Suggested change
|
||||||
| * that their metadata records do not conflict with each other. | ||||||
| */ | ||||||
| ensIndexerRef: t.text().notNull(), | ||||||
|
|
||||||
| /** | ||||||
| * Key | ||||||
| * | ||||||
| * Allowed keys: | ||||||
| * - `EnsNodeMetadataEnsDbVersion['key']` | ||||||
| * - `EnsNodeMetadataEnsIndexerPublicConfig['key']` | ||||||
| * - `EnsNodeMetadataEnsIndexerIndexingStatus['key']` | ||||||
| */ | ||||||
| key: t.text().notNull(), | ||||||
|
|
||||||
| /** | ||||||
| * Value | ||||||
| * | ||||||
| * Allowed values: | ||||||
| * - `EnsNodeMetadataEnsDbVersion['value']` | ||||||
| * - `EnsNodeMetadataEnsIndexerPublicConfig['value']` | ||||||
| * - `EnsNodeMetadataEnsIndexerIndexingStatus['value']` | ||||||
| * | ||||||
| * Guaranteed to be a serialized representation of JSON object. | ||||||
| */ | ||||||
| value: t.jsonb().notNull(), | ||||||
| }), | ||||||
| (table) => [ | ||||||
| /** | ||||||
| * Primary key constraint on 'ensIndexerRef' and 'key' columns, | ||||||
| * to ensure that there is only one record for each key per ENSIndexer instance. | ||||||
| */ | ||||||
| primaryKey({ | ||||||
| name: "ensnode_metadata_pkey", | ||||||
| columns: [table.ensIndexerRef, table.key], | ||||||
| }), | ||||||
| ], | ||||||
| ); | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { pgSchema } from "drizzle-orm/pg-core"; | ||
|
|
||
| export const ENSNODE_SCHEMA_NAME = "ensnode"; | ||
|
|
||
| export const ENSNODE_SCHEMA = pgSchema(ENSNODE_SCHEMA_NAME); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| // Re-export relevant schema definitions for backward compatibility. | ||
|
Member
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. Which backwards compatibility are we working to preserve? My understanding is no one is using |
||
| export * from "./ensindexer-schema"; | ||
|
Member
Author
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 file is modified in a later commit to only include reference to Ponder code repository. Feel free to skip reviewing it. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,186 @@ | ||
| // This file defines tables for RPC request cache schema. | ||
| // Relevant codebase was copied from Ponder Sync schema defined in the Ponder repository: | ||
| // https://github.com/ponder-sh/ponder/blob/ponder%400.16.2/packages/core/src/sync-store/schema.ts | ||
|
|
||
| /** | ||
| * RPC Request Cache Schema | ||
| * | ||
| * Defines the database objects for caching RPC requests and their results. | ||
| * | ||
| * This file defines tables for RPC request cache schema. | ||
| * Relevant codebase was copied from Ponder Sync schema defined in the Ponder repository. | ||
| * @see https://github.com/ponder-sh/ponder/blob/ponder%400.16.2/packages/core/src/sync-store/schema.ts | ||
| */ | ||
|
tk-o marked this conversation as resolved.
Outdated
|
||
|
|
||
| import { customType, index, primaryKey } from "drizzle-orm/pg-core"; | ||
| import type { Address, Hash, Hex } from "viem"; | ||
|
|
||
| import { PONDER_SCHEMA } from "./schema"; | ||
|
|
||
| export { PONDER_SCHEMA_NAME } from "./schema"; | ||
|
|
||
| const numeric78 = customType<{ data: bigint; driverData: string }>({ | ||
| dataType() { | ||
| return "numeric(78,0)"; | ||
| }, | ||
| fromDriver(value: string) { | ||
| return BigInt(value); | ||
| }, | ||
| }); | ||
|
|
||
| export const blocks = PONDER_SCHEMA.table( | ||
| "blocks", | ||
| (t) => ({ | ||
| chainId: t.bigint({ mode: "bigint" }).notNull(), | ||
| number: t.bigint({ mode: "bigint" }).notNull(), | ||
| timestamp: t.bigint({ mode: "bigint" }).notNull(), | ||
| hash: t.varchar({ length: 66 }).notNull().$type<Hash>(), | ||
| parentHash: t.varchar({ length: 66 }).notNull().$type<Hash>(), | ||
| logsBloom: t.varchar({ length: 514 }).notNull().$type<Hex>(), | ||
| miner: t.varchar({ length: 42 }).notNull().$type<Address>(), | ||
| gasUsed: numeric78().notNull(), | ||
| gasLimit: numeric78().notNull(), | ||
| baseFeePerGas: numeric78(), | ||
| nonce: t.varchar({ length: 18 }).$type<Hex>(), | ||
| mixHash: t.varchar({ length: 66 }).$type<Hash>(), | ||
| stateRoot: t.varchar({ length: 66 }).notNull().$type<Hash>(), | ||
| receiptsRoot: t.varchar({ length: 66 }).notNull().$type<Hash>(), | ||
| transactionsRoot: t.varchar({ length: 66 }).notNull().$type<Hash>(), | ||
| sha3Uncles: t.varchar({ length: 66 }).$type<Hash>(), | ||
| size: numeric78().notNull(), | ||
| difficulty: numeric78().notNull(), | ||
| totalDifficulty: numeric78(), | ||
| extraData: t.text().notNull().$type<Hex>(), | ||
| }), | ||
| (table) => [ | ||
| primaryKey({ | ||
| name: "blocks_pkey", | ||
| columns: [table.chainId, table.number], | ||
| }), | ||
| ], | ||
| ); | ||
|
|
||
| export const transactions = PONDER_SCHEMA.table( | ||
| "transactions", | ||
| (t) => ({ | ||
| chainId: t.bigint({ mode: "bigint" }).notNull(), | ||
| blockNumber: t.bigint({ mode: "bigint" }).notNull(), | ||
| transactionIndex: t.integer().notNull(), | ||
| hash: t.varchar({ length: 66 }).notNull().$type<Hash>(), | ||
| blockHash: t.varchar({ length: 66 }).notNull().$type<Hash>(), | ||
| from: t.varchar({ length: 42 }).notNull().$type<Address>(), | ||
| to: t.varchar({ length: 42 }).$type<Address>(), | ||
| input: t.text().notNull().$type<Hex>(), | ||
| value: numeric78().notNull(), | ||
| nonce: t.integer().notNull(), | ||
| r: t.varchar({ length: 66 }).$type<Hex>(), | ||
| s: t.varchar({ length: 66 }).$type<Hex>(), | ||
| v: numeric78(), | ||
| type: t.text().notNull().$type<Hex>(), | ||
| gas: numeric78().notNull(), | ||
| gasPrice: numeric78(), | ||
| maxFeePerGas: numeric78(), | ||
| maxPriorityFeePerGas: numeric78(), | ||
| accessList: t.text(), | ||
| }), | ||
| (table) => [ | ||
| primaryKey({ | ||
| name: "transactions_pkey", | ||
| columns: [table.chainId, table.blockNumber, table.transactionIndex], | ||
| }), | ||
| ], | ||
| ); | ||
|
|
||
| export const transactionReceipts = PONDER_SCHEMA.table( | ||
| "transaction_receipts", | ||
| (t) => ({ | ||
| chainId: t.bigint({ mode: "bigint" }).notNull(), | ||
| blockNumber: t.bigint({ mode: "bigint" }).notNull(), | ||
| transactionIndex: t.integer().notNull(), | ||
| transactionHash: t.varchar({ length: 66 }).notNull().$type<Hash>(), | ||
| blockHash: t.varchar({ length: 66 }).notNull().$type<Hash>(), | ||
| from: t.varchar({ length: 42 }).notNull().$type<Address>(), | ||
| to: t.varchar({ length: 42 }).$type<Address>(), | ||
| contractAddress: t.varchar({ length: 42 }).$type<Address>(), // Note: incorrect | ||
|
tk-o marked this conversation as resolved.
Outdated
|
||
| logsBloom: t.varchar({ length: 514 }).notNull().$type<Hex>(), | ||
| gasUsed: numeric78().notNull(), | ||
| cumulativeGasUsed: numeric78().notNull(), | ||
| effectiveGasPrice: numeric78().notNull(), | ||
| status: t.text().notNull().$type<Hex>(), | ||
| type: t.text().notNull().$type<Hex>(), | ||
| }), | ||
| (table) => [ | ||
| primaryKey({ | ||
| name: "transaction_receipts_pkey", | ||
| columns: [table.chainId, table.blockNumber, table.transactionIndex], | ||
| }), | ||
| ], | ||
| ); | ||
|
|
||
| export const logs = PONDER_SCHEMA.table( | ||
| "logs", | ||
| (t) => ({ | ||
| chainId: t.bigint({ mode: "bigint" }).notNull(), | ||
| blockNumber: t.bigint({ mode: "bigint" }).notNull(), | ||
| logIndex: t.integer().notNull(), | ||
| transactionIndex: t.integer().notNull(), | ||
| blockHash: t.varchar({ length: 66 }).notNull().$type<Hash>(), | ||
| transactionHash: t.varchar({ length: 66 }).notNull().$type<Hash>(), | ||
| address: t.varchar({ length: 42 }).notNull().$type<Address>(), | ||
| topic0: t.varchar({ length: 66 }).$type<Hex>(), | ||
| topic1: t.varchar({ length: 66 }).$type<Hex>(), | ||
| topic2: t.varchar({ length: 66 }).$type<Hex>(), | ||
| topic3: t.varchar({ length: 66 }).$type<Hex>(), | ||
| data: t.text().notNull().$type<Hex>(), | ||
| }), | ||
| (table) => [ | ||
| primaryKey({ | ||
| name: "logs_pkey", | ||
| columns: [table.chainId, table.blockNumber, table.logIndex], | ||
| }), | ||
| ], | ||
| ); | ||
|
|
||
| export const traces = PONDER_SCHEMA.table( | ||
| "traces", | ||
| (t) => ({ | ||
| chainId: t.bigint({ mode: "bigint" }).notNull(), | ||
| blockNumber: t.bigint({ mode: "bigint" }).notNull(), | ||
| transactionIndex: t.integer().notNull(), | ||
| traceIndex: t.integer().notNull(), | ||
| from: t.varchar({ length: 42 }).notNull().$type<Address>(), | ||
| to: t.varchar({ length: 42 }).$type<Address>(), | ||
| input: t.text().notNull().$type<Hex>(), | ||
| output: t.text().$type<Hex>(), | ||
| value: numeric78(), | ||
| type: t.text().notNull(), | ||
| gas: numeric78().notNull(), | ||
| gasUsed: numeric78().notNull(), | ||
| error: t.text(), | ||
| revertReason: t.text(), | ||
| subcalls: t.integer().notNull(), | ||
| }), | ||
| (table) => [ | ||
| primaryKey({ | ||
| name: "traces_pkey", | ||
| columns: [table.chainId, table.blockNumber, table.transactionIndex, table.traceIndex], | ||
| }), | ||
| ], | ||
| ); | ||
|
|
||
| export const rpcRequestResults = PONDER_SCHEMA.table( | ||
| "rpc_request_results", | ||
| (t) => ({ | ||
| requestHash: t.text().notNull(), | ||
| chainId: t.bigint({ mode: "bigint" }).notNull(), | ||
| blockNumber: t.bigint({ mode: "bigint" }), | ||
| result: t.text().notNull(), | ||
| }), | ||
| (table) => [ | ||
| primaryKey({ | ||
| name: "rpc_request_results_pkey", | ||
| columns: [table.chainId, table.requestHash], | ||
| }), | ||
| index("rpc_request_results_chain_id_block_number_index").on(table.chainId, table.blockNumber), | ||
| ], | ||
| ); | ||
|
tk-o marked this conversation as resolved.
Outdated
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { pgSchema } from "drizzle-orm/pg-core"; | ||
|
|
||
| export const PONDER_SCHEMA_NAME = "ponder_sync"; | ||
|
|
||
| export const PONDER_SCHEMA = pgSchema(PONDER_SCHEMA_NAME); |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| { | ||
| "extends": "@ensnode/shared-configs/tsconfig.ponder.json", | ||
| "extends": "@ensnode/shared-configs/tsconfig.lib.json", | ||
| "compilerOptions": { | ||
| "rootDir": "." // necessary for 'The project root is ambiguous' | ||
| }, | ||
| "include": ["./**/*.ts"], | ||
| "exclude": ["node_modules"] | ||
| } |
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.
We should update the
descriptionfor this package several lines above.