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

async-flow contracts: patterns for shared state and continuing invitations #9796

Closed
Tracked by #9782
0xpatrickdev opened this issue Jul 29, 2024 · 7 comments · Fixed by #10023
Closed
Tracked by #9782

async-flow contracts: patterns for shared state and continuing invitations #9796

0xpatrickdev opened this issue Jul 29, 2024 · 7 comments · Fixed by #10023
Assignees
Labels
asyncFlow related to membrane-based replay and upgrade of async functions enhancement New feature or request

Comments

@0xpatrickdev
Copy link
Member

0xpatrickdev commented Jul 29, 2024

What is the Problem Being Solved?

As an orchestration contract developer, I would like to be able to write a contract that uses async-flow for continuing invitation offer handlers. The path for this seems unclear until we've carved out some patterns for sharing state between exos.

In a recently written restake contact #9821, it was found that:

  • only the initial offerHandler (on the publicFacet) was able to leverage async-flow
  • continuing invitations need to be provided through an endowed exo, which requires a guest developer to write host code

In a very WIP commit https://github.com/Agoric/agoric-sdk/compare/7df6abefa6460c5ca9a7acc3575f602c53c75960..ca68722f017e7f6ba9c7a9ce4668eb2b5d089239

  • attempting to use async-flow for Restake and CancelRestake handlers (and the WakerHandler)
  • coming up short on patterns for sharing state (orchAccount, repeater) in the context of multiple async-flows
    • also coming up short on a pattern to make asyncFlow that target of an invitationMaker
  • for now, it offers simplified code that can be leveraged as a starting point for making this real

Here are some recent explorations composing exos and continuingOffers that are somewhat, but not entirely relevant to the task at hand:

Description of the Design

TBD

Security Considerations

Scaling Considerations

Test Plan

Upgrade Considerations

@0xpatrickdev 0xpatrickdev added enhancement New feature or request asyncFlow related to membrane-based replay and upgrade of async functions labels Jul 29, 2024
@dckc
Copy link
Member

dckc commented Jul 29, 2024

Did you consider / try makeStateRecord()?

The pattern from sendAnywhere.contract.js seems like it would extend to multiple flows straightforwardly.

@mhofman
Copy link
Member

mhofman commented Jul 29, 2024

makeStateRecord() should be renamed makeGlobalStateRecord(). It only works for endowed state shared between all invocations of a flow, which roughly makes it global like.

@dckc
Copy link
Member

dckc commented Jul 30, 2024

I don't understand. It doesn't seem to be global state at all. makeStateRecord() makes a thingy; you pass the thingy around as usual. What am I missing?

@mhofman
Copy link
Member

mhofman commented Jul 30, 2024

Mark suggested makeSharedStateRecord. The important part in this case is that you pass the recorde during the prepare phase of the flow, and the record is shared by all invocations of the flow.

What this issue requires is state used by multiple flow definition, but more importantly not shared between invocations of the flows. To be more clear, flows A, B and C work with some common state such that invocation A-10 shares state with invocations B-35 and C-42.

In the makeStateRecord case, you have a flow D, where invocation D-1, D-2, D-3 etc all share the same state record.

The endowments mechanism cannot support per invocation objects.

@dckc
Copy link
Member

dckc commented Jul 30, 2024

makeSharedStateRecord works for me.

... the prepare phase of the flow ...

I'm struggling to understand that. OrchestrationFlows are top-level functions; we don't prepare them, do we?

@mhofman
Copy link
Member

mhofman commented Jul 30, 2024

These top level orchestrated functions are used with orchestrate or orchestrateAll which is a prepare action. They are comparable the behavior argument of an Exo that was extracted to top level scope.

@mhofman
Copy link
Member

mhofman commented Aug 2, 2024

Filed #9832 to capture the need to support exo async-flow methods

@turadg turadg self-assigned this Aug 26, 2024
mergify bot added a commit that referenced this issue Sep 5, 2024
refs: #9796 

## Description

#10023 started with a series of refactors and cleanup. This separates those into another PR to be reviewed more rapidly.

It also includes a new feature to orchestrateAll to ease calling flows from flows. Each flow is available on the context object under `flows`.

### Security Considerations
Every flow can call another flow. In the event a developer wants isolate between flows, they won't put them in the same `orchestrateAll`.

### Scaling Considerations
n/a

### Documentation Considerations
none

### Testing Considerations
new tests

### Upgrade Considerations
not yet deployed
@mergify mergify bot closed this as completed in #10023 Sep 6, 2024
mergify bot added a commit that referenced this issue Sep 6, 2024
closes: #9796

## Description
Demonstrates a pattern for creating continuing invitations that have handlers written as orchestration flows.

Builds upon the combine-invitation-makers from #9821

### Security Considerations
None

### Scaling Considerations
Augmenting an existing exo's invitationMaker requires two new ones: the exo holding the other makers and an exo to wrap them both.

### Documentation Considerations
Once this lands it should have an explicit tutorial for developers needing this functionality.

### Testing Considerations
new tests

### Upgrade Considerations
not yet deployed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
asyncFlow related to membrane-based replay and upgrade of async functions enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants