Skip to content

Use Union[None, T] instead of Optional[T] in SSZ datastructures - #5200

Closed
ericsson49 wants to merge 1 commit into
ethereum:masterfrom
ericsson49:fix-gloas-ssz-optional
Closed

Use Union[None, T] instead of Optional[T] in SSZ datastructures#5200
ericsson49 wants to merge 1 commit into
ethereum:masterfrom
ericsson49:fix-gloas-ssz-optional

Conversation

@ericsson49

Copy link
Copy Markdown
Contributor

Recent PR #5180 introduced Vector[Optional[boolean], PTC_SIZE]] in gloas fork-choice.md.

However, Optional is not supported as SSZ type, which breaks the generated gloas spec, e.g.

% uv run python -c "from eth_consensus_specs.test import context"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/alexvlasov/Work/GitHub/consensus-specs/tests/core/pyspec/eth_consensus_specs/test/context.py", line 35, in <module>
    from .helpers.specs import (
  File "/Users/alexvlasov/Work/GitHub/consensus-specs/tests/core/pyspec/eth_consensus_specs/test/helpers/specs.py", line 16, in <module>
    exec(
  File "<string>", line 1, in <module>
  File "/Users/alexvlasov/Work/GitHub/consensus-specs/tests/core/pyspec/eth_consensus_specs/gloas/__init__.py", line 1, in <module>
    from . import mainnet as spec  # noqa:F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alexvlasov/Work/GitHub/consensus-specs/tests/core/pyspec/eth_consensus_specs/gloas/mainnet.py", line 1248, in <module>
    class Store(object):
  File "/Users/alexvlasov/Work/GitHub/consensus-specs/tests/core/pyspec/eth_consensus_specs/gloas/mainnet.py", line 1268, in Store
    payload_timeliness_vote: Dict[Root, Vector[Optional[boolean], PTC_SIZE]] = field(
                                        ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alexvlasov/Work/GitHub/consensus-specs/.venv/lib/python3.11/site-packages/remerkleable/complex.py", line 605, in __class_getitem__
    if element_view_cls.is_fixed_byte_length():
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.12_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/typing.py", line 1317, in __getattr__
    return getattr(self.__origin__, attr)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.12_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/typing.py", line 474, in __getattr__
    raise AttributeError(item)
AttributeError: is_fixed_byte_length

The PR fixes this by using Vector[Union[None, boolean], PTC_SIZE] instead.

Related to #5180

@github-actions github-actions Bot added the gloas label Apr 30, 2026
@jtraglia

Copy link
Copy Markdown
Member

So SSZ unions are not actually used anywhere in the specs and we were debating whether or not we should remove them (#3906). Also, implementers of this would probably just use non-SSZ types here. Let me look into if switching away from SSZ types here, for this particular field. If it's not trivial, we can merge this PR and deal with it later.

payloads: Dict[Root, ExecutionPayloadEnvelope] = field(default_factory=dict)
# [New in Gloas:EIP7732]
payload_timeliness_vote: Dict[Root, Vector[Optional[boolean], PTC_SIZE]] = field(
payload_timeliness_vote: Dict[Root, Vector[Union[None, boolean], PTC_SIZE]] = field(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Store is not an SSZ container, what's the problem with optional?
If Optional is problematic, this should be PyUnion, not SSZ Union.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem was that it was used inside Vector which is an SSZ type. We shouldn't have been using Vector here in the first place. I should have caught this earlier. I made #5208 to fix this.

jtraglia added a commit that referenced this pull request May 5, 2026
So we shouldn't have been using `Vector` (an SSZ type) for these.
`Store` can use native types for lists, sets, dictionaries, etc. We
can/should use SSZ types for the entries though. This PR is an
alternative to #5200.
@jtraglia

jtraglia commented May 5, 2026

Copy link
Copy Markdown
Member

Closing this in favor of #5208.

@jtraglia jtraglia closed this May 5, 2026
@ericsson49
ericsson49 deleted the fix-gloas-ssz-optional branch May 6, 2026 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants