Skip to content

feat: add state persistence for LiteSVM#321

Draft
kc1116 wants to merge 1 commit intoLiteSVM:masterfrom
kc1116:kc1116/litesvm-state-persist
Draft

feat: add state persistence for LiteSVM#321
kc1116 wants to merge 1 commit intoLiteSVM:masterfrom
kc1116:kc1116/litesvm-state-persist

Conversation

@kc1116
Copy link
Copy Markdown

@kc1116 kc1116 commented Apr 14, 2026

Summary

  • Adds a litesvm-persistence crate that can save and restore full LiteSVM state to/from files or byte buffers using bincode serialization
  • Feature-gated persistence-internal on litesvm exposes internal getters/setters without polluting the public API
  • Two-pass account loading during restore avoids MissingAccount errors when upgradeable BPF programs are inserted before their ProgramData accounts
  • CRC32 checksums detect file/data corruption, atomic temp-file writes prevent corrupt snapshots on crash

Persisted state

Accounts, feature set, compute budget, fee structure (including compute_fee_bins), blockhash, airdrop keypair, sigverify/blockhash_check/log_bytes_limit settings, and transaction history with capacity.

Restore ordering

with_compute_budget() is called before with_builtins() so runtime environments are created with the correct budget. All accounts are bulk-inserted first (set_account_no_checks), then sysvar + program caches are rebuilt in a single rebuild_caches() pass.

Test plan

  • 21 round-trip tests covering: basic accounts, multiple accounts, sysvars, config flags, blockhash, airdrop keypair, transaction history, BPF program execution after restore, custom compute budget, custom fee structure, history capacity, bytes API, double round-trip, full default round-trip, error cases (nonexistent file, corrupted data), CRC32 checksum verification (bytes + file)
  • 2 doc-tests compile successfully
  • All existing litesvm tests still pass

🤖 Generated with Claude Code

Add a `litesvm-persistence` crate that can save and restore LiteSVM
state to/from files or byte buffers using bincode serialization.

Key design decisions:
- Feature-gated `persistence-internal` on litesvm exposes getters/setters
  without polluting the public API
- Two-pass account loading avoids MissingAccount errors when upgradeable
  programs are inserted before their ProgramData accounts
- Compute budget is set before builtins so runtime environments are
  created with the correct budget
- CRC32 checksums detect file corruption
- Atomic temp-file-then-rename prevents corrupt snapshots on crash

Persisted state includes: accounts, feature set, compute budget, fee
structure, blockhash, airdrop keypair, sigverify/blockhash_check/
log_bytes_limit settings, and transaction history with capacity.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant