-
Notifications
You must be signed in to change notification settings - Fork 5.4k
feat: forc-node local contract state forking #7478
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
base: master
Are you sure you want to change the base?
Conversation
6fef5a7 to
5593f9b
Compare
CodSpeed Performance ReportMerging #7478 will not alter performanceComparing Summary
|
|
|
||
| [[package]] | ||
| name = "std" | ||
| version = "0.69.1" |
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.
seem to be using outdated version of forc
|
Nice, this is looking really promising. It'd be great to also write up some documentation to include with this PR, stepping through an example use case of when and how to use this feature. Maybe in the same sort of vein as what we have written up for forc debug. |
6a1d2a5 to
07eecf9
Compare
kayagokalp
left a comment
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.
Very excited for this! We also might want to make sure we depend on std via path instead of registry in the test. That way std will keep up-to-date with the repo for the tests.
Co-authored-by: kaya <[email protected]>
Co-authored-by: kaya <[email protected]>
Co-authored-by: kaya <[email protected]>
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.
This PR is being reviewed by Cursor Bugbot
Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
| Ok(exists) | ||
| } else { | ||
| Ok(false) | ||
| } |
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.
Bug: Inconsistent Key Slicing Causes Panics
The exists method for Column::ContractsRawCode attempts to slice key[..32] without first checking if key.len() >= 32. This causes a panic when the key is shorter than 32 bytes. The other methods (size_of_value, get, read) have the same issue. In contrast, Column::ContractsState correctly checks key.len() == 64 before slicing, preventing out-of-bounds access.
## Description This pull request makes a small change to the visibility of struct fields in the `DataSource` struct. The fields `data` and `stage` are now public, which allows them to be accessed from outside the module. Currently there is no way to override these attributes with custom values externally. This is required for FuelLabs/sway#7478 - as we override these attributes to enable contract state forking in the PR. ## Checklist - [ ] Breaking changes are clearly marked as such in the PR description and changelog - [ ] New behavior is reflected in tests - [ ] [The specification](https://github.com/FuelLabs/fuel-specs/) matches the implemented behavior (link update PR if changes are needed) ### Before requesting review - [x] I have reviewed the code myself - [ ] I have created follow-up issues caused by this PR and linked them here ### After merging, notify other teams [Add or remove entries as needed] - [ ] [Rust SDK](https://github.com/FuelLabs/fuels-rs/) - [x] [Sway compiler](https://github.com/FuelLabs/sway/) - [ ] [Platform documentation](https://github.com/FuelLabs/devrel-requests/issues/new?assignees=&labels=new+request&projects=&template=NEW-REQUEST.yml&title=%5BRequest%5D%3A+) (for out-of-organization contributors, the person merging the PR will do this) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Expose `DataSource` fields `data` and `stage` publicly and add corresponding changelog entry. > > - **State**: > - `crates/fuel-core/src/state/data_source.rs`: Make `DataSource` fields `data` and `stage` public. > - **Changelog**: > - `.changes/changed/3134.md`: Add entry noting public visibility of `DataSource` fields. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit ab6b0e3. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: z <[email protected]> Co-authored-by: Green Baneling <[email protected]>
Description
Addresses #7448
This pull request introduces state forking support to the local node in
forc-node, allowing developers to run a local node that mirrors the contract state from a remote node at latest block height (currently only latest is supported).The contract bytecode and state is fetched dynamically (at runtime - from specified forked url) as the state is requested.
State Forking Feature
fork_urlandfork_block_numbertoforc-node local, enabling users to specify a remote node and block height for state forking (it must supporthistorical execution).local/mod.rsto support state forking by integrating a newforkmodule, which handles fetching state from the remote node and merging it with local storage. The node now conditionally initializes with forking logic based on user input.Dependency and Build Updates
Cargo.tomlandforc-node/Cargo.tomlto use patched versions offuel-corecrates from a specific branchdatasourcein the combined database; the datasource attributes are private; the fuel-corev0.46.0patch simply updates the visibility of the relevant attributes so that they can be overriden to provide fork functionalityblock_on_any_runtimefunction inforc-pkg/src/source/reg/mod.rspublic, allowing it to be used outside its original moduleTesting and Examples
forkandfork-caller) to demonstrate and validate the state forking capability.These updates collectively enable local development nodes to fork contract state from a remote node, greatly enhancing testing flexibility and realism for smart contract developers.
Related PR: FuelLabs/fuel-core#3134
Checklist
Breaking*orNew Featurelabels where relevant.Note
Adds state forking to
forc-node localvia--fork-url/--fork-block-number, fetching contract bytecode/state on demand and persisting locally, with tests, docs, and dependency updates.--fork-urland--fork-block-numberenable mirroring contract state from a remote node; lazily fetches contract bytecode/storage and caches in local DB.ForkingOnChainStorage/ForkClientand reconstructsCombinedDatabaseto overlay remote state; supports non-interactive mode for config updates.check_and_update_chain_configsupports non-interactive flows;block_on_any_runtimemade public for blocking async calls from sync contexts.fork,fork-caller) validating bytecode/state forking and transitive calls; updates EVM tests to newerrevmAPI.fuel-core*crates to gitmaster; bumpsrevmand enables features; aligns Cargo.toml/dev-deps accordingly.Written by Cursor Bugbot for commit d6c6bd9. This will update automatically on new commits. Configure here.