From a4c25d1f1cc259f8de6743bf40e928aba9e1497a Mon Sep 17 00:00:00 2001 From: Robert Autenrieth Date: Sat, 9 Oct 2021 00:23:07 +0200 Subject: [PATCH] wip --- .../ledgerinteraction/GrpcLedgerClient.scala | 2 +- .../api/util/util/TimeProvider.scala | 4 +- .../api/util/util/TimestampConversion.scala | 46 ++++++++- .../util/util/TimestampConversionSpec.scala | 38 +++++++- .../configuration/LedgerTimeModel.scala | 9 +- .../apiserver/SpannedIndexService.scala | 1 - .../apiserver/StandaloneApiServer.scala | 13 +-- .../admin/ApiPackageManagementService.scala | 11 +-- .../platform/index/ReadOnlySqlLedger.scala | 1 - .../index/TransactionConversion.scala | 4 +- .../packages/InMemoryPackageStore.scala | 9 +- .../scala/platform/store/BaseLedger.scala | 1 - .../scala/platform/store/Conversions.scala | 10 -- .../scala/platform/store/ReadOnlyLedger.scala | 1 - .../store/appendonlydao/JdbcLedgerDao.scala | 2 +- .../appendonlydao/events/EventsTable.scala | 18 +--- .../events/PostCommitValidation.scala | 1 - .../ContractStorageBackendTemplate.scala | 1 - .../DeduplicationStorageBackendTemplate.scala | 2 +- .../common/EventStorageBackendTemplate.scala | 1 - .../platform/store/backend/common/Field.scala | 1 - .../PackageStorageBackendTemplate.scala | 2 +- .../backend/oracle/OracleStorageBackend.scala | 1 - .../postgresql/PostgresStorageBackend.scala | 1 - .../MutableCacheBackedContractStore.scala | 1 - .../platform/store/dao/JdbcLedgerDao.scala | 40 ++++---- .../platform/store/dao/MeteredLedgerDao.scala | 1 - .../store/dao/events/ContractStateEvent.scala | 1 - .../store/dao/events/ContractsReader.scala | 14 +-- .../platform/store/entries/LedgerEntry.scala | 1 - .../interfaces/LedgerDaoContractsReader.scala | 1 - .../interfaces/TransactionLogUpdate.scala | 1 - .../StorageBackendTestsDeduplication.scala | 22 ++--- ...dbcLedgerDaoCommandDeduplicationSpec.scala | 11 +-- .../dao/JdbcLedgerDaoCompletionsSpec.scala | 6 +- .../dao/JdbcLedgerDaoContractsSpec.scala | 6 +- .../dao/JdbcLedgerDaoDivulgenceSpec.scala | 9 +- .../store/dao/JdbcLedgerDaoPackagesSpec.scala | 7 +- .../store/dao/JdbcLedgerDaoPartiesSpec.scala | 13 ++- .../store/dao/JdbcLedgerDaoSuite.scala | 54 +++++------ .../JdbcLedgerDaoTransactionTreesSpec.scala | 10 +- .../dao/JdbcLedgerDaoTransactionsSpec.scala | 10 +- .../dao/JdbcPipelinedInsertionsSpec.scala | 4 +- .../ApiPackageManagementServiceSpec.scala | 11 +-- .../StoreBackedCommandExecutorSpec.scala | 5 +- .../services/ApiSubmissionServiceSpec.scala | 16 ++-- .../platform/index/BuffersUpdaterSpec.scala | 7 +- .../index/TransactionConversionSpec.scala | 7 +- .../platform/indexer/ExecuteUpdateSpec.scala | 7 +- .../store/CompletionFromTransactionSpec.scala | 7 +- .../SequentialWriteDaoSpec.scala | 3 +- .../BufferedTransactionsReaderSpec.scala | 10 +- .../MutableCacheBackedContractStoreSpec.scala | 29 ++---- .../platform/sandbox/SandboxServer.scala | 10 +- .../stores/LedgerBackedWriteService.scala | 2 +- .../stores/SandboxIndexAndWriteService.scala | 4 +- .../sandbox/stores/ledger/Ledger.scala | 4 +- .../sandbox/stores/ledger/MeteredLedger.scala | 4 +- .../stores/ledger/ScenarioLoader.scala | 4 +- .../ledger/inmemory/InMemoryLedger.scala | 93 +++++++------------ .../sandbox/stores/ledger/sql/SqlLedger.scala | 30 +++--- .../sql/SqlLedgerOnMutableIndexSpec.scala | 8 +- .../stores/ledger/sql/SqlLedgerSpec.scala | 8 +- 63 files changed, 309 insertions(+), 352 deletions(-) diff --git a/daml-script/runner/src/main/scala/com/digitalasset/daml/lf/engine/script/ledgerinteraction/GrpcLedgerClient.scala b/daml-script/runner/src/main/scala/com/digitalasset/daml/lf/engine/script/ledgerinteraction/GrpcLedgerClient.scala index 3c4ed821398a..d6606a9da8c8 100644 --- a/daml-script/runner/src/main/scala/com/digitalasset/daml/lf/engine/script/ledgerinteraction/GrpcLedgerClient.scala +++ b/daml-script/runner/src/main/scala/com/digitalasset/daml/lf/engine/script/ledgerinteraction/GrpcLedgerClient.scala @@ -251,7 +251,7 @@ class GrpcLedgerClient(val grpcClient: LedgerClient, val applicationId: Applicat resp <- ClientAdapter .serverStreaming(GetTimeRequest(grpcClient.ledgerId.unwrap), timeService.getTime) .runWith(Sink.head) - } yield Time.Timestamp.assertFromInstant(TimestampConversion.toInstant(resp.getCurrentTime)) + } yield TimestampConversion.toLf(resp.getCurrentTime, TimestampConversion.ConversionMode.HalfUp) } override def setStaticTime(time: Time.Timestamp)(implicit diff --git a/language-support/scala/bindings/src/main/scala/com/digitalasset/api/util/util/TimeProvider.scala b/language-support/scala/bindings/src/main/scala/com/digitalasset/api/util/util/TimeProvider.scala index 0a663aae5d5a..f6c046d5b918 100644 --- a/language-support/scala/bindings/src/main/scala/com/digitalasset/api/util/util/TimeProvider.scala +++ b/language-support/scala/bindings/src/main/scala/com/digitalasset/api/util/util/TimeProvider.scala @@ -4,13 +4,15 @@ package com.daml.api.util import java.time.{Clock, Instant} - import com.daml.api.util.TimeProvider.MappedTimeProvider +import com.daml.lf.data.Time.Timestamp trait TimeProvider { self => def getCurrentTime: Instant + def getCurrentTimestamp: Timestamp = Timestamp.assertFromInstant(getCurrentTime) + def map(transform: Instant => Instant): TimeProvider = MappedTimeProvider(this, transform) } diff --git a/language-support/scala/bindings/src/main/scala/com/digitalasset/api/util/util/TimestampConversion.scala b/language-support/scala/bindings/src/main/scala/com/digitalasset/api/util/util/TimestampConversion.scala index 995224ffcd25..b21858d45aa7 100644 --- a/language-support/scala/bindings/src/main/scala/com/digitalasset/api/util/util/TimestampConversion.scala +++ b/language-support/scala/bindings/src/main/scala/com/digitalasset/api/util/util/TimestampConversion.scala @@ -7,7 +7,8 @@ import java.time.Instant import java.util.concurrent.TimeUnit import com.daml.ledger.api.v1.value.Value -import com.google.protobuf.timestamp.Timestamp +import com.google.protobuf.timestamp.{Timestamp => ProtoTimestamp} +import com.daml.lf.data.Time.{Timestamp => LfTimestamp} object TimestampConversion { val MIN = Instant parse "0001-01-01T00:00:00Z" @@ -32,11 +33,48 @@ object TimestampConversion { } - def toInstant(protoTimestamp: Timestamp): Instant = { + def toInstant(protoTimestamp: ProtoTimestamp): Instant = { Instant.ofEpochSecond(protoTimestamp.seconds, protoTimestamp.nanos.toLong) } - def fromInstant(instant: Instant): Timestamp = { - new Timestamp().withSeconds(instant.getEpochSecond).withNanos(instant.getNano) + def fromInstant(instant: Instant): ProtoTimestamp = { + new ProtoTimestamp().withSeconds(instant.getEpochSecond).withNanos(instant.getNano) + } + + def toLf(protoTimestamp: ProtoTimestamp, mode: ConversionMode): LfTimestamp = { + val instant = roundToMicros(toInstant(protoTimestamp), mode) + LfTimestamp.assertFromInstant(instant) + } + + def fromLf(timestamp: LfTimestamp): ProtoTimestamp = { + fromInstant(timestamp.toInstant) + } + + private def roundToMicros(t: Instant, mode: ConversionMode): Instant = { + val fractionNanos = t.getNano % 1000L + if (fractionNanos != 0) { + mode match { + case ConversionMode.Exact => throw new IllegalArgumentException( + s"Conversion of $t to microsecond granularity would result in loss of precision." + ) + case ConversionMode.Up => t.plusNanos(1000L - fractionNanos) + case ConversionMode.Down => t.plusNanos(- fractionNanos) + case ConversionMode.HalfUp => t.plusNanos(if (fractionNanos >= 500L) 1000L - fractionNanos else -fractionNanos) + } + } else { + t + } + } + + sealed trait ConversionMode + object ConversionMode { + /** Throw an exception if the input can not be represented in microsecond resolution */ + case object Exact extends ConversionMode + /** Round up to the nearest microsecond */ + case object Up extends ConversionMode + /** Round down to the nearest microsecond */ + case object Down extends ConversionMode + /** Round to the nearest microsecond */ + case object HalfUp extends ConversionMode } } diff --git a/language-support/scala/bindings/src/test/scala/com/digitalasset/api/util/util/TimestampConversionSpec.scala b/language-support/scala/bindings/src/test/scala/com/digitalasset/api/util/util/TimestampConversionSpec.scala index 8aed4dec04af..e7fb313612ee 100644 --- a/language-support/scala/bindings/src/test/scala/com/digitalasset/api/util/util/TimestampConversionSpec.scala +++ b/language-support/scala/bindings/src/test/scala/com/digitalasset/api/util/util/TimestampConversionSpec.scala @@ -4,13 +4,12 @@ package com.daml.api.util import java.time.Instant - import com.daml.ledger.api.v1.value.Value.{Sum => VSum} import TimestampConversion._ - import org.scalacheck.Gen import org.scalacheck.Prop import Prop.exists +import com.daml.lf.data.Time import org.scalatestplus.scalacheck.{Checkers, ScalaCheckDrivenPropertyChecks} import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec @@ -81,6 +80,39 @@ class TimestampConversionSpec } } } + + "fromLf" when { + "given a value in specified domain" should { + "be retracted by toLf" in forAll(lfTimestampGen) { ts => + toLf(fromLf(ts), ConversionMode.Exact) shouldBe ts + } + } + } + + "toLf" when { + "given a valid microsecond timestamp" should { + "be retracted by fromLf" in forAll(anyMicroInRange) { ts => + val protoTs = fromInstant(ts) + fromLf(toLf(protoTs, ConversionMode.Exact)) shouldBe protoTs + } + } + + "given a valid nanosecond timestamp" should { + "be retracted by fromLf" in forAll(anyTimeInRange) { ts => + val protoTs = fromInstant(ts) + val down = toLf(protoTs, ConversionMode.Down) + val up = toLf(protoTs, ConversionMode.Up) + val halfUp = toLf(protoTs, ConversionMode.HalfUp) + down.toInstant should be <= ts + up.toInstant should be >= ts + down should be < up + halfUp should (be (down) or be (up)) + (up.micros - down.micros) shouldBe 1000 + up.toInstant.truncatedTo(java.time.temporal.ChronoUnit.MICROS) shouldBe up.toInstant + down.toInstant.truncatedTo(java.time.temporal.ChronoUnit.MICROS) shouldBe down.toInstant + } + } + } } object TimestampConversionSpec { @@ -110,4 +142,6 @@ object TimestampConversionSpec { val anyMicroInRange: Gen[Instant] = timeGen(MIN, MAX, microsOnly = true) + + val lfTimestampGen: Gen[Time.Timestamp] = arbitrary[Long] map Time.Timestamp.assertFromLong } diff --git a/ledger/ledger-configuration/src/main/scala/com/daml/ledger/configuration/LedgerTimeModel.scala b/ledger/ledger-configuration/src/main/scala/com/daml/ledger/configuration/LedgerTimeModel.scala index 4bf5b29c2b72..5860ee00807d 100644 --- a/ledger/ledger-configuration/src/main/scala/com/daml/ledger/configuration/LedgerTimeModel.scala +++ b/ledger/ledger-configuration/src/main/scala/com/daml/ledger/configuration/LedgerTimeModel.scala @@ -4,8 +4,8 @@ package com.daml.ledger.configuration import java.time.{Duration, Instant} - import com.daml.ledger.configuration.LedgerTimeModel._ +import com.daml.lf.data.Time.Timestamp import scala.util.Try @@ -43,6 +43,13 @@ case class LedgerTimeModel private ( } } + def checkTime( + ledgerTime: Timestamp, + recordTime: Timestamp, + ): Either[OutOfRange, Unit] = { + checkTime(ledgerTime.toInstant, recordTime.toInstant) + } + private[ledger] def minLedgerTime(recordTime: Instant): Instant = recordTime.minus(minSkew) diff --git a/ledger/participant-integration-api/src/main/scala/platform/apiserver/SpannedIndexService.scala b/ledger/participant-integration-api/src/main/scala/platform/apiserver/SpannedIndexService.scala index f9dfce075140..49743ea89b4c 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/apiserver/SpannedIndexService.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/apiserver/SpannedIndexService.scala @@ -3,7 +3,6 @@ package com.daml.platform.apiserver -import java.time.Instant import akka.NotUsed import akka.stream.scaladsl.Source import com.daml.daml_lf_dev.DamlLf diff --git a/ledger/participant-integration-api/src/main/scala/platform/apiserver/StandaloneApiServer.scala b/ledger/participant-integration-api/src/main/scala/platform/apiserver/StandaloneApiServer.scala index 387ce87a52be..e15ad9c8565f 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/apiserver/StandaloneApiServer.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/apiserver/StandaloneApiServer.scala @@ -4,8 +4,7 @@ package com.daml.platform.apiserver import java.io.File -import java.time.{Clock, Instant} - +import java.time.Clock import akka.actor.ActorSystem import akka.stream.Materializer import com.daml.api.util.TimeProvider @@ -18,15 +17,11 @@ import com.daml.ledger.configuration.LedgerId import com.daml.ledger.participant.state.{v2 => state} import com.daml.ledger.resources.{Resource, ResourceContext, ResourceOwner} import com.daml.lf.data.Ref +import com.daml.lf.data.Time.Timestamp import com.daml.lf.engine.{Engine, ValueEnricher} import com.daml.logging.{ContextualizedLogger, LoggingContext} import com.daml.metrics.Metrics -import com.daml.platform.configuration.{ - CommandConfiguration, - PartyConfiguration, - ServerRole, - SubmissionConfiguration, -} +import com.daml.platform.configuration.{CommandConfiguration, PartyConfiguration, ServerRole, SubmissionConfiguration} import com.daml.platform.index.JdbcIndex import com.daml.platform.packages.InMemoryPackageStore import com.daml.platform.services.time.TimeProviderType @@ -166,7 +161,7 @@ final class StandaloneApiServer( config.archiveFiles .foldLeft[Either[(String, File), InMemoryPackageStore]](Right(InMemoryPackageStore.empty)) { case (storeE, f) => - storeE.flatMap(_.withDarFile(Instant.now(), None, f).left.map(_ -> f)) + storeE.flatMap(_.withDarFile(Timestamp.now(), None, f).left.map(_ -> f)) } .fold({ case (err, file) => sys.error(s"Could not load package $file: $err") }, identity) } diff --git a/ledger/participant-integration-api/src/main/scala/platform/apiserver/services/admin/ApiPackageManagementService.scala b/ledger/participant-integration-api/src/main/scala/platform/apiserver/services/admin/ApiPackageManagementService.scala index 51b6c4d85726..4779560d3b29 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/apiserver/services/admin/ApiPackageManagementService.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/apiserver/services/admin/ApiPackageManagementService.scala @@ -5,18 +5,14 @@ package com.daml.platform.apiserver.services.admin import java.time.Duration import java.util.zip.ZipInputStream - import akka.stream.Materializer import akka.stream.scaladsl.Source +import com.daml.api.util.TimestampConversion import com.daml.daml_lf_dev.DamlLf.Archive import com.daml.ledger.api.domain.{LedgerOffset, PackageEntry} import com.daml.ledger.api.v1.admin.package_management_service.PackageManagementServiceGrpc.PackageManagementService import com.daml.ledger.api.v1.admin.package_management_service._ -import com.daml.ledger.participant.state.index.v2.{ - IndexPackagesService, - IndexTransactionsService, - LedgerEndService, -} +import com.daml.ledger.participant.state.index.v2.{IndexPackagesService, IndexTransactionsService, LedgerEndService} import com.daml.ledger.participant.state.{v2 => state} import com.daml.lf.archive.{Dar, DarParser, Decode, GenDarReader} import com.daml.lf.data.Ref @@ -29,7 +25,6 @@ import com.daml.platform.apiserver.services.logging import com.daml.platform.server.api.ValidationLogger import com.daml.platform.server.api.validation.ErrorFactories import com.daml.telemetry.{DefaultTelemetry, TelemetryContext} -import com.google.protobuf.timestamp.Timestamp import io.grpc.{ServerServiceDefinition, StatusRuntimeException} import scalaz.std.either._ import scalaz.std.list._ @@ -81,7 +76,7 @@ private[apiserver] final class ApiPackageManagementService private ( PackageDetails( pkgId.toString, details.size, - Some(Timestamp(details.knownSince.getEpochSecond, details.knownSince.getNano)), + Some(TimestampConversion.fromLf(details.knownSince)), details.sourceDescription.getOrElse(""), ) }) diff --git a/ledger/participant-integration-api/src/main/scala/platform/index/ReadOnlySqlLedger.scala b/ledger/participant-integration-api/src/main/scala/platform/index/ReadOnlySqlLedger.scala index d8bdb44c72c7..ef1cfd25ec14 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/index/ReadOnlySqlLedger.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/index/ReadOnlySqlLedger.scala @@ -4,7 +4,6 @@ package com.daml.platform.index import java.sql.SQLException -import java.time.Instant import akka.Done import akka.actor.Cancellable import akka.stream._ diff --git a/ledger/participant-integration-api/src/main/scala/platform/index/TransactionConversion.scala b/ledger/participant-integration-api/src/main/scala/platform/index/TransactionConversion.scala index 726fa673d4b5..bbdf64d68c97 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/index/TransactionConversion.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/index/TransactionConversion.scala @@ -106,7 +106,7 @@ private[platform] object TransactionConversion { transactionId = entry.transactionId, commandId = commandId, workflowId = entry.workflowId.getOrElse(""), - effectiveAt = Some(TimestampConversion.fromInstant(entry.ledgerEffectiveTime)), + effectiveAt = Some(TimestampConversion.fromLf(entry.ledgerEffectiveTime)), events = filtered, offset = offset.value, ) @@ -220,7 +220,7 @@ private[platform] object TransactionConversion { transactionId = entry.transactionId, commandId = maskCommandId(entry.commandId, entry.actAs, requestingParties), workflowId = entry.workflowId.getOrElse(""), - effectiveAt = Some(TimestampConversion.fromInstant(entry.ledgerEffectiveTime)), + effectiveAt = Some(TimestampConversion.fromLf(entry.ledgerEffectiveTime)), offset = offset.value, ) ) diff --git a/ledger/participant-integration-api/src/main/scala/platform/packages/InMemoryPackageStore.scala b/ledger/participant-integration-api/src/main/scala/platform/packages/InMemoryPackageStore.scala index e093a3149721..20a6fa8051b8 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/packages/InMemoryPackageStore.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/packages/InMemoryPackageStore.scala @@ -4,13 +4,12 @@ package com.daml.platform.packages import java.io.File -import java.time.Instant - import com.daml.ledger.participant.state.index.v2.PackageDetails import com.daml.lf.archive import com.daml.lf.data.Ref.PackageId import com.daml.lf.language.Ast import com.daml.daml_lf_dev.DamlLf +import com.daml.lf.data.Time.Timestamp import org.slf4j.LoggerFactory import scalaz.std.either._ import scalaz.std.list._ @@ -49,14 +48,14 @@ private[platform] case class InMemoryPackageStore( packages.get(packageId) def withPackages( - knownSince: Instant, + knownSince: Timestamp, sourceDescription: Option[String], packages: List[DamlLf.Archive], ): Either[String, InMemoryPackageStore] = addArchives(knownSince, sourceDescription, packages) def withDarFile( - knownSince: Instant, + knownSince: Timestamp, sourceDescription: Option[String], file: File, ): Either[String, InMemoryPackageStore] = @@ -90,7 +89,7 @@ private[platform] case class InMemoryPackageStore( } private def addArchives( - knownSince: Instant, + knownSince: Timestamp, sourceDescription: Option[String], archives: List[DamlLf.Archive], ): Either[String, InMemoryPackageStore] = diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/BaseLedger.scala b/ledger/participant-integration-api/src/main/scala/platform/store/BaseLedger.scala index 0b03ed5703b7..ee114cf77215 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/BaseLedger.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/BaseLedger.scala @@ -3,7 +3,6 @@ package com.daml.platform.store -import java.time.Instant import akka.NotUsed import akka.stream.scaladsl.Source import com.daml.daml_lf_dev.DamlLf diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/Conversions.scala b/ledger/participant-integration-api/src/main/scala/platform/store/Conversions.scala index 82d92bd734cf..3a04f2dc55d0 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/Conversions.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/Conversions.scala @@ -7,7 +7,6 @@ import java.io.BufferedReader import java.sql.{PreparedStatement, Timestamp, Types} import java.time.Instant import java.util.Date -import java.util.concurrent.TimeUnit import java.util.stream.Collectors import anorm.Column.nonNull @@ -324,15 +323,6 @@ private[platform] object Conversions { def instantFromTimestamp(name: String): RowParser[Instant] = SqlParser.get[Date](name).map(_.toInstant) - def instantFromMicros(name: String): RowParser[Instant] = - SqlParser.get[Long](name).map(instantFromMicros) - - def instantFromMicros(micros: Long): Instant = { - val seconds = TimeUnit.MICROSECONDS.toSeconds(micros) - val microsOfSecond = micros - TimeUnit.SECONDS.toMicros(seconds) - Instant.ofEpochSecond(seconds, TimeUnit.MICROSECONDS.toNanos(microsOfSecond)) - } - def timestampFromMicros(name: String): RowParser[com.daml.lf.data.Time.Timestamp] = SqlParser.get[Long](name).map(com.daml.lf.data.Time.Timestamp.assertFromLong) diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/ReadOnlyLedger.scala b/ledger/participant-integration-api/src/main/scala/platform/store/ReadOnlyLedger.scala index 63b07466dad2..54ddc251bc54 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/ReadOnlyLedger.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/ReadOnlyLedger.scala @@ -3,7 +3,6 @@ package com.daml.platform.store -import java.time.Instant import akka.NotUsed import akka.stream.scaladsl.Source import com.daml.daml_lf_dev.DamlLf.Archive diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/JdbcLedgerDao.scala b/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/JdbcLedgerDao.scala index 623086c02ef0..8b5c4b5fa3bf 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/JdbcLedgerDao.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/JdbcLedgerDao.scala @@ -21,7 +21,7 @@ import com.daml.ledger.participant.state.{v2 => state} import com.daml.ledger.resources.ResourceOwner import com.daml.lf.archive.ArchiveParser import com.daml.lf.data.Time.Timestamp -import com.daml.lf.data.{Ref, Time} +import com.daml.lf.data.Ref import com.daml.lf.engine.ValueEnricher import com.daml.lf.transaction.{BlindingInfo, CommittedTransaction} import com.daml.logging.LoggingContext.withEnrichedLoggingContext diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/events/EventsTable.scala b/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/events/EventsTable.scala index abdad4fb87a0..334ab0090031 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/events/EventsTable.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/events/EventsTable.scala @@ -3,19 +3,11 @@ package com.daml.platform.store.appendonlydao.events +import com.daml.api.util.TimestampConversion import com.daml.ledger.api.v1.active_contracts_service.GetActiveContractsResponse import com.daml.ledger.api.v1.event.Event -import com.daml.ledger.api.v1.transaction.{ - TreeEvent, - Transaction => ApiTransaction, - TransactionTree => ApiTransactionTree, -} -import com.daml.ledger.api.v1.transaction_service.{ - GetFlatTransactionResponse, - GetTransactionResponse, - GetTransactionTreesResponse, - GetTransactionsResponse, -} +import com.daml.ledger.api.v1.transaction.{TreeEvent, Transaction => ApiTransaction, TransactionTree => ApiTransactionTree} +import com.daml.ledger.api.v1.transaction_service.{GetFlatTransactionResponse, GetTransactionResponse, GetTransactionTreesResponse, GetTransactionsResponse} import com.daml.ledger.offset.Offset import com.daml.lf.data.Time.Timestamp import com.daml.platform.ApiOffset @@ -50,7 +42,7 @@ object EventsTable { ApiTransaction( transactionId = first.transactionId, commandId = first.commandId, - effectiveAt = Some(first.ledgerEffectiveTime), + effectiveAt = Some(TimestampConversion.fromLf(first.ledgerEffectiveTime)), workflowId = first.workflowId, offset = ApiOffset.toApiString(first.eventOffset), events = flatEvents, @@ -123,7 +115,7 @@ object EventsTable { transactionId = first.transactionId, commandId = first.commandId, workflowId = first.workflowId, - effectiveAt = Some(first.ledgerEffectiveTime), + effectiveAt = Some(TimestampConversion.fromLf(first.ledgerEffectiveTime)), offset = ApiOffset.toApiString(first.eventOffset), eventsById = eventsById, rootEventIds = rootEventIds, diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/events/PostCommitValidation.scala b/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/events/PostCommitValidation.scala index fcf58a8cfa5c..126df7bef38c 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/events/PostCommitValidation.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/events/PostCommitValidation.scala @@ -4,7 +4,6 @@ package com.daml.platform.store.appendonlydao.events import java.sql.Connection -import java.time.Instant import com.daml.ledger.api.domain import com.daml.ledger.participant.state.{v1, v2} import com.daml.lf.data.Time.Timestamp diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/ContractStorageBackendTemplate.scala b/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/ContractStorageBackendTemplate.scala index ea786be63b9a..646a4504a788 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/ContractStorageBackendTemplate.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/ContractStorageBackendTemplate.scala @@ -12,7 +12,6 @@ import com.daml.platform.store.Conversions.{ contractId, flatEventWitnessesColumn, identifier, - instantFromMicros, offset, timestampFromMicros, } diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/DeduplicationStorageBackendTemplate.scala b/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/DeduplicationStorageBackendTemplate.scala index 5d2de735649c..a5e89e5cd34d 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/DeduplicationStorageBackendTemplate.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/DeduplicationStorageBackendTemplate.scala @@ -6,7 +6,7 @@ package com.daml.platform.store.backend.common import java.sql.Connection import anorm.{RowParser, SQL} import com.daml.lf.data.Time.Timestamp -import com.daml.platform.store.Conversions.{instantFromMicros, timestampFromMicros} +import com.daml.platform.store.Conversions.timestampFromMicros import com.daml.platform.store.backend.DeduplicationStorageBackend private[backend] trait DeduplicationStorageBackendTemplate extends DeduplicationStorageBackend { diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/EventStorageBackendTemplate.scala b/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/EventStorageBackendTemplate.scala index 6cad3689c207..7128c1836b85 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/EventStorageBackendTemplate.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/EventStorageBackendTemplate.scala @@ -14,7 +14,6 @@ import com.daml.platform.store.Conversions.{ contractId, eventId, identifier, - instantFromMicros, offset, timestampFromMicros, } diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/Field.scala b/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/Field.scala index 9da2608ccab8..6734ca5c256d 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/Field.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/Field.scala @@ -5,7 +5,6 @@ package com.daml.platform.store.backend.common import java.lang import java.sql.PreparedStatement -import java.util.concurrent.TimeUnit import scala.reflect.ClassTag diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/PackageStorageBackendTemplate.scala b/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/PackageStorageBackendTemplate.scala index 5c6619f5798f..c3d6a8171142 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/PackageStorageBackendTemplate.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/PackageStorageBackendTemplate.scala @@ -8,7 +8,7 @@ import anorm.SqlParser.{flatten, str} import anorm.{Macro, RowParser, SQL, SqlParser} import com.daml.ledger.offset.Offset import com.daml.ledger.participant.state.index.v2.PackageDetails -import com.daml.platform.store.Conversions.{instantFromMicros, ledgerString, offset, timestampFromMicros} +import com.daml.platform.store.Conversions.{ledgerString, offset, timestampFromMicros} import com.daml.lf.data.Ref.PackageId import com.daml.lf.data.Time.Timestamp import com.daml.platform.store.SimpleSqlAsVectorOf.SimpleSqlAsVectorOf diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/backend/oracle/OracleStorageBackend.scala b/ledger/participant-integration-api/src/main/scala/platform/store/backend/oracle/OracleStorageBackend.scala index 5b646d41b6d6..9932bb7f4335 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/backend/oracle/OracleStorageBackend.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/backend/oracle/OracleStorageBackend.scala @@ -32,7 +32,6 @@ import com.daml.platform.store.backend.{ } import java.sql.Connection -import java.time.Instant import com.daml.ledger.offset.Offset import com.daml.lf.data.Time.Timestamp import com.daml.platform.store.backend.EventStorageBackend.FilterParams diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/backend/postgresql/PostgresStorageBackend.scala b/ledger/participant-integration-api/src/main/scala/platform/store/backend/postgresql/PostgresStorageBackend.scala index a8e455e15d5d..4caa041ccef8 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/backend/postgresql/PostgresStorageBackend.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/backend/postgresql/PostgresStorageBackend.scala @@ -4,7 +4,6 @@ package com.daml.platform.store.backend.postgresql import java.sql.Connection -import java.time.Instant import anorm.SQL import anorm.SqlParser.{get, int} import com.daml.ledger.offset.Offset diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/cache/MutableCacheBackedContractStore.scala b/ledger/participant-integration-api/src/main/scala/platform/store/cache/MutableCacheBackedContractStore.scala index 2604df79c0b2..d8372287390a 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/cache/MutableCacheBackedContractStore.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/cache/MutableCacheBackedContractStore.scala @@ -21,7 +21,6 @@ import com.daml.platform.store.dao.events.ContractStateEvent.LedgerEndMarker import com.daml.platform.store.interfaces.LedgerDaoContractsReader import com.daml.platform.store.interfaces.LedgerDaoContractsReader.{ActiveContract, ArchivedContract, ContractState, KeyState} -import java.time.Instant import java.util.concurrent.atomic.AtomicReference import scala.concurrent.duration.{DurationInt, FiniteDuration} import scala.concurrent.{ExecutionContext, Future} diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/dao/JdbcLedgerDao.scala b/ledger/participant-integration-api/src/main/scala/platform/store/dao/JdbcLedgerDao.scala index 6d8fd0d9c883..385c73980f7c 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/dao/JdbcLedgerDao.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/dao/JdbcLedgerDao.scala @@ -282,7 +282,7 @@ private class JdbcLedgerDao( SQL_INSERT_CONFIGURATION_ENTRY .on( "ledger_offset" -> offsetStep.offset, - "recorded_at" -> recordedAt, + "recorded_at" -> recordedAt.toInstant, "submission_id" -> submissionId, "typ" -> typ, "rejection_reason" -> finalRejectionReason.orNull, @@ -333,7 +333,7 @@ private class JdbcLedgerDao( SQL_INSERT_PARTY_ENTRY_ACCEPT .on( "ledger_offset" -> offsetStep.offset, - "recorded_at" -> recordTime, + "recorded_at" -> recordTime.toInstant, "submission_id" -> submissionIdOpt, "party" -> partyDetails.party, "display_name" -> partyDetails.displayName, @@ -362,7 +362,7 @@ private class JdbcLedgerDao( SQL_INSERT_PARTY_ENTRY_REJECT .on( "ledger_offset" -> offsetStep.offset, - "recorded_at" -> recordTime, + "recorded_at" -> recordTime.toInstant, "submission_id" -> submissionId, "rejection_reason" -> reason, ) @@ -453,7 +453,7 @@ private class JdbcLedgerDao( completionInfo, workflowId, transactionId, - ledgerEffectiveTime, + ledgerEffectiveTime.toInstant, offset, transaction, divulgedContracts, @@ -463,11 +463,11 @@ private class JdbcLedgerDao( private def handleError( offset: Offset, completionInfo: state.CompletionInfo, - recordTime: Instant, + recordTime: Timestamp, rejectionReason: state.Update.CommandRejected.RejectionReasonTemplate, )(implicit connection: Connection): Unit = { stopDeduplicatingCommandSync(domain.CommandId(completionInfo.commandId), completionInfo.actAs) - queries.prepareRejectionInsert(completionInfo, offset, recordTime, rejectionReason).execute() + queries.prepareRejectionInsert(completionInfo, offset, recordTime.toInstant, rejectionReason).execute() () } @@ -492,7 +492,7 @@ private class JdbcLedgerDao( override def completeTransaction( completionInfo: Option[state.CompletionInfo], transactionId: Ref.TransactionId, - recordTime: Instant, + recordTime: Timestamp, offsetStep: OffsetStep, )(implicit loggingContext: LoggingContext): Future[PersistenceResponse] = dbDispatcher @@ -540,7 +540,7 @@ private class JdbcLedgerDao( metrics.daml.index.db.storeTransactionDbMetrics.commitValidation, postCommitValidation.validate( transaction = transaction, - transactionLedgerEffectiveTime = ledgerEffectiveTime, + transactionLedgerEffectiveTime = ledgerEffectiveTime.toInstant, divulged = divulged.iterator.map(_.contractId).toSet, ), ) @@ -554,7 +554,7 @@ private class JdbcLedgerDao( Timed.value( metrics.daml.index.db.storeTransactionDbMetrics.insertCompletion, completionInfo - .map(queries.prepareCompletionInsert(_, offsetStep.offset, transactionId, recordTime)) + .map(queries.prepareCompletionInsert(_, offsetStep.offset, transactionId, recordTime.toInstant)) .foreach(_.execute()), ) @@ -573,7 +573,7 @@ private class JdbcLedgerDao( logger.info("Storing rejection") dbDispatcher.executeSql(metrics.daml.index.db.storeRejectionDbMetrics) { implicit conn => for (info <- completionInfo) { - handleError(offsetStep.offset, info, recordTime.toInstant, reason) + handleError(offsetStep.offset, info, recordTime, reason) } ParametersTable.updateLedgerEnd(offsetStep) Ok @@ -615,7 +615,7 @@ private class JdbcLedgerDao( blindingInfo = None, ).write(metrics) completionInfo - .map(queries.prepareCompletionInsert(_, offset, tx.transactionId, tx.recordedAt)) + .map(queries.prepareCompletionInsert(_, offset, tx.transactionId, tx.recordedAt.toInstant)) .foreach(_.execute()) case LedgerEntry.Rejection( recordTime, @@ -630,7 +630,7 @@ private class JdbcLedgerDao( completionInfo = state.CompletionInfo(actAs, applicationId, commandId, None, Some(submissionId)), offset = offset, - recordTime = recordTime, + recordTime = recordTime.toInstant, reason = reason.toParticipantStateRejectionReason, ) .execute() @@ -702,7 +702,7 @@ private class JdbcLedgerDao( _.map(d => Ref.PackageId.assertFromString(d.packageId) -> PackageDetails( d.size, - d.knownSince.toInstant, + Timestamp.assertFromInstant(d.knownSince.toInstant), d.sourceDescription, ) ).toMap @@ -758,7 +758,7 @@ private class JdbcLedgerDao( SQL_INSERT_PACKAGE_ENTRY_ACCEPT .on( "ledger_offset" -> offsetStep.offset, - "recorded_at" -> recordTime, + "recorded_at" -> recordTime.toInstant, "submission_id" -> submissionId, ) .execute() @@ -766,7 +766,7 @@ private class JdbcLedgerDao( SQL_INSERT_PACKAGE_ENTRY_REJECT .on( "ledger_offset" -> offsetStep.offset, - "recorded_at" -> recordTime, + "recorded_at" -> recordTime.toInstant, "submission_id" -> submissionId, "rejection_reason" -> reason, ) @@ -788,7 +788,7 @@ private class JdbcLedgerDao( "upload_id" -> uploadId, "source_description" -> p._2.sourceDescription, "size" -> p._2.size, - "known_since" -> p._2.knownSince, + "known_since" -> p._2.knownSince.toInstant, "package" -> p._1.toByteArray, ) ) @@ -805,10 +805,10 @@ private class JdbcLedgerDao( .map { case (offset, recordTime, Some(submissionId), `acceptType`, None) => offset -> - PackageLedgerEntry.PackageUploadAccepted(submissionId, recordTime.toInstant) + PackageLedgerEntry.PackageUploadAccepted(submissionId, Timestamp.assertFromInstant(recordTime.toInstant)) case (offset, recordTime, Some(submissionId), `rejectType`, Some(reason)) => offset -> - PackageLedgerEntry.PackageUploadRejected(submissionId, recordTime.toInstant, reason) + PackageLedgerEntry.PackageUploadRejected(submissionId, Timestamp.assertFromInstant(recordTime.toInstant), reason) case invalidRow => sys.error(s"packageEntryParser: invalid party entry row: $invalidRow") } @@ -855,8 +855,8 @@ private class JdbcLedgerDao( val updated = SQL(queries.SQL_INSERT_COMMAND) .on( "deduplicationKey" -> key, - "submittedAt" -> submittedAt, - "deduplicateUntil" -> deduplicateUntil, + "submittedAt" -> submittedAt.toInstant, + "deduplicateUntil" -> deduplicateUntil.toInstant, ) .executeUpdate() diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/dao/MeteredLedgerDao.scala b/ledger/participant-integration-api/src/main/scala/platform/store/dao/MeteredLedgerDao.scala index 1aebe8f77a8d..0b2bcf16462f 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/dao/MeteredLedgerDao.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/dao/MeteredLedgerDao.scala @@ -3,7 +3,6 @@ package com.daml.platform.store.dao -import java.time.Instant import akka.NotUsed import akka.stream.scaladsl.Source import com.daml.daml_lf_dev.DamlLf.Archive diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/dao/events/ContractStateEvent.scala b/ledger/participant-integration-api/src/main/scala/platform/store/dao/events/ContractStateEvent.scala index f1e49d9f2132..b7818c36bfac 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/dao/events/ContractStateEvent.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/dao/events/ContractStateEvent.scala @@ -3,7 +3,6 @@ package com.daml.platform.store.dao.events -import java.time.Instant import com.daml.ledger.offset.Offset import com.daml.lf.data.Time.Timestamp diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/dao/events/ContractsReader.scala b/ledger/participant-integration-api/src/main/scala/platform/store/dao/events/ContractsReader.scala index 7a2ae2ba1f01..12956b02e958 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/dao/events/ContractsReader.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/dao/events/ContractsReader.scala @@ -4,22 +4,17 @@ package com.daml.platform.store.dao.events import java.io.InputStream -import java.time.Instant - import anorm.SqlParser._ import anorm.{RowParser, SqlParser, SqlStringInterpolation} import com.codahale.metrics.Timer +import com.daml.lf.data.Time.Timestamp import com.daml.logging.LoggingContext import com.daml.metrics.{Metrics, Timed} import com.daml.platform.store.Conversions._ import com.daml.platform.store.DbType import com.daml.platform.store.interfaces.LedgerDaoContractsReader._ import com.daml.platform.store.dao.DbDispatcher -import com.daml.platform.store.dao.events.SqlFunctions.{ - H2SqlFunctions, - OracleSqlFunctions, - PostgresSqlFunctions, -} +import com.daml.platform.store.dao.events.SqlFunctions.{H2SqlFunctions, OracleSqlFunctions, PostgresSqlFunctions} import com.daml.platform.store.dao.events.ContractsReader._ import com.daml.platform.store.interfaces.LedgerDaoContractsReader import com.daml.platform.store.serialization.{Compression, ValueSerializer} @@ -36,14 +31,15 @@ private[dao] sealed class ContractsReader( override def lookupMaximumLedgerTime(ids: Set[ContractId])(implicit loggingContext: LoggingContext - ): Future[Option[Instant]] = + ): Future[Option[Timestamp]] = Timed.future( metrics.daml.index.db.lookupMaximumLedgerTime, dispatcher .executeSql(metrics.daml.index.db.lookupMaximumLedgerTimeDbMetrics) { implicit connection => committedContracts.lookupMaximumLedgerTime(ids) } - .map(_.get), + .map(_.get) + .map(_.map(Timestamp.assertFromInstant)), ) override def lookupContractKey( diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/entries/LedgerEntry.scala b/ledger/participant-integration-api/src/main/scala/platform/store/entries/LedgerEntry.scala index d097e76ff8ce..41115afb24c6 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/entries/LedgerEntry.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/entries/LedgerEntry.scala @@ -3,7 +3,6 @@ package com.daml.platform.store.entries -import java.time.Instant import com.daml.ledger.api.domain.RejectionReason import com.daml.lf.data.Ref import com.daml.lf.data.Relation.Relation diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/interfaces/LedgerDaoContractsReader.scala b/ledger/participant-integration-api/src/main/scala/platform/store/interfaces/LedgerDaoContractsReader.scala index f7546ae7654c..acd6c5636a70 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/interfaces/LedgerDaoContractsReader.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/interfaces/LedgerDaoContractsReader.scala @@ -3,7 +3,6 @@ package com.daml.platform.store.interfaces -import java.time.Instant import com.daml.lf.data.Ref.Party import com.daml.lf.data.Time.Timestamp import com.daml.lf.transaction.GlobalKey diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/interfaces/TransactionLogUpdate.scala b/ledger/participant-integration-api/src/main/scala/platform/store/interfaces/TransactionLogUpdate.scala index 71970a014c11..9dedde91a352 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/interfaces/TransactionLogUpdate.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/interfaces/TransactionLogUpdate.scala @@ -3,7 +3,6 @@ package com.daml.platform.store.interfaces -import java.time.Instant import com.daml.ledger.offset.Offset import com.daml.lf.value.{Value => LfValue} import com.daml.lf.data.Ref.IdString diff --git a/ledger/participant-integration-api/src/test/lib/scala/platform/store/backend/StorageBackendTestsDeduplication.scala b/ledger/participant-integration-api/src/test/lib/scala/platform/store/backend/StorageBackendTestsDeduplication.scala index af4df11ca655..3346586f54aa 100644 --- a/ledger/participant-integration-api/src/test/lib/scala/platform/store/backend/StorageBackendTestsDeduplication.scala +++ b/ledger/participant-integration-api/src/test/lib/scala/platform/store/backend/StorageBackendTestsDeduplication.scala @@ -3,11 +3,11 @@ package com.daml.platform.store.backend +import com.daml.lf.data.Time.Timestamp import org.scalatest.Inside import org.scalatest.flatspec.AsyncFlatSpec import org.scalatest.matchers.should.Matchers -import java.time.Instant import scala.concurrent.Future private[backend] trait StorageBackendTestsDeduplication @@ -22,8 +22,8 @@ private[backend] trait StorageBackendTestsDeduplication it should "only allow one upsertDeduplicationEntry to insert a new entry" in { val key = "deduplication key" - val submittedAt = Instant.EPOCH - val deduplicateUntil = submittedAt.plusSeconds(1) + val submittedAt = Timestamp.assertFromLong(0L) + val deduplicateUntil = Timestamp.assertFromLong(1000L) val n = 8 for { @@ -44,10 +44,10 @@ private[backend] trait StorageBackendTestsDeduplication it should "only allow one upsertDeduplicationEntry to update an existing expired entry" in { val key = "deduplication key" - val submittedAt = Instant.EPOCH - val deduplicateUntil = submittedAt.plusSeconds(1) - val submittedAt2 = deduplicateUntil.plusSeconds(1) - val deduplicateUntil2 = submittedAt2.plusSeconds(1) + val submittedAt = Timestamp.assertFromLong(0L) + val deduplicateUntil = Timestamp.assertFromLong(1000L) + val submittedAt2 = Timestamp.assertFromLong(2000L) + val deduplicateUntil2 = Timestamp.assertFromLong(3000L) val n = 8 for { @@ -76,10 +76,10 @@ private[backend] trait StorageBackendTestsDeduplication it should "not update or insert anything if there is an existing active entry" in { val key = "deduplication key" - val submittedAt = Instant.EPOCH - val deduplicateUntil = submittedAt.plusSeconds(10) - val submittedAt2 = submittedAt.plusSeconds(1) - val deduplicateUntil2 = submittedAt2.plusSeconds(10) + val submittedAt = Timestamp.assertFromLong(0L) + val deduplicateUntil = Timestamp.assertFromLong(5000L) + val submittedAt2 = Timestamp.assertFromLong(1000L) + val deduplicateUntil2 = Timestamp.assertFromLong(6000L) for { _ <- executeSql(backend.initializeParameters(someIdentityParams)) diff --git a/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoCommandDeduplicationSpec.scala b/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoCommandDeduplicationSpec.scala index a54eac191617..5eabd8c9555e 100644 --- a/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoCommandDeduplicationSpec.scala +++ b/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoCommandDeduplicationSpec.scala @@ -5,12 +5,9 @@ package com.daml.platform.store.dao import java.time.Instant import java.util.UUID - import com.daml.ledger.api.domain.CommandId -import com.daml.ledger.participant.state.index.v2.{ - CommandDeduplicationDuplicate, - CommandDeduplicationNew, -} +import com.daml.ledger.participant.state.index.v2.{CommandDeduplicationDuplicate, CommandDeduplicationNew} +import com.daml.lf.data.Time.Timestamp import org.scalatest.flatspec.AsyncFlatSpec import org.scalatest.matchers.should.Matchers @@ -97,7 +94,7 @@ private[dao] trait JdbcLedgerDaoCommandDeduplicationSpec { } private[this] val t0 = Instant.now() - private[this] def t(ms: Long): Instant = { - t0.plusMillis(ms) + private[this] def t(ms: Long): Timestamp = { + Timestamp.assertFromInstant(t0.plusMillis(ms)) } } diff --git a/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoCompletionsSpec.scala b/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoCompletionsSpec.scala index 25cd6af8bd76..fb7f9f68c5e6 100644 --- a/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoCompletionsSpec.scala +++ b/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoCompletionsSpec.scala @@ -3,13 +3,13 @@ package com.daml.platform.store.dao -import java.time.Instant import java.util.UUID import akka.stream.scaladsl.Sink import com.daml.ledger.api.v1.command_completion_service.CompletionStreamResponse import com.daml.ledger.offset.Offset import com.daml.ledger.participant.state.{v2 => state} import com.daml.lf.data.Ref +import com.daml.lf.data.Time.Timestamp import com.daml.platform.ApiOffset import com.daml.platform.store.dao.JdbcLedgerDaoCompletionsSpec._ import com.google.rpc.status.{Status => RpcStatus} @@ -208,7 +208,7 @@ private[dao] trait JdbcLedgerDaoCompletionsSpec extends OptionValues with LoneEl submissionId = Some(submissionId), ) ), - recordTime = Instant.now, + recordTime = Timestamp.now(), offsetStep = nextOffsetStep(offset), reason = reason, ) @@ -232,7 +232,7 @@ private[dao] trait JdbcLedgerDaoCompletionsSpec extends OptionValues with LoneEl submissionId = Some(submissionId), ) ), - recordTime = Instant.now, + recordTime = Timestamp.now(), offsetStep = nextOffsetStep(offset), reason = reason, ) diff --git a/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoContractsSpec.scala b/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoContractsSpec.scala index 5f721a83443d..03903c5fc421 100644 --- a/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoContractsSpec.scala +++ b/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoContractsSpec.scala @@ -3,9 +3,9 @@ package com.daml.platform.store.dao -import java.time.Instant -import java.util.UUID +import com.daml.lf.data.Time.Timestamp +import java.util.UUID import com.daml.lf.transaction.GlobalKey import com.daml.lf.transaction.Node.KeyWithMaintainers import com.daml.lf.value.Value.{ContractId, ContractInst, ValueText} @@ -178,7 +178,7 @@ private[dao] trait JdbcLedgerDaoContractsSpec extends LoneElement with Inside wi result <- contractsReader.lookupMaximumLedgerTime(nonTransient(tx)) } yield { inside(result) { case Some(time) => - time should be <= Instant.now + time should be <= Timestamp.now() } } } diff --git a/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoDivulgenceSpec.scala b/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoDivulgenceSpec.scala index 056566edf583..ec86fb419de5 100644 --- a/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoDivulgenceSpec.scala +++ b/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoDivulgenceSpec.scala @@ -3,10 +3,9 @@ package com.daml.platform.store.dao -import java.time.Instant import java.util.UUID - import com.daml.lf.data.ImmArray +import com.daml.lf.data.Time.Timestamp import com.daml.lf.transaction.Node.{KeyWithMaintainers, NodeCreate, NodeExercises, NodeFetch} import com.daml.lf.transaction.TransactionVersion import com.daml.lf.transaction.test.TransactionBuilder @@ -144,9 +143,9 @@ private[dao] trait JdbcLedgerDaoDivulgenceSpec extends LoneElement with Inside { ), ) - val t1 = Instant.now() - val t2 = t1.plusMillis(1) - val t3 = t2.plusMillis(1) + val t1 = Timestamp.now() + val t2 = t1.addMicros(1000) + val t3 = t2.addMicros(1000) val appId = UUID.randomUUID().toString for { _ <- store( diff --git a/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoPackagesSpec.scala b/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoPackagesSpec.scala index 15b96a3f0fb7..6cdb6c9d3699 100644 --- a/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoPackagesSpec.scala +++ b/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoPackagesSpec.scala @@ -3,15 +3,14 @@ package com.daml.platform.store.dao -import java.time.Instant import java.util.UUID - import akka.stream.scaladsl.Sink import org.scalatest.flatspec.AsyncFlatSpec import org.scalatest.matchers.should.Matchers import com.daml.daml_lf_dev.DamlLf import com.daml.ledger.offset.Offset import com.daml.ledger.participant.state.index.v2.PackageDetails +import com.daml.lf.data.Time.Timestamp import com.daml.platform.indexer.IncrementalOffsetStep import com.daml.platform.store.dao.ParametersTable.LedgerEndUpdateError import com.daml.platform.store.entries.PackageLedgerEntry @@ -54,7 +53,7 @@ private[dao] trait JdbcLedgerDaoPackagesSpec { val offset2 = nextOffset() val offset3 = nextOffset() val accepted1 = - PackageLedgerEntry.PackageUploadAccepted(UUID.randomUUID().toString, Instant.EPOCH) + PackageLedgerEntry.PackageUploadAccepted(UUID.randomUUID().toString, Timestamp.Epoch) for { uploadAcceptedResult <- storePackageEntry( offset = offset2, @@ -65,7 +64,7 @@ private[dao] trait JdbcLedgerDaoPackagesSpec { ) rejected1 = PackageLedgerEntry.PackageUploadRejected( UUID.randomUUID().toString, - Instant.EPOCH, + Timestamp.Epoch, "some rejection reason", ) uploadRejectedResult <- storePackageEntry( diff --git a/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoPartiesSpec.scala b/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoPartiesSpec.scala index 671063a42739..cad299282eec 100644 --- a/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoPartiesSpec.scala +++ b/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoPartiesSpec.scala @@ -3,13 +3,12 @@ package com.daml.platform.store.dao -import java.time.Instant import java.util.UUID - import akka.stream.scaladsl.Sink import com.daml.ledger.api.domain.PartyDetails import com.daml.ledger.offset.Offset import com.daml.lf.data.Ref +import com.daml.lf.data.Time.Timestamp import com.daml.platform.indexer.{IncrementalOffsetStep, OffsetStep} import com.daml.platform.store.dao.ParametersTable.LedgerEndUpdateError import com.daml.platform.store.entries.PartyLedgerEntry @@ -56,11 +55,11 @@ private[dao] trait JdbcLedgerDaoPartiesSpec { isLocal = true, ) val acceptedSubmissionId = UUID.randomUUID().toString - val acceptedRecordTime = Instant.now() + val acceptedRecordTime = Timestamp.now() val accepted1 = PartyLedgerEntry.AllocationAccepted(Some(acceptedSubmissionId), acceptedRecordTime, accepted) val rejectedSubmissionId = UUID.randomUUID().toString - val rejectedRecordTime = Instant.now() + val rejectedRecordTime = Timestamp.now() val rejected1 = PartyLedgerEntry.AllocationRejected(rejectedSubmissionId, rejectedRecordTime, rejectionReason) val originalOffset = previousOffset.get().get @@ -153,7 +152,7 @@ private[dao] trait JdbcLedgerDaoPartiesSpec { recoverToSucceededIf[LedgerEndUpdateError]( ledgerDao.storePartyEntry( IncrementalOffsetStep(nextOffset(), nextOffset()), - PartyLedgerEntry.AllocationAccepted(Some(UUID.randomUUID().toString), Instant.now(), fred), + PartyLedgerEntry.AllocationAccepted(Some(UUID.randomUUID().toString), Timestamp.now(), fred), ) ) } @@ -332,7 +331,7 @@ private[dao] trait JdbcLedgerDaoPartiesSpec { partyDetails: PartyDetails, offset: Offset, submissionIdOpt: Option[Ref.SubmissionId] = Some(UUID.randomUUID().toString), - recordTime: Instant = Instant.now(), + recordTime: Timestamp = Timestamp.now(), ) = ledgerDao .storePartyEntry( @@ -348,7 +347,7 @@ private[dao] trait JdbcLedgerDaoPartiesSpec { reason: String, offset: Offset, submissionIdOpt: Ref.SubmissionId, - recordTime: Instant, + recordTime: Timestamp, ): Future[PersistenceResponse] = ledgerDao .storePartyEntry( diff --git a/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoSuite.scala b/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoSuite.scala index bb3fd4e5b0d1..ca2dde0b43f7 100644 --- a/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoSuite.scala +++ b/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoSuite.scala @@ -4,10 +4,9 @@ package com.daml.platform.store.dao import java.io.File -import java.time.{Duration, Instant} +import java.time.Duration import java.util.UUID import java.util.concurrent.atomic.{AtomicLong, AtomicReference} - import akka.stream.scaladsl.Sink import com.daml.bazeltools.BazelRunfiles.rlocation import com.daml.daml_lf_dev.DamlLf @@ -18,6 +17,7 @@ import com.daml.ledger.participant.state.{v2 => state} import com.daml.ledger.test.ModelTestDar import com.daml.lf.archive.DarParser import com.daml.lf.data.Ref.{Identifier, Party} +import com.daml.lf.data.Time.Timestamp import com.daml.lf.data.{FrontStack, ImmArray, Ref, Time} import com.daml.lf.transaction.Node._ import com.daml.lf.transaction._ @@ -58,7 +58,7 @@ private[dao] trait JdbcLedgerDaoSuite extends JdbcLedgerDaoBackend { private[this] val dar = DarParser.assertReadArchiveFromFile(new File(rlocation(ModelTestDar.path))) - private val now = Instant.now() + private val now = Timestamp.now() protected final val packages: List[(DamlLf.Archive, v2.PackageDetails)] = dar.all.map(dar => dar -> v2.PackageDetails(dar.getSerializedSize.toLong, now, None)) @@ -284,7 +284,7 @@ private[dao] trait JdbcLedgerDaoSuite extends JdbcLedgerDaoBackend { val eid = txBuilder.add(creation) val offset = nextOffset() val id = offset.toLong - val let = Instant.now + val let = Timestamp.now() offset -> LedgerEntry.Transaction( commandId = Some(s"commandId$id"), transactionId = s"trId$id", @@ -310,7 +310,7 @@ private[dao] trait JdbcLedgerDaoSuite extends JdbcLedgerDaoBackend { ): (Offset, LedgerEntry.Transaction) = { val offset = nextOffset() val id = offset.toLong - val let = Instant.now + val let = Timestamp.now() offset -> LedgerEntry.Transaction( commandId = Some(s"commandId$id"), transactionId = s"trId$id", @@ -410,8 +410,8 @@ private[dao] trait JdbcLedgerDaoSuite extends JdbcLedgerDaoBackend { submissionId = Some(s"submissionId${id.coid}"), actAs = List(divulgees.head), workflowId = None, - ledgerEffectiveTime = Instant.now, - recordedAt = Instant.now, + ledgerEffectiveTime = Timestamp.now(), + recordedAt = Timestamp.now(), transaction = txBuilder.buildCommitted(), explicitDisclosure = Map.empty, ) @@ -425,7 +425,7 @@ private[dao] trait JdbcLedgerDaoSuite extends JdbcLedgerDaoBackend { val nid = txBuilder.add(exerciseNode(targetCid, key)) val offset = nextOffset() val id = offset.toLong - val let = Instant.now + val let = Timestamp.now() offset -> LedgerEntry.Transaction( commandId = Some(s"commandId$id"), transactionId = s"trId$id", @@ -447,7 +447,7 @@ private[dao] trait JdbcLedgerDaoSuite extends JdbcLedgerDaoBackend { val nid = txBuilder.add(exerciseNode(targetCid)) val offset = nextOffset() val id = offset.toLong - val let = Instant.now + val let = Timestamp.now() offset -> LedgerEntry.Transaction( commandId = Some(s"commandId$id"), transactionId = s"trId$id", @@ -469,7 +469,7 @@ private[dao] trait JdbcLedgerDaoSuite extends JdbcLedgerDaoBackend { val nid = txBuilder.add(exerciseNode(targetCid).copy(consuming = false)) val offset = nextOffset() val id = offset.toLong - val let = Instant.now + val let = Timestamp.now() offset -> LedgerEntry.Transaction( commandId = Some(s"commandId$id"), transactionId = s"trId$id", @@ -494,7 +494,7 @@ private[dao] trait JdbcLedgerDaoSuite extends JdbcLedgerDaoBackend { val offset = nextOffset() val id = offset.toLong val txId = s"trId$id" - val let = Instant.now + val let = Timestamp.now() offset -> LedgerEntry.Transaction( commandId = Some(s"commandId$id"), transactionId = txId, @@ -516,7 +516,7 @@ private[dao] trait JdbcLedgerDaoSuite extends JdbcLedgerDaoBackend { val cid = txBuilder.newCid val createId = txBuilder.add(create(cid)) val exerciseId = txBuilder.add(exerciseNode(cid)) - val let = Instant.now + val let = Timestamp.now() nextOffset() -> LedgerEntry.Transaction( commandId = Some(UUID.randomUUID().toString), transactionId = UUID.randomUUID().toString, @@ -544,7 +544,7 @@ private[dao] trait JdbcLedgerDaoSuite extends JdbcLedgerDaoBackend { val rootExerciseId = txBuilder.add(exerciseNode(root).copy(actingParties = Set(charlie))) val createTransientId = txBuilder.add(create(transient), rootExerciseId) val consumeTransientId = txBuilder.add(exerciseNode(transient), rootExerciseId) - val let = Instant.now + val let = Timestamp.now() nextOffset() -> LedgerEntry.Transaction( commandId = Some(UUID.randomUUID.toString), transactionId = UUID.randomUUID().toString, @@ -599,7 +599,7 @@ private[dao] trait JdbcLedgerDaoSuite extends JdbcLedgerDaoBackend { create(txBuilder.newCid), exerciseId, ) - val let = Instant.now + val let = Timestamp.now() nextOffset() -> LedgerEntry.Transaction( commandId = Some(UUID.randomUUID().toString), transactionId = UUID.randomUUID().toString, @@ -646,8 +646,8 @@ private[dao] trait JdbcLedgerDaoSuite extends JdbcLedgerDaoBackend { submissionId = Some(UUID.randomUUID.toString), actAs = List(operator), workflowId = Some("workflowId"), - ledgerEffectiveTime = Instant.now, - recordedAt = Instant.now, + ledgerEffectiveTime = Timestamp.now(), + recordedAt = Timestamp.now(), transaction = txBuilder.buildCommitted(), explicitDisclosure = disclosure.toMap, ) @@ -752,8 +752,8 @@ private[dao] trait JdbcLedgerDaoSuite extends JdbcLedgerDaoBackend { submissionId = Some(UUID.randomUUID().toString), actAs = List(party), workflowId = Some(defaultWorkflowId), - ledgerEffectiveTime = Instant.now, - recordedAt = Instant.now, + ledgerEffectiveTime = Timestamp.now(), + recordedAt = Timestamp.now(), transaction = txBuilder.buildCommitted(), explicitDisclosure = Map(createNodeId -> Set(party)), ) @@ -791,8 +791,8 @@ private[dao] trait JdbcLedgerDaoSuite extends JdbcLedgerDaoBackend { submissionId = Some(UUID.randomUUID().toString), actAs = List(party), workflowId = Some(defaultWorkflowId), - ledgerEffectiveTime = Instant.now, - recordedAt = Instant.now, + ledgerEffectiveTime = Timestamp.now(), + recordedAt = Timestamp.now(), transaction = txBuilder.buildCommitted(), explicitDisclosure = Map(archiveNodeId -> Set(party)), ) @@ -820,8 +820,8 @@ private[dao] trait JdbcLedgerDaoSuite extends JdbcLedgerDaoBackend { submissionId = Some(UUID.randomUUID().toString), actAs = List(party), workflowId = Some(defaultWorkflowId), - ledgerEffectiveTime = Instant.now(), - recordedAt = Instant.now(), + ledgerEffectiveTime = Timestamp.now(), + recordedAt = Timestamp.now(), transaction = txBuilder.buildCommitted(), explicitDisclosure = Map(lookupByKeyNodeId -> Set(party)), ) @@ -851,8 +851,8 @@ private[dao] trait JdbcLedgerDaoSuite extends JdbcLedgerDaoBackend { submissionId = Some(UUID.randomUUID().toString), actAs = List(party), workflowId = Some(defaultWorkflowId), - ledgerEffectiveTime = Instant.now(), - recordedAt = Instant.now(), + ledgerEffectiveTime = Timestamp.now(), + recordedAt = Timestamp.now(), transaction = txBuilder.buildCommitted(), explicitDisclosure = Map(fetchNodeId -> Set(party)), ) @@ -866,8 +866,8 @@ private[dao] trait JdbcLedgerDaoSuite extends JdbcLedgerDaoBackend { submissionId = Some(UUID.randomUUID().toString), actAs = List(party), workflowId = Some(defaultWorkflowId), - ledgerEffectiveTime = Instant.now(), - recordedAt = Instant.now(), + ledgerEffectiveTime = Timestamp.now(), + recordedAt = Timestamp.now(), transaction = TransactionBuilder.EmptyCommitted, explicitDisclosure = Map.empty, ) @@ -901,7 +901,7 @@ private[dao] trait JdbcLedgerDaoSuite extends JdbcLedgerDaoBackend { .orElse(previousOffset.get()) .map(IncrementalOffsetStep(_, offset)) .getOrElse(CurrentOffset(offset)), - Instant.EPOCH, + Timestamp.Epoch, submissionId, lastConfig, rejectionReason, diff --git a/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoTransactionTreesSpec.scala b/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoTransactionTreesSpec.scala index f95efbd0ed09..0a92093db712 100644 --- a/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoTransactionTreesSpec.scala +++ b/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoTransactionTreesSpec.scala @@ -5,6 +5,7 @@ package com.daml.platform.store.dao import akka.NotUsed import akka.stream.scaladsl.{Sink, Source} +import com.daml.api.util.TimestampConversion import com.daml.ledger.api.v1.transaction.TransactionTree import com.daml.ledger.api.v1.transaction_service.GetTransactionTreesResponse import com.daml.ledger.offset.Offset @@ -61,8 +62,7 @@ private[dao] trait JdbcLedgerDaoTransactionTreesSpec tx.transaction.nodes.head transaction.commandId shouldBe tx.commandId.get transaction.offset shouldBe ApiOffset.toApiString(offset) - transaction.effectiveAt.value.seconds shouldBe tx.ledgerEffectiveTime.getEpochSecond - transaction.effectiveAt.value.nanos shouldBe tx.ledgerEffectiveTime.getNano + TimestampConversion.toLf(transaction.effectiveAt.value, TimestampConversion.ConversionMode.Exact) shouldBe tx.ledgerEffectiveTime transaction.transactionId shouldBe tx.transactionId transaction.workflowId shouldBe tx.workflowId.getOrElse("") val created = transaction.eventsById.values.loneElement.getCreated @@ -93,8 +93,7 @@ private[dao] trait JdbcLedgerDaoTransactionTreesSpec exercise.transaction.nodes.head transaction.commandId shouldBe exercise.commandId.get transaction.offset shouldBe ApiOffset.toApiString(offset) - transaction.effectiveAt.value.seconds shouldBe exercise.ledgerEffectiveTime.getEpochSecond - transaction.effectiveAt.value.nanos shouldBe exercise.ledgerEffectiveTime.getNano + TimestampConversion.toLf(transaction.effectiveAt.value, TimestampConversion.ConversionMode.Exact) shouldBe exercise.ledgerEffectiveTime transaction.transactionId shouldBe exercise.transactionId transaction.workflowId shouldBe exercise.workflowId.getOrElse("") val exercised = transaction.eventsById.values.loneElement.getExercised @@ -133,8 +132,7 @@ private[dao] trait JdbcLedgerDaoTransactionTreesSpec transaction.offset shouldBe ApiOffset.toApiString(offset) transaction.transactionId shouldBe tx.transactionId transaction.workflowId shouldBe tx.workflowId.getOrElse("") - transaction.effectiveAt.value.seconds shouldBe tx.ledgerEffectiveTime.getEpochSecond - transaction.effectiveAt.value.nanos shouldBe tx.ledgerEffectiveTime.getNano + TimestampConversion.toLf(transaction.effectiveAt.value, TimestampConversion.ConversionMode.Exact) shouldBe tx.ledgerEffectiveTime transaction.rootEventIds should have size 2 transaction.rootEventIds(0) shouldBe EventId( diff --git a/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoTransactionsSpec.scala b/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoTransactionsSpec.scala index 1420346d2d6f..02fcd68756be 100644 --- a/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoTransactionsSpec.scala +++ b/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcLedgerDaoTransactionsSpec.scala @@ -5,6 +5,7 @@ package com.daml.platform.store.dao import akka.NotUsed import akka.stream.scaladsl.{Sink, Source} +import com.daml.api.util.TimestampConversion import com.daml.ledger.api.v1.transaction.Transaction import com.daml.ledger.api.v1.transaction_service.GetTransactionsResponse import com.daml.ledger.api.{v1 => lav1} @@ -61,8 +62,7 @@ private[dao] trait JdbcLedgerDaoTransactionsSpec extends OptionValues with Insid inside(result.value.transaction) { case Some(transaction) => transaction.commandId shouldBe tx.commandId.get transaction.offset shouldBe ApiOffset.toApiString(offset) - transaction.effectiveAt.value.seconds shouldBe tx.ledgerEffectiveTime.getEpochSecond - transaction.effectiveAt.value.nanos shouldBe tx.ledgerEffectiveTime.getNano + TimestampConversion.toLf(transaction.effectiveAt.value, TimestampConversion.ConversionMode.Exact) shouldBe tx.ledgerEffectiveTime transaction.transactionId shouldBe tx.transactionId transaction.workflowId shouldBe tx.workflowId.getOrElse("") inside(transaction.events.loneElement.event.created) { case Some(created) => @@ -94,8 +94,7 @@ private[dao] trait JdbcLedgerDaoTransactionsSpec extends OptionValues with Insid transaction.commandId shouldBe exercise.commandId.get transaction.offset shouldBe ApiOffset.toApiString(offset) transaction.transactionId shouldBe exercise.transactionId - transaction.effectiveAt.value.seconds shouldBe exercise.ledgerEffectiveTime.getEpochSecond - transaction.effectiveAt.value.nanos shouldBe exercise.ledgerEffectiveTime.getNano + TimestampConversion.toLf(transaction.effectiveAt.value, TimestampConversion.ConversionMode.Exact) shouldBe exercise.ledgerEffectiveTime transaction.workflowId shouldBe exercise.workflowId.getOrElse("") inside(transaction.events.loneElement.event.archived) { case Some(archived) => val (nodeId, exerciseNode: NodeExercises) = @@ -154,8 +153,7 @@ private[dao] trait JdbcLedgerDaoTransactionsSpec extends OptionValues with Insid transaction.commandId shouldBe tx.commandId.get transaction.offset shouldBe ApiOffset.toApiString(offset) transaction.transactionId shouldBe tx.transactionId - transaction.effectiveAt.value.seconds shouldBe tx.ledgerEffectiveTime.getEpochSecond - transaction.effectiveAt.value.nanos shouldBe tx.ledgerEffectiveTime.getNano + TimestampConversion.toLf(transaction.effectiveAt.value, TimestampConversion.ConversionMode.Exact) shouldBe tx.ledgerEffectiveTime transaction.workflowId shouldBe tx.workflowId.getOrElse("") transaction.events shouldBe Seq.empty } diff --git a/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcPipelinedInsertionsSpec.scala b/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcPipelinedInsertionsSpec.scala index 62a1e07fed5c..1aec230f2b32 100644 --- a/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcPipelinedInsertionsSpec.scala +++ b/ledger/participant-integration-api/src/test/lib/scala/platform/store/dao/JdbcPipelinedInsertionsSpec.scala @@ -3,6 +3,7 @@ package com.daml.platform.store.dao +import com.daml.api.util.TimestampConversion import com.daml.ledger.offset.Offset import com.daml.lf.ledger.EventId import com.daml.lf.transaction.Node.NodeCreate @@ -38,8 +39,7 @@ trait JdbcPipelinedInsertionsSpec extends Inside with OptionValues with Matchers inside(result.value.transaction) { case Some(transaction) => transaction.commandId shouldBe tx.commandId.get transaction.offset shouldBe ApiOffset.toApiString(offset) - transaction.effectiveAt.value.seconds shouldBe tx.ledgerEffectiveTime.getEpochSecond - transaction.effectiveAt.value.nanos shouldBe tx.ledgerEffectiveTime.getNano + TimestampConversion.toLf(transaction.effectiveAt.value, TimestampConversion.ConversionMode.Exact) shouldBe tx.ledgerEffectiveTime transaction.transactionId shouldBe tx.transactionId transaction.workflowId shouldBe tx.workflowId.getOrElse("") inside(transaction.events.loneElement.event.created) { case Some(created) => diff --git a/ledger/participant-integration-api/src/test/suite/scala/db/migration/translation/apiserver/services/admin/ApiPackageManagementServiceSpec.scala b/ledger/participant-integration-api/src/test/suite/scala/db/migration/translation/apiserver/services/admin/ApiPackageManagementServiceSpec.scala index b8ec9bc1eaa2..0167431e3d89 100644 --- a/ledger/participant-integration-api/src/test/suite/scala/db/migration/translation/apiserver/services/admin/ApiPackageManagementServiceSpec.scala +++ b/ledger/participant-integration-api/src/test/suite/scala/db/migration/translation/apiserver/services/admin/ApiPackageManagementServiceSpec.scala @@ -3,26 +3,23 @@ package com.daml.platform.apiserver.services.admin -import java.time.{Duration, Instant} +import java.time.Duration import java.util.concurrent.{CompletableFuture, CompletionStage} import java.util.zip.ZipInputStream - import akka.stream.scaladsl.Source import com.daml.daml_lf_dev.DamlLf import com.daml.daml_lf_dev.DamlLf.Archive import com.daml.ledger.api.domain.LedgerOffset.Absolute import com.daml.ledger.api.domain.PackageEntry import com.daml.ledger.api.testing.utils.AkkaBeforeAndAfterAll -import com.daml.ledger.api.v1.admin.package_management_service.{ - PackageManagementServiceGrpc, - UploadDarFileRequest, -} +import com.daml.ledger.api.v1.admin.package_management_service.{PackageManagementServiceGrpc, UploadDarFileRequest} import com.daml.ledger.participant.state.index.v2.{IndexPackagesService, IndexTransactionsService} import com.daml.ledger.participant.state.{v2 => state} import com.daml.lf.archive.testing.Encode import com.daml.lf.archive.{Dar, GenDarReader} import com.daml.lf.data.Ref import com.daml.lf.data.Ref.PackageId +import com.daml.lf.data.Time.Timestamp import com.daml.lf.engine.Engine import com.daml.lf.language.Ast.Expr import com.daml.lf.language.{Ast, LanguageVersion} @@ -85,7 +82,7 @@ class ApiPackageManagementServiceSpec when(mockIndexPackagesService.packageEntries(any[Option[Absolute]])(any[LoggingContext])) .thenReturn( Source.single( - PackageEntry.PackageUploadAccepted(aSubmissionId, Instant.EPOCH) + PackageEntry.PackageUploadAccepted(aSubmissionId, Timestamp.Epoch) ) ) diff --git a/ledger/participant-integration-api/src/test/suite/scala/platform/apiserver/execution/StoreBackedCommandExecutorSpec.scala b/ledger/participant-integration-api/src/test/suite/scala/platform/apiserver/execution/StoreBackedCommandExecutorSpec.scala index aa3dcfb4a15c..2e9356cc69f2 100644 --- a/ledger/participant-integration-api/src/test/suite/scala/platform/apiserver/execution/StoreBackedCommandExecutorSpec.scala +++ b/ledger/participant-integration-api/src/test/suite/scala/platform/apiserver/execution/StoreBackedCommandExecutorSpec.scala @@ -3,8 +3,7 @@ package com.daml.platform.apiserver.execution -import java.time.{Duration, Instant} - +import java.time.Duration import com.codahale.metrics.MetricRegistry import com.daml.ledger.api.DeduplicationPeriod import com.daml.ledger.api.domain.{ApplicationId, CommandId, Commands, LedgerId, SubmissionId} @@ -63,7 +62,7 @@ class StoreBackedCommandExecutorSpec submissionId = SubmissionId(Ref.SubmissionId.assertFromString("submissionId")), actAs = Set.empty, readAs = Set.empty, - submittedAt = Instant.EPOCH, + submittedAt = Time.Timestamp.Epoch, deduplicationPeriod = DeduplicationPeriod.DeduplicationDuration(Duration.ZERO), commands = LfCommands( commands = ImmArray.Empty, diff --git a/ledger/participant-integration-api/src/test/suite/scala/platform/apiserver/services/ApiSubmissionServiceSpec.scala b/ledger/participant-integration-api/src/test/suite/scala/platform/apiserver/services/ApiSubmissionServiceSpec.scala index 0486d11720af..a705fd5d5b60 100644 --- a/ledger/participant-integration-api/src/test/suite/scala/platform/apiserver/services/ApiSubmissionServiceSpec.scala +++ b/ledger/participant-integration-api/src/test/suite/scala/platform/apiserver/services/ApiSubmissionServiceSpec.scala @@ -3,7 +3,7 @@ package com.daml.platform.apiserver.services -import java.time.{Duration, Instant} +import java.time.Duration import java.util.UUID import java.util.concurrent.CompletableFuture.completedFuture import java.util.concurrent.atomic.AtomicInteger @@ -349,8 +349,8 @@ class ApiSubmissionServiceSpec verify(indexSubmissionService).deduplicateCommand( any[CommandId], any[List[Ref.Party]], - any[Instant], - any[Instant], + any[Timestamp], + any[Timestamp], )(any[LoggingContext]) Success(succeed) }) @@ -391,8 +391,8 @@ class ApiSubmissionServiceSpec verify(indexSubmissionService, never).deduplicateCommand( any[CommandId], any[List[Ref.Party]], - any[Instant], - any[Instant], + any[Timestamp], + any[Timestamp], )(any[LoggingContext]) Success(succeed) }) @@ -418,7 +418,7 @@ object ApiSubmissionServiceSpec { submissionId = SubmissionId(Ref.SubmissionId.assertFromString(UUID.randomUUID().toString)), actAs = Set.empty, readAs = Set.empty, - submittedAt = Instant.MIN, + submittedAt = Timestamp.Epoch, deduplicationPeriod = DeduplicationPeriod.DeduplicationDuration(Duration.ZERO), commands = LfCommands(ImmArray.Empty, Timestamp.MinValue, ""), ) @@ -446,8 +446,8 @@ object ApiSubmissionServiceSpec { mockIndexSubmissionService.deduplicateCommand( any[CommandId], anyList[Ref.Party], - any[Instant], - any[Instant], + any[Timestamp], + any[Timestamp], )(any[LoggingContext]) ).thenReturn(Future.successful(CommandDeduplicationNew)) when( diff --git a/ledger/participant-integration-api/src/test/suite/scala/platform/index/BuffersUpdaterSpec.scala b/ledger/participant-integration-api/src/test/suite/scala/platform/index/BuffersUpdaterSpec.scala index 17b3ee0f2915..1c3cfe591cda 100644 --- a/ledger/participant-integration-api/src/test/suite/scala/platform/index/BuffersUpdaterSpec.scala +++ b/ledger/participant-integration-api/src/test/suite/scala/platform/index/BuffersUpdaterSpec.scala @@ -3,9 +3,7 @@ package com.daml.platform.index -import java.time.Instant import java.util.concurrent.atomic.{AtomicInteger, AtomicLong} - import akka.NotUsed import akka.actor.ActorSystem import akka.stream.scaladsl.Source @@ -13,6 +11,7 @@ import akka.stream.{Materializer, QueueOfferResult} import ch.qos.logback.classic.Level import com.daml.ledger.offset.Offset import com.daml.lf.data.Ref +import com.daml.lf.data.Time.Timestamp import com.daml.lf.transaction.TransactionVersion import com.daml.lf.value.Value.{ContractId, ValueInt64, ValueText, VersionedValue} import com.daml.logging.LoggingContext @@ -202,7 +201,7 @@ final class BuffersUpdaterSpec val createdCid = ContractId.assertFromString("#createdCid") val createdOffset = Offset.fromByteArray(BigInt(1337L).toByteArray) val createdEventSeqId = 9876L - val createdLedgerEffectiveTime = Instant.ofEpochMilli(987654321L) + val createdLedgerEffectiveTime = Timestamp.assertFromLong(987654321L) val createdTemplateId = Ref.Identifier.assertFromString("create:template:id") val createdContractKey = VersionedValue(TransactionVersion.VDev, ValueInt64(1337L)) @@ -262,7 +261,7 @@ final class BuffersUpdaterSpec val transaction = TransactionLogUpdate.Transaction( transactionId = "some-tx-id", workflowId = "some-workflow-id", - effectiveAt = Instant.EPOCH, + effectiveAt = Timestamp.Epoch, offset = Offset.beforeBegin, events = Vector( createdEvent, diff --git a/ledger/participant-integration-api/src/test/suite/scala/platform/index/TransactionConversionSpec.scala b/ledger/participant-integration-api/src/test/suite/scala/platform/index/TransactionConversionSpec.scala index d58b62901c92..2c16ce8d43be 100644 --- a/ledger/participant-integration-api/src/test/suite/scala/platform/index/TransactionConversionSpec.scala +++ b/ledger/participant-integration-api/src/test/suite/scala/platform/index/TransactionConversionSpec.scala @@ -3,13 +3,12 @@ package com.daml.platform.index -import java.time.Instant - import com.daml.ledger.api.domain.LedgerOffset import com.daml.ledger.api.v1.event.{ArchivedEvent, CreatedEvent, Event, ExercisedEvent} import com.daml.ledger.api.v1.transaction.TreeEvent import com.daml.ledger.api.v1.{value => v} import com.daml.lf.data.Ref.LedgerString +import com.daml.lf.data.Time.Timestamp import com.daml.lf.data.{ImmArray, Ref} import com.daml.lf.transaction.CommittedTransaction import com.daml.lf.transaction.test.TransactionBuilder @@ -123,8 +122,8 @@ final class TransactionConversionSpec extends AnyWordSpec with Matchers { submissionId = Some(Ref.SubmissionId.assertFromString("submissionId")), actAs = List(party), workflowId = None, - ledgerEffectiveTime = Instant.EPOCH, - recordedAt = Instant.EPOCH, + ledgerEffectiveTime = Timestamp.Epoch, + recordedAt = Timestamp.Epoch, transaction = transaction, explicitDisclosure = Map.empty, ) diff --git a/ledger/participant-integration-api/src/test/suite/scala/platform/indexer/ExecuteUpdateSpec.scala b/ledger/participant-integration-api/src/test/suite/scala/platform/indexer/ExecuteUpdateSpec.scala index 09e3ed138216..5052b45e8b90 100644 --- a/ledger/participant-integration-api/src/test/suite/scala/platform/indexer/ExecuteUpdateSpec.scala +++ b/ledger/participant-integration-api/src/test/suite/scala/platform/indexer/ExecuteUpdateSpec.scala @@ -3,14 +3,13 @@ package com.daml.platform.indexer -import java.time.Instant - import akka.stream.scaladsl.{Flow, Source} import com.codahale.metrics.MetricRegistry import com.daml.ledger.api.testing.utils.AkkaBeforeAndAfterAll import com.daml.ledger.offset.Offset import com.daml.ledger.participant.state.{v2 => state} import com.daml.ledger.resources.TestResourceContext +import com.daml.lf.data.Time.Timestamp import com.daml.lf.data.{Bytes, ImmArray, Ref, Time} import com.daml.lf.transaction.{TransactionVersion, VersionedTransaction} import com.daml.lf.{crypto, transaction} @@ -50,7 +49,7 @@ final class ExecuteUpdateSpec private val someMetrics = new Metrics(new MetricRegistry) private val someParticipantId = Ref.ParticipantId.assertFromString("some-participant") private val prepareUpdateParallelism = 2 - private val ledgerEffectiveTime = Instant.EPOCH + private val ledgerEffectiveTime = Timestamp.Epoch private val packageUploadRejectionReason = "some rejection reason" private val submissionId = Ref.SubmissionId.assertFromString("s1") @@ -82,7 +81,7 @@ final class ExecuteUpdateSpec private val transactionAcceptedOffsetPair = OffsetUpdate(currentOffset, txAccepted) private val packageUploadRejected = state.Update.PublicPackageUploadRejected( submissionId = submissionId, - recordTime = Time.Timestamp(ledgerEffectiveTime.toEpochMilli), + recordTime = ledgerEffectiveTime, rejectionReason = packageUploadRejectionReason, ) private val metadataUpdateOffsetPair = OffsetUpdate(currentOffset, packageUploadRejected) diff --git a/ledger/participant-integration-api/src/test/suite/scala/platform/store/CompletionFromTransactionSpec.scala b/ledger/participant-integration-api/src/test/suite/scala/platform/store/CompletionFromTransactionSpec.scala index fcccadf5dba4..d62196a81e18 100644 --- a/ledger/participant-integration-api/src/test/suite/scala/platform/store/CompletionFromTransactionSpec.scala +++ b/ledger/participant-integration-api/src/test/suite/scala/platform/store/CompletionFromTransactionSpec.scala @@ -5,6 +5,7 @@ package com.daml.platform.store import com.daml.ledger.api.v1.completion.Completion.DeduplicationPeriod import com.daml.ledger.offset.Offset +import com.daml.lf.data.Time import com.google.protobuf.duration.Duration import com.google.protobuf.timestamp.Timestamp import com.google.rpc.status.Status @@ -57,7 +58,7 @@ class CompletionFromTransactionSpec expectedDeduplicationPeriod, ) => val completionStream = CompletionFromTransaction.acceptedCompletion( - Instant.EPOCH, + Time.Timestamp.Epoch, Offset.beforeBegin, "commandId", "transactionId", @@ -91,7 +92,7 @@ class CompletionFromTransactionSpec forEvery(testCases) { (deduplicationDurationSeconds, deduplicationDurationNanos) => an[IllegalArgumentException] shouldBe thrownBy( CompletionFromTransaction.acceptedCompletion( - Instant.EPOCH, + Time.Timestamp.Epoch, Offset.beforeBegin, "commandId", "transactionId", @@ -108,7 +109,7 @@ class CompletionFromTransactionSpec "create a rejected completion" in { val status = Status.of(io.grpc.Status.Code.INTERNAL.value(), "message", Seq.empty) val completionStream = CompletionFromTransaction.rejectedCompletion( - Instant.EPOCH, + Time.Timestamp.Epoch, Offset.beforeBegin, "commandId", status, diff --git a/ledger/participant-integration-api/src/test/suite/scala/platform/store/appendonlydao/SequentialWriteDaoSpec.scala b/ledger/participant-integration-api/src/test/suite/scala/platform/store/appendonlydao/SequentialWriteDaoSpec.scala index 14163237b55c..b4e14d335752 100644 --- a/ledger/participant-integration-api/src/test/suite/scala/platform/store/appendonlydao/SequentialWriteDaoSpec.scala +++ b/ledger/participant-integration-api/src/test/suite/scala/platform/store/appendonlydao/SequentialWriteDaoSpec.scala @@ -4,7 +4,6 @@ package com.daml.platform.store.appendonlydao import java.sql.Connection -import java.time.Instant import com.daml.ledger.offset.Offset import com.daml.ledger.participant.state.{v2 => state} @@ -140,7 +139,7 @@ object SequentialWriteDaoSpec { private def someUpdate(key: String) = Some( state.Update.PublicPackageUploadRejected( submissionId = Ref.SubmissionId.assertFromString("abc"), - recordTime = Timestamp.assertFromInstant(Instant.now), + recordTime = Timestamp.now(), rejectionReason = key, ) ) diff --git a/ledger/participant-integration-api/src/test/suite/scala/platform/store/appendonlydao/events/BufferedTransactionsReaderSpec.scala b/ledger/participant-integration-api/src/test/suite/scala/platform/store/appendonlydao/events/BufferedTransactionsReaderSpec.scala index 75ad185ac19a..8bd90fcc0e53 100644 --- a/ledger/participant-integration-api/src/test/suite/scala/platform/store/appendonlydao/events/BufferedTransactionsReaderSpec.scala +++ b/ledger/participant-integration-api/src/test/suite/scala/platform/store/appendonlydao/events/BufferedTransactionsReaderSpec.scala @@ -3,19 +3,15 @@ package com.daml.platform.store.appendonlydao.events -import java.time.Instant - import akka.actor.ActorSystem import akka.stream.Materializer import akka.stream.scaladsl.{Sink, Source} import com.codahale.metrics.MetricRegistry import com.daml.ledger.offset.Offset +import com.daml.lf.data.Time.Timestamp import com.daml.metrics.Metrics import com.daml.platform.store.appendonlydao.events.BufferedTransactionsReader.FetchTransactions -import com.daml.platform.store.appendonlydao.events.BufferedTransactionsReaderSpec.{ - predecessor, - transactionLogUpdate, -} +import com.daml.platform.store.appendonlydao.events.BufferedTransactionsReaderSpec.{predecessor, transactionLogUpdate} import com.daml.platform.store.cache.EventsBuffer import com.daml.platform.store.interfaces.TransactionLogUpdate import org.mockito.MockitoSugar @@ -198,7 +194,7 @@ object BufferedTransactionsReaderSpec { TransactionLogUpdate.Transaction( transactionId = discriminator, workflowId = "", - effectiveAt = Instant.EPOCH, + effectiveAt = Timestamp.Epoch, offset = Offset.beforeBegin, events = Vector(null), ) diff --git a/ledger/participant-integration-api/src/test/suite/scala/platform/store/cache/MutableCacheBackedContractStoreSpec.scala b/ledger/participant-integration-api/src/test/suite/scala/platform/store/cache/MutableCacheBackedContractStoreSpec.scala index 5bc4eb19d66c..6eb1af017817 100644 --- a/ledger/participant-integration-api/src/test/suite/scala/platform/store/cache/MutableCacheBackedContractStoreSpec.scala +++ b/ledger/participant-integration-api/src/test/suite/scala/platform/store/cache/MutableCacheBackedContractStoreSpec.scala @@ -3,7 +3,6 @@ package com.daml.platform.store.cache -import java.time.Instant import java.util.concurrent.atomic.AtomicReference import akka.NotUsed import akka.actor.ActorSystem @@ -14,6 +13,7 @@ import com.codahale.metrics.MetricRegistry import com.daml.ledger.offset.Offset import com.daml.ledger.resources.ResourceContext import com.daml.lf.data.ImmArray +import com.daml.lf.data.Time.Timestamp import com.daml.lf.transaction.GlobalKey import com.daml.lf.transaction.test.TransactionBuilder import com.daml.lf.value.Value.{ContractInst, ValueRecord, ValueText} @@ -22,24 +22,11 @@ import com.daml.metrics.Metrics import com.daml.platform.store.EventSequentialId import com.daml.platform.store.cache.ContractKeyStateValue.{Assigned, Unassigned} import com.daml.platform.store.cache.ContractStateValue.{Active, Archived} -import com.daml.platform.store.cache.MutableCacheBackedContractStore.{ - ContractNotFound, - EmptyContractIds, - EventSequentialId, - SubscribeToContractStateEvents, -} -import com.daml.platform.store.cache.MutableCacheBackedContractStoreSpec.{ - ContractsReaderFixture, - contractStore, - _, -} +import com.daml.platform.store.cache.MutableCacheBackedContractStore.{ContractNotFound, EmptyContractIds, EventSequentialId, SubscribeToContractStateEvents} +import com.daml.platform.store.cache.MutableCacheBackedContractStoreSpec.{ContractsReaderFixture, contractStore, _} import com.daml.platform.store.dao.events.ContractStateEvent import com.daml.platform.store.interfaces.LedgerDaoContractsReader -import com.daml.platform.store.interfaces.LedgerDaoContractsReader.{ - ContractState, - KeyAssigned, - KeyUnassigned, -} +import com.daml.platform.store.interfaces.LedgerDaoContractsReader.{ContractState, KeyAssigned, KeyUnassigned} import org.mockito.MockitoSugar import org.scalatest.concurrent.Eventually import org.scalatest.matchers.should.Matchers @@ -376,7 +363,7 @@ class MutableCacheBackedContractStoreSpec maybeKey: Option[GlobalKey], stakeholders: Set[Party], eventSequentialId: EventSequentialId, - createLedgerEffectiveTime: Instant, + createLedgerEffectiveTime: Timestamp, )(implicit queue: BoundedSourceQueue[ContractStateEvent]): Future[ContractStateEvent.Created] = { val created = ContractStateEvent.Created( contractId = contractId, @@ -431,7 +418,7 @@ object MutableCacheBackedContractStoreSpec { Seq(t1, t2, t3, t4, _, t6, _), ) = (1 to 7).map { id => - (contractId(id), contract(s"id$id"), Instant.ofEpochSecond(id.toLong)) + (contractId(id), contract(s"id$id"), Timestamp.assertFromLong(id.toLong * 1000L)) }.unzip3 private val someKey = globalKey("key1") @@ -489,7 +476,7 @@ object MutableCacheBackedContractStoreSpec { override def lookupMaximumLedgerTime(ids: Set[ContractId])(implicit loggingContext: LoggingContext - ): Future[Option[Instant]] = ids match { + ): Future[Option[Timestamp]] = ids match { case setIds if setIds == Set(cId_4) => Future.successful(Some(t4)) case set if set.isEmpty => @@ -535,7 +522,7 @@ object MutableCacheBackedContractStoreSpec { private def activeContract( contract: Contract, parties: Set[Party], - ledgerEffectiveTime: Instant, + ledgerEffectiveTime: Timestamp, ) = Future.successful( Some(LedgerDaoContractsReader.ActiveContract(contract, parties, ledgerEffectiveTime)) diff --git a/ledger/sandbox-classic/src/main/scala/platform/sandbox/SandboxServer.scala b/ledger/sandbox-classic/src/main/scala/platform/sandbox/SandboxServer.scala index 4f9ec82b3340..c1db29df3d13 100644 --- a/ledger/sandbox-classic/src/main/scala/platform/sandbox/SandboxServer.scala +++ b/ledger/sandbox-classic/src/main/scala/platform/sandbox/SandboxServer.scala @@ -7,7 +7,6 @@ import java.io.File import java.nio.file.Files import java.time.Instant import java.util.concurrent.Executors - import akka.actor.ActorSystem import akka.stream.Materializer import com.codahale.metrics.MetricRegistry @@ -21,13 +20,10 @@ import com.daml.ledger.api.health.HealthChecks import com.daml.ledger.participant.state.v2.metrics.TimedWriteService import com.daml.ledger.resources.{Resource, ResourceContext, ResourceOwner} import com.daml.lf.data.ImmArray +import com.daml.lf.data.Time.Timestamp import com.daml.lf.engine.{Engine, EngineConfig} import com.daml.lf.language.LanguageVersion -import com.daml.lf.transaction.{ - LegacyTransactionCommitter, - StandardTransactionCommitter, - TransactionCommitter, -} +import com.daml.lf.transaction.{LegacyTransactionCommitter, StandardTransactionCommitter, TransactionCommitter} import com.daml.logging.LoggingContext.newLoggingContextWith import com.daml.logging.{ContextualizedLogger, LoggingContext} import com.daml.metrics.{Metrics, MetricsReporting} @@ -467,7 +463,7 @@ final class SandboxServer( config.damlPackages .foldLeft[Either[(String, File), InMemoryPackageStore]](Right(InMemoryPackageStore.empty)) { case (storeE, f) => - storeE.flatMap(_.withDarFile(Instant.EPOCH, None, f).left.map(_ -> f)) + storeE.flatMap(_.withDarFile(Timestamp.Epoch, None, f).left.map(_ -> f)) } .fold({ case (err, file) => sys.error(s"Could not load package $file: $err") }, identity) diff --git a/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/LedgerBackedWriteService.scala b/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/LedgerBackedWriteService.scala index 9d2edc60ee15..45d078c236a1 100644 --- a/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/LedgerBackedWriteService.scala +++ b/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/LedgerBackedWriteService.scala @@ -77,7 +77,7 @@ private[stores] final class LedgerBackedWriteService( "packageHashes" -> payload.view.map(_.getHash), ) { implicit loggingContext => FutureConverters.toJava( - ledger.uploadPackages(submissionId, timeProvider.getCurrentTime, sourceDescription, payload) + ledger.uploadPackages(submissionId, timeProvider.getCurrentTimestamp, sourceDescription, payload) ) } diff --git a/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/SandboxIndexAndWriteService.scala b/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/SandboxIndexAndWriteService.scala index 4b8cc9779af3..8d875789be7b 100644 --- a/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/SandboxIndexAndWriteService.scala +++ b/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/SandboxIndexAndWriteService.scala @@ -4,7 +4,6 @@ package com.daml.platform.sandbox.stores import java.time.Instant - import akka.stream.Materializer import akka.stream.scaladsl.{Sink, Source} import com.daml.api.util.TimeProvider @@ -12,6 +11,7 @@ import com.daml.ledger.api.domain import com.daml.ledger.participant.state.index.v2.IndexService import com.daml.ledger.participant.state.{v2 => state} import com.daml.ledger.resources.{Resource, ResourceContext, ResourceOwner} +import com.daml.lf.data.Time.Timestamp import com.daml.lf.data.{ImmArray, Ref} import com.daml.lf.engine.Engine import com.daml.lf.transaction.TransactionCommitter @@ -151,7 +151,7 @@ private[sandbox] object SandboxIndexAndWriteService { TimeProvider.UTC, 10.minutes, "deduplication cache maintenance", - ledger.removeExpiredDeduplicationData, + i => ledger.removeExpiredDeduplicationData(Timestamp.assertFromInstant(i)), ) } yield new IndexAndWriteService { override val indexService: IndexService = indexSvc diff --git a/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/Ledger.scala b/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/Ledger.scala index 653a05caca96..532d68ae7cd3 100644 --- a/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/Ledger.scala +++ b/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/Ledger.scala @@ -3,8 +3,6 @@ package com.daml.platform.sandbox.stores.ledger -import java.time.Instant - import com.daml.daml_lf_dev.DamlLf.Archive import com.daml.ledger.configuration.Configuration import com.daml.ledger.participant.state.{v2 => state} @@ -43,7 +41,7 @@ private[sandbox] trait Ledger extends ReadOnlyLedger { // Package management def uploadPackages( submissionId: Ref.SubmissionId, - knownSince: Instant, + knownSince: Timestamp, sourceDescription: Option[String], payload: List[Archive], )(implicit loggingContext: LoggingContext): Future[state.SubmissionResult] diff --git a/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/MeteredLedger.scala b/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/MeteredLedger.scala index a761125e3610..d4f9f84e8ff2 100644 --- a/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/MeteredLedger.scala +++ b/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/MeteredLedger.scala @@ -3,8 +3,6 @@ package com.daml.platform.sandbox.stores.ledger -import java.time.Instant - import com.daml.daml_lf_dev.DamlLf.Archive import com.daml.ledger.configuration.Configuration import com.daml.ledger.participant.state.{v2 => state} @@ -43,7 +41,7 @@ private class MeteredLedger(ledger: Ledger, metrics: Metrics) def uploadPackages( submissionId: Ref.SubmissionId, - knownSince: Instant, + knownSince: Time.Timestamp, sourceDescription: Option[String], payload: List[Archive], )(implicit loggingContext: LoggingContext): Future[state.SubmissionResult] = diff --git a/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/ScenarioLoader.scala b/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/ScenarioLoader.scala index f227378efecc..4b21ca24165e 100644 --- a/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/ScenarioLoader.scala +++ b/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/ScenarioLoader.scala @@ -238,8 +238,8 @@ private[sandbox] object ScenarioLoader { submissionId, richTransaction.actAs.toList, workflowId, - time.toInstant, - time.toInstant, + time, + time, tx, richTransaction.blindingInfo.disclosure, ), diff --git a/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/inmemory/InMemoryLedger.scala b/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/inmemory/InMemoryLedger.scala index c3427ba2db0f..2114c013e305 100644 --- a/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/inmemory/InMemoryLedger.scala +++ b/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/inmemory/InMemoryLedger.scala @@ -5,51 +5,26 @@ package com.daml.platform.sandbox.stores.ledger.inmemory import java.time.Instant import java.util.concurrent.atomic.AtomicReference - import akka.NotUsed import akka.stream.scaladsl.Source import com.daml.api.util.TimeProvider import com.daml.daml_lf_dev.DamlLf.Archive -import com.daml.ledger.api.domain.{ - ApplicationId, - CommandId, - Filters, - InclusiveFilters, - LedgerId, - LedgerOffset, - PartyDetails, - RejectionReason, - TransactionFilter, -} +import com.daml.ledger.api.domain.{ApplicationId, CommandId, Filters, InclusiveFilters, LedgerId, LedgerOffset, PartyDetails, RejectionReason, TransactionFilter} import com.daml.ledger.api.health.{HealthStatus, Healthy} import com.daml.ledger.api.v1.active_contracts_service.GetActiveContractsResponse import com.daml.ledger.api.v1.command_completion_service.CompletionStreamResponse import com.daml.ledger.api.v1.event.CreatedEvent -import com.daml.ledger.api.v1.transaction_service.{ - GetFlatTransactionResponse, - GetTransactionResponse, - GetTransactionTreesResponse, - GetTransactionsResponse, -} +import com.daml.ledger.api.v1.transaction_service.{GetFlatTransactionResponse, GetTransactionResponse, GetTransactionTreesResponse, GetTransactionsResponse} import com.daml.ledger.configuration.Configuration import com.daml.ledger.offset.Offset -import com.daml.ledger.participant.state.index.v2.{ - CommandDeduplicationDuplicate, - CommandDeduplicationNew, - CommandDeduplicationResult, - PackageDetails, -} +import com.daml.ledger.participant.state.index.v2.{CommandDeduplicationDuplicate, CommandDeduplicationNew, CommandDeduplicationResult, PackageDetails} import com.daml.ledger.participant.state.{v2 => state} +import com.daml.lf.data.Time.Timestamp import com.daml.lf.data.{ImmArray, Ref, Time} -import com.daml.lf.engine.{Engine, ValueEnricher, Result, ResultDone} +import com.daml.lf.engine.{Engine, Result, ResultDone, ValueEnricher} import com.daml.lf.language.Ast import com.daml.lf.ledger.EventId -import com.daml.lf.transaction.{ - GlobalKey, - CommittedTransaction, - SubmittedTransaction, - TransactionCommitter, -} +import com.daml.lf.transaction.{CommittedTransaction, GlobalKey, SubmittedTransaction, TransactionCommitter} import com.daml.lf.value.Value import com.daml.lf.value.Value.{ContractId, ContractInst} import com.daml.logging.{ContextualizedLogger, LoggingContext} @@ -63,12 +38,7 @@ import com.daml.platform.sandbox.stores.ledger.{Ledger, Rejection} import com.daml.platform.store.CompletionFromTransaction import com.daml.platform.store.Contract.ActiveContract import com.daml.platform.store.Conversions.RejectionReasonOps -import com.daml.platform.store.entries.{ - ConfigurationEntry, - LedgerEntry, - PackageLedgerEntry, - PartyLedgerEntry, -} +import com.daml.platform.store.entries.{ConfigurationEntry, LedgerEntry, PackageLedgerEntry, PartyLedgerEntry} import com.daml.platform.{ApiOffset, index} import io.grpc.Status import scalaz.syntax.tag.ToTagOps @@ -335,7 +305,7 @@ private[sandbox] final class InMemoryLedger( override def lookupMaximumLedgerTime(contractIds: Set[ContractId])(implicit loggingContext: LoggingContext - ): Future[Option[Instant]] = + ): Future[Option[Timestamp]] = if (contractIds.isEmpty) { Future.failed( new IllegalArgumentException( @@ -352,7 +322,7 @@ private[sandbox] final class InMemoryLedger( ) .let acc.map(acc => if (let.isAfter(acc)) let else acc) - }) + }).map(Timestamp.assertFromInstant) })) } @@ -370,8 +340,8 @@ private[sandbox] final class InMemoryLedger( // Validates the given ledger time according to the ledger time model private def checkTimeModel( - ledgerTime: Instant, - recordTime: Instant, + ledgerTime: Timestamp, + recordTime: Timestamp, ): Either[Rejection, Unit] = ledgerConfiguration .toRight(Rejection.NoLedgerConfiguration) @@ -385,8 +355,8 @@ private[sandbox] final class InMemoryLedger( transactionMeta: state.TransactionMeta, transaction: SubmittedTransaction, )(implicit loggingContext: LoggingContext): Unit = { - val ledgerTime = transactionMeta.ledgerEffectiveTime.toInstant - val recordTime = timeProvider.getCurrentTime + val ledgerTime = transactionMeta.ledgerEffectiveTime + val recordTime = timeProvider.getCurrentTimestamp checkTimeModel(ledgerTime, recordTime) .fold( rejection => handleError(submitterInfo, rejection.toDomainRejectionReason), @@ -424,7 +394,7 @@ private[sandbox] final class InMemoryLedger( Some(submitterInfo.submissionId), submitterInfo.actAs, transactionMeta.workflowId, - transactionMeta.ledgerEffectiveTime.toInstant, + transactionMeta.ledgerEffectiveTime, recordTime, committedTransaction, disclosureForIndex, @@ -445,7 +415,7 @@ private[sandbox] final class InMemoryLedger( entries.publish( InMemoryLedgerEntry( LedgerEntry.Rejection( - timeProvider.getCurrentTime, + timeProvider.getCurrentTimestamp, submitterInfo.commandId, submitterInfo.applicationId, submitterInfo.submissionId, @@ -531,7 +501,7 @@ private[sandbox] final class InMemoryLedger( InMemoryPartyEntry( PartyLedgerEntry.AllocationRejected( submissionId, - timeProvider.getCurrentTime, + timeProvider.getCurrentTimestamp, "Party already exists", ) ) @@ -542,7 +512,7 @@ private[sandbox] final class InMemoryLedger( InMemoryPartyEntry( PartyLedgerEntry.AllocationAccepted( Some(submissionId), - timeProvider.getCurrentTime, + timeProvider.getCurrentTimestamp, PartyDetails(party, displayName, isLocal = true), ) ) @@ -583,7 +553,7 @@ private[sandbox] final class InMemoryLedger( override def uploadPackages( submissionId: Ref.SubmissionId, - knownSince: Instant, + knownSince: Timestamp, sourceDescription: Option[String], payload: List[Archive], )(implicit loggingContext: LoggingContext): Future[state.SubmissionResult] = { @@ -596,7 +566,7 @@ private[sandbox] final class InMemoryLedger( entries.publish( InMemoryPackageEntry( PackageLedgerEntry - .PackageUploadRejected(submissionId, timeProvider.getCurrentTime, err) + .PackageUploadRejected(submissionId, timeProvider.getCurrentTimestamp, err) ) ) Future.successful(state.SubmissionResult.Acknowledged) @@ -605,7 +575,7 @@ private[sandbox] final class InMemoryLedger( if (packageStoreRef.compareAndSet(oldStore, newStore)) { entries.publish( InMemoryPackageEntry( - PackageLedgerEntry.PackageUploadAccepted(submissionId, timeProvider.getCurrentTime) + PackageLedgerEntry.PackageUploadAccepted(submissionId, timeProvider.getCurrentTimestamp) ) ) Future.successful(state.SubmissionResult.Acknowledged) @@ -623,8 +593,7 @@ private[sandbox] final class InMemoryLedger( )(implicit loggingContext: LoggingContext): Future[state.SubmissionResult] = Future.successful { this.synchronized { - val recordTime = timeProvider.getCurrentTime - val mrt = maxRecordTime.toInstant + val recordTime = timeProvider.getCurrentTimestamp ledgerConfiguration match { case Some(currentConfig) if config.generation != currentConfig.generation + 1 => entries.publish( @@ -637,12 +606,12 @@ private[sandbox] final class InMemoryLedger( ) ) - case _ if recordTime.isAfter(mrt) => + case _ if recordTime > maxRecordTime => entries.publish( InMemoryConfigEntry( ConfigurationEntry.Rejected( submissionId, - s"Configuration change timed out: $mrt > $recordTime", + s"Configuration change timed out: $maxRecordTime > $recordTime", config, ) ) @@ -689,8 +658,8 @@ private[sandbox] final class InMemoryLedger( override def deduplicateCommand( commandId: CommandId, submitters: List[Ref.Party], - submittedAt: Instant, - deduplicateUntil: Instant, + submittedAt: Timestamp, + deduplicateUntil: Timestamp, )(implicit loggingContext: LoggingContext): Future[CommandDeduplicationResult] = Future.successful { this.synchronized { @@ -698,28 +667,28 @@ private[sandbox] final class InMemoryLedger( val entry = commands.get(key) if (entry.isEmpty) { // No previous entry - new command - commands += (key -> CommandDeduplicationEntry(key, deduplicateUntil)) + commands += (key -> CommandDeduplicationEntry(key, deduplicateUntil.toInstant)) CommandDeduplicationNew } else { val previousDeduplicateUntil = entry.get.deduplicateUntil - if (submittedAt.isAfter(previousDeduplicateUntil)) { + if (submittedAt.toInstant.isAfter(previousDeduplicateUntil)) { // Previous entry expired - new command - commands += (key -> CommandDeduplicationEntry(key, deduplicateUntil)) + commands += (key -> CommandDeduplicationEntry(key, deduplicateUntil.toInstant)) CommandDeduplicationNew } else { // Existing previous entry - deduplicate command - CommandDeduplicationDuplicate(previousDeduplicateUntil) + CommandDeduplicationDuplicate(Timestamp.assertFromInstant(previousDeduplicateUntil)) } } } } - override def removeExpiredDeduplicationData(currentTime: Instant)(implicit + override def removeExpiredDeduplicationData(currentTime: Timestamp)(implicit loggingContext: LoggingContext ): Future[Unit] = Future.successful { this.synchronized { - commands.retain((_, v) => v.deduplicateUntil.isAfter(currentTime)) + commands.retain((_, v) => v.deduplicateUntil.isAfter(currentTime.toInstant)) () } } diff --git a/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/sql/SqlLedger.scala b/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/sql/SqlLedger.scala index 3729e563ec1f..3bb24fdde5c5 100644 --- a/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/sql/SqlLedger.scala +++ b/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/sql/SqlLedger.scala @@ -3,9 +3,7 @@ package com.daml.platform.sandbox.stores.ledger.sql -import java.time.Instant import java.util.concurrent.atomic.AtomicReference - import akka.Done import akka.stream.QueueOfferResult.{Dropped, Enqueued, QueueClosed} import akka.stream.scaladsl.{Keep, Sink, Source, SourceQueueWithComplete} @@ -21,6 +19,7 @@ import com.daml.ledger.offset.Offset import com.daml.ledger.participant.state.index.v2.{ContractStore, PackageDetails} import com.daml.ledger.participant.state.{v2 => state} import com.daml.ledger.resources.{Resource, ResourceContext, ResourceOwner} +import com.daml.lf.data.Time.Timestamp import com.daml.lf.data.{ImmArray, Ref, Time} import com.daml.lf.engine.{Engine, ValueEnricher} import com.daml.lf.transaction.{SubmittedTransaction, TransactionCommitter} @@ -218,7 +217,7 @@ private[sandbox] object SqlLedger { _ <- copyPackages( packages, ledgerDao, - timeProvider.getCurrentTime, + timeProvider.getCurrentTimestamp, SandboxOffset.toOffset(ledgerEnd), ) _ <- ledgerDao.storeInitialState(ledgerEntries, SandboxOffset.toOffset(ledgerEnd)) @@ -228,7 +227,7 @@ private[sandbox] object SqlLedger { private def copyPackages( store: InMemoryPackageStore, ledgerDao: LedgerWriteDao, - knownSince: Instant, + knownSince: Timestamp, newLedgerEnd: Offset, ): Future[Unit] = { val packageDetails = store.listLfPackagesSync() @@ -398,8 +397,8 @@ private final class SqlLedger( // Validates the given ledger time according to the ledger time model private def checkTimeModel( - ledgerTime: Instant, - recordTime: Instant, + ledgerTime: Timestamp, + recordTime: Timestamp, ): Either[Rejection, Unit] = currentConfiguration .get() @@ -416,8 +415,8 @@ private final class SqlLedger( enqueue { offset => val transactionId = offset.toApiString - val ledgerTime = transactionMeta.ledgerEffectiveTime.toInstant - val recordTime = timeProvider.getCurrentTime + val ledgerTime = transactionMeta.ledgerEffectiveTime + val recordTime = timeProvider.getCurrentTimestamp checkTimeModel(ledgerTime, recordTime) .fold( @@ -438,7 +437,7 @@ private final class SqlLedger( completionInfo = Some(submitterInfo.toCompletionInfo), workflowId = transactionMeta.workflowId, transactionId = transactionId, - ledgerEffectiveTime = transactionMeta.ledgerEffectiveTime.toInstant, + ledgerEffectiveTime = transactionMeta.ledgerEffectiveTime, offset = CurrentOffset(offset), transaction = transactionCommitter.commitTransaction(transactionId, transaction), divulgedContracts = divulgedContracts, @@ -492,7 +491,7 @@ private final class SqlLedger( CurrentOffset(offset), PartyLedgerEntry.AllocationAccepted( Some(submissionId), - timeProvider.getCurrentTime, + timeProvider.getCurrentTimestamp, PartyDetails(party, displayName, isLocal = true), ), ) @@ -517,7 +516,7 @@ private final class SqlLedger( override def uploadPackages( submissionId: Ref.SubmissionId, - knownSince: Instant, + knownSince: Timestamp, sourceDescription: Option[String], payload: List[Archive], )(implicit loggingContext: LoggingContext): Future[state.SubmissionResult] = { @@ -529,7 +528,7 @@ private final class SqlLedger( .storePackageEntry( CurrentOffset(offset), packages, - Some(PackageLedgerEntry.PackageUploadAccepted(submissionId, timeProvider.getCurrentTime)), + Some(PackageLedgerEntry.PackageUploadAccepted(submissionId, timeProvider.getCurrentTimestamp)), ) .map(_ => ())(DEC) .recover { case t => @@ -546,18 +545,17 @@ private final class SqlLedger( config: Configuration, )(implicit loggingContext: LoggingContext): Future[state.SubmissionResult] = enqueue { offset => - val recordTime = timeProvider.getCurrentTime - val mrt = maxRecordTime.toInstant + val recordTime = timeProvider.getCurrentTimestamp val storeF = - if (recordTime.isAfter(mrt)) { + if (recordTime > maxRecordTime) { ledgerDao .storeConfigurationEntry( CurrentOffset(offset), recordTime, submissionId, config, - Some(s"Configuration change timed out: $mrt > $recordTime"), + Some(s"Configuration change timed out: $maxRecordTime > $recordTime"), ) } else { // NOTE(JM): If the generation in the new configuration is invalid diff --git a/ledger/sandbox-classic/src/test/suite/scala/platform/sandbox/stores/ledger/sql/SqlLedgerOnMutableIndexSpec.scala b/ledger/sandbox-classic/src/test/suite/scala/platform/sandbox/stores/ledger/sql/SqlLedgerOnMutableIndexSpec.scala index 03fe1cae0e2c..b88785612e37 100644 --- a/ledger/sandbox-classic/src/test/suite/scala/platform/sandbox/stores/ledger/sql/SqlLedgerOnMutableIndexSpec.scala +++ b/ledger/sandbox-classic/src/test/suite/scala/platform/sandbox/stores/ledger/sql/SqlLedgerOnMutableIndexSpec.scala @@ -5,7 +5,6 @@ package com.daml.platform.sandbox.stores.ledger.sql import java.io.File import java.time.{Duration, Instant} - import akka.stream.scaladsl.Sink import ch.qos.logback.classic.Level import com.daml.api.util.TimeProvider @@ -21,6 +20,7 @@ import com.daml.ledger.participant.state.v2.{SubmissionResult, SubmitterInfo, Tr import com.daml.ledger.resources.{Resource, ResourceContext, TestResourceContext} import com.daml.ledger.test.ModelTestDar import com.daml.lf.archive.DarParser +import com.daml.lf.data.Time.Timestamp import com.daml.lf.data.{ImmArray, Ref, Time} import com.daml.lf.engine.Engine import com.daml.lf.transaction.LegacyTransactionCommitter @@ -263,7 +263,7 @@ final class SqlLedgerOnMutableIndexSpec } "publish a transaction" in { - val now = Time.Timestamp.assertFromInstant(Instant.now()) + val now = Time.Timestamp.now() for { sqlLedger <- createSqlLedger() start = sqlLedger.ledgerEnd() @@ -303,7 +303,7 @@ final class SqlLedgerOnMutableIndexSpec } "reject a transaction if no configuration is found" in { - val now = Time.Timestamp.assertFromInstant(Instant.now()) + val now = Time.Timestamp.now() for { sqlLedger <- createSqlLedger() start = sqlLedger.ledgerEnd() @@ -443,7 +443,7 @@ final class SqlLedgerOnMutableIndexSpec participantId = participantId.getOrElse(DefaultParticipantId), timeProvider = timeProvider, packages = InMemoryPackageStore.empty - .withPackages(Instant.EPOCH, None, packages) + .withPackages(Timestamp.Epoch, None, packages) .fold(sys.error, identity), initialLedgerEntries = ImmArray.Empty, queueDepth = queueDepth, diff --git a/ledger/sandbox-classic/src/test/suite/scala/platform/sandbox/stores/ledger/sql/SqlLedgerSpec.scala b/ledger/sandbox-classic/src/test/suite/scala/platform/sandbox/stores/ledger/sql/SqlLedgerSpec.scala index 2af385b9c03f..f318d62cc4f7 100644 --- a/ledger/sandbox-classic/src/test/suite/scala/platform/sandbox/stores/ledger/sql/SqlLedgerSpec.scala +++ b/ledger/sandbox-classic/src/test/suite/scala/platform/sandbox/stores/ledger/sql/SqlLedgerSpec.scala @@ -5,7 +5,6 @@ package com.daml.platform.sandbox.stores.ledger.sql import java.io.File import java.time.{Duration, Instant} - import akka.stream.scaladsl.Sink import ch.qos.logback.classic.Level import com.daml.api.util.TimeProvider @@ -21,6 +20,7 @@ import com.daml.ledger.participant.state.v2.{SubmissionResult, SubmitterInfo, Tr import com.daml.ledger.resources.{Resource, ResourceContext, TestResourceContext} import com.daml.ledger.test.ModelTestDar import com.daml.lf.archive.DarParser +import com.daml.lf.data.Time.Timestamp import com.daml.lf.data.{ImmArray, Ref, Time} import com.daml.lf.engine.Engine import com.daml.lf.transaction.LegacyTransactionCommitter @@ -248,7 +248,7 @@ final class SqlLedgerSpec } "publish a transaction" in { - val now = Time.Timestamp.assertFromInstant(Instant.now()) + val now = Time.Timestamp.now() for { sqlLedger <- createSqlLedger() start = sqlLedger.ledgerEnd() @@ -288,7 +288,7 @@ final class SqlLedgerSpec } "reject a transaction if no configuration is found" in { - val now = Time.Timestamp.assertFromInstant(Instant.now()) + val now = Time.Timestamp.now() for { sqlLedger <- createSqlLedger() start = sqlLedger.ledgerEnd() @@ -454,7 +454,7 @@ final class SqlLedgerSpec participantId = participantId.getOrElse(DefaultParticipantId), timeProvider = timeProvider, packages = InMemoryPackageStore.empty - .withPackages(Instant.EPOCH, None, packages) + .withPackages(Timestamp.Epoch, None, packages) .fold(sys.error, identity), initialLedgerEntries = ImmArray.Empty, queueDepth = queueDepth,