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

Support submitMustFail in DAML Script Service #7076

Merged
merged 6 commits into from
Aug 12, 2020
Merged

Conversation

aherrmann-da
Copy link
Contributor

@aherrmann-da aherrmann-da commented Aug 10, 2020

Closes #7008

Pushes handling of submitMustFail into the DAML script interpreter rather than DAML script itself.

For backwards compatibility we keep the implementation of the old handling around.

Pull Request Checklist

  • Read and understand the contribution guidelines
  • Include appropriate tests
  • Set a descriptive title and thorough description
  • Add a reference to the issue this PR will solve, if appropriate
  • Include changelog additions in one or more commit message bodies between the CHANGELOG_BEGIN and CHANGELOG_END tags
  • Normal production system change, include purpose of change in description

NOTE: CI is not automatically run on non-members pull-requests for security
reasons. The reviewer will have to comment with /AzurePipelines run to
trigger the build.

@aherrmann-da
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link
Contributor

Azure Pipelines successfully started running 1 pipeline(s).

@aherrmann-da
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link
Contributor

Azure Pipelines successfully started running 1 pipeline(s).

Comment on lines +403 to +407
// This branch is superseded by SubmitMustFail below,
// however, it is maintained for backwards
// compatibility with DAML script DARs generated by
// older SDK versions that didn't distinguish Submit
// and SubmitMustFail.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have confirmed that replacing this branch by Future.failed(...) breaks the corresponding compatibility test.

Copy link
Contributor

Choose a reason for hiding this comment

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

We don’t seem to have a submitMustFail in the compat tests. Should we add one?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh nvm, I just saw that you added it 🤦

changelog_begin
changelog_end
Pushes handling of `submitMustFail` into the DAML script interpreter
rather than DAML script itself.
@aherrmann-da aherrmann-da marked this pull request as ready for review August 11, 2020 12:19
Copy link
Contributor

@cocreature cocreature left a comment

Choose a reason for hiding this comment

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

Nice work, thank you! I’d like to understand a bit better if we can get rid of the duplication between submit and submitMustFail but I’m fine with merging this and trying to improve it in a follow-up PR.

Comment on lines +403 to +407
// This branch is superseded by SubmitMustFail below,
// however, it is maintained for backwards
// compatibility with DAML script DARs generated by
// older SDK versions that didn't distinguish Submit
// and SubmitMustFail.
Copy link
Contributor

Choose a reason for hiding this comment

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

We don’t seem to have a submitMustFail in the compat tests. Should we add one?

@@ -463,6 +476,73 @@ class IdeClient(val compiledPackages: CompiledPackages) extends ScriptLedgerClie
Future.fromTry(result)
}

override def submitMustFail(party: SParty, commands: List[ScriptLedgerClient.Command])(
Copy link
Contributor

Choose a reason for hiding this comment

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

I am slightly worried that we are effectively replicating a significant part of the logic of submit. What happens if we replace the whole implementation here by something that catches SError and flips it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By catching SError you mean the SResultError branch? AFAIU that's not enough as we also want to flip in other cases, e.g. on commitTransaction error in SResultScenarioCommit. Conversely we don't always want to recover from Failure, e.g. AFAIU we don't want to recover from Failure(new RuntimeException(s"Unexpected abort: $x")). The other submit implementations use Left for errors that should be caught by submitMustFail but the Left parameter is restricted to StatusRuntimeException which doesn't really work in this case.

An alternative might be to use a more general or a trait associated type instead of StatusRuntimeException and then use Success(Left(_)) in IdeClient.submit for errors that submitMustFail should catch.

Copy link
Contributor

Choose a reason for hiding this comment

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

Side note: SResultScenarioCommit was a bug, fixed in #7089. Doesn’t change anything here.

There are a few cases to consider here:

  1. The future completes successfully. In that case, we want to turn it into a failure.
  2. The future fails with SError. This includes calls to error as well as ScenarioErrorCommitError which we will get back from a failed commit for things like authorization errors.
  3. Other stuff, e.g., the wildcard match at the end which we hope not to hit.

My idea would be to call submit and then handle the three cases.

  1. This is an actual failure. We expected things to fail and they didn’t.
  2. This is the successful case. We expected a failure during submission and we got one.
  3. This is a crash, something went wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I see. That seems to be possible. I've pushed a commit implementing this.

Comment on lines +403 to +407
// This branch is superseded by SubmitMustFail below,
// however, it is maintained for backwards
// compatibility with DAML script DARs generated by
// older SDK versions that didn't distinguish Submit
// and SubmitMustFail.
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh nvm, I just saw that you added it 🤦

Copy link
Contributor

@cocreature cocreature left a comment

Choose a reason for hiding this comment

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

Nice, thanks for simplifying it!

@mergify mergify bot merged commit f764c2f into master Aug 12, 2020
@mergify mergify bot deleted the submit-must-fail branch August 12, 2020 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support submitMustFail in DAML Script Service
3 participants