Skip to content

Conversation

@exp0nge
Copy link

@exp0nge exp0nge commented Nov 4, 2025

Motivation

The current fork functionality calls out to the defined RPC url (internet) when either something is missing from the local state DB or misc calls like (eth_chainId).

With --load-state, this behavior doesn't change. As outlined above in the two issues, the goal of this PR is to entirely eliminate all remote RPC calls when the fork is running in --offline mode: if there is state cached: use that, if not, return default/0.

This allows the Anvil fork to become portable in environments where internet egress is not possible or unwanted due to security/reproducibility concerns (e.g. namely CI systems).

Solution

  • Use a new offline fork DB
  • Redirect all calls to local state or default if offline mode

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Copy link
Contributor

@onbjerg onbjerg left a comment

Choose a reason for hiding this comment

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

Please provide a description and a motivation for this change. Going off the original issue, you are passing a fork URL, which Anvil correctly tries to talk to. If you want to be fully offline, you should be able to just pass the chain ID, and use --load-state.

@onbjerg onbjerg self-assigned this Nov 4, 2025
@exp0nge
Copy link
Author

exp0nge commented Nov 4, 2025

Please provide a description and a motivation for this change. Going off the original issue, you are passing a fork URL, which Anvil correctly tries to talk to. If you want to be fully offline, you should be able to just pass the chain ID, and use --load-state.

Hey, updated the description. I actually did start with that flag (re: my original issue), but the fork will always call out to the RPC for missing state.

@onbjerg
Copy link
Contributor

onbjerg commented Nov 4, 2025

Yes, this is expected, if you pass a fork URL it will try to reach out to get missing state and things like chain ID. It should work if you remove --fork-url and just use --load-state. That is, to use it in offline mode, use state from disk (--load-state) and don't pass a fork URL. I'm closing this PR and the issue given this is working as intended, unless there is a bug with --load-state.

@exp0nge
Copy link
Author

exp0nge commented Nov 4, 2025

Yes, this is expected, if you pass a fork URL it will try to reach out to get missing state and things like chain ID. It should work if you remove --fork-url and just use --load-state. That is, to use it in offline mode, use state from disk (--load-state) and don't pass a fork URL. I'm closing this PR and the issue given this is working as intended, unless there is a bug with --load-state.

OK, the other parts to this was missing some specific support for like debug_ rpc endpoints. Should I PR that separately?

@onbjerg onbjerg reopened this Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants