-
Notifications
You must be signed in to change notification settings - Fork 469
Open
Labels
C-discussionAn issue for discussion for a given topic.An issue for discussion for a given topic.
Description
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
andE
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 likeMessageResult
. Instead, each contract message would just define theirO
andE
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 becauseink!
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
Labels
C-discussionAn issue for discussion for a given topic.An issue for discussion for a given topic.