-
Notifications
You must be signed in to change notification settings - Fork 232
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
removes fallible ErasureMeta.fec_set_index type-casts #1841
removes fallible ErasureMeta.fec_set_index type-casts #1841
Conversation
5a66107
to
067312a
Compare
4b21f3e
to
5f35b48
Compare
fec_set_index is u32 by the definition in the shred struct. Blockstore however uses u64 for ErasureMeta.fec_set_index for backward compatibility reasons which results in weird typing and fallible conversions from u64 to u32. Any ErasureMeta with a fec_set_index which does not fit in u32 is invalid and should be discarded early. The commit changes ErasureMeta.fec_set_index type to u32 while using serde attributes to maintain backward compatibility for (de)serialization.
5f35b48
to
463dd5c
Compare
// Serializes a value of type T by first type-casting to type R. | ||
pub(super) fn serialize<S: Serializer, R, T: Copy>( | ||
&val: &T, | ||
serializer: S, | ||
) -> Result<S::Ok, S::Error> | ||
where | ||
R: TryFrom<T> + Serialize, | ||
<R as TryFrom<T>>::Error: std::fmt::Display, | ||
{ | ||
R::try_from(val) | ||
.map_err(serde::ser::Error::custom)? | ||
.serialize(serializer) | ||
} | ||
|
||
// Deserializes a value of type R and type-casts it to type T. | ||
pub(super) fn deserialize<'de, D, R, T>(deserializer: D) -> Result<T, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
R: Deserialize<'de>, | ||
T: TryFrom<R>, | ||
<T as TryFrom<R>>::Error: std::fmt::Display, | ||
{ | ||
R::deserialize(deserializer) | ||
.map(T::try_from)? | ||
.map_err(serde::de::Error::custom) | ||
} |
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.
intentionally generic so that it can be used elsewhere for similar type discrepancies.
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.
LGTM maybe the serde module can also be used for SlotMeta
fields? and eventually we can do an overhaul to key blockstore by u32
for shreds as well.
yeah, looking into other blockstore fields with mismatching types. |
Problem
fec_set_index
isu32
by the definition in the shred struct. Blockstore however usesu64
forErasureMeta.fec_set_index
for backward compatibility reasons which results in weird typing and fallible conversions fromu64
tou32
.Any
ErasureMeta
with afec_set_index
which does not fit inu32
is invalid and should be discarded early.Summary of Changes
The commit changes
ErasureMeta.fec_set_index
type tou32
while usingserde
attributes to maintain backward compatibility for (de)serialization.