Skip to content

Perf/incremental state snapshots - #181

Draft
anshulchikhale30-p wants to merge 2 commits into
StabilityNexus:mainfrom
anshulchikhale30-p:perf/incremental-state-snapshots
Draft

anshulchikhale30-p wants to merge 2 commits into
StabilityNexus:mainfrom
anshulchikhale30-p:perf/incremental-state-snapshots

Conversation

@anshulchikhale30-p

@anshulchikhale30-p anshulchikhale30-p commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Addressed Issues: add_block deep-copies every account on every block

Fixes #167

Screenshots/Recordings:

TODO: If applicable, add screenshots or recordings that demonstrate the interface before and after the changes.

Additional Notes:

AI Usage Disclosure:

We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact. AI slop is strongly discouraged and may lead to banning and blocking. Do not spam our repos with AI slop.

Check one of the checkboxes below:

  • This PR does not contain AI-generated code at all.
  • This PR contains AI-generated code. I have read the AI Usage Policy and this PR complies with this policy. I have tested the code locally and I am responsible for it.

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.
  • My code follows the project's code style and conventions
  • If applicable, I have made corresponding changes or additions to the documentation
  • If applicable, I have made corresponding changes or additions to tests
  • My changes generate no new warnings or errors
  • I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • I have read the Contribution Guidelines
  • Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.
  • I have filled this PR template completely and carefully, and I understand that my PR may be closed without review otherwise.

Summary by CodeRabbit

  • New Features
    • Added immutable state snapshots that preserve account data across updates and restores.
    • Made StateSnapshot available through the package’s public interface.
    • Snapshots reuse unchanged state and record account additions, updates, and deletions, while remaining independent of later changes.
    • Restored state is now available through tracked account data, and snapshots created from copied journals remain self-contained.

@coderabbitai

coderabbitai Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

Copy link
Copy Markdown

Coverage

Coverage Report
FileStmtsMissCoverMissing
minichain
   __init__.py100100% 
   block.py92199%14
   chain.py2273983%182–185, 195–196, 205–206, 209–210, 214–215, 234, 258, 266–274, 283–284, 286–287, 310–313, 316–325, 335–336
   contract.py1713281%39–42, 74–84, 89–93, 105–112, 218–220, 240–241
   identity.py240100% 
   mempool.py65395%32–34, 56
   mpt.py140100% 
   network_config.py100100% 
   node_config.py110100% 
   p2p.py36923437%89, 92, 98, 125–143, 146–147, 150–151, 164–170, 198, 206–208, 211, 214, 221–222, 226–227, 256–257, 271–277, 290, 300, 304–306, 333–334, 347–365, 373–391, 401–417, 422–606
   persistence.py1950100% 
   pow.py430100% 
   receipt.py140100% 
   rpc.py82199%91
   serialization.py80100% 
   state.py3442294%66, 75, 78, 81, 115–117, 120–126, 129–131, 134–135, 146–147, 352
   transaction.py590100% 
   validators.py90100% 
TOTAL174733281% 
Tests Skipped Failures Errors Time
237 0 💤 0 ❌ 0 🔥 7.878s ⏱️

@anshulchikhale30-p

Copy link
Copy Markdown
Contributor Author

Hi @SIDDHANTCOOKIE ,
I’ve implemented the fix for issue #167
What changed:

  • State.snapshot() no longer deep-copies the entire accounts dictionary on every block.
  • Snapshots now store only the accounts changed since the previous snapshot, using a new delta-based StateSnapshot.
  • Added an AccountStore that tracks dirty and deleted accounts, including in-place account mutations.
  • Older states are rebuilt by replaying snapshot deltas when a reorg needs them.
  • Added periodic snapshot compaction so the delta history stays bounded instead of growing indefinitely.
  • Genesis now reuses a single snapshot instead of taking the same full copy twice.
  • Added tests covering delta snapshots, restoring older states, account deletions, journal snapshots, and snapshot reuse.

Verification:

  • All 237 tests pass.
test_results
  • In a local 50k-account benchmark, steady-state snapshot time dropped from roughly 187 ms for a full deep copy to about 0.005 ms per block snapshot.

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.

add_block deep-copies every account on every block

1 participant