Skip to content

feat: add litesvm-persistence crate for state snapshot save/load#319

Open
Rhovian wants to merge 2 commits intoLiteSVM:masterfrom
Rhovian:feat/state-persistence
Open

feat: add litesvm-persistence crate for state snapshot save/load#319
Rhovian wants to merge 2 commits intoLiteSVM:masterfrom
Rhovian:feat/state-persistence

Conversation

@Rhovian
Copy link
Copy Markdown

@Rhovian Rhovian commented Apr 9, 2026

Add the ability to save and restore LiteSVM state to/from disk, enabling hot-reload dev workflows, CI test fixture caching, and debugging.

  • New persistence-internal feature flag on core litesvm crate exposing getters, setters, and cache rebuild methods
  • New litesvm-persistence workspace crate with public API: save_to_file, load_from_file, to_bytes, from_bytes
  • Two-pass restoration: bulk insert accounts first, then rebuild sysvar cache and program cache to avoid ordering dependencies
  • Bincode serialization with version byte for forward compatibility
  • Serde remote derives for upstream types lacking serde (FeeStructure, ComputeBudget)
  • 16 roundtrip tests including BPF program execution after restore

One note on restore semantics: rebuild_caches() currently rebuilds the builtin runtime by calling set_builtins().

I think that is the right tradeoff for this PR, since the target workflow is persistence for standard LiteSVM::new() environments, where rebuilding builtins/runtime state is effectively idempotent.

The limitation is that restore is not intended to exactly preserve custom environments that mutate builtin accounts or intentionally strip builtins. Supporting that cleanly would likely require splitting runtime-environment rebuild from builtin-account insertion, which felt like too much scope for an otherwise additive persistence PR.

Happy to document this explicitly and leave stricter round-trip guarantees for custom builtin setups as a follow-up if desired.

Closes #303

Add the ability to save and restore LiteSVM state to/from disk, enabling
hot-reload dev workflows, CI test fixture caching, and debugging.

- New `persistence-internal` feature flag on core litesvm crate exposing
  getters, setters, and cache rebuild methods
- New `litesvm-persistence` workspace crate with public API:
  save_to_file, load_from_file, to_bytes, from_bytes
- Two-pass restoration: bulk insert accounts first, then rebuild sysvar
  cache and program cache to avoid ordering dependencies
- Bincode serialization with version byte for forward compatibility
- Serde remote derives for upstream types lacking serde (FeeStructure,
  ComputeBudget)
- 16 roundtrip tests including BPF program execution after restore

Closes LiteSVM#303
@Rhovian Rhovian force-pushed the feat/state-persistence branch from 69a91aa to f1784f5 Compare April 9, 2026 15:41
@Rhovian Rhovian marked this pull request as ready for review April 9, 2026 16:05
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.

Feature Request: State Persistence (save/load snapshots to disk)

1 participant