add_block deep-copies every account on every block

Open
#167 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@anshulchikhale30-p is already working on this.

Since Nov 10, 2026.

  • #174 by @anshulchikhale30-p — closed without merging
  • #181 by @anshulchikhale30-p — open

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
45/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Active
Tech stack
python

Research direction

Start with State.snapshot() in minichain/state.py and trace how Blockchain.add_block stores and uses snapshots during reorgs. The issue suggests recording only accounts changed in a block’s journal and rebuilding older states when needed. Done means snapshots avoid copying every account while preserving correct state after a reorg; the issue names no tests to run.

Written by the indexing model from the issue text.

Description

enhancement

Problem

Every time a block is added, Blockchain.add_block saves a snapshot of the state for reorgs, and State.snapshot() (minichain/state.py) does a copy.deepcopy of the whole accounts dict. So each block costs time proportional to the total number of accounts, even when the block only touches a few of them.

Measurements

Time for one empty block vs. the snapshot copy alone (best of 5):

Accounts One block Snapshot copy alone
1,000 2.7 ms 2.1 ms
10,000 34.5 ms 29.5 ms
50,000 194.4 ms 204.1 ms

The copy is most of the cost of a block and grows linearly with the number of accounts.

Impact

Fine at MiniChain's current scale, but block processing slows down as the number of accounts grows.

Possible direction

A block only changes the accounts in its journal, so a snapshot could record just those accounts instead of copying everything. Older states would then be rebuilt from those changes when a reorg needs them.

Dominant language
Python
Stars
12
Forks
27
Avg merge
2m
Merged PRs (30d)
1

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from StabilityNexus/MiniChain

All issues in StabilityNexus/MiniChain

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.