Improve type safeness of InitializedReport #729
Merged
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.
InitializedReport has a
Option<Vec<u8>>
field which is only set by the helper, but this fact is known at compile time, it doesn't need to be encoded in a runtime option.By replacing
Option<Vec<u8>>
with a generic that can either be()
orWithPeerPrepShare
we make it explicit which parts of the code are dealing with reports from a client and which parts are dealing with reports from a peer (leader).In other words, we lift an invariant that was held by a comment
into one upheld by the compiler.
And finally instead of having on
new
constructor we havefrom_client
andfrom_leader
to make it obvious what the intent is when constructing, which in turn results in different sets of arguments being required (the former doesn't require a peer_prep_share where the latter does)Other advantages of this change are:
Some
case in leader codeNone
case in helper codenew
with thehelper
role and passNone
to the peer_prep_share argument, but this test did it anyway