Skip to content

Conversation

@dimartiro
Copy link

Motivation

Add initial forking support by introducing a lazy-loading backend that retrieves state from the forked chain on demand.

Solution

Replace Substrate’s default backend with the new ForkedLazyBackend, which is composed of:

1. ForkedLazyBackend

  • Core backend implementing the sp_state_machine::Backend trait
  • Lazily fetches storage values from the forked network via RPC
  • Maintains an in-memory cache (db) of previously accessed state
  • Tracks removed keys to prevent unnecessary remote fetches

2. RPCClient

  • Abstraction layer for RPC communication with the forked network
  • Provides methods to fetch blocks, headers, storage values, storage hashes, and paginated keys

3. Blockchain

  • In-memory blockchain storage for cached blocks and headers
  • Lazily loads block data via RPC when not available locally
  • Maintains fork metadata (best block, finalized block, leaves)

4. RawIter

  • Custom storage iterator that merges local and remote state
  • Iterates over storage keys by checking the local cache first, then falling back to RPC
  • Respects prefix filters and removed keys during iteration

Note: Basic tests were also added to verify the lazy-loading behavior.


Closes: ChainSafe/gossamer-parity#59, ChainSafe/gossamer-parity#61, ChainSafe/gossamer-parity#62, ChainSafe/gossamer-parity#63, ChainSafe/gossamer-parity#65

@timwu20
Copy link

timwu20 commented Nov 4, 2025

Can you fix the CI checks?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants