Commit 87c52b4
authored
refactor(specs): port state refactor to older forks (#2750)
* refactor(specs): apply state refactor to bpo forks
* refactor(specs): apply state refactor to post-merge forks
Apply the state tracker refactor (originally done for amsterdam) to the
remaining post-merge forks: osaka, prague, cancun, shanghai, and paris.
For each fork:
- Delete fork-specific state.py and trie.py
- Add fork-specific state_tracker.py with BlockState, TransactionState,
and the associated read/write helpers
- Update fork.py to wrap chain.state in a BlockState, thread
TransactionState through check_transaction / process_transaction /
system transactions / withdrawals, and apply the block diff via
apply_changes_to_state at the end of state_transition
- Update vm/__init__.py to use BlockState/TransactionState and import
Trie from ethereum.merkle_patricia_trie
- Update interpreter to use copy_tx_state/restore_tx_state in place of
begin/commit/rollback_transaction
- Update utils/message.py, vm/eoa_delegation.py, and vm/instructions/*
to read state via evm.message.tx_env.state
- Update blocks.py docstring cross-refs to the shared state / trie
modules
* refactor(specs): apply state refactor to pre-merge forks
Apply the state tracker refactor (originally done for amsterdam) to the
remaining pre-merge forks: gray_glacier, arrow_glacier, london, berlin,
muir_glacier, istanbul, constantinople, byzantium, spurious_dragon,
tangerine_whistle, dao_fork, homestead, and frontier.
For each fork:
- Delete fork-specific state.py and trie.py
- Add fork-specific state_tracker.py with BlockState, TransactionState,
and the associated read/write helpers
- Update fork.py to wrap chain.state in a BlockState, thread
TransactionState through check_transaction / process_transaction /
block-reward payout, and apply the block diff via
apply_changes_to_state at the end of state_transition
- Update vm/__init__.py to use BlockState/TransactionState and import
Trie from ethereum.merkle_patricia_trie
- Update interpreter to use copy_tx_state/restore_tx_state in place of
begin/commit/rollback_transaction
- Update utils/message.py and vm/instructions/* to read state via
evm.message.tx_env.state
- Update blocks.py docstring cross-refs to the shared state / trie
modules
For pre-merge forks, the state_tracker also exposes `create_ether`
(used for paying ommer/miner rewards) and the pre-EIP-161 forks have
`destroy_touched_empty_accounts` and `touch_account`. Pre-byzantium
receipts include an intermediate state root, computed by committing the
tx's writes to the block state and calling
`pre_state.compute_state_root_and_trie_changes` on the accumulated
block diff.
The DAO fork irregular state transition now creates a throwaway
BlockState/TransactionState, applies the moves, and flushes the diff
back to `chain.state`.
* fix(specs): track storage clears across pre-EIP-6780 destructions
Pre-EIP-6780 ``SELFDESTRUCT`` fully wipes an account's storage, and a
later ``CREATE2`` at the same address must start from empty storage.
After the state refactor, ``destroy_storage`` only removed tx-level
writes, so reads still fell through to the pre_state's storage trie —
``CREATE2`` then saw ``account_has_storage`` return True and bailed
without bumping the nonce.
Track wiped addresses in a new ``storage_clears`` set on ``BlockState``,
``TransactionState``, and ``BlockDiff``. Reads short-circuit on it, and
``compute_state_root_and_trie_changes`` / ``apply_changes_to_state``
drop the corresponding storage tries before re-applying writes, so
post-wipe writes begin from empty storage.
Applies to Frontier through Shanghai; post-6780 forks leave the set
empty.
* refactor(evm_tools): wire t8n through ForkLoad accessors
The t8n tool kept a mix of direct imports from ``amsterdam`` and raw
``_module(...)`` lookups into each fork's ``state_tracker`` and
``block_access_lists`` modules, and ``ForkLoad`` still carried fallback
shims for helpers (``State``, ``set_account``, ``copy_trie``, ``root``,
etc.) that now live exclusively in the shared ``ethereum.state`` and
``ethereum.merkle_patricia_trie`` modules.
Collapse all three:
* Drop the fork-independent shims from ``ForkLoad`` and import the
helpers directly at the t8n / fixture-loader call sites.
* Expose ``BlockState``, ``TransactionState``, ``extract_block_diff``,
``incorporate_tx_into_block``, ``BlockAccessIndex``,
``BlockAccessListBuilder``, and ``validate_block_access_list_gas_limit``
as ``ForkLoad`` properties so t8n never has to hardcode ``amsterdam``
or reach into ``_module``.
* Fix ``pay_block_rewards`` to wrap ``BlockState`` in a
``TransactionState`` via the fork's own state_tracker (the previous
code passed the block-scoped state straight to ``create_ether``,
which expects the tx-scoped wrapper).
* Remove the now-dead ``has_block_state`` feature flag and its
fallback branches — every fork has a ``state_tracker`` module.
* chore(tests): adjust json_loader tests for the state refactor
Point the json_loader tests at the shared ``ethereum.state`` and
``ethereum.merkle_patricia_trie`` modules now that per-fork ``state``
and ``trie`` modules no longer exist, and switch to the State-method
accessors (``state.get_storage(...)`` etc.) instead of the old
module-level functions.
Skip ``test_optimized_state`` wholesale: the optimized state integration
still imports per-fork ``state`` modules and exposes a pre-refactor
``destroy_storage(state, addr)`` API, both removed by the refactor.
Tracked by #2256
pending the optimized state redesign.
Extend ``vulture_whitelist.py`` to cover the ``@add_item``-registered
``begin_transaction`` / ``commit_transaction`` / ``rollback_transaction``
patches in ``ethereum_optimized.state_db``.
* refactor(specs): drop fork_types re-exports of shared state types
The state refactor initially re-imported ``Account``, ``Address``,
``EMPTY_ACCOUNT``, and ``EMPTY_CODE_HASH`` from ``ethereum.state`` into
each pre-merge fork's ``fork_types.py`` (plus a matching ``__all__``)
so existing call sites like ``from .fork_types import Address`` could
stay untouched. ``Root`` was similarly duplicated as ``Root = Hash32``
in every fork.
``docc`` does not follow ``__all__`` re-exports when resolving
cross-references, which breaks ``just docs-spec`` on the first consumer
that imports ``EMPTY_ACCOUNT`` through a fork's ``fork_types``.
Drop the re-exports from all 13 pre-merge forks and import the shared
symbols directly from ``ethereum.state`` at every call site — matching
the shape that shanghai / paris already use. Each ``fork_types.py``
collapses to ``Bloom``, ``encode_account``, and the ``Account`` type
import that ``encode_account`` needs.
Also update ``tests/json_loader/test_optimized_state.py`` to import
``EMPTY_ACCOUNT`` from ``ethereum.state`` rather than through the
dropped ``frontier.fork_types`` re-export.
* refactor(specs): address PR #2750 review feedback
Apply review suggestions from @SamWilsn:
* ``ethereum.state.BlockDiff.storage_clears`` docstring switches to
markdown style with a cross-ref to ``storage_changes``, so docc
renders the link.
* In every fork's ``state_tracker.get_account``, replace the
``isinstance(account, Account)`` guard with an explicit
``if account is None`` check. The ``isinstance`` was a leftover from
when ``fork_types.Account`` was a separate class; now that every
fork pulls ``Account`` directly from ``ethereum.state``, the
``is None`` form expresses the intent ("is there an account?")
rather than the implementation ("is this an account?").
* Reintroduce the ``create_ether`` helper in every post-merge fork's
state tracker (paris through bpo5). It was dropped during the
post-merge state refactor because the PoS forks no longer
``pay_rewards`` to a miner, but it remains the natural helper for
``process_withdrawals``. Updates the withdrawal call sites in
shanghai onwards (paris itself has no caller; ``create_ether`` is
added there purely to keep sibling parity with london and shanghai).
Also relocate ``create_ether`` in every pre-merge fork from its
legacy spot in the trailing "Pre-EIP-161 cleanup" section to
immediately after ``move_ether`` — they are structurally the same
kind of balance mutator, and the new placement is consistent
across every fork.
* Rewrite the ``untracked_state`` comment in
``process_checked_system_transaction`` (prague through bpo5) to
make the throwaway-scope and "always calls
process_unchecked_system_transaction below" contracts explicit.1 parent 44923d4 commit 87c52b4
320 files changed
Lines changed: 21976 additions & 30466 deletions
File tree
- src
- ethereum_spec_tools/evm_tools
- loaders
- t8n
- ethereum
- forks
- amsterdam
- arrow_glacier
- utils
- vm
- instructions
- berlin
- utils
- vm
- instructions
- bpo1
- utils
- vm
- instructions
- bpo2
- utils
- vm
- instructions
- bpo3
- utils
- vm
- instructions
- bpo4
- utils
- vm
- instructions
- bpo5
- utils
- vm
- instructions
- byzantium
- utils
- vm
- instructions
- cancun
- utils
- vm
- instructions
- constantinople
- utils
- vm
- instructions
- dao_fork
- utils
- vm
- instructions
- frontier
- utils
- vm
- instructions
- gray_glacier
- utils
- vm
- instructions
- homestead
- utils
- vm
- instructions
- istanbul
- utils
- vm
- instructions
- london
- utils
- vm
- instructions
- muir_glacier
- utils
- vm
- instructions
- osaka
- utils
- vm
- instructions
- paris
- utils
- vm
- instructions
- prague
- utils
- vm
- instructions
- shanghai
- utils
- vm
- instructions
- spurious_dragon
- utils
- vm
- instructions
- tangerine_whistle
- utils
- vm
- instructions
- tests/json_loader
- helpers
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
| |||
696 | 697 | | |
697 | 698 | | |
698 | 699 | | |
699 | | - | |
700 | | - | |
701 | | - | |
702 | | - | |
703 | | - | |
704 | | - | |
705 | | - | |
706 | | - | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
707 | 708 | | |
708 | 709 | | |
709 | 710 | | |
| |||
1108 | 1109 | | |
1109 | 1110 | | |
1110 | 1111 | | |
1111 | | - | |
1112 | | - | |
1113 | | - | |
| 1112 | + | |
1114 | 1113 | | |
1115 | 1114 | | |
1116 | 1115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
143 | | - | |
144 | | - | |
145 | | - | |
| 143 | + | |
146 | 144 | | |
| 145 | + | |
| 146 | + | |
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| |||
568 | 568 | | |
569 | 569 | | |
570 | 570 | | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
571 | 594 | | |
572 | 595 | | |
573 | 596 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | | - | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
72 | | - | |
73 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
74 | 76 | | |
75 | 77 | | |
76 | | - | |
77 | | - | |
78 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
| |||
85 | 87 | | |
86 | 88 | | |
87 | 89 | | |
88 | | - | |
89 | | - | |
| 90 | + | |
| 91 | + | |
90 | 92 | | |
91 | 93 | | |
92 | 94 | | |
| |||
96 | 98 | | |
97 | 99 | | |
98 | 100 | | |
99 | | - | |
100 | | - | |
| 101 | + | |
| 102 | + | |
101 | 103 | | |
102 | 104 | | |
103 | 105 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
31 | 38 | | |
32 | 39 | | |
33 | 40 | | |
| |||
36 | 43 | | |
37 | 44 | | |
38 | 45 | | |
39 | | - | |
40 | | - | |
41 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
42 | 49 | | |
43 | 50 | | |
44 | 51 | | |
45 | 52 | | |
| 53 | + | |
46 | 54 | | |
| 55 | + | |
47 | 56 | | |
48 | 57 | | |
49 | | - | |
50 | 58 | | |
51 | 59 | | |
52 | 60 | | |
| |||
59 | 67 | | |
60 | 68 | | |
61 | 69 | | |
62 | | - | |
63 | 70 | | |
64 | 71 | | |
65 | 72 | | |
| |||
174 | 181 | | |
175 | 182 | | |
176 | 183 | | |
| 184 | + | |
| 185 | + | |
177 | 186 | | |
178 | 187 | | |
179 | | - | |
| 188 | + | |
180 | 189 | | |
181 | 190 | | |
182 | 191 | | |
| |||
191 | 200 | | |
192 | 201 | | |
193 | 202 | | |
194 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
195 | 209 | | |
196 | 210 | | |
197 | 211 | | |
| |||
209 | 223 | | |
210 | 224 | | |
211 | 225 | | |
| 226 | + | |
212 | 227 | | |
213 | 228 | | |
214 | 229 | | |
| |||
430 | 445 | | |
431 | 446 | | |
432 | 447 | | |
| 448 | + | |
433 | 449 | | |
434 | 450 | | |
435 | 451 | | |
| |||
442 | 458 | | |
443 | 459 | | |
444 | 460 | | |
| 461 | + | |
| 462 | + | |
445 | 463 | | |
446 | 464 | | |
447 | 465 | | |
| |||
472 | 490 | | |
473 | 491 | | |
474 | 492 | | |
475 | | - | |
| 493 | + | |
476 | 494 | | |
477 | 495 | | |
478 | 496 | | |
| |||
581 | 599 | | |
582 | 600 | | |
583 | 601 | | |
584 | | - | |
| 602 | + | |
585 | 603 | | |
586 | 604 | | |
587 | 605 | | |
| |||
663 | 681 | | |
664 | 682 | | |
665 | 683 | | |
666 | | - | |
667 | | - | |
668 | | - | |
| 684 | + | |
669 | 685 | | |
670 | 686 | | |
671 | 687 | | |
| |||
684 | 700 | | |
685 | 701 | | |
686 | 702 | | |
687 | | - | |
688 | | - | |
689 | | - | |
690 | | - | |
691 | | - | |
692 | | - | |
| 703 | + | |
| 704 | + | |
693 | 705 | | |
694 | 706 | | |
695 | 707 | | |
696 | 708 | | |
| 709 | + | |
697 | 710 | | |
698 | 711 | | |
699 | | - | |
| 712 | + | |
700 | 713 | | |
701 | 714 | | |
702 | 715 | | |
703 | | - | |
| 716 | + | |
704 | 717 | | |
705 | | - | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
706 | 721 | | |
707 | 722 | | |
708 | 723 | | |
| |||
735 | 750 | | |
736 | 751 | | |
737 | 752 | | |
| 753 | + | |
| 754 | + | |
738 | 755 | | |
739 | 756 | | |
740 | 757 | | |
| |||
750 | 767 | | |
751 | 768 | | |
752 | 769 | | |
| 770 | + | |
753 | 771 | | |
754 | 772 | | |
755 | | - | |
| 773 | + | |
756 | 774 | | |
757 | 775 | | |
758 | 776 | | |
759 | 777 | | |
760 | | - | |
| 778 | + | |
761 | 779 | | |
762 | 780 | | |
763 | 781 | | |
764 | 782 | | |
765 | | - | |
766 | | - | |
767 | | - | |
| 783 | + | |
768 | 784 | | |
769 | 785 | | |
770 | 786 | | |
| |||
780 | 796 | | |
781 | 797 | | |
782 | 798 | | |
| 799 | + | |
783 | 800 | | |
784 | 801 | | |
785 | 802 | | |
| |||
801 | 818 | | |
802 | 819 | | |
803 | 820 | | |
804 | | - | |
805 | | - | |
806 | | - | |
807 | | - | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
808 | 825 | | |
809 | 826 | | |
810 | 827 | | |
811 | | - | |
| 828 | + | |
812 | 829 | | |
813 | 830 | | |
814 | 831 | | |
815 | | - | |
| 832 | + | |
816 | 833 | | |
817 | 834 | | |
818 | 835 | | |
819 | | - | |
820 | | - | |
| 836 | + | |
| 837 | + | |
821 | 838 | | |
822 | 839 | | |
823 | | - | |
| 840 | + | |
824 | 841 | | |
825 | | - | |
| 842 | + | |
826 | 843 | | |
827 | 844 | | |
828 | 845 | | |
| |||
841 | 858 | | |
842 | 859 | | |
843 | 860 | | |
| 861 | + | |
| 862 | + | |
844 | 863 | | |
845 | 864 | | |
846 | 865 | | |
| |||
0 commit comments