Skip to content

Commit

Permalink
LF: Rename GenTransaction to Transaction (#11599)
Browse files Browse the repository at this point in the history
* LF: Rename GenTransaction to Transaction

Following up #10827 and #10921 that drop type parameters from GenNode,
we rename GenTransaction to Transaction.

CHANGELOG_BEGIN
CHANGELOG_END

* fix

* a bit more fixes
  • Loading branch information
remyhaemmerle-da authored Nov 9, 2021
1 parent 3b61a1b commit a7559d0
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package com.daml.lf.engine
import com.daml.lf.data._
import com.daml.lf.data.Ref.Party
import com.daml.lf.transaction.Node
import com.daml.lf.transaction.{BlindingInfo, GenTransaction, NodeId, VersionedTransaction}
import com.daml.lf.transaction.{BlindingInfo, Transaction, NodeId, VersionedTransaction}
import com.daml.lf.ledger._
import com.daml.lf.data.Relation.Relation

Expand Down Expand Up @@ -43,8 +43,8 @@ object Blinding {
def divulgedTransaction(
divulgences: Relation[NodeId, Party],
party: Party,
tx: GenTransaction,
): GenTransaction = {
tx: Transaction,
): Transaction = {
val partyDivulgences = Relation.invert(divulgences)(party)
// Note that this relies on the local divulgence to be well-formed:
// if an exercise node is divulged to A but some of its descendants
Expand Down Expand Up @@ -74,7 +74,7 @@ object Blinding {
}
}

GenTransaction(
Transaction(
roots = go(BackStack.empty, tx.roots.toFrontStack),
nodes = filteredNodes,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.daml.lf.data.Ref.{Identifier, Name, PackageId}
import com.daml.lf.language.{Ast, LookupError}
import com.daml.lf.transaction.{
IncompleteTransaction,
GenTransaction,
Transaction,
Node,
NodeId,
VersionedTransaction,
Expand Down Expand Up @@ -174,7 +174,7 @@ final class ValueEnricher(
} yield exe.copy(chosenValue = choiceArg, exerciseResult = result, key = key)
}

def enrichTransaction(tx: GenTransaction): Result[GenTransaction] =
def enrichTransaction(tx: Transaction): Result[Transaction] =
for {
normalizedNodes <-
tx.nodes.foldLeft[Result[Map[NodeId, Node]]](ResultDone(Map.empty)) {
Expand All @@ -184,14 +184,14 @@ final class ValueEnricher(
normalizedNode <- enrichNode(node)
} yield nodes.updated(nid, normalizedNode)
}
} yield GenTransaction(
} yield Transaction(
nodes = normalizedNodes,
roots = tx.roots,
)

def enrichVersionedTransaction(versionedTx: VersionedTransaction): Result[VersionedTransaction] =
enrichTransaction(GenTransaction(versionedTx.nodes, versionedTx.roots)).map {
case GenTransaction(nodes, roots) =>
enrichTransaction(Transaction(versionedTx.nodes, versionedTx.roots)).map {
case Transaction(nodes, roots) =>
VersionedTransaction(versionedTx.version, nodes, roots)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import com.daml.lf.transaction.{
NodeId,
SubmittedTransaction,
VersionedTransaction,
GenTransaction => GenTx,
Transaction => Tx,
TransactionVersion => TxVersions,
}
Expand Down Expand Up @@ -1196,7 +1195,7 @@ class EngineTest
}
}

def txFetchActors(tx: GenTx): Set[Party] =
def txFetchActors(tx: Tx): Set[Party] =
tx.fold(Set[Party]()) { case (actors, (_, n)) =>
actors union actFetchActors(n)
}
Expand Down Expand Up @@ -1369,9 +1368,7 @@ class EngineTest
lookerUpCid -> lookerUpInst,
)

def firstLookupNode(
tx: GenTx
): Option[(NodeId, Node.LookupByKey)] =
def firstLookupNode(tx: Tx): Option[(NodeId, Node.LookupByKey)] =
tx.nodes.collectFirst { case (nid, nl @ Node.LookupByKey(_, _, _, _)) =>
nid -> nl
}
Expand Down Expand Up @@ -2213,7 +2210,7 @@ object EngineTest {
dependsOnTime: Boolean = false,
nodeSeeds: BackStack[(NodeId, crypto.Hash)] = BackStack.empty,
) {
def commit(tr: GenTx, meta: Tx.Metadata) = {
def commit(tr: Tx, meta: Tx.Metadata) = {
val (newContracts, newKeys) = tr.fold((contracts, keys)) {
case ((contracts, keys), (_, exe: Node.Exercise)) =>
(contracts - exe.targetCoid, keys)
Expand Down Expand Up @@ -2306,10 +2303,7 @@ object EngineTest {
finalState.map(state =>
(
TxVersions.asVersionedTransaction(
GenTx(
state.nodes,
state.roots.toImmArray,
)
Tx(state.nodes, state.roots.toImmArray)
),
Tx.Metadata(
submissionSeed = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ import com.daml.bazeltools.BazelRunfiles
import com.daml.lf.data.Ref._
import com.daml.lf.data._
import com.daml.lf.language.Ast._
import com.daml.lf.transaction.{
GlobalKeyWithMaintainers,
NodeId,
GenTransaction,
SubmittedTransaction,
}
import com.daml.lf.transaction.{GlobalKeyWithMaintainers, NodeId, Transaction, SubmittedTransaction}
import com.daml.lf.transaction.Node.{NodeRollback, NodeExercises, NodeCreate}
import com.daml.lf.value.Value._
import com.daml.lf.command._
Expand Down Expand Up @@ -193,7 +188,7 @@ object ReinterpretTest {
final case class Rollback(x: List[Shape]) extends Shape
final case class Create() extends Shape

def ofTransaction(tx: GenTransaction): Top = {
def ofTransaction(tx: Transaction): Top = {
def ofNid(nid: NodeId): Shape = {
tx.nodes(nid) match {
case node: NodeExercises => Exercise(node.children.toList.map(ofNid))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
package com.daml.lf
package speedy

import com.daml.lf.transaction.{NodeId, GenTransaction}
import com.daml.lf.transaction.{NodeId, Transaction}
import com.daml.lf.transaction.Node
import com.daml.lf.data.{BackStack, ImmArray}
import com.daml.lf.data.Trampoline.{Bounce, Land, Trampoline}

private[lf] object NormalizeRollbacks {

private[this] type TX = GenTransaction
private[this] type TX = Transaction

// Normalize a transaction so rollback nodes satisfy the normalization rules.
// see `makeRoll` below
Expand All @@ -30,7 +30,7 @@ private[lf] object NormalizeRollbacks {
// (1) drop nodes; (2) combine nodes (3) lift nodes from a lower level to a higher level.

txOriginal match {
case GenTransaction(nodesOriginal, rootsOriginal) =>
case Transaction(nodesOriginal, rootsOriginal) =>
def traverseNodeIds[R](
xs: List[NodeId]
)(k: Vector[Norm] => Trampoline[R]): Trampoline[R] = {
Expand Down Expand Up @@ -74,7 +74,7 @@ private[lf] object NormalizeRollbacks {
pushNorms(initialState, norms.toList) { (finalState, roots) =>
Land(
(
GenTransaction(finalState.nodeMap, roots.to(ImmArray)),
Transaction(finalState.nodeMap, roots.to(ImmArray)),
finalState.seedIds.toImmArray,
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.daml.lf.data.{BackStack, ImmArray, Ref, Time}
import com.daml.lf.ledger.{Authorize, FailedAuthorization}
import com.daml.lf.transaction.{
ContractKeyUniquenessMode,
GenTransaction,
GlobalKey,
Node,
NodeId,
Expand Down Expand Up @@ -325,7 +324,7 @@ private[speedy] case class PartialTransaction(

nodes.keySet diff allChildNodeIds
}
val tx = GenTransaction(nodes, rootNodes.to(ImmArray))
val tx = Tx(nodes, rootNodes.to(ImmArray))

tx.foreach { (nid, node) =>
val rootPrefix = if (rootNodes.contains(nid)) "root " else ""
Expand Down Expand Up @@ -370,7 +369,7 @@ private[speedy] case class PartialTransaction(
context.info match {
case _: RootContextInfo if aborted.isEmpty =>
val roots = context.children.toImmArray
val tx0 = GenTransaction(nodes, roots)
val tx0 = Tx(nodes, roots)
val (tx, seeds) = NormalizeRollbacks.normalizeTx(tx0)
CompleteTransaction(
SubmittedTransaction(
Expand All @@ -389,7 +388,7 @@ private[speedy] case class PartialTransaction(
val ptx = unwind()

transaction.IncompleteTransaction(
GenTransaction(
Tx(
ptx.nodes,
ptx.context.children.toImmArray.toSeq.sortBy(_.index).toImmArray,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.daml.lf.data.Ref
import com.daml.lf.transaction.Node
import com.daml.lf.transaction.Transaction.LeafNode
import com.daml.lf.transaction.TransactionVersion
import com.daml.lf.transaction.{NodeId, GenTransaction}
import com.daml.lf.transaction.{NodeId, Transaction}
import com.daml.lf.value.{Value => V}

class NormalizeRollbacksSpec extends AnyWordSpec with Matchers with Inside {
Expand Down Expand Up @@ -172,7 +172,7 @@ class NormalizeRollbacksSpec extends AnyWordSpec with Matchers with Inside {
object NormalizeRollbackSpec {

type Cid = V.ContractId
type TX = GenTransaction
type TX = Transaction

def preOrderNidsOfTxIsIncreasingFromZero(tx: TX): Boolean = {
def check(x1: Int, xs: List[Int]): Boolean = {
Expand Down Expand Up @@ -221,7 +221,7 @@ object NormalizeRollbackSpec {

def isNormalized(tx: TX): Boolean = {
tx match {
case GenTransaction(nodes, _) =>
case Transaction(nodes, _) =>
def isRB(node: Node): Boolean = {
node match {
case _: Node.Rollback => true
Expand Down Expand Up @@ -269,7 +269,7 @@ object NormalizeRollbackSpec {
}
}
val roots: List[NodeId] = top.xs.map(toNid)
GenTransaction(nodes, roots.to(ImmArray))
Transaction(nodes, roots.to(ImmArray))
}

def ofTransaction(tx: TX): Top = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ package test

import com.daml.lf.data.Ref._
import com.daml.lf.data._
import com.daml.lf.transaction.{
GenTransaction,
Node,
NodeId,
TransactionVersion,
VersionedTransaction,
}
import com.daml.lf.transaction.{Transaction, Node, NodeId, TransactionVersion, VersionedTransaction}
import com.daml.lf.transaction.test.TransactionBuilder
import com.daml.lf.value.Value._
import org.scalacheck.{Arbitrary, Gen}
Expand Down Expand Up @@ -485,11 +479,11 @@ object ValueGenerators {
*
* This list is complete as of transaction version 5. -SC
*/
val malformedGenTransaction: Gen[GenTransaction] = {
val malformedGenTransaction: Gen[Transaction] = {
for {
nodes <- Gen.listOf(danglingRefGenNode)
roots <- Gen.listOf(Arbitrary.arbInt.arbitrary.map(NodeId(_)))
} yield GenTransaction(nodes.toMap, roots.to(ImmArray))
} yield Transaction(nodes.toMap, roots.to(ImmArray))
}

/*
Expand All @@ -503,7 +497,7 @@ object ValueGenerators {
*
*/

val noDanglingRefGenTransaction: Gen[GenTransaction] = {
val noDanglingRefGenTransaction: Gen[Transaction] = {

def nonDanglingRefNodeGen(
maxDepth: Int,
Expand Down Expand Up @@ -557,7 +551,7 @@ object ValueGenerators {
}

nonDanglingRefNodeGen(3, NodeId(0)).map { case (nodeIds, nodes) =>
GenTransaction(nodes, nodeIds)
Transaction(nodes, nodeIds)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ package transaction
import com.daml.lf.data.Ref.Location

final case class IncompleteTransaction(
transaction: GenTransaction,
transaction: Transaction,
locationInfo: Map[NodeId, Location],
)
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ final case class VersionedTransaction private[lf] (
)

// O(1)
def transaction: GenTransaction =
GenTransaction(nodes, roots)
def transaction: Transaction =
Transaction(nodes, roots)

}

Expand All @@ -54,18 +54,18 @@ final case class VersionedTransaction private[lf] (
* For performance reasons, users are not required to call `isWellFormed`.
* Therefore, it is '''forbidden''' to create ill-formed instances, i.e., instances with `!isWellFormed.isEmpty`.
*/
final case class GenTransaction(
final case class Transaction(
nodes: Map[NodeId, Node],
roots: ImmArray[NodeId],
) extends HasTxNodes
with value.CidContainer[GenTransaction] {
with value.CidContainer[Transaction] {

import GenTransaction._
import Transaction._

override protected def self: this.type = this
override def mapCid(f: ContractId => ContractId): GenTransaction =
override def mapCid(f: ContractId => ContractId): Transaction =
copy(nodes = nodes.map { case (nodeId, node) => nodeId -> node.mapCid(f) })
def mapNodeId(f: NodeId => NodeId): GenTransaction =
def mapNodeId(f: NodeId => NodeId): Transaction =
copy(
nodes = nodes.map { case (nodeId, node) => f(nodeId) -> node.mapNodeId(f) },
roots = roots.map(f),
Expand Down Expand Up @@ -134,13 +134,13 @@ final case class GenTransaction(
/** Compares two Transactions up to renaming of Nids. You most likely want to use this rather than ==, since the
* Nid is irrelevant to the content of the transaction.
*/
def equalForest(other: GenTransaction): Boolean =
def equalForest(other: Transaction): Boolean =
compareForest(other)(_ == _)

/** Compares two Transactions up to renaming of Nids. with the specified comparision of nodes
* Nid is irrelevant to the content of the transaction.
*/
def compareForest(other: GenTransaction)(
def compareForest(other: Transaction)(
compare: (Node, Node) => Boolean
): Boolean = {
@tailrec
Expand Down Expand Up @@ -731,14 +731,14 @@ sealed abstract class HasTxNodes {

}

object GenTransaction {
object Transaction {

@deprecated("use com.daml.transaction.GenTransaction directly", since = "1.18.0")
type WithTxValue = GenTransaction
type WithTxValue = Transaction

private[this] val Empty = GenTransaction(HashMap.empty, ImmArray.Empty)
private[this] val Empty = Transaction(HashMap.empty, ImmArray.Empty)

private[lf] def empty: GenTransaction = Empty
private[lf] def empty: Transaction = Empty

private[lf] case class NotWellFormedError(nid: NodeId, reason: NotWellFormedErrorReason)
private[lf] sealed trait NotWellFormedErrorReason
Expand Down Expand Up @@ -778,12 +778,6 @@ object GenTransaction {
}
}.duplicates
}
}

object Transaction {

@deprecated("use com.daml.value.Value.VersionedValue directly", since = "1.18.0")
type Value = Value.VersionedValue

@deprecated("use com.daml.value.Value.VersionedContractInstance", since = "1.18.0")
type ContractInstance = Value.VersionedContractInstance
Expand All @@ -793,11 +787,6 @@ object Transaction {
@deprecated("use com.daml.transaction.Node.LeafOnlyAction directly", since = "1.18.0")
type LeafNode = Node.LeafOnlyAction

@deprecated("use com.daml.transaction.VersionedTransaction", since = "1.18.0")
type Transaction = VersionedTransaction
@deprecated("use com.daml.transaction.VersionedTransaction", since = "1.18.0")
val Transaction: VersionedTransaction.type = VersionedTransaction

/** Transaction meta data
*
* @param submissionSeed : the submission seed used to derive the contract IDs.
Expand Down Expand Up @@ -901,4 +890,5 @@ object Transaction {
* was inconsistent with earlier nodes (in execution order).
*/
final case class InconsistentKeys(key: GlobalKey) extends KeyInputError

}
Loading

0 comments on commit a7559d0

Please sign in to comment.