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(swingset): allow buildRootObject to return a Promise #5250

Merged
merged 1 commit into from
Apr 29, 2022

Conversation

warner
Copy link
Member

@warner warner commented Apr 29, 2022

New (or upgraded) vats are defined by a user-provided
buildRootObject function. This function has two responsibilities:

  • provide a root object
  • use defineDurableKind to bind behavior to any pre-existing durable
    kinds

Previously, buildRootObject was given exactly one "turn" to fulfill
these responsibilities: it was required to return the root object
synchronously. If it returned a Promise, that was rejected as an
error.

This requirement is at odds with the needs for updated ZCF vats to
evaluate their contract code and interact with it (giving the contract
a chance to bind their own Kind behavior). The importBundle function
we use to load contracts is async. However, it is still "prompt": it
needs no IO, nor any messages leaving the vat. So it will still
complete within the crank, just not synchronously within the turn.

So this commit changes liveslots to allow buildRootObject to return
a Promise for the root object. The requirement, however, is that this
Promise must resolve by the end of the initial crank (before
waitUntilQuiescent / setImmediate determines that the promise
queue is empty). If the Promise is not fulfilled by then, the vat
creation/update is considered broken.

closes #5246

New (or upgraded) vats are defined by a user-provided
`buildRootObject` function. This function has two responsibilities:

* provide a root object
* use `defineDurableKind` to bind behavior to any pre-existing durable
  kinds

Previously, `buildRootObject` was given exactly one "turn" to fulfill
these responsibilities: it was required to return the root object
synchronously. If it returned a Promise, that was rejected as an
error.

This requirement is at odds with the needs for updated ZCF vats to
evaluate their contract code and interact with it (giving the contract
a chance to bind their own Kind behavior). The `importBundle` function
we use to load contracts is async. However, it is still "prompt": it
needs no IO, nor any messages leaving the vat. So it will still
complete within the *crank*, just not synchronously within the turn.

So this commit changes liveslots to allow `buildRootObject` to return
a Promise for the root object. The requirement, however, is that this
Promise must resolve by the end of the initial crank (before
`waitUntilQuiescent` / `setImmediate` determines that the promise
queue is empty). If the Promise is not fulfilled by then, the vat
creation/update is considered broken.

closes #5246
@warner warner added the SwingSet package: SwingSet label Apr 29, 2022
@warner warner requested a review from mhofman April 29, 2022 16:16
@warner warner self-assigned this Apr 29, 2022
@warner
Copy link
Member Author

warner commented Apr 29, 2022

oops, this is a recreation of #5249 , which I accidentally closed by deleting the branch (git push :5246-async-buildrootobject) instead of updating it (git push +5246-async-buildrootobject)

@mhofman could you re-review to satisfy the merge criteria? I added a comment to address your note.

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.

Carrying over previous approval

@warner warner added the automerge:rebase Automatically rebase updates, then merge label Apr 29, 2022
@mergify mergify bot merged commit 90ad757 into master Apr 29, 2022
@mergify mergify bot deleted the 5246-async-buildrootobject branch April 29, 2022 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:rebase Automatically rebase updates, then merge SwingSet package: SwingSet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

async buildRootObject
2 participants