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 608eb71bbb9a..460978c67df0 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 @@ -252,7 +252,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..915d86263807 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 @@ -6,11 +6,14 @@ 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..3ed3e8c70e0b 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,46 @@ 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.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 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..c752370184a3 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 @@ -11,6 +11,7 @@ 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 +82,32 @@ 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 { + "round half up" in forAll(anyTimeInRange) { ts => + val protoTs = fromInstant(ts) + val halfUp = toLf(protoTs, ConversionMode.HalfUp) + halfUp.toInstant should be > ts.plusNanos(-500) + halfUp.toInstant should be <= ts.plusNanos(500) + } + } + } } object TimestampConversionSpec { @@ -110,4 +137,9 @@ object TimestampConversionSpec { val anyMicroInRange: Gen[Instant] = timeGen(MIN, MAX, microsOnly = true) + + val lfTimestampGen: Gen[Time.Timestamp] = Gen.choose( + Time.Timestamp.MinValue.micros, + Time.Timestamp.MaxValue.micros, + ) map Time.Timestamp.assertFromLong } diff --git a/ledger/ledger-api-common/src/main/scala/com/digitalasset/ledger/api/validation/CommandsValidator.scala b/ledger/ledger-api-common/src/main/scala/com/digitalasset/ledger/api/validation/CommandsValidator.scala index 25ab82124a13..5caa2740c77a 100644 --- a/ledger/ledger-api-common/src/main/scala/com/digitalasset/ledger/api/validation/CommandsValidator.scala +++ b/ledger/ledger-api-common/src/main/scala/com/digitalasset/ledger/api/validation/CommandsValidator.scala @@ -75,7 +75,7 @@ final class CommandsValidator(ledgerId: LedgerId) { submissionId = submissionId, actAs = submitters.actAs, readAs = submitters.readAs, - submittedAt = currentUtcTime, + submittedAt = Time.Timestamp.assertFromInstant(currentUtcTime), deduplicationPeriod = deduplicationPeriod, commands = Commands( commands = validatedCommands.to(ImmArray), diff --git a/ledger/ledger-api-common/src/test/suite/scala/com/digitalasset/ledger/api/validation/SubmitRequestValidatorTest.scala b/ledger/ledger-api-common/src/test/suite/scala/com/digitalasset/ledger/api/validation/SubmitRequestValidatorTest.scala index a9a2ebb3b3d9..1bfe73335489 100644 --- a/ledger/ledger-api-common/src/test/suite/scala/com/digitalasset/ledger/api/validation/SubmitRequestValidatorTest.scala +++ b/ledger/ledger-api-common/src/test/suite/scala/com/digitalasset/ledger/api/validation/SubmitRequestValidatorTest.scala @@ -87,7 +87,7 @@ class SubmitRequestValidatorTest submissionId = submissionId, actAs = Set(DomainMocks.party), readAs = Set.empty, - submittedAt = submittedAt, + submittedAt = Time.Timestamp.assertFromInstant(submittedAt), deduplicationPeriod = DeduplicationPeriod.DeduplicationDuration(deduplicationDuration), commands = LfCommands( ImmArray( diff --git a/ledger/ledger-api-domain/src/main/scala/com/digitalasset/ledger/api/DeduplicationPeriod.scala b/ledger/ledger-api-domain/src/main/scala/com/digitalasset/ledger/api/DeduplicationPeriod.scala index 36b1b6ee4c64..b73aadb19809 100644 --- a/ledger/ledger-api-domain/src/main/scala/com/digitalasset/ledger/api/DeduplicationPeriod.scala +++ b/ledger/ledger-api-domain/src/main/scala/com/digitalasset/ledger/api/DeduplicationPeriod.scala @@ -3,9 +3,9 @@ package com.daml.ledger.api -import java.time.{Duration, Instant} - +import java.time.Duration import com.daml.ledger.offset.Offset +import com.daml.lf.data.Time.Timestamp import com.daml.logging.entries.{LoggingValue, ToLoggingValue} /** Specifies the deduplication period for a command submission. @@ -18,17 +18,17 @@ sealed trait DeduplicationPeriod extends Product with Serializable object DeduplicationPeriod { - /** Transforms the [[period]] into an [[Instant]] to be used for deduplication into the future(deduplicateUntil). + /** Transforms the [[period]] into a [[Timestamp]] to be used for deduplication into the future(deduplicateUntil). * Only used for backwards compatibility - * @param time The time to use for calculating the [[Instant]]. It can either be submission time or current time, based on usage + * @param time The time to use for calculating the [[Timestamp]]. It can either be submission time or current time, based on usage * @param period The deduplication period */ def deduplicateUntil( - time: Instant, + time: Timestamp, period: DeduplicationPeriod, - ): Instant = period match { + ): Timestamp = period match { case DeduplicationDuration(duration) => - time.plus(duration) + time.addMicros(duration.toNanos / 1000) case DeduplicationOffset(_) => throw new NotImplementedError("Offset deduplication is not supported") } @@ -37,18 +37,18 @@ object DeduplicationPeriod { * We measure `deduplicationStart` on the ledger’s clock, and thus * we need to add the minSkew to compensate for the maximal skew that the participant might be behind the ledger’s clock. * @param time submission time or current time - * @param deduplicationStart the [[Instant]] from where we should start deduplication, must be < than time + * @param deduplicationStart the [[Timestamp]] from where we should start deduplication, must be < than time * @param minSkew the minimum skew as specified by the current ledger time model */ def deduplicationDurationFromTime( - time: Instant, - deduplicationStart: Instant, + time: Timestamp, + deduplicationStart: Timestamp, minSkew: Duration, ): Duration = { - assert(deduplicationStart.isBefore(time), "Deduplication must start in the past") + assert(deduplicationStart < time, "Deduplication must start in the past") Duration.between( - deduplicationStart, - time.plus(minSkew), + deduplicationStart.toInstant, + time.toInstant.plus(minSkew), ) } @@ -62,6 +62,10 @@ object DeduplicationPeriod { */ final case class DeduplicationDuration(duration: Duration) extends DeduplicationPeriod { require(!duration.isNegative, s"The deduplication window must not be negative: $duration") + require( + duration.toNanos % 1000 == 0, + s"The deduplication window must not use nanosecond precision: $duration", + ) } /** The `offset` defines the start of the deduplication period. */ diff --git a/ledger/ledger-api-domain/src/main/scala/com/digitalasset/ledger/api/domain.scala b/ledger/ledger-api-domain/src/main/scala/com/digitalasset/ledger/api/domain.scala index b00f06e3e1ea..edebfe46f8b9 100644 --- a/ledger/ledger-api-domain/src/main/scala/com/digitalasset/ledger/api/domain.scala +++ b/ledger/ledger-api-domain/src/main/scala/com/digitalasset/ledger/api/domain.scala @@ -3,13 +3,12 @@ package com.daml.ledger.api -import java.time.Instant - import com.daml.ledger.api.domain.Event.{CreateOrArchiveEvent, CreateOrExerciseEvent} import com.daml.ledger.configuration.Configuration import com.daml.lf.command.{Commands => LfCommands} import com.daml.lf.data.Ref import com.daml.lf.data.Ref.LedgerString.ordering +import com.daml.lf.data.Time.Timestamp import com.daml.lf.data.logging._ import com.daml.lf.value.{Value => Lf} import com.daml.logging.entries.{LoggingValue, ToLoggingValue} @@ -131,7 +130,7 @@ object domain { def workflowId: Option[WorkflowId] - def effectiveAt: Instant + def effectiveAt: Timestamp def offset: LedgerOffset.Absolute } @@ -140,7 +139,7 @@ object domain { transactionId: TransactionId, commandId: Option[CommandId], workflowId: Option[WorkflowId], - effectiveAt: Instant, + effectiveAt: Timestamp, offset: LedgerOffset.Absolute, eventsById: immutable.Map[EventId, CreateOrExerciseEvent], rootEventIds: immutable.Seq[EventId], @@ -150,31 +149,31 @@ object domain { transactionId: TransactionId, commandId: Option[CommandId], workflowId: Option[WorkflowId], - effectiveAt: Instant, + effectiveAt: Timestamp, events: immutable.Seq[CreateOrArchiveEvent], offset: LedgerOffset.Absolute, ) extends TransactionBase sealed trait CompletionEvent extends Product with Serializable { def offset: LedgerOffset.Absolute - def recordTime: Instant + def recordTime: Timestamp } object CompletionEvent { - final case class Checkpoint(offset: LedgerOffset.Absolute, recordTime: Instant) + final case class Checkpoint(offset: LedgerOffset.Absolute, recordTime: Timestamp) extends CompletionEvent final case class CommandAccepted( offset: LedgerOffset.Absolute, - recordTime: Instant, + recordTime: Timestamp, commandId: CommandId, transactionId: TransactionId, ) extends CompletionEvent final case class CommandRejected( offset: LedgerOffset.Absolute, - recordTime: Instant, + recordTime: Timestamp, commandId: CommandId, reason: RejectionReason, ) extends CompletionEvent @@ -282,7 +281,7 @@ object domain { submissionId: SubmissionId, actAs: Set[Ref.Party], readAs: Set[Ref.Party], - submittedAt: Instant, + submittedAt: Timestamp, deduplicationPeriod: DeduplicationPeriod, commands: LfCommands, ) @@ -291,6 +290,9 @@ object domain { import Logging._ + implicit val `Timestamp to LoggingValue`: ToLoggingValue[Timestamp] = + ToLoggingValue.ToStringToLoggingValue + implicit val `Commands to LoggingValue`: ToLoggingValue[Commands] = commands => LoggingValue.Nested.fromEntries( "ledgerId" -> commands.ledgerId, @@ -347,12 +349,12 @@ object domain { object PackageEntry { final case class PackageUploadAccepted( submissionId: String, - recordTime: Instant, + recordTime: Timestamp, ) extends PackageEntry final case class PackageUploadRejected( submissionId: String, - recordTime: Instant, + recordTime: Timestamp, reason: String, ) extends PackageEntry } diff --git a/ledger/ledger-api-domain/src/test/suite/scala/com/daml/ledger/api/DeduplicationPeriodSpec.scala b/ledger/ledger-api-domain/src/test/suite/scala/com/daml/ledger/api/DeduplicationPeriodSpec.scala index e11eef5909a4..b490dba9ea8b 100644 --- a/ledger/ledger-api-domain/src/test/suite/scala/com/daml/ledger/api/DeduplicationPeriodSpec.scala +++ b/ledger/ledger-api-domain/src/test/suite/scala/com/daml/ledger/api/DeduplicationPeriodSpec.scala @@ -3,21 +3,22 @@ package com.daml.ledger.api -import java.time.{Duration, Instant} +import com.daml.lf.data.Time.Timestamp +import java.time.Duration import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec class DeduplicationPeriodSpec extends AnyWordSpec with Matchers { "calculating deduplication until" should { - val time = Instant.ofEpochSecond(100) + val time = Timestamp.assertFromLong(100 * 1000 * 1000) "return expected result when sending duration" in { val deduplicateUntil = DeduplicationPeriod.deduplicateUntil( time, DeduplicationPeriod.DeduplicationDuration(Duration.ofSeconds(3)), ) - deduplicateUntil shouldEqual time.plusSeconds(3) + deduplicateUntil shouldEqual time.add(Duration.ofSeconds(3)) } } 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..aeb7f772f78e 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 @@ -6,6 +6,7 @@ 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 +44,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/db/migration/postgres/V2_1__Rebuild_Acs.scala b/ledger/participant-integration-api/src/main/scala/db/migration/postgres/V2_1__Rebuild_Acs.scala index 66cb3783beba..4e639e780c8f 100644 --- a/ledger/participant-integration-api/src/main/scala/db/migration/postgres/V2_1__Rebuild_Acs.scala +++ b/ledger/participant-integration-api/src/main/scala/db/migration/postgres/V2_1__Rebuild_Acs.scala @@ -17,6 +17,7 @@ import com.daml.ledger.api.domain.RejectionReason import com.daml.ledger.api.domain.RejectionReason._ import com.daml.lf.data.Ref import com.daml.lf.data.Relation.Relation +import com.daml.lf.data.Time.Timestamp import com.daml.lf.engine.Blinding import com.daml.lf.transaction.GlobalKey import com.daml.lf.value.Value.ContractId @@ -358,7 +359,7 @@ private[migration] class V2_1__Rebuild_Acs extends BaseJavaMigration { // Note: ACS is typed as Unit here, as the ACS is given implicitly by the current database state // within the current SQL transaction. All of the given functions perform side effects to update the database. val atr = acsManager.addTransaction( - ledgerEffectiveTime, + ledgerEffectiveTime.toInstant, transactionId, workflowId, tx.actAs, @@ -462,8 +463,8 @@ private[migration] class V2_1__Rebuild_Acs extends BaseJavaMigration { submissionId = None, actAs = List(submitter), workflowId = workflowId, - ledgerEffectiveTime = effectiveAt.toInstant, - recordedAt = recordedAt.toInstant, + ledgerEffectiveTime = Timestamp.assertFromInstant(effectiveAt.toInstant), + recordedAt = Timestamp.assertFromInstant(recordedAt.toInstant), transaction = transactionSerializer .deserializeTransaction(transactionId, transactionStream) .getOrElse(sys.error(s"failed to deserialize transaction! trId: $transactionId")), @@ -487,7 +488,7 @@ private[migration] class V2_1__Rebuild_Acs extends BaseJavaMigration { val submissionId = Ref.SubmissionId.assertFromString(UUID.randomUUID().toString) val rejectionReason = readRejectionReason(rejectionType, rejectionDescription) offset -> LedgerEntry.Rejection( - recordTime = recordedAt.toInstant, + recordTime = Timestamp.assertFromInstant(recordedAt.toInstant), commandId = commandId, applicationId = applicationId, submissionId = submissionId, 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 bbb3366c3d34..7097ad43abc0 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,8 +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 @@ -31,6 +29,7 @@ import com.daml.ledger.offset.Offset import com.daml.ledger.participant.state.index.v2 import com.daml.ledger.participant.state.index.v2.IndexService import com.daml.lf.data.Ref +import com.daml.lf.data.Time.Timestamp import com.daml.lf.language.Ast import com.daml.lf.transaction.GlobalKey import com.daml.lf.value.Value @@ -144,7 +143,7 @@ private[daml] final class SpannedIndexService(delegate: IndexService) extends In override def lookupMaximumLedgerTime( ids: Set[Value.ContractId] - )(implicit loggingContext: LoggingContext): Future[Option[Instant]] = + )(implicit loggingContext: LoggingContext): Future[Option[Timestamp]] = delegate.lookupMaximumLedgerTime(ids) override def getLedgerId()(implicit loggingContext: LoggingContext): Future[LedgerId] = @@ -185,8 +184,8 @@ private[daml] final class SpannedIndexService(delegate: IndexService) extends In override def deduplicateCommand( commandId: CommandId, submitter: List[Ref.Party], - submittedAt: Instant, - deduplicateUntil: Instant, + submittedAt: Timestamp, + deduplicateUntil: Timestamp, )(implicit loggingContext: LoggingContext): Future[v2.CommandDeduplicationResult] = delegate.deduplicateCommand(commandId, submitter, submittedAt, deduplicateUntil) 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 8d1501fe7a22..d6a259290522 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 @@ -16,6 +16,7 @@ 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 @@ -34,7 +35,7 @@ import io.grpc.{BindableService, ServerInterceptor} import scalaz.{-\/, \/-} import java.io.File -import java.time.{Clock, Instant} +import java.time.Clock import scala.collection.immutable import scala.concurrent.ExecutionContextExecutor import scala.util.{Failure, Success, Try} @@ -177,7 +178,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/TimedIndexService.scala b/ledger/participant-integration-api/src/main/scala/platform/apiserver/TimedIndexService.scala index c18d9d4354af..0ffb4a96296a 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/apiserver/TimedIndexService.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/apiserver/TimedIndexService.scala @@ -3,8 +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 @@ -31,6 +29,7 @@ import com.daml.ledger.offset.Offset import com.daml.ledger.participant.state.index.v2 import com.daml.ledger.participant.state.index.v2.IndexService import com.daml.lf.data.Ref +import com.daml.lf.data.Time.Timestamp import com.daml.lf.language.Ast import com.daml.lf.transaction.GlobalKey import com.daml.lf.value.Value @@ -159,7 +158,7 @@ private[daml] final class TimedIndexService(delegate: IndexService, metrics: Met override def lookupMaximumLedgerTime( ids: Set[Value.ContractId] - )(implicit loggingContext: LoggingContext): Future[Option[Instant]] = + )(implicit loggingContext: LoggingContext): Future[Option[Timestamp]] = Timed.future( metrics.daml.services.index.lookupMaximumLedgerTime, delegate.lookupMaximumLedgerTime(ids), @@ -206,8 +205,8 @@ private[daml] final class TimedIndexService(delegate: IndexService, metrics: Met override def deduplicateCommand( commandId: CommandId, submitters: List[Ref.Party], - submittedAt: Instant, - deduplicateUntil: Instant, + submittedAt: Timestamp, + deduplicateUntil: Timestamp, )(implicit loggingContext: LoggingContext): Future[v2.CommandDeduplicationResult] = Timed.future( metrics.daml.services.index.deduplicateCommand, diff --git a/ledger/participant-integration-api/src/main/scala/platform/apiserver/execution/LedgerTimeAwareCommandExecutor.scala b/ledger/participant-integration-api/src/main/scala/platform/apiserver/execution/LedgerTimeAwareCommandExecutor.scala index efb9accbc1e2..1adc56117431 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/apiserver/execution/LedgerTimeAwareCommandExecutor.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/apiserver/execution/LedgerTimeAwareCommandExecutor.scala @@ -66,8 +66,7 @@ private[apiserver] final class LedgerTimeAwareCommandExecutor( else contractStore .lookupMaximumLedgerTime(usedContractIds) - .flatMap { maxUsedInstant => - val maxUsedTime = maxUsedInstant.map(Time.Timestamp.assertFromInstant) + .flatMap { maxUsedTime => if (maxUsedTime.forall(_ <= commands.commands.ledgerEffectiveTime)) { Future.successful(Right(cer)) } else if (!cer.dependsOnLedgerTime) { 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 8425c50c92e3..08548d100a52 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 @@ -7,6 +7,7 @@ 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.error.{DamlContextualizedErrorLogger, ContextualizedErrorLogger} import com.daml.ledger.api.domain.{LedgerOffset, PackageEntry} @@ -29,7 +30,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._ @@ -83,7 +83,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/LedgerBackedIndexService.scala b/ledger/participant-integration-api/src/main/scala/platform/index/LedgerBackedIndexService.scala index 6439948a93f2..10725f9e017e 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/index/LedgerBackedIndexService.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/index/LedgerBackedIndexService.scala @@ -3,7 +3,6 @@ package com.daml.platform.index -import java.time.Instant import akka.NotUsed import akka.stream.scaladsl.Source import com.daml.daml_lf_dev.DamlLf.Archive @@ -36,6 +35,7 @@ import com.daml.ledger.offset.Offset import com.daml.ledger.participant.state.index.v2._ import com.daml.lf.data.Ref import com.daml.lf.data.Ref.{Identifier, PackageId, Party} +import com.daml.lf.data.Time.Timestamp import com.daml.lf.language.Ast import com.daml.lf.transaction.GlobalKey import com.daml.lf.value.Value.{ContractId, VersionedContractInstance} @@ -220,7 +220,7 @@ private[platform] final class LedgerBackedIndexService( override def lookupMaximumLedgerTime(ids: Set[ContractId])(implicit loggingContext: LoggingContext - ): Future[Option[Instant]] = + ): Future[Option[Timestamp]] = ledger.lookupMaximumLedgerTime(ids) override def lookupContractKey( @@ -313,8 +313,8 @@ private[platform] final class LedgerBackedIndexService( override def deduplicateCommand( commandId: CommandId, submitters: List[Ref.Party], - submittedAt: Instant, - deduplicateUntil: Instant, + submittedAt: Timestamp, + deduplicateUntil: Timestamp, )(implicit loggingContext: LoggingContext): Future[CommandDeduplicationResult] = ledger.deduplicateCommand(commandId, submitters, submittedAt, deduplicateUntil) diff --git a/ledger/participant-integration-api/src/main/scala/platform/index/MeteredReadOnlyLedger.scala b/ledger/participant-integration-api/src/main/scala/platform/index/MeteredReadOnlyLedger.scala index 7a93e5956a8e..51bebb0c239c 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/index/MeteredReadOnlyLedger.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/index/MeteredReadOnlyLedger.scala @@ -3,8 +3,6 @@ package com.daml.platform.index -import java.time.Instant - import akka.NotUsed import akka.stream.scaladsl.Source import com.daml.daml_lf_dev.DamlLf.Archive @@ -22,6 +20,7 @@ import com.daml.ledger.configuration.Configuration import com.daml.ledger.offset.Offset import com.daml.ledger.participant.state.index.v2.{CommandDeduplicationResult, PackageDetails} import com.daml.lf.data.Ref +import com.daml.lf.data.Time.Timestamp import com.daml.lf.language.Ast import com.daml.lf.transaction.GlobalKey import com.daml.lf.value.Value.{ContractId, VersionedContractInstance} @@ -108,7 +107,7 @@ private[platform] class MeteredReadOnlyLedger(ledger: ReadOnlyLedger, metrics: M override def lookupMaximumLedgerTime( contractIds: Set[ContractId] - )(implicit loggingContext: LoggingContext): Future[Option[Instant]] = + )(implicit loggingContext: LoggingContext): Future[Option[Timestamp]] = Timed.future( metrics.daml.index.lookupMaximumLedgerTime, ledger.lookupMaximumLedgerTime(contractIds), @@ -166,15 +165,15 @@ private[platform] class MeteredReadOnlyLedger(ledger: ReadOnlyLedger, metrics: M override def deduplicateCommand( commandId: CommandId, submitters: List[Ref.Party], - submittedAt: Instant, - deduplicateUntil: Instant, + submittedAt: Timestamp, + deduplicateUntil: Timestamp, )(implicit loggingContext: LoggingContext): Future[CommandDeduplicationResult] = Timed.future( metrics.daml.index.deduplicateCommand, ledger.deduplicateCommand(commandId, submitters, submittedAt, deduplicateUntil), ) - override def removeExpiredDeduplicationData(currentTime: Instant)(implicit + override def removeExpiredDeduplicationData(currentTime: Timestamp)(implicit loggingContext: LoggingContext ): Future[Unit] = Timed.future( 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 033c8a97639d..715cd3d9bfb1 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._ @@ -15,6 +14,7 @@ import com.daml.ledger.offset.Offset import com.daml.ledger.participant.state.index.v2.ContractStore 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.ValueEnricher import com.daml.logging.{ContextualizedLogger, LoggingContext} import com.daml.metrics.Metrics @@ -176,7 +176,7 @@ private[index] abstract class ReadOnlySqlLedger( private val (deduplicationCleanupKillSwitch, deduplicationCleanupDone) = Source .tick[Unit](0.millis, 10.minutes, ()) - .mapAsync[Unit](1)(_ => ledgerDao.removeExpiredDeduplicationData(Instant.now())) + .mapAsync[Unit](1)(_ => ledgerDao.removeExpiredDeduplicationData(Timestamp.now())) .viaMat(KillSwitches.single)(Keep.right[Cancellable, UniqueKillSwitch]) .toMat(Sink.ignore)(Keep.both[UniqueKillSwitch, Future[Done]]) .run() 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 8c461ee766f7..d03d399a9e44 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 @@ -25,6 +24,7 @@ import com.daml.ledger.participant.state.index.v2 import com.daml.ledger.participant.state.index.v2.{CommandDeduplicationResult, ContractStore} import com.daml.lf.archive.Decode import com.daml.lf.data.Ref +import com.daml.lf.data.Time.Timestamp import com.daml.lf.language.Ast import com.daml.lf.transaction.GlobalKey import com.daml.lf.value.Value.{ContractId, VersionedContractInstance} @@ -131,7 +131,7 @@ private[platform] abstract class BaseLedger( override def lookupMaximumLedgerTime( contractIds: Set[ContractId] - )(implicit loggingContext: LoggingContext): Future[Option[Instant]] = + )(implicit loggingContext: LoggingContext): Future[Option[Timestamp]] = contractStore.lookupMaximumLedgerTime(contractIds) override def getParties(parties: Seq[Ref.Party])(implicit @@ -188,12 +188,12 @@ private[platform] abstract class BaseLedger( override def deduplicateCommand( commandId: CommandId, submitters: List[Ref.Party], - submittedAt: Instant, - deduplicateUntil: Instant, + submittedAt: Timestamp, + deduplicateUntil: Timestamp, )(implicit loggingContext: LoggingContext): Future[CommandDeduplicationResult] = ledgerDao.deduplicateCommand(commandId, submitters, submittedAt, deduplicateUntil) - override def removeExpiredDeduplicationData(currentTime: Instant)(implicit + override def removeExpiredDeduplicationData(currentTime: Timestamp)(implicit loggingContext: LoggingContext ): Future[Unit] = ledgerDao.removeExpiredDeduplicationData(currentTime) diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/CompletionFromTransaction.scala b/ledger/participant-integration-api/src/main/scala/platform/store/CompletionFromTransaction.scala index 9c8f31ac482d..a7122fd17b7f 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/CompletionFromTransaction.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/CompletionFromTransaction.scala @@ -3,13 +3,12 @@ package com.daml.platform.store -import java.time.Instant - import com.daml.api.util.TimestampConversion.fromInstant import com.daml.ledger.api.v1.command_completion_service.{Checkpoint, CompletionStreamResponse} import com.daml.ledger.api.v1.completion.Completion import com.daml.ledger.api.v1.ledger_offset.LedgerOffset import com.daml.ledger.offset.Offset +import com.daml.lf.data.Time.Timestamp import com.daml.platform.ApiOffset.ApiOffsetConverter import com.google.protobuf.duration.Duration import com.google.rpc.status.{Status => StatusProto} @@ -23,7 +22,7 @@ private[platform] object CompletionFromTransaction { private val RejectionTransactionId = "" def acceptedCompletion( - recordTime: Instant, + recordTime: Timestamp, offset: Offset, commandId: String, transactionId: String, @@ -50,7 +49,7 @@ private[platform] object CompletionFromTransaction { ) def rejectedCompletion( - recordTime: Instant, + recordTime: Timestamp, offset: Offset, commandId: String, status: StatusProto, @@ -76,9 +75,9 @@ private[platform] object CompletionFromTransaction { ), ) - private def toApiCheckpoint(recordTime: Instant, offset: Offset): Checkpoint = + private def toApiCheckpoint(recordTime: Timestamp, offset: Offset): Checkpoint = Checkpoint.of( - recordTime = Some(fromInstant(recordTime)), + recordTime = Some(fromInstant(recordTime.toInstant)), offset = Some(LedgerOffset.of(LedgerOffset.Value.Absolute(offset.toApiString))), ) 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 18d480172349..adc9aa23f3f8 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 @@ -4,10 +4,7 @@ package com.daml.platform.store 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.sql.{PreparedStatement, Types} import java.util.stream.Collectors import anorm.Column.nonNull @@ -96,16 +93,6 @@ private[platform] object JdbcArrayConversions { implicit object CharArrayToStatement extends ArrayToStatement[String]("VARCHAR") - implicit object TimestampArrayToStatement extends ArrayToStatement[Timestamp]("TIMESTAMP") - - implicit object InstantArrayToStatement extends ToStatement[Array[Instant]] { - override def set(s: PreparedStatement, index: Int, v: Array[Instant]): Unit = { - val conn = s.getConnection - val ts = conn.createArrayOf("TIMESTAMP", v.map(java.sql.Timestamp.from)) - s.setArray(index, ts) - } - } - } private[platform] object Conversions { @@ -318,20 +305,10 @@ private[platform] object Conversions { .map(v => Offset.fromHexString(Ref.HexString.assertFromString(v))) ) - // Instant - - // TODO append-only: Delete after removing the mutating schema. The append-only schema only uses BIGINT for timestamps. - def instantFromTimestamp(name: String): RowParser[Instant] = - SqlParser.get[Date](name).map(_.toInstant) + // Timestamp - 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) // Hash 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 738c8573652e..c1e9f7dfd3de 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,8 +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 @@ -22,6 +20,7 @@ import com.daml.ledger.configuration.Configuration import com.daml.ledger.offset.Offset import com.daml.ledger.participant.state.index.v2.{CommandDeduplicationResult, PackageDetails} import com.daml.lf.data.Ref +import com.daml.lf.data.Time.Timestamp import com.daml.lf.language.Ast import com.daml.lf.transaction.GlobalKey import com.daml.lf.value.Value.{ContractId, VersionedContractInstance} @@ -72,7 +71,7 @@ private[platform] trait ReadOnlyLedger extends ReportsHealth with AutoCloseable def lookupMaximumLedgerTime( contractIds: Set[ContractId] - )(implicit loggingContext: LoggingContext): Future[Option[Instant]] + )(implicit loggingContext: LoggingContext): Future[Option[Timestamp]] def lookupKey(key: GlobalKey, forParties: Set[Ref.Party])(implicit loggingContext: LoggingContext @@ -135,8 +134,8 @@ private[platform] trait ReadOnlyLedger extends ReportsHealth with AutoCloseable def deduplicateCommand( commandId: CommandId, submitters: List[Ref.Party], - submittedAt: Instant, - deduplicateUntil: Instant, + submittedAt: Timestamp, + deduplicateUntil: Timestamp, )(implicit loggingContext: LoggingContext): Future[CommandDeduplicationResult] /** Stops deduplicating the given command. @@ -162,7 +161,7 @@ private[platform] trait ReadOnlyLedger extends ReportsHealth with AutoCloseable * it does not modify any on-ledger data. */ def removeExpiredDeduplicationData( - currentTime: Instant + currentTime: Timestamp )(implicit loggingContext: LoggingContext): Future[Unit] /** Performs participant ledger pruning up to and including the specified offset. 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 d393f0753446..5f300cc14cef 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 @@ -3,7 +3,6 @@ package com.daml.platform.store.appendonlydao import java.sql.Connection -import java.time.Instant import akka.NotUsed import akka.stream.scaladsl.Source import com.daml.daml_lf_dev.DamlLf.Archive @@ -21,7 +20,8 @@ import com.daml.ledger.participant.state.index.v2.{ 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.{Ref, Time} +import com.daml.lf.data.Time.Timestamp +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 @@ -146,7 +146,7 @@ private class JdbcLedgerDao( override def storeConfigurationEntry( offset: Offset, - recordedAt: Instant, + recordedAt: Timestamp, submissionId: String, configuration: Configuration, rejectionReason: Option[String], @@ -179,7 +179,7 @@ private class JdbcLedgerDao( val update = finalRejectionReason match { case None => state.Update.ConfigurationChanged( - recordTime = Time.Timestamp.assertFromInstant(recordedAt), + recordTime = recordedAt, submissionId = Ref.SubmissionId.assertFromString(submissionId), participantId = Ref.ParticipantId.assertFromString("1"), // not used for DbDto generation @@ -188,7 +188,7 @@ private class JdbcLedgerDao( case Some(reason) => state.Update.ConfigurationChangeRejected( - recordTime = Time.Timestamp.assertFromInstant(recordedAt), + recordTime = recordedAt, submissionId = Ref.SubmissionId.assertFromString(submissionId), participantId = Ref.ParticipantId.assertFromString("1"), // not used for DbDto generation @@ -226,7 +226,7 @@ private class JdbcLedgerDao( // // This will be properly resolved once we move away from the `sandbox-classic` codebase. participantId = if (partyDetails.isLocal) participantId else NonLocalParticipantId, - recordTime = Time.Timestamp.assertFromInstant(recordTime), + recordTime = recordTime, submissionId = submissionIdOpt, ) ), @@ -241,7 +241,7 @@ private class JdbcLedgerDao( state.Update.PartyAllocationRejected( submissionId = submissionId, participantId = participantId, - recordTime = Time.Timestamp.assertFromInstant(recordTime), + recordTime = recordTime, rejectionReason = reason, ) ), @@ -270,7 +270,7 @@ private class JdbcLedgerDao( } private def validate( - ledgerEffectiveTime: Instant, + ledgerEffectiveTime: Timestamp, transaction: CommittedTransaction, divulged: Iterable[state.DivulgedContract], )(implicit connection: Connection): Option[PostCommitValidation.Rejection] = @@ -285,7 +285,7 @@ private class JdbcLedgerDao( override def storeRejection( completionInfo: Option[state.CompletionInfo], - recordTime: Instant, + recordTime: Timestamp, offset: Offset, reason: state.Update.CommandRejected.RejectionReasonTemplate, )(implicit loggingContext: LoggingContext): Future[PersistenceResponse] = @@ -296,7 +296,7 @@ private class JdbcLedgerDao( offset, completionInfo.map(info => state.Update.CommandRejected( - recordTime = Time.Timestamp.assertFromInstant(recordTime), + recordTime = recordTime, completionInfo = info, reasonTemplate = reason, ) @@ -335,8 +335,7 @@ private class JdbcLedgerDao( state.Update.TransactionAccepted( optCompletionInfo = completionInfo, transactionMeta = state.TransactionMeta( - ledgerEffectiveTime = - Time.Timestamp.assertFromInstant(tx.ledgerEffectiveTime), + ledgerEffectiveTime = tx.ledgerEffectiveTime, workflowId = tx.workflowId, submissionTime = null, // not used for DbDto generation submissionSeed = null, // not used for DbDto generation @@ -346,7 +345,7 @@ private class JdbcLedgerDao( ), transaction = tx.transaction, transactionId = tx.transactionId, - recordTime = Time.Timestamp.assertFromInstant(tx.recordedAt), + recordTime = tx.recordedAt, divulgedContracts = Nil, blindingInfo = None, ) @@ -365,7 +364,7 @@ private class JdbcLedgerDao( offset, Some( state.Update.CommandRejected( - recordTime = Time.Timestamp.assertFromInstant(recordTime), + recordTime = recordTime, completionInfo = state .CompletionInfo(actAs, applicationId, commandId, None, Some(submissionId)), reasonTemplate = reason.toParticipantStateRejectionReason, @@ -438,13 +437,11 @@ private class JdbcLedgerDao( sourceDescription = packages.headOption.flatMap( _._2.sourceDescription ), - recordTime = Time.Timestamp.assertFromInstant( - packages.headOption - .map( - _._2.knownSince - ) - .getOrElse(Instant.EPOCH) - ), + recordTime = packages.headOption + .map( + _._2.knownSince + ) + .getOrElse(Timestamp.Epoch), submissionId = None, // If the submission ID is missing, this update will not insert a row in the package_entries table ) @@ -455,14 +452,14 @@ private class JdbcLedgerDao( sourceDescription = packages.headOption.flatMap( _._2.sourceDescription ), - recordTime = Time.Timestamp.assertFromInstant(recordTime), + recordTime = recordTime, submissionId = Some(submissionId), ) case Some(PackageLedgerEntry.PackageUploadRejected(submissionId, recordTime, reason)) => state.Update.PublicPackageUploadRejected( submissionId = submissionId, - recordTime = Time.Timestamp.assertFromInstant(recordTime), + recordTime = recordTime, rejectionReason = reason, ) } @@ -491,8 +488,8 @@ private class JdbcLedgerDao( override def deduplicateCommand( commandId: domain.CommandId, submitters: List[Ref.Party], - submittedAt: Instant, - deduplicateUntil: Instant, + submittedAt: Timestamp, + deduplicateUntil: Timestamp, )(implicit loggingContext: LoggingContext): Future[CommandDeduplicationResult] = dbDispatcher.executeSql(metrics.daml.index.db.deduplicateCommandDbMetrics) { conn => val key = DeduplicationKeyMaker.make(commandId, submitters) @@ -513,7 +510,7 @@ private class JdbcLedgerDao( } override def removeExpiredDeduplicationData( - currentTime: Instant + currentTime: Timestamp )(implicit loggingContext: LoggingContext): Future[Unit] = dbDispatcher.executeSql(metrics.daml.index.db.removeExpiredDeduplicationDataDbMetrics)( storageBackend.removeExpiredDeduplicationData(currentTime) @@ -658,12 +655,12 @@ private class JdbcLedgerDao( completionInfo: Option[state.CompletionInfo], workflowId: Option[Ref.WorkflowId], transactionId: Ref.TransactionId, - ledgerEffectiveTime: Instant, + ledgerEffectiveTime: Timestamp, offset: Offset, transaction: CommittedTransaction, divulgedContracts: Iterable[state.DivulgedContract], blindingInfo: Option[BlindingInfo], - recordTime: Instant, + recordTime: Timestamp, )(implicit loggingContext: LoggingContext): Future[PersistenceResponse] = { logger.info("Storing transaction") dbDispatcher @@ -677,7 +674,7 @@ private class JdbcLedgerDao( state.Update.TransactionAccepted( optCompletionInfo = completionInfo, transactionMeta = state.TransactionMeta( - ledgerEffectiveTime = Time.Timestamp.assertFromInstant(ledgerEffectiveTime), + ledgerEffectiveTime = ledgerEffectiveTime, workflowId = workflowId, submissionTime = null, // not used for DbDto generation submissionSeed = null, // not used for DbDto generation @@ -687,7 +684,7 @@ private class JdbcLedgerDao( ), transaction = transaction, transactionId = transactionId, - recordTime = Time.Timestamp.assertFromInstant(recordTime), + recordTime = recordTime, divulgedContracts = divulgedContracts.toList, blindingInfo = blindingInfo, ) @@ -696,7 +693,7 @@ private class JdbcLedgerDao( case Some(reason) => completionInfo.map(info => state.Update.CommandRejected( - recordTime = Time.Timestamp.assertFromInstant(recordTime), + recordTime = recordTime, completionInfo = info, reasonTemplate = reason.toStateV2RejectionReason, ) diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/LedgerDao.scala b/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/LedgerDao.scala index ef19fc09b207..73339b8c8aa4 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/LedgerDao.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/LedgerDao.scala @@ -21,6 +21,7 @@ import com.daml.ledger.offset.Offset import com.daml.ledger.participant.state.index.v2.{CommandDeduplicationResult, PackageDetails} import com.daml.ledger.participant.state.{v2 => state} import com.daml.lf.data.Ref +import com.daml.lf.data.Time.Timestamp import com.daml.lf.transaction.{BlindingInfo, CommittedTransaction} import com.daml.logging.LoggingContext import com.daml.platform.store.appendonlydao.events.{ContractStateEvent, FilterRelation} @@ -32,7 +33,6 @@ import com.daml.platform.store.entries.{ } import com.daml.platform.store.interfaces.{LedgerDaoContractsReader, TransactionLogUpdate} -import java.time.Instant import scala.concurrent.Future private[platform] trait LedgerDaoTransactionsReader { @@ -185,8 +185,8 @@ private[platform] trait LedgerReadDao extends ReportsHealth { def deduplicateCommand( commandId: CommandId, submitters: List[Ref.Party], - submittedAt: Instant, - deduplicateUntil: Instant, + submittedAt: Timestamp, + deduplicateUntil: Timestamp, )(implicit loggingContext: LoggingContext): Future[CommandDeduplicationResult] /** Remove all expired deduplication entries. This method has to be called @@ -200,7 +200,7 @@ private[platform] trait LedgerReadDao extends ReportsHealth { * call deduplicateCommand(). */ def removeExpiredDeduplicationData( - currentTime: Instant + currentTime: Timestamp )(implicit loggingContext: LoggingContext): Future[Unit] /** Stops deduplicating the given command. This method should be called after @@ -251,7 +251,7 @@ private[platform] trait LedgerWriteDao extends ReportsHealth { def storeRejection( completionInfo: Option[state.CompletionInfo], - recordTime: Instant, + recordTime: Timestamp, offset: Offset, reason: state.Update.CommandRejected.RejectionReasonTemplate, )(implicit loggingContext: LoggingContext): Future[PersistenceResponse] @@ -283,7 +283,7 @@ private[platform] trait LedgerWriteDao extends ReportsHealth { */ def storeConfigurationEntry( offset: Offset, - recordedAt: Instant, + recordedAt: Timestamp, submissionId: String, configuration: Configuration, rejectionReason: Option[String], @@ -307,12 +307,12 @@ private[platform] trait LedgerWriteDao extends ReportsHealth { completionInfo: Option[state.CompletionInfo], workflowId: Option[Ref.WorkflowId], transactionId: Ref.TransactionId, - ledgerEffectiveTime: Instant, + ledgerEffectiveTime: Timestamp, offset: Offset, transaction: CommittedTransaction, divulgedContracts: Iterable[state.DivulgedContract], blindingInfo: Option[BlindingInfo], - recordTime: Instant, + recordTime: Timestamp, )(implicit loggingContext: LoggingContext): Future[PersistenceResponse] } diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/MeteredLedgerDao.scala b/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/MeteredLedgerDao.scala index 8bb07a50914e..bc7d13df48fd 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/MeteredLedgerDao.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/MeteredLedgerDao.scala @@ -13,6 +13,7 @@ import com.daml.ledger.offset.Offset import com.daml.ledger.participant.state.index.v2.{CommandDeduplicationResult, PackageDetails} import com.daml.ledger.participant.state.{v2 => state} import com.daml.lf.data.Ref +import com.daml.lf.data.Time.Timestamp import com.daml.lf.transaction.{BlindingInfo, CommittedTransaction} import com.daml.logging.LoggingContext import com.daml.metrics.{Metrics, Timed} @@ -24,7 +25,6 @@ import com.daml.platform.store.entries.{ } import com.daml.platform.store.interfaces.LedgerDaoContractsReader -import java.time.Instant import scala.concurrent.Future private[platform] class MeteredLedgerReadDao(ledgerDao: LedgerReadDao, metrics: Metrics) @@ -113,15 +113,15 @@ private[platform] class MeteredLedgerReadDao(ledgerDao: LedgerReadDao, metrics: override def deduplicateCommand( commandId: CommandId, submitters: List[Ref.Party], - submittedAt: Instant, - deduplicateUntil: Instant, + submittedAt: Timestamp, + deduplicateUntil: Timestamp, )(implicit loggingContext: LoggingContext): Future[CommandDeduplicationResult] = Timed.future( metrics.daml.index.db.deduplicateCommand, ledgerDao.deduplicateCommand(commandId, submitters, submittedAt, deduplicateUntil), ) - override def removeExpiredDeduplicationData(currentTime: Instant)(implicit + override def removeExpiredDeduplicationData(currentTime: Timestamp)(implicit loggingContext: LoggingContext ): Future[Unit] = Timed.future( @@ -154,7 +154,7 @@ private[platform] class MeteredLedgerDao(ledgerDao: LedgerDao, metrics: Metrics) override def storeRejection( completionInfo: Option[state.CompletionInfo], - recordTime: Instant, + recordTime: Timestamp, offset: Offset, reason: state.Update.CommandRejected.RejectionReasonTemplate, )(implicit loggingContext: LoggingContext): Future[PersistenceResponse] = @@ -192,7 +192,7 @@ private[platform] class MeteredLedgerDao(ledgerDao: LedgerDao, metrics: Metrics) override def storeConfigurationEntry( offset: Offset, - recordTime: Instant, + recordTime: Timestamp, submissionId: String, configuration: Configuration, rejectionReason: Option[String], @@ -225,12 +225,12 @@ private[platform] class MeteredLedgerDao(ledgerDao: LedgerDao, metrics: Metrics) completionInfo: Option[state.CompletionInfo], workflowId: Option[Ref.WorkflowId], transactionId: Ref.TransactionId, - ledgerEffectiveTime: Instant, + ledgerEffectiveTime: Timestamp, offset: Offset, transaction: CommittedTransaction, divulgedContracts: Iterable[state.DivulgedContract], blindingInfo: Option[BlindingInfo], - recordTime: Instant, + recordTime: Timestamp, )(implicit loggingContext: LoggingContext): Future[PersistenceResponse] = Timed.future( metrics.daml.index.db.storeTransactionCombined, diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/events/ContractStateEvent.scala b/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/events/ContractStateEvent.scala index 7c6e255a517d..a7631d6d8471 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/events/ContractStateEvent.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/events/ContractStateEvent.scala @@ -4,8 +4,7 @@ package com.daml.platform.store.appendonlydao.events import com.daml.ledger.offset.Offset - -import java.time.Instant +import com.daml.lf.data.Time.Timestamp sealed trait ContractStateEvent extends Product with Serializable { def eventOffset: Offset @@ -16,7 +15,7 @@ object ContractStateEvent { contractId: ContractId, contract: Contract, globalKey: Option[Key], - ledgerEffectiveTime: Instant, + ledgerEffectiveTime: Timestamp, stakeholders: Set[Party], eventOffset: Offset, eventSequentialId: Long, diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/events/ContractsReader.scala b/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/events/ContractsReader.scala index 608d95a8596e..fb381f15b23a 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/events/ContractsReader.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/events/ContractsReader.scala @@ -4,9 +4,8 @@ package com.daml.platform.store.appendonlydao.events import java.io.ByteArrayInputStream -import java.time.Instant - 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.interfaces.LedgerDaoContractsReader._ @@ -27,7 +26,7 @@ private[appendonlydao] 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 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 41a0b9276f83..9f3004ac9505 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,8 +3,7 @@ package com.daml.platform.store.appendonlydao.events -import java.time.Instant - +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.{ @@ -19,10 +18,10 @@ import com.daml.ledger.api.v1.transaction_service.{ GetTransactionsResponse, } import com.daml.ledger.offset.Offset +import com.daml.lf.data.Time.Timestamp import com.daml.platform.ApiOffset import com.daml.platform.api.v1.event.EventOps.{EventOps, TreeEventOps} import com.daml.platform.index.TransactionConversion -import com.google.protobuf.timestamp.Timestamp // TODO append-only: FIXME: move to the right place object EventsTable { @@ -32,7 +31,7 @@ object EventsTable { transactionId: String, nodeIndex: Int, eventSequentialId: Long, - ledgerEffectiveTime: Instant, + ledgerEffectiveTime: Timestamp, commandId: String, workflowId: String, event: E, @@ -40,9 +39,6 @@ object EventsTable { object Entry { - private def instantToTimestamp(t: Instant): Timestamp = - Timestamp(seconds = t.getEpochSecond, nanos = t.getNano) - private def flatTransaction(events: Vector[Entry[Event]]): Option[ApiTransaction] = events.headOption.flatMap { first => val flatEvents = @@ -55,7 +51,7 @@ object EventsTable { ApiTransaction( transactionId = first.transactionId, commandId = first.commandId, - effectiveAt = Some(instantToTimestamp(first.ledgerEffectiveTime)), + effectiveAt = Some(TimestampConversion.fromLf(first.ledgerEffectiveTime)), workflowId = first.workflowId, offset = ApiOffset.toApiString(first.eventOffset), events = flatEvents, @@ -128,7 +124,7 @@ object EventsTable { transactionId = first.transactionId, commandId = first.commandId, workflowId = first.workflowId, - effectiveAt = Some(instantToTimestamp(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 2830523907e7..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,10 +4,9 @@ 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 import com.daml.lf.transaction.CommittedTransaction import com.daml.platform.store.appendonlydao.events.PostCommitValidation._ import com.daml.platform.store.backend.{ContractStorageBackend, PartyStorageBackend} @@ -31,7 +30,7 @@ private[appendonlydao] sealed trait PostCommitValidation { def validate( transaction: CommittedTransaction, - transactionLedgerEffectiveTime: Instant, + transactionLedgerEffectiveTime: Timestamp, divulged: Set[ContractId], )(implicit connection: Connection): Option[Rejection] @@ -47,7 +46,7 @@ private[appendonlydao] object PostCommitValidation { object Skip extends PostCommitValidation { @inline override def validate( committedTransaction: CommittedTransaction, - transactionLedgerEffectiveTime: Instant, + transactionLedgerEffectiveTime: Timestamp, divulged: Set[ContractId], )(implicit connection: Connection): Option[Rejection] = None @@ -60,7 +59,7 @@ private[appendonlydao] object PostCommitValidation { def validate( transaction: CommittedTransaction, - transactionLedgerEffectiveTime: Instant, + transactionLedgerEffectiveTime: Timestamp, divulged: Set[ContractId], )(implicit connection: Connection): Option[Rejection] = { @@ -84,7 +83,7 @@ private[appendonlydao] object PostCommitValidation { */ private def validateCausalMonotonicity( transaction: CommittedTransaction, - transactionLedgerEffectiveTime: Instant, + transactionLedgerEffectiveTime: Timestamp, divulged: Set[ContractId], )(implicit connection: Connection): Option[Rejection] = { val referredContracts = collectReferredContracts(transaction, divulged) @@ -99,11 +98,11 @@ private[appendonlydao] object PostCommitValidation { } private def validateCausalMonotonicity( - maximumLedgerEffectiveTime: Option[Instant], - transactionLedgerEffectiveTime: Instant, + maximumLedgerEffectiveTime: Option[Timestamp], + transactionLedgerEffectiveTime: Timestamp, ): Option[Rejection] = maximumLedgerEffectiveTime - .filter(_.isAfter(transactionLedgerEffectiveTime)) + .filter(_ > transactionLedgerEffectiveTime) .fold(Option.empty[Rejection])(contractLedgerEffectiveTime => { Some( Rejection.CausalMonotonicityViolation( @@ -324,8 +323,8 @@ private[appendonlydao] object PostCommitValidation { } final case class CausalMonotonicityViolation( - contractLedgerEffectiveTime: Instant, - transactionLedgerEffectiveTime: Instant, + contractLedgerEffectiveTime: Timestamp, + transactionLedgerEffectiveTime: Timestamp, ) extends Rejection { override lazy val description: String = s"Encountered contract with LET [$contractLedgerEffectiveTime] greater than the LET of the transaction [$transactionLedgerEffectiveTime]" diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/events/TransactionLogUpdatesConversions.scala b/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/events/TransactionLogUpdatesConversions.scala index ec072e0d2e08..f2854cde8e95 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/events/TransactionLogUpdatesConversions.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/appendonlydao/events/TransactionLogUpdatesConversions.scala @@ -3,7 +3,7 @@ package com.daml.platform.store.appendonlydao.events -import java.time.Instant +import com.daml.api.util.TimestampConversion.fromInstant import com.daml.ledger.api.v1.event.Event import com.daml.ledger.api.v1.transaction.{ @@ -60,7 +60,7 @@ private[events] object TransactionLogUpdatesConversions { transactionId = first.transactionId, commandId = getCommandId(events, requestingParties), workflowId = first.workflowId, - effectiveAt = Some(instantToTimestamp(first.ledgerEffectiveTime)), + effectiveAt = Some(timestampToTimestamp(first.ledgerEffectiveTime)), events = flatEvents, offset = ApiOffset.toApiString(tx.offset), ) @@ -227,7 +227,7 @@ private[events] object TransactionLogUpdatesConversions { transactionId = tx.transactionId, commandId = getCommandId(filteredForVisibility, requestingParties), workflowId = tx.workflowId, - effectiveAt = Some(instantToTimestamp(tx.effectiveAt)), + effectiveAt = Some(timestampToTimestamp(tx.effectiveAt)), offset = ApiOffset.toApiString(tx.offset), eventsById = eventsById, rootEventIds = rootEventIds, @@ -389,8 +389,8 @@ private[events] object TransactionLogUpdatesConversions { } } - private def instantToTimestamp(t: Instant): Timestamp = - Timestamp(seconds = t.getEpochSecond, nanos = t.getNano) + private def timestampToTimestamp(t: com.daml.lf.data.Time.Timestamp): Timestamp = + fromInstant(t.toInstant) private def getCommandId( flatTransactionEvents: Vector[TransactionLogUpdate.Event], diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/backend/StorageBackend.scala b/ledger/participant-integration-api/src/main/scala/platform/store/backend/StorageBackend.scala index 531a44e7b4ff..01b52d3b8655 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/backend/StorageBackend.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/backend/StorageBackend.scala @@ -4,14 +4,13 @@ package com.daml.platform.store.backend import java.sql.Connection -import java.time.Instant - import com.daml.ledger.api.domain.{LedgerId, ParticipantId, PartyDetails} import com.daml.ledger.api.v1.command_completion_service.CompletionStreamResponse import com.daml.ledger.configuration.Configuration import com.daml.ledger.offset.Offset import com.daml.ledger.participant.state.index.v2.PackageDetails import com.daml.lf.data.Ref +import com.daml.lf.data.Time.Timestamp import com.daml.lf.ledger.EventId import com.daml.logging.LoggingContext import com.daml.platform @@ -25,8 +24,8 @@ import com.daml.platform.store.backend.postgresql.{PostgresDataSourceConfig, Pos import com.daml.platform.store.entries.{ConfigurationEntry, PackageLedgerEntry, PartyLedgerEntry} import com.daml.platform.store.interfaces.LedgerDaoContractsReader.KeyState import com.daml.scalautil.NeverEqualsOverride -import javax.sql.DataSource +import javax.sql.DataSource import scala.annotation.unused import scala.util.Try @@ -192,13 +191,13 @@ trait PackageStorageBackend { } trait DeduplicationStorageBackend { - def deduplicatedUntil(deduplicationKey: String)(connection: Connection): Instant + def deduplicatedUntil(deduplicationKey: String)(connection: Connection): Timestamp def upsertDeduplicationEntry( key: String, - submittedAt: Instant, - deduplicateUntil: Instant, + submittedAt: Timestamp, + deduplicateUntil: Timestamp, )(connection: Connection)(implicit loggingContext: LoggingContext): Int - def removeExpiredDeduplicationData(currentTime: Instant)(connection: Connection): Unit + def removeExpiredDeduplicationData(currentTime: Timestamp)(connection: Connection): Unit def stopDeduplicatingCommand(deduplicationKey: String)(connection: Connection): Unit } @@ -219,7 +218,7 @@ trait CompletionStorageBackend { trait ContractStorageBackend { def contractKeyGlobally(key: Key)(connection: Connection): Option[ContractId] - def maximumLedgerTime(ids: Set[ContractId])(connection: Connection): Try[Option[Instant]] + def maximumLedgerTime(ids: Set[ContractId])(connection: Connection): Try[Option[Timestamp]] def keyState(key: Key, validAt: Long)(connection: Connection): KeyState def contractState(contractId: ContractId, before: Long)( connection: Connection @@ -359,7 +358,7 @@ object StorageBackend { createArgument: Option[Array[Byte]], createArgumentCompression: Option[Int], eventKind: Int, - ledgerEffectiveTime: Option[Instant], + ledgerEffectiveTime: Option[Timestamp], ) class RawContract( @@ -372,7 +371,7 @@ object StorageBackend { eventKind: Int, contractId: ContractId, templateId: Option[Ref.Identifier], - ledgerEffectiveTime: Option[Instant], + ledgerEffectiveTime: Option[Timestamp], createKeyValue: Option[Array[Byte]], createKeyCompression: Option[Int], createArgument: Option[Array[Byte]], @@ -391,7 +390,7 @@ object StorageBackend { eventId: EventId, contractId: platform.store.appendonlydao.events.ContractId, templateId: Option[platform.store.appendonlydao.events.Identifier], - ledgerEffectiveTime: Option[Instant], + ledgerEffectiveTime: Option[Timestamp], createSignatories: Option[Array[String]], createObservers: Option[Array[String]], createAgreementText: Option[String], diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/CompletionStorageBackendTemplate.scala b/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/CompletionStorageBackendTemplate.scala index 49dd622ffea4..d02c883aad53 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/CompletionStorageBackendTemplate.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/CompletionStorageBackendTemplate.scala @@ -4,18 +4,17 @@ package com.daml.platform.store.backend.common import java.sql.Connection -import java.time.Instant - import anorm.SqlParser.{byteArray, int, long, str} import anorm.{Row, RowParser, SimpleSql, ~} import com.daml.ledger.api.v1.command_completion_service.CompletionStreamResponse import com.daml.ledger.offset.Offset import com.daml.lf.data.Ref import com.daml.lf.data.Ref.Party +import com.daml.lf.data.Time.Timestamp import com.daml.logging.{ContextualizedLogger, LoggingContext} import com.daml.platform.index.index.StatusDetails import com.daml.platform.store.CompletionFromTransaction -import com.daml.platform.store.Conversions.{instantFromMicros, offset} +import com.daml.platform.store.Conversions.{offset, timestampFromMicros} import com.daml.platform.store.backend.CompletionStorageBackend import com.daml.platform.store.backend.common.ComposableQuery.SqlStringInterpolation import com.google.protobuf.any @@ -62,15 +61,15 @@ trait CompletionStorageBackendTemplate extends CompletionStorageBackend { .as(completionParser.*)(connection) } - private val sharedColumns: RowParser[Offset ~ Instant ~ String ~ String ~ Option[String]] = + private val sharedColumns: RowParser[Offset ~ Timestamp ~ String ~ String ~ Option[String]] = offset("completion_offset") ~ - instantFromMicros("record_time") ~ + timestampFromMicros("record_time") ~ str("command_id") ~ str("application_id") ~ str("submission_id").? private val acceptedCommandSharedColumns - : RowParser[Offset ~ Instant ~ String ~ String ~ Option[String] ~ String] = + : RowParser[Offset ~ Timestamp ~ String ~ String ~ Option[String] ~ String] = sharedColumns ~ str("transaction_id") private val deduplicationOffsetColumn: RowParser[Option[String]] = @@ -79,8 +78,8 @@ trait CompletionStorageBackendTemplate extends CompletionStorageBackend { long("deduplication_duration_seconds").? private val deduplicationDurationNanosColumn: RowParser[Option[Int]] = int("deduplication_duration_nanos").? - private val deduplicationStartColumn: RowParser[Option[Instant]] = - instantFromMicros("deduplication_start").? + private val deduplicationStartColumn: RowParser[Option[Timestamp]] = + timestampFromMicros("deduplication_start").? private val acceptedCommandParser: RowParser[CompletionStreamResponse] = acceptedCommandSharedColumns ~ 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 1a89ab263d5e..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 @@ -4,17 +4,16 @@ package com.daml.platform.store.backend.common import java.sql.Connection -import java.time.Instant - import anorm.SqlParser.{byteArray, int, long, str} import anorm.{ResultSetParser, Row, RowParser, SimpleSql, SqlParser, ~} import com.daml.lf.data.Ref +import com.daml.lf.data.Time.Timestamp import com.daml.platform.store.Conversions.{ contractId, flatEventWitnessesColumn, identifier, - instantFromMicros, offset, + timestampFromMicros, } import com.daml.platform.store.SimpleSqlAsVectorOf.SimpleSqlAsVectorOf import com.daml.platform.store.appendonlydao.events.{ContractId, Key} @@ -97,18 +96,20 @@ trait ContractStorageBackendTemplate extends ContractStorageBackend { // TODO append-only: consider pulling up traversal logic to upper layer override def maximumLedgerTime( ids: Set[ContractId] - )(connection: Connection): Try[Option[Instant]] = { + )(connection: Connection): Try[Option[Timestamp]] = { if (ids.isEmpty) { Failure(emptyContractIds) } else { - def lookup(id: ContractId): Option[Option[Instant]] = - maximumLedgerTimeSqlLiteral(id).as(instantFromMicros("ledger_effective_time").?.singleOpt)( + def lookup(id: ContractId): Option[Option[Timestamp]] = + maximumLedgerTimeSqlLiteral(id).as( + timestampFromMicros("ledger_effective_time").?.singleOpt + )( connection ) - val queriedIds: List[(ContractId, Option[Option[Instant]])] = ids.toList + val queriedIds: List[(ContractId, Option[Option[Timestamp]])] = ids.toList .map(id => id -> lookup(id)) - val foundLedgerEffectiveTimes: List[Option[Instant]] = queriedIds + val foundLedgerEffectiveTimes: List[Option[Timestamp]] = queriedIds .collect { case (_, Some(found)) => found } @@ -141,7 +142,8 @@ trait ContractStorageBackendTemplate extends ContractStorageBackend { ~ flatEventWitnessesColumn("flat_event_witnesses") ~ byteArray("create_argument").? ~ int("create_argument_compression").? - ~ int("event_kind") ~ instantFromMicros("ledger_effective_time").?) + ~ int("event_kind") + ~ timestampFromMicros("ledger_effective_time").?) .map(SqlParser.flatten) .map(StorageBackend.RawContractState.tupled) @@ -171,7 +173,7 @@ trait ContractStorageBackendTemplate extends ContractStorageBackend { (int("event_kind") ~ contractId("contract_id") ~ identifier("template_id").? ~ - instantFromMicros("ledger_effective_time").? ~ + timestampFromMicros("ledger_effective_time").? ~ byteArray("create_key_value").? ~ int("create_key_value_compression").? ~ byteArray("create_argument").? ~ 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 2401136f5d65..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 @@ -4,10 +4,9 @@ package com.daml.platform.store.backend.common import java.sql.Connection -import java.time.Instant - import anorm.{RowParser, SQL} -import com.daml.platform.store.Conversions.instantFromMicros +import com.daml.lf.data.Time.Timestamp +import com.daml.platform.store.Conversions.timestampFromMicros import com.daml.platform.store.backend.DeduplicationStorageBackend private[backend] trait DeduplicationStorageBackendTemplate extends DeduplicationStorageBackend { @@ -18,13 +17,13 @@ private[backend] trait DeduplicationStorageBackendTemplate extends Deduplication |where deduplication_key = {deduplicationKey} """.stripMargin) - private case class ParsedCommandData(deduplicateUntil: Instant) + private case class ParsedCommandData(deduplicateUntil: Timestamp) private val CommandDataParser: RowParser[ParsedCommandData] = - instantFromMicros("deduplicate_until") + timestampFromMicros("deduplicate_until") .map(ParsedCommandData) - def deduplicatedUntil(deduplicationKey: String)(connection: Connection): Instant = + override def deduplicatedUntil(deduplicationKey: String)(connection: Connection): Timestamp = SQL_SELECT_COMMAND .on("deduplicationKey" -> deduplicationKey) .as(CommandDataParser.single)(connection) @@ -35,9 +34,11 @@ private[backend] trait DeduplicationStorageBackendTemplate extends Deduplication |where deduplicate_until < {currentTime} """.stripMargin) - def removeExpiredDeduplicationData(currentTime: Instant)(connection: Connection): Unit = { + override def removeExpiredDeduplicationData( + currentTime: Timestamp + )(connection: Connection): Unit = { SQL_DELETE_EXPIRED_COMMANDS - .on("currentTime" -> Timestamp.instantToMicros(currentTime)) + .on("currentTime" -> currentTime.micros) .execute()(connection) () } @@ -47,7 +48,7 @@ private[backend] trait DeduplicationStorageBackendTemplate extends Deduplication |where deduplication_key = {deduplicationKey} """.stripMargin) - def stopDeduplicatingCommand(deduplicationKey: String)(connection: Connection): Unit = { + override def stopDeduplicatingCommand(deduplicationKey: String)(connection: Connection): Unit = { SQL_DELETE_COMMAND .on("deduplicationKey" -> deduplicationKey) .execute()(connection) 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 1c7ae079e680..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 @@ -4,18 +4,18 @@ package com.daml.platform.store.backend.common import java.sql.Connection -import java.time.Instant import anorm.SqlParser.{array, bool, byteArray, int, long, str} import anorm.{Row, RowParser, SimpleSql, ~} import com.daml.ledger.offset.Offset import com.daml.lf.data.Ref +import com.daml.lf.data.Time.Timestamp import com.daml.logging.{ContextualizedLogger, LoggingContext} import com.daml.platform.store.Conversions.{ contractId, eventId, identifier, - instantFromMicros, offset, + timestampFromMicros, } import com.daml.platform.store.SimpleSqlAsVectorOf.SimpleSqlAsVectorOf import com.daml.platform.store.appendonlydao.events.{EventsTable, Identifier, Raw} @@ -60,7 +60,7 @@ trait EventStorageBackendTemplate extends EventStorageBackend { ).mkString(", ") private type SharedRow = - Offset ~ String ~ Int ~ Long ~ String ~ String ~ Instant ~ Identifier ~ Option[String] ~ + Offset ~ String ~ Int ~ Long ~ String ~ String ~ Timestamp ~ Identifier ~ Option[String] ~ Option[String] ~ Array[String] private val sharedRow: RowParser[SharedRow] = @@ -70,7 +70,7 @@ trait EventStorageBackendTemplate extends EventStorageBackend { long("event_sequential_id") ~ str("event_id") ~ str("contract_id") ~ - instantFromMicros("ledger_effective_time") ~ + timestampFromMicros("ledger_effective_time") ~ identifier("template_id") ~ str("command_id").? ~ str("workflow_id").? ~ @@ -516,7 +516,7 @@ trait EventStorageBackendTemplate extends EventStorageBackend { eventId("event_id") ~ contractId("contract_id") ~ identifier("template_id").? ~ - instantFromMicros("ledger_effective_time").? ~ + timestampFromMicros("ledger_effective_time").? ~ array[String]("create_signatories").? ~ array[String]("create_observers").? ~ str("create_agreement_text").? ~ 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 25cf101327b5..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,8 +5,6 @@ package com.daml.platform.store.backend.common import java.lang import java.sql.PreparedStatement -import java.time.Instant -import java.util.concurrent.TimeUnit import scala.reflect.ClassTag @@ -92,11 +90,6 @@ private[backend] case class BooleanOptional[FROM](extract: FROM => Option[Boolea override def convert: Option[Boolean] => lang.Boolean = _.map(Boolean.box).orNull } -private[backend] object Timestamp { - def instantToMicros(i: Instant): Long = - TimeUnit.SECONDS.toMicros(i.getEpochSecond) + TimeUnit.NANOSECONDS.toMicros(i.getNano.toLong) -} - private[backend] case class StringArray[FROM](extract: FROM => Iterable[String]) extends Field[FROM, Iterable[String], Array[String]] { override def convert: Iterable[String] => Array[String] = _.toArray 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 3ce057df31d8..39294535215d 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 @@ -9,8 +9,9 @@ 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} +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 import com.daml.platform.store.appendonlydao.JdbcLedgerDao.{acceptType, rejectType} import com.daml.platform.store.backend.PackageStorageBackend @@ -47,7 +48,7 @@ private[backend] trait PackageStorageBackendTemplate extends PackageStorageBacke .map(d => PackageId.assertFromString(d.packageId) -> PackageDetails( d.size, - instantFromMicros(d.knownSince), + Timestamp.assertFromLong(d.knownSince), d.sourceDescription, ) ) @@ -80,7 +81,7 @@ private[backend] trait PackageStorageBackendTemplate extends PackageStorageBacke private val packageEntryParser: RowParser[(Offset, PackageLedgerEntry)] = (offset("ledger_offset") ~ - instantFromMicros("recorded_at") ~ + timestampFromMicros("recorded_at") ~ ledgerString("submission_id").? ~ str("typ") ~ str("rejection_reason").?) diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/PartyStorageBackendTemplate.scala b/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/PartyStorageBackendTemplate.scala index 83cface29a3f..51c0bb19bbf6 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/PartyStorageBackendTemplate.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/PartyStorageBackendTemplate.scala @@ -10,7 +10,7 @@ import anorm.SqlParser.{bool, flatten, str} import com.daml.ledger.api.domain.PartyDetails import com.daml.ledger.offset.Offset import com.daml.lf.data.Ref -import com.daml.platform.store.Conversions.{ledgerString, instantFromMicros, offset, party} +import com.daml.platform.store.Conversions.{ledgerString, offset, party, timestampFromMicros} import com.daml.platform.store.SimpleSqlAsVectorOf.SimpleSqlAsVectorOf import com.daml.platform.store.appendonlydao.JdbcLedgerDao.{acceptType, rejectType} import com.daml.platform.store.backend.PartyStorageBackend @@ -32,7 +32,7 @@ trait PartyStorageBackendTemplate extends PartyStorageBackend { private val partyEntryParser: RowParser[(Offset, PartyLedgerEntry)] = { import com.daml.platform.store.Conversions.bigDecimalColumnToBoolean (offset("ledger_offset") ~ - instantFromMicros("recorded_at") ~ + timestampFromMicros("recorded_at") ~ ledgerString("submission_id").? ~ party("party").? ~ str("display_name").? ~ diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/backend/h2/H2StorageBackend.scala b/ledger/participant-integration-api/src/main/scala/platform/store/backend/h2/H2StorageBackend.scala index 54d4a1564e7e..879915a66642 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/backend/h2/H2StorageBackend.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/backend/h2/H2StorageBackend.scala @@ -4,11 +4,11 @@ package com.daml.platform.store.backend.h2 import java.sql.Connection -import java.time.Instant import anorm.{Row, SQL, SimpleSql} import anorm.SqlParser.get import com.daml.ledger.offset.Offset import com.daml.lf.data.Ref +import com.daml.lf.data.Time.Timestamp import com.daml.logging.{ContextualizedLogger, LoggingContext} import com.daml.platform.store.appendonlydao.events.ContractId import com.daml.platform.store.backend.EventStorageBackend.FilterParams @@ -19,17 +19,16 @@ import com.daml.platform.store.backend.common.{ ConfigurationStorageBackendTemplate, ContractStorageBackendTemplate, DataSourceStorageBackendTemplate, - IntegrityStorageBackendTemplate, DeduplicationStorageBackendTemplate, EventStorageBackendTemplate, EventStrategy, IngestionStorageBackendTemplate, InitHookDataSourceProxy, + IntegrityStorageBackendTemplate, PackageStorageBackendTemplate, ParameterStorageBackendTemplate, PartyStorageBackendTemplate, QueryStrategy, - Timestamp, } import com.daml.platform.store.backend.{ DBLockStorageBackend, @@ -104,8 +103,8 @@ private[backend] object H2StorageBackend override def upsertDeduplicationEntry( key: String, - submittedAt: Instant, - deduplicateUntil: Instant, + submittedAt: Timestamp, + deduplicateUntil: Timestamp, )(connection: Connection)(implicit loggingContext: LoggingContext): Int = { // Under the default READ_COMMITTED isolation level used for the indexdb, when a deduplication @@ -124,8 +123,8 @@ private[backend] object H2StorageBackend SQL(SQL_INSERT_COMMAND) .on( "deduplicationKey" -> key, - "submittedAt" -> Timestamp.instantToMicros(submittedAt), - "deduplicateUntil" -> Timestamp.instantToMicros(deduplicateUntil), + "submittedAt" -> submittedAt.micros, + "deduplicateUntil" -> deduplicateUntil.micros, ) .executeUpdate()(connection) ) 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 043e27e0b2bd..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 @@ -12,17 +12,16 @@ import com.daml.platform.store.backend.common.{ ConfigurationStorageBackendTemplate, ContractStorageBackendTemplate, DataSourceStorageBackendTemplate, - IntegrityStorageBackendTemplate, DeduplicationStorageBackendTemplate, EventStorageBackendTemplate, EventStrategy, IngestionStorageBackendTemplate, InitHookDataSourceProxy, + IntegrityStorageBackendTemplate, PackageStorageBackendTemplate, ParameterStorageBackendTemplate, PartyStorageBackendTemplate, QueryStrategy, - Timestamp, } import com.daml.platform.store.backend.{ DBLockStorageBackend, @@ -33,8 +32,8 @@ 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 import com.daml.logging.{ContextualizedLogger, LoggingContext} import com.daml.platform.store.backend.common.ComposableQuery.{CompositeSql, SqlStringInterpolation} @@ -100,8 +99,8 @@ private[backend] object OracleStorageBackend override def upsertDeduplicationEntry( key: String, - submittedAt: Instant, - deduplicateUntil: Instant, + submittedAt: Timestamp, + deduplicateUntil: Timestamp, )(connection: Connection)(implicit loggingContext: LoggingContext): Int = { // Under the default READ_COMMITTED isolation level used for the indexdb, when a deduplication @@ -120,8 +119,8 @@ private[backend] object OracleStorageBackend SQL(SQL_INSERT_COMMAND) .on( "deduplicationKey" -> key, - "submittedAt" -> Timestamp.instantToMicros(submittedAt), - "deduplicateUntil" -> Timestamp.instantToMicros(deduplicateUntil), + "submittedAt" -> submittedAt.micros, + "deduplicateUntil" -> deduplicateUntil.micros, ) .executeUpdate()(connection) ) 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 0fb1ce24b05f..4fae9dfbc759 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,12 +4,12 @@ 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.error.NoLogging import com.daml.ledger.offset.Offset import com.daml.lf.data.Ref +import com.daml.lf.data.Time.Timestamp import com.daml.logging.{ContextualizedLogger, LoggingContext} import com.daml.platform.server.api.validation.ErrorFactories import com.daml.platform.store.appendonlydao.events.Party @@ -31,7 +31,6 @@ import com.daml.platform.store.backend.common.{ ParameterStorageBackendTemplate, PartyStorageBackendTemplate, QueryStrategy, - Timestamp, } import com.daml.platform.store.backend.{ DBLockStorageBackend, @@ -79,14 +78,14 @@ private[backend] object PostgresStorageBackend override def upsertDeduplicationEntry( key: String, - submittedAt: Instant, - deduplicateUntil: Instant, + submittedAt: Timestamp, + deduplicateUntil: Timestamp, )(connection: Connection)(implicit loggingContext: LoggingContext): Int = SQL(SQL_INSERT_COMMAND) .on( "deduplicationKey" -> key, - "submittedAt" -> Timestamp.instantToMicros(submittedAt), - "deduplicateUntil" -> Timestamp.instantToMicros(deduplicateUntil), + "submittedAt" -> submittedAt.micros, + "deduplicateUntil" -> deduplicateUntil.micros, ) .executeUpdate()(connection) diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/cache/ContractsStateCache.scala b/ledger/participant-integration-api/src/main/scala/platform/store/cache/ContractsStateCache.scala index 55b63ed1ab88..e21b9a586729 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/cache/ContractsStateCache.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/cache/ContractsStateCache.scala @@ -2,9 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 package com.daml.platform.store.cache -import java.time.Instant - import com.daml.caching.SizedCache +import com.daml.lf.data.Time.Timestamp import com.daml.metrics.Metrics import scala.concurrent.ExecutionContext @@ -32,7 +31,7 @@ object ContractStateValue { final case class Active( contract: Contract, stakeholders: Set[Party], - createLedgerEffectiveTime: Instant, + createLedgerEffectiveTime: Timestamp, ) extends ExistingContractValue final case class Archived(stakeholders: Set[Party]) extends ExistingContractValue 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 281341aef3b0..952d2538b9fe 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 @@ -9,6 +9,7 @@ import akka.{Done, NotUsed} import com.daml.ledger.offset.Offset import com.daml.ledger.participant.state.index.v2.ContractStore import com.daml.ledger.resources.{Resource, ResourceContext, ResourceOwner} +import com.daml.lf.data.Time.Timestamp import com.daml.lf.transaction.GlobalKey import com.daml.logging.{ContextualizedLogger, LoggingContext} import com.daml.metrics.{Metrics, Timed} @@ -25,7 +26,6 @@ import com.daml.platform.store.interfaces.LedgerDaoContractsReader.{ KeyState, } -import java.time.Instant import java.util.concurrent.atomic.AtomicReference import scala.concurrent.duration.{DurationInt, FiniteDuration} import scala.concurrent.{ExecutionContext, Future} @@ -72,7 +72,7 @@ private[platform] class MutableCacheBackedContractStore( override def lookupMaximumLedgerTime(ids: Set[ContractId])(implicit loggingContext: LoggingContext - ): Future[Option[Instant]] = + ): Future[Option[Timestamp]] = if (ids.isEmpty) Future.failed(EmptyContractIds()) else { @@ -95,7 +95,7 @@ private[platform] class MutableCacheBackedContractStore( val cached = cacheQueried.view .map(_._2) - .foldLeft(Try(Set.empty[Instant])) { + .foldLeft(Try(Set.empty[Timestamp])) { case (Success(timestamps), Some(active: Active)) => Success(timestamps + active.createLedgerEffectiveTime) case (Success(_), Some(Archived(_))) => Failure(ContractNotFound(ids)) diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/cache/TranslationCacheBackedContractStore.scala b/ledger/participant-integration-api/src/main/scala/platform/store/cache/TranslationCacheBackedContractStore.scala index 03a86fd3b5bb..151a590b128d 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/cache/TranslationCacheBackedContractStore.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/cache/TranslationCacheBackedContractStore.scala @@ -3,10 +3,9 @@ package com.daml.platform.store.cache -import java.time.Instant - import com.daml.ledger.participant.state.index.v2.ContractStore import com.daml.ledger.resources.Resource +import com.daml.lf.data.Time.Timestamp import com.daml.logging.LoggingContext import com.daml.platform.store.LfValueTranslationCache import com.daml.platform.store.interfaces.LedgerDaoContractsReader @@ -44,7 +43,7 @@ class TranslationCacheBackedContractStore( */ override def lookupMaximumLedgerTime(ids: Set[ContractId])(implicit loggingContext: LoggingContext - ): Future[Option[Instant]] = + ): Future[Option[Timestamp]] = contractsReader.lookupMaximumLedgerTime(ids) } 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 45f21fe2ad9b..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,11 +3,10 @@ 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 +import com.daml.lf.data.Time.Timestamp import com.daml.lf.transaction.{CommittedTransaction, NodeId} private[platform] sealed abstract class LedgerEntry extends Product with Serializable @@ -15,7 +14,7 @@ private[platform] sealed abstract class LedgerEntry extends Product with Seriali private[platform] object LedgerEntry { final case class Rejection( - recordTime: Instant, + recordTime: Timestamp, commandId: Ref.CommandId, applicationId: Ref.ApplicationId, submissionId: Ref.SubmissionId, @@ -30,8 +29,8 @@ private[platform] object LedgerEntry { submissionId: Option[Ref.SubmissionId], actAs: List[Ref.Party], workflowId: Option[Ref.WorkflowId], - ledgerEffectiveTime: Instant, - recordedAt: Instant, + ledgerEffectiveTime: Timestamp, + recordedAt: Timestamp, transaction: CommittedTransaction, explicitDisclosure: Relation[NodeId, Ref.Party], ) extends LedgerEntry diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/entries/PackageLedgerEntry.scala b/ledger/participant-integration-api/src/main/scala/platform/store/entries/PackageLedgerEntry.scala index 13095f0b3c9a..193c160dc33e 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/entries/PackageLedgerEntry.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/entries/PackageLedgerEntry.scala @@ -3,10 +3,9 @@ package com.daml.platform.store.entries -import java.time.Instant - import com.daml.ledger.api.domain.PackageEntry import com.daml.lf.data.Ref +import com.daml.lf.data.Time.Timestamp private[platform] sealed abstract class PackageLedgerEntry extends Product with Serializable { def submissionId: Ref.SubmissionId @@ -18,7 +17,7 @@ private[platform] object PackageLedgerEntry { final case class PackageUploadAccepted( submissionId: Ref.SubmissionId, - recordTime: Instant, + recordTime: Timestamp, ) extends PackageLedgerEntry { override def toDomain: PackageEntry = PackageEntry.PackageUploadAccepted( @@ -29,7 +28,7 @@ private[platform] object PackageLedgerEntry { final case class PackageUploadRejected( submissionId: Ref.SubmissionId, - recordTime: Instant, + recordTime: Timestamp, reason: String, ) extends PackageLedgerEntry { override def toDomain: PackageEntry = diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/entries/PartyLedgerEntry.scala b/ledger/participant-integration-api/src/main/scala/platform/store/entries/PartyLedgerEntry.scala index 12c4ded437a1..201261ee06c3 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/entries/PartyLedgerEntry.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/entries/PartyLedgerEntry.scala @@ -3,27 +3,26 @@ package com.daml.platform.store.entries -import java.time.Instant - import com.daml.ledger.api.domain.PartyDetails import com.daml.lf.data.Ref +import com.daml.lf.data.Time.Timestamp private[platform] sealed abstract class PartyLedgerEntry() extends Product with Serializable { val submissionIdOpt: Option[Ref.SubmissionId] - val recordTime: Instant + val recordTime: Timestamp } private[platform] object PartyLedgerEntry { final case class AllocationAccepted( submissionIdOpt: Option[Ref.SubmissionId], - recordTime: Instant, + recordTime: Timestamp, partyDetails: PartyDetails, ) extends PartyLedgerEntry final case class AllocationRejected( submissionId: Ref.SubmissionId, - recordTime: Instant, + recordTime: Timestamp, reason: String, ) extends PartyLedgerEntry { override val submissionIdOpt: Option[Ref.SubmissionId] = Some(submissionId) 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 ebdd18b8f47b..305b80a9c31c 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,9 +3,8 @@ 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 import com.daml.logging.LoggingContext import com.daml.platform.store.interfaces.LedgerDaoContractsReader._ @@ -21,7 +20,7 @@ private[platform] trait LedgerDaoContractsReader { */ def lookupMaximumLedgerTime(ids: Set[ContractId])(implicit loggingContext: LoggingContext - ): Future[Option[Instant]] + ): Future[Option[Timestamp]] /** Looks up an active or divulged contract if it is visible for the given party. * @@ -94,7 +93,7 @@ object LedgerDaoContractsReader { final case class ActiveContract( contract: Contract, stakeholders: Set[Party], - ledgerEffectiveTime: Instant, + ledgerEffectiveTime: Timestamp, ) extends ContractState final case class ArchivedContract(stakeholders: Set[Party]) extends ContractState 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 bd68ecb37540..51f2fed4c90c 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,10 +3,10 @@ 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 +import com.daml.lf.data.Time.Timestamp import com.daml.lf.ledger.EventId import com.daml.platform.store.appendonlydao.events.{ContractId, Identifier} import com.daml.platform.store.cache.MutableCacheBackedContractStore.EventSequentialId @@ -33,7 +33,7 @@ object TransactionLogUpdate { final case class Transaction( transactionId: String, workflowId: String, - effectiveAt: Instant, + effectiveAt: Timestamp, offset: Offset, events: Vector[Event], ) extends TransactionLogUpdate { @@ -57,7 +57,7 @@ object TransactionLogUpdate { def eventId: EventId def commandId: String def workflowId: String - def ledgerEffectiveTime: Instant + def ledgerEffectiveTime: Timestamp def treeEventWitnesses: Set[String] def flatEventWitnesses: Set[String] def submitters: Set[String] @@ -72,7 +72,7 @@ object TransactionLogUpdate { eventSequentialId: Long, eventId: EventId, contractId: ContractId, - ledgerEffectiveTime: Instant, + ledgerEffectiveTime: Timestamp, templateId: Identifier, commandId: String, workflowId: String, @@ -93,7 +93,7 @@ object TransactionLogUpdate { eventSequentialId: Long, eventId: EventId, contractId: ContractId, - ledgerEffectiveTime: Instant, + ledgerEffectiveTime: Timestamp, templateId: Identifier, commandId: String, workflowId: String, 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..fab9d9f3e552 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 = submittedAt.addMicros(1000L) val n = 8 for { @@ -44,10 +44,11 @@ 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 = submittedAt.addMicros(1000L) + // Second submission is after the deduplication window of the first one + val submittedAt2 = Timestamp.assertFromLong(2000L) + val deduplicateUntil2 = submittedAt2.addMicros(1000L) val n = 8 for { @@ -76,10 +77,11 @@ 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 = submittedAt.addMicros(5000L) + // Second submission is within the deduplication window of the first one + val submittedAt2 = Timestamp.assertFromLong(1000L) + val deduplicateUntil2 = submittedAt2.addMicros(5000L) for { _ <- executeSql(backend.initializeParameters(someIdentityParams)) diff --git a/ledger/participant-integration-api/src/test/lib/scala/platform/store/backend/StorageBackendTestsTimestamps.scala b/ledger/participant-integration-api/src/test/lib/scala/platform/store/backend/StorageBackendTestsTimestamps.scala index 1f434ac0bf6a..a2bdf8917167 100644 --- a/ledger/participant-integration-api/src/test/lib/scala/platform/store/backend/StorageBackendTestsTimestamps.scala +++ b/ledger/participant-integration-api/src/test/lib/scala/platform/store/backend/StorageBackendTestsTimestamps.scala @@ -38,9 +38,9 @@ private[backend] trait StorageBackendTestsTimestamps extends Matchers with Stora let2 <- executeSql(withDefaultTimeZone("GMT-1")(backend.maximumLedgerTime(Set(cid)))) let3 <- executeSql(withDefaultTimeZone("GMT+1")(backend.maximumLedgerTime(Set(cid)))) } yield { - withClue("UTC") { let1 shouldBe Success(Some(let.toInstant)) } - withClue("GMT-1") { let2 shouldBe Success(Some(let.toInstant)) } - withClue("GMT+1") { let3 shouldBe Success(Some(let.toInstant)) } + withClue("UTC") { let1 shouldBe Success(Some(let)) } + withClue("GMT-1") { let2 shouldBe Success(Some(let)) } + withClue("GMT+1") { let3 shouldBe Success(Some(let)) } } } @@ -63,9 +63,9 @@ private[backend] trait StorageBackendTestsTimestamps extends Matchers with Stora events2 <- executeSql(withDefaultTimeZone("GMT-1")(backend.rawEvents(0L, 1L))) events3 <- executeSql(withDefaultTimeZone("GMT+1")(backend.rawEvents(0L, 1L))) } yield { - withClue("UTC") { events1.head.ledgerEffectiveTime shouldBe Some(let.toInstant) } - withClue("GMT-1") { events2.head.ledgerEffectiveTime shouldBe Some(let.toInstant) } - withClue("GMT+1") { events3.head.ledgerEffectiveTime shouldBe Some(let.toInstant) } + withClue("UTC") { events1.head.ledgerEffectiveTime shouldBe Some(let) } + withClue("GMT-1") { events2.head.ledgerEffectiveTime shouldBe Some(let) } + withClue("GMT+1") { events3.head.ledgerEffectiveTime shouldBe Some(let) } } } 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..417a16f72f64 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 @@ -11,6 +11,7 @@ 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 +98,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 d4a6d0b0adf7..0cde0cdf8b57 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(), offset, reason = reason, ) @@ -232,7 +232,7 @@ private[dao] trait JdbcLedgerDaoCompletionsSpec extends OptionValues with LoneEl submissionId = Some(submissionId), ) ), - recordTime = Instant.now, + recordTime = Timestamp.now(), 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 cc586f7d5359..e71c63e832b1 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, VersionedContractInstance, 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 391eefdc9ba2..1f2273001e4b 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,10 @@ 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 @@ -142,9 +142,9 @@ private[dao] trait JdbcLedgerDaoDivulgenceSpec extends LoneElement with Inside { arg = someContractInstance.arg, ) - 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 5aa520009a08..1447404f8739 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,7 +3,6 @@ package com.daml.platform.store.dao -import java.time.Instant import java.util.UUID import akka.stream.scaladsl.Sink @@ -12,6 +11,7 @@ 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.store.appendonlydao._ import com.daml.platform.store.entries.PackageLedgerEntry @@ -53,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, @@ -64,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 5319c9b55d5b..1f88d00d5a47 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,12 +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.store.appendonlydao.PersistenceResponse import com.daml.platform.store.entries.PartyLedgerEntry import com.daml.platform.store.entries.PartyLedgerEntry.AllocationAccepted @@ -54,11 +54,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 @@ -239,7 +239,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( @@ -255,7 +255,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 029823c60764..c62e7ea33e7d 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,7 +4,7 @@ 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 @@ -17,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._ @@ -56,7 +57,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)) @@ -282,7 +283,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", @@ -308,7 +309,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", @@ -408,8 +409,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, ) @@ -423,7 +424,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", @@ -445,7 +446,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", @@ -467,7 +468,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", @@ -492,7 +493,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, @@ -514,7 +515,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, @@ -542,7 +543,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, @@ -597,7 +598,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, @@ -644,8 +645,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, ) @@ -721,8 +722,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)), ) @@ -760,8 +761,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)), ) @@ -789,8 +790,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)), ) @@ -820,8 +821,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)), ) @@ -835,8 +836,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, ) @@ -863,7 +864,7 @@ private[dao] trait JdbcLedgerDaoSuite extends JdbcLedgerDaoBackend { ledgerDao .storeConfigurationEntry( offset = 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..ccac1acbcebb 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,10 @@ 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 +96,10 @@ 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 +138,10 @@ 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 72abcc4a7381..d804e9201e59 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} @@ -62,8 +63,10 @@ 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) => @@ -95,8 +98,10 @@ 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) = @@ -155,8 +160,10 @@ 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/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..c783573530f6 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,7 +3,7 @@ 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 @@ -23,6 +23,7 @@ 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 +86,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 a6b94723c988..5b4c7184f7c5 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 @@ -41,7 +41,7 @@ import org.scalatest.flatspec.AsyncFlatSpec import org.scalatest.matchers.should.Matchers import org.scalatest.{Assertion, Inside} -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 @@ -367,8 +367,8 @@ class ApiSubmissionServiceSpec verify(indexSubmissionService).deduplicateCommand( any[CommandId], any[List[Ref.Party]], - any[Instant], - any[Instant], + any[Timestamp], + any[Timestamp], )(any[LoggingContext]) Success(succeed) }) @@ -409,8 +409,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) }) @@ -436,7 +436,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, ""), ) @@ -465,8 +465,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 9609a7be18f9..0f569762d2c2 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,7 +3,6 @@ package com.daml.platform.index -import java.time.Instant import java.util.concurrent.atomic.{AtomicInteger, AtomicLong} import akka.NotUsed import akka.actor.ActorSystem @@ -12,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 @@ -200,7 +200,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)) @@ -260,7 +260,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/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..9bd2931e6a6a 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,13 +3,12 @@ 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.{ @@ -198,7 +197,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/appendonlydao/events/PostCommitValidationSpec.scala b/ledger/participant-integration-api/src/test/suite/scala/platform/store/appendonlydao/events/PostCommitValidationSpec.scala index 3793dedab24d..5ffe7261e399 100644 --- a/ledger/participant-integration-api/src/test/suite/scala/platform/store/appendonlydao/events/PostCommitValidationSpec.scala +++ b/ledger/participant-integration-api/src/test/suite/scala/platform/store/appendonlydao/events/PostCommitValidationSpec.scala @@ -6,6 +6,7 @@ package com.daml.platform.store.appendonlydao.events 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.lf.transaction.GlobalKey import com.daml.lf.transaction.test.{TransactionBuilder => TxBuilder} import com.daml.lf.value.Value.ValueText @@ -36,7 +37,7 @@ final class PostCommitValidationSpec extends AnyWordSpec with Matchers { val error = store.validate( transaction = TxBuilder.justCommitted(createWithKey), - transactionLedgerEffectiveTime = Instant.now(), + transactionLedgerEffectiveTime = Timestamp.now(), divulged = Set.empty, ) @@ -48,7 +49,7 @@ final class PostCommitValidationSpec extends AnyWordSpec with Matchers { val error = store.validate( transaction = TxBuilder.justCommitted(createWithoutKey), - transactionLedgerEffectiveTime = Instant.now(), + transactionLedgerEffectiveTime = Timestamp.now(), divulged = Set.empty, ) @@ -61,7 +62,7 @@ final class PostCommitValidationSpec extends AnyWordSpec with Matchers { val error = store.validate( transaction = TxBuilder.justCommitted(createContract, exerciseContract), - transactionLedgerEffectiveTime = Instant.now(), + transactionLedgerEffectiveTime = Timestamp.now(), divulged = Set.empty, ) @@ -74,7 +75,7 @@ final class PostCommitValidationSpec extends AnyWordSpec with Matchers { val error = store.validate( transaction = TxBuilder.justCommitted(exerciseContract), - transactionLedgerEffectiveTime = Instant.now(), + transactionLedgerEffectiveTime = Timestamp.now(), divulged = Set(divulgedContract.coid), ) @@ -87,7 +88,7 @@ final class PostCommitValidationSpec extends AnyWordSpec with Matchers { val error = store.validate( transaction = TxBuilder.justCommitted(exerciseContract), - transactionLedgerEffectiveTime = Instant.now(), + transactionLedgerEffectiveTime = Timestamp.now(), divulged = Set.empty, ) @@ -99,7 +100,7 @@ final class PostCommitValidationSpec extends AnyWordSpec with Matchers { val error = store.validate( transaction = TxBuilder.justCommitted(createContract, txBuilder.fetch(createContract)), - transactionLedgerEffectiveTime = Instant.now(), + transactionLedgerEffectiveTime = Timestamp.now(), divulged = Set.empty, ) @@ -111,7 +112,7 @@ final class PostCommitValidationSpec extends AnyWordSpec with Matchers { val error = store.validate( transaction = TxBuilder.justCommitted(txBuilder.fetch(divulgedContract)), - transactionLedgerEffectiveTime = Instant.now(), + transactionLedgerEffectiveTime = Timestamp.now(), divulged = Set(divulgedContract.coid), ) @@ -123,7 +124,7 @@ final class PostCommitValidationSpec extends AnyWordSpec with Matchers { val error = store.validate( transaction = TxBuilder.justCommitted(txBuilder.fetch(missingCreate)), - transactionLedgerEffectiveTime = Instant.now(), + transactionLedgerEffectiveTime = Timestamp.now(), divulged = Set.empty, ) @@ -136,7 +137,7 @@ final class PostCommitValidationSpec extends AnyWordSpec with Matchers { val error = store.validate( transaction = TxBuilder .justCommitted(createContract, txBuilder.lookupByKey(createContract, found = true)), - transactionLedgerEffectiveTime = Instant.now(), + transactionLedgerEffectiveTime = Timestamp.now(), divulged = Set.empty, ) @@ -148,7 +149,7 @@ final class PostCommitValidationSpec extends AnyWordSpec with Matchers { val error = store.validate( transaction = TxBuilder.justCommitted(txBuilder.lookupByKey(missingCreate, found = true)), - transactionLedgerEffectiveTime = Instant.now(), + transactionLedgerEffectiveTime = Timestamp.now(), divulged = Set.empty, ) @@ -163,7 +164,7 @@ final class PostCommitValidationSpec extends AnyWordSpec with Matchers { val error = store.validate( transaction = TxBuilder.justCommitted(txBuilder.lookupByKey(missingContract, found = false)), - transactionLedgerEffectiveTime = Instant.now(), + transactionLedgerEffectiveTime = Timestamp.now(), divulged = Set.empty, ) @@ -178,7 +179,7 @@ final class PostCommitValidationSpec extends AnyWordSpec with Matchers { val error = store.validate( transaction = builder.buildCommitted(), - transactionLedgerEffectiveTime = Instant.now(), + transactionLedgerEffectiveTime = Timestamp.now(), divulged = Set.empty, ) @@ -194,7 +195,7 @@ final class PostCommitValidationSpec extends AnyWordSpec with Matchers { val error = store.validate( transaction = builder.buildCommitted(), - transactionLedgerEffectiveTime = Instant.now(), + transactionLedgerEffectiveTime = Timestamp.now(), divulged = Set.empty, ) @@ -210,7 +211,7 @@ final class PostCommitValidationSpec extends AnyWordSpec with Matchers { val error = store.validate( transaction = builder.buildCommitted(), - transactionLedgerEffectiveTime = Instant.now(), + transactionLedgerEffectiveTime = Timestamp.now(), divulged = Set.empty, ) @@ -227,7 +228,7 @@ final class PostCommitValidationSpec extends AnyWordSpec with Matchers { val error = store.validate( transaction = builder.buildCommitted(), - transactionLedgerEffectiveTime = Instant.now(), + transactionLedgerEffectiveTime = Timestamp.now(), divulged = Set.empty, ) @@ -242,7 +243,7 @@ final class PostCommitValidationSpec extends AnyWordSpec with Matchers { val error = store.validate( transaction = builder.buildCommitted(), - transactionLedgerEffectiveTime = Instant.now(), + transactionLedgerEffectiveTime = Timestamp.now(), divulged = Set.empty, ) @@ -253,7 +254,8 @@ final class PostCommitValidationSpec extends AnyWordSpec with Matchers { "run with one committed contract with a key" should { val committedContract = genTestCreate() val exerciseOnCommittedContract = genTestExercise(committedContract) - val committedContractLedgerEffectiveTime = Instant.ofEpochMilli(1000) + val committedContractLedgerEffectiveTime = + Timestamp.assertFromInstant(Instant.ofEpochMilli(1000)) val store = new PostCommitValidation.BackedBy( committedContracts( @@ -292,14 +294,14 @@ final class PostCommitValidationSpec extends AnyWordSpec with Matchers { "reject an exercise pre-dating the committed contract" in { val error = store.validate( transaction = TxBuilder.justCommitted(exerciseOnCommittedContract), - transactionLedgerEffectiveTime = committedContractLedgerEffectiveTime.minusNanos(1), + transactionLedgerEffectiveTime = committedContractLedgerEffectiveTime.addMicros(-1), divulged = Set.empty, ) error shouldBe Some( Rejection.CausalMonotonicityViolation( contractLedgerEffectiveTime = committedContractLedgerEffectiveTime, - transactionLedgerEffectiveTime = committedContractLedgerEffectiveTime.minusNanos(1), + transactionLedgerEffectiveTime = committedContractLedgerEffectiveTime.addMicros(-1), ) ) } @@ -317,14 +319,14 @@ final class PostCommitValidationSpec extends AnyWordSpec with Matchers { "reject a fetch pre-dating the committed contract" in { val error = store.validate( transaction = TxBuilder.justCommitted(txBuilder.fetch(committedContract)), - transactionLedgerEffectiveTime = committedContractLedgerEffectiveTime.minusNanos(1), + transactionLedgerEffectiveTime = committedContractLedgerEffectiveTime.addMicros(-1), divulged = Set.empty, ) error shouldBe Some( Rejection.CausalMonotonicityViolation( contractLedgerEffectiveTime = committedContractLedgerEffectiveTime, - transactionLedgerEffectiveTime = committedContractLedgerEffectiveTime.minusNanos(1), + transactionLedgerEffectiveTime = committedContractLedgerEffectiveTime.addMicros(-1), ) ) } @@ -431,7 +433,7 @@ final class PostCommitValidationSpec extends AnyWordSpec with Matchers { "accept an exercise on the divulged contract" in { val error = store.validate( transaction = TxBuilder.justCommitted(exerciseOnDivulgedContract), - transactionLedgerEffectiveTime = Instant.now(), + transactionLedgerEffectiveTime = Timestamp.now(), divulged = Set.empty, ) @@ -441,7 +443,7 @@ final class PostCommitValidationSpec extends AnyWordSpec with Matchers { "accept a fetch on the divulged contract" in { val error = store.validate( transaction = TxBuilder.justCommitted(txBuilder.fetch(divulgedContract)), - transactionLedgerEffectiveTime = Instant.now(), + transactionLedgerEffectiveTime = Timestamp.now(), divulged = Set.empty, ) @@ -459,7 +461,7 @@ final class PostCommitValidationSpec extends AnyWordSpec with Matchers { val createWithKey = genTestCreate() val error = store.validate( transaction = TxBuilder.justCommitted(createWithKey), - transactionLedgerEffectiveTime = Instant.now(), + transactionLedgerEffectiveTime = Timestamp.now(), divulged = Set.empty, ) @@ -474,7 +476,7 @@ final class PostCommitValidationSpec extends AnyWordSpec with Matchers { val error = store.validate( transaction = builder.buildCommitted(), - transactionLedgerEffectiveTime = Instant.now(), + transactionLedgerEffectiveTime = Timestamp.now(), divulged = Set.empty, ) @@ -514,7 +516,7 @@ object PostCommitValidationSpec { private final case class ContractFixture private ( id: ContractId, - ledgerEffectiveTime: Option[Instant], + ledgerEffectiveTime: Option[Timestamp], key: Option[Key], ) @@ -527,12 +529,12 @@ object PostCommitValidationSpec { contracts.find(c => c.key.contains(key)).map(_.id) override def maximumLedgerTime( ids: Set[ContractId] - )(connection: Connection): Try[Option[Instant]] = { + )(connection: Connection): Try[Option[Timestamp]] = { val lookup = contracts.collect { case c if ids.contains(c.id) => c.ledgerEffectiveTime } if (lookup.isEmpty) Failure(notFound(ids)) - else Success(lookup.fold[Option[Instant]](None)(pickTheGreatest)) + else Success(lookup.fold[Option[Timestamp]](None)(pickTheGreatest)) } override def keyState(key: Key, validAt: Long)(connection: Connection): KeyState = notImplemented() @@ -571,8 +573,8 @@ object PostCommitValidationSpec { ) } - private def pickTheGreatest(l: Option[Instant], r: Option[Instant]): Option[Instant] = - l.fold(r)(left => r.fold(l)(right => if (left.isAfter(right)) l else r)) + private def pickTheGreatest(l: Option[Timestamp], r: Option[Timestamp]): Option[Timestamp] = + l.fold(r)(left => r.fold(l)(right => if (left > right) l else r)) private def notFound(contractIds: Set[ContractId]): Throwable = new IllegalArgumentException( @@ -597,7 +599,7 @@ object PostCommitValidationSpec { private def committed( id: String, - ledgerEffectiveTime: Instant, + ledgerEffectiveTime: Timestamp, key: Option[Key], ): ContractFixture = ContractFixture( diff --git a/ledger/participant-integration-api/src/test/suite/scala/platform/store/backend/UpdateToDbDtoSpec.scala b/ledger/participant-integration-api/src/test/suite/scala/platform/store/backend/UpdateToDbDtoSpec.scala index 1110c87ee9a0..70eb5c5e27f8 100644 --- a/ledger/participant-integration-api/src/test/suite/scala/platform/store/backend/UpdateToDbDtoSpec.scala +++ b/ledger/participant-integration-api/src/test/suite/scala/platform/store/backend/UpdateToDbDtoSpec.scala @@ -1240,10 +1240,10 @@ class UpdateToDbDtoSpec extends AnyWordSpec with Matchers { None, ), ( - Some(DeduplicationDuration(Duration.ofDays(1L).plusNanos(100))), + Some(DeduplicationDuration(Duration.ofDays(1L).plusNanos(100 * 1000))), None, Some(Duration.ofDays(1L).toMinutes * 60L), - Some(100), + Some(100 * 1000), ), ) 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 f92d6e9c15c5..6be070d13862 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} @@ -376,7 +376,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 +431,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 +489,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 +535,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/participant-state-index/src/main/scala/com/daml/ledger/participant/state/index/v2/ContractStore.scala b/ledger/participant-state-index/src/main/scala/com/daml/ledger/participant/state/index/v2/ContractStore.scala index 8e05c498d572..bf50689420d9 100644 --- a/ledger/participant-state-index/src/main/scala/com/daml/ledger/participant/state/index/v2/ContractStore.scala +++ b/ledger/participant-state-index/src/main/scala/com/daml/ledger/participant/state/index/v2/ContractStore.scala @@ -3,10 +3,9 @@ package com.daml.ledger.participant.state.index.v2 -import java.time.Instant - import com.daml.lf.data.Ref import com.daml.lf.data.Ref.Party +import com.daml.lf.data.Time.Timestamp import com.daml.lf.transaction.GlobalKey import com.daml.lf.value.Value.{ContractId, VersionedContractInstance} import com.daml.logging.LoggingContext @@ -33,5 +32,5 @@ trait ContractStore { */ def lookupMaximumLedgerTime(ids: Set[ContractId])(implicit loggingContext: LoggingContext - ): Future[Option[Instant]] + ): Future[Option[Timestamp]] } diff --git a/ledger/participant-state-index/src/main/scala/com/daml/ledger/participant/state/index/v2/IndexSubmissionService.scala b/ledger/participant-state-index/src/main/scala/com/daml/ledger/participant/state/index/v2/IndexSubmissionService.scala index 04d6985d2cf8..860074b21d32 100644 --- a/ledger/participant-state-index/src/main/scala/com/daml/ledger/participant/state/index/v2/IndexSubmissionService.scala +++ b/ledger/participant-state-index/src/main/scala/com/daml/ledger/participant/state/index/v2/IndexSubmissionService.scala @@ -3,10 +3,9 @@ package com.daml.ledger.participant.state.index.v2 -import java.time.Instant - import com.daml.ledger.api.domain.CommandId import com.daml.lf.data.Ref +import com.daml.lf.data.Time.Timestamp import com.daml.logging.LoggingContext import scala.concurrent.Future @@ -18,8 +17,8 @@ trait IndexSubmissionService { def deduplicateCommand( commandId: CommandId, submitters: List[Ref.Party], - submittedAt: Instant, - deduplicateUntil: Instant, + submittedAt: Timestamp, + deduplicateUntil: Timestamp, )(implicit loggingContext: LoggingContext): Future[CommandDeduplicationResult] def stopDeduplicatingCommand( diff --git a/ledger/participant-state-index/src/main/scala/com/daml/ledger/participant/state/index/v2/package.scala b/ledger/participant-state-index/src/main/scala/com/daml/ledger/participant/state/index/v2/package.scala index 7f6cc6985988..b05ca42384bd 100644 --- a/ledger/participant-state-index/src/main/scala/com/daml/ledger/participant/state/index/v2/package.scala +++ b/ledger/participant-state-index/src/main/scala/com/daml/ledger/participant/state/index/v2/package.scala @@ -3,7 +3,7 @@ package com.daml.ledger.participant.state.index -import java.time.{Duration, Instant} +import java.time.Duration import akka.NotUsed import akka.stream.scaladsl.Source @@ -13,6 +13,8 @@ import com.daml.ledger.api.domain._ package v2 { + import com.daml.lf.data.Time.Timestamp + object AcsUpdateEvent { final case class Create( @@ -83,8 +85,8 @@ package v2 { final case class TransactionMeta( transactionId: TransactionId, offset: LedgerOffset.Absolute, - ledgerEffectiveTime: Instant, - recordTime: Instant, + ledgerEffectiveTime: Timestamp, + recordTime: Timestamp, workflowId: WorkflowId, ) @@ -102,7 +104,7 @@ package v2 { */ final case class PackageDetails( size: Long, - knownSince: Instant, + knownSince: Timestamp, sourceDescription: Option[String], ) @@ -112,6 +114,6 @@ package v2 { case object CommandDeduplicationNew extends CommandDeduplicationResult /** This command was submitted before. */ - final case class CommandDeduplicationDuplicate(deduplicateUntil: Instant) + final case class CommandDeduplicationDuplicate(deduplicateUntil: Timestamp) extends CommandDeduplicationResult } diff --git a/ledger/participant-state/src/main/scala/com/daml/ledger/participant/state/v2/AdaptedV1WriteService.scala b/ledger/participant-state/src/main/scala/com/daml/ledger/participant/state/v2/AdaptedV1WriteService.scala index 18dc7ef30d6e..6545ca6cb3e5 100644 --- a/ledger/participant-state/src/main/scala/com/daml/ledger/participant/state/v2/AdaptedV1WriteService.scala +++ b/ledger/participant-state/src/main/scala/com/daml/ledger/participant/state/v2/AdaptedV1WriteService.scala @@ -3,7 +3,6 @@ package com.daml.ledger.participant.state.v2 -import java.time.Instant import java.util.concurrent.CompletionStage import com.daml.daml_lf_dev.DamlLf @@ -12,6 +11,7 @@ import com.daml.ledger.api.health.HealthStatus import com.daml.ledger.configuration.Configuration import com.daml.ledger.offset.Offset import com.daml.ledger.participant.state.v1 +import com.daml.lf.data.Time.Timestamp import com.daml.lf.data.{Ref, Time} import com.daml.lf.transaction.SubmittedTransaction import com.daml.telemetry.TelemetryContext @@ -90,14 +90,14 @@ private[v2] object AdaptedV1WriteService { def adaptSubmitterInfo(submitterInfo: SubmitterInfo): v1.SubmitterInfo = { val deduplicateUntil = DeduplicationPeriod.deduplicateUntil( - Instant.now(), + Timestamp.now(), submitterInfo.deduplicationPeriod, ) v1.SubmitterInfo( actAs = submitterInfo.actAs, applicationId = submitterInfo.applicationId, commandId = submitterInfo.commandId, - deduplicateUntil = deduplicateUntil, + deduplicateUntil = deduplicateUntil.toInstant, ) } 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 a69f3f60ae72..6d882e568f8f 100644 --- a/ledger/sandbox-classic/src/main/scala/platform/sandbox/SandboxServer.scala +++ b/ledger/sandbox-classic/src/main/scala/platform/sandbox/SandboxServer.scala @@ -17,6 +17,7 @@ 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.{ @@ -474,7 +475,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..5a4d3336a05d 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,12 @@ 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 e05f48770971..4883eab8e4df 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 @@ -12,6 +12,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 @@ -149,7 +150,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 69e15b535b74..77cd8ad16b19 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 @@ -40,13 +40,14 @@ import com.daml.ledger.participant.state.index.v2.{ 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, + GlobalKey, SubmittedTransaction, TransactionCommitter, } @@ -334,7 +335,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( @@ -343,15 +344,17 @@ private[sandbox] final class InMemoryLedger( ) } else { Future.fromTry(Try(this.synchronized { - contractIds.foldLeft[Option[Instant]](Some(Instant.MIN))((acc, id) => { - val let = acs.activeContracts - .getOrElse( - id, - sys.error(s"Contract $id not found while looking for maximum ledger time"), - ) - .let - acc.map(acc => if (let.isAfter(acc)) let else acc) - }) + contractIds + .foldLeft[Option[Instant]](Some(Instant.MIN))((acc, id) => { + val let = acs.activeContracts + .getOrElse( + id, + sys.error(s"Contract $id not found while looking for maximum ledger time"), + ) + .let + acc.map(acc => if (let.isAfter(acc)) let else acc) + }) + .map(Timestamp.assertFromInstant) })) } @@ -369,8 +372,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) @@ -384,8 +387,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), @@ -423,7 +426,7 @@ private[sandbox] final class InMemoryLedger( Some(submitterInfo.submissionId), submitterInfo.actAs, transactionMeta.workflowId, - transactionMeta.ledgerEffectiveTime.toInstant, + transactionMeta.ledgerEffectiveTime, recordTime, committedTransaction, disclosureForIndex, @@ -444,7 +447,7 @@ private[sandbox] final class InMemoryLedger( entries.publish( InMemoryLedgerEntry( LedgerEntry.Rejection( - timeProvider.getCurrentTime, + timeProvider.getCurrentTimestamp, submitterInfo.commandId, submitterInfo.applicationId, submitterInfo.submissionId, @@ -530,7 +533,7 @@ private[sandbox] final class InMemoryLedger( InMemoryPartyEntry( PartyLedgerEntry.AllocationRejected( submissionId, - timeProvider.getCurrentTime, + timeProvider.getCurrentTimestamp, "Party already exists", ) ) @@ -541,7 +544,7 @@ private[sandbox] final class InMemoryLedger( InMemoryPartyEntry( PartyLedgerEntry.AllocationAccepted( Some(submissionId), - timeProvider.getCurrentTime, + timeProvider.getCurrentTimestamp, PartyDetails(party, displayName, isLocal = true), ) ) @@ -582,7 +585,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] = { @@ -595,7 +598,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) @@ -604,7 +607,8 @@ 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) @@ -622,8 +626,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( @@ -636,12 +639,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, ) ) @@ -688,8 +691,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 { @@ -697,28 +700,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 a2da015566ad..61c1fd5c54e0 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,7 +3,6 @@ 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} @@ -20,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} @@ -215,7 +215,7 @@ private[sandbox] object SqlLedger { _ <- copyPackages( packages, ledgerDao, - timeProvider.getCurrentTime, + timeProvider.getCurrentTimestamp, SandboxOffset.toOffset(ledgerEnd), ) _ <- ledgerDao.storeInitialState(ledgerEntries, SandboxOffset.toOffset(ledgerEnd)) @@ -225,7 +225,7 @@ private[sandbox] object SqlLedger { private def copyPackages( store: InMemoryPackageStore, ledgerDao: LedgerWriteDao, - knownSince: Instant, + knownSince: Timestamp, newLedgerEnd: Offset, ): Future[Unit] = { val packageDetails = store.listLfPackagesSync() @@ -381,8 +381,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() @@ -399,8 +399,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( @@ -421,7 +421,7 @@ private final class SqlLedger( completionInfo = Some(submitterInfo.toCompletionInfo), workflowId = transactionMeta.workflowId, transactionId = transactionId, - ledgerEffectiveTime = transactionMeta.ledgerEffectiveTime.toInstant, + ledgerEffectiveTime = transactionMeta.ledgerEffectiveTime, offset = offset, transaction = transactionCommitter.commitTransaction(transactionId, transaction), divulgedContracts = divulgedContracts, @@ -475,7 +475,7 @@ private final class SqlLedger( offset, PartyLedgerEntry.AllocationAccepted( Some(submissionId), - timeProvider.getCurrentTime, + timeProvider.getCurrentTimestamp, PartyDetails(party, displayName, isLocal = true), ), ) @@ -500,7 +500,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] = { @@ -512,7 +512,9 @@ private final class SqlLedger( .storePackageEntry( offset, packages, - Some(PackageLedgerEntry.PackageUploadAccepted(submissionId, timeProvider.getCurrentTime)), + Some( + PackageLedgerEntry.PackageUploadAccepted(submissionId, timeProvider.getCurrentTimestamp) + ), ) .map(_ => ())(DEC) .recover { case t => @@ -529,18 +531,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( 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/SqlLedgerSpec.scala b/ledger/sandbox-classic/src/test/suite/scala/platform/sandbox/stores/ledger/sql/SqlLedgerSpec.scala index ff6caab38946..fdc13f832254 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 @@ -21,6 +21,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 +249,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 +289,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 +455,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,