Skip to content

dev: change type of branch node subnodes#1066

Merged
SamWilsn merged 10 commits intoethereum:masterfrom
kkrt-labs:dev/change-type-branch-nodes
Jan 25, 2025
Merged

dev: change type of branch node subnodes#1066
SamWilsn merged 10 commits intoethereum:masterfrom
kkrt-labs:dev/change-type-branch-nodes

Conversation

@enitrat
Copy link
Contributor

@enitrat enitrat commented Dec 20, 2024

What was wrong?

The type for the BranchNode's subnodes was List[rlp.Extended]. While this is not inherently wrong, a more suitable type would be a tuple with 16 rlp.Extended elements, each representing a BranchNode of the trie, as there's no intent to mutate the subnodes after instantiation.

Related to Issue #

How was it fixed?

Changed to Annotated[Tuple[rlp.Extended, ...], 16]. Also open to just repeating 16 times the rlp.Extended argument, but using an annotation sounds more convenient rather than repeating. The annotation conveys at type hint that the tuple is of size 16.

Cute Animal Picture

Our beloved moodeng friend
Put a link to a cute animal picture inside the parenthesis-->

@enitrat enitrat force-pushed the dev/change-type-branch-nodes branch from bcef93c to 2a3b61a Compare December 30, 2024 09:25
@SamWilsn
Copy link
Contributor

Does the annotation get enforced? If not, I'd prefer the tuple with 16 elements, probably as a proper type or type alias.

@enitrat
Copy link
Contributor Author

enitrat commented Dec 30, 2024

The Annotation is not enforced. It's only a "hint" for the reader that it expects 16 elements. We could create a proper type that

Perhaps something like:

BranchSubnodes = Tuple[rlp.Extended, rlp.Extended, rlp.Extended, rlp.Extended,
                      rlp.Extended, rlp.Extended, rlp.Extended, rlp.Extended,
                      rlp.Extended, rlp.Extended, rlp.Extended, rlp.Extended,
                      rlp.Extended, rlp.Extended, rlp.Extended, rlp.Extended]


@slotted_freezable
@dataclass
class BranchNode:
    """Branch node in the Merkle Trie"""

    subnodes: BranchSubnodes
    value: rlp.Extended

@SamWilsn
Copy link
Contributor

Kinda ugly, but I don't see a shorter way of making the type annotation meaningful to mypy. Let's go with the sixteen rlp.Extended type alias 🤣

@enitrat
Copy link
Contributor Author

enitrat commented Dec 30, 2024

done :)

@enitrat
Copy link
Contributor Author

enitrat commented Jan 4, 2025

Hi @SamWilsn, any chance you can help me understand why CI is failing ?

@SamWilsn
Copy link
Contributor

SamWilsn commented Jan 7, 2025

Re-ran it and it seems to be passing now. The error wasn't something I've ever seen before, so I'm hoping it's just something weird on our github runner.

@SamWilsn
Copy link
Contributor

I think avoiding the cast here hurts readability, so here's my proposal: kkrt-labs#1

@enitrat
Copy link
Contributor Author

enitrat commented Jan 21, 2025

merged it @SamWilsn :)

@SamWilsn
Copy link
Contributor

This passed for me. I'll dig into this a bit. I bet it's something to do with my local Python version.

@SamWilsn
Copy link
Contributor

Fixed: kkrt-labs#2

@SamWilsn SamWilsn merged commit 26ab1bc into ethereum:master Jan 25, 2025
5 checks passed
SamWilsn added a commit to SamWilsn/eth1.0-specs that referenced this pull request Jan 25, 2025
SamWilsn added a commit to SamWilsn/eth1.0-specs that referenced this pull request Jan 27, 2025
SamWilsn added a commit to SamWilsn/eth1.0-specs that referenced this pull request Mar 5, 2025
* dev: change type of branch node subnodes

* Annotate tuple with 16

* add ellipsis to tuple

* explicit tuple

* use explicit 16-field tuple

* fmt

* remove Annotated import

* fix types

* Use assert_type alongside cast (#1)

* Import from typing_extensions instead of typing (#2)

---------

Co-authored-by: Sam Wilson <57262657+SamWilsn@users.noreply.github.com>
Shashwat-Nautiyal pushed a commit to Shashwat-Nautiyal/execution-specs that referenced this pull request Mar 17, 2025
* dev: change type of branch node subnodes

* Annotate tuple with 16

* add ellipsis to tuple

* explicit tuple

* use explicit 16-field tuple

* fmt

* remove Annotated import

* fix types

* Use assert_type alongside cast (ethereum#1)

* Import from typing_extensions instead of typing (ethereum#2)

---------

Co-authored-by: Sam Wilson <57262657+SamWilsn@users.noreply.github.com>
Shashwat-Nautiyal pushed a commit to Shashwat-Nautiyal/execution-specs that referenced this pull request Mar 20, 2025
* dev: change type of branch node subnodes

* Annotate tuple with 16

* add ellipsis to tuple

* explicit tuple

* use explicit 16-field tuple

* fmt

* remove Annotated import

* fix types

* Use assert_type alongside cast (ethereum#1)

* Import from typing_extensions instead of typing (ethereum#2)

---------

Co-authored-by: Sam Wilson <57262657+SamWilsn@users.noreply.github.com>
fselmo pushed a commit to fselmo/execution-specs that referenced this pull request Apr 9, 2025
SamWilsn added a commit to SamWilsn/eth1.0-specs that referenced this pull request Apr 11, 2025
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.

3 participants

Comments