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(08-wasm)!: use concrete types for json serialization #4909

Merged

Conversation

damiannolan
Copy link
Member

@damiannolan damiannolan commented Oct 18, 2023

Description

Removes usage of exported interface types in the contract api types to allow clean codec usage with native Go implementations.

We should run an e2e regression with this but encoding should be fine.

closes: #4908


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md).
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/).
  • Added relevant godoc comments.
  • Provide a commit message to be used for the changelog entry in the PR description for review.
  • Re-reviewed Files changed in the Github PR explorer.
  • Review Codecov Report in the comment section below once CI passes.

@damiannolan
Copy link
Member Author

With this PR, I could successfully get a test scaffolding together like this for VerifyMembership

Copy link
Contributor

@DimitrisJim DimitrisJim left a comment

Choose a reason for hiding this comment

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

lgtm! (rocket and fire emojis)

Copy link
Member

@srdtrk srdtrk left a comment

Choose a reason for hiding this comment

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

lgtm. Thank you!

@@ -86,9 +86,14 @@ func (cs ClientState) GetTimestampAtHeight(
cdc codec.BinaryCodec,
height exported.Height,
) (uint64, error) {
timestampHeight, ok := height.(clienttypes.Height)
if !ok {
return 0, errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", clienttypes.Height{}, height)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return 0, errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", clienttypes.Height{}, height)
return 0, errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", (*clienttypes.Height)(nil), height)

Copy link
Contributor

Choose a reason for hiding this comment

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

we mostly use the approach used here. We should open a larger issue about fixing the way we do this tho since I see we're not consistent all over the place, not just 08-wasm.

Copy link
Member Author

Choose a reason for hiding this comment

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

if !ok {
return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path)
}

proofHeight, ok := height.(clienttypes.Height)
if !ok {
return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", clienttypes.Height{}, height)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", clienttypes.Height{}, height)
return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", (*clienttypes.Height)(nil), height)

I think there are other places in the code where this is done. So I might just open a separate PR for this.

if !ok {
return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path)
}

proofHeight, ok := height.(clienttypes.Height)
if !ok {
return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", clienttypes.Height{}, height)
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Comment on lines +48 to +49
UpgradeClientState: *wasmUpgradeClientState,
UpgradeConsensusState: *wasmUpgradeConsState,
Copy link
Member

Choose a reason for hiding this comment

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

This will panic if wasmUpgradeClientState or wasmUpgradeConsState is nil. Is it possible to assert this earlier and possibly handle it as an error there?

Not a big deal though as it's probably ok for it to panic. Or it is somehow not possible for it to reach here if it were nil.

Copy link
Contributor

@DimitrisJim DimitrisJim Oct 19, 2023

Choose a reason for hiding this comment

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

nil is handled by type assertion. Type assertions yield false if the underlying value of interface you're trying to cast from is nil or != T (target type).

Copy link
Contributor

@crodriguezvega crodriguezvega left a comment

Choose a reason for hiding this comment

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

Thank you, @damiannolan

@crodriguezvega crodriguezvega merged commit f02c619 into feat/wasm-clients Oct 20, 2023
64 checks passed
@crodriguezvega crodriguezvega deleted the damian/4908-wasm-contract-api-encoding branch October 20, 2023 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants