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 968d263abf15..7ec0a8dff602 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 @@ -204,7 +203,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( 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 d272f9ef87a3..13a61f91fa06 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,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 @@ -104,7 +103,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), diff --git a/ledger/participant-integration-api/src/main/scala/platform/indexer/ExecuteUpdate.scala b/ledger/participant-integration-api/src/main/scala/platform/indexer/ExecuteUpdate.scala index f2739ce1b7f7..9fe0c8507bf3 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/indexer/ExecuteUpdate.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/indexer/ExecuteUpdate.scala @@ -98,7 +98,7 @@ trait ExecuteUpdate { completionInfo = tx.optCompletionInfo, workflowId = tx.transactionMeta.workflowId, transactionId = tx.transactionId, - ledgerEffectiveTime = tx.transactionMeta.ledgerEffectiveTime.toInstant, + ledgerEffectiveTime = tx.transactionMeta.ledgerEffectiveTime, offset = offsetStepPair.offsetStep.offset, transaction = tx.transaction, divulgedContracts = tx.divulgedContracts, @@ -129,7 +129,7 @@ trait ExecuteUpdate { ) => val entry = PartyLedgerEntry.AllocationAccepted( submissionId, - recordTime.toInstant, + recordTime, domain.PartyDetails(party, Some(displayName), participantId == hostingParticipantId), ) ledgerDao.storePartyEntry(offsetStep, entry) @@ -142,30 +142,29 @@ trait ExecuteUpdate { ) => val entry = PartyLedgerEntry.AllocationRejected( submissionId, - recordTime.toInstant, + recordTime, rejectionReason, ) ledgerDao.storePartyEntry(offsetStep, entry) case PublicPackageUpload(archives, optSourceDescription, recordTime, optSubmissionId) => - val recordTimeInstant = recordTime.toInstant val packages: List[(DamlLf.Archive, v2.PackageDetails)] = archives.map(archive => archive -> v2.PackageDetails( size = archive.getPayload.size.toLong, - knownSince = recordTimeInstant, + knownSince = recordTime, sourceDescription = optSourceDescription, ) ) val optEntry: Option[PackageLedgerEntry] = optSubmissionId.map(submissionId => - PackageLedgerEntry.PackageUploadAccepted(submissionId, recordTimeInstant) + PackageLedgerEntry.PackageUploadAccepted(submissionId, recordTime) ) ledgerDao.storePackageEntry(offsetStep, packages, optEntry) case PublicPackageUploadRejected(submissionId, recordTime, rejectionReason) => val entry = PackageLedgerEntry.PackageUploadRejected( submissionId, - recordTime.toInstant, + recordTime, rejectionReason, ) ledgerDao.storePackageEntry(offsetStep, List.empty, Some(entry)) @@ -173,7 +172,7 @@ trait ExecuteUpdate { case config: ConfigurationChanged => ledgerDao.storeConfigurationEntry( offsetStep, - config.recordTime.toInstant, + config.recordTime, config.submissionId, config.newConfiguration, None, @@ -182,7 +181,7 @@ trait ExecuteUpdate { case configRejection: ConfigurationChangeRejected => ledgerDao.storeConfigurationEntry( offsetStep, - configRejection.recordTime.toInstant, + configRejection.recordTime, configRejection.submissionId, configRejection.proposedConfiguration, Some(configRejection.rejectionReason), @@ -191,7 +190,7 @@ trait ExecuteUpdate { case CommandRejected(recordTime, completionInfo, reason) => ledgerDao.storeRejection( Some(completionInfo), - recordTime.toInstant, + recordTime, offsetStep, reason, ) @@ -206,7 +205,7 @@ trait ExecuteUpdate { completionInfo = optCompletionInfo, workflowId = transactionMeta.workflowId, transactionId = transactionId, - ledgerEffectiveTime = transactionMeta.ledgerEffectiveTime.toInstant, + ledgerEffectiveTime = transactionMeta.ledgerEffectiveTime, offset = offsetStep.offset, transaction = transaction, divulgedContracts = divulgedContracts, @@ -214,8 +213,8 @@ trait ExecuteUpdate { ), completionInfo = optCompletionInfo, transactionId = transactionId, - recordTime = recordTime.toInstant, - ledgerEffectiveTime = transactionMeta.ledgerEffectiveTime.toInstant, + recordTime = recordTime, + ledgerEffectiveTime = transactionMeta.ledgerEffectiveTime, offsetStep = offsetStep, transaction = transaction, divulged = divulgedContracts, @@ -291,7 +290,7 @@ class PipelinedExecuteUpdate( ledgerDao.completeTransaction( completionInfo = tx.optCompletionInfo, transactionId = tx.transactionId, - recordTime = tx.recordTime.toInstant, + recordTime = tx.recordTime, offsetStep = offsetStep, ), ) @@ -383,8 +382,8 @@ class AtomicExecuteUpdate( preparedInsert, completionInfo = optCompletionInfo, transactionId = transactionId, - recordTime = recordTime.toInstant, - ledgerEffectiveTime = transactionMeta.ledgerEffectiveTime.toInstant, + recordTime = recordTime, + ledgerEffectiveTime = transactionMeta.ledgerEffectiveTime, offsetStep = offsetStep, transaction = transaction, divulged = divulgedContracts, 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 c6e25511f4a0..0b03ed5703b7 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 @@ -133,7 +133,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 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 1d2f87b86f2e..63b07466dad2 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 @@ -73,7 +73,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 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 32522fe1373d..7ca742f7ebd2 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 @@ -158,7 +158,7 @@ private class JdbcLedgerDao( override def storeConfigurationEntry( offsetStep: OffsetStep, - recordedAt: Instant, + recordedAt: Timestamp, submissionId: String, configuration: Configuration, rejectionReason: Option[String], @@ -191,7 +191,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 @@ -200,7 +200,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 @@ -240,7 +240,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, ) ), @@ -255,7 +255,7 @@ private class JdbcLedgerDao( state.Update.PartyAllocationRejected( submissionId = submissionId, participantId = participantId, - recordTime = Time.Timestamp.assertFromInstant(recordTime), + recordTime = recordTime, rejectionReason = reason, ) ), @@ -287,7 +287,7 @@ 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], @@ -315,7 +315,7 @@ private class JdbcLedgerDao( override def completeTransaction( completionInfo: Option[state.CompletionInfo], transactionId: Ref.TransactionId, - recordTime: Instant, + recordTime: Timestamp, offsetStep: OffsetStep, )(implicit loggingContext: LoggingContext): Future[PersistenceResponse] = throw new UnsupportedOperationException( @@ -326,8 +326,8 @@ private class JdbcLedgerDao( preparedInsert: PreparedInsert, completionInfo: Option[state.CompletionInfo], transactionId: Ref.TransactionId, - recordTime: Instant, - ledgerEffectiveTime: Instant, + recordTime: Timestamp, + ledgerEffectiveTime: Timestamp, offsetStep: OffsetStep, transaction: CommittedTransaction, divulged: Iterable[state.DivulgedContract], @@ -337,7 +337,7 @@ private class JdbcLedgerDao( ) // TODO append-only: cleanup private def validate( - ledgerEffectiveTime: Instant, + ledgerEffectiveTime: Timestamp, transaction: CommittedTransaction, divulged: Iterable[state.DivulgedContract], )(implicit connection: Connection): Option[PostCommitValidation.Rejection] = @@ -352,7 +352,7 @@ private class JdbcLedgerDao( override def storeRejection( completionInfo: Option[state.CompletionInfo], - recordTime: Instant, + recordTime: Timestamp, offsetStep: OffsetStep, reason: state.Update.CommandRejected.RejectionReasonTemplate, )(implicit loggingContext: LoggingContext): Future[PersistenceResponse] = @@ -364,7 +364,7 @@ private class JdbcLedgerDao( offset, completionInfo.map(info => state.Update.CommandRejected( - recordTime = Time.Timestamp.assertFromInstant(recordTime), + recordTime = recordTime, completionInfo = info, reasonTemplate = reason, ) @@ -403,8 +403,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 @@ -414,7 +413,7 @@ private class JdbcLedgerDao( ), transaction = tx.transaction, transactionId = tx.transactionId, - recordTime = Time.Timestamp.assertFromInstant(tx.recordedAt), + recordTime = tx.recordedAt, divulgedContracts = Nil, blindingInfo = None, ) @@ -433,7 +432,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, @@ -507,13 +506,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 ) @@ -524,14 +521,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, ) } @@ -727,12 +724,12 @@ private class JdbcLedgerDao( completionInfo: Option[state.CompletionInfo], workflowId: Option[Ref.WorkflowId], transactionId: Ref.TransactionId, - ledgerEffectiveTime: Instant, + ledgerEffectiveTime: Timestamp, offsetStep: OffsetStep, transaction: CommittedTransaction, divulgedContracts: Iterable[state.DivulgedContract], blindingInfo: Option[BlindingInfo], - recordTime: Instant, + recordTime: Timestamp, )(implicit loggingContext: LoggingContext): Future[PersistenceResponse] = { logger.info("Storing transaction") dbDispatcher @@ -746,7 +743,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 @@ -756,7 +753,7 @@ private class JdbcLedgerDao( ), transaction = transaction, transactionId = transactionId, - recordTime = Time.Timestamp.assertFromInstant(recordTime), + recordTime = recordTime, divulgedContracts = divulgedContracts.toList, blindingInfo = blindingInfo, ) @@ -765,7 +762,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/backend/common/PackageStorageBackendTemplate.scala b/ledger/participant-integration-api/src/main/scala/platform/store/backend/common/PackageStorageBackendTemplate.scala index 3ce057df31d8..5c6619f5798f 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 @@ -4,13 +4,13 @@ package com.daml.platform.store.backend.common import java.sql.Connection - 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.{instantFromMicros, 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 +47,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 +80,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..9de6f83f44a5 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 @@ -4,13 +4,12 @@ package com.daml.platform.store.backend.common import java.sql.Connection - import anorm.{RowParser, SQL, ~} 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 +31,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/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 8638e2895def..2604df79c0b2 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} @@ -18,12 +19,7 @@ import com.daml.platform.store.cache.MutableCacheBackedContractStore._ import com.daml.platform.store.dao.events.ContractStateEvent import com.daml.platform.store.dao.events.ContractStateEvent.LedgerEndMarker import com.daml.platform.store.interfaces.LedgerDaoContractsReader -import com.daml.platform.store.interfaces.LedgerDaoContractsReader.{ - ActiveContract, - ArchivedContract, - ContractState, - KeyState, -} +import com.daml.platform.store.interfaces.LedgerDaoContractsReader.{ActiveContract, ArchivedContract, ContractState, KeyState} import java.time.Instant import java.util.concurrent.atomic.AtomicReference @@ -72,7 +68,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 +91,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/dao/CommandCompletionsTable.scala b/ledger/participant-integration-api/src/main/scala/platform/store/dao/CommandCompletionsTable.scala index 95ebc10572b6..998851833a8f 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/dao/CommandCompletionsTable.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/dao/CommandCompletionsTable.scala @@ -3,12 +3,11 @@ package com.daml.platform.store.dao -import java.time.Instant - -import anorm.{~, Row, RowParser, SimpleSql, SqlParser, SqlStringInterpolation} +import anorm.{Row, RowParser, SimpleSql, SqlParser, SqlStringInterpolation, ~} 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.Time.Timestamp import com.daml.platform.store.CompletionFromTransaction import com.daml.platform.store.Conversions._ import com.daml.platform.store.dao.events.SqlFunctions @@ -18,8 +17,8 @@ private[platform] object CommandCompletionsTable { import SqlParser.{int, str} - private val sharedColumns: RowParser[Offset ~ Instant ~ String ~ String] = - offset("completion_offset") ~ instantFromTimestamp("record_time") ~ str("command_id") ~ str( + private val sharedColumns: RowParser[Offset ~ Timestamp ~ String ~ String] = + offset("completion_offset") ~ timestampFromMicros("record_time") ~ str("command_id") ~ str( "application_id" ) diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/dao/JdbcLedgerDao.scala b/ledger/participant-integration-api/src/main/scala/platform/store/dao/JdbcLedgerDao.scala index ec35b48dbe6c..6d8fd0d9c883 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/dao/JdbcLedgerDao.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/dao/JdbcLedgerDao.scala @@ -5,38 +5,23 @@ package com.daml.platform.store.dao import java.sql.Connection import java.time.Instant import java.util.{Date, UUID} - import akka.NotUsed import akka.stream.scaladsl.Source import anorm.SqlParser._ import anorm.ToStatement.optionToStatement -import anorm.{ - BatchSql, - Macro, - NamedParameter, - Row, - RowParser, - SQL, - SimpleSql, - SqlParser, - SqlStringInterpolation, -} +import anorm.{BatchSql, Macro, NamedParameter, Row, RowParser, SQL, SimpleSql, SqlParser, SqlStringInterpolation} import com.daml.daml_lf_dev.DamlLf.Archive import com.daml.ledger.api.domain import com.daml.ledger.api.domain.{LedgerId, ParticipantId, PartyDetails} 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.index.v2.{ - CommandDeduplicationDuplicate, - CommandDeduplicationNew, - CommandDeduplicationResult, - PackageDetails, -} +import com.daml.ledger.participant.state.index.v2.{CommandDeduplicationDuplicate, CommandDeduplicationNew, CommandDeduplicationResult, PackageDetails} import com.daml.ledger.participant.state.{v2 => state} import com.daml.ledger.resources.ResourceOwner import com.daml.lf.archive.ArchiveParser import com.daml.lf.data.Ref +import com.daml.lf.data.Time.Timestamp import com.daml.lf.engine.ValueEnricher import com.daml.lf.transaction.{BlindingInfo, CommittedTransaction} import com.daml.logging.LoggingContext.withEnrichedLoggingContext @@ -53,12 +38,7 @@ import com.daml.platform.store.dao.CommandCompletionsTable.prepareCompletionsDel import com.daml.platform.store.dao.PersistenceResponse.Ok import com.daml.platform.store.dao.events.TransactionsWriter.PreparedInsert import com.daml.platform.store.dao.events._ -import com.daml.platform.store.entries.{ - ConfigurationEntry, - LedgerEntry, - PackageLedgerEntry, - PartyLedgerEntry, -} +import com.daml.platform.store.entries.{ConfigurationEntry, LedgerEntry, PackageLedgerEntry, PartyLedgerEntry} import scalaz.syntax.tag._ import spray.json.DefaultJsonProtocol._ import spray.json._ @@ -259,7 +239,7 @@ private class JdbcLedgerDao( override def storeConfigurationEntry( offsetStep: OffsetStep, - recordedAt: Instant, + recordedAt: Timestamp, submissionId: String, configuration: Configuration, rejectionReason: Option[String], @@ -417,7 +397,7 @@ private class JdbcLedgerDao( offset -> PartyLedgerEntry.AllocationAccepted( submissionIdOpt, - recordTime.toInstant, + Timestamp.assertFromInstant(recordTime.toInstant), PartyDetails(party, displayNameOpt, isLocal), ) case ( @@ -432,7 +412,7 @@ private class JdbcLedgerDao( ) => offset -> PartyLedgerEntry.AllocationRejected( submissionId, - recordTime.toInstant, + Timestamp.assertFromInstant(recordTime.toInstant), reason, ) case invalidRow => @@ -463,7 +443,7 @@ 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], @@ -526,8 +506,8 @@ private class JdbcLedgerDao( preparedInsert: PreparedInsert, completionInfo: Option[state.CompletionInfo], transactionId: Ref.TransactionId, - recordTime: Instant, - ledgerEffectiveTime: Instant, + recordTime: Timestamp, + ledgerEffectiveTime: Timestamp, offsetStep: OffsetStep, transaction: CommittedTransaction, divulged: Iterable[state.DivulgedContract], @@ -552,7 +532,7 @@ private class JdbcLedgerDao( } private def validate( - ledgerEffectiveTime: Instant, + ledgerEffectiveTime: Timestamp, transaction: CommittedTransaction, divulged: Iterable[state.DivulgedContract], )(implicit connection: Connection): Option[PostCommitValidation.Rejection] = @@ -568,7 +548,7 @@ private class JdbcLedgerDao( private def insertCompletions( completionInfo: Option[state.CompletionInfo], transactionId: Ref.TransactionId, - recordTime: Instant, + recordTime: Timestamp, offsetStep: OffsetStep, )(implicit connection: Connection): Unit = Timed.value( @@ -586,14 +566,14 @@ private class JdbcLedgerDao( override def storeRejection( completionInfo: Option[state.CompletionInfo], - recordTime: Instant, + recordTime: Timestamp, offsetStep: OffsetStep, reason: state.Update.CommandRejected.RejectionReasonTemplate, )(implicit loggingContext: LoggingContext): Future[PersistenceResponse] = { logger.info("Storing rejection") dbDispatcher.executeSql(metrics.daml.index.db.storeRejectionDbMetrics) { implicit conn => for (info <- completionInfo) { - handleError(offsetStep.offset, info, recordTime, reason) + handleError(offsetStep.offset, info, recordTime.toInstant, reason) } ParametersTable.updateLedgerEnd(offsetStep) Ok @@ -866,8 +846,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) { implicit conn => val key = DeduplicationKeyMaker.make(commandId, submitters) @@ -889,7 +869,7 @@ private class JdbcLedgerDao( .on("deduplicationKey" -> key) .as(CommandDataParser.single) - CommandDeduplicationDuplicate(result.deduplicateUntil) + CommandDeduplicationDuplicate(Timestamp.assertFromInstant(result.deduplicateUntil)) } } @@ -899,12 +879,12 @@ private class JdbcLedgerDao( """.stripMargin) override def removeExpiredDeduplicationData( - currentTime: Instant + currentTime: Timestamp )(implicit loggingContext: LoggingContext): Future[Unit] = dbDispatcher.executeSql(metrics.daml.index.db.removeExpiredDeduplicationDataDbMetrics) { implicit conn => SQL_DELETE_EXPIRED_COMMANDS - .on("currentTime" -> currentTime) + .on("currentTime" -> currentTime.toInstant) .execute() () } @@ -1027,12 +1007,12 @@ private class JdbcLedgerDao( completionInfo: Option[state.CompletionInfo], workflowId: Option[Ref.WorkflowId], transactionId: Ref.TransactionId, - ledgerEffectiveTime: Instant, + ledgerEffectiveTime: Timestamp, offset: OffsetStep, transaction: CommittedTransaction, divulgedContracts: Iterable[state.DivulgedContract], blindingInfo: Option[BlindingInfo], - recordTime: Instant, + recordTime: Timestamp, )(implicit loggingContext: LoggingContext): Future[PersistenceResponse] = { val preparedInsert = prepareTransactionInsert( completionInfo = completionInfo, diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/dao/LedgerDao.scala b/ledger/participant-integration-api/src/main/scala/platform/store/dao/LedgerDao.scala index 1dd0f36824fe..27a94c6cbd5d 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/dao/LedgerDao.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/dao/LedgerDao.scala @@ -3,7 +3,6 @@ package com.daml.platform.store.dao -import java.time.Instant import akka.NotUsed import akka.stream.scaladsl.Source import com.daml.daml_lf_dev.DamlLf.Archive @@ -257,7 +256,7 @@ 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], @@ -269,8 +268,8 @@ private[platform] trait LedgerWriteDao extends ReportsHealth { preparedInsert: PreparedInsert, completionInfo: Option[state.CompletionInfo], transactionId: Ref.TransactionId, - recordTime: Instant, - ledgerEffectiveTime: Instant, + recordTime: Timestamp, + ledgerEffectiveTime: Timestamp, offsetStep: OffsetStep, transaction: CommittedTransaction, divulged: Iterable[state.DivulgedContract], @@ -290,13 +289,13 @@ private[platform] trait LedgerWriteDao extends ReportsHealth { def completeTransaction( completionInfo: Option[state.CompletionInfo], transactionId: Ref.TransactionId, - recordTime: Instant, + recordTime: Timestamp, offsetStep: OffsetStep, )(implicit loggingContext: LoggingContext): Future[PersistenceResponse] def storeRejection( completionInfo: Option[state.CompletionInfo], - recordTime: Instant, + recordTime: Timestamp, offsetStep: OffsetStep, reason: state.Update.CommandRejected.RejectionReasonTemplate, )(implicit loggingContext: LoggingContext): Future[PersistenceResponse] @@ -328,7 +327,7 @@ private[platform] trait LedgerWriteDao extends ReportsHealth { */ def storeConfigurationEntry( offsetStep: OffsetStep, - recordedAt: Instant, + recordedAt: Timestamp, submissionId: String, configuration: Configuration, rejectionReason: Option[String], @@ -352,12 +351,12 @@ private[platform] trait LedgerWriteDao extends ReportsHealth { completionInfo: Option[state.CompletionInfo], workflowId: Option[Ref.WorkflowId], transactionId: Ref.TransactionId, - ledgerEffectiveTime: Instant, + ledgerEffectiveTime: Timestamp, offset: OffsetStep, 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/dao/MeteredLedgerDao.scala b/ledger/participant-integration-api/src/main/scala/platform/store/dao/MeteredLedgerDao.scala index d02a7786e52d..1aebe8f77a8d 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/dao/MeteredLedgerDao.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/dao/MeteredLedgerDao.scala @@ -4,7 +4,6 @@ package com.daml.platform.store.dao import java.time.Instant - import akka.NotUsed import akka.stream.scaladsl.Source import com.daml.daml_lf_dev.DamlLf.Archive @@ -15,18 +14,14 @@ 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} import com.daml.platform.indexer.OffsetStep import com.daml.platform.store.dao.events.TransactionsWriter import com.daml.platform.store.dao.events.TransactionsWriter.PreparedInsert -import com.daml.platform.store.entries.{ - ConfigurationEntry, - LedgerEntry, - PackageLedgerEntry, - PartyLedgerEntry, -} +import com.daml.platform.store.entries.{ConfigurationEntry, LedgerEntry, PackageLedgerEntry, PartyLedgerEntry} import com.daml.platform.store.interfaces.LedgerDaoContractsReader import scala.concurrent.Future @@ -117,15 +112,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( @@ -160,8 +155,8 @@ private[platform] class MeteredLedgerDao(ledgerDao: LedgerDao, metrics: Metrics) preparedInsert: PreparedInsert, completionInfo: Option[state.CompletionInfo], transactionId: Ref.TransactionId, - recordTime: Instant, - ledgerEffectiveTime: Instant, + recordTime: Timestamp, + ledgerEffectiveTime: Timestamp, offsetStep: OffsetStep, transaction: CommittedTransaction, divulged: Iterable[state.DivulgedContract], @@ -184,7 +179,7 @@ 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], @@ -203,7 +198,7 @@ private[platform] class MeteredLedgerDao(ledgerDao: LedgerDao, metrics: Metrics) override def storeRejection( completionInfo: Option[state.CompletionInfo], - recordTime: Instant, + recordTime: Timestamp, offsetStep: OffsetStep, reason: state.Update.CommandRejected.RejectionReasonTemplate, )(implicit loggingContext: LoggingContext): Future[PersistenceResponse] = @@ -241,7 +236,7 @@ private[platform] class MeteredLedgerDao(ledgerDao: LedgerDao, metrics: Metrics) override def storeConfigurationEntry( offsetStep: OffsetStep, - recordTime: Instant, + recordTime: Timestamp, submissionId: String, configuration: Configuration, rejectionReason: Option[String], @@ -280,7 +275,7 @@ private[platform] class MeteredLedgerDao(ledgerDao: LedgerDao, metrics: Metrics) override def completeTransaction( completionInfo: Option[state.CompletionInfo], transactionId: Ref.TransactionId, - recordTime: Instant, + recordTime: Timestamp, offsetStep: OffsetStep, )(implicit loggingContext: LoggingContext): Future[PersistenceResponse] = ledgerDao.completeTransaction(completionInfo, transactionId, recordTime, offsetStep) @@ -292,12 +287,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: OffsetStep, 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/entries/LedgerEntry.scala b/ledger/participant-integration-api/src/main/scala/platform/store/entries/LedgerEntry.scala index 45f21fe2ad9b..d097e76ff8ce 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 @@ -4,10 +4,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 +15,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 +30,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-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 75d2d66601d9..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 @@ -85,8 +85,8 @@ package v2 { final case class TransactionMeta( transactionId: TransactionId, offset: LedgerOffset.Absolute, - ledgerEffectiveTime: Instant, - recordTime: Instant, + ledgerEffectiveTime: Timestamp, + recordTime: Timestamp, workflowId: WorkflowId, ) @@ -104,7 +104,7 @@ package v2 { */ final case class PackageDetails( size: Long, - knownSince: Instant, + knownSince: Timestamp, sourceDescription: Option[String], )