FluffyLabs / FluffyLabs/typeberry
Fix state handling in STF: avoid shared mutable state singleton
- Dominant language
- TypeScript
- Stars
- 10
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
## Problem
Fix how state is being passed to STF. We currently assume the state object is internally mutated, so every STF holds it as readonly field. Now it's not true. Currently we use a hacky solution to replace a backend of the state.
## Current Implementation Issues
- The importer holds a single `SerializedState` instance as a readonly field
- Uses `updateBackend()` method to mutate the backend in place
- This creates risks of stale views if blocks are imported in parallel or forks occur
- Assumes blocks are imported strictly sequentially
- Assumes no other components hold references to the old backend
## Potential Solutions
1. Change the main OnChain STF and create smaller ones each time
2. Pass the state as input parameter instead of holding it as a readonly field
## Context
Related to the LMDB state storage implementation where state is now serialized rather than held in-memory.
## References
- PR: https://github.com/FluffyLabs/typeberry/pull/419
- Comment: https://github.com/FluffyLabs/typeberry/pull/419#discussion_r2137698677
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.