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

Prohibit contract IDs in contract keys and add key maintainers to exercises #4048

Merged
merged 14 commits into from
Jan 20, 2020

Conversation

oggy-
Copy link
Contributor

@oggy- oggy- commented Jan 14, 2020

As discussed with @bame-da @remyhaemmerle-da and @gerolf-da , this completely removes the support for contract IDs in contract keys. This is a backwards incompatible change, but lookupByKey already didn't support such keys, so it is unlikely that this was used.

Additionally, this adds key maintainers to NodeExercises. I also took the opportunity to remove some duplication in the compiler around keys and maintainers.

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.

@oggy-
Copy link
Contributor Author

oggy- commented Jan 14, 2020

Mmm, OK, I'm getting some CI errors that I can't make sense of, I will figure it out tomorrow and reopen the PR

@oggy- oggy- closed this Jan 14, 2020
…rcises

CHANGELOG_BEGIN

- [DAML-LF] Prohibit contract IDs in contract keys completely. Previously, creating keys containing absolute (but not relative) contract IDs was allowed, but `lookupByKey` on such a key would crash. Minor backwards incompatibility.

CHANGELOG_END
@oggy- oggy- reopened this Jan 14, 2020
@digitalasset-cla
Copy link
Member

digitalasset-cla commented Jan 14, 2020

CLA assistant check
All committers have signed the CLA.

@oggy- oggy- force-pushed the add-key-maintainers-to-exercises branch from 1f1c197 to 1d1f228 Compare January 14, 2020 20:30
Copy link
Collaborator

@remyhaemmerle-da remyhaemmerle-da 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.
Though, I would like that @S11001001 takes a look at transaction encoding code.

@@ -59,6 +59,7 @@ private[digitalasset] object VersionTimeline {
// * change the following line when LF 1.8 is frozen.
// * do not insert line after this once until 1.8 is frozen.
This(This(ValueVersion("7"))),
This(That(TransactionVersion("9"))),
Copy link
Collaborator

@remyhaemmerle-da remyhaemmerle-da Jan 15, 2020

Choose a reason for hiding this comment

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

Move this line before the FIXME comment. between line 57 and 58.
It is fine since GenMap (the only addition to value version 7) has never been release.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed now

()
}
case (None, _) | (Some(_), true) =>
case (None, _, _) | (Some(_), true, _) =>
Right(())
Copy link
Collaborator

Choose a reason for hiding this comment

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

[Cosmetic]
I found this pattern matching with booleans a bit confusing.
I woul prefer something like

  _ <- e.key match {
            case Some(KeyWithMaintainers(k, maintainers))
                if !(transactionVersion precedes minContractKeyInExercise) =>
              if ((transactionVersion precedes minMaintainersInExercise) && maintainers.nonEmpty)
                Left(EncodeError(transactionVersion, isTooOldFor = "maintainers in NodeExercises"))
              else
                encodeVal(k).map { encodedKey =>
                  exBuilder.setContractKey(encodedKey._2)
                  exBuilder.addAllKeyMaintainers(maintainers.toSet[String].asJava)
                  ()
                }
            case _ =>
              Right(())
          }

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 also messed up the logic here. I also changed the style now but I'm ambivalent to that.

@@ -232,9 +239,9 @@ object TransactionCoder {
keyWithMaintainers: TransactionOuterClass.KeyWithMaintainers)
: Either[DecodeError, KeyWithMaintainers[Val]] =
for {
mainteners <- toPartySet(keyWithMaintainers.getMaintainersList)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator

@remyhaemmerle-da remyhaemmerle-da left a comment

Choose a reason for hiding this comment

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

Please change the order of This(That(TransactionVersion("9"))) in VersionTimeline.

@@ -55,6 +55,7 @@ private[digitalasset] object VersionTimeline {
This(That(TransactionVersion("8"))),
Both(This(ValueVersion("5")), LanguageVersion(LMV.V1, "6")),
Both(This(ValueVersion("6")), LanguageVersion(LMV.V1, "7")),
This(That(TransactionVersion("9"))),
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@S11001001 S11001001 left a comment

Choose a reason for hiding this comment

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

To be clear, you intend to invalidate prior valid transactions with contract IDs in contract keys. I am not really comfortable with this, but will defer to @remyhaemmerle-da's judgement.

As defined, it would be improper to only mention this restriction in a since version 9 section in transaction.rst (as commented elserwhere), since you are imposing the restriction retroactively.

@@ -315,6 +322,8 @@ class TransactionCoderSpec
(x: GenNode[Nid, Cid, Val]) => withoutExerciseResult(withoutContractKeyInExercise(x)))
else if (txvMin precedes minContractKeyInExercise)
transactionWithout(tx, (x: GenNode[Nid, Cid, Val]) => withoutContractKeyInExercise(x))
else if (txvMin precedes minMaintainersInExercise)
transactionWithout(tx, (x: GenNode[Nid, Cid, Val]) => withoutMaintainersInExercise(x))
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to do withoutMaintainersInExercise in both prior if branches (see how withoutContractKeyInExercise is also done in the branch prior its precedence test), or (ideally) reorganize this function so the precedence tests are independent of each other.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added and reorganized. Less efficient when no changes need to be done, but this is test code.

@@ -503,6 +505,11 @@ Containing the result of the exercised choice.
New optional field `contract_key` is now set when the exercised
contract has a contract key defined.
Copy link
Contributor

Choose a reason for hiding this comment

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

Restriction on key contents must be mentioned here, and also under message KeyWithMaintainers.

Incidentally, it would be cleaner to use message KeyWithMaintainers instead of adding field key_maintainers as well, but I'll let @remyhaemmerle-da speak on that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added and using KeyWithMaintainers now.

Copy link
Contributor

Choose a reason for hiding this comment

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

The restriction still must be mentioned here, because this part does not use KeyWithMaintainers, even though it will in version 9.

@oggy- oggy- requested a review from S11001001 January 16, 2020 11:39

The key may not contain contract IDs. This change is backwards
incompatible; that is, transactions containing contract IDs in keys
cannot be deserialized any more.
Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned in a previous comment

it would be improper to only mention this restriction in a since version 9 section in transaction.rst (as commented elsewhere), since you are imposing the restriction retroactively.

That's because you can always read the spec such that if you are dealing with version n, you can ignore all sections since version e where e > n; that is not the case here.

Effectively, the restriction you are introducing is since version 3, in other words, on all KeyWithMaintainers.

@@ -503,6 +505,11 @@ Containing the result of the exercised choice.
New optional field `contract_key` is now set when the exercised
contract has a contract key defined.
Copy link
Contributor

Choose a reason for hiding this comment

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

The restriction still must be mentioned here, because this part does not use KeyWithMaintainers, even though it will in version 9.

@oggy- oggy- requested a review from S11001001 January 16, 2020 15:32
Copy link
Contributor

@S11001001 S11001001 left a comment

Choose a reason for hiding this comment

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

With these changes we make clear that the new restriction is not associated with version 9.

daml-lf/spec/transaction.rst Outdated Show resolved Hide resolved
daml-lf/spec/transaction.rst Show resolved Hide resolved
daml-lf/spec/transaction.rst Outdated Show resolved Hide resolved
daml-lf/spec/transaction.rst Outdated Show resolved Hide resolved
Co-Authored-By: Stephen Compall <stephen.compall@daml.com>
Copy link
Collaborator

@remyhaemmerle-da remyhaemmerle-da left a comment

Choose a reason for hiding this comment

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

Need futher discussion with me and @gerolf-da

Copy link
Collaborator

@remyhaemmerle-da remyhaemmerle-da left a comment

Choose a reason for hiding this comment

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

Please add to the changelog something to explain the change in contract key.
Thanks for the help.

@oggy- oggy- merged commit 589f710 into master Jan 20, 2020
@oggy- oggy- deleted the add-key-maintainers-to-exercises branch January 20, 2020 15:36
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.

4 participants