-
Notifications
You must be signed in to change notification settings - Fork 206
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
Conversation
@andreaslochbihler-da , @simonmaxen-da Do the function |
daml-lf/transaction/src/main/scala/com/digitalasset/daml/lf/transaction/Util.scala
Outdated
Show resolved
Hide resolved
daml-lf/transaction/src/main/scala/com/digitalasset/daml/lf/transaction/Effects.scala
Outdated
Show resolved
Hide resolved
daml-lf/transaction/src/main/scala/com/digitalasset/daml/lf/transaction/Effects.scala
Outdated
Show resolved
Hide resolved
daml-lf/transaction/src/main/scala/com/digitalasset/daml/lf/transaction/Inputs.scala
Outdated
Show resolved
Hide resolved
daml-lf/transaction/src/main/scala/com/digitalasset/daml/lf/transaction/Inputs.scala
Outdated
Show resolved
Hide resolved
daml-lf/transaction/src/main/scala/com/digitalasset/daml/lf/transaction/Inputs.scala
Outdated
Show resolved
Hide resolved
* 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
daml-lf/transaction/src/main/scala/com/digitalasset/daml/lf/transaction/Util.scala
Outdated
Show resolved
Hide resolved
|
||
case exe: Node.NodeExercises[NodeId, Value.ContractId] => | ||
addContractInput(exe.targetCoid) | ||
exe.key.foreach(addContractKey(exe.templateId, _)) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
CHANGELOG_BEGIN CHANGELOG_END
be30419
to
a547fa1
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 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. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** 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 */ |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* The contract keys created, exercise, fetched or lookup or updated | |
* The contract keys created, exercised, fetched, looked up or updated |
/** Compute the inputs to a DAML transaction (in traversal order), that is, the referenced contracts, parties, | ||
* and key. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** 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 = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def contractKeyToStateKey(tmplId: Identifier, key: Value[ContractId]): DamlStateKey = | |
def contractKeyToStateKey(templateId: Identifier, key: Value[ContractId]): DamlStateKey = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
import scala.collection.immutable.{TreeMap, TreeSet} | ||
|
||
/** The effects of a transaction, that is: |
There was a problem hiding this comment.
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)); () }, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
implicit val ordering = Ordering.by[GlobalKey, crypto.Hash](_.hash) | |
implicit val ordering: Ordering[GlobalKey] = Ordering.by(_.hash) |
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
CHANGELOG_BEGIN
andCHANGELOG_END
tagsNOTE: CI is not automatically run on non-members pull-requests for security
reasons. The reviewer will have to comment with
/AzurePipelines run
totrigger the build.