From 7a88c7d97c68d07d7399e15cb87d3873e562d82a Mon Sep 17 00:00:00 2001 From: Robin Krom Date: Wed, 13 Oct 2021 14:22:10 +0200 Subject: [PATCH] trigger-service: dev-mode-unsafe flag (#11233) * trigger-service: dev-mode-unsafe flag This adds a `--dev-mode-unsafe` flag analogous to the trigger service analogous to its counterpart in the trigger runner. CHANGELOG_BEGIN CHANGELOG_END * fix tests --- triggers/service/BUILD.bazel | 2 ++ .../daml/lf/engine/trigger/Server.scala | 9 ++++++--- .../daml/lf/engine/trigger/ServiceConfig.scala | 13 +++++++++++++ .../daml/lf/engine/trigger/ServiceMain.scala | 4 ++++ .../lf/engine/trigger/TriggerServiceFixture.scala | 2 ++ 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/triggers/service/BUILD.bazel b/triggers/service/BUILD.bazel index 276905d26ce..8313503e7dd 100644 --- a/triggers/service/BUILD.bazel +++ b/triggers/service/BUILD.bazel @@ -95,6 +95,7 @@ binary_deps = [ "//daml-lf/archive:daml_lf_archive_reader", "//daml-lf/archive:daml_lf_dev_archive_proto_java", "//daml-lf/data", + "//daml-lf/interpreter", "//language-support/scala/bindings", "//ledger/ledger-api-common", "//libs-scala/contextualized-logging", @@ -161,6 +162,7 @@ da_scala_library( "//daml-lf/archive:daml_lf_archive_reader", "//daml-lf/archive:daml_lf_dev_archive_proto_java", "//daml-lf/data", + "//daml-lf/interpreter", "//language-support/scala/bindings-akka", "//ledger-api/rs-grpc-bridge", "//ledger-api/testing-utils", diff --git a/triggers/service/src/main/scala/com/digitalasset/daml/lf/engine/trigger/Server.scala b/triggers/service/src/main/scala/com/digitalasset/daml/lf/engine/trigger/Server.scala index d771f076fa8..fe519c85651 100644 --- a/triggers/service/src/main/scala/com/digitalasset/daml/lf/engine/trigger/Server.scala +++ b/triggers/service/src/main/scala/com/digitalasset/daml/lf/engine/trigger/Server.scala @@ -44,6 +44,7 @@ import com.daml.auth.middleware.api.{ Request => AuthRequest, Response => AuthResponse, } +import com.daml.lf.speedy.Compiler import com.daml.scalautil.Statement.discard import com.daml.scalautil.ExceptionOps._ import com.typesafe.scalalogging.StrictLogging @@ -59,6 +60,7 @@ import scala.util.{Failure, Success, Try} class Server( authRoutes: Option[Directive1[AuthClient.Routes]], triggerDao: RunningTriggerDao, + compilerConfig: Compiler.Config, val logTriggerStatus: (UUID, String) => Unit, )(implicit ctx: ActorContext[Server.Message]) extends StrictLogging { @@ -67,7 +69,7 @@ class Server( // When running with a persistent store we also write the encoded packages so we can recover // our state after the service shuts down or crashes. val compiledPackages: MutableCompiledPackages = - ConcurrentCompiledPackages(speedy.Compiler.Config.Dev) + ConcurrentCompiledPackages(compilerConfig) private def addPackagesInMemory(pkgs: List[(PackageId, DamlLf.ArchivePayload)]): Unit = { // We store decoded packages in memory @@ -504,6 +506,7 @@ object Server { initialDars: List[Dar[(PackageId, DamlLf.ArchivePayload)]], jdbcConfig: Option[JdbcConfig], allowExistingSchema: Boolean, + compilerConfig: speedy.Compiler.Config, logTriggerStatus: (UUID, String) => Unit = (_, _) => (), ): Behavior[Message] = Behaviors.setup { implicit ctx => // Implicit boilerplate. @@ -540,11 +543,11 @@ object Server { val (dao, server, initializeF): (RunningTriggerDao, Server, Future[Unit]) = jdbcConfig match { case None => val dao = InMemoryTriggerDao() - val server = new Server(authRoutes, dao, logTriggerStatus) + val server = new Server(authRoutes, dao, compilerConfig, logTriggerStatus) (dao, server, Future.successful(())) case Some(c) => val dao = DbTriggerDao(c) - val server = new Server(authRoutes, dao, logTriggerStatus) + val server = new Server(authRoutes, dao, compilerConfig, logTriggerStatus) val initialize = for { _ <- dao.initialize(allowExistingSchema) packages <- dao.readPackages diff --git a/triggers/service/src/main/scala/com/digitalasset/daml/lf/engine/trigger/ServiceConfig.scala b/triggers/service/src/main/scala/com/digitalasset/daml/lf/engine/trigger/ServiceConfig.scala index 2af8b623b6b..08e2c45f08b 100644 --- a/triggers/service/src/main/scala/com/digitalasset/daml/lf/engine/trigger/ServiceConfig.scala +++ b/triggers/service/src/main/scala/com/digitalasset/daml/lf/engine/trigger/ServiceConfig.scala @@ -3,6 +3,8 @@ package com.daml.lf.engine.trigger +import com.daml.lf.speedy.Compiler + import java.nio.file.{Path, Paths} import java.time.Duration @@ -41,6 +43,7 @@ private[trigger] final case class ServiceConfig( jdbcConfig: Option[JdbcConfig], portFile: Option[Path], allowExistingSchema: Boolean, + compilerConfig: Compiler.Config, ) private[trigger] object ServiceConfig { @@ -53,6 +56,7 @@ private[trigger] object ServiceConfig { val DefaultAuthCallbackTimeout: FiniteDuration = FiniteDuration(1, duration.MINUTES) val DefaultMaxHttpEntityUploadSize: Long = RunnerConfig.DefaultMaxInboundMessageSize.toLong val DefaultHttpEntityUploadTimeout: FiniteDuration = FiniteDuration(1, duration.MINUTES) + val DefaultCompilerConfig: Compiler.Config = Compiler.Config.Default implicit val redirectToLoginRead: scopt.Read[AuthClient.RedirectToLogin] = scopt.Read.reads { _.toLowerCase match { @@ -190,6 +194,14 @@ private[trigger] object ServiceConfig { } .text("TTL in seconds used for commands emitted by the trigger. Defaults to 30s.") + opt[Unit]("dev-mode-unsafe") + .action((_, c) => c.copy(compilerConfig = Compiler.Config.Dev)) + .optional() + .text( + "Turns on development mode. Development mode allows development versions of Daml-LF language." + ) + .hidden() + implicit val jcd: DBConfig.JdbcConfigDefaults = DBConfig.JdbcConfigDefaults( supportedJdbcDrivers = supportedJdbcDriverNames, defaultDriver = Some("org.postgresql.Driver"), @@ -263,6 +275,7 @@ private[trigger] object ServiceConfig { jdbcConfig = None, portFile = None, allowExistingSchema = false, + compilerConfig = DefaultCompilerConfig, ), ) } diff --git a/triggers/service/src/main/scala/com/digitalasset/daml/lf/engine/trigger/ServiceMain.scala b/triggers/service/src/main/scala/com/digitalasset/daml/lf/engine/trigger/ServiceMain.scala index 9352b6a1f47..22f27c2de47 100644 --- a/triggers/service/src/main/scala/com/digitalasset/daml/lf/engine/trigger/ServiceMain.scala +++ b/triggers/service/src/main/scala/com/digitalasset/daml/lf/engine/trigger/ServiceMain.scala @@ -17,6 +17,7 @@ import com.daml.dbutils.JdbcConfig import com.daml.lf.archive.{Dar, DarReader} import com.daml.lf.data.Ref.PackageId import com.daml.lf.engine.trigger.dao.DbTriggerDao +import com.daml.lf.speedy.Compiler import com.daml.logging.ContextualizedLogger import com.daml.ports.{Port, PortFiles} import com.daml.scalautil.Statement.discard @@ -51,6 +52,7 @@ object ServiceMain { encodedDars: List[Dar[(PackageId, DamlLf.ArchivePayload)]], jdbcConfig: Option[JdbcConfig], allowExistingSchema: Boolean, + compilerConfig: Compiler.Config, logTriggerStatus: (UUID, String) => Unit = (_, _) => (), ): Future[(ServerBinding, ActorSystem[Server.Message])] = { @@ -71,6 +73,7 @@ object ServiceMain { encodedDars, jdbcConfig, allowExistingSchema, + compilerConfig, logTriggerStatus, ), "TriggerService", @@ -164,6 +167,7 @@ object ServiceMain { encodedDars, config.jdbcConfig, config.allowExistingSchema, + config.compilerConfig, ), "TriggerService", ) diff --git a/triggers/service/src/test/scala/com/digitalasset/daml/lf/engine/trigger/TriggerServiceFixture.scala b/triggers/service/src/test/scala/com/digitalasset/daml/lf/engine/trigger/TriggerServiceFixture.scala index 8c77e6db573..dcaba78814a 100644 --- a/triggers/service/src/test/scala/com/digitalasset/daml/lf/engine/trigger/TriggerServiceFixture.scala +++ b/triggers/service/src/test/scala/com/digitalasset/daml/lf/engine/trigger/TriggerServiceFixture.scala @@ -47,6 +47,7 @@ import com.daml.ledger.resources.{Resource, ResourceContext, ResourceOwner} import com.daml.lf.archive.Dar import com.daml.lf.data.Ref._ import com.daml.lf.engine.trigger.dao.DbTriggerDao +import com.daml.lf.speedy.Compiler import com.daml.platform.apiserver.SeedService.Seeding import com.daml.platform.apiserver.services.GrpcClientResource import com.daml.platform.common.LedgerIdMode @@ -524,6 +525,7 @@ trait TriggerServiceFixture encodedDars, jdbcConfig, false, + Compiler.Config.Dev, logTriggerStatus, ) } yield r