Skip to content

Commit

Permalink
update canton to 20240724.12179.0.v56114e19/2.10.0-snapshot.20240724.…
Browse files Browse the repository at this point in the history
…12179.0.v56114e19 in main-2.x (#19671)

tell-slack: canton

Co-authored-by: Azure Pipelines Daml Build <support@digitalasset.com>
  • Loading branch information
azure-pipelines[bot] and Azure Pipelines Daml Build authored Jul 25, 2024
1 parent 0f1b48f commit 3500e77
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,11 @@ class DomainNodeBootstrap(
_ <- initializeSequencerServices
_ <- initializeSequencer(domainId, topologyManager, namespaceKey)
// store the static domain parameters in our settings store
_ <- settingsStore
.saveSettings(StoredDomainNodeSettings(staticDomainParametersFromConfig))
.leftMap(_.toString)
_ <- EitherT
.right(
settingsStore
.saveSettings(StoredDomainNodeSettings(staticDomainParametersFromConfig))
)
.mapK(FutureUnlessShutdown.outcomeK)
// finally, store the node id (which means we have completed initialisation)
// as all methods above are idempotent, if we die during initialisation, we should come back here
Expand Down Expand Up @@ -355,11 +357,11 @@ class DomainNodeBootstrap(
// with another init call (which then writes to the node config store).
// fix this and either support crash recovery for init data or only persist once everything
// is properly initialized
staticDomainParameters <- settingsStore.fetchSettings
.map(
_.fold(staticDomainParametersFromConfig)(_.staticDomainParameters)
staticDomainParameters <- EitherT
.right(
settingsStore.fetchSettings
.map(_.fold(staticDomainParametersFromConfig)(_.staticDomainParameters))
)
.leftMap(_.toString)
.mapK(FutureUnlessShutdown.outcomeK)
manager <- EitherT
.fromEither[FutureUnlessShutdown](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

package com.digitalasset.canton.domain.config.store

import cats.data.EitherT
import cats.instances.future.*
import cats.syntax.either.*
import com.digitalasset.canton.ProtoDeserializationError
import com.digitalasset.canton.config.NonNegativeDuration
import com.digitalasset.canton.logging.{NamedLoggerFactory, NamedLogging}
import com.digitalasset.canton.resource.{DbStorage, MemoryStorage, Storage}
Expand All @@ -27,37 +23,29 @@ trait BaseNodeSettingsStore[T] extends AutoCloseable {
// (as we do it for participant settings).
// also, the update configuration should be atomic. right now, we do fetch / save, which is racy
// also, update this to mediator and sequencer. right now, we only do this for domain manager and domain nodes
def fetchSettings(implicit
traceContext: TraceContext
): EitherT[Future, BaseNodeSettingsStoreError, Option[T]]
def fetchSettings(implicit traceContext: TraceContext): Future[Option[T]]

def saveSettings(settings: T)(implicit
traceContext: TraceContext
): EitherT[Future, BaseNodeSettingsStoreError, Unit]
def saveSettings(settings: T)(implicit traceContext: TraceContext): Future[Unit]

// TODO(#15153) remove once we can assume that static domain parameters are persisted
protected def fixPreviousSettings(resetToConfig: Boolean, timeout: NonNegativeDuration)(
update: Option[T] => EitherT[Future, BaseNodeSettingsStoreError, Unit]
update: Option[T] => Future[Unit]
)(implicit executionContext: ExecutionContext, traceContext: TraceContext): Unit = {

val eitherT = fetchSettings.flatMap {
val result: Future[Unit] = fetchSettings.flatMap {
// if a value is stored, don't do anything
case Some(_) if !resetToConfig =>
EitherT.rightT[Future, BaseNodeSettingsStoreError](())
Future.unit
case Some(value) =>
noTracingLogger.warn(
"Resetting static domain parameters to the ones defined in the config! Please disable this again."
)
update(Some(value))
case None => update(None)
}

// wait until setting of static domain parameters completed
timeout
.await("Setting static domain parameters")(eitherT.value)
.valueOr { err =>
logger.error(s"Failed to updating static domain parameters during initialization: $err")
throw new RuntimeException(err.toString)
}
timeout.await("Setting static domain parameters")(result)
}

}
Expand All @@ -67,8 +55,6 @@ object BaseNodeSettingsStore {
storage: Storage,
dbFactory: DbStorage => BaseNodeSettingsStore[T],
loggerFactory: NamedLoggerFactory,
)(implicit
executionContext: ExecutionContext
): BaseNodeSettingsStore[T] =
storage match {
case _: MemoryStorage => new InMemoryBaseNodeConfigStore[T](loggerFactory)
Expand All @@ -77,30 +63,22 @@ object BaseNodeSettingsStore {

}

sealed trait BaseNodeSettingsStoreError
object BaseNodeSettingsStoreError {
final case class DbError(exception: Throwable) extends BaseNodeSettingsStoreError
final case class DeserializationError(deserializationError: ProtoDeserializationError)
extends BaseNodeSettingsStoreError
}

class InMemoryBaseNodeConfigStore[T](val loggerFactory: NamedLoggerFactory)(implicit
executionContext: ExecutionContext
) extends BaseNodeSettingsStore[T]
class InMemoryBaseNodeConfigStore[T](val loggerFactory: NamedLoggerFactory)
extends BaseNodeSettingsStore[T]
with NamedLogging {

private val currentSettings = new AtomicReference[Option[T]](None)

override def fetchSettings(implicit
traceContext: TraceContext
): EitherT[Future, BaseNodeSettingsStoreError, Option[T]] =
EitherT.pure(currentSettings.get())
): Future[Option[T]] =
Future.successful(currentSettings.get())

override def saveSettings(settings: T)(implicit
traceContext: TraceContext
): EitherT[Future, BaseNodeSettingsStoreError, Unit] = {
): Future[Unit] = {
currentSettings.set(Some(settings))
EitherT.pure(())
Future.unit
}

override def close(): Unit = ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@

package com.digitalasset.canton.domain.config.store

import cats.data.EitherT
import com.daml.nameof.NameOf.functionFullName
import com.digitalasset.canton.config.CantonRequireTypes.String1
import com.digitalasset.canton.config.ProcessingTimeout
import com.digitalasset.canton.logging.NamedLoggerFactory
import com.digitalasset.canton.protocol.StaticDomainParameters
import com.digitalasset.canton.resource.{DbStorage, DbStore, MemoryStorage, Storage}
import com.digitalasset.canton.tracing.TraceContext
import com.digitalasset.canton.util.EitherTUtil
import slick.jdbc.SetParameter

import java.util.concurrent.atomic.AtomicBoolean
Expand Down Expand Up @@ -71,47 +69,43 @@ class DbDomainNodeSettingsStore(

override def fetchSettings(implicit
traceContext: TraceContext
): EitherT[Future, BaseNodeSettingsStoreError, Option[StoredDomainNodeSettings]] = {
): Future[Option[StoredDomainNodeSettings]] = {
// we need to run this here since we introduced HA into the domain manager, as the pool
// might not be active, so would throw a PassiveInstanceException, taking the entire node down
fixPreviousSettingsOnce()
EitherTUtil.fromFuture(
storage
.query(
sql"""select static_domain_parameters from domain_node_settings #${storage
.limit(1)}""".as[StaticDomainParameters].headOption,
functionFullName,
)
.map(_.map(StoredDomainNodeSettings)),
BaseNodeSettingsStoreError.DbError,
)

storage
.query(
sql"""select static_domain_parameters from domain_node_settings #${storage
.limit(1)}""".as[StaticDomainParameters].headOption,
functionFullName,
)
.map(_.map(StoredDomainNodeSettings))
}

override def saveSettings(
settings: StoredDomainNodeSettings
)(implicit traceContext: TraceContext): EitherT[Future, BaseNodeSettingsStoreError, Unit] = {
)(implicit traceContext: TraceContext): Future[Unit] = {

val params = settings.staticDomainParameters
@unused
implicit val setConnParam: SetParameter[StaticDomainParameters] =
StaticDomainParameters.getVersionedSetParameter

EitherT.right(
storage
.update_(
storage.profile match {
case _: DbStorage.Profile.H2 =>
sqlu"""merge into domain_node_settings
storage.update_(
storage.profile match {
case _: DbStorage.Profile.H2 =>
sqlu"""merge into domain_node_settings
(lock, static_domain_parameters)
values
($singleRowLockValue, ${params})"""
case _: DbStorage.Profile.Postgres =>
sqlu"""insert into domain_node_settings (static_domain_parameters)
case _: DbStorage.Profile.Postgres =>
sqlu"""insert into domain_node_settings (static_domain_parameters)
values (${params})
on conflict (lock) do update set
static_domain_parameters = excluded.static_domain_parameters"""
case _: DbStorage.Profile.Oracle =>
sqlu"""merge into domain_node_settings dsc
case _: DbStorage.Profile.Oracle =>
sqlu"""merge into domain_node_settings dsc
using (
select
${params} static_domain_parameters
Expand All @@ -125,9 +119,8 @@ class DbDomainNodeSettingsStore(
insert (static_domain_parameters)
values (excluded.static_domain_parameters)
"""
},
functionFullName,
)
},
functionFullName,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ trait DomainNodeSettingsStoreTest {
val store = mkStore(false)
val config = makeConfig()
for {
_ <- store.saveSettings(config).valueOrFail("save")
current <- store.fetchSettings.valueOrFail("fetch")
_ <- store.saveSettings(config)
current <- store.fetchSettings
} yield {
current should contain(config)
}
Expand All @@ -42,9 +42,9 @@ trait DomainNodeSettingsStoreTest {
val updateConfig = makeConfig(true)

for {
_ <- store.saveSettings(config).valueOrFail("save")
_ <- store.saveSettings(updateConfig).valueOrFail("save")
current <- store.fetchSettings.valueOrFail("fetch")
_ <- store.saveSettings(config)
_ <- store.saveSettings(updateConfig)
current <- store.fetchSettings
} yield {
current should contain(updateConfig)
}
Expand Down Expand Up @@ -96,7 +96,7 @@ trait DbDomainNodeSettingsStoreTest
"prepopulates empty stores" in {
val store = mkStore(false)
for {
current <- store.fetchSettings.value.map(_.value)
current <- store.fetchSettings
} yield {
current should contain(makeConfig())
}
Expand All @@ -107,11 +107,11 @@ trait DbDomainNodeSettingsStoreTest
val store = mkStore(false)

for {
_ <- store.saveSettings(nonDefaultConfig).valueOrFail("save")
_ <- store.saveSettings(nonDefaultConfig)
store2 = mkStore(true)
current <-
loggerFactory.assertLogs(
store2.fetchSettings.valueOrFail("fetch"),
store2.fetchSettings,
_.warningMessage should include("Resetting static domain parameters to the ones "),
)
} yield {
Expand Down
6 changes: 3 additions & 3 deletions sdk/test-common/canton/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ if [ "{local}" = "true" ]; then
exit 0
fi
CANTON_ENTERPRISE_VERSION=2.10.0-snapshot.20240723.12177.0.vdf7c4002
CANTON_ENTERPRISE_SHA=1b1ebcaf295d90d8cf8536a16e39c84978ec2e14b91f12565c65f2e7e75837df
CANTON_ENTERPRISE_URL=https://digitalasset.jfrog.io/artifactory/assembly/daml/canton-backup/2.10.0-snapshot.20240723.12177.0.vdf7c4002/1b1ebcaf295d90d8cf8536a16e39c84978ec2e14b91f12565c65f2e7e75837df/canton-enterprise-2.10.0-snapshot.20240723.12177.0.vdf7c4002.tar.gz
CANTON_ENTERPRISE_VERSION=2.10.0-snapshot.20240724.12179.0.v56114e19
CANTON_ENTERPRISE_SHA=990516ddcf520b1791646ccd7dc1b7dfcf195b28097455f4693f321428ec89c1
CANTON_ENTERPRISE_URL=https://digitalasset.jfrog.io/artifactory/assembly/daml/canton-backup/2.10.0-snapshot.20240724.12179.0.v56114e19/990516ddcf520b1791646ccd7dc1b7dfcf195b28097455f4693f321428ec89c1/canton-enterprise-2.10.0-snapshot.20240724.12179.0.v56114e19.tar.gz
url=$$CANTON_ENTERPRISE_URL
Expand Down

0 comments on commit 3500e77

Please sign in to comment.