Skip to content

Commit

Permalink
participant-state: Remove the Daml-LF transaction and value aliases. …
Browse files Browse the repository at this point in the history
…[KVL-1002] (#10317)

* participant-state: Remove the Daml-LF transaction aliases.

They add nothing.

CHANGELOG_BEGIN
CHANGELOG_END

* participant-state: Move the `ContractInst` alias to where it's used.

Either inlining it or extracting out a similar alias elsewhere.

This further removes dependencies on _participant-state_.

* Fix a couple of typos.

Co-authored-by: Miklos <[email protected]>

Co-authored-by: Miklos <[email protected]>
  • Loading branch information
SamirTalwar and miklos-da authored Jul 19, 2021
1 parent 159728d commit 9a01065
Show file tree
Hide file tree
Showing 36 changed files with 84 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,25 @@ import akka.NotUsed
import akka.stream.scaladsl.Source
import anorm.SqlParser._
import anorm.{BatchSql, Macro, NamedParameter, RowParser, SQL, SqlParser}
import com.daml.ledger.participant.state.v1.{ContractInst, TransactionId}
import com.daml.ledger.api.domain.RejectionReason
import com.daml.ledger.api.domain.RejectionReason._
import com.daml.ledger.participant.state.v1.TransactionId
import com.daml.ledger.{ApplicationId, CommandId, WorkflowId}
import com.daml.lf.data.Ref.Party
import com.daml.lf.data.Relation.Relation
import com.daml.lf.engine.Blinding
import com.daml.lf.transaction.GlobalKey
import com.daml.lf.value.Value
import com.daml.lf.value.Value.ContractId
import com.daml.ledger.api.domain.RejectionReason
import com.daml.ledger.api.domain.RejectionReason._
import com.daml.ledger.{ApplicationId, CommandId, WorkflowId}
import com.daml.platform.store.Contract.ActiveContract
import com.daml.platform.store.Conversions._
import com.daml.platform.store.entries.LedgerEntry
import com.daml.platform.store.serialization.KeyHasher
import com.daml.platform.store.{ActiveLedgerState, ActiveLedgerStateManager, Let, LetLookup}
import com.daml.platform.db.migration.translation.{
ContractSerializer,
TransactionSerializer,
ValueSerializer,
}
import com.daml.platform.store.Contract.ActiveContract
import com.daml.platform.store.Conversions._
import com.daml.platform.store.entries.LedgerEntry
import com.daml.platform.store.serialization.KeyHasher
import com.daml.platform.store.{ActiveLedgerState, ActiveLedgerStateManager, Let, LetLookup}
import org.flywaydb.core.api.migration.{BaseJavaMigration, Context}
import org.slf4j.LoggerFactory

Expand Down Expand Up @@ -328,7 +327,7 @@ private[migration] class V2_1__Rebuild_Acs extends BaseJavaMigration {
override def divulgeAlreadyCommittedContracts(
transactionId: TransactionId,
global: Relation[ContractId, Party],
referencedContracts: List[(Value.ContractId, ContractInst)],
referencedContracts: ActiveLedgerState.ReferencedContracts,
) = {
val divulgenceParams = global
.flatMap { case (cid, parties) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ package com.daml.platform.store

import java.time.Instant

import com.daml.ledger.participant.state.v1.ContractInst
import com.daml.ledger.TransactionId
import com.daml.lf.data.Ref.Party
import com.daml.lf.data.Relation.Relation
import com.daml.lf.transaction.GlobalKey
import com.daml.lf.value.Value
import com.daml.lf.value.Value.ContractId
import com.daml.ledger.TransactionId
import com.daml.platform.store.ActiveLedgerState._
import com.daml.platform.store.Contract.ActiveContract

private[platform] sealed abstract class LetLookup
Expand Down Expand Up @@ -68,12 +68,19 @@ private[platform] trait ActiveLedgerState[ALS <: ActiveLedgerState[ALS]] {
def divulgeAlreadyCommittedContracts(
transactionId: TransactionId,
global: Relation[ContractId, Party],
referencedContracts: List[(Value.ContractId, ContractInst)],
referencedContracts: ReferencedContracts,
): ALS

/** Clone the current active ledger state. The new state starts out
* being identical to the old one but writes to the cloned
* state will not affect the original state and the other way around.
* state will not affect the original state and the other way around.
*/
def cloneState(): ALS
}

object ActiveLedgerState {

type ReferencedContracts =
List[(Value.ContractId, Value.ContractInst[Value.VersionedValue[Value.ContractId]])]

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ import java.time.Instant

import com.daml.ledger.api.domain.RejectionReason
import com.daml.ledger.api.domain.RejectionReason.{Inconsistent, InvalidLedgerTime}
import com.daml.ledger.participant.state.v1.ContractInst
import com.daml.ledger.{TransactionId, WorkflowId}
import com.daml.lf.data.Ref.Party
import com.daml.lf.data.Relation.Relation
import com.daml.lf.transaction.GlobalKey
import com.daml.lf.transaction.{CommittedTransaction, NodeId, Node => N}
import com.daml.lf.value.Value
import com.daml.lf.transaction.{CommittedTransaction, GlobalKey, NodeId, Node => N}
import com.daml.lf.value.Value.ContractId
import com.daml.platform.store.Contract.ActiveContract

Expand Down Expand Up @@ -64,8 +61,8 @@ private[platform] class ActiveLedgerStateManager[ALS <: ActiveLedgerState[ALS]](
copy(currentState = currentState.mapAcs(f), rollbackStates = rollbackStates.map(_.mapAcs(f)))

def result: Either[Set[RejectionReason], ALS] = {
if (!rollbackStates.isEmpty) {
sys.error(s"IMPOSSIBLE finished transaction but rollback states is not empty")
if (rollbackStates.nonEmpty) {
sys.error("IMPOSSIBLE finished transaction but rollback states is not empty")
}
currentState.als match {
case None =>
Expand Down Expand Up @@ -104,7 +101,7 @@ private[platform] class ActiveLedgerStateManager[ALS <: ActiveLedgerState[ALS]](
transaction: CommittedTransaction,
disclosure: Relation[NodeId, Party],
divulgence: Relation[ContractId, Party],
divulgedContracts: List[(Value.ContractId, ContractInst)],
divulgedContracts: ActiveLedgerState.ReferencedContracts,
): Either[Set[RejectionReason], ALS] = {
// If some node requires a contract, check that we have that contract, and check that that contract is not
// created after the current let.
Expand Down Expand Up @@ -217,7 +214,7 @@ private[platform] class ActiveLedgerStateManager[ALS <: ActiveLedgerState[ALS]](
} else {
state.copy(
errs = state.errs + Inconsistent(
s"Contract key lookup with different results: expected [${nlkup.result}], actual [${currentResult}]"
s"Contract key lookup with different results: expected [${nlkup.result}], actual [$currentResult]"
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.daml.ledger.{TransactionId, WorkflowId}
import com.daml.lf.archive.ArchiveParser
import com.daml.lf.data.{Ref, Time}
import com.daml.lf.engine.ValueEnricher
import com.daml.lf.transaction.BlindingInfo
import com.daml.lf.transaction.{BlindingInfo, CommittedTransaction}
import com.daml.logging.LoggingContext.withEnrichedLoggingContext
import com.daml.logging.entries.LoggingEntry
import com.daml.logging.{ContextualizedLogger, LoggingContext}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ package com.daml.platform.store.appendonlydao.events
import java.sql.Connection
import java.time.Instant

import com.daml.ledger.participant.state.v1.{CommittedTransaction, RejectionReasonV0}
import com.daml.ledger.participant.state.v1.RejectionReasonV0
import com.daml.lf.transaction.CommittedTransaction
import com.daml.platform.store.backend.{ContractStorageBackend, PartyStorageBackend}

/** Performs post-commit validation on transactions for Sandbox Classic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import com.daml.lf.archive.ArchiveParser
import com.daml.lf.data.Ref
import com.daml.lf.data.Ref.{PackageId, Party}
import com.daml.lf.engine.ValueEnricher
import com.daml.lf.transaction.BlindingInfo
import com.daml.lf.transaction.{BlindingInfo, CommittedTransaction}
import com.daml.logging.LoggingContext.withEnrichedLoggingContext
import com.daml.logging.entries.LoggingEntry
import com.daml.logging.{ContextualizedLogger, LoggingContext}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.daml.ledger.participant.state.v1._
import com.daml.ledger.{ApplicationId, WorkflowId}
import com.daml.lf.data.Ref
import com.daml.lf.data.Ref.{PackageId, Party}
import com.daml.lf.transaction.BlindingInfo
import com.daml.lf.transaction.{BlindingInfo, CommittedTransaction}
import com.daml.logging.LoggingContext
import com.daml.platform.indexer.OffsetStep
import com.daml.platform.store.dao.events.TransactionsWriter.PreparedInsert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import com.daml.ledger.participant.state.v1._
import com.daml.ledger.{TransactionId, WorkflowId}
import com.daml.lf.data.Ref
import com.daml.lf.data.Ref.{PackageId, Party}
import com.daml.lf.transaction.BlindingInfo
import com.daml.lf.transaction.{BlindingInfo, CommittedTransaction}
import com.daml.logging.LoggingContext
import com.daml.metrics.{Metrics, Timed}
import com.daml.platform.indexer.OffsetStep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ package com.daml.platform.store.dao.events
import java.sql.Connection
import java.time.Instant

import com.daml.ledger.participant.state.v1.{CommittedTransaction, RejectionReasonV0}
import com.daml.ledger.participant.state.v1.RejectionReasonV0
import com.daml.lf.transaction.CommittedTransaction

/** Performs post-commit validation on transactions for Sandbox Classic.
* This is intended exclusively as a temporary replacement for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ package com.daml.platform.store.dao.events
import java.time.Instant

import com.daml.ledger.offset.Offset
import com.daml.ledger.participant.state.v1.{DivulgedContract, SubmitterInfo}
import com.daml.ledger.{TransactionId, WorkflowId}
import com.daml.ledger.participant.state.v1.{CommittedTransaction, DivulgedContract, SubmitterInfo}
import com.daml.lf.ledger.EventId
import com.daml.lf.transaction.BlindingInfo
import com.daml.lf.transaction.{BlindingInfo, CommittedTransaction}
import com.daml.platform.store.serialization.Compression

import scala.collection.compat._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import java.time.Instant

import anorm.{Row, SimpleSql}
import com.daml.ledger.offset.Offset
import com.daml.ledger.participant.state.v1.{CommittedTransaction, DivulgedContract, SubmitterInfo}
import com.daml.ledger.participant.state.v1.{DivulgedContract, SubmitterInfo}
import com.daml.ledger.{TransactionId, WorkflowId}
import com.daml.lf.engine.Blinding
import com.daml.lf.transaction.BlindingInfo
import com.daml.lf.transaction.{BlindingInfo, CommittedTransaction}
import com.daml.metrics.{Metrics, Timed}
import com.daml.platform.store.DbType

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import com.daml.lf.data.{FrontStack, ImmArray, Ref, Time}
import com.daml.lf.transaction.Node._
import com.daml.lf.transaction._
import com.daml.lf.transaction.test.TransactionBuilder
import com.daml.lf.value.Value.{ContractId, ContractInst, ValueText}
import com.daml.lf.value.Value.{ContractId, ContractInst, ValueText, VersionedValue}
import com.daml.lf.value.{Value => LfValue}
import com.daml.logging.LoggingContext
import com.daml.platform.indexer.{CurrentOffset, IncrementalOffsetStep, OffsetStep}
import com.daml.platform.store.dao.JdbcLedgerDaoSuite._
import com.daml.platform.store.dao.events.TransactionsWriter
import com.daml.platform.store.entries.LedgerEntry
import org.scalatest.AsyncTestSuite
Expand Down Expand Up @@ -652,7 +653,7 @@ private[dao] trait JdbcLedgerDaoSuite extends JdbcLedgerDaoBackend {
)

protected final def store(
divulgedContracts: Map[(ContractId, v1.ContractInst), Set[Party]],
divulgedContracts: DivulgedContracts,
blindingInfo: Option[BlindingInfo],
offsetAndTx: (Offset, LedgerEntry.Transaction),
): Future[(Offset, LedgerEntry.Transaction)] =
Expand All @@ -663,7 +664,7 @@ private[dao] trait JdbcLedgerDaoSuite extends JdbcLedgerDaoBackend {
)

protected final def storeOffsetStepAndTx(
divulgedContracts: Map[(ContractId, v1.ContractInst), Set[Party]],
divulgedContracts: DivulgedContracts,
blindingInfo: Option[BlindingInfo],
offsetStepAndTx: (OffsetStep, LedgerEntry.Transaction),
): Future[(Offset, LedgerEntry.Transaction)] = {
Expand Down Expand Up @@ -885,16 +886,19 @@ private[dao] trait JdbcLedgerDaoSuite extends JdbcLedgerDaoBackend {

object JdbcLedgerDaoSuite {

import scalaz.syntax.traverse._
import scalaz.{Free, Monad, NaturalTransformation, Traverse}
private type DivulgedContracts =
Map[(ContractId, ContractInst[VersionedValue[ContractId]]), Set[Party]]

implicit final class `TraverseFM Ops`[T[_], A](private val self: T[A]) extends AnyVal {

import scalaz.syntax.traverse._
import scalaz.{Free, Monad, NaturalTransformation, Traverse}

/** Like `traverse`, but guarantees that
*
* - `f` is evaluated left-to-right, and
* - `B` from the preceding element is evaluated before `f` is invoked for
* the subsequent `A`.
* the subsequent `A`.
*/
def traverseFM[F[_]: Monad, B](f: A => F[B])(implicit T: Traverse[T]): F[T[B]] =
self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ import com.daml.ledger.participant.state.v1.Update.{
import com.daml.ledger.participant.state.v1._
import com.daml.ledger.resources.TestResourceContext
import com.daml.lf.data.{Bytes, ImmArray, Ref, Time}
import com.daml.lf.transaction.{BlindingInfo, NodeId, TransactionVersion, VersionedTransaction}
import com.daml.lf.transaction.{
BlindingInfo,
CommittedTransaction,
NodeId,
TransactionVersion,
VersionedTransaction,
}
import com.daml.lf.value.Value.ContractId
import com.daml.lf.{crypto, transaction}
import com.daml.logging.LoggingContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.daml.ledger.configuration.Configuration
import com.daml.ledger.offset.Offset
import com.daml.ledger.participant.state.v1._
import com.daml.lf.data.{Ref, Time}
import com.daml.lf.transaction.SubmittedTransaction
import com.daml.metrics.{Metrics, Timed}
import com.daml.telemetry.TelemetryContext

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.daml.ledger.participant.state.kvutils.DamlKvutils._
import com.daml.ledger.participant.state.v1._
import com.daml.lf.data.Ref
import com.daml.lf.data.Time.Timestamp
import com.daml.lf.transaction.SubmittedTransaction
import com.daml.lf.value.Value.ContractId
import com.daml.metrics.Metrics
import com.google.protobuf.ByteString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.daml.ledger.configuration.{Configuration, LedgerInitialConditions}
import com.daml.ledger.offset.Offset
import com.daml.ledger.participant.state.v1._
import com.daml.lf.data.{Ref, Time}
import com.daml.lf.transaction.SubmittedTransaction
import com.daml.metrics.Metrics
import com.daml.telemetry.TelemetryContext

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.daml.ledger.participant.state.kvutils.DamlKvutils.DamlSubmission
import com.daml.ledger.participant.state.kvutils.{Envelope, KeyValueSubmission}
import com.daml.ledger.participant.state.v1._
import com.daml.lf.data.{Ref, Time}
import com.daml.lf.transaction.SubmittedTransaction
import com.daml.metrics.Metrics
import com.daml.telemetry.TelemetryContext

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import com.daml.lf.data.Time.Timestamp
import com.daml.lf.data.{ImmArray, Ref}
import com.daml.lf.engine.Engine
import com.daml.lf.language.Ast
import com.daml.lf.transaction.Transaction
import com.daml.lf.transaction.{SubmittedTransaction, Transaction}
import com.daml.logging.LoggingContext
import com.daml.metrics.Metrics
import scalaz.std.list._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ import com.daml.lf.value.Value
*/
final case class DivulgedContract(
contractId: Value.ContractId,
contractInst: ContractInst,
contractInst: Value.ContractInst[Value.VersionedValue[Value.ContractId]],
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package com.daml.ledger.participant.state.v1

import com.daml.lf.crypto
import com.daml.lf.data.{ImmArray, Ref, Time}
import com.daml.lf.transaction.NodeId

/** Meta-data of a transaction visible to all parties that can see a part of
* the transaction.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.daml.daml_lf_dev.DamlLf
import com.daml.ledger.configuration.Configuration
import com.daml.lf.data.Ref
import com.daml.lf.data.Time.Timestamp
import com.daml.lf.transaction.BlindingInfo
import com.daml.lf.transaction.{BlindingInfo, CommittedTransaction}

/** An update to the (abstract) participant state.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package com.daml.ledger.participant.state.v1
import java.util.concurrent.CompletionStage

import com.daml.ledger.api.health.ReportsHealth
import com.daml.lf.transaction.SubmittedTransaction
import com.daml.telemetry.TelemetryContext

/** An interface to change a ledger via a participant.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
package com.daml.ledger.participant.state

import com.daml.lf.data.Ref
import com.daml.lf.transaction
import com.daml.lf.value.Value

/** Interfaces to read from and write to an (abstract) participant state.
*
Expand Down Expand Up @@ -76,24 +74,4 @@ package object v1 {
val SubmissionId: Ref.LedgerString.type = Ref.LedgerString
type SubmissionId = Ref.LedgerString

/** Identifiers for nodes in a transaction. */
type NodeId = transaction.NodeId

/** A transaction with contract IDs that may require suffixing.
*
* See the Contract Id specification for more detail daml-lf/spec/contract-id.rst
*/
type SubmittedTransaction = transaction.SubmittedTransaction

/** A transaction with globally unique contract IDs.
*
* Used to communicate transactions that have been accepted to the ledger.
* See the Contract Id specification for more detail daml-lf/spec/contract-id.rst
*/
type CommittedTransaction = transaction.CommittedTransaction

/** A contract instance. */
type ContractInst =
Value.ContractInst[Value.VersionedValue[Value.ContractId]]

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.daml.ledger.configuration.Configuration
import com.daml.ledger.offset.Offset
import com.daml.ledger.participant.state.v1
import com.daml.lf.data.{Ref, Time}
import com.daml.lf.transaction.SubmittedTransaction
import com.daml.telemetry.TelemetryContext
import com.google.rpc.code.Code
import com.google.rpc.error_details.ErrorInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ import com.daml.lf.value.Value
*/
final case class DivulgedContract(
contractId: Value.ContractId,
contractInst: ContractInst,
contractInst: Value.ContractInst[Value.VersionedValue[Value.ContractId]],
)
Loading

0 comments on commit 9a01065

Please sign in to comment.