Add anvil fork mode to cartesi run#421
Conversation
🦋 Changeset detectedLatest commit: 35b34cc The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
39e4df4 to
2c2d626
Compare
Coverage Report
📁 File Coverage (11 files)
|
a7da1d3 to
71d8c01
Compare
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
71d8c01 to
4982e0f
Compare
|
Depending on the chosen fork-url the deployed contracts can have different addresses. So the CLI needs to use the correct address during application deployment, and also report the correct address in the So it should know not only the addresses on local deployment, but also the addresses on all supported live networks, which can potentially be forked. So I had to modify the devnet package to also package the deployments from all networks, which is maintained at cannon registry. So I changed to devnet packaging to call When merged the devnet package will need to be released first, then SDK, then CLI. |
70df749 to
feb831d
Compare
f39a101 to
e580d99
Compare
8224b62 to
d559b36
Compare
So, are these devnet changes in some other PR? Also, I tried building the CLI from this branch, but it fails on the devnet package. Building it in isolation, here are the logs I received. Is there a specific version that is expected? Currently, my system is using 1.5.0-stable. @cartesi/devnet:build:
@cartesi/devnet:build: IPFS Availability Score(# of nodes): Run IPFS Locally to get this score
@cartesi/devnet:build:
✖ Failed to parse anvil version. Is anvil installed?
@cartesi/devnet:build: ✔ Download dependencies
@cartesi/devnet:build: ✔ Anvil started (PID: 98596)
@cartesi/devnet:build: ✔ Contracts deployed
@cartesi/devnet:build: ✔ Local deployments written to deployments/anvil.json
@cartesi/devnet:build: ✔ Export cannon packages
@cartesi/devnet:build: ✔ Anvil stopped -> anvil_state.json
@cartesi/devnet:build: error: script "build:dump" exited with code 1
@cartesi/devnet:build: ERROR: "build:dump" exited with 1.
@cartesi/devnet:build: error: script "build" exited with code 1
@cartesi/devnet:build: ERROR: command finished with error: command (/Users/--x--/cartesi/public/cli/packages/devnet) /opt/homebrew/bin/bun run build exited (1)
@cartesi/devnet#build: command (/Users/--x--/cartesi/public/cli/packages/devnet) /opt/homebrew/bin/bun run build exited (1)
Tasks: 0 successful, 1 total └───────────────────┘
Cached: 0 cached, 1 total
Time: 7.866s
Failed: @cartesi/devnet#build |
brunomenezes
left a comment
There was a problem hiding this comment.
I made the dry-runs suggested and also create/build/run an dapp. No hiccups.
Allow forking from a live chain instead of using pre-baked devnet state. Adds --fork, --fork-url, and --fork-block-number options. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
d559b36 to
8f41216
Compare
|
I think it's safer to remove the default fork url and require the user to provide one.
Users who want to fork must now explicitly pass |
What was the motivation was because of rate limiting, because it goes straight to Ethereum-mainnet or a combination of both? Just picking your brain here. nonetheless I think that is better as a more deliberate decision. |
| daveAppFactoryAddress[ | ||
| forkChainId as keyof typeof daveAppFactoryAddress | ||
| ]; | ||
| if (!chainDaveAppFactoryAddress) { |
There was a problem hiding this comment.
@tuler, should you do this kind of validation also on compose/anvil.ts and compose/node.ts? As this getAddressBook would only run when a address-book command is issued to the CLI.
The validation is about whether the chain ID of the fork is supported or not, right?
There was a problem hiding this comment.
Good catch, added check as well to node.ts
It was not working properly, the node was being disconnected often and dying. |
add supported fork to run
Improved behavior of address-book. Now it prints a different set of contracts weather it’s a running fork or a running devnet. Test tokens are only present at devnet. ERC-4377 are currently only present at fork (not devnet).
|
Improved behavior of address-book. Test tokens are only present at devnet. |
|
When using an invalid URL it fails, I suggest catching the error and printing a nice message |
|
I'm not sure how careful we should be with this kind or URL being accepted via CLI argument, since they may probably have some secret/token init that should be carefully handled. If we do not provide getting this from ENV we should at least show a disclaimer about rotating/revoking the token after using it. |
The CLI is for dev environment, to run on the developer machine. I don't see a big risk here. |
Summary
--forkflag tocartesi runto fork from a live chain instead of using pre-baked devnet state--fork-url <url>option to specify a custom RPC endpoint (implies--fork, defaults tohttps://ethereum.reth.rs/rpc)--fork-block-number <number>option to pin the fork to a specific blockIn fork mode, Anvil runs directly with
--fork-urland--chain-id 31337instead of thedevnetwrapper that loadsanvil_state.json. All other services (node, explorer, bundler, paymaster) continue working unchanged since the chain ID remains 31337.Test plan
cartesi run --dry-run— verify normal devnet mode is unchanged (no regression)cartesi run --fork --dry-run— verify anvil command uses fork with default URLcartesi run --fork-url https://custom-rpc.example.com --dry-run— verify fork with custom URL (implies--fork)cartesi run --fork --fork-block-number 12345 --dry-run— verify fork at specific block numbercartesi run --fork— verify full environment starts and is healthy against a forked chain🤖 Generated with Claude Code