Skip to content

Conversation

@zees-dev
Copy link
Contributor

@zees-dev zees-dev commented Oct 31, 2025

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

  • Added fork_url and fork_block_number to forc-node local, enabling users to specify a remote node and block height for state forking (it must support historical execution).
  • Refactored local/mod.rs to support state forking by integrating a new fork module, 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

  • Updated Cargo.toml and forc-node/Cargo.toml to use patched versions of fuel-core crates from a specific branch
    • This was required as we need to override the datasource in the combined database; the datasource attributes are private; the fuel-core v0.46.0 patch simply updates the visibility of the relevant attributes so that they can be overriden to provide fork functionality
  • Made the block_on_any_runtime function in forc-pkg/src/source/reg/mod.rs public, allowing it to be used outside its original module
    • This is necessary for async operations in the new forking logic since the overriden trait function impls are not async

Testing and Examples

  • Added new test contracts and supporting files (fork and fork-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

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@zees-dev zees-dev force-pushed the feat/forc-node-local-state-forking branch from 6fef5a7 to 5593f9b Compare October 31, 2025 03:33
@zees-dev zees-dev self-assigned this Oct 31, 2025
@zees-dev zees-dev added enhancement New feature or request forc dev-experience Anything to do with the developer experience team:tooling Tooling Team forc-node Everything related to forc-node, bootstrapping a fuel-core node labels Oct 31, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Oct 31, 2025

CodSpeed Performance Report

Merging #7478 will not alter performance

Comparing feat/forc-node-local-state-forking (494fa90) with master (bfbe490)

Summary

✅ 25 untouched

@zees-dev zees-dev marked this pull request as ready for review October 31, 2025 05:35
@zees-dev zees-dev requested review from a team as code owners October 31, 2025 05:35

[[package]]
name = "std"
version = "0.69.1"
Copy link
Member

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

@JoshuaBatty
Copy link
Member

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.

@zees-dev zees-dev force-pushed the feat/forc-node-local-state-forking branch from 6a1d2a5 to 07eecf9 Compare November 3, 2025 02:11
@zees-dev zees-dev requested review from a team as code owners November 4, 2025 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dev-experience Anything to do with the developer experience enhancement New feature or request forc forc-node Everything related to forc-node, bootstrapping a fuel-core node team:tooling Tooling Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants