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

LF: V1 Contract ID check in Preprocessor #10687

Merged
merged 3 commits into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Address Moritz' review
  • Loading branch information
remyhaemmerle-da committed Aug 30, 2021
commit 78d8f0dc16f4b63f1eb8aa795190d60a60bd6a17
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Engine(val config: EngineConfig = Engine.StableConfig) {
private[engine] val preprocessor =
new preprocessing.Preprocessor(
compiledPackages = compiledPackages,
requireV1ContractId = config.requireV1ContractId,
forbidV0ContractId = config.requireV1ContractId,
requireV1ContractIdSuffix = config.requireSuffixedGlobalContractId,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import scala.annotation.tailrec

private[lf] final class CommandPreprocessor(
interface: language.Interface,
// See Preprocessor.requiredCidSuffix for more details about the following flags.
requireV1ContractId: Boolean,
// See Preprocessor scala doc for more details about the following flags.
forbidV0ContractId: Boolean,
requireV1ContractIdSuffix: Boolean,
) {

val valueTranslator =
new ValueTranslator(
interface = interface,
requireV1ContractId = requireV1ContractId,
forbidV0ContractId = forbidV0ContractId,
requireV1ContractIdSuffix = requireV1ContractIdSuffix,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import scala.annotation.tailrec
* Daml-LF package definitions against the command should
* resolved/typechecked. It is updated dynamically each time the
* [[ResultNeedPackage]] continuation is called.
* @param requireV1ContractId when `true` the preprocessor will reject
* @param forbidV0ContractId when `true` the preprocessor will reject
* any value/command/transaction that contains V0 Contract IDs
* without suffixed.
* @param requireV1ContractIdSuffix when `true` the preprocessor will reject
Expand All @@ -40,7 +40,7 @@ import scala.annotation.tailrec
*/
private[engine] final class Preprocessor(
compiledPackages: MutableCompiledPackages,
requireV1ContractId: Boolean = true,
forbidV0ContractId: Boolean = true,
requireV1ContractIdSuffix: Boolean = true,
) {

Expand All @@ -51,7 +51,7 @@ private[engine] final class Preprocessor(
val commandPreprocessor =
new CommandPreprocessor(
interface = interface,
requireV1ContractId = requireV1ContractId,
forbidV0ContractId = forbidV0ContractId,
requireV1ContractIdSuffix = requireV1ContractIdSuffix,
)
val transactionPreprocessor = new TransactionPreprocessor(commandPreprocessor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import scala.annotation.tailrec

private[engine] final class ValueTranslator(
interface: language.Interface,
// See Preprocessor.requiredCidSuffix for more details about the following flags.
requireV1ContractId: Boolean,
// See Preprocessor scala doc for more details about the following flags.
forbidV0ContractId: Boolean,
requireV1ContractIdSuffix: Boolean,
) {

Expand Down Expand Up @@ -54,7 +54,7 @@ private[engine] final class ValueTranslator(
SValue.SContractId(_)

private[this] val unsafeTranslateV0Cid: ContractId.V0 => SValue.SContractId =
if (requireV1ContractId)
if (forbidV0ContractId)
cid => throw Error.Preprocessing.IllegalContractId(cid)
else
SValue.SContractId(_)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class PreprocessorSpec

val valueTranslator = new ValueTranslator(
compiledPackage.interface,
requireV1ContractId = true,
forbidV0ContractId = true,
requireV1ContractIdSuffix = false,
)
import valueTranslator.unsafeTranslateValue
Expand Down Expand Up @@ -223,7 +223,7 @@ class PreprocessorSpec

val valueTranslator = new ValueTranslator(
compiledPackage.interface,
requireV1ContractId = false,
forbidV0ContractId = false,
requireV1ContractIdSuffix = false,
)
val cids = List(
Expand All @@ -245,7 +245,7 @@ class PreprocessorSpec

val valueTranslator = new ValueTranslator(
compiledPackage.interface,
requireV1ContractId = true,
forbidV0ContractId = true,
requireV1ContractIdSuffix = false,
)
val legalCid =
Expand All @@ -266,7 +266,7 @@ class PreprocessorSpec

val valueTranslator = new ValueTranslator(
compiledPackage.interface,
requireV1ContractId = true,
forbidV0ContractId = true,
requireV1ContractIdSuffix = true,
)
val legalCid =
Expand Down Expand Up @@ -335,7 +335,7 @@ class PreprocessorSpec

val cmdPreprocessor = new CommandPreprocessor(
compiledPackage.interface,
requireV1ContractId = false,
forbidV0ContractId = false,
requireV1ContractIdSuffix = false,
)

Expand All @@ -359,7 +359,7 @@ class PreprocessorSpec

val cmdPreprocessor = new CommandPreprocessor(
compiledPackage.interface,
requireV1ContractId = true,
forbidV0ContractId = true,
requireV1ContractIdSuffix = false,
)

Expand All @@ -383,7 +383,7 @@ class PreprocessorSpec

val cmdPreprocessor = new CommandPreprocessor(
compiledPackage.interface,
requireV1ContractId = true,
forbidV0ContractId = true,
requireV1ContractIdSuffix = true,
)
val List(aLegalCid, anotherLegalCid) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ object Converter {
valueTranslator =
new preprocessing.ValueTranslator(
compiledPackages.interface,
requireV1ContractId = false,
forbidV0ContractId = false,
requireV1ContractIdSuffix = false,
)
sValue <- valueTranslator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ object ScriptF {
def compiledPackages = machine.compiledPackages
val valueTranslator = new ValueTranslator(
interface = compiledPackages.interface,
requireV1ContractId = false,
forbidV0ContractId = false,
requireV1ContractIdSuffix = false,
)
val utcClock = Clock.systemUTC()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class IdeLedgerClient(
private[this] val preprocessor =
new preprocessing.CommandPreprocessor(
compiledPackages.interface,
requireV1ContractId = false,
forbidV0ContractId = true,
requireV1ContractIdSuffix = false,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SpeedyToValueBenchmark extends BenchmarkWithLedgerExport {
val translator =
new ValueTranslator(
interface = submissions.compiledPackages.interface,
requireV1ContractId = false,
forbidV0ContractId = false,
requireV1ContractIdSuffix = false,
)
speedyValues = decodedValues.map(x => assertTranslate(translator)(x.mapValue(_.value)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ValueTranslatorBenchmark extends BenchmarkWithLedgerExport {
decodedValues = submissions.values.map(_.mapValue(assertDecode).mapValue(_.value)).toVector
translator = new ValueTranslator(
submissions.compiledPackages.interface,
requireV1ContractId = false,
forbidV0ContractId = false,
requireV1ContractIdSuffix = false,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ object Converter {
def apply(compiledPackages: CompiledPackages, triggerIds: TriggerIds): Converter = {
val valueTranslator = new preprocessing.ValueTranslator(
compiledPackages.interface,
requireV1ContractId = false,
forbidV0ContractId = false,
requireV1ContractIdSuffix = false,
)
Converter(
Expand Down