Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package org.lfdecentralizedtrust.splice.console

import com.digitalasset.canton.config.{ConsoleCommandTimeout, NonNegativeDuration}
import com.digitalasset.canton.config.ConsoleCommandTimeout
import com.digitalasset.canton.console.{
CommandErrors,
ConsoleCommandResult,
Expand All @@ -17,7 +17,6 @@ import org.apache.pekko.http.scaladsl.model.HttpHeader
import org.lfdecentralizedtrust.splice.admin.api.client.HttpCtlRunner
import org.lfdecentralizedtrust.splice.admin.api.client.commands.{HttpCommand, HttpCommandException}
import org.lfdecentralizedtrust.splice.config.NetworkAppClientConfig
import org.lfdecentralizedtrust.splice.environment.SpliceEnvironment
import org.lfdecentralizedtrust.splice.http.HttpClient
import org.lfdecentralizedtrust.splice.util.TemplateJsonDecoder

Expand All @@ -26,18 +25,16 @@ import scala.concurrent.{ExecutionContextExecutor, TimeoutException}
/** HTTP version of Canton’s GrpcAdminCommandRunner
*/
class ConsoleHttpCommandRunner(
environment: SpliceEnvironment,
commandTimeouts: ConsoleCommandTimeout,
requestTimeout: NonNegativeDuration,
)(implicit tracer: Tracer, templateDecoder: TemplateJsonDecoder)
extends NamedLogging
override val loggerFactory: NamedLoggerFactory,
)(implicit
tracer: Tracer,
templateDecoder: TemplateJsonDecoder,
httpClient: HttpClient,
ec: ExecutionContextExecutor,
as: ActorSystem,
) extends NamedLogging
with Spanning {

private implicit val executionContext: ExecutionContextExecutor =
environment.executionContext
private implicit val actorSystem: ActorSystem = environment.actorSystem
override val loggerFactory: NamedLoggerFactory = environment.loggerFactory

private val httpRunner = new HttpCtlRunner(
loggerFactory
)
Expand All @@ -57,9 +54,6 @@ class ConsoleHttpCommandRunner(
)
val commandTimeout = commandTimeouts.bounded

implicit val httpClient: HttpClient =
HttpClient(HttpClient.HttpRequestParameters(requestTimeout), logger)

val url = clientConfig.url
try {
val start = System.currentTimeMillis()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

package org.lfdecentralizedtrust.splice.console

import org.apache.pekko.actor.ActorSystem
import org.lfdecentralizedtrust.splice.codegen.java.splice
import org.lfdecentralizedtrust.splice.codegen.java.splice.types.Round
import org.lfdecentralizedtrust.splice.codegen.java.splice.amulet.FeaturedAppRight
Expand Down Expand Up @@ -724,8 +723,7 @@ abstract class ScanAppReference(
final class ScanAppBackendReference(
override val spliceConsoleEnvironment: SpliceConsoleEnvironment,
name: String,
)(implicit actorSystem: ActorSystem)
extends ScanAppReference(spliceConsoleEnvironment, name)
) extends ScanAppReference(spliceConsoleEnvironment, name)
with AppBackendReference
with BaseInspection[ScanApp] {

Expand All @@ -747,14 +745,6 @@ final class ScanAppBackendReference(
override def config: ScanAppBackendConfig =
spliceConsoleEnvironment.environment.config.scansByString(name)

/** Remote participant this scan app is configured to interact with. */
lazy val participantClient =
new ParticipantClientReference(
spliceConsoleEnvironment,
s"remote participant for `$name``",
config.participantClient.getParticipantClientConfig(),
)

/** Remote participant this scan app is configured to interact with. Uses admin tokens to bypass auth. */
lazy val participantClientWithAdminToken =
new ParticipantClientReference(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import org.apache.pekko.http.scaladsl.model.headers.{Authorization, OAuth2Bearer
import com.digitalasset.daml.lf.archive.DarParser
import org.lfdecentralizedtrust.splice.admin.api.client.HttpAdminAppClient
import org.lfdecentralizedtrust.splice.admin.api.client.commands.HttpCommand
import org.lfdecentralizedtrust.splice.config.{NetworkAppClientConfig, SpliceBackendConfig}
import org.lfdecentralizedtrust.splice.config.{
BaseParticipantClientConfig,
NetworkAppClientConfig,
SpliceBackendConfig,
}
import org.lfdecentralizedtrust.splice.environment.{
NodeBase,
SpliceConsoleEnvironment,
Expand Down Expand Up @@ -45,7 +49,7 @@ import com.digitalasset.canton.topology.admin.grpc.TopologyStoreId
import com.digitalasset.canton.topology.transaction.VettedPackage

import java.io.File
import scala.concurrent.ExecutionContext
import scala.concurrent.{Await, ExecutionContext}
import scala.concurrent.duration.*
import scala.reflect.ClassTag
import scala.util.Try
Expand Down Expand Up @@ -237,6 +241,37 @@ trait AppBackendReference extends AppReference with LocalInstanceReference {
x => x,
)
}

def getParticipantClient()(implicit ec: ExecutionContext): ParticipantClientReference = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can make these private right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's in abstract class so we can make it protected

val remoteParticipantClientConfig = getRemoteParticipantConfigWithToken(
config.participantClient
)
new ParticipantClientReference(
spliceConsoleEnvironment,
s"remote participant for `$name``",
remoteParticipantClientConfig,
)
}

def getRemoteParticipantConfigWithToken(
participantClientConfig: BaseParticipantClientConfig
)(implicit ec: ExecutionContext): RemoteParticipantConfig = {
val tokenStrO = Await.result(
spliceConsoleEnvironment.httpClient
.getToken(participantClientConfig.ledgerApi.authConfig)
.map(_.map(_.accessToken)),
30.seconds,
)
RemoteParticipantConfig(
participantClientConfig.adminApi,
participantClientConfig.ledgerApi.clientConfig,
tokenStrO,
)
}
implicit val ec: ExecutionContext = executionContext

/** Remote participant this splitwell app is configured to interact with. */
lazy val participantClient = getParticipantClient()
}

/** Subclass of participantClient that takes the config as an argument
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

package org.lfdecentralizedtrust.splice.console

import org.apache.pekko.actor.ActorSystem
import com.daml.ledger.api.v2.CommandsOuterClass
import com.daml.ledger.javaapi.data.codegen.Update
import org.lfdecentralizedtrust.splice.codegen.java.splice.splitwell as splitwellCodegen
Expand All @@ -29,8 +28,10 @@ import com.digitalasset.canton.console.{
LedgerApiCommandRunner,
}
import com.digitalasset.canton.console.commands.BaseLedgerApiAdministration
import com.digitalasset.canton.topology.{SynchronizerId, PartyId}
import com.digitalasset.canton.topology.{PartyId, SynchronizerId}

import scala.concurrent.{Await, ExecutionContext}
import scala.concurrent.duration.DurationInt
import scala.jdk.CollectionConverters.*

/** Splitwell app reference. Defines the console commands that can be run against either a client or backend splitwell reference.
Expand Down Expand Up @@ -78,22 +79,26 @@ final class SplitwellAppClientReference(
override val spliceConsoleEnvironment: SpliceConsoleEnvironment,
name: String,
val config: SplitwellAppClientConfig, // adding this explicitly for easier overriding
)(implicit actorSystem: ActorSystem)
extends SplitwellAppReference(spliceConsoleEnvironment, name) {
) extends SplitwellAppReference(spliceConsoleEnvironment, name) {
private val acceptDuration = new RelTime(
60_000_000
)

override protected val instanceType = "Splitwell Client"

override def httpClientConfig = config.adminApi

implicit val ec: ExecutionContext = executionContext
override lazy val ledgerApi: com.digitalasset.canton.console.ExternalLedgerApiClient =
new ExternalLedgerApiClient(
config.participantClient.ledgerApi.clientConfig.address,
config.participantClient.ledgerApi.clientConfig.port,
config.participantClient.ledgerApi.clientConfig.tls,
config.participantClient.ledgerApi.getToken().map(_.accessToken),
Await.result(
spliceConsoleEnvironment.httpClient
.getToken(config.participantClient.ledgerApi.authConfig)
.map(_.map(_.accessToken)),
30.seconds,
),
)(consoleEnvironment)

val userId: String = config.ledgerApiUser
Expand Down Expand Up @@ -469,8 +474,7 @@ final class SplitwellAppClientReference(
final class SplitwellAppBackendReference(
override val consoleEnvironment: SpliceConsoleEnvironment,
name: String,
)(implicit actorSystem: ActorSystem)
extends SplitwellAppReference(consoleEnvironment, name)
) extends SplitwellAppReference(consoleEnvironment, name)
with AppBackendReference
with BaseInspection[SplitwellApp] {

Expand Down Expand Up @@ -508,14 +512,6 @@ final class SplitwellAppBackendReference(

override val scanClientConfig = config.scanClient

/** Remote participant this splitwell app is configured to interact with. */
lazy val participantClient =
new ParticipantClientReference(
consoleEnvironment,
s"remote participant for `$name``",
config.participantClient.getParticipantClientConfig(),
)

/** Remote participant this splitwell app is configured to interact with. Uses admin tokens to bypass auth. */
lazy val participantClientWithAdminToken =
new ParticipantClientReference(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import com.digitalasset.canton.admin.api.client.data.NodeStatus
import com.digitalasset.canton.console.{BaseInspection, Help}
import com.digitalasset.canton.topology.{ParticipantId, PartyId}
import com.digitalasset.canton.tracing.TraceContext
import org.apache.pekko.actor.ActorSystem

import scala.jdk.OptionConverters.*
import java.time.Instant
Expand Down Expand Up @@ -283,8 +282,7 @@ final case class SvAppClientReference(
class SvAppBackendReference(
override val consoleEnvironment: SpliceConsoleEnvironment,
name: String,
)(implicit actorSystem: ActorSystem)
extends SvAppReference(consoleEnvironment, name)
) extends SvAppReference(consoleEnvironment, name)
with AppBackendReference
with BaseInspection[SvApp] {

Expand Down Expand Up @@ -403,14 +401,6 @@ class SvAppBackendReference(
httpCommand(HttpSvOperatorAppClient.GetMediatorNodeStatus())
}

/** Remote participant this sv app is configured to interact with. */
lazy val participantClient =
new ParticipantClientReference(
consoleEnvironment,
s"remote participant for `$name``",
config.participantClient.getParticipantClientConfig(),
)

/** Remote participant this sv app is configured to interact with. Uses admin tokens to bypass auth. */
lazy val participantClientWithAdminToken =
new ParticipantClientReference(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ import org.lfdecentralizedtrust.tokenstandard.{metadata, transferinstruction}
import com.digitalasset.canton.console.{BaseInspection, Help}
import com.digitalasset.canton.data.CantonTimestamp
import com.digitalasset.canton.topology.PartyId
import org.apache.pekko.actor.ActorSystem
import org.lfdecentralizedtrust.splice.codegen.java.splice.amuletrules.TransferPreapproval
import org.lfdecentralizedtrust.splice.codegen.java.splice.api.token.{
allocationv1,
allocationinstructionv1,
allocationv1,
transferinstructionv1,
}
import org.lfdecentralizedtrust.splice.codegen.java.splice.externalpartyamuletrules.TransferCommandCounter
Expand Down Expand Up @@ -505,8 +504,7 @@ abstract class ValidatorAppReference(
final class ValidatorAppBackendReference(
override val consoleEnvironment: SpliceConsoleEnvironment,
name: String,
)(implicit actorSystem: ActorSystem)
extends ValidatorAppReference(consoleEnvironment, name)
) extends ValidatorAppReference(consoleEnvironment, name)
with AppBackendReference
with BaseInspection[ValidatorApp] {

Expand Down Expand Up @@ -565,14 +563,6 @@ final class ValidatorAppBackendReference(
override def config: ValidatorAppBackendConfig =
consoleEnvironment.environment.config.validatorsByString(name)

/** Remote participant this validator app is configured to interact with. */
lazy val participantClient =
new ParticipantClientReference(
consoleEnvironment,
s"remote participant for `$name`",
config.participantClient.getParticipantClientConfig(),
)

/** Remote participant this validator app is configured to interact with. Uses admin tokens to bypass auth. */
val participantClientWithAdminToken =
new ParticipantClientReference(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

package org.lfdecentralizedtrust.splice.environment

import com.daml.metrics.api.MetricHandle.LabeledMetricsFactory
import com.daml.metrics.api.MetricsContext
import com.digitalasset.canton.config.CantonRequireTypes.InstanceName
import com.digitalasset.canton.console.{
ConsoleEnvironment,
Expand All @@ -16,6 +18,7 @@ import com.digitalasset.daml.lf.typesig.PackageSignature
import org.apache.pekko.actor.ActorSystem
import org.lfdecentralizedtrust.splice.config.SpliceConfig
import org.lfdecentralizedtrust.splice.console.*
import org.lfdecentralizedtrust.splice.http.{HttpClient, HttpClientMetrics}
import org.lfdecentralizedtrust.splice.scan.config.ScanAppClientConfig
import org.lfdecentralizedtrust.splice.sv.SvAppClientConfig
import org.lfdecentralizedtrust.splice.util.ResourceTemplateDecoder
Expand All @@ -25,6 +28,8 @@ import org.lfdecentralizedtrust.splice.validator.config.{
}
import org.lfdecentralizedtrust.splice.wallet.config.WalletAppClientConfig

import scala.concurrent.ExecutionContext

class SpliceConsoleEnvironment(
override val environment: SpliceEnvironment,
val consoleOutput: ConsoleOutput = StandardConsoleOutput,
Expand All @@ -33,17 +38,29 @@ class SpliceConsoleEnvironment(

override type Config = SpliceConfig

implicit val actorSystem: ActorSystem = environment.actorSystem
private implicit lazy val actorSystem: ActorSystem = environment.actorSystem
private implicit lazy val ec: ExecutionContext = environment.executionContext
private lazy val templateDecoder = new ResourceTemplateDecoder(
SpliceConsoleEnvironment.packageSignatures,
environment.loggerFactory,
)

private val metricsContext = MetricsContext("component" -> "splice-console-environment")

lazy val metricsFactory: LabeledMetricsFactory =
environment.metrics.metricsFactoryProvider.generateMetricsFactory(
metricsContext
)
lazy val httpClient: HttpClient = HttpClient(
HttpClient.HttpRequestParameters(environment.config.parameters.timeouts.requestTimeout),
HttpClientMetrics(metricsFactory),
logger,
)

lazy val httpCommandRunner: ConsoleHttpCommandRunner = new ConsoleHttpCommandRunner(
environment,
environment.config.parameters.timeouts.console,
environment.config.parameters.timeouts.requestTimeout,
)(this.tracer, templateDecoder)
environment.loggerFactory,
)(this.tracer, templateDecoder, httpClient, environment.executionContext, actorSystem)

def mergeLocalSpliceInstances(
locals: Seq[AppBackendReference]*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SpliceEnvironment(
// dump config (without sensitive data) to ease debugging
logger.info(s"SpliceEnvironment with config = {\n${config.dumpString}\n}")

private lazy val metrics = SpliceMetricsFactory(
lazy val metrics = SpliceMetricsFactory(
metricsRegistry,
dbStorageHistograms,
loggerFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ case class EnvironmentDefinition(
environment,
new TestConsoleOutput(loggerFactory),
) with TestEnvironment[SpliceConfig] {
override val actorSystem = super[TestEnvironment].actorSystem
override lazy val actorSystem = super[TestEnvironment].actorSystem
override val actualConfig: SpliceConfig = this.environment.config

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.digitalasset.canton.tracing.NoReportingTracerProvider
import com.digitalasset.canton.util.FutureInstances.parallelFuture
import com.typesafe.scalalogging.LazyLogging
import org.apache.pekko.Done
import org.apache.pekko.actor.{ActorSystem, CoordinatedShutdown}
import org.apache.pekko.actor.CoordinatedShutdown
import org.apache.pekko.http.scaladsl.Http
import org.lfdecentralizedtrust.splice.admin.api.client.{DamlGrpcClientMetrics, GrpcClientMetrics}
import org.lfdecentralizedtrust.splice.auth.AuthUtil
Expand Down Expand Up @@ -267,7 +267,7 @@ object SpliceTests extends LazyLogging {
// make `aliceSplitwell` etc. use updated usernames
override def rsw(name: String)(implicit
env: SpliceTestConsoleEnvironment
): SplitwellAppClientReference = extendLedgerApiUserWithCaseId(super.rsw(name))(env.actorSystem)
): SplitwellAppClientReference = extendLedgerApiUserWithCaseId(super.rsw(name))

override def perTestCaseName(name: String)(implicit env: SpliceTestConsoleEnvironment) =
s"${name}_tc$testCaseId.unverified.$ansAcronym"
Expand Down Expand Up @@ -297,7 +297,7 @@ object SpliceTests extends LazyLogging {

private def extendLedgerApiUserWithCaseId(
ref: SplitwellAppClientReference
)(implicit actorSystem: ActorSystem): SplitwellAppClientReference = {
): SplitwellAppClientReference = {
val newLedgerApiUser = perTestCaseNameWithoutUnverified(ref.config.ledgerApiUser)
val newLedgerApiConfig = ref.config.participantClient.ledgerApi
.copy(authConfig =
Expand Down
Loading
Loading