Commit 610d538
authored
refactor(specs): make
* refactor(spec): make Trie fork-agnostic for amsterdam
Move all trie logic to a shared `src/ethereum/trie.py`, removing the
fork-specific `src/ethereum/forks/amsterdam/trie.py`. Also move trie
internal node types (LeafNode, ExtensionNode, BranchNode, InternalNode)
from `ethereum.state` into `ethereum.trie`, and trim `ethereum.state`
to just account types and the PreState protocol.
- New `ethereum/trie.py`: Trie, trie_set/get/copy, root, patricialize,
encode_node/account/internal_node, EMPTY_TRIE_ROOT, and node types
- `ethereum/state.py`: remove trie node types; import InternalNode from
ethereum.trie under TYPE_CHECKING to break the runtime cycle
- `amsterdam/trie.py`: deleted; consumers updated to import directly
from ethereum.trie
- `fork_loader.py`: fall back to ethereum.trie when a fork has no
fork-specific trie module
* refactor(spec): make State fork-agnostic for amsterdam
Move the `State` class and all state helper functions from
`ethereum/forks/amsterdam/state.py` into the shared `ethereum/state.py`,
making the state implementation fork-agnostic for amsterdam.
To break the circular import that would arise between `state.py` and
`trie.py`, introduce `ethereum/types.py` as a thin module holding the
base account types (`Account`, `Address`, `Root`, `EMPTY_CODE_HASH`,
`EMPTY_ACCOUNT`). `trie.py` now imports from `types.py`, allowing
`state.py` to import from both `types.py` and `trie.py` without a cycle.
`ethereum/state.py` re-exports the base types so that the ~260 existing
`from ethereum.state import ...` call sites across all forks require no
changes.
`fork_loader.py` and `t8n_types.py` are updated to fall back to the
shared `ethereum.state` module when the fork-specific `state` module no
longer exists.
* refactor(tests): fall back to ethereum.state in VmTestLoader
Add `_state_module()` helper to `VmTestLoader` that tries the
fork-specific state module first and falls back to the shared
`ethereum.state` when the fork no longer ships its own
`state.py` (e.g. after the fork-agnostic-state refactor).
TODO: remove the fallback once the state module is ported over
to the older forks.
* fix(tests): fix other json_infra tests
* fix(docs): fix docs references
* refactor(spec): address review feedback on encode_node
Add a note explaining why `EMPTY_TRIE_ROOT` uses `Hash32` rather than
`Root` (circular import), unify the `storage_root` annotation on
`encode_node` to use `Bytes | None` for consistency with the `node`
parameter, and tighten `encode_node`'s `node` parameter to `Extended`
(non-nullable) now that `_prepare_trie` narrows `value` away from
`None` before calling in.State fork agnostic (#2381)1 parent 49b882e commit 610d538
12 files changed
Lines changed: 434 additions & 359 deletions
File tree
- src
- ethereum_spec_tools/evm_tools
- loaders
- t8n
- ethereum
- forks/amsterdam
- vm
- tests/json_loader
- helpers
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | | - | |
116 | | - | |
| 115 | + | |
| 116 | + | |
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | | - | |
128 | | - | |
| 127 | + | |
| 128 | + | |
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
138 | | - | |
139 | | - | |
| 138 | + | |
| 139 | + | |
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
33 | 40 | | |
34 | 41 | | |
35 | 42 | | |
| |||
60 | 67 | | |
61 | 68 | | |
62 | 69 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | 70 | | |
68 | 71 | | |
69 | 72 | | |
| |||
89 | 92 | | |
90 | 93 | | |
91 | 94 | | |
92 | | - | |
93 | 95 | | |
94 | 96 | | |
95 | 97 | | |
| |||
263 | 265 | | |
264 | 266 | | |
265 | 267 | | |
266 | | - | |
| 268 | + | |
267 | 269 | | |
268 | 270 | | |
269 | 271 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
41 | | - | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
30 | | - | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
0 commit comments