Skip to content

Commit

Permalink
Update 2022-05-16.07 (#26)
Browse files Browse the repository at this point in the history
Reference commit: 34e687665

Co-authored-by: Canton <[email protected]>
  • Loading branch information
canton-machine and Canton authored May 16, 2022
1 parent 359a954 commit 17366f9
Show file tree
Hide file tree
Showing 165 changed files with 2,172 additions and 1,800 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,12 @@ object TopologyAdminCommands {
signedBy: Option[Fingerprint],
domainId: DomainId,
newParameters: DynamicDomainParameters,
force: Boolean,
) extends BaseCommand[v0.DomainParametersChangeAuthorization] {
override def createRequest(): Either[String, v0.DomainParametersChangeAuthorization] =
v0.DomainParametersChangeAuthorization(
authorization =
authData(TopologyChangeOp.Replace, signedBy, replaceExisting = false, force = false),
authData(TopologyChangeOp.Replace, signedBy, replaceExisting = false, force = force),
domain = domainId.toProtoPrimitive,
parameters = Option(newParameters.toProtoV0),
).asRight
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,34 +249,4 @@ object VaultAdminCommands {
)
}

case class RotateHmacSecret(length: Int)
extends BaseVaultAdminCommand[
v0.RotateHmacSecretRequest,
v0.RotateHmacSecretResponse,
Unit,
] {

override def createRequest(): Either[String, v0.RotateHmacSecretRequest] =
Right(
v0.RotateHmacSecretRequest(
length = length
)
)

override def submitRequest(
service: VaultServiceStub,
request: v0.RotateHmacSecretRequest,
): Future[v0.RotateHmacSecretResponse] = {
service.rotateHmacSecret(request)
}

override def handleResponse(
response: v0.RotateHmacSecretResponse
): Either[String, Unit] = Right(())

// may time some time if we need to wait for entropy
override def timeoutType: TimeoutType = DefaultUnboundedTimeout

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.digitalasset.canton.console.CommandErrors.ConsoleTimeout
import com.digitalasset.canton.crypto.Crypto
import com.digitalasset.canton.environment.{CantonNode, CantonNodeBootstrap}
import com.digitalasset.canton.logging.{NamedLogging, TracedLogger}
import com.digitalasset.canton.tracing.NoTracing

import scala.annotation.tailrec

Expand Down Expand Up @@ -103,7 +102,7 @@ trait BaseInspection[I <: CantonNode] {

}

trait FeatureFlagFilter extends NamedLogging with NoTracing {
trait FeatureFlagFilter extends NamedLogging {

protected def consoleEnvironment: ConsoleEnvironment

Expand All @@ -113,7 +112,7 @@ trait FeatureFlagFilter extends NamedLogging with NoTracing {
if (flag) {
command
} else {
logger.error(
noTracingLogger.error(
s"The command is currently disabled. You need to enable it explicitly by setting `canton.features.${config} = yes` in your Canton configuration file (`.conf`)"
)
throw new CommandFailure()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ammonite.util.Bind
import com.digitalasset.canton.DomainAlias
import com.digitalasset.canton.admin.api.client.data.CantonStatus
import com.digitalasset.canton.config.RequireTypes.{InstanceName, NonNegativeInt}
import com.digitalasset.canton.config.{ConsoleCommandTimeout, TimeoutDuration}
import com.digitalasset.canton.config.{ConsoleCommandTimeout, ProcessingTimeout, TimeoutDuration}
import com.digitalasset.canton.console.CommandErrors.{
CantonCommandError,
CommandInternalError,
Expand All @@ -17,6 +17,7 @@ import com.digitalasset.canton.console.Help.{Description, Summary, Topic}
import com.digitalasset.canton.crypto.Fingerprint
import com.digitalasset.canton.data.CantonTimestamp
import com.digitalasset.canton.environment.Environment
import com.digitalasset.canton.lifecycle.{FlagCloseable, Lifecycle}
import com.digitalasset.canton.logging.{NamedLoggerFactory, NamedLogging}
import com.digitalasset.canton.sequencing.{GrpcSequencerConnection, SequencerConnection}
import com.digitalasset.canton.time.{NonNegativeFiniteDuration, SimClock}
Expand All @@ -38,7 +39,7 @@ case class NodeReferences[A, R <: A, L <: A](local: Seq[L], remote: Seq[R]) {
/** The environment in which console commands are evaluated.
*/
@SuppressWarnings(Array("org.wartremover.warts.Any")) // required for `Binding[_]` usage
trait ConsoleEnvironment extends NamedLogging with AutoCloseable with NoTracing {
trait ConsoleEnvironment extends NamedLogging with FlagCloseable with NoTracing {
type Env <: Environment
type DomainLocalRef <: LocalDomainReference
type DomainRemoteRef <: RemoteDomainReference
Expand Down Expand Up @@ -129,6 +130,8 @@ trait ConsoleEnvironment extends NamedLogging with AutoCloseable with NoTracing

}

protected def timeouts: ProcessingTimeout = environment.config.parameters.timeouts.processing

/** @return maximum runtime of a console command
*/
def commandTimeouts: ConsoleCommandTimeout = commandTimeoutReference.get()
Expand Down Expand Up @@ -441,10 +444,8 @@ trait ConsoleEnvironment extends NamedLogging with AutoCloseable with NoTracing
*/
protected def selfAlias(): Bind[_] = Bind(ConsoleEnvironmentBinding.BindingName, this)

override def close(): Unit = {
grpcAdminCommandRunner.close()
environment.close()
tracerProvider.close()
override def onClosed(): Unit = {
Lifecycle.close(grpcAdminCommandRunner, environment, tracerProvider)(logger)
}

def startAll(): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.digitalasset.canton.participant.config.{
import com.digitalasset.canton.protocol.{LfContractId, SerializableContractWithWitnesses}
import com.digitalasset.canton.sequencing.SequencerConnection
import com.digitalasset.canton.topology.{DomainId, Identity, ParticipantId}
import com.digitalasset.canton.tracing.TraceContext
import com.digitalasset.canton.tracing.{NoTracing, TraceContext}
import com.digitalasset.canton.util.ErrorUtil

import scala.util.hashing.MurmurHash3
Expand Down Expand Up @@ -82,7 +82,7 @@ trait InstanceReference
/** Pointer for a potentially running instance by instance type (domain/participant) and its id.
* These methods define the REPL interface for these instances (e.g. participant1 start)
*/
trait LocalInstanceReference extends InstanceReference {
trait LocalInstanceReference extends InstanceReference with NoTracing {

val name: String
val consoleEnvironment: ConsoleEnvironment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.digitalasset.canton.topology._
import com.digitalasset.canton.topology.admin.grpc.BaseQuery
import com.digitalasset.canton.topology.store.{TimeQuery, TopologyStoreId}
import com.digitalasset.canton.topology.transaction._
import com.google.protobuf.ByteString

trait DomainAdministration {
this: AdminCommandRunner =>
Expand Down Expand Up @@ -117,8 +118,8 @@ trait DomainAdministration {
)

@Help.Summary("Set the Dynamic Domain Parameters configured for the domain")
def set_dynamic_domain_parameters(dynamicDomainParameters: DynamicDomainParameters) =
topology.domain_parameters_changes.authorize(id, dynamicDomainParameters).discard
def set_dynamic_domain_parameters(dynamicDomainParameters: DynamicDomainParameters): Unit =
topology.domain_parameters_changes.authorize(id, dynamicDomainParameters).discard[ByteString]

@Help.Summary("Update the Dynamic Domain Parameters for the domain")
def update_dynamic_parameters(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import com.digitalasset.canton.metrics.MetricHandle
import com.digitalasset.canton.networking.grpc.{GrpcError, RecordingStreamObserver}
import com.digitalasset.canton.protocol.LfContractId
import com.digitalasset.canton.topology.{DomainId, ParticipantId, PartyId}
import com.digitalasset.canton.tracing.NoTracing
import com.digitalasset.canton.util.ResourceUtil
import com.digitalasset.canton.{LedgerTransactionId, LfPartyId}
import io.grpc.StatusRuntimeException
Expand All @@ -64,7 +65,7 @@ import java.util.concurrent.TimeoutException
import java.util.concurrent.atomic.AtomicReference
import scala.concurrent.Await

trait BaseLedgerApiAdministration {
trait BaseLedgerApiAdministration extends NoTracing {

this: LedgerApiCommandRunner with NamedLogging with FeatureFlagFilter =>
implicit protected val consoleEnvironment: ConsoleEnvironment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import com.digitalasset.canton.sequencing.{
import com.digitalasset.canton.serialization.ProtoConverter
import com.digitalasset.canton.time.{DomainTimeTrackerConfig, NonNegativeFiniteDuration}
import com.digitalasset.canton.topology.{DomainId, ParticipantId, PartyId}
import com.digitalasset.canton.tracing.NoTracing
import com.digitalasset.canton.util.ShowUtil._
import com.digitalasset.canton.util._

Expand Down Expand Up @@ -306,7 +307,8 @@ class LocalParticipantTestingGroup(
consoleEnvironment: ConsoleEnvironment,
loggerFactory: NamedLoggerFactory,
) extends ParticipantTestingGroup(participantRef, consoleEnvironment, loggerFactory)
with FeatureFlagFilter {
with FeatureFlagFilter
with NoTracing {

import participantRef._
@Help.Summary("Lookup contracts in the Private Contract Store", FeatureFlag.Testing)
Expand Down Expand Up @@ -557,7 +559,8 @@ class LocalParticipantPruningAdministrationGroup(
runner: AdminCommandRunner with LedgerApiCommandRunner with BaseInspection[ParticipantNode],
consoleEnvironment: ConsoleEnvironment,
loggerFactory: NamedLoggerFactory,
) extends ParticipantPruningAdministrationGroup(runner, consoleEnvironment, loggerFactory) {
) extends ParticipantPruningAdministrationGroup(runner, consoleEnvironment, loggerFactory)
with NoTracing {

import runner._

Expand All @@ -579,7 +582,8 @@ class LocalCommitmentsAdministrationGroup(
val consoleEnvironment: ConsoleEnvironment,
val loggerFactory: NamedLoggerFactory,
) extends FeatureFlagFilter
with Helpful {
with Helpful
with NoTracing {

import runner._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1177,11 +1177,11 @@ class TopologyAdministrationGroup(
object domain_parameters_changes extends Helpful {
@Help.Summary("Change domain parameters")
@Help.Description("""Authorize a transaction to change parameters of the domain.
domainId: Id of the domain affected by the change.
newParameters: New value of the domain parameters.
signedBy: Refers to the fingerprint of the authorizing key which in turn must be authorized by a valid, locally existing certificate.
If none is given, a key is automatically determined.
synchronize: Synchronize timeout can be used to ensure that the state has been propagated into the node
|domainId: Id of the domain affected by the change.
|newParameters: New value of the domain parameters.
|signedBy: Refers to the fingerprint of the authorizing key which in turn must be authorized by a valid, locally existing certificate.
| If none is given, a key is automatically determined.
|synchronize: Synchronize timeout can be used to ensure that the state has been propagated into the node
""")
def authorize(
domainId: DomainId,
Expand All @@ -1194,7 +1194,7 @@ class TopologyAdministrationGroup(
consoleEnvironment.run {
adminCommand(
TopologyAdminCommands.Write
.AuthorizeDomainParametersChange(signedBy, domainId, newParameters)
.AuthorizeDomainParametersChange(signedBy, domainId, newParameters, force = false)
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,6 @@ class SecretKeyAdministration(runner: AdminCommandRunner, consoleEnvironment: Co
}
}

@Help.Summary("Rotate the HMAC secret")
@Help.Description(
"""Replace the stored HMAC secret with a new generated secret of the given length.
length: Length of the HMAC secret. Must be at least 128 bits, but less than the internal block size of the hash function.
|"""
)
def rotate_hmac_secret(length: Int = HmacSecret.defaultLength): Unit = {
consoleEnvironment.run {
adminCommand(VaultAdminCommands.RotateHmacSecret(length))
}
}

}

class LocalSecretKeyAdministration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ if(participant.domains.list_registered().isEmpty) {

// above connect operation is asynchronous. it is generally at the discretion of the domain
// to decide if a participant can join and when. therefore, we need to asynchronously wait here
// until the participant observes his activation on the domain
// until the participant observes its activation on the domain
utils.retry_until_true {
participant.domains.active("mydomain")
}
// synchronize vetting to ensure the participant has the package needed for the ping
participant.packages.synchronize_vetting()

// verify that the connection works
participant.health.ping(participant)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sdk-version: 2.2.0-snapshot.20220504.9851.0.4c8e027d
sdk-version: 2.3.0-snapshot.20220511.9887.0.5a509164
sandbox-options:
- --wall-clock-time
name: contact
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sdk-version: 2.2.0-snapshot.20220504.9851.0.4c8e027d
sdk-version: 2.3.0-snapshot.20220511.9887.0.5a509164
sandbox-options:
- --wall-clock-time
name: message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

package com.digitalasset.canton.integration

import java.util.concurrent.Semaphore
import com.typesafe.scalalogging.LazyLogging

import java.util.concurrent.Semaphore
import java.util.concurrent.atomic.AtomicReference
import scala.util.control.NonFatal

/** Although our integration tests are designed not to conflict with one another when running concurrently,
Expand All @@ -22,31 +24,60 @@ import scala.util.control.NonFatal
* This may well activate a slow poke notification in ScalaTest, however these are left in place to support discovery
* of any tests that fail to halt entirely or run for an abnormally long amount of time.
*/
object ConcurrentEnvironmentLimiter {
object ConcurrentEnvironmentLimiter extends LazyLogging {

private sealed trait State
private object New extends State
private object Queued extends State
private object Running extends State
private object Failed extends State
private object Done extends State

val IntegrationTestConcurrencyLimit = "canton-test.integration.concurrency"

private val concurrencyLimit: Int = System.getProperty(IntegrationTestConcurrencyLimit, "1").toInt

/** Configured to be fair so earlier started tests will be first to get environments */
private val semaphore = new Semaphore(concurrencyLimit, true)

/** contains a map from test name to state (queue, run) */
private val active = new AtomicReference[Map[String, State]](Map.empty)

private def change(name: String, state: State, purge: Boolean = false): Unit = {
val current = active
.getAndUpdate { cur =>
if (purge) cur.removed(name)
else cur.updated(name, state)
}
val currentState = current.getOrElse(name, New)
val currentSet = current.keys.toSet
val numSet = if (purge) (currentSet - name) else (currentSet + name)
logger.debug(s"${name}: $currentState => $state (${numSet.size} pending)")
}

/** Block an environment creation until a permit is available. */
def create[A](block: => A): A = {
def create[A](name: String)(block: => A): A = {
change(name, Queued)
scala.concurrent.blocking {
semaphore.acquire()
}
change(name, Running)
try block
catch {
// creations can easily fail and throw
// capture these and immediately release the permit as the destroy method will not be called
case NonFatal(e) =>
semaphore.release()
change(name, Failed, purge = true)
throw e
}
}

/** Attempt to destroy an environment and ensure that the permit is released */
def destroy[A](block: => A): A =
def destroy[A](name: String)(block: => A): A =
try block
finally semaphore.release()
finally {
semaphore.release()
change(name, Done, purge = true)
}
}
Loading

0 comments on commit 17366f9

Please sign in to comment.