Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions packages/ensnode-schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,60 @@
"Ponder"
],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should update the description for this package several lines above.

"exports": {
".": "./src/ponder.schema.ts"
".": "./src/index.ts",
"./ponder": "./src/ponder-schema/index.ts",
"./ensindexer": "./src/ensindexer-schema/index.ts",
"./ensnode": "./src/ensnode-schema/index.ts"
},
Comment thread
coderabbitai[bot] marked this conversation as resolved.
"files": [
"dist"
],
"publishConfig": {
"access": "public",
"exports": {
"types": "./dist/ponder.schema.d.ts",
"default": "./dist/ponder.schema.js"
},
"main": "./dist/ponder.schema.js",
"module": "./dist/ponder.schema.mjs",
"types": "./dist/ponder.schema.d.ts"
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"./ponder": {
"import": {
"types": "./dist/ponder-schema.d.ts",
"default": "./dist/ponder-schema.js"
}
},
"./ensindexer": {
"import": {
"types": "./dist/ensindexer-schema.d.ts",
"default": "./dist/ensindexer-schema.js"
}
},
"./ensnode": {
"import": {
"types": "./dist/ensnode-schema.d.ts",
"default": "./dist/ensnode-schema.js"
Comment thread
tk-o marked this conversation as resolved.
Outdated
}
}
}
},
"scripts": {
"prepublish": "tsup",
"lint": "biome check --write .",
"lint:ci": "biome ci"
},
"dependencies": {
"peerDependencies": {
"drizzle-orm": "catalog:",
"ponder": "catalog:",
"viem": "catalog:"
},
"devDependencies": {
"@ensnode/ensnode-sdk": "workspace:",
"@ensnode/shared-configs": "workspace:*",
"drizzle-orm": "catalog:",
"ponder": "catalog:",
"tsup": "catalog:",
"typescript": "catalog:"
"typescript": "catalog:",
"viem": "catalog:"
}
}
66 changes: 66 additions & 0 deletions packages/ensnode-schema/src/ensnode-schema/index.ts
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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Defines the database objects describing the ENSNode services state.
* Defines the database objects that hold the state of services in an ENSNode instance.

*/

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* multiple ENSIndexer instances using the same database, while ensuring
* multiple ENSIndexer instances using the same ENSDb, while ensuring

* 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],
}),
],
);
5 changes: 5 additions & 0 deletions packages/ensnode-schema/src/ensnode-schema/schema.ts
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);
2 changes: 2 additions & 0 deletions packages/ensnode-schema/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Re-export relevant schema definitions for backward compatibility.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 ensnode-schema outside our monorepo.

export * from "./ensindexer-schema";
186 changes: 186 additions & 0 deletions packages/ensnode-schema/src/ponder-schema/index.ts
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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
*/
Comment thread
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
Comment thread
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),
],
);
5 changes: 5 additions & 0 deletions packages/ensnode-schema/src/ponder-schema/schema.ts
Comment thread
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);
37 changes: 0 additions & 37 deletions packages/ensnode-schema/src/schemas/ensnode-metadata.schema.ts

This file was deleted.

5 changes: 4 additions & 1 deletion packages/ensnode-schema/tsconfig.json
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"]
}
Loading