Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional [ list [ Optional [ Data Structures ] ] ] #19157

Open
buggybuck opened this issue Jan 16, 2025 · 3 comments
Open

Optional [ list [ Optional [ Data Structures ] ] ] #19157

buggybuck opened this issue Jan 16, 2025 · 3 comments
Assignees

Comments

@buggybuck
Copy link

Hi there!

I'm trying to deserialize this twisted little line here [1]:

message_data: Optional[list[Optional[SignatureRequestSourceData]]]

Does it mean that if there is a list (1st Optional) then the list will always contain at least one element? Either 0x00 if the SignatureRequestSourceData item isn't present or 0x01 plus the SignatureRequestSourceData item?

Is the inner Optional really necessary? I have the impression that the (non-)existence of the item is already established by the serialized length of the list, and deserializing the inner Optional feels a little futile. Although I enjoyed the little mind twist :) ;)

Kind regards

[1] https://github.com/Chia-Network/chia-blockchain/blob/main/chia/protocols/harvester_protocol.py#L95

@wjblanke
Copy link
Contributor

Hi Harold, it looks like you may be most familiar with this. Can you respond

@haorldbchi
Copy link
Contributor

haorldbchi commented Jan 30, 2025

Is the inner Optional really necessary?

I can't remember exactly what was the reason. I'd have to go through it all and check. The only thing that I vaguely remember might be the type checker complaining at some point.

There might be some more info looking through the initial PR: https://github.com/Chia-Network/chia-blockchain/pull/17435/commits

I can look into it more once the current work slows down

@haorldbchi
Copy link
Contributor

Does it mean that if there is a list (1st Optional) then the list will always contain at least one element? Either 0x00 if the SignatureRequestSourceData item isn't present or 0x01 plus the SignatureRequestSourceData item?

I can't recall exactly if there is at least one element, but it might be the case. You might be able to find additional info in the PR above. There's some tests there that help show its usage and intent as well

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

No branches or pull requests

3 participants