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

LF: Move KV's InputsAndEffects to LF land #9361

Closed
wants to merge 4 commits into from

Conversation

remyhaemmerle-da
Copy link
Collaborator

@remyhaemmerle-da remyhaemmerle-da commented Apr 8, 2021

We move the code from computing from KV to LF.
Testing + more refactoring will follows in subsequent PRs.

CHANGELOG_BEGIN
CHANGELOG_END

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.

@remyhaemmerle-da
Copy link
Collaborator Author

@andreaslochbihler-da , @simonmaxen-da Do the function computeInputs and `computeEffects' are usefull for you ?

* contracts should be created. The key should be a combination of the transaction
* id and the relative contract id (that is, the node index).
* @param keys
* The contract keys created or updated as part of the transaction.
Copy link
Contributor

Choose a reason for hiding this comment

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

This information is not enough to check the preconditions of a transaction w.r.t. the ledger state. For example, it's not clear whether the keys should be unassigned or assigned at the beginning of the transaction.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I need this to.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

andreaslochbihler-da

This information is not enough to check the preconditions of a transaction w.r.t. the ledger state. For example, it's not clear > whether the keys should be unassigned or assigned at the beginning of the transaction.

Let's tackle that in an upcoming PR.

@remyhaemmerle-da remyhaemmerle-da requested a review from a user April 8, 2021 15:10

case exe: Node.NodeExercises[NodeId, Value.ContractId] =>
addContractInput(exe.targetCoid)
exe.key.foreach(addContractKey(exe.templateId, _))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you have to add the key to the inputs if the byKey flag is not set?

Copy link
Collaborator Author

@remyhaemmerle-da remyhaemmerle-da Apr 8, 2021

Choose a reason for hiding this comment

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

We don't. If the byKey flag is not set, then exe.key = None.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Let's postpone semantics consideration to another PR.
For now, I just move the code around keeping as much as possible the original behavior of the utility as defined in KV.

Copy link
Contributor

@andreaslochbihler-da andreaslochbihler-da left a comment

Choose a reason for hiding this comment

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

I don't think these functions are particularly useful for Canton as is.

@remyhaemmerle-da remyhaemmerle-da marked this pull request as draft April 8, 2021 15:53
@remyhaemmerle-da remyhaemmerle-da force-pushed the remy-lf-inputs-and-effects branch from be30419 to a547fa1 Compare April 15, 2021 09:28
Copy link
Contributor

@miklos-da miklos-da left a comment

Choose a reason for hiding this comment

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

Looks good overall, thanks, @remyhaemmerle-da!

* @param contracts
* The contracts fetched or looked up by the transaction.
* @param parties
* The union of the informees of all the nodes of the transaction
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* The union of the informees of all the nodes of the transaction
* The union of the informees of all the nodes of the transaction.


val Empty = Effects(TreeSet.empty, TreeMap.empty, TreeMap.empty)

/** Compute the effects of a DAML transaction, that is, the created and consumed contracts. */
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/** Compute the effects of a DAML transaction, that is, the created and consumed contracts. */
/** Compute the effects of a Daml transaction, that is, the created and consumed contracts. */

updatedContractKeys: TreeMap[GlobalKey, Option[ContractId]],
)

/** utilities to compute the effects of a DAML transaction */
Copy link
Contributor

Choose a reason for hiding this comment

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

Feel free to remove this comment (i.e., there's only a single method here which is well-documented).

* @param parties
* The union of the informees of all the nodes of the transaction
* @param keys
* The contract keys created, exercise, fetched or lookup or updated
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* The contract keys created, exercise, fetched or lookup or updated
* The contract keys created, exercised, fetched, looked up or updated

Comment on lines +29 to +30
/** Compute the inputs to a DAML transaction (in traversal order), that is, the referenced contracts, parties,
* and key.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/** Compute the inputs to a DAML transaction (in traversal order), that is, the referenced contracts, parties,
* and key.
/** Compute the inputs to a Daml transaction (in traversal order), that is, the referenced contracts, parties,
* and keys.


def globalKeyToStateKey(key: GlobalKey): DamlStateKey = {
DamlStateKey.newBuilder
.setContractKey(encodeGlobalKey(key))
.build
}

def contractKeyToStateKey(tmplId: Identifier, key: Value[ContractId]): DamlStateKey =
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def contractKeyToStateKey(tmplId: Identifier, key: Value[ContractId]): DamlStateKey =
def contractKeyToStateKey(templateId: Identifier, key: Value[ContractId]): DamlStateKey =

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I applied this in #9429 and #9433


import scala.collection.immutable.{TreeMap, TreeSet}

/** The effects of a transaction, that is:
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the comments in the original InputsAndEffects.Effects regarding semantics of consumed/create contracts captured somewhere else in the code?

val inputDamlStatesFromTx = new util.ArrayList[DamlStateKey]()
transaction.Inputs.collectInputs(
tx,
{ cid => inputDamlStatesFromTx.add(Conversions.contractIdToStateKey(cid)); () },
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use native Scala types here for improving readability and calling .asJava when constructing the protobuf message?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I apply the suggestion in #9429

@@ -1,7 +1,8 @@
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package com.daml.ledger.participant.state
package com.daml
Copy link
Contributor

Choose a reason for hiding this comment

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

Please revert this change. We don't use this package notation in kvutils.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I revert this change in #9433

@@ -39,6 +39,8 @@ object GlobalKey {
@throws[IllegalArgumentException]
def assertBuild(templateId: Ref.TypeConName, key: Value[ContractId]): GlobalKey =
data.assertRight(build(templateId, key))

implicit val ordering = Ordering.by[GlobalKey, crypto.Hash](_.hash)
Copy link

Choose a reason for hiding this comment

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

I think this might work and it's a little terser.

Suggested change
implicit val ordering = Ordering.by[GlobalKey, crypto.Hash](_.hash)
implicit val ordering: Ordering[GlobalKey] = Ordering.by(_.hash)

@remyhaemmerle-da remyhaemmerle-da deleted the remy-lf-inputs-and-effects branch April 16, 2021 14:11
@remyhaemmerle-da
Copy link
Collaborator Author

subsumed by #9429 and #9433

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants