Skip to content

Commit

Permalink
Handle rollback nodes in protoNodeInfo (#9589)
Browse files Browse the repository at this point in the history
This PR clarifies that NodeInfo is only intended for actions by
renaming it to ActionNodeInfo and correspondingly also changes
protoNodeInfo to protoActionNodeInfo and makes it return a `Left` for
rollback nodes.

changelog_begin
changelog_end
  • Loading branch information
cocreature authored May 6, 2021
1 parent 42d189d commit 45fbdef
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ object Node {
/** action nodes parametrized over identifier type */
sealed abstract class GenActionNode[+Nid, +Cid]
extends GenNode[Nid, Cid]
with NodeInfo
with ActionNodeInfo
with CidContainer[GenActionNode[Nid, Cid]] {

def templateId: TypeConName
Expand Down Expand Up @@ -231,7 +231,7 @@ object Node {
// For the sake of consistency between types with a version field, keep this field the last.
override val version: TransactionVersion,
) extends LeafOnlyActionNode[Cid]
with NodeInfo.Create {
with ActionNodeInfo.Create {

override def byKey: Boolean = false

Expand Down Expand Up @@ -261,7 +261,7 @@ object Node {
// For the sake of consistency between types with a version field, keep this field the last.
override val version: TransactionVersion,
) extends LeafOnlyActionNode[Cid]
with NodeInfo.Fetch {
with ActionNodeInfo.Fetch {

override private[lf] def updateVersion(version: TransactionVersion): NodeFetch[Cid] =
copy(version = version)
Expand Down Expand Up @@ -293,7 +293,7 @@ object Node {
// For the sake of consistency between types with a version field, keep this field the last.
override val version: TransactionVersion,
) extends GenActionNode[Nid, Cid]
with NodeInfo.Exercise {
with ActionNodeInfo.Exercise {
@deprecated("use actingParties instead", since = "1.1.2")
private[daml] def controllers: actingParties.type = actingParties

Expand All @@ -320,7 +320,7 @@ object Node {
// For the sake of consistency between types with a version field, keep this field the last.
override val version: TransactionVersion,
) extends LeafOnlyActionNode[Cid]
with NodeInfo.LookupByKey {
with ActionNodeInfo.LookupByKey {

override def keyMaintainers: Set[Party] = key.maintainers
override def hasResult: Boolean = result.isDefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ package com.daml.lf.transaction

import com.daml.lf.data.Ref.Party

/** Trait for extracting information from an abstract node.
/** Trait for extracting information from an abstract action node.
* Used for sharing the implementation of common computations
* over nodes and transactions.
*
* External codebases use these utilities on transaction and
* node implementations that are not the one defined by [[Node]]
* node implementations that are not the one defined by [[ActionNode]]
* and hence the need for the indirection.
*/
trait NodeInfo {
trait ActionNodeInfo {

/** Compute the informees of a node based on the ledger model definition.
*
Expand All @@ -33,17 +33,17 @@ trait NodeInfo {
def requiredAuthorizers: Set[Party]
}

object NodeInfo {
object ActionNodeInfo {

trait Create extends NodeInfo {
trait Create extends ActionNodeInfo {
def signatories: Set[Party]
def stakeholders: Set[Party]

final def requiredAuthorizers: Set[Party] = signatories
final def informeesOfNode: Set[Party] = stakeholders
}

trait Fetch extends NodeInfo {
trait Fetch extends ActionNodeInfo {
def signatories: Set[Party]
def stakeholders: Set[Party]
def actingParties: Set[Party]
Expand All @@ -55,7 +55,7 @@ object NodeInfo {

}

trait Exercise extends NodeInfo {
trait Exercise extends ActionNodeInfo {

def consuming: Boolean
def signatories: Set[Party]
Expand All @@ -72,7 +72,7 @@ object NodeInfo {
signatories | actingParties | choiceObservers
}

trait LookupByKey extends NodeInfo {
trait LookupByKey extends ActionNodeInfo {
def keyMaintainers: Set[Party]
def hasResult: Boolean

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,28 +787,33 @@ object TransactionCoder {
else
decodeVersion(node.getVersion)

/** Node information for a serialized transaction node. Used to compute
/** Action node information for a serialized transaction node. Used to compute
* informees when deserialization is too costly.
* This method is not supported for transaction version <5 (as NodeInfo does not support it).
* We're not using e.g. "implicit class" in order to keep the decoding errors explicit.
* NOTE(JM): Currently used only externally, but kept here to keep in sync
* with the implementation.
* Note that this can only be applied to action nodes and will return Left on
* rollback nodes.
*/
def protoNodeInfo(
def protoActionNodeInfo(
txVersion: TransactionVersion,
protoNode: TransactionOuterClass.Node,
): Either[DecodeError, NodeInfo] =
): Either[DecodeError, ActionNodeInfo] =
protoNode.getNodeTypeCase match {
case NodeTypeCase.ROLLBACK =>
// TODO https://github.com/digital-asset/daml/issues/8020
sys.error("protoNodeInfo, rollback nodes are not supported")
Left(
DecodeError(
"protoActionNodeInfo only supports action nodes but was applied to a rollback node"
)
)
case NodeTypeCase.CREATE =>
val protoCreate = protoNode.getCreate
for {
signatories_ <- toPartySet(protoCreate.getSignatoriesList)
stakeholders_ <- toPartySet(protoCreate.getStakeholdersList)
} yield {
new NodeInfo.Create {
new ActionNodeInfo.Create {
def signatories = signatories_
def stakeholders = stakeholders_
}
Expand All @@ -820,7 +825,7 @@ object TransactionCoder {
stakeholders_ <- toPartySet(protoFetch.getStakeholdersList)
signatories_ <- toPartySet(protoFetch.getSignatoriesList)
} yield {
new NodeInfo.Fetch {
new ActionNodeInfo.Fetch {
def signatories = signatories_
def stakeholders = stakeholders_
def actingParties = actingParties_
Expand All @@ -839,7 +844,7 @@ object TransactionCoder {
else
toPartySet(protoExe.getObserversList)
} yield {
new NodeInfo.Exercise {
new ActionNodeInfo.Exercise {
def signatories = signatories_
def stakeholders = stakeholders_
def actingParties = actingParties_
Expand All @@ -853,7 +858,7 @@ object TransactionCoder {
for {
maintainers <- toPartySet(protoLookupByKey.getKeyWithMaintainers.getMaintainersList)
} yield {
new NodeInfo.LookupByKey {
new ActionNodeInfo.LookupByKey {
def hasResult = protoLookupByKey.hasContractIdStruct
def keyMaintainers = maintainers
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class TransactionCoderSpec

Right(createNode.informeesOfNode) shouldEqual
TransactionCoder
.protoNodeInfo(txVersion, encodedNode)
.protoActionNodeInfo(txVersion, encodedNode)
.map(_.informeesOfNode)
}
}
Expand Down Expand Up @@ -100,7 +100,7 @@ class TransactionCoderSpec
) shouldBe Right((NodeId(0), normalizeFetch(versionedNode)))
Right(fetchNode.informeesOfNode) shouldEqual
TransactionCoder
.protoNodeInfo(txVersion, encodedNode)
.protoActionNodeInfo(txVersion, encodedNode)
.map(_.informeesOfNode)
}
}
Expand Down Expand Up @@ -128,7 +128,7 @@ class TransactionCoderSpec

Right(normalizedNode.informeesOfNode) shouldEqual
TransactionCoder
.protoNodeInfo(txVersion, encodedNode)
.protoActionNodeInfo(txVersion, encodedNode)
.map(_.informeesOfNode)
}
}
Expand Down

0 comments on commit 45fbdef

Please sign in to comment.