-
Notifications
You must be signed in to change notification settings - Fork 371
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
Remove the concept of a "zero Height" #2346
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.
Have you thought of making the revision_height
member of Height
a NonZeroU64
?
And maybe making both members non-public while we are at it.
This will enforce avoidance of 0, and ensure that std::mem::size_of::<Option<Height>>()
is 16.
@@ -29,11 +29,8 @@ pub struct MsgConnectionOpenAck { | |||
impl MsgConnectionOpenAck { | |||
/// Getter for accessing the `consensus_height` field from this message. Returns the special | |||
/// value `Height(0)` if this field is not set. |
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 comments like this need to be updated too.
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 didn't find any other comments that referred to "Height zero"
Yes, my original plan was to use // e.g. when building from a tendermint header
Height::new(chain_id(), header_height_revision_number.try_into().map_err(|_| ...)?) Basically since all the other types use I am also planning on making the members private. |
Great work @plafer! 👍 Just left some comments and questions. |
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.
Awesome work @plafer, thanks so much!
Prior to this PR, the `Height` type used a special `Height::zero()` value to denote the absence of height value. This caused ad hoc checks of whether a height is zero in various places. From now on, we instead use `Option<Height>` on places where the height value may be optional, and require non-zero value in the `Height` constructor. - Optional height parameters should use `Option<Height>` instead of `Height`. - Checking of `height == Height::zero()` is replaced with Option matching. --- * From<Height> for String fix * Use Option<Height> instead of Height::zero for consensus_height * recv_packet still had Height::zero() in events * TryFrom<RawHeight> for Height * pre height parse changes * Packet.timeout_height is now an Option<Height> * rustdoc * Remove Height::with_revision_height * commit pre-modifying cli * Finish Height::new() returns Result * remove Height::is_zero() * Remove `Height::zero()` * Remove Height::default() * Height fields accessors * use revision_height accessor * use revision_number accessor * make Height fields private (WIP) * compile error fixes * FIXME in transfer.rs addressed * Use existing constants instead of hardcoded strings * changelog * TimeoutHeight newtype * Use TimeoutHeight everywhere * Fixes after merging with master * has_expired() fix * doc url * fix send_packet test * Remove timeout_height == 0 && timestamp == 0 check * Remove `has_timeout()` * Change TimeoutHeight impl * docstrings * tests fix * fix history manipulation test * transfer test: no timeout * msgtransfer test * packet no timeout or timestamp test * send_packet timeout height equal destination chain height * send_packet test with timeout = height - 1 * test invalid timeout height * fix docstring * clippy * Fix clippy warnings introduced in Rust 1.62 * Fix serialization of `TimeoutHeight` to match the format used by `Height` Co-authored-by: Romain Ruetschi <romain@informal.systems>
Closes: cosmos/ibc-go#1009
Description
PR author checklist:
unclog
.docs/
).Reviewer checklist:
Files changed
in the GitHub PR explorer.