-
Notifications
You must be signed in to change notification settings - Fork 115
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
Proposal: Efficient entity ownership transfer #379
Labels
Comments
Lezek123
pushed a commit
to Lezek123/substrate-runtime-joystream
that referenced
this issue
May 21, 2020
Proposal form: Runtime upgrade
V2ProblemThis proposal ended up being broken, as observed by @iorveth, because it does not deal with inbound same owner references to the entity. Instead, we are doing this simple approach below. Solution
|
This was referenced May 26, 2020
Merged
49 tasks
Closed by #396 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Background
In the existing content directory, the only way of reassigning ownership is to transfer ownership of channels. There is no way to transfer ownership of entities in the version store, and the only way channels can be transferred is precisely because they live (incorrectly) in the content directory working group.
Problem
Reassigning entity ownership is going very likely going to be needed functionality, however, implementing it is not trivial due to the new same owner on references constraint which is going to be introduced in 2.0.
#175
This is done using field
ClassPermissions::referenced_entity_must_have_same_controller
. A naive change of theEntityPermission::controller
, e.g. inupdate_entity_controller
, for an entity, will break all inbound references from other entities.While introducing an index from can allow us to at least detect whether a naive ownership change is OK or not, this is not sufficiently practical, as we would just be blocked from making the transfer we want.
Another alternative would be to do some sort of tree search to using the index, going from entity to entity, to find the full set of entities impacted, and then update the controller value for all of them in concert. So for example, changing ownership of a channel could involve an initial search that enumerates some hundreds or thousands of entities, and then updating the controller value by iterating through and mutating. To prevent DoS attack one could cap the size of such a search upfront.
This second solution highlights an obvious property of the entity relationships that are not explicitly modeled but could be, namely that entities are organized into trees, based on their referencing properties, where all entities have the same owner. If we just embrace this, the constant time ownership transfer is possible.
Solution
We allow entities to have their controller be defined not only as a specific
EntityController
, but also be simply pointing at anotherEntity
and having the same controller as this entity. Notice that this entity may itself have the same policy. This indirect ownership specification should obviously be cycle free, something that must be ensured when changing ownership of an entity.We should also limit how deep this can go, and this must be ensured both when creating entities, and changing ownership of entities. At an implementation level, we can do
Notice that an entity can have
controller = EntityController::SameAsEntity(x)
, wherex
is the id of an entity from another class. We also have to update the way controllers are assigned to entities, currently viaInitialControllerPolicy
, to be something likeCreate entity
We must also update
create_entity
to allow for the specification of a possibleInitialControllerPolicy::SameAsEntity
value, but this is only valid when the class is in this policy mode, so it must be optional. Moreover, we must check that adding the entity does not exceed the max depth of the indirect ownership specification. Obviously, there is no way to introduce a cycle when introducing a new entity, so this problem needs not to be kept in mind.Authentication
Whenever one authenticates, which typically requires providing
as: ActorInGroupId<T>
, the authentication logic must climb the tree ofSameAsEntity
values, until it gets to an entity which has a direct ``EntityController` value. We can trust that this process concludes in a timely manner, by virtue of constraints that are enforced on there being no cycles and max depth.Change ownership
The primary constraint one must respect in this transition is to not grow the indirect ownership tree any deeper than a given constant value in the runtime. Computing this requires some iteration, but it is all bound by 2*the old depth constraint.
Question
This change is non-trivial, its needs a proper sanity check.
The text was updated successfully, but these errors were encountered: