-
Notifications
You must be signed in to change notification settings - Fork 214
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
Use Proxy
for the state of Virtual Objects
#5170
Comments
Attn @erights |
But IIUC we call (and must call) I do not understand how this can play well with (from a private conversation)
We have several exo |
This issue was written before
I have not audited them but based on the purpose of |
I see. In that case, I follow the rest. Thanks. |
This analogue of temporal dead zone cures my queasiness with the previous early-creation point. Invariant-violating uninitialized state would not be observable. Early calls to methods that read such state during Note that for shaped exos, we can still do all of this without a proxy. Just put that TDZ behavior into the accessors. |
Something like this was prototyped in endojs/endo@master...mhofman/ergonomic-exo-classes while experimenting on We may also want to move this state logic into endo as much as possible as heap exos could also use this approach, and avoid issues like endojs/endo#1648. #10170 shows how similar the heap exo state building is to liveslots's VOM. |
What is the Problem Being Solved?
init
call. After an upgrade it's impossible to add new properties to an existing object, making it impossible for a virtual object to implement lazy upgrades to their state that require new properties. See durable Kinds forget state property names across upgrade, are inconsistent when init() adds more #4935 (comment)init
doesn't have access to thefacets
(and to a lesser extent to the state), we had to introduce afinish
option that can perform work on the facets before returning those to the consumer. However because of this approach, it causes developers to store init arguments in the state even if they're not needed for the behavior. See feat(run-protocol): convert RunStakeManager to vobj #5135 (comment)init
shouldn't be necessary if no state or facet setup is needed.Description of the Design
state
as aProxy
instance that traps get, set, has, defineOwnProperty, etc, to mutate the stored data. Each state property can be completely lazy (loaded or written on demand) and independent of each other (e.g. cached independently).context
from the behavior and thisstate
object, before callinginit
or any other user code.init
with this samecontext
as the what the behavior methods would get, allowing users to roll theirfinish
logic intoinit
.While this makes it easier for users to cause different instances to have different state shapes, especially adding entries after construction, it's already possible today at
init
time by conditionally setting state properties. I understand that we want to think of the state of virtual objects as a DB table, but we could also think of it as a big Map keyed by${vref}:${stateProp}
. This also doesn't prevent us in the future of adding an explicit schema that would be enforced by the proxy.I believe by constructing the state once ahead of time, we can greatly simplify the VO internal init logic, since we don't need to extract and build a "manual getter/setter proxy" object after the fact.
Security Considerations
Not a security consideration per-se, but it's not obvious if the proxy trap should allow the state object to be sealed. However it's pretty clear that allowing the state to be frozen is likely undesirable, as it'd make the state unable to be updated. The proxy can prevent the state from being frozen or sealed.
Preventing state freezing would in effect prevent anything referencing the
state
from being hardened. That IMO is actually a benefit as the state should not end up used outside the behavior in the first place.Test Plan
This would be a breaking API change, and I'm not sure if there's a way to provide ergonomic backwards compatibility.
The text was updated successfully, but these errors were encountered: