Skip to content
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

At least one functionality is not schema aware (e.g. Flush) #1359

Open
daramir opened this issue Dec 19, 2024 · 1 comment
Open

At least one functionality is not schema aware (e.g. Flush) #1359

daramir opened this issue Dec 19, 2024 · 1 comment

Comments

@daramir
Copy link

daramir commented Dec 19, 2024

Version

0.8.6

Current behavior

I'm indexing the same token on two chains. For this I have to separate projects, each running

  • ponder start --port 6060 --schema ethereum
  • ponder start --port 6060 --schema polygon
    Using the same DB.

There is a concerning lack of schema awareness somewhere (up to the point that I don't know if the data is being written on the table I expect or if the data is getting mixed up) causing errors similar to this:

10:38:20 AM INFO  app        Indexed 21 events with 100% complete and 2ms remaining
10:38:20 AM ERROR indexing   Internal error occurred while flushing cache. Please report this error here: https://github.com/ponder-sh/ponder/issues
10:38:20 AM WARN  user       Failed 'holder.flush()' database method 
10:38:20 AM ERROR indexing   Error while processing 'Token:Transfer' event in 'mainnet' block 21429711
FlushError: column "account_type" is of type polygon.account_type but expression is of type text
    at /Users/[redacted]/ethereum/src/Token.ts:190:21
  188 |   // Update Token Stats Table
  189 |   // Find the total holder metric from the latest block
> 190 |   const prevStats = await context.db.sql
      |                     ^
  191 |     .select()
  192 |     .from(tokenStat)
  193 |     .orderBy(desc(tokenStat.blockNumber))
Event arguments:
  from    0x3[redacted]9
  to      0x1[redacted]3
  value   1000000000
10:38:20 AM WARN  process    Encountered indexing error, starting shutdown sequence
10:38:20 AM FATAL process    Finished shutdown sequence, terminating (exit code 1)

Expected behavior

While running
ponder start --port 6060 --schema ethereum
I don't expect to see any mention to tables in the polygon schema

Steps to reproduce

Use the same ponder.schema.ts across two different projects, each targeting a different chain e.g. ethereum/polygon:

I saw this issue first with this ponder.schema.ts:

import { onchainTable, onchainEnum, index, relations } from "ponder";

// Event tables
export const transferEvent = onchainTable(
  "transfer_event",
  (t) => ({
    id: t.uuid().primaryKey(),
    amount: t.bigint().notNull(),
    timestamp: t.bigint().notNull(),
    from: t.hex().notNull(),
    to: t.hex().notNull(),
    txHash: t.hex().notNull(),
  }),
  (table) => ({
    fromIdx: index().on(table.from),
    toIdx: index().on(table.to),
  })
);

export const destroyedBlackFundsEvent = onchainTable(
  "destroyed_black_funds_event",
  (t) => ({
    id: t.uuid().primaryKey(),
    blackListedUser: t.hex().notNull(),
    balance: t.bigint().notNull(),
    txHash: t.hex().notNull(),
  }),
  (table) => ({
    blackListedUserIdx: index().on(table.blackListedUser),
  })
);

// Business tables
export const accountType = onchainEnum("account_type", ["EOA", "CONTRACT"]);

export const balance = onchainTable("balance", (t) => ({
  address: t.text().primaryKey(),
  balance: t.bigint().notNull(),
}));

export const holder = onchainTable("holder", (t) => ({
  address: t.text().primaryKey(),
  accountType: accountType("account_type"),
  lastTransfer: t.bigint(), // Unix timestamp in seconds
}));

// Stats tables
export const tokenStat = onchainTable("token_stat", (t) => ({
  blockNumber: t.bigint().primaryKey(),
  totalSupply: t.bigint().notNull(),
  totalHolders: t.bigint().notNull(),
}));

// Relations
export const accountRelation = relations(balance, ({ one }) => ({
  account: one(holder, { fields: [balance.address], references: [holder.address] }),
}));

This yielded the error BaseError: column "account_type" is of type polygon.account_type but expression is of type ethereum.account_type

So I thought it was because of the accountType fancy onchain enum, so I made it text in my Ethereum project and kept it as Enum in the Polygon project. In which case I still have the error which is being reported above.

ponder.config.ts:

import { createConfig } from "ponder";
import { http } from "viem";
import * as dotenv from "dotenv";
import { TokenAbi } from "./abis/TokenAbi";

dotenv.config({ path: "../.env.local" });

export default createConfig({
  networks: {
    mainnet: { chainId: 1, transport: http(process.env.PONDER_RPC_URL_1) },
  },
  contracts: {
    Token: {
      abi: TokenAbi,
      address: "0xbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaA",
      network: "mainnet",
      startBlock: 18733028,
    },
  },
  database: {
    kind: "postgres",
    connectionString: process.env.DATABASE_URL,
  },
});

Link to repository

No response

Anything else?

No response

@kyscott18
Copy link
Collaborator

kyscott18 commented Jan 4, 2025

Hey, this looks like a bug in ponder. I haven't been able to reproduce this, so if you could include some more information about the steps that led up to this bug, it would be helpful.

  • did you change the schema in between running the ethereum and polygon deployment?
  • which deployment did you run first?
  • do you see any missing or irregular data when inspecting your database (with psql and \dT)?
  • do you have a value set for `DATABASE_SCHEMA in .env.local ?
  • have to tried removing dotenv related code
  • does the error persist when running with v0.9 prerelease ? https://t.me/ponder_sh/9335

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants