-
Notifications
You must be signed in to change notification settings - Fork 990
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
Implement kernel and output features as enums #2312
Conversation
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.
It is critical that we reject features outside the current range 0-2,
so we need to maintain the fallback clause
let valid_features = match features {
...
_ => false,
@tromp Rust enums matching must be exhaustive (it won't compile otherwise). We don't need a fallback here because we have covered all the possibilities. In fact if we try and add a fallback clause here then the rust compiler will complain -
It is now impossible to construct a TxKernel with a KernelFeatures outside of the range 0-2. |
Then what happens if the deserializer reads a value 3? Is that guaranteed to result in error? |
Yes we will catch this during deserialization here -
Edit: let me add a test to demonstrate/verify this, so we have something to refer to in the code. |
So the KernelFeatures::from_u8 throws an error given a value of 3? |
Longer term we may want to consider being able to maintain the various feature specific data (lock heights for a height locked kernel, fee for coinbase kernel etc.) on the enum itself.
But to do this we would need to implement per enum type serialization and we would no longer be able to represent the enum as a simple u8.
This PR gets us 90% of the way there in terms of simplifying how we deal with features.
TODO -
floonet
(nothing should change)