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

Block builder #1451

Merged
merged 5 commits into from
Dec 28, 2018
Merged

Conversation

cryptocode
Copy link
Contributor

@cryptocode cryptocode commented Dec 14, 2018

Implements a builder pattern for all block types.

@cryptocode cryptocode force-pushed the improvement/block-builders branch 2 times, most recently from 4ca7027 to ba1b4cd Compare December 14, 2018 12:22
@rkeene rkeene added quality improvements This item indicates the need for or supplies changes that improve maintainability major This item indicates the need for or supplies a major or notable change labels Dec 16, 2018
@rkeene rkeene added this to the V18.0 milestone Dec 17, 2018
@rkeene rkeene requested review from rkeene and SergiySW December 18, 2018 20:03
@rkeene
Copy link
Contributor

rkeene commented Dec 18, 2018

What if someone does something like:

auto block = builder.state().clear().sign(key.prv, key.pub).balance(1).build();

Maybe an assert that can catch these kinds of errors, or nullify members which become invalid after updating ?

@cryptocode
Copy link
Contributor Author

cryptocode commented Dec 18, 2018

@rkeene The sign function returns a base class type so attempted to call balance will be a compile error.

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.

@clemahieu
Copy link
Contributor

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.

@cryptocode
Copy link
Contributor Author

cryptocode commented Dec 20, 2018

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 build() ?

edit: Actually, the std::error_code might be usable for this while building to save space.

@clemahieu
Copy link
Contributor

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.

@cryptocode
Copy link
Contributor Author

@clemahieu that makes sense, thanks!

@cryptocode
Copy link
Contributor Author

cryptocode commented Dec 20, 2018

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)

@cryptocode
Copy link
Contributor Author

cryptocode commented Dec 21, 2018

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

@cryptocode cryptocode force-pushed the improvement/block-builders branch from ba1b4cd to 53338dd Compare December 21, 2018 23:02
@cryptocode cryptocode force-pushed the improvement/block-builders branch from 53338dd to 80e57d0 Compare December 21, 2018 23:19
Copy link
Contributor

@rkeene rkeene left a 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 !

@rkeene rkeene merged commit 5fb4617 into nanocurrency:master Dec 28, 2018
@cryptocode cryptocode deleted the improvement/block-builders branch December 29, 2018 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major This item indicates the need for or supplies a major or notable change quality improvements This item indicates the need for or supplies changes that improve maintainability
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants