Cleanup boundary between Machine and PartialTransaction (#14393)

changelog_begin
changelog_end
This commit is contained in:
nickchapman-da 2022-07-12 09:23:12 +02:00 committed by GitHub
parent 160a48cb89
commit 9f1b1b1f82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 31 deletions

View File

@ -941,10 +941,8 @@ private[lf] object SBuiltin {
IE.CreateEmptyContractKeyMaintainers(cached.templateId, createArgValue, key)
)
}
val auth = machine.auth
val (coid, newPtx) = onLedger.ptx
.insertCreate(
auth = auth,
templateId = cached.templateId,
arg = createArgValue,
agreementText = agreement,
@ -1000,11 +998,9 @@ private[lf] object SBuiltin {
val obsrs = extractParties(NameOf.qualifiedNameOfCurrentFunc, args.get(3))
onLedger.enforceChoiceObserversLimit(obsrs, coid, templateId, choiceId, chosenValue)
val mbKey = cached.key
val auth = machine.auth
onLedger.ptx = onLedger.ptx
.beginExercises(
auth = auth,
targetId = coid,
templateId = templateId,
interfaceId = interfaceId,
@ -1366,17 +1362,12 @@ private[lf] object SBuiltin {
val signatories = cached.signatories
val observers = cached.observers
val key = cached.key
val stakeholders = observers union signatories
val contextActors = machine.contextActors
val auth = machine.auth
onLedger.ptx = onLedger.ptx.insertFetch(
auth = auth,
coid = coid,
templateId = templateId,
optLocation = machine.lastLocation,
actingParties = contextActors intersect stakeholders,
signatories = signatories,
stakeholders = stakeholders,
observers = observers,
key = key,
byKey = byKey,
version = machine.tmplId2TxVersion(templateId),
@ -1412,9 +1403,7 @@ private[lf] object SBuiltin {
}
case _ => crash(s"Non option value when inserting lookup node")
}
val auth = machine.auth
onLedger.ptx = onLedger.ptx.insertLookup(
auth = auth,
templateId = templateId,
optLocation = machine.lastLocation,
key = Node.KeyWithMaintainers(

View File

@ -10,7 +10,6 @@ import com.daml.lf.data.{FrontStack, ImmArray, Ref, Time}
import com.daml.lf.interpretation.{Error => IError}
import com.daml.lf.language.Ast._
import com.daml.lf.language.{LookupError, Util => AstUtil}
import com.daml.lf.ledger.Authorize
import com.daml.lf.speedy.Compiler.{CompilationError, PackageNotFound}
import com.daml.lf.speedy.SError._
import com.daml.lf.speedy.SExpr._
@ -479,13 +478,6 @@ private[lf] object Speedy {
s.result()
}
private[lf] def contextActors: Set[Party] =
withOnLedger("ptx") { onLedger =>
onLedger.ptx.context.info.authorizers
}
private[lf] def auth: Authorize = Authorize(this.contextActors)
/** Reuse an existing speedy machine to evaluate a new expression.
* Do not use if the machine is partway though an existing evaluation.
* i.e. run() has returned an `SResult` requiring a callback.

View File

@ -38,7 +38,7 @@ private[lf] object PartialTransaction {
sealed abstract class ContextInfo {
val actionChildSeed: Int => crypto.Hash
def authorizers: Set[Party]
private[PartialTransaction] def authorizers: Set[Party]
}
sealed abstract class RootContextInfo extends ContextInfo {
@ -350,7 +350,6 @@ private[speedy] case class PartialTransaction(
* contract instance.
*/
def insertCreate(
auth: Authorize,
templateId: Ref.Identifier,
arg: Value,
agreementText: String,
@ -360,6 +359,7 @@ private[speedy] case class PartialTransaction(
key: Option[Node.KeyWithMaintainers],
version: TxVersion,
): (Value.ContractId, PartialTransaction) = {
val auth = Authorize(context.info.authorizers)
val actionNodeSeed = context.nextActionChildSeed
val discriminator =
crypto.Hash.deriveContractDiscriminator(actionNodeSeed, submissionTime, stakeholders)
@ -391,17 +391,19 @@ private[speedy] case class PartialTransaction(
}
def insertFetch(
auth: Authorize,
coid: Value.ContractId,
templateId: TypeConName,
optLocation: Option[Location],
actingParties: Set[Party],
signatories: Set[Party],
stakeholders: Set[Party],
observers: Set[Party],
key: Option[Node.KeyWithMaintainers],
byKey: Boolean,
version: TxVersion,
): PartialTransaction = {
val stakeholders = observers union signatories
val contextActors = context.info.authorizers
val actingParties = contextActors intersect stakeholders
val auth = Authorize(context.info.authorizers)
val nid = NodeId(nextNodeIdx)
val node = Node.Fetch(
coid,
@ -424,13 +426,13 @@ private[speedy] case class PartialTransaction(
}
def insertLookup(
auth: Authorize,
templateId: TypeConName,
optLocation: Option[Location],
key: Node.KeyWithMaintainers,
result: Option[Value.ContractId],
version: TxVersion,
): PartialTransaction = {
val auth = Authorize(context.info.authorizers)
val nid = NodeId(nextNodeIdx)
val node = Node.LookupByKey(
templateId,
@ -453,7 +455,6 @@ private[speedy] case class PartialTransaction(
* Must be closed by a `endExercises` or an `abortExercise`.
*/
def beginExercises(
auth: Authorize,
targetId: Value.ContractId,
templateId: TypeConName,
interfaceId: Option[TypeConName],
@ -469,6 +470,7 @@ private[speedy] case class PartialTransaction(
chosenValue: Value,
version: TxVersion,
): PartialTransaction = {
val auth = Authorize(context.info.authorizers)
val nid = NodeId(nextNodeIdx)
val ec =
ExercisesContextInfo(

View File

@ -5,7 +5,6 @@ package com.daml.lf
package speedy
import com.daml.lf.data.ImmArray
import com.daml.lf.ledger.Authorize
import com.daml.lf.speedy.PartialTransaction._
import com.daml.lf.speedy.SValue.{SValue => _, _}
import com.daml.lf.transaction.{ContractKeyUniquenessMode, Node, TransactionVersion}
@ -21,7 +20,7 @@ class PartialTransactionSpec extends AnyWordSpec with Matchers with Inside {
private[this] val choiceId = data.Ref.Name.assertFromString("choice")
private[this] val cid = Value.ContractId.V1(crypto.Hash.hashPrivateKey("My contract"))
private[this] val party = data.Ref.Party.assertFromString("Alice")
private[this] val committers: Set[data.Ref.Party] = Set.empty
private[this] val committers: Set[data.Ref.Party] = Set(party)
private[this] val initialState = PartialTransaction.initial(
ContractKeyUniquenessMode.Strict,
@ -45,7 +44,6 @@ class PartialTransactionSpec extends AnyWordSpec with Matchers with Inside {
def insertCreate_ : PartialTransaction =
ptx
.insertCreate(
auth = Authorize(Set(party)),
templateId = templateId,
arg = Value.ValueUnit,
agreementText = "agreement",
@ -59,7 +57,6 @@ class PartialTransactionSpec extends AnyWordSpec with Matchers with Inside {
def beginExercises_ : PartialTransaction =
ptx.beginExercises(
auth = Authorize(Set(party)),
targetId = cid,
templateId = templateId,
interfaceId = None,