-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
Interface inheritance #172
Conversation
33615ae
to
bb16871
Compare
6ea0ea3
to
947edf4
Compare
b830dfd
to
824a4ab
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some continue
arms can be removed and use break
instead. Others look good to me.
src/interface/inheritance.rs
Outdated
overflow = true; | ||
errors.push(ExtensionError::GlobalOverflow) | ||
}) | ||
.ok(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we check if overflow
after insertion and then breaks here?
Such that we can get rid of the None if overflow
condition arm.
iface: break if overflow
A follow up to #162 which contains chances to interfaces outside of inheritance.
This is epic adding inheritance to the interfaces and refactoring related concepts.
What remains:
RGB interface specification
Actors
Schema and implementation development
It is up to the schema developer to ensure the consistency of schema operations
under multiple interfaces. Schema developer selects a set of interfaces for a
schema, and should create a single unified interface inheriting all of them.
Next, an implementation of that interface have to be made for a schema.
If schema developer fails to create a coherent interface users may lose the
ability to transact with a contract or see its full state.
NB: Since interfaces and implementations does not exist on the consensus level,
contract validation is interface- and implementation independent; thus once a
user can create a valid transaction, any other user will be able to verify and
accept it even if the interface or implementation is broken.
Implementations and interfaces must commit to the developer identity - like
schemata.
Inheritance and specialization
Interface inheritance is a form of interface specialization: a higher-order
interface inheriting from some other (called parent interface) can only add
or tighten what was defined before, but not relax.
Multiple inheritance is allowed, in this case the higher-order interface sums
up what is possible with lower-order interfaces, by creating unnamed
intermediate interfaces inheriting the parents in the order they are specified.
In this case the same specialization rules applies, such that at each step only
specialization may happen and the final interface specializes all the parent
interfaces.
Multiple inheritance is generally non-commutative on the order of the parent
interfaces.
Interface inheriting other interface(s) may only:
interfaces marks operation is abstract and overriden;
state types or assignments in contract or any of the operations, but only if
all the parent interfaces;
interfaces;
operation in any of the parent interfaces;
It is disallowed to:
parent interface;
specialization.
Once compiled, the higher-order interface includes all parent interfaces as part
of it in explicit form, however, it commits and stores the information on the
parent interface ids in their inheritance order.
Implementation implements this final interface, covering all parent interfaces
in a single data structure. However, when used, the implementation can be
dynamically specialized as a specific parent interface, excluding the rest of
interfaces. This is possible and always deterministic due to the above
inheritance rules.
Updates and fixes
Schema developer or a third-party may create a new implementation - for new
interfaces or as an alternative to an existing implementation, implementing some
operations more efficiently (or fixing bugs).
Developers should include into the implementation an increasing version number,
which must be unique and incremental for a given developer identity.
These new implementations and new generic interfaces covering new cases can be
distributed by these devs as a part of contract, transfer, schema or interface
consignments. All these consignments can include multiple interfaces and
multiple implementations of the same or different interfaces for the same
schema. Users may import the new interfaces and implementations into their
stashes (upon validation) and switch on using them even for existing contracts
with a state.
The user verifies the interface, implementation and schema consistency, and also
checks the dev signatures. It is recommended not to accept interfaces and
implementations coming from an untrusted parties.
Conflict resolution
If a stash contains multiple implementations of the same interface for the same
schema the wallet or an app must select the one which has the most dev trust.
If two or more has the same level of trust, than the one which has the highest
version number. If multiple implementations has the same version number, they
either has to be rejected to be included into the stash, or the one with the
highest lexicographic id number must be selected.