Skip to content
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

feat(zone)!: implement zone.makeOnce(key, maker) #7891

Merged
merged 14 commits into from
Jul 25, 2023
Merged

Conversation

michaelfig
Copy link
Member

@michaelfig michaelfig commented Jun 6, 2023

closes: #7663

Description

Implements zone.makeOnce(key, maker) in a similar spirit to #7663, but with verification that it is called only once per key,zone,incarnation.

Also moves the implementation to Zone. The original once implementation was a method on Stores, but they might be detached (i.e. have no backing store) and thereby not need key usage tracking.

Security Considerations

A breaking change in this PR was necessary: heapZone and virtualZone became new vestiges of global mutable state since they each had a new namespace (the used keys) associated with them. This was not Jessie-safe and introduced many name conflicts in actual code (especially in concurrent testing), so I removed them and replaced them with makeHeapZone() and makeVirtualZone() to make them more POLA-friendly and segregate their scope.

Scaling Considerations

Documentation Considerations

Testing Considerations

@michaelfig michaelfig marked this pull request as ready for review June 7, 2023 02:16
@erights
Copy link
Member

erights commented Jun 7, 2023

A breaking change in this PR was necessary

Agreed. But doesn't this mean the title should be feat(zone)! ... ?

@michaelfig michaelfig changed the title feat(zone): implement zone.makeOnce(key, maker) feat(zone)!: implement zone.makeOnce(key, maker) Jun 7, 2023
@michaelfig
Copy link
Member Author

A breaking change in this PR was necessary

Agreed. But doesn't this mean the title should be feat(zone)! ... ?

Yes. When I squash the commits (one of them has the breaking change bang) I'll also update the commit messages.

packages/zone/src/make-once.js Outdated Show resolved Hide resolved
packages/zone/src/make-once.js Outdated Show resolved Hide resolved
packages/zone/src/make-once.js Outdated Show resolved Hide resolved
packages/zone/src/make-once.js Outdated Show resolved Hide resolved
packages/zone/src/virtual.js Outdated Show resolved Hide resolved
packages/zone/src/heap.js Outdated Show resolved Hide resolved
packages/zone/src/durable.js Show resolved Hide resolved
packages/zone/src/virtual.js Outdated Show resolved Hide resolved
packages/vats/src/vat-agoricNames.js Outdated Show resolved Hide resolved
packages/zone/src/make-once.js Outdated Show resolved Hide resolved
packages/zone/src/durable.js Show resolved Hide resolved
packages/zone/src/heap.js Outdated Show resolved Hide resolved
Copy link
Member

@erights erights left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More testing? I see only test-make-once.js . IIUC, it tests only makeOnce and isStorable.

I mean, not just in this PR, but in the zone/test directory that would result from this PR. IOW, prior testing situation was thin.

@erights
Copy link
Member

erights commented Jun 21, 2023

See endojs/endo#1648 , which I assigned to myself.

I will continue the review under the assumption we expect endojs/endo#1648 to be fixed shortly after this PR. Thus, this PR should behave sensibly both before and afterwards, but be designed for the world in which endojs/endo#1648 has been fixed.

Copy link
Member

@mhofman mhofman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am concerned about the upgradability of this change, but then I don't really know how to solve the problem either.

I think we half painted ourselves in a corner with the prepare and zone abstractions.

At the lowest level, kind handles are the unique identity representing a durable class definition, and it's up to the contract code to stash it in baggage and reconnect the definitions on restart. The code has full control over the process.

What the prepare and zone abstractions do is hide the handles and automatically store them in a location derived from the definition. However this removes the flexibility to restructure the code and update the definition, such as renaming the class, or switching from the provide pattern to the zone mechanism.

We should have a discussion about what transition use case we want to support, and how.

packages/zone/src/durable.js Show resolved Hide resolved
Copy link
Member

@erights erights left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found some problems that I think need to be fixed. However, I'm too tired now to try to write them up. It looks like I'll be able to focus on this for most of tomorrow.

Requesting changes for now just as an interlock, so it's not accidentally merged before I write these down.

Copy link
Member

@erights erights left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my suggestions at #7971

michaelfig pushed a commit that referenced this pull request Jun 23, 2023
@michaelfig michaelfig requested a review from erights June 27, 2023 21:40
Copy link
Member

@erights erights left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, somehow I thought I'd already approved this.

LGTM!!

@michaelfig michaelfig marked this pull request as draft July 2, 2023 20:33
@michaelfig
Copy link
Member Author

Putting back into draft until more tests are written.

@erights
Copy link
Member

erights commented Jul 5, 2023

#7116 raises an additional question about this PR:

When switching durable state in the obvious manner from a pre-zone baggage-based API to a zone-based one, is the resulting durable state exactly the same? If not, what are the implications for upgrade? Should we have a test for upgrade of code using pre-zone baggage to zone, such as #7116 ? How would we write such a test?

Attn @warner @FUDCo @dckc

michaelfig pushed a commit that referenced this pull request Jul 19, 2023
@michaelfig michaelfig force-pushed the mfig-zone-make-once branch 3 times, most recently from 990098b to 0e6ce59 Compare July 19, 2023 22:28
Base automatically changed from 8012-refactor-liveslots-vatstore-usage to master July 19, 2023 23:50
Copy link
Member

@erights erights left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Looking forward to using this a lot!

Comment on lines +35 to +36
* Ensure the wrapped function is only called once per incarnation. It is
* expected to update the backing store directly.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, per wrapper, where each call to wrapProvider creates a fresh wrapper. I want to avoid the misunderstanding that the "ensure" is based on the identity of the provide function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I'll make note of that next time I'm in the vicinity.

@michaelfig michaelfig added this pull request to the merge queue Jul 25, 2023
Merged via the queue into master with commit 8baf0aa Jul 25, 2023
59 checks passed
@michaelfig michaelfig deleted the mfig-zone-make-once branch July 25, 2023 22:36
mhofman pushed a commit that referenced this pull request Aug 7, 2023
mhofman pushed a commit that referenced this pull request Aug 7, 2023
feat(zone)!: implement `zone.makeOnce(key, maker)`
anilhelvaci pushed a commit to anilhelvaci/agoric-sdk that referenced this pull request Aug 16, 2023
anilhelvaci pushed a commit to Jorge-Lopes/agoric-sdk that referenced this pull request Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants