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

Add Never type to avoid ibc_packet_receive errors #1513

Merged
merged 4 commits into from
Jan 4, 2023
Merged

Conversation

webmaster128
Copy link
Member

When refactoring some ibc_packet_receive code in Nois I realized I really want type safety to ensure I don't shoot myself in the foot. A Never type makes explicit what is documented as best practive already: let ibc_packet_receive never return an error.

This way we keep compatibility with the current API (ibc_packet_receive returns Result<IbcReceiveResponse<C>, E> with E: ToString) but make it impossible to refactor code in a way that it returns an error (which is easy to get wrong with the ? operator).

Copy link
Member

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

Looks good, happy for this type.

However, we no longer need this in receive as we auto-wrap errors in ibc receive as long as you use the same JSON format for errors as in ics20 and ics27.

We really should have this for ack and timeout, so the type is useful.

}
}

impl core::fmt::Display for Never {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a comment that this is needed to satisfy the requirement of error type in cosmwasm results

@webmaster128
Copy link
Member Author

However, we no longer need this in receive as we auto-wrap errors in ibc receive as long as you use the same JSON format for errors as in ics20 and ics27.

Where/how is this happening? Did I miss something that I should be aware of?

@ethanfrey
Copy link
Member

We changed this when upgrading to ibc-go v3. This handles errors just in reply.

It was added in January. I know I had various discussions on GitHub here and I thought it was documented.

@webmaster128
Copy link
Member Author

Oh, this PR might be obsolete then. I will check that.

@webmaster128 webmaster128 marked this pull request as draft November 24, 2022 09:27
@ethanfrey
Copy link
Member

Never in other areas would be useful.
It was just the receive block we converted to app-level error instead of transaction rollback.

(And anyone that doesn't want that error format must ensure Never and manually handle)

@webmaster128
Copy link
Member Author

Never in other areas would be useful.

Yeah, it seems like we have the same issue in ibc_packet_ack, right? You don't want to fail the ack transaction from the relayer just because of some failing ? in the CosmWasm implementation.

@webmaster128 webmaster128 marked this pull request as ready for review January 2, 2023 16:13
@webmaster128 webmaster128 added this to the 1.2.0 milestone Jan 2, 2023
@webmaster128 webmaster128 merged commit d6f5dfc into main Jan 4, 2023
@webmaster128 webmaster128 deleted the add-Never branch January 4, 2023 09:32
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.

2 participants