LAPI code cleanup (pure refactoring) (#12768)

removing dead code

changelog_begin
changelog_end
This commit is contained in:
Marton Nagy 2022-02-07 13:43:06 +01:00 committed by GitHub
parent 79fd012508
commit cbff4b124a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 3 additions and 194 deletions

View File

@ -364,7 +364,6 @@ final class Metrics(val registry: MetricRegistry) {
val listKnownParties: Timer = registry.timer(Prefix :+ "list_known_parties")
val listLfPackages: Timer = registry.timer(Prefix :+ "list_lf_packages")
val getLfArchive: Timer = registry.timer(Prefix :+ "get_lf_archive")
val getLfPackage: Timer = registry.timer(Prefix :+ "get_lf_package")
val prune: Timer = registry.timer(Prefix :+ "prune")
val getTransactionMetering: Timer = registry.timer(Prefix :+ "get_transaction_metering")
@ -637,7 +636,6 @@ final class Metrics(val registry: MetricRegistry) {
val listLfPackages: Timer = registry.timer(Prefix :+ "list_lf_packages")
val getLfArchive: Timer = registry.timer(Prefix :+ "get_lf_archive")
val getLfPackage: Timer = registry.timer(Prefix :+ "get_lf_package")
val packageEntries: Timer = registry.timer(Prefix :+ "package_entries")
val getLedgerConfiguration: Timer = registry.timer(Prefix :+ "get_ledger_configuration")
val currentLedgerEnd: Timer = registry.timer(Prefix :+ "current_ledger_end")

View File

@ -24,7 +24,6 @@ import com.daml.ledger.participant.state.index.v2.{IndexService, MeteringStore}
import com.daml.lf.data.Ref
import com.daml.lf.data.Ref.ApplicationId
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
import com.daml.logging.LoggingContext
@ -44,11 +43,6 @@ private[daml] final class SpannedIndexService(delegate: IndexService) extends In
): Future[Option[DamlLf.Archive]] =
delegate.getLfArchive(packageId)
override def getLfPackage(packageId: Ref.PackageId)(implicit
loggingContext: LoggingContext
): Future[Option[Ast.Package]] =
delegate.getLfPackage(packageId)
override def packageEntries(
startExclusive: Option[LedgerOffset.Absolute]
)(implicit loggingContext: LoggingContext): Source[domain.PackageEntry, NotUsed] =

View File

@ -24,7 +24,6 @@ import com.daml.ledger.participant.state.index.v2.{IndexService, MeteringStore}
import com.daml.lf.data.Ref
import com.daml.lf.data.Ref.{ApplicationId, 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
import com.daml.logging.LoggingContext
@ -45,11 +44,6 @@ private[daml] final class TimedIndexService(delegate: IndexService, metrics: Met
): Future[Option[DamlLf.Archive]] =
Timed.future(metrics.daml.services.index.getLfArchive, delegate.getLfArchive(packageId))
override def getLfPackage(packageId: Ref.PackageId)(implicit
loggingContext: LoggingContext
): Future[Option[Ast.Package]] =
Timed.future(metrics.daml.services.index.getLfPackage, delegate.getLfPackage(packageId))
override def packageEntries(
startExclusive: Option[LedgerOffset.Absolute]
)(implicit loggingContext: LoggingContext): Source[domain.PackageEntry, NotUsed] =

View File

@ -34,7 +34,6 @@ import com.daml.ledger.participant.state.index.v2._
import com.daml.lf.data.Ref
import com.daml.lf.data.Ref.{ApplicationId, 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}
import com.daml.logging.{ContextualizedLogger, LoggingContext}
@ -214,11 +213,6 @@ private[platform] final class LedgerBackedIndexService(
): Future[Option[Archive]] =
ledger.getLfArchive(packageId)
override def getLfPackage(packageId: PackageId)(implicit
loggingContext: LoggingContext
): Future[Option[Ast.Package]] =
ledger.getLfPackage(packageId)
override def lookupActiveContract(
readers: Set[Party],
contractId: ContractId,

View File

@ -23,7 +23,6 @@ import com.daml.ledger.participant.state.index.v2.PackageDetails
import com.daml.lf.data.Ref
import com.daml.lf.data.Ref.ApplicationId
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}
import com.daml.logging.LoggingContext
@ -140,11 +139,6 @@ private[platform] class MeteredReadOnlyLedger(ledger: ReadOnlyLedger, metrics: M
): Future[Option[Archive]] =
Timed.future(metrics.daml.index.getLfArchive, ledger.getLfArchive(packageId))
override def getLfPackage(packageId: Ref.PackageId)(implicit
loggingContext: LoggingContext
): Future[Option[Ast.Package]] =
Timed.future(metrics.daml.index.getLfPackage, ledger.getLfPackage(packageId))
override def packageEntries(
startExclusive: Offset
)(implicit loggingContext: LoggingContext): Source[(Offset, PackageLedgerEntry), NotUsed] =

View File

@ -21,10 +21,8 @@ import com.daml.ledger.configuration.Configuration
import com.daml.ledger.offset.Offset
import com.daml.ledger.participant.state.index.v2
import com.daml.ledger.participant.state.index.v2.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}
import com.daml.logging.LoggingContext
@ -35,8 +33,7 @@ import com.daml.platform.store.appendonlydao.{LedgerDaoTransactionsReader, Ledge
import com.daml.ledger.participant.state.index.v2.MeteringStore.TransactionMetering
import com.daml.platform.store.entries.{ConfigurationEntry, PackageLedgerEntry, PartyLedgerEntry}
import scala.concurrent.{ExecutionContext, Future}
import scala.util.Try
import scala.concurrent.Future
private[platform] abstract class BaseLedger(
val ledgerId: LedgerId,
@ -156,15 +153,6 @@ private[platform] abstract class BaseLedger(
): Future[Option[DamlLf.Archive]] =
ledgerDao.getLfArchive(packageId)
override def getLfPackage(packageId: Ref.PackageId)(implicit
loggingContext: LoggingContext
): Future[Option[Ast.Package]] =
ledgerDao
.getLfArchive(packageId)
.flatMap(archiveO =>
Future.fromTry(Try(archiveO.map(archive => Decode.assertDecodeArchive(archive)._2)))
)(ExecutionContext.parasitic)
override def packageEntries(startExclusive: Offset)(implicit
loggingContext: LoggingContext
): Source[(Offset, PackageLedgerEntry), NotUsed] =

View File

@ -22,7 +22,6 @@ import com.daml.ledger.participant.state.index.v2.MeteringStore.TransactionMeter
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.language.Ast
import com.daml.lf.transaction.GlobalKey
import com.daml.lf.value.Value.{ContractId, VersionedContractInstance}
import com.daml.logging.LoggingContext
@ -108,10 +107,6 @@ private[platform] trait ReadOnlyLedger extends ReportsHealth with AutoCloseable
loggingContext: LoggingContext
): Future[Option[Archive]]
def getLfPackage(packageId: Ref.PackageId)(implicit
loggingContext: LoggingContext
): Future[Option[Ast.Package]]
def packageEntries(startExclusive: Offset)(implicit
loggingContext: LoggingContext
): Source[(Offset, PackageLedgerEntry), NotUsed]

View File

@ -149,17 +149,6 @@ private[appendonlydao] sealed class ContractsReader(
),
)
}
override def lookupContractKey(
key: Key,
readers: Set[Party],
)(implicit loggingContext: LoggingContext): Future[Option[ContractId]] =
Timed.future(
metrics.daml.index.db.lookupKey,
dispatcher.executeSql(metrics.daml.index.db.lookupContractByKeyDbMetrics)(
storageBackend.contractKey(readers, key)
),
)
}
private[appendonlydao] object ContractsReader {

View File

@ -1,61 +0,0 @@
// Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package com.daml.platform.store.cache
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
import scala.concurrent.Future
class TranslationCacheBackedContractStore(
lfValueTranslationCache: LfValueTranslationCache.Cache,
contractsReader: LedgerDaoContractsReader,
) extends ContractStore {
override def lookupActiveContract(
readers: Set[Party],
contractId: ContractId,
)(implicit loggingContext: LoggingContext): Future[Option[Contract]] =
lfValueTranslationCache.contracts
.getIfPresent(LfValueTranslationCache.ContractCache.Key(contractId)) match {
case Some(createArgument) =>
contractsReader.lookupActiveContractWithCachedArgument(
readers,
contractId,
createArgument.argument,
)
case None =>
contractsReader.lookupActiveContractAndLoadArgument(readers, contractId)
}
override def lookupContractKey(readers: Set[Party], key: Key)(implicit
loggingContext: LoggingContext
): Future[Option[ContractId]] =
contractsReader.lookupContractKey(key, readers)
/** @return The maximum ledger effective time of all contracts in ids, fails as follows:
* - if ids is empty or not all the non-divulged ids can be found, a failed [[Future]]
* - if all ids are found but each refer to a divulged contract, a successful [[None]]
*/
override def lookupMaximumLedgerTime(ids: Set[ContractId])(implicit
loggingContext: LoggingContext
): Future[Option[Timestamp]] =
contractsReader.lookupMaximumLedgerTime(ids)
}
object TranslationCacheBackedContractStore {
def owner(
lfValueTranslationCache: LfValueTranslationCache.Cache,
contractsReader: LedgerDaoContractsReader,
): Resource[TranslationCacheBackedContractStore] =
Resource.successful(
new TranslationCacheBackedContractStore(
lfValueTranslationCache,
contractsReader,
)
)
}

View File

@ -48,17 +48,6 @@ private[platform] trait LedgerDaoContractsReader {
createArgument: Value,
)(implicit loggingContext: LoggingContext): Future[Option[Contract]]
/** Looks up a Contract given a contract key and a party
*
* @param key the contract key to query
* @param forParties a set of parties for one of which the contract must be visible
* @return the optional [[ContractId]]
*/
def lookupContractKey(
key: GlobalKey,
forParties: Set[Party],
)(implicit loggingContext: LoggingContext): Future[Option[ContractId]]
/** Looks up the contract by id at a specific ledger event sequential id.
*
* @param contractId the contract id to query

View File

@ -7,9 +7,7 @@ import com.daml.lf.crypto.Hash
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, ValueText, VersionedContractInstance}
import com.daml.lf.value.Value.{ContractId, VersionedContractInstance}
import com.daml.platform.apiserver.execution.MissingContracts
import org.scalatest.flatspec.AsyncFlatSpec
import org.scalatest.matchers.should.Matchers
@ -111,59 +109,6 @@ private[dao] trait JdbcLedgerDaoContractsSpec extends LoneElement with Inside wi
}
}
it should "not find keys if none of requesters are stakeholders" in {
val aTextValue = ValueText(scala.util.Random.nextString(10))
for {
(_, _) <- createAndStoreContract(
submittingParties = Set(alice),
signatories = Set(alice, bob),
stakeholders = Set(alice, bob),
key = Some(KeyWithMaintainers(aTextValue, Set(alice, bob))),
)
key = GlobalKey.assertBuild(someTemplateId, aTextValue)
result <- contractsReader.lookupContractKey(key, Set(charlie, emma))
} yield {
result shouldBe None
}
}
it should "find a key if at least one of requesters is a stakeholder" in {
val aTextValue = ValueText(scala.util.Random.nextString(10))
for {
(_, tx) <- createAndStoreContract(
submittingParties = Set(alice),
signatories = Set(alice, bob),
stakeholders = Set(alice, bob, charlie),
key = Some(KeyWithMaintainers(aTextValue, Set(alice, bob))),
)
contractId = nonTransient(tx).loneElement
key = GlobalKey.assertBuild(someTemplateId, aTextValue)
result <- contractsReader.lookupContractKey(key, Set(emma, charlie))
} yield {
result.value shouldBe contractId
}
}
it should "not find a key if the requesters are only divulgees" in {
val aTextValue = ValueText(scala.util.Random.nextString(10))
for {
(_, tx) <- createAndStoreContract(
submittingParties = Set(alice),
signatories = Set(alice, bob),
stakeholders = Set(alice, bob, charlie),
key = Some(KeyWithMaintainers(aTextValue, Set(alice, bob))),
)
_ <- storeCommitedContractDivulgence(
id = nonTransient(tx).loneElement,
divulgees = Set(david, emma),
)
key = GlobalKey.assertBuild(someTemplateId, aTextValue)
result <- contractsReader.lookupContractKey(key, Set(david, emma))
} yield {
result shouldBe None
}
}
it should "prevent retrieving the maximum ledger time if some contracts are not found" in {
val randomContractId = ContractId.V1(Hash.hashPrivateKey(UUID.randomUUID.toString))
for {

View File

@ -517,10 +517,6 @@ object MutableCacheBackedContractStoreSpec {
case (`cId_2`, parties) if parties.contains(charlie) => Future.successful(Some(contract2))
case _ => Future.successful(Option.empty)
}
override def lookupContractKey(key: Key, forParties: Set[Party])(implicit
loggingContext: LoggingContext
): Future[Option[ContractId]] = throw new RuntimeException("This method should not be called")
}
private def activeContract(

View File

@ -23,7 +23,6 @@ da_scala_library(
deps = [
"//daml-lf/archive:daml_lf_1.dev_archive_proto_java",
"//daml-lf/data",
"//daml-lf/language",
"//daml-lf/transaction",
"//ledger-api/grpc-definitions:ledger_api_proto_scala",
"//ledger/ledger-api-domain",

View File

@ -20,6 +20,7 @@ trait IndexCompletionsService extends LedgerEndService {
parties: Set[Ref.Party],
)(implicit loggingContext: LoggingContext): Source[CompletionStreamResponse, NotUsed]
// TODO Remove, as possible. This is solely serving KV Deduplication Offset -> Duration conversion
def getCompletions(
startExclusive: LedgerOffset,
endInclusive: LedgerOffset,

View File

@ -8,7 +8,6 @@ import akka.stream.scaladsl.Source
import com.daml.daml_lf_dev.DamlLf.Archive
import com.daml.ledger.api.domain.{LedgerOffset, PackageEntry}
import com.daml.lf.data.Ref.PackageId
import com.daml.lf.language.Ast.Package
import com.daml.logging.LoggingContext
import scala.concurrent.Future
@ -25,11 +24,6 @@ trait IndexPackagesService {
packageId: PackageId
)(implicit loggingContext: LoggingContext): Future[Option[Archive]]
/** Like [[getLfArchive]], but already parsed. */
def getLfPackage(
packageId: PackageId
)(implicit loggingContext: LoggingContext): Future[Option[Package]]
def packageEntries(
startExclusive: Option[LedgerOffset.Absolute]
)(implicit loggingContext: LoggingContext): Source[PackageEntry, NotUsed]