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

Fallback not working #1457

Open
joaoh9 opened this issue Jan 21, 2025 · 2 comments
Open

Fallback not working #1457

joaoh9 opened this issue Jan 21, 2025 · 2 comments

Comments

@joaoh9
Copy link

joaoh9 commented Jan 21, 2025

Version

0.5.23

Current behavior

Having problem indexing blocks from arbitrum from a public RPC with fallback implementation.

ponder.config.ts file:

const rpcHttp =
  process.env.PONDER_RPC_URL_PROD?.split(',')
    .filter(el => !!el)
    .map(rpc => http(rpc) as Transport) || [];

const websocket =
  process.env.PONDER_WEBSOCKET_URL_PROD?.split(',')
    .filter(el => !!el)
    .map(ws => webSocket(ws)) || [];

const rateLimitRpc =
  process.env.PONDER_RATELIMIT_RPC_URL_PROD?.split(',')
    .filter(el => !!el)
    .map(rpc => rateLimit(http(rpc), { requestsPerSecond: 1 })) || [];

export default createConfig({
  networks: {
    [process.env.NETWORK as string]: {
      chainId: Number(process.env.CHAIN_ID),
      transport: loadBalance([...rpcHttp, ...websocket, ...rateLimitRpc]),
    },
  },

Getting the following error messages:

URL: https://arbitrum.getblock.io/api_key/mainnet
Request body: {"method":"eth_getBlockByNumber","params":["0x0",true]}

Details: fetch failed
Version: [email protected]

and :

WARN  sync       Failed 'eth_chainId' RPC request after 10 attempts
UnknownRpcError: An unknown RPC error occurred.

Details: Cannot read properties of undefined (reading 'request')
Version: [email protected]

Expected behavior

If one RPC connection fails, another one should be tried. Currently it exits with status code 1
RPC list for easy testing:
PONDER_RPC_URL_PROD=https://arbitrum.llamarpc.com,https://arb1.arbitrum.io/rpc,https://rpc.ankr.com/arbitrum

Steps to reproduce

No response

Link to repository

No response

Anything else?

No response

@kyscott18
Copy link
Collaborator

Can you please add some more info about your ponder.config.ts (which contracts, accounts you have registered)? Based on this error message is seems like the problem is that Ponder is trying to request block 0, rather than the fallback transport itself.

@joaoh9
Copy link
Author

joaoh9 commented Jan 21, 2025

Can you please add some more info about your ponder.config.ts (which contracts, accounts you have registered)? Based on this error message is seems like the problem is that Ponder is trying to request block 0, rather than the fallback transport itself.

It is 3 custom smart contracts I use in a closed environment (not publicly accessible)

import { createConfig } from '@ponder/core';
import { loadBalance, rateLimit } from '@ponder/utils';
import { http, parseAbiItem, Transport, webSocket } from 'viem';

import { Consensus } from '../abis/ts/Consensus';
import { ConsensusFactory } from '../abis/ts/ConsensusFactory';
import { ConsensusPolicy } from '../abis/ts/ConsensusPolicy';
import { ConsensusPolicyFactory } from '../abis/ts/ConsensusPolicyFactory';
import { Nfor } from '../abis/ts/Nfor';

const rpcHttp =
  process.env.PONDER_RPC_URL_PROD?.split(',')
    .filter(el => !!el)
    .map(rpc => http(rpc) as Transport) || [];

const websocket =
  process.env.PONDER_WEBSOCKET_URL_PROD?.split(',')
    .filter(el => !!el)
    .map(ws => webSocket(ws)) || [];

const rateLimitRpc =
  process.env.PONDER_RATELIMIT_RPC_URL_PROD?.split(',')
    .filter(el => !!el)
    .map(rpc => rateLimit(http(rpc), { requestsPerSecond: 1 })) || [];

export default createConfig({
  networks: {
    [process.env.NETWORK as string]: {
      chainId: Number(process.env.CHAIN_ID),
      transport: loadBalance([...rpcHttp, ...websocket, ...rateLimitRpc]),
    },
  },
  contracts: {
    factory: {
      abi: ConsensusFactory,
      network: process.env.NETWORK as string,
      address: process.env.CONSENSUS_FACTORY_ADDRESS as `0x${string}`,
      startBlock: Number(process.env.CONSENSUS_FACTORY_START_BLOCK),
      includeTransactionReceipts: true,
      includeCallTraces: true,
    },
    consensusPolicyFactory: {
      abi: ConsensusPolicyFactory,
      network: process.env.NETWORK as string,
      address: process.env.CONSENSUS_POLICY_FACTORY_ADDRESS as `0x${string}`,
      startBlock: Number(process.env.CONSENSUS_POLICY_FACTORY_START_BLOCK),
      includeTransactionReceipts: true,
      includeCallTraces: true,
    },
    consensus: {
      network: process.env.NETWORK as string,
      abi: Consensus,
      factory: {
        // The address of the factory contract that creates instances of this child contract.
        address: process.env.CONSENSUS_FACTORY_ADDRESS as `0x${string}`,
        // The event emitted by the factory that announces a new instance of this child contract.
        event: parseAbiItem(
          'event NewConsensus(address creator,bytes32 indexed org,address indexed consensusAddress,address indexed nforAddress,uint256 amount,string role)',
        ),
        // The name of the parameter that contains the address of the new child contract.
        parameter: 'consensusAddress',
      },
      startBlock: Number(process.env.CONSENSUS_FACTORY_START_BLOCK),
      includeTransactionReceipts: true,
      includeCallTraces: true,
    },
    consensusPolicy: {
      network: process.env.NETWORK as string,
      abi: ConsensusPolicy,
      factory: {
        address: process.env.CONSENSUS_POLICY_FACTORY_ADDRESS as `0x${string}`,
        event: parseAbiItem(
          'event NewConsensusPolicy(address creator,bytes32 indexed org,address indexed consensusAddress,address indexed nforAddress,uint256 amount,string role)',
        ),
        parameter: 'consensusAddress',
      },
      startBlock: Number(process.env.CONSENSUS_POLICY_FACTORY_START_BLOCK),
      includeTransactionReceipts: true,
      includeCallTraces: true,
    },
    nfor: {
      network: process.env.NETWORK as string,
      abi: Nfor,
      address: process.env.NFOR_ADDRESS as `0x${string}`,
      startBlock: Number(process.env.NFOR_START_BLOCK),
      includeTransactionReceipts: true,
      includeCallTraces: true,
    },
  },
});

// .env.local file:

PONDER_RPC_URL_1337=http://0.0.0.0:8545
PONDER_RPC_URL_PROD=https://arbitrum.llamarpc.com,https://arb1.arbitrum.io/rpc,https://rpc.ankr.com/arbitrum
PONDER_WEBSOCKET_URL_PROD=
PONDER_RATELIMIT_RPC_URL_PROD=
CHAIN_ID=42161
NETWORK=arbitrum

NFOR_ADDRESS=0xF67e33dD6245c5d074518d1BE37eb2e070949BDd
NFOR_START_BLOCK=297712573

CONSENSUS_FACTORY_ADDRESS=0x96De4C23A93104Ea7dF386c897221e6DDA154572
CONSENSUS_FACTORY_START_BLOCK=297712602

CONSENSUS_POLICY_FACTORY_ADDRESS=0x61492Ce5842cd348D7dFb0252076aA532e31c2db
CONSENSUS_POLICY_FACTORY_SiTART_BLOCK=297712631

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