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

implement "callable updates" as "create and exercise" Ledger API command #382

Closed
francesco-da opened this issue Apr 11, 2019 · 8 comments · Fixed by #563
Closed

implement "callable updates" as "create and exercise" Ledger API command #382

francesco-da opened this issue Apr 11, 2019 · 8 comments · Fixed by #563
Labels
component/ledger Sandbox and Ledger API discussion Things to be discussed and decided

Comments

@francesco-da
Copy link
Contributor

Many people have expressed the desire of being able to define "top level updates" in their .daml files that they can call from their application.

While talking to @martin-drhu-da , it occurred to me that we can implement that easily with the existing infrastructure if we add a "CreateAndExercise" command to the Ledger API, which as the name suggests bundles a CreateCommand and ExerciseCommand in one go.

Then, the "top level update" can be implemented as a template that has the submitter party as only argument and signatory, and then a choice (or multiple choices) that contain the argument of the top level update.

cc @martin-drhu-da @neil-da @bame-da @andrae-da @filmackay

@francesco-da francesco-da added component/ledger Sandbox and Ledger API discussion Things to be discussed and decided labels Apr 11, 2019
@francesco-da francesco-da added this to the Backlog milestone Apr 11, 2019
@gerolf-da
Copy link
Contributor

gerolf-da commented Apr 15, 2019

@francesco-da: strictly speaking we cannot reuse the ExerciseCommand directly, because the user cannot fill the contract_id field with a sensible value.

We could add a dedicated "application service" request that ultimately will be converted to a CreateCommand and ExerciseCommand:

message CreateAndExerciseRequest {
  string ledger_id = 1;
  string workflow_id = 2;
  string application_id = 3;

  // should this rather be set by the application service itself?
  // or should this command_id be used for the exercise,
  // so the user could observe the final outcome separately on the
  // completions stream with this command_id
  string command_id = 4;  

  string party = 5;

  // maybe we only want the user to specify a TTL that is then used for both
  // the CreateCommand and the ExerciseCommand
  google.protobuf.Timestamp ledger_effective_time = 6; // 
  google.protobuf.Timestamp maximum_record_time = 7;

  Identifier template_id = 8;
  Record create_arguments = 9;
  string choice = 10;
  Record choice_argument = 11;
}

How do you want to handle failure scenarios?

Create Exercise Overall
Failed - Failed
Successful Failed Retry exercise n times (if applicable), then fail?
Successful Successful Successful, return the transaction tree? (trivial to implement after #406 and #479)

@gerolf-da
Copy link
Contributor

gerolf-da commented Apr 16, 2019

Alternatively, we can implement the CreateAndExercise as an atomic set of LF create and exercise commands, although that means we'd need to open up command translation to relative contract IDs.

Edit: it seems like there are quite a few places in the engine that assumes only absolute contract ids, so we either open up relative contract ids again in general, or we go the compound-api-service route.

@gerolf-da
Copy link
Contributor

Conclusion, similar to translateExercise, we'll create a method that produces an Update expression for both creating the contract and exercising the choice.

@bame-da
Copy link
Contributor

bame-da commented Apr 16, 2019

I'm not sold on the value of this addition. You are saving developers a simple "check for existence and create the Action contract if it doesn't" step in the automation. You still can't get return values from Updates in the application layer and still can't access pure DAML functions.

@gerolf-da
Copy link
Contributor

@bame-da: Return value from exercise is implemented by #479.

@gerolf-da
Copy link
Contributor

you could then execute a pure function (in a slightly round-about way) in terms of a create-and-exercise.

@bame-da
Copy link
Contributor

bame-da commented Apr 16, 2019

Yeah, but you get the side-effect of writing a transaction. Would it be so difficult to flip this around and allow evaluation of functions with serializable arguments and return type a or Update a, where a is serializable?
The semantics would be that functions of type Update a are submitted as a transaction.

gerolf-da added a commit that referenced this issue Apr 17, 2019
The CreateAndExerciseCommand allows users to create a contract and
exercise a choice on it within the same transaction. Users can use this
method to implement "callable update functions" by creating a template
that calls the update function in a choice body.

Fixes #382.
gerolf-da added a commit that referenced this issue Apr 17, 2019
The CreateAndExerciseCommand allows users to create a contract and
exercise a choice on it within the same transaction. Users can use this
method to implement "callable update functions" by creating a template
that calls the update function in a choice body.

Fixes #382.
gerolf-da added a commit that referenced this issue Apr 17, 2019
The CreateAndExerciseCommand allows users to create a contract and
exercise a choice on it within the same transaction. Users can use this
method to implement "callable update functions" by creating a template
that calls the update function in a choice body.

Fixes #382.
gerolf-da added a commit that referenced this issue Apr 17, 2019
The CreateAndExerciseCommand allows users to create a contract and
exercise a choice on it within the same transaction. Users can use this
method to implement "callable update functions" by creating a template
that calls the update function in a choice body.

Fixes #382.
gerolf-da added a commit that referenced this issue Apr 17, 2019
The CreateAndExerciseCommand allows users to create a contract and
exercise a choice on it within the same transaction. Users can use this
method to implement "callable update functions" by creating a template
that calls the update function in a choice body.

Fixes #382.
gerolf-da added a commit that referenced this issue Apr 18, 2019
The CreateAndExerciseCommand allows users to create a contract and
exercise a choice on it within the same transaction. Users can use this
method to implement "callable update functions" by creating a template
that calls the update function in a choice body.

Fixes #382.
gerolf-da added a commit that referenced this issue Apr 18, 2019
The CreateAndExerciseCommand allows users to create a contract and
exercise a choice on it within the same transaction. Users can use this
method to implement "callable update functions" by creating a template
that calls the update function in a choice body.

Fixes #382.
gerolf-da added a commit that referenced this issue Apr 18, 2019
The CreateAndExerciseCommand allows users to create a contract and
exercise a choice on it within the same transaction. Users can use this
method to implement "callable update functions" by creating a template
that calls the update function in a choice body.

Fixes #382.
gerolf-da added a commit that referenced this issue Apr 18, 2019
The CreateAndExerciseCommand allows users to create a contract and
exercise a choice on it within the same transaction. Users can use this
method to implement "callable update functions" by creating a template
that calls the update function in a choice body.

Fixes #382.
bitonic pushed a commit that referenced this issue Apr 18, 2019
The CreateAndExerciseCommand allows users to create a contract and
exercise a choice on it within the same transaction. Users can use this
method to implement "callable update functions" by creating a template
that calls the update function in a choice body.

Fixes #382.
mergify bot pushed a commit that referenced this issue Apr 18, 2019
* Add release notes entry

* Add CreateAndExercise command to Java Bindings data layer

* Add CreateAndExercise command to DAMLe

The CreateAndExerciseCommand allows users to create a contract and
exercise a choice on it within the same transaction. Users can use this
method to implement "callable update functions" by creating a template
that calls the update function in a choice body.

Fixes #382.

* Add CreateAndExercise command handling to the sandbox

* Add CreateAndExercise command to the Ledger API
@bitonic
Copy link
Contributor

bitonic commented Apr 25, 2019

done, see #563

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/ledger Sandbox and Ledger API discussion Things to be discussed and decided
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants