Skip to content

Commit

Permalink
participant-integration-api: Move SeedService here. (#10261)
Browse files Browse the repository at this point in the history
I don't see a reason why it's part of the participant state API, and
it definitely doesn't need to change between v1 and v2.

CHANGELOG_BEGIN
- [Integration Kit] The class ``SeedService`` has been moved from the
  *participant-state* Maven package to the *participant-integration-api*
  Maven package, under the Java package name
  ``com.daml.platform.apiserver`` to reflect its usage by the API
  server, not the participant state API. If you use this class directly,
  you will need to change your imports.
CHANGELOG_END
  • Loading branch information
SamirTalwar authored Jul 14, 2021
1 parent 58c0b46 commit 6c63f96
Show file tree
Hide file tree
Showing 28 changed files with 57 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package com.daml

import java.io.File
import java.time.{Duration, Instant}
import java.util.Arrays.asList
import java.util.concurrent.TimeUnit
import java.util.stream.{Collectors, StreamSupport}
import java.util.{Optional, UUID}
Expand All @@ -17,6 +18,7 @@ import com.daml.ledger.api.v1.{ActiveContractsServiceGrpc, CommandServiceGrpc}
import com.daml.ledger.javaapi.data
import com.daml.ledger.javaapi.data._
import com.daml.ledger.resources.ResourceContext
import com.daml.platform.apiserver.SeedService.Seeding
import com.daml.platform.apiserver.services.GrpcClientResource
import com.daml.platform.common.LedgerIdMode
import com.daml.platform.sandbox
Expand All @@ -31,8 +33,6 @@ import scala.concurrent.Future
import scala.jdk.CollectionConverters._
import scala.language.implicitConversions

import java.util.Arrays.asList

object TestUtil {

def testDalf =
Expand All @@ -44,7 +44,7 @@ object TestUtil {
testCode: Channel => Assertion
)(implicit resourceContext: ResourceContext): Future[Assertion] = {
val config = sandbox.DefaultConfig.copy(
seeding = Some(com.daml.ledger.participant.state.v1.SeedService.Seeding.Weak),
seeding = Some(Seeding.Weak),
port = Port.Dynamic,
damlPackages = List(testDalf),
ledgerIdMode = LedgerIdMode.Static(LedgerId(LedgerID)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package com.daml.http

import java.io.File
import java.time.Instant

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.Http.ServerBinding
Expand All @@ -29,15 +30,15 @@ import com.daml.ledger.api.refinements.ApiTypes.ApplicationId
import com.daml.ledger.api.refinements.{ApiTypes => lar}
import com.daml.ledger.api.tls.TlsConfiguration
import com.daml.ledger.api.v1.{value => v}
import com.daml.ledger.client.{LedgerClient => DamlLedgerClient}
import com.daml.ledger.client.configuration.{
CommandClientConfiguration,
LedgerClientConfiguration,
LedgerIdRequirement,
}
import com.daml.ledger.participant.state.v1.SeedService.Seeding
import com.daml.ledger.client.{LedgerClient => DamlLedgerClient}
import com.daml.logging.LoggingContextOf
import com.daml.metrics.Metrics
import com.daml.platform.apiserver.SeedService.Seeding
import com.daml.platform.common.LedgerIdMode
import com.daml.platform.sandbox
import com.daml.platform.sandbox.SandboxServer
Expand Down Expand Up @@ -237,7 +238,7 @@ object HttpServiceTestFixture extends LazyLogging with Assertions with Inside {
for {
dao <- Future(ContractDao(c.driver, c.url, c.user, c.password))
_ <- {
import dao.{logHandler, jdbcDriver}
import dao.{jdbcDriver, logHandler}
dao.transact(ContractDao.initialize).unsafeToFuture(): Future[Unit]
}
} yield dao
Expand Down
2 changes: 1 addition & 1 deletion ledger/daml-on-sql/src/main/scala/on/sql/Cli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package com.daml.on.sql

import com.daml.ledger.participant.state.v1.SeedService.Seeding
import com.daml.platform.apiserver.SeedService.Seeding
import com.daml.platform.common.LedgerIdMode
import com.daml.platform.sandbox.cli.{CommonCli, SandboxCli}
import com.daml.platform.sandbox.config.{PostgresStartupMode, SandboxConfig}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package com.daml.on.sql

import com.daml.ledger.participant.state.v1.SeedService.Seeding
import com.daml.platform.apiserver.SeedService.Seeding
import com.daml.platform.sandbox.config.SandboxConfig
import com.daml.testing.postgresql.PostgresAround

Expand Down
6 changes: 3 additions & 3 deletions ledger/daml-on-sql/src/test/suite/scala/on/sql/CliSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
package com.daml.on.sql

import com.daml.ledger.api.domain.LedgerId
import com.daml.ledger.participant.state.v1.SeedService.Seeding
import com.daml.on.sql.CliSpec._
import com.daml.platform.apiserver.SeedService.Seeding
import com.daml.platform.common.LedgerIdMode
import com.daml.platform.sandbox.cli.CommonCliSpecBase
import com.daml.platform.sandbox.cli.CommonCliSpecBase._
import org.scalatest.BeforeAndAfterEach

import scala.collection.mutable
import CliSpec._
import org.scalatest.BeforeAndAfterEach

class CliSpec
extends CommonCliSpecBase(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ package com.daml.platform.apiserver
import java.io.File
import java.nio.file.Path
import java.time.Duration

import com.daml.ledger.api.tls.TlsConfiguration
import com.daml.ledger.participant.state.v1.ParticipantId
import com.daml.ledger.participant.state.v1.SeedService.Seeding
import com.daml.platform.apiserver.SeedService.Seeding
import com.daml.platform.configuration.IndexConfiguration
import com.daml.ports.Port

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.daml.ledger.api.health.HealthChecks
import com.daml.ledger.api.v1.command_completion_service.CompletionEndRequest
import com.daml.ledger.client.services.commands.CommandSubmissionFlow
import com.daml.ledger.participant.state.index.v2._
import com.daml.ledger.participant.state.v1.{SeedService, WriteService}
import com.daml.ledger.participant.state.v1.WriteService
import com.daml.ledger.resources.{Resource, ResourceContext, ResourceOwner}
import com.daml.lf.data.Ref
import com.daml.lf.engine._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package com.daml.ledger.participant.state.v1
package com.daml.platform.apiserver

import java.security.SecureRandom
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -42,7 +42,7 @@ object SeedService {
* Thread safe.
*/
// lazy to avoid gathering unnecessary entropy.
lazy val StrongRandom = {
lazy val StrongRandom: SeedService = {
val logger = org.slf4j.LoggerFactory.getLogger(this.getClass)
val timer = new java.util.Timer()
val task = new java.util.TimerTask {
Expand Down Expand Up @@ -71,7 +71,7 @@ object SeedService {
lazy val WeakRandom: SeedService = {
val seed = new Array[Byte](crypto.Hash.underlyingHashLength)
// uses `nextBytes` on a default SecureRandom, that should not block
(new SecureRandom()).nextBytes(seed)
new SecureRandom().nextBytes(seed)
new SeedService(crypto.Hash.assertFromByteArray(seed))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.daml.ledger.api.auth.interceptor.AuthorizationInterceptor
import com.daml.ledger.api.auth.{AuthService, Authorizer}
import com.daml.ledger.api.domain
import com.daml.ledger.api.health.HealthChecks
import com.daml.ledger.participant.state.v1.{LedgerId, ParticipantId, SeedService, WriteService}
import com.daml.ledger.participant.state.v1.{LedgerId, ParticipantId, WriteService}
import com.daml.ledger.resources.{Resource, ResourceContext, ResourceOwner}
import com.daml.lf.engine.{Engine, ValueEnricher}
import com.daml.logging.{ContextualizedLogger, LoggingContext}
Expand All @@ -34,7 +34,7 @@ import io.grpc.{BindableService, ServerInterceptor}
import scalaz.{-\/, \/-}

import scala.collection.immutable
import scala.concurrent.{ExecutionContextExecutor}
import scala.concurrent.ExecutionContextExecutor
import scala.util.{Failure, Success, Try}

// Main entry point to start an index server that also hosts the ledger API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ import com.daml.ledger.participant.state.v1.SubmissionResult.{
Overloaded,
SynchronousReject,
}
import com.daml.ledger.participant.state.v1.{
Configuration,
SeedService,
SubmissionResult,
WriteService,
}
import com.daml.ledger.participant.state.v1.{Configuration, SubmissionResult, WriteService}
import com.daml.lf.crypto
import com.daml.lf.data.Ref.Party
import com.daml.lf.engine.{Error => LfError}
Expand All @@ -32,14 +27,15 @@ import com.daml.lf.transaction.SubmittedTransaction
import com.daml.logging.LoggingContext.{withEnrichedLoggingContext, withEnrichedLoggingContextFrom}
import com.daml.logging.{ContextualizedLogger, LoggingContext}
import com.daml.metrics.Metrics
import com.daml.telemetry.TelemetryContext
import com.daml.platform.api.grpc.GrpcApiService
import com.daml.platform.apiserver.SeedService
import com.daml.platform.apiserver.execution.{CommandExecutionResult, CommandExecutor}
import com.daml.platform.server.api.services.domain.CommandSubmissionService
import com.daml.platform.server.api.services.grpc.GrpcCommandSubmissionService
import com.daml.platform.server.api.validation.ErrorFactories
import com.daml.platform.services.time.TimeProviderType
import com.daml.platform.store.ErrorCause
import com.daml.telemetry.TelemetryContext
import com.daml.timer.Delayed
import io.grpc.Status

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package com.daml.ledger.participant.state.v1
package com.daml.platform.apiserver

import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,20 @@ import com.daml.ledger.participant.state.index.v2.{
}
import com.daml.ledger.participant.state.v1._
import com.daml.ledger.resources.TestResourceContext
import com.daml.lf
import com.daml.lf.command.{Commands => LfCommands}
import com.daml.lf.crypto.Hash
import com.daml.lf.data.Time.Timestamp
import com.daml.lf.data.{ImmArray, Ref}
import com.daml.lf.engine.{Error => LfError}
import com.daml.lf.interpretation.{Error => LfInterpretationError}
import com.daml.lf.language.LookupError
import com.daml.lf
import com.daml.lf.transaction.{GlobalKey, NodeId, ReplayNodeMismatch}
import com.daml.lf.transaction.test.TransactionBuilder
import com.daml.lf.transaction.{GlobalKey, NodeId, ReplayNodeMismatch}
import com.daml.lf.value.Value
import com.daml.logging.LoggingContext
import com.daml.metrics.Metrics
import com.daml.platform.apiserver.SeedService
import com.daml.platform.apiserver.execution.CommandExecutor
import com.daml.platform.configuration.LedgerConfiguration
import com.daml.platform.store.ErrorCause
Expand Down
1 change: 0 additions & 1 deletion ledger/participant-state/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ da_scala_library(
"//ledger/participant-state/protobuf:ledger_configuration_proto_java",
"//libs-scala/logging-entries",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:org_slf4j_slf4j_api",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import java.nio.file.Path
import java.time.Duration
import java.util.UUID
import java.util.concurrent.TimeUnit

import com.daml.caching
import com.daml.ledger.api.tls.TlsConfiguration
import com.daml.ledger.participant.state.kvutils.app.Config.EngineMode
import com.daml.ledger.participant.state.v1.ParticipantId
import com.daml.ledger.participant.state.v1.SeedService.Seeding
import com.daml.ledger.resources.ResourceOwner
import com.daml.metrics.MetricsReporter
import com.daml.platform.apiserver.SeedService.Seeding
import com.daml.platform.configuration.Readers._
import com.daml.platform.configuration.{CommandConfiguration, IndexConfiguration}
import com.daml.ports.Port
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package com.daml.platform.sandbox

import com.daml.ledger.participant.state.v1.SeedService.Seeding
import com.daml.platform.apiserver.SeedService.Seeding
import com.daml.platform.sandbox.cli.{CommonCli, SandboxCli}
import com.daml.platform.sandbox.config.SandboxConfig
import scopt.OptionParser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import com.daml.ledger.api.auth.interceptor.AuthorizationInterceptor
import com.daml.ledger.api.auth.{AuthService, AuthServiceWildcard, Authorizer}
import com.daml.ledger.api.domain.LedgerId
import com.daml.ledger.api.health.HealthChecks
import com.daml.ledger.participant.state.v1.SeedService
import com.daml.ledger.participant.state.v1.SeedService.Seeding
import com.daml.ledger.participant.state.v1.metrics.TimedWriteService
import com.daml.ledger.resources.{Resource, ResourceContext, ResourceOwner}
import com.daml.lf.data.ImmArray
Expand All @@ -33,6 +31,7 @@ import com.daml.lf.transaction.{
import com.daml.logging.LoggingContext.newLoggingContextWith
import com.daml.logging.{ContextualizedLogger, LoggingContext}
import com.daml.metrics.{Metrics, MetricsReporting}
import com.daml.platform.apiserver.SeedService.Seeding
import com.daml.platform.apiserver._
import com.daml.platform.configuration.{InvalidConfigException, PartyConfiguration}
import com.daml.platform.packages.InMemoryPackageStore
Expand Down Expand Up @@ -185,7 +184,7 @@ final class SandboxServer(
this(DefaultName, config, materializer, new Metrics(new MetricRegistry))

private val authService: AuthService = config.authService.getOrElse(AuthServiceWildcard)
private val seedingService = SeedService(config.seeding.getOrElse(SeedService.Seeding.Weak))
private val seedingService = SeedService(config.seeding.getOrElse(Seeding.Weak))

// We store a Future rather than a Resource to avoid keeping old resources around after a reset.
// It's package-private so we can test that we drop the reference properly in ResetServiceIT.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
package com.daml.platform.sandbox

import com.daml.ledger.api.domain.LedgerId
import com.daml.ledger.participant.state.v1.SeedService.Seeding
import com.daml.lf.data.Ref
import com.daml.platform.apiserver.SeedService.Seeding
import com.daml.platform.common.LedgerIdMode
import com.daml.platform.sandbox.cli.CommonCliSpecBase
import com.daml.platform.sandbox.cli.CommonCliSpecBase.exampleJdbcUrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import com.daml.ledger.api.refinements.ApiTypes.ApplicationId
import com.daml.ledger.api.v1.command_service.SubmitAndWaitRequest
import com.daml.ledger.api.v1.commands.{Command, Commands, CreateCommand}
import com.daml.ledger.api.v1.value.{Identifier, Record, RecordField, Value}
import com.daml.ledger.participant.state.v1.SeedService.Seeding
import com.daml.ledger.resources.TestResourceContext
import com.daml.lf.language.LanguageVersion
import com.daml.platform.apiserver.SeedService.Seeding
import com.daml.platform.apiserver.services.GrpcClientResource
import com.daml.platform.sandbox.config.SandboxConfig
import com.daml.platform.sandbox.services.SandboxFixture
Expand Down
Loading

0 comments on commit 6c63f96

Please sign in to comment.