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

Use standard IBC errors #3908

Merged
merged 14 commits into from
Jan 6, 2023
Merged

Use standard IBC errors #3908

merged 14 commits into from
Jan 6, 2023

Conversation

nicolaslara
Copy link
Contributor

Refs: #3838 (comment)

What is the purpose of the change

Wasm hooks now uses the standard ibc v4 errors but emits the errors for the user to review.

Brief Changelog

(for example:)

  • Added an utility function to osmoutils for emiting errors before returning an ibc ack error
  • Updated wasmhooks errors to use that function

Testing and Verifying

Updated tests to check the errors properly (TODO)

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes? (yes / no)
  • Is a relevant changelog entry added to the Unreleased section in CHANGELOG.md? (yes / no)
  • How is the feature or change documented? (not applicable / specification (x/<module>/spec/) / Osmosis docs repo / not documented)

@nicolaslara nicolaslara added the V:state/breaking State machine breaking PR label Jan 3, 2023
Copy link
Member

@mattverse mattverse left a comment

Choose a reason for hiding this comment

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

Looks nice! Left some minor comments, please take a look

ErrBadMetadataFormatMsg = "wasm metadata not properly formatted for: '%v'. %s"
ErrBadExecutionMsg = "cannot execute contract: %v"
ErrBadResponse = "cannot create response: %v"

ErrMsgValidation = sdkerrors.Register("wasm-hooks", 1, "error in wasmhook message validation")
Copy link
Member

Choose a reason for hiding this comment

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

Just curious why use "wasm-hooks" instead of ModuleName? Also is it possible in this case to avoid using sdkerrors? AFAIK our goal in general is to refrain from using sdk errors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just curious why use "wasm-hooks" instead of ModuleName?

This error is specific to the validation of the wasm hook. The module could (and probably will in the future) have different hooks. That said, don't mind changing it.

is it possible in this case to avoid using sdkerrors? AFAIK our goal in general is to refrain from using sdk errors

What's the alternative? Ibc internally expects an error with codespace and code id. (https://github.com/cosmos/ibc-go/blob/b40dbc646c7191aaee12d3a70243f9b6f3f80919/modules/core/04-channel/types/acknowledgement.go#L32-L42)

Copy link
Member

@mattverse mattverse Jan 5, 2023

Choose a reason for hiding this comment

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

This error is specific to the validation of the wasm hook. The module could (and probably will in the future) have different hooks. That said, don't mind changing it.

Ah I see what you were trying to do. LGTM!

What's the alternative? Ibc internally expects an error with codespace and code id. (https://github.com/cosmos/ibc-go/blob/b40dbc646c7191aaee12d3a70243f9b6f3f80919/modules/core/04-channel/types/acknowledgement.go#L32-L42)

Don't know much about ibc-go but is this the method that receives the error? https://github.com/cosmos/ibc-go/blob/b40dbc646c7191aaee12d3a70243f9b6f3f80919/modules/core/04-channel/types/acknowledgement.go#L32-L35 looks like it takes in go lang error. Or I assume there might be different components in ibc-go that accepts codespace and code-id. If so, please feel free to resolve this comment!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, we can pass a golang errors (the sdk errors are golang errors under the hood). I guess I could define the error type using sdkerrors.New or manually as Error{codespace: codespace, code: code, desc: desc}, but not sure what the advantage of doing that would be.

Maybe we should have a standard way to do this across osmosis?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ValarDragon can you chime in here? I think we should leave these using sdkerrors. AFAICT, passing a normal error to IBC's channeltypes.NewErrorAcknowledgement will return the default "internalABCICode" (1). Having the code numbers is useful to determine what happened.

Copy link
Member

Choose a reason for hiding this comment

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

We're generally trying to rethink codespacing in cosmos: cosmos/cosmos-sdk#14070

Very few people actually use codespacing in their integrator logic.

I'm not very opinionated on this, since its unlikely these errors are things we'd want to change in a patch release.

Copy link
Member

Choose a reason for hiding this comment

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

I believe we have to start registration from 2 onwards though

Copy link
Member

Choose a reason for hiding this comment

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

Ah given that this is IBC-standard here, agreed with SDK registering these

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, so, in conclusion: keep sdk errors for this so it matches other IBC errors and move the first code to 2 (which was just an oversight on my part), right?

Copy link
Member

Choose a reason for hiding this comment

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

yup!

osmoutils/ibc.go Show resolved Hide resolved
},
// NewEmitErrorAcknowledgement creates a new error acknowledgement after having emitted an event with the
// details of the error.
func NewEmitErrorAcknowledgement(ctx sdk.Context, err error, errorContexts ...string) channeltypes.Acknowledgement {
Copy link
Member

Choose a reason for hiding this comment

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

Why don't we just move this to ibc-hooks, then we can delete the entire ibc-hooks <> osmoutils dependency

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahh, no. Just realized it's in osmoutils because rate-limiting is also using it (we could have rate limiting import it from wasm hooks, but it seems dirtier)

Copy link
Member

Choose a reason for hiding this comment

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

Didn't we want rate limiting to import ibc-hooks anyway? (This isn't release blocking at all either way though)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, that makes sense. We can change it later when rate limits is based off ibc hooks.

),
})

return channeltypes.NewErrorAcknowledgement(err)
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

@ValarDragon ValarDragon left a comment

Choose a reason for hiding this comment

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

LGTM, we just need to increment codespace by one

@nicolaslara nicolaslara merged commit 73b5717 into main Jan 6, 2023
@nicolaslara nicolaslara deleted the nicolas/ibc-standard-errors branch January 6, 2023 09:36
nicolaslara added a commit that referenced this pull request Jan 6, 2023
* reverted errors to the ibc standard

* revision change

* updated dependencies

* fix rate limit errors

* fixed rate limit errors

* updated versions

* updated commit to after the merge

* convert new error

* new go mod

* increment error codes

* updated go mod to latest ibc-hooks

Co-authored-by: Dev Ojha <[email protected]>
ValarDragon added a commit that referenced this pull request Jan 6, 2023
* Enforce SDK 45 in the dependencies (#3863)

* using sdk 45

* added osmoutils to go.sum

* move all versions to 0.45

* changed for all

* fixed import to latest

* updated go.mod

* Lifecycle completed without contracts (#3927)

* selecting lyfecycle change

* updated version and tidy

* updated bersions again to one with the proper go.sum

* proper counter contract for tests

* updated test bytecode

* wasm hooks from main

* lifecycle message update

* go mod tidy

* Use standard IBC errors (#3908)

* reverted errors to the ibc standard

* revision change

* updated dependencies

* fix rate limit errors

* fixed rate limit errors

* updated versions

* updated commit to after the merge

* convert new error

* new go mod

* increment error codes

* updated go mod to latest ibc-hooks

Co-authored-by: Dev Ojha <[email protected]>

* new commit

* update ibc-hook version

* Update root version

* updated osmomath

Co-authored-by: Dev Ojha <[email protected]>
Co-authored-by: Dev Ojha <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
V:state/breaking State machine breaking PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants