-
Notifications
You must be signed in to change notification settings - Fork 795
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
Block builder #1451
Block builder #1451
Conversation
4ca7027
to
ba1b4cd
Compare
What if someone does something like:
Maybe an assert that can catch these kinds of errors, or nullify members which become invalid after updating ? |
@rkeene The The param-less build() will assert if there's an internal error. We just have to decide what those errors should be. It's currently decoding errors. To catch your example, we might have to track some state. I'm fine with that, just need a list of things to catch. |
Can we use sentinel values to pack unset/invalid_decoding information in the value itself? We should have a way to query can_build if the block has all the appropriate items set, based on its type. I think build() should assert if can_build is false and make it a precondition to being called. |
The whole domain for some values (like destination pubkey) seems to be valid so no sentinel will do IIUC. Could we use an uint8_t bitmap in the builder which is updated while building, and then validated on edit: Actually, the std::error_code might be usable for this while building to save space. |
Since it's a 256bit value , if we use a random internal sentinel it shouldn't be a problem. Globals create random values for not-a-block or not-an-account. |
@clemahieu that makes sense, thanks! |
There are work (64-bit) and amount (128-bit) values too though. The 64-bit one is in the realm of collisions (maybe max-1 works? 0 is used in tests) |
After discussing it a bit, currently reworking this to use builder state instead of sentinels. This allows for fast validation through per-block-type masks. edit: updated |
ba1b4cd
to
53338dd
Compare
53338dd
to
80e57d0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me !
Implements a builder pattern for all block types.