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

Extend reinterpret to take inputContract as input #20008

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class Engine(val config: EngineConfig) {
for {
pkgResolution <- preprocessor.buildPackageResolution(packageMap, packagePreference)
processedCmds <- preprocessor.preprocessApiCommands(pkgResolution, cmds.commands)
processedDiscs <- preprocessor.preprocessDisclosedContracts(disclosures)
processedDiscs <- preprocessor.preprocessInputContracts(disclosures)
result <-
interpretCommands(
validating = false,
Expand Down Expand Up @@ -189,6 +189,7 @@ class Engine(val config: EngineConfig) {
def reinterpret(
submitters: Set[Party],
command: ReplayCommand,
inputContracts: ImmArray[FatContractInstance] = ImmArray.empty,
nodeSeed: Option[crypto.Hash],
submissionTime: Time.Timestamp,
ledgerEffectiveTime: Time.Timestamp,
Expand All @@ -197,12 +198,15 @@ class Engine(val config: EngineConfig) {
)(implicit loggingContext: LoggingContext): Result[(SubmittedTransaction, Tx.Metadata)] =
for {
speedyCommand <- preprocessor.preprocessReplayCommand(command)
processedContracts <- preprocessor.preprocessInputContracts(inputContracts)
sexpr <- runCompilerSafely(
NameOf.qualifiedNameOfCurrentFunc,
compiledPackages.compiler.unsafeCompileForReinterpretation(speedyCommand),
compiledPackages.compiler.unsafeCompile(ImmArray(speedyCommand), processedContracts),
)
// reinterpret is never used for submission, only for validation.
result <- interpretExpression(
// TODO https://github.com/digital-asset/daml/issues/19539
// Once canton uses the input contracts prevent the machine to query contract/key when validation is on
validating = true,
submitters = submitters,
readAs = Set.empty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ private[engine] final class Preprocessor(
commandPreprocessor.unsafePreprocessApiCommands(pkgResolution, cmds)
}

def preprocessDisclosedContracts(
def preprocessInputContracts(
discs: data.ImmArray[FatContractInstance]
): Result[ImmArray[speedy.DisclosedContract]] =
safelyRun(pullPackage(discs.toSeq.view.map(_.templateId))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,12 @@ class NodeSeedsTest(majorLanguageVersion: LanguageMajorVersion) extends AnyWordS
val Right((rTx, _)) =
engine
.reinterpret(
Set(operator),
cmd,
nodeSeeds.get(nodeId),
time,
time,
submitters = Set(operator),
command = cmd,
inputContracts = ImmArray.empty,
nodeSeed = nodeSeeds.get(nodeId),
submissionTime = time,
ledgerEffectiveTime = time,
)(LoggingContext.empty)
.consume(pcs = contracts, pkgs = packages, grantUpgradeVerification = None)
rTx.nodes.values.collect { case create: Node.Create => create }.toSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1312,11 +1312,12 @@ class EngineTest(majorLanguageVersion: LanguageMajorVersion)
val Right((reinterpreted, _)) =
suffixLenientEngine
.reinterpret(
n.requiredAuthorizers,
ReplayCommand.Fetch(n.templateId, n.coid),
txMeta.nodeSeeds.toSeq.collectFirst { case (`nid`, seed) => seed },
txMeta.submissionTime,
let,
submitters = n.requiredAuthorizers,
command = ReplayCommand.Fetch(n.templateId, n.coid),
inputContracts = ImmArray.empty,
nodeSeed = txMeta.nodeSeeds.toSeq.collectFirst { case (`nid`, seed) => seed },
submissionTime = txMeta.submissionTime,
ledgerEffectiveTime = let,
)
.consume(lookupContract, lookupPackage, lookupKey, grantUpgradeVerification = None)
isReplayedBy(fetchTx, reinterpreted) shouldBe Right(())
Expand Down Expand Up @@ -1360,7 +1361,7 @@ class EngineTest(majorLanguageVersion: LanguageMajorVersion)
"succeed with a fresh engine, correctly compiling packages" in {
val engine = newEngine()

val fetchNode = ReplayCommand.Fetch(
val fetchCmd = ReplayCommand.Fetch(
templateId = fetchedTid,
coid = fetchedCid,
)
Expand All @@ -1371,7 +1372,14 @@ class EngineTest(majorLanguageVersion: LanguageMajorVersion)

val reinterpreted =
engine
.reinterpret(submitters, fetchNode, None, let, let)
.reinterpret(
submitters = submitters,
command = fetchCmd,
inputContracts = ImmArray.empty,
nodeSeed = None,
submissionTime = let,
ledgerEffectiveTime = let,
)
.consume(lookupContract, lookupPackage, lookupKey, grantUpgradeVerification = None)

reinterpreted shouldBe a[Right[_, _]]
Expand Down Expand Up @@ -1474,11 +1482,12 @@ class EngineTest(majorLanguageVersion: LanguageMajorVersion)
val Right((reinterpreted, _)) =
newEngine()
.reinterpret(
submitters,
ReplayCommand.LookupByKey(lookupNode.templateId, lookupNode.key.value),
nodeSeedMap.get(nid),
txMeta.submissionTime,
now,
submitters = submitters,
command = ReplayCommand.LookupByKey(lookupNode.templateId, lookupNode.key.value),
inputContracts = ImmArray.empty,
nodeSeed = nodeSeedMap.get(nid),
submissionTime = txMeta.submissionTime,
ledgerEffectiveTime = now,
)
.consume(lookupContract, lookupPackage, lookupKey, grantUpgradeVerification = None)

Expand Down Expand Up @@ -1514,11 +1523,12 @@ class EngineTest(majorLanguageVersion: LanguageMajorVersion)
val Right((reinterpreted, _)) =
newEngine()
.reinterpret(
submitters,
ReplayCommand.LookupByKey(lookupNode.templateId, lookupNode.key.value),
nodeSeedMap.get(nid),
txMeta.submissionTime,
now,
submitters = submitters,
command = ReplayCommand.LookupByKey(lookupNode.templateId, lookupNode.key.value),
inputContracts = ImmArray.empty,
nodeSeed = nodeSeedMap.get(nid),
submissionTime = txMeta.submissionTime,
ledgerEffectiveTime = now,
)
.consume(lookupContract, lookupPackage, lookupKey)

Expand Down Expand Up @@ -2591,11 +2601,12 @@ class EngineTestHelpers(majorLanguageVersion: LanguageMajorVersion) {
}
currentStep <- engine
.reinterpret(
submitters,
cmd,
nodeSeedMap.get(nodeId),
txMeta.submissionTime,
ledgerEffectiveTime,
submitters = submitters,
command = cmd,
inputContracts = ImmArray.empty,
nodeSeed = nodeSeedMap.get(nodeId),
submissionTime = txMeta.submissionTime,
ledgerEffectiveTime = ledgerEffectiveTime,
)
.consume(
state.contracts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class PreprocessorSpec(majorLanguageVersion: LanguageMajorVersion)
val contract2 =
buildDisclosedContract(contractId, templateId = withKeyTmplId, keyHash = Some(keyHash))
val finalResult = preprocessor
.preprocessDisclosedContracts(ImmArray(contract1, contract2))
.preprocessInputContracts(ImmArray(contract1, contract2))
.consume(pkgs = pkgs)

inside(finalResult) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ class ReinterpretTest(majorLanguageVersion: LanguageMajorVersion)
private def reinterpretCommand(theCommand: ReplayCommand): Either[Error, SubmittedTransaction] = {
val res = engine
.reinterpret(
submitters,
theCommand,
Some(seed),
time,
time,
submitters = submitters,
command = theCommand,
inputContracts = ImmArray.empty,
nodeSeed = Some(seed),
submissionTime = time,
ledgerEffectiveTime = time,
)
.consume(pcs = defaultContracts, pkgs = allPackages, grantUpgradeVerification = None)
res match {
Expand Down