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.
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
imp!: define helper trait for
Timestamp
conversions + updateConsensusState::timestamp()
to returnResult
#1353imp!: define helper trait for
Timestamp
conversions + updateConsensusState::timestamp()
to returnResult
#1353Changes from all commits
f238020
14abdcc
bd27973
a4bc6a2
4f11258
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Check warning on line 56 in ibc-clients/ics07-tendermint/types/src/header.rs
ibc-clients/ics07-tendermint/types/src/header.rs#L55-L56
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.
Am I correct to understand, these helper traits with auto-impls only reduce extra function calls and imports ?
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.
That’s one benefit. But more importantly it removes
tendermint
dependency inibc_primitives
. This fits with the plan to completely decouple the ibc-rs core stack from thetendermint
.It also makes things easier for light client developers or integrators. By implementing these traits, they can smoother convert their own time type to
Timestamp
wherever ibc-rs asks for, or reconstruct their types from ibc-rs’sTimestamp
if needed.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 meant whether these traits are just syntactic sugars. Because, the developers could also just use
T::try_from(OffsetDateTime::from(ibc_timestamp))
instead ofibc_timestamp.into_host_time()
andTimestamp::try_from(OffsetDateTime::from(host_timestamp))
instead ofhost_timestamp.into_timestamp()
.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.
Ah, I get what you mean now. It’s not quite that way.
We can't really assume the structure of a time type across different hosts or what conversions they use. They might not even be using
OffsetDateTime
. So, I added default implementations for any time type that follows this conversion path, just for convenience. As it's the case withtendermint::Time
. But this won’t necessarily apply to other timestamp types in differentConsensusState
structs.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.
Hmm. I am trying to understand, why would user need these two helper traits?
It seems to me, for a struct
HostTime
, they can just implementimpl TryFrom<Timestamp> for HostTime
andimpl TryFrom<HostTime> for Timestamp
.We can just use the trait bounds as
TryFrom<Timestamp>
andTryFrom<HostTime>
appropriately in ibc-rs.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.
Basically,
IntoHostTime<T>
is equivalent toTryInto<T>
andIntoTimestamp
is equivalent toTryInto<Timestamp>
.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.
Totally, this works too. But if a host has multiple
TryFrom<HostTime>
implementations, which usually can be the case, the consumer would need to specify the exact type and use the full path. Can’t simply calltry_from
ortry_into
on the time object. Plus, as you mentioned, this would definitely benefit from being syntactic sugar, making it more readable and easier to work with.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.
Yea. I am ok with this. Thanks, Farhad, for explaining.
Check warning on line 306 in ibc-primitives/src/types/timestamp.rs
ibc-primitives/src/types/timestamp.rs#L304-L306
Check warning on line 203 in ibc-testkit/src/hosts/tendermint.rs
ibc-testkit/src/hosts/tendermint.rs#L203