chore(trie): Make trie Fork agnostic#2267
chore(trie): Make trie Fork agnostic#2267kevaundray wants to merge 13 commits intoethereum:forks/amsterdamfrom
trie Fork agnostic#2267Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## forks/amsterdam #2267 +/- ##
===================================================
+ Coverage 86.00% 88.91% +2.91%
===================================================
Files 600 536 -64
Lines 39357 32516 -6841
Branches 3770 2797 -973
===================================================
- Hits 33850 28913 -4937
+ Misses 4877 3022 -1855
+ Partials 630 581 -49
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
3dd17e4 to
3f12fc9
Compare
|
The issue with We now import from |
| with (fork_dir / "trie.py").open("r") as f: | ||
| assert ( | ||
| "from ethereum.forks.paris import trie as previous_trie" | ||
| in f.read() | ||
| ) |
There was a problem hiding this comment.
trie.py is no longer fork dependent, so I removed this check in new-fork tool
| @@ -322,18 +322,18 @@ def create_ether(self) -> Any: | |||
|
|
|||
| @property | |||
| def root(self) -> Any: | |||
| """Root function of the fork.""" | |||
| return self._module("trie").root | |||
| """Root function.""" | |||
| return trie_root | |||
|
|
|||
| @property | |||
| def copy_trie(self) -> Any: | |||
| """copy_trie function of the fork.""" | |||
| return self._module("trie").copy_trie | |||
| """copy_trie function.""" | |||
| return copy_trie | |||
|
|
|||
| @property | |||
| def trie_get(self) -> Any: | |||
| """trie_get function of the fork.""" | |||
| return self._module("trie").trie_get | |||
| """trie_get function.""" | |||
| return trie_get | |||
There was a problem hiding this comment.
These are no longer dependent on the fork, left them here to not increase the diff further in this PR.
trie Fork agnostic
|
I think the rough shape of this is now visible, so would say the experiment is done. CC @SamWilsn and @gurukamath for input when you get back next week. Kind of a PITA that it touches so many files, but this was somewhat inevitable |
cde3285 to
9a6bf98
Compare
9a6bf98 to
93ccb50
Compare
gurukamath
left a comment
There was a problem hiding this comment.
Largely looks good to me. Thanks for taking this on :). Just left a couple of smaller comments.
| return keccak256(encoded) | ||
|
|
||
|
|
||
| def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes: |
There was a problem hiding this comment.
| def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes: | |
| def encode_node(node: Optional[Extended], storage_root: Optional[Bytes] = None) -> Bytes: |
And then handle the None case explicitly in the function body to raise the relevant AssertionError. The V typevar also becomes V = TypeVar("V", bound=Optional[Extended]) in that case.
For context, we do use the broad Any type in some tooling related code but try to avoid it in the specs code itself.
There was a problem hiding this comment.
This is more just a comment from a quick fly-by. @gurukamath any reason to not use Extended | None instead of importing Optional just to use Optional[Extended]? It seems to be the preferred usage for Python >= 3.10. Of course, we can make our own decisions on that, but just curious.
| V = TypeVar("V") | ||
|
|
||
|
|
||
| def encode_account(raw_account_data: Account, storage_root: Bytes) -> Bytes: |
There was a problem hiding this comment.
Perhaps, this belongs in ethereum.state since that is also where we have defined Account
…agnostic-trie # Conflicts: # src/ethereum/forks/amsterdam/fork.py # src/ethereum/forks/amsterdam/fork_types.py # src/ethereum/forks/amsterdam/state.py
SamWilsn
left a comment
There was a problem hiding this comment.
This makes sense. I guess maybe it might be reasonable to rename it to mp_trie.py eventually if we need to differentiate between trie implementations.
My internal reasoning for accepting this hoist is that the diffs between the MP trie and any other trie would be extremely messy and not particularly useful.
|
|
||
|
|
||
| def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes: | ||
| def encode_node(node: Any, storage_root: Optional[Bytes] = None) -> Bytes: |
|
|
||
| Address = Bytes20 | ||
| Root = Hash32 | ||
| Account_ = Any # noqa N806 |
There was a problem hiding this comment.
If there's only one Account now, I don't think we need this Any any longer.
| ) | ||
| state_mod = cast(Any, import_module("ethereum.forks." + fork + ".state")) | ||
| Account = types_mod.Account # noqa N806 | ||
| Account = Account_cls # noqa: N806 |
There was a problem hiding this comment.
What is the purpose of this line?
|
I think this is semi-blocked on backporting We could have each fork define an |
|
superceded by #2381 |
🗒️ Description
Bullet point 3 from #2207
This makes the
Triedata structure and its methods fork agnostic.There were some tox related errors that were surfacing due to
Accountnot being fork agnostic for forks pre-Amsterdam. I've changed those imports for Account to point to the one defined inethereum.statefor simplicity (this is what I imagine the endgame solution tends towards, given the issue on making Account fork agnostic)🔗 Related Issues or PRs
#2293
Related to #2154 -- we could also pull out Account in a separate PR
✅ Checklist
toxchecks to avoid unnecessary CI fails, see also Code Standards and Enabling Pre-commit Checks:uvx tox -e statictype(scope):.mkdocs servelocally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.@ported_frommarker.Cute Animal Picture