Skip to content
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

fix: duration conversion between prost and core types #1386

Conversation

DeVikingMark
Copy link

Description

This PR addresses the issue of converting durations between Prost types and core Rust types. It introduces utility functions for handling these conversions safely and updates the affected modules to use these utilities.

Fixes

Fixes #1376


Description of Changes

  • Add dedicated duration conversion functions in ibc-primitives
  • Improve error handling for invalid duration values
  • Reject negative durations as invalid
  • Add comprehensive tests for duration conversions
  • Clean up and simplify duration handling in ClientState

Critical Files to Review

  1. ibc-clients/ics07-tendermint/types/src/client_state.rs
  2. ibc-primitives/src/types/duration.rs
  3. ibc-primitives/src/types/mod.rs

PR Author Checklist:


Reviewer Checklist:

  • Reviewed the changes in the Files changed tab.
  • Verified unit and integration tests cover all updated functionality.
  • Checked for proper documentation updates and adherence to contributing guidelines.
  • Performed manual testing if necessary (integration/unit/mock tests absent).

👋 Thank you for reviewing this PR! Please feel free to provide any feedback or additional requirements for changes.

Comment on lines +6 to +10
pub fn duration_to_proto(d: Duration) -> Option<RawDuration> {
let seconds = i64::try_from(d.as_secs()).ok()?;
let nanos = i32::try_from(d.subsec_nanos()).ok()?;
Some(RawDuration { seconds, nanos })
}
Copy link
Member

@rnbguy rnbguy Dec 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really sure if you understood my original issue because I need to have RawDuration: From<Duration> i.e. infallible duration_to_proto.

@rnbguy
Copy link
Member

rnbguy commented Dec 26, 2024

I will close this PR as it doesn't resolve the linked issue. This needs to be resolved at external dependencies. For further context, check the linked issues (at remote repos) in the original issue.

@rnbguy rnbguy closed this Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ibc-client-tendermint-types] properly handle fallible conversion between prost Duration and core Duration
2 participants