-
Notifications
You must be signed in to change notification settings - Fork 7
Implement forking support with lazy loading backend #426
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
Implement forking support with lazy loading backend #426
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. Let's bring in the latest changes from the feature branch
crates/anvil-polkadot/src/substrate_node/lazy_loading/backend/mod.rs
Outdated
Show resolved
Hide resolved
52d3c29 to
04279c8
Compare
| /// Tests that forking preserves contract state from source chain and that multiple contract | ||
| /// instances maintain independent storage | ||
| #[tokio::test(flavor = "multi_thread")] | ||
| async fn test_fork_with_contract_deployment() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not neccessarily for this PR, but have a look at what other forking-related test scenarios regular anvil has. We should mirror them where it makes sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as an example, what we discussed earlier in the call, using calls which mutate the state on top of a forked network (anvil_setBalance, etc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we are already doing that with test_fork_preserves_state_and_allows_modifications right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm talking about the RPCs that use node-side state mutation, so mutating the state without sending extrinsics (using the BackendWithOverlay we mentioned yesterday).
like set_chainid, set_balance, set_code, set_storageAt, setNonce
| // List of general purpose DRPC keys to rotate through | ||
| static DRPC_KEYS: LazyLock<Vec<String>> = LazyLock::new(|| { | ||
| let mut keys = vec!["AgasqIYODEW_j_J0F91L8oETmhtHCXkR8JAVssvAG40d".to_owned()]; | ||
| let mut keys = vec![ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that the tests are still failing because of invalid API keys. Let's try to debug this a bit.
Comment the if block which starts on line 42
|
Let's also fix clippy |
|
While playing around with this branch locally I ran into another panic. I was just sending balances around on both the original node and the fork Full logs: |
hmm actually I'm getting similar panic on a node that uses master. Looks like only a problem when using cast and sending requests one after the other (if we wait a bit more there is no issue). I'll investigate. Probably cast is not properly waiting for the response before sending the next request |
yeah, this was the issue: #438 |
Great finding! |
Description
This PR implements forking functionality for anvil-polkadot, allowing users to fork from a remote Substrate/Polkadot node and run local tests against live network state.
Adds the ability to fork from a running anvil-polkadot node (or compatible Substrate node) using the
--fork-urlflag. The implementation uses a lazy-loading approach to fetch state from the remote node on-demand, caching values locally for performanceManual testing
After compiling the entire project using
cargo build --release1. Start base node
2. Modify state on base node
3. Verify modified balance
4. Start fork node (inherits modified state)
5. Verify fork inherited state
6. Make changes on fork (doesn't affect base)
7. Verify isolation
Integration tests
Closes: ChainSafe/gossamer-parity#52, ChainSafe/gossamer-parity#58, ChainSafe/gossamer-parity#65, ChainSafe/gossamer-parity#84