-
Notifications
You must be signed in to change notification settings - Fork 216
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
Deserialize boundedbtreeset #781
Merged
bkchr
merged 4 commits into
paritytech:master
from
ozgunozerk:deserialize_boundedbtreeset
Aug 31, 2023
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is weird. You insert before checking for the max, i.e. you add 1 more value over the limit before you check the limit?
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.
I also found it weird. It was like that in
BoundedVec
's Deserialize implementation: https://github.com/paritytech/parity-common/blob/master/bounded-collections/src/bounded_vec.rs#L90-L92I thought that was intentional and didn't put much thought tbh.
I can fix them both if you like?
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.
Sure, but there's one more additional issue: checking
values.len() > max
doesn't sound right to me either, because it too is also waiting for 1 element over the max before the condition triggers. What should really happen isvalues.len() >= max
.It would be so great if you can write tests for these as well.
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.
Since we are already discussing the implementation of Deserialize for BoundedVec as well, I had another thing which confused me:
https://github.com/paritytech/parity-common/blob/master/bounded-collections/src/bounded_vec.rs#L84-L85
So, if we are performing a check in here for the size, do we need another check in here:
https://github.com/paritytech/parity-common/blob/master/bounded-collections/src/bounded_vec.rs#L90-L92
?
I think the second check is not necessary and the error produced by the second check is unreachable. So, I don't know if it's possible to write a test for triggering that error. It will trigger the previous error instead.
I might be missing something, so feel free to correct me
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.
The first check is using
size_hint()
and that could also beNone
in which case the size is0
as you see in the code.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.
I've added a new commit:
deserializer_test
and made the size equal to the boundsize_hint()
does indeed returnNone
, so I'm positive I'm testing the inner checkdeserializer_test