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

Decode ClientState from Protobuf's Any type #233

Merged
merged 10 commits into from
Sep 17, 2020

Conversation

romac
Copy link
Member

@romac romac commented Sep 15, 2020

See: cosmos/ibc-rs#115

Description

Decode both Tendermint and Mock client states from Protobuf's Any type.


For contributor use:

  • Unit tests written
  • Added test to CI if applicable
  • Updated CHANGELOG_PENDING.md
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Updated relevant documentation (docs/) and code comments
  • Re-reviewed Files changed in the Github PR explorer

@romac romac requested review from adizere and ancazamfir September 15, 2020 16:01
Copy link
Member

@adizere adizere left a comment

Choose a reason for hiding this comment

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

Looks great! I only had relatively minor comments.

use crate::mock_client::header::MockHeader;
#[cfg(test)]
use crate::mock_client::state::{MockClientState, MockConsensusState};
use {
Copy link
Member

Choose a reason for hiding this comment

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

Ahh this is such a treat to the eyes.

impl AnyClientState {
pub fn from_any(any: prost_types::Any) -> Result<Self, Error> {
match any.type_url.as_str() {
"ibc.tendermint.ClientState" => {
Copy link
Member

Choose a reason for hiding this comment

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

Minor:

Maybe we should consider keeping these strings (lines 125 "ibc.tendermint.ClientState" and 135 "ibc.mock.ClientState") hardcoded in some enum as opposed to hardcoded here? I can imagine they could even go in the ibc-proto repo, not here, but not sure what would be best.

To keep things simpler and get this merged fast, we can also just keep the hardcoded values as they are and just add a todo.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah good point! Those should probably be defined as constants somewhere.

@@ -14,23 +14,26 @@
//! TODO: Separate the Cosmos-SDK specific functionality from canonical ICS types. Decorators?

#![allow(clippy::too_many_arguments)]
Copy link
Member

Choose a reason for hiding this comment

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

Looking at the code, I think it's safe to remove this now.

@@ -1,5 +1,6 @@
use crate::ics23_commitment::commitment::CommitmentPrefix;
use ibc_proto::commitment::MerklePath;

use ibc_proto::ibc::commitment::MerklePath;
Copy link
Member

Choose a reason for hiding this comment

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

Seems we always import types from ibc proto as use ibc_proto::ibc::X, so I'm wondering why is the ibc namespace in the middle necessary. We could just say use ibc_proto::X.

Copy link
Member Author

Choose a reason for hiding this comment

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

See this PR for a (poorly explained) rationale: informalsystems/ibc-proto#9

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, the ibc_proto crate exports other types which are not ibc-specific so imho it makes sense to qualify their usage, though we could te-export them at the top level but that may cause similar issues to the one mentioned in the PR linked above.

Copy link
Collaborator

@ancazamfir ancazamfir left a comment

Choose a reason for hiding this comment

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

Looks great! thanks!

impl AnyClientState {
pub fn from_any(any: prost_types::Any) -> Result<Self, Error> {
match any.type_url.as_str() {
"ibc.tendermint.ClientState" => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wondering if we should define these type_url strings in a separate place so they can also be used for encoding. We can do it later also.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed! See my reply to Adi’s comment above.

@adizere adizere mentioned this pull request Sep 16, 2020
6 tasks
@ancazamfir ancazamfir merged commit 6495798 into anca/proto_update Sep 17, 2020
@adizere adizere deleted the romain/decode-client-state branch September 17, 2020 08:00
ancazamfir added a commit that referenced this pull request Sep 17, 2020
* initial changes for ibc_proto 0.2.2

* Fix cargo fmt errors

* Add client proof to verify proofs

* Add the client state verification functions

* Fix error

* Fix fmt error

* Review comments

* Some initial changes verification arguments not tight to ClientDef

* Decode ClientState from Protobuf's Any type (#233)

* Fix Clippy warnings

* Add stub for deserializing ClientState from Protbuf's Any

* Update to latest ibc-proto

* Decode Tendermint client state from raw

* Decode raw client states

* Add FIXME comments to uses of `epoch_height`

* Update ibc-proto to 0.3.0

* Remove local path to ibc-proto dependency

* Stylistic fixes

* cleanup, comment is in the trait

* fix mock context historical info validation

Co-authored-by: Romain Ruetschi <romain@informal.systems>
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.

3 participants