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

[Feature] Better support for Anvil/Foundry #916

Closed
4 tasks done
0xOlias opened this issue May 28, 2024 · 4 comments
Closed
4 tasks done

[Feature] Better support for Anvil/Foundry #916

0xOlias opened this issue May 28, 2024 · 4 comments

Comments

@0xOlias
Copy link
Collaborator

0xOlias commented May 28, 2024

Per discussion in the chat, Ponder doesn't currently work very well when indexing a local chain like Anvil or Hardhat Network.

Here is the proposed workflow:

  1. Write contracts, start anvil, deploy to anvil
    a. anvil
    b. forge script ./script/0_Deploy.s.sol:Deploy --broadcast --fork-url http://localhost:8545 ...
  2. Start ponder dev server, which accurately indexes events emitted during the foundry script
    a. ponder dev
  3. Update contracts, reset local chain
    a. kill anvil process
    b. anvil
    c. forge script ./script/0_Deploy.s.sol:Deploy --broadcast --fork-url http://localhost:8545 ...
  4. Restart ponder dev server, which syncs from scratch + again indexes correctly
    a. kill ponder dev process
    b. ponder dev

We should be able to unblock this with some debugging and a few small changes. Here's a first pass:

  1. RPC request cache invalidation: Today, the workflow above breaks Ponder because on subsequent starts, the cache will contain stale data from the prior version of the chain. To solve this, we could add an option on networks that disables caching. Could call it disableCache or maybe isLocalChain. In practice, the easiest implementation would be to delete all cached data for that chain on startup. Ideally, this RPC cache invalidation function would be the same thing that powers the proposed ponder cache CLI entrypoint.
  2. Fix start block bug(s): We need better testing around edge case conditions between a contract startBlock and endBlock and the network latest and finalized blocks. Nearly certain we have bugs if the start block is in the unfinalized range. I'd like to design a durable solution here that also fixes [Feature] Support future endBlock #813.
  3. Test local chain + live chain: Users have reported some events don't get processed when both chains are "uncommented", which suggests that the overall sync checkpoint gets stuck at some point in the past. This could be related to 2. I'm also curious if automine behavior plays a role here - what block timestamp gets used for blocks mined on a fresh chain vs a fork, etc? Ponder relies heavily on block timestamp, so that could be the problem here.

Checklist

  • Sync cache invalidation
  • Decide on isLocalChain config API. Note that the Viem Chain type already has testnet?: boolean.
  • Add better tests for interactions between startBlock, endBlock, latest block number and finality block count to understand current behavior and probably find existing bugs
  • Fix [Feature] Support future endBlock #813
@trajan0x
Copy link

trajan0x commented May 28, 2024

I'd suggest one UX improvement on this:

Anvil may be open to adding a Server header that we could use to detect anvil. Obviously the isLocalChain option would take precedence if specified, but this would help new users a bunch

@aureliusbtc
Copy link

Anvil may be open to adding a Server header

Anvil doesn't need to add this, since Ponder could call the web3_clientVersion RPC method to determine if it's a local network:

~ cast rpc web3_clientVersion -r http://127.0.0.1:8545
"anvil/v0.2.0"

This has stayed consistent throughout Foundry version upgrades, with "anvil/vX.X.X" being the returned response.

@trajan0x
Copy link

Makes sense, thought a server header would be better b/c this is an additional request on startup. But makes sense

@0xOlias
Copy link
Collaborator Author

0xOlias commented Jun 10, 2024

Done in #923

@0xOlias 0xOlias closed this as completed Jun 10, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Ponder Roadmap Jun 10, 2024
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

3 participants