Skip to content

Contract output on reverted executions #1841

@xermicus

Description

@xermicus

As per the docs, returning an Err from a message will always revert the contract execution. Now that makes me wondering as to why ink! contracts always return a MessageResult, instead of the actual type?

Given that:

  • Returning Ok will never revert the execution
  • Return Err will always revert the execution

Unless I'm missing something here, it does seem unnecessary to always encode the contract output as a Result; this is known anyways based on the revert flag. Additionally, the current model implies that we need to support situations where a contract would return Err but not revert it's state and vice versa, and I'm not sure when that would be useful.

I think the whole situation could be simplified by defining that:

  • Contracts return two types O and E as their output
  • Type O is expected if the execution did not revert
  • Type E is expected if the execution did revert

Which would:

  • Simplify the ink! metadata. There would be no need do define a "special" LanguageError type or wrapping the message ouptuts in nested types like MessageResult. Instead, each contract message would just define their O and E types.
  • Remove the need to encode and encode these nested Result types at runtime. Yes it's only 1 or 2 bytes but why not getting rid of any redundancy we can. Requiring all contracts to always encode their message results prefixed with 1 or 2 bytes, which encode no meaningful (because redundant) data, just because ink! does expect that, signals inelegance.
  • Make the metadata no longer agnostic to Rusts Result type.

Of course, this would be a major breaking change requiring careful consideration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-discussionAn issue for discussion for a given topic.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions