From af3cd7a3eeb9e398a25039f1e7f742dfc7eb0b82 Mon Sep 17 00:00:00 2001 From: Moritz Kiefer Date: Wed, 13 Oct 2021 08:37:35 +0200 Subject: [PATCH 01/13] Reduce default assignees (#11219) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stefano is bored so now he’s responsible for everything changelog_begin changelog_end --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- .github/ISSUE_TEMPLATE/feature_request.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index ab0dadd42fc2..3b232b786481 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -3,7 +3,7 @@ name: Bug report about: Create a report to help Daml improve title: "[BUG] " labels: '' -assignees: stefanobaghino-da, cocreature, gerolf-da, adriaanm-da +assignees: stefanobaghino-da --- diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 2d77ebeec7d8..37e14e9d5c86 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -3,7 +3,7 @@ name: Feature request about: Suggest an idea to improve Daml title: "[FEATURE REQUEST] " labels: '' -assignees: stefanobaghino-da, cocreature, gerolf-da, adriaanm-da +assignees: stefanobaghino-da --- From b942011336112598270688f748c662adee649c9f Mon Sep 17 00:00:00 2001 From: "azure-pipelines[bot]" <36771401+azure-pipelines[bot]@users.noreply.github.com> Date: Wed, 13 Oct 2021 06:58:58 +0000 Subject: [PATCH 02/13] update NOTICES file (#11225) CHANGELOG_BEGIN CHANGELOG_END Co-authored-by: Azure Pipelines DAML Build --- NOTICES | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NOTICES b/NOTICES index bfbd0642d447..875874194b44 100644 --- a/NOTICES +++ b/NOTICES @@ -100,7 +100,7 @@ ASM 5.0.4 : BSD 3-clause "New" or "Revised" License asn1-encoding 0.9.6 : BSD 3-clause "New" or "Revised" License asn1-parse 0.9.5 : BSD 3-clause "New" or "Revised" License asn1-types 0.3.4 : BSD 3-clause "New" or "Revised" License -asn1.js-rfc2560 v5.4.1 : MIT License +asn1.js v5.4.1 : MIT License assoc 1.0.2 : BSD 3-clause "New" or "Revised" License Async 0.9.2 : MIT License Async 1.5.2 : MIT License @@ -10549,7 +10549,7 @@ SOFTWARE --- MIT License -(asn1.js-rfc2560 v5.4.1) +(asn1.js v5.4.1) MIT License From e3ae424682f4bf04edc8e9d360308eafc2bb3968 Mon Sep 17 00:00:00 2001 From: nicu-da Date: Wed, 13 Oct 2021 01:15:17 -0700 Subject: [PATCH 03/13] Extract party_allocation.proto from daml_kvutils.proto [KVL-1090] (#11213) CHANGELOG_BEGIN CHANGELOG_END --- .../state/kvutils/daml_kvutils.proto | 36 -------------- .../store/events/party_allocation.proto | 47 +++++++++++++++++++ .../state/kvutils/store/log_entry.proto | 5 +- .../state/kvutils/wire/submission.proto | 4 +- .../state/kvutils/KeyValueConsumption.scala | 1 + .../state/kvutils/KeyValueSubmission.scala | 6 ++- .../committer/PartyAllocationCommitter.scala | 4 ++ .../daml/ledger/validator/TestHelper.scala | 2 +- .../state/kvutils/KVUtilsPartySpec.scala | 2 +- .../kvutils/KeyValueConsumptionSpec.scala | 2 + .../KeyValueParticipantStateReaderSpec.scala | 2 +- .../kvutils/committer/CommitterSpec.scala | 6 ++- .../PartyAllocationCommitterSpec.scala | 2 +- .../RawPreExecutingCommitStrategySpec.scala | 2 +- .../LogAppendingReadServiceFactorySpec.scala | 2 +- ...reExecutingCommitStrategySupportSpec.scala | 2 +- .../RawWriteSetComparisonSpec.scala | 6 ++- 17 files changed, 78 insertions(+), 53 deletions(-) create mode 100644 ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/events/party_allocation.proto diff --git a/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/daml_kvutils.proto b/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/daml_kvutils.proto index 920589dea9cf..7290435387ae 100644 --- a/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/daml_kvutils.proto +++ b/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/daml_kvutils.proto @@ -41,42 +41,6 @@ message DamlConfigurationRejectionEntry { } } -// An allocation of party name and assignment of a party to a given -// participant. -// A party can only be hosted once (this may not be true in more -// sophisticated ledgers in the future). -message DamlPartyAllocationEntry { - // A unique string scoped to a particular participant. - // Implementers are free to select adequate mechanism e.g. UUID or similar. - string submission_id = 1; - - // The party name to be allocated. - string party = 2; - - // Allocating participant's id. - string participant_id = 3; - - // A display name associated with the given party. - string display_name = 4; -} - -// A message indicating that party allocation was unsuccessful. -message DamlPartyAllocationRejectionEntry { - // An id selected by the submitter, can be used for matching rejection with - // the original upload entry. - string submission_id = 1; - - // Uploading participant's id. - string participant_id = 2; - - oneof reason { - AlreadyExists already_exists = 3; - Invalid invalid_name = 4; - ParticipantNotAuthorized participant_not_authorized = 5; - Duplicate duplicate_submission = 6; - } -} - // Errors // diff --git a/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/events/party_allocation.proto b/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/events/party_allocation.proto new file mode 100644 index 000000000000..16542a214417 --- /dev/null +++ b/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/events/party_allocation.proto @@ -0,0 +1,47 @@ +// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +syntax = "proto3"; + +package com.daml.ledger.participant.state.kvutils.store.events; + +option java_package = "com.daml.ledger.participant.state.kvutils.store.events"; +option java_multiple_files = true; +option csharp_namespace = "Com.Daml.Ledger.Participant.State.KVUtils.Store.Events"; + +import "com/daml/ledger/participant/state/kvutils/daml_kvutils.proto"; + +// An allocation of party name and assignment of a party to a given +// participant. +// A party can only be hosted once (this may not be true in more +// sophisticated ledgers in the future). +message DamlPartyAllocationEntry { + // A unique string scoped to a particular participant. + // Implementers are free to select adequate mechanism e.g. UUID or similar. + string submission_id = 1; + + // The party name to be allocated. + string party = 2; + + // Allocating participant's id. + string participant_id = 3; + + // A display name associated with the given party. + string display_name = 4; +} + +// A message indicating that party allocation was unsuccessful. +message DamlPartyAllocationRejectionEntry { + // An id selected by the submitter, can be used for matching rejection with + // the original upload entry. + string submission_id = 1; + + // Uploading participant's id. + string participant_id = 2; + + oneof reason { + AlreadyExists already_exists = 3; + Invalid invalid_name = 4; + ParticipantNotAuthorized participant_not_authorized = 5; + Duplicate duplicate_submission = 6; + } +} diff --git a/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/log_entry.proto b/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/log_entry.proto index cfe9c1f1b16e..0a6ec8f1a086 100644 --- a/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/log_entry.proto +++ b/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/log_entry.proto @@ -14,6 +14,7 @@ import "google/protobuf/timestamp.proto"; import "com/daml/ledger/participant/state/kvutils/daml_kvutils.proto"; import "com/daml/ledger/participant/state/kvutils/store/events/configuration.proto"; import "com/daml/ledger/participant/state/kvutils/store/events/package_upload.proto"; +import "com/daml/ledger/participant/state/kvutils/store/events/party_allocation.proto"; import "com/daml/ledger/participant/state/kvutils/store/events/transaction.proto"; // A log entry for a committed Daml submission. @@ -49,10 +50,10 @@ message DamlLogEntry { DamlConfigurationRejectionEntry configuration_rejection_entry = 7; // Allocation of a new Daml party and its assignment to a participant. - DamlPartyAllocationEntry party_allocation_entry = 8; + com.daml.ledger.participant.state.kvutils.store.events.DamlPartyAllocationEntry party_allocation_entry = 8; // A rejection of party allocation request. - DamlPartyAllocationRejectionEntry party_allocation_rejection_entry = 9; + com.daml.ledger.participant.state.kvutils.store.events.DamlPartyAllocationRejectionEntry party_allocation_rejection_entry = 9; // A rejection of a pre-executed submission because of out-of-time-bounds. DamlOutOfTimeBoundsEntry out_of_time_bounds_entry = 10; diff --git a/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/wire/submission.proto b/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/wire/submission.proto index 340dff2b5861..ff2cff110bc1 100644 --- a/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/wire/submission.proto +++ b/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/wire/submission.proto @@ -7,9 +7,9 @@ option java_package = "com.daml.ledger.participant.state.kvutils.wire"; option java_multiple_files = true; option csharp_namespace = "Com.Daml.Ledger.Participant.State.KVUtils.Wire"; -import "com/daml/ledger/participant/state/kvutils/daml_kvutils.proto"; import "com/daml/ledger/participant/state/kvutils/store/state.proto"; import "com/daml/ledger/participant/state/kvutils/store/events/package_upload.proto"; +import "com/daml/ledger/participant/state/kvutils/store/events/party_allocation.proto"; import "com/daml/ledger/participant/state/kvutils/store/events/transaction.proto"; import "com/daml/ledger/participant/state/kvutils/wire/configuration_submission.proto"; @@ -22,7 +22,7 @@ message DamlSubmission { com.daml.ledger.participant.state.kvutils.store.events.DamlTransactionEntry transaction_entry = 2; com.daml.ledger.participant.state.kvutils.store.events.DamlPackageUploadEntry package_upload_entry = 3; DamlConfigurationSubmission configuration_submission = 4; - DamlPartyAllocationEntry party_allocation_entry = 5; + com.daml.ledger.participant.state.kvutils.store.events.DamlPartyAllocationEntry party_allocation_entry = 5; } bytes submission_seed = 6; } diff --git a/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/KeyValueConsumption.scala b/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/KeyValueConsumption.scala index aa34c26bc28c..3ec0b6a431d7 100644 --- a/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/KeyValueConsumption.scala +++ b/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/KeyValueConsumption.scala @@ -9,6 +9,7 @@ import com.daml.ledger.participant.state.kvutils.Conversions._ import com.daml.ledger.participant.state.kvutils.DamlKvutils._ import com.daml.ledger.participant.state.kvutils.store.events.PackageUpload.DamlPackageUploadRejectionEntry import com.daml.ledger.participant.state.kvutils.store.events.{ + DamlPartyAllocationRejectionEntry, DamlTransactionBlindingInfo, DamlTransactionEntry, DamlTransactionRejectionEntry, diff --git a/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/KeyValueSubmission.scala b/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/KeyValueSubmission.scala index 1d6d0657c43b..89b30ab68afc 100644 --- a/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/KeyValueSubmission.scala +++ b/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/KeyValueSubmission.scala @@ -6,10 +6,12 @@ package com.daml.ledger.participant.state.kvutils import com.daml.daml_lf_dev.DamlLf.Archive import com.daml.ledger.configuration.Configuration import com.daml.ledger.participant.state.kvutils.Conversions._ -import com.daml.ledger.participant.state.kvutils.DamlKvutils._ import com.daml.ledger.participant.state.kvutils.store.DamlStateKey -import com.daml.ledger.participant.state.kvutils.store.events.DamlTransactionEntry import com.daml.ledger.participant.state.kvutils.store.events.PackageUpload.DamlPackageUploadEntry +import com.daml.ledger.participant.state.kvutils.store.events.{ + DamlPartyAllocationEntry, + DamlTransactionEntry, +} import com.daml.ledger.participant.state.kvutils.wire.{DamlConfigurationSubmission, DamlSubmission} import com.daml.ledger.participant.state.v2.{SubmitterInfo, TransactionMeta} import com.daml.lf.data.Ref diff --git a/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/committer/PartyAllocationCommitter.scala b/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/committer/PartyAllocationCommitter.scala index 71be49d6a83a..d332d3518064 100644 --- a/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/committer/PartyAllocationCommitter.scala +++ b/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/committer/PartyAllocationCommitter.scala @@ -6,6 +6,10 @@ package com.daml.ledger.participant.state.kvutils.committer import com.daml.ledger.participant.state.kvutils.Conversions.partyAllocationDedupKey import com.daml.ledger.participant.state.kvutils.DamlKvutils._ import com.daml.ledger.participant.state.kvutils.committer.Committer.buildLogEntryWithOptionalRecordTime +import com.daml.ledger.participant.state.kvutils.store.events.{ + DamlPartyAllocationEntry, + DamlPartyAllocationRejectionEntry, +} import com.daml.ledger.participant.state.kvutils.store.{ DamlLogEntry, DamlPartyAllocation, diff --git a/ledger/participant-state/kvutils/src/test/lib/scala/com/daml/ledger/validator/TestHelper.scala b/ledger/participant-state/kvutils/src/test/lib/scala/com/daml/ledger/validator/TestHelper.scala index 99a6646aae4f..4628d5aa0506 100644 --- a/ledger/participant-state/kvutils/src/test/lib/scala/com/daml/ledger/validator/TestHelper.scala +++ b/ledger/participant-state/kvutils/src/test/lib/scala/com/daml/ledger/validator/TestHelper.scala @@ -5,8 +5,8 @@ package com.daml.ledger.validator import java.util.UUID -import com.daml.ledger.participant.state.kvutils.DamlKvutils._ import com.daml.ledger.participant.state.kvutils.Raw +import com.daml.ledger.participant.state.kvutils.store.events.DamlPartyAllocationEntry import com.daml.ledger.participant.state.kvutils.store.{ DamlCommandDedupKey, DamlContractKey, diff --git a/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/KVUtilsPartySpec.scala b/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/KVUtilsPartySpec.scala index c08904f438f3..25a67190bc19 100644 --- a/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/KVUtilsPartySpec.scala +++ b/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/KVUtilsPartySpec.scala @@ -3,8 +3,8 @@ package com.daml.ledger.participant.state.kvutils -import com.daml.ledger.participant.state.kvutils.DamlKvutils.DamlPartyAllocationRejectionEntry import com.daml.ledger.participant.state.kvutils.store.DamlLogEntry +import com.daml.ledger.participant.state.kvutils.store.events.DamlPartyAllocationRejectionEntry import com.daml.logging.LoggingContext import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec diff --git a/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/KeyValueConsumptionSpec.scala b/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/KeyValueConsumptionSpec.scala index 4e44bfaf080f..f9fb46d55595 100644 --- a/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/KeyValueConsumptionSpec.scala +++ b/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/KeyValueConsumptionSpec.scala @@ -22,6 +22,8 @@ import com.daml.ledger.participant.state.kvutils.store.events.PackageUpload.{ } import com.daml.ledger.participant.state.kvutils.store.events.{ DamlConfigurationEntry, + DamlPartyAllocationEntry, + DamlPartyAllocationRejectionEntry, DamlSubmitterInfo, DamlTransactionEntry, DamlTransactionRejectionEntry, diff --git a/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/api/KeyValueParticipantStateReaderSpec.scala b/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/api/KeyValueParticipantStateReaderSpec.scala index f2d58a1c8455..501af8433012 100644 --- a/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/api/KeyValueParticipantStateReaderSpec.scala +++ b/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/api/KeyValueParticipantStateReaderSpec.scala @@ -8,9 +8,9 @@ import akka.stream.scaladsl.{Sink, Source} import com.codahale.metrics.MetricRegistry import com.daml.ledger.api.testing.utils.AkkaBeforeAndAfterAll import com.daml.ledger.offset.Offset -import com.daml.ledger.participant.state.kvutils.DamlKvutils._ import com.daml.ledger.participant.state.kvutils.api.KeyValueParticipantStateReader.offsetForUpdate import com.daml.ledger.participant.state.kvutils.api.KeyValueParticipantStateReaderSpec._ +import com.daml.ledger.participant.state.kvutils.store.events.DamlPartyAllocationEntry import com.daml.ledger.participant.state.kvutils.store.{ DamlLogEntry, DamlLogEntryId, diff --git a/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/committer/CommitterSpec.scala b/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/committer/CommitterSpec.scala index 4ba053357bd5..18b2ba6bcc8f 100644 --- a/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/committer/CommitterSpec.scala +++ b/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/committer/CommitterSpec.scala @@ -10,12 +10,14 @@ import com.codahale.metrics.MetricRegistry import com.daml.ledger.configuration.protobuf.LedgerConfiguration import com.daml.ledger.configuration.{Configuration, LedgerTimeModel} import com.daml.ledger.participant.state.kvutils.Conversions.{buildTimestamp, configurationStateKey} -import com.daml.ledger.participant.state.kvutils.DamlKvutils._ import com.daml.ledger.participant.state.kvutils.Err import com.daml.ledger.participant.state.kvutils.TestHelpers.{createCommitContext, theDefaultConfig} import com.daml.ledger.participant.state.kvutils.committer.CommitterSpec._ -import com.daml.ledger.participant.state.kvutils.store.events.DamlConfigurationEntry import com.daml.ledger.participant.state.kvutils.store.events.PackageUpload.DamlPackageUploadRejectionEntry +import com.daml.ledger.participant.state.kvutils.store.events.{ + DamlConfigurationEntry, + DamlPartyAllocationEntry, +} import com.daml.ledger.participant.state.kvutils.store.{DamlLogEntry, DamlStateKey, DamlStateValue} import com.daml.ledger.participant.state.kvutils.wire.DamlSubmission import com.daml.lf.data.Ref diff --git a/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/committer/PartyAllocationCommitterSpec.scala b/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/committer/PartyAllocationCommitterSpec.scala index d8a4e3d10ff0..b1413e27f83f 100644 --- a/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/committer/PartyAllocationCommitterSpec.scala +++ b/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/committer/PartyAllocationCommitterSpec.scala @@ -4,8 +4,8 @@ package com.daml.ledger.participant.state.kvutils.committer import com.codahale.metrics.MetricRegistry -import com.daml.ledger.participant.state.kvutils.DamlKvutils.DamlPartyAllocationEntry import com.daml.ledger.participant.state.kvutils.TestHelpers.{createCommitContext, theRecordTime} +import com.daml.ledger.participant.state.kvutils.store.events.DamlPartyAllocationEntry import com.daml.logging.LoggingContext import com.daml.metrics.Metrics import org.scalatest.matchers.should.Matchers diff --git a/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/validator/preexecution/RawPreExecutingCommitStrategySpec.scala b/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/validator/preexecution/RawPreExecutingCommitStrategySpec.scala index d63a8272e14a..f5798588a38d 100644 --- a/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/validator/preexecution/RawPreExecutingCommitStrategySpec.scala +++ b/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/validator/preexecution/RawPreExecutingCommitStrategySpec.scala @@ -3,8 +3,8 @@ package com.daml.ledger.validator.preexecution -import com.daml.ledger.participant.state.kvutils.DamlKvutils.DamlPartyAllocationRejectionEntry import com.daml.ledger.participant.state.kvutils.KeyValueCommitting.PreExecutionResult +import com.daml.ledger.participant.state.kvutils.store.events.DamlPartyAllocationRejectionEntry import com.daml.ledger.participant.state.kvutils.store.{ DamlContractState, DamlLogEntry, diff --git a/ledger/participant-state/kvutils/tools/integrity-check/src/test/scala/ledger/participant/state/kvutils/tools/integritycheck/LogAppendingReadServiceFactorySpec.scala b/ledger/participant-state/kvutils/tools/integrity-check/src/test/scala/ledger/participant/state/kvutils/tools/integritycheck/LogAppendingReadServiceFactorySpec.scala index 24f6b0d9ba13..27f31e50fdc7 100644 --- a/ledger/participant-state/kvutils/tools/integrity-check/src/test/scala/ledger/participant/state/kvutils/tools/integritycheck/LogAppendingReadServiceFactorySpec.scala +++ b/ledger/participant-state/kvutils/tools/integrity-check/src/test/scala/ledger/participant/state/kvutils/tools/integritycheck/LogAppendingReadServiceFactorySpec.scala @@ -9,8 +9,8 @@ import java.util.concurrent.TimeUnit import akka.stream.scaladsl.Sink import com.codahale.metrics.MetricRegistry import com.daml.ledger.api.testing.utils.AkkaBeforeAndAfterAll -import com.daml.ledger.participant.state.kvutils.DamlKvutils.DamlPartyAllocationEntry import com.daml.ledger.participant.state.kvutils.export.SubmissionInfo +import com.daml.ledger.participant.state.kvutils.store.events.DamlPartyAllocationEntry import com.daml.ledger.participant.state.kvutils.store.{DamlLogEntry, DamlLogEntryId} import com.daml.ledger.participant.state.kvutils.tools.integritycheck.LogAppendingReadServiceFactorySpec._ import com.daml.ledger.participant.state.kvutils.{Envelope, Raw} diff --git a/ledger/participant-state/kvutils/tools/integrity-check/src/test/scala/ledger/participant/state/kvutils/tools/integritycheck/RawPreExecutingCommitStrategySupportSpec.scala b/ledger/participant-state/kvutils/tools/integrity-check/src/test/scala/ledger/participant/state/kvutils/tools/integritycheck/RawPreExecutingCommitStrategySupportSpec.scala index ff2b388e03a4..4c948fe4c9c5 100644 --- a/ledger/participant-state/kvutils/tools/integrity-check/src/test/scala/ledger/participant/state/kvutils/tools/integritycheck/RawPreExecutingCommitStrategySupportSpec.scala +++ b/ledger/participant-state/kvutils/tools/integrity-check/src/test/scala/ledger/participant/state/kvutils/tools/integritycheck/RawPreExecutingCommitStrategySupportSpec.scala @@ -8,8 +8,8 @@ import java.time.{Duration, Instant, ZoneOffset, ZonedDateTime} import com.codahale.metrics.MetricRegistry import com.daml.ledger.api.testing.utils.AkkaBeforeAndAfterAll import com.daml.ledger.configuration.{Configuration, LedgerTimeModel} -import com.daml.ledger.participant.state.kvutils.DamlKvutils.DamlPartyAllocationEntry import com.daml.ledger.participant.state.kvutils.export.{SubmissionInfo, WriteSet} +import com.daml.ledger.participant.state.kvutils.store.events.DamlPartyAllocationEntry import com.daml.ledger.participant.state.kvutils.store.{ DamlLogEntry, DamlStateKey, diff --git a/ledger/participant-state/kvutils/tools/integrity-check/src/test/scala/ledger/participant/state/kvutils/tools/integritycheck/RawWriteSetComparisonSpec.scala b/ledger/participant-state/kvutils/tools/integrity-check/src/test/scala/ledger/participant/state/kvutils/tools/integritycheck/RawWriteSetComparisonSpec.scala index 92274d20aa26..960632b1a02d 100644 --- a/ledger/participant-state/kvutils/tools/integrity-check/src/test/scala/ledger/participant/state/kvutils/tools/integritycheck/RawWriteSetComparisonSpec.scala +++ b/ledger/participant-state/kvutils/tools/integrity-check/src/test/scala/ledger/participant/state/kvutils/tools/integritycheck/RawWriteSetComparisonSpec.scala @@ -4,8 +4,10 @@ package com.daml.ledger.participant.state.kvutils.tools.integritycheck import com.daml.ledger.configuration.protobuf.LedgerConfiguration -import com.daml.ledger.participant.state.kvutils.DamlKvutils.DamlPartyAllocationEntry -import com.daml.ledger.participant.state.kvutils.store.events.DamlConfigurationEntry +import com.daml.ledger.participant.state.kvutils.store.events.{ + DamlConfigurationEntry, + DamlPartyAllocationEntry, +} import com.daml.ledger.participant.state.kvutils.store.{ DamlLogEntry, DamlLogEntryId, From f4ca8767560552591944cce829301462cf8af693 Mon Sep 17 00:00:00 2001 From: Robin Krom Date: Wed, 13 Oct 2021 10:17:17 +0200 Subject: [PATCH 04/13] interfaces: test for triggers (#11221) This adds a test checking whether we can exercise choices on interface contract IDs in triggers. We can only test this for daml-lf 1.dev. CHANGELOG_BEGIN CHANGELOG_END --- triggers/tests/BUILD.bazel | 6 +- triggers/tests/daml/Interface.daml | 77 +++++++++++++++++++ .../daml/lf/engine/trigger/test/DevOnly.scala | 47 +++++++++++ 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 triggers/tests/daml/Interface.daml create mode 100644 triggers/tests/src/test/scala/com/digitalasset/daml/lf/engine/trigger/test/DevOnly.scala diff --git a/triggers/tests/BUILD.bazel b/triggers/tests/BUILD.bazel index e71e0e9def75..558317a4f2f0 100644 --- a/triggers/tests/BUILD.bazel +++ b/triggers/tests/BUILD.bazel @@ -44,6 +44,10 @@ DAML_LF_VERSIONS = [ cp -L $(location //templates:copy-trigger/src/CopyTrigger.daml) $$TMP_DIR/daml cp -L $(location //triggers/daml:daml-trigger{suffix}.dar) $$TMP_DIR/daml-trigger.dar cp -L $(location //daml-script/daml:daml-script{suffix}.dar) $$TMP_DIR/daml-script.dar + if [ "{lf_version}" = "1.dev" ] + then + cp -L $(location :daml/Interface.daml) $$TMP_DIR/daml + fi cat << EOF > $$TMP_DIR/daml.yaml sdk-version: {sdk} name: acs @@ -131,7 +135,7 @@ da_scala_library( "Tls", "RunnerSpec", "UnfoldStateSpec", - ] + ] + (["DevOnly"] if lf_version else []) ], data = [ ":acs%s.dar" % suffix, diff --git a/triggers/tests/daml/Interface.daml b/triggers/tests/daml/Interface.daml new file mode 100644 index 000000000000..409f2fef2c6e --- /dev/null +++ b/triggers/tests/daml/Interface.daml @@ -0,0 +1,77 @@ +-- Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Interface where + +import DA.Foldable +import Daml.Trigger + +test : Trigger Int +test = Trigger with + initialize = pure 3 + updateState = \msg -> case msg of + MCompletion c + | Failed {} <- c.status -> modify (subtract 1) + _ -> pure () + rule = \p1 -> do + cs <- query @Asset + case cs of + [] -> do + dedupCreate Asset {owner = p1, issuer = p1, amount = 10} + cs -> do + forA_ cs $ \(cid, _asset) -> do + dedupExercise (toTokenContractId cid) $ Transfer with newOwner = p1 + registeredTemplates = AllInDar + heartbeat = None + +interface Token where + getAmount : Int + + choice Split : (ContractId Token, ContractId Token) + with + splitAmount : Int + + choice Transfer : ContractId Token + with + newOwner : Party + + nonconsuming choice Noop : () + with + nothing : () + +template Asset + with + issuer : Party + owner : Party + amount : Int + where + signatory issuer + implements Token where + let getAmount = amount + + choice Split : (ContractId Token, ContractId Token) + with + splitAmount : Int + controller owner + do + assert (splitAmount < amount) + cid1 <- create this with amount = splitAmount + cid2 <- create this with amount = amount - splitAmount + pure (toTokenContractId cid1, toTokenContractId cid2) + + choice Transfer : ContractId Token + with + newOwner : Party + controller owner + do + cid <- create this with owner = newOwner + pure (toTokenContractId cid) + + nonconsuming choice Noop : () + with + nothing : () + controller owner + do + pure () + + diff --git a/triggers/tests/src/test/scala/com/digitalasset/daml/lf/engine/trigger/test/DevOnly.scala b/triggers/tests/src/test/scala/com/digitalasset/daml/lf/engine/trigger/test/DevOnly.scala new file mode 100644 index 000000000000..2d4649d019bd --- /dev/null +++ b/triggers/tests/src/test/scala/com/digitalasset/daml/lf/engine/trigger/test/DevOnly.scala @@ -0,0 +1,47 @@ +// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +package com.daml.lf.engine.trigger.test + +import akka.stream.scaladsl.Flow +import com.daml.lf.data.Ref._ +import com.daml.ledger.api.testing.utils.SuiteResourceManagementAroundAll +import com.daml.ledger.api.v1.{value => LedgerApi} +import org.scalatest._ +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AsyncWordSpec +import com.daml.lf.engine.trigger.TriggerMsg + +class DevOnly + extends AsyncWordSpec + with AbstractTriggerTest + with Matchers + with Inside + with SuiteResourceManagementAroundAll + with TryValues { + self: Suite => + + this.getClass.getSimpleName can { + "InterfaceTest" should { + val triggerId = QualifiedName.assertFromString("Interface:test") + val tId = LedgerApi.Identifier(packageId, "Interface", "Asset") + "1 transfer" in { + for { + client <- ledgerClient() + party <- allocateParty(client) + runner = getRunner(client, triggerId, party) + (acs, offset) <- runner.queryACS() + // 1 for create of Asset + // 1 for completion + // 1 for exercise + // 1 for corresponding completion + _ <- runner.runWithACS(acs, offset, msgFlow = Flow[TriggerMsg].take(4))._2 + acs <- queryACS(client, party) + } yield { + assert(acs(tId).length == 1) + } + } + } + + } +} From cb1fb6f7bfce6a1d2b3ef67d8d796352abc9d1c0 Mon Sep 17 00:00:00 2001 From: Moritz Kiefer Date: Wed, 13 Oct 2021 11:19:44 +0200 Subject: [PATCH 05/13] Reuse sandbox & JSON API across `daml ledger` tests (#11214) Speeds them up by more than 2x and reduces flakiness. I also added a higher timeout to the allocate party call since that seems to still be sometimes too slow if lots of things run in parallel. changelog_begin changelog_end --- .../test/DA/Daml/Helper/Test/Ledger.hs | 381 +++++++++--------- 1 file changed, 185 insertions(+), 196 deletions(-) diff --git a/daml-assistant/daml-helper/test/DA/Daml/Helper/Test/Ledger.hs b/daml-assistant/daml-helper/test/DA/Daml/Helper/Test/Ledger.hs index a5d95500d59a..9711d42f413f 100644 --- a/daml-assistant/daml-helper/test/DA/Daml/Helper/Test/Ledger.hs +++ b/daml-assistant/daml-helper/test/DA/Daml/Helper/Test/Ledger.hs @@ -35,210 +35,199 @@ main = do locateRunfiles (mainWorkspace "daml-assistant" "daml-helper" exe "daml-helper") testDar <- locateRunfiles (mainWorkspace "daml-assistant" "daml-helper" "test.dar") defaultMain $ + withSandbox defaultSandboxConf $ \getSandboxPort -> + withHttpJson getSandboxPort (defaultHttpJsonConf "Alice") $ \getHttpJson -> testGroup "daml ledger" - [ withSandbox defaultSandboxConf $ \getSandboxPort -> do - withHttpJson getSandboxPort (defaultHttpJsonConf "Alice") $ \getHttpJson -> - testGroup - "list-parties" - [ testCase "succeeds against HTTP JSON API" $ do - HttpJson {hjPort, hjTokenFile} <- getHttpJson - sandboxPort <- getSandboxPort - -- allocate parties via gRPC - callCommand $ - unwords - [ damlHelper - , "ledger" - , "allocate-party" - , "--host" - , "localhost" - , "--port" - , show sandboxPort - , "Bob" - ] - -- check for parties via json api - let ledgerOpts = - [ "--host=localhost" - , "--json-api" - , "--port" - , show hjPort - , "--access-token-file" - , hjTokenFile - ] - out <- readProcess damlHelper ("ledger" : "list-parties" : ledgerOpts) "" - ((show $ PartyDetails (Party "Bob") "Bob" True) `elem` lines out) @? - "Bob is not contained in list-parties output." - ] - , withSandbox defaultSandboxConf $ \getSandboxPort -> do - withHttpJson getSandboxPort (defaultHttpJsonConf "Alice") $ \getHttpJson -> - testGroup - "allocate-parties" - [ testCase "succeeds against HTTP JSON API" $ do - HttpJson {hjPort, hjTokenFile} <- getHttpJson - sandboxPort <- getSandboxPort - -- allocate parties via json api - callCommand $ - unwords - [ damlHelper - , "ledger" - , "allocate-parties" - , "--host=localhost" - , "--json-api" - , "--port" - , show hjPort - , "--access-token-file" - , hjTokenFile - , "Bob" - , "Charlie" - ] - -- check for parties via gRPC - let ledgerOpts = ["--host=localhost", "--port", show sandboxPort] - out <- readProcess damlHelper ("ledger" : "list-parties" : ledgerOpts) "" - ((show $ PartyDetails (Party "Bob") "Bob" True) `elem` lines out) @? - "Bob is not contained in list-parties output." - ((show $ PartyDetails (Party "Charlie") "Charlie" True) `elem` lines out) @? - "Charlie is not contained in list-parties output." - ] - , withSandbox defaultSandboxConf $ \getSandboxPort -> do - withHttpJson getSandboxPort (defaultHttpJsonConf "Alice") $ \getHttpJson -> - testGroup - "upload-dar" - [ testCase "succeeds against HTTP JSON API" $ do - HttpJson {hjPort, hjTokenFile} <- getHttpJson - sandboxPort <- getSandboxPort - testDarPkgId <- readDarMainPackageId testDar - -- upload-dar via json-api - callCommand $ - unwords - [ damlHelper - , "ledger" - , "upload-dar" - , "--host=localhost" - , "--json-api" - , "--port" - , show hjPort - , "--access-token-file" - , hjTokenFile - , testDar - ] - -- fetch dar via gRPC - withTempFile $ \tmp -> do - callCommand $ - unwords - [ damlHelper - , "ledger" - , "fetch-dar" - , "--host=localhost" - , "--port" - , show sandboxPort - , "--main-package-id" - , testDarPkgId - , "-o" - , tmp - ] - fetchedPkgId <- readDarMainPackageId tmp - fetchedPkgId == testDarPkgId @? "Fechted dar differs from uploaded dar." - ] - , withSandbox defaultSandboxConf $ \getSandboxPort -> do - withHttpJson getSandboxPort (defaultHttpJsonConf "Alice") $ \getHttpJson -> - testGroup - "fetch-dar" - [ testCase "succeeds against HTTP JSON API" $ do - HttpJson {hjPort, hjTokenFile} <- getHttpJson - sandboxPort <- getSandboxPort - testDarPkgId <- readDarMainPackageId testDar - -- upload-dar via gRPC - callCommand $ - unwords - [ damlHelper - , "ledger" - , "upload-dar" - , "--host=localhost" - , "--port" - , show sandboxPort - , testDar - ] - -- fetch dar via http json - withTempFile $ \tmp -> do - callCommand $ - unwords - [ damlHelper - , "ledger" - , "fetch-dar" - , "--json-api" - , "--host=localhost" - , "--port" - , show hjPort - , "--access-token-file" - , hjTokenFile - , "--main-package-id" - , testDarPkgId - , "-o" - , tmp - ] - fetchedPkgId <- readDarMainPackageId tmp - testDarPkgId == fetchedPkgId @? "Fechted dar differs from uploaded dar." - ] - , withSandbox defaultSandboxConf $ \getSandboxPort -> do - testGroup - "fetch-dar limited gRPC message size" - [ testCase "fails if the message size is too low" $ do - sandboxPort <- getSandboxPort - testDarPkgId <- readDarMainPackageId testDar - -- upload-dar via gRPC + [ testGroup "list-parties" + [ testCase "succeeds against HTTP JSON API" $ do + HttpJson {hjPort, hjTokenFile} <- getHttpJson + sandboxPort <- getSandboxPort + -- allocate parties via gRPC + callCommand $ + unwords + [ damlHelper + , "ledger" + , "allocate-party" + , "--host" + , "localhost" + , "--port" + , show sandboxPort + , "--timeout=120" + , "Bob" + ] + -- check for parties via json api + let ledgerOpts = + [ "--host=localhost" + , "--json-api" + , "--port" + , show hjPort + , "--access-token-file" + , hjTokenFile + ] + out <- readProcess damlHelper ("ledger" : "list-parties" : ledgerOpts) "" + ((show $ PartyDetails (Party "Bob") "Bob" True) `elem` lines out) @? + "Bob is not contained in list-parties output." + ] + , testGroup "allocate-parties" + [ testCase "succeeds against HTTP JSON API" $ do + HttpJson {hjPort, hjTokenFile} <- getHttpJson + sandboxPort <- getSandboxPort + -- allocate parties via json api + callCommand $ + unwords + [ damlHelper + , "ledger" + , "allocate-parties" + , "--host=localhost" + , "--json-api" + , "--port" + , show hjPort + , "--access-token-file" + , hjTokenFile + , "Bob" + , "Charlie" + ] + -- check for parties via gRPC + let ledgerOpts = ["--host=localhost", "--port", show sandboxPort] + out <- readProcess damlHelper ("ledger" : "list-parties" : ledgerOpts) "" + ((show $ PartyDetails (Party "Bob") "Bob" True) `elem` lines out) @? + "Bob is not contained in list-parties output." + ((show $ PartyDetails (Party "Charlie") "Charlie" True) `elem` lines out) @? + "Charlie is not contained in list-parties output." + ] + , testGroup "upload-dar" + [ testCase "succeeds against HTTP JSON API" $ do + HttpJson {hjPort, hjTokenFile} <- getHttpJson + sandboxPort <- getSandboxPort + testDarPkgId <- readDarMainPackageId testDar + -- upload-dar via json-api + callCommand $ + unwords + [ damlHelper + , "ledger" + , "upload-dar" + , "--host=localhost" + , "--json-api" + , "--port" + , show hjPort + , "--access-token-file" + , hjTokenFile + , testDar + ] + -- fetch dar via gRPC + withTempFile $ \tmp -> do callCommand $ unwords [ damlHelper , "ledger" - , "upload-dar" + , "fetch-dar" , "--host=localhost" , "--port" , show sandboxPort - , testDar + , "--main-package-id" + , testDarPkgId + , "-o" + , tmp + ] + fetchedPkgId <- readDarMainPackageId tmp + fetchedPkgId == testDarPkgId @? "Fechted dar differs from uploaded dar." + ] + , testGroup "fetch-dar" + [ testCase "succeeds against HTTP JSON API" $ do + HttpJson {hjPort, hjTokenFile} <- getHttpJson + sandboxPort <- getSandboxPort + testDarPkgId <- readDarMainPackageId testDar + -- upload-dar via gRPC + callCommand $ + unwords + [ damlHelper + , "ledger" + , "upload-dar" + , "--host=localhost" + , "--port" + , show sandboxPort + , testDar + ] + -- fetch dar via http json + withTempFile $ \tmp -> do + callCommand $ + unwords + [ damlHelper + , "ledger" + , "fetch-dar" + , "--json-api" + , "--host=localhost" + , "--port" + , show hjPort + , "--access-token-file" + , hjTokenFile + , "--main-package-id" + , testDarPkgId + , "-o" + , tmp ] - -- fetch dar via gRPC, but too small max-inbound-message-size - withTempFile $ \tmp -> do - (exitCode, _, _) <- - readCreateProcessWithExitCode - (shell $ - unwords - [ damlHelper - , "ledger" - , "fetch-dar" - , "--host=localhost" - , "--port" - , show sandboxPort - , "--main-package-id" - , testDarPkgId - , "-o" - , tmp - , "--max-inbound-message-size" - , "20" - ]) - "" - exitCode == - ExitFailure 1 @? - "fetch-dar did not fail with too small max-inbound-message-size flag" - (exitCode2, _, _) <- - readCreateProcessWithExitCode - (shell $ - unwords - [ damlHelper - , "ledger" - , "fetch-dar" - , "--host=localhost" - , "--port" - , show sandboxPort - , "--main-package-id" - , testDarPkgId - , "-o" - , tmp - , "--max-inbound-message-size" - , "2000000" - ]) - "" - exitCode2 == - ExitSuccess @? - "fetch-dar did fail with big enough max-inbound-message-size flag" - ] + fetchedPkgId <- readDarMainPackageId tmp + testDarPkgId == fetchedPkgId @? "Fechted dar differs from uploaded dar." + ] + , testGroup "fetch-dar limited gRPC message size" + [ testCase "fails if the message size is too low" $ do + sandboxPort <- getSandboxPort + testDarPkgId <- readDarMainPackageId testDar + -- upload-dar via gRPC + callCommand $ + unwords + [ damlHelper + , "ledger" + , "upload-dar" + , "--host=localhost" + , "--port" + , show sandboxPort + , testDar + ] + -- fetch dar via gRPC, but too small max-inbound-message-size + withTempFile $ \tmp -> do + (exitCode, _, _) <- + readCreateProcessWithExitCode + (shell $ + unwords + [ damlHelper + , "ledger" + , "fetch-dar" + , "--host=localhost" + , "--port" + , show sandboxPort + , "--main-package-id" + , testDarPkgId + , "-o" + , tmp + , "--max-inbound-message-size" + , "20" + ]) + "" + exitCode == + ExitFailure 1 @? + "fetch-dar did not fail with too small max-inbound-message-size flag" + (exitCode2, _, _) <- + readCreateProcessWithExitCode + (shell $ + unwords + [ damlHelper + , "ledger" + , "fetch-dar" + , "--host=localhost" + , "--port" + , show sandboxPort + , "--main-package-id" + , testDarPkgId + , "-o" + , tmp + , "--max-inbound-message-size" + , "2000000" + ]) + "" + exitCode2 == + ExitSuccess @? + "fetch-dar did fail with big enough max-inbound-message-size flag" + ] ] From d1611e8bc19f8a02eeac2c38d66c233da5a43b2d Mon Sep 17 00:00:00 2001 From: Remy Date: Wed, 13 Oct 2021 11:40:30 +0200 Subject: [PATCH 06/13] LF: Drop templateID from SEScopeExercise and KCloseExercise. (#11228) We do not need to keep track of it because we have it in the partial transaction. CHANGELOG_BEGIN CHANGELOG_END --- .../scala/com/digitalasset/daml/lf/speedy/Anf.scala | 4 ++-- .../com/digitalasset/daml/lf/speedy/Compiler.scala | 12 ++++++------ .../com/digitalasset/daml/lf/speedy/Pretty.scala | 2 +- .../com/digitalasset/daml/lf/speedy/SExpr.scala | 4 ++-- .../com/digitalasset/daml/lf/speedy/Speedy.scala | 6 ++---- .../daml/lf/speedy/iterable/SExprIterable.scala | 2 +- .../daml/lf/transaction/PartialTransaction.scala | 5 +++-- .../daml/lf/speedy/PartialTransactionSpec.scala | 2 +- 8 files changed, 18 insertions(+), 19 deletions(-) diff --git a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Anf.scala b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Anf.scala index 5f5567963fc4..a9dc71f0bc75 100644 --- a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Anf.scala +++ b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Anf.scala @@ -343,9 +343,9 @@ private[lf] object Anf { ).bounce Bounce(() => transform(depth, SETryCatch(body, handler), k)) - case SEScopeExercise(templateId, body0) => + case SEScopeExercise(body0) => val body: SExpr = flattenExp(depth, env, body0)(anf => Land(anf.wrapped)).bounce - Bounce(() => transform(depth, SEScopeExercise(templateId, body), k)) + Bounce(() => transform(depth, SEScopeExercise(body), k)) case _: SEAbs | _: SEDamlException | _: SEAppAtomicFun | _: SEAppAtomicGeneral | _: SEAppAtomicSaturatedBuiltin | _: SELet1Builtin | _: SELet1BuiltinArithmetic | diff --git a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Compiler.scala b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Compiler.scala index 82867ceea402..a4f3fea6391c 100644 --- a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Compiler.scala +++ b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Compiler.scala @@ -1014,7 +1014,7 @@ private[lf] final class Compiler( ) ) { _ => addExprVar(choice.selfBinder, cidPos) - SEScopeExercise(tmplId, app(compile(choice.update), svar(tokenPos))) + SEScopeExercise(app(compile(choice.update), svar(tokenPos))) } } } @@ -1048,7 +1048,7 @@ private[lf] final class Compiler( ) ) { _ => addExprVar(choice.selfBinder, cidPos) - SEScopeExercise(ifaceId, app(compile(choice.update), svar(tokenPos))) + SEScopeExercise(app(compile(choice.update), svar(tokenPos))) } } } @@ -1248,8 +1248,8 @@ private[lf] final class Compiler( closureConvert(shift(remaps, 1), handler), ) - case SEScopeExercise(templateId, body) => - SEScopeExercise(templateId, closureConvert(remaps, body)) + case SEScopeExercise(body) => + SEScopeExercise(closureConvert(remaps, body)) case SELabelClosure(label, expr) => SELabelClosure(label, closureConvert(remaps, expr)) @@ -1320,7 +1320,7 @@ private[lf] final class Compiler( go(expr, bound, free) case SETryCatch(body, handler) => go(body, bound, go(handler, 1 + bound, free)) - case SEScopeExercise(_, body) => + case SEScopeExercise(body) => go(body, bound, free) case _: SELoc | _: SEMakeClo | _: SEDamlException | _: SEImportValue | @@ -1411,7 +1411,7 @@ private[lf] final class Compiler( case SETryCatch(body, handler) => go(body) goBody(maxS + 1, maxA, maxF)(handler) - case SEScopeExercise(_, body) => + case SEScopeExercise(body) => go(body) case _: SEVar | _: SEAbs | _: SEDamlException | _: SEImportValue => diff --git a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Pretty.scala b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Pretty.scala index 30472fa05c2a..49a4b659af0c 100644 --- a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Pretty.scala +++ b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Pretty.scala @@ -519,7 +519,7 @@ private[lf] object Pretty { text("try-catch") + char('(') + prettySExpr(index)(body) + text(", ") + prettySExpr(index)(handler) + char(')') - case SEScopeExercise(_, body) => + case SEScopeExercise(body) => text("exercise") + char('(') + prettySExpr(index)(body) + text(")") case x: SEBuiltinRecursiveDefinition => str(x) diff --git a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/SExpr.scala b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/SExpr.scala index 64a02ddfdf47..58b0f35a68f1 100644 --- a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/SExpr.scala +++ b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/SExpr.scala @@ -407,9 +407,9 @@ object SExpr { } /** Exercise scope (begin..end) */ - final case class SEScopeExercise(templateId: TypeConName, body: SExpr) extends SExpr { + final case class SEScopeExercise(body: SExpr) extends SExpr { def execute(machine: Machine): Unit = { - machine.pushKont(KCloseExercise(templateId, machine)) + machine.pushKont(KCloseExercise(machine)) machine.ctrl = body } } diff --git a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Speedy.scala b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Speedy.scala index 6faf65085196..883a78b26db2 100644 --- a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Speedy.scala +++ b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Speedy.scala @@ -1291,13 +1291,11 @@ private[lf] object Speedy { * (1) by 'endExercises' if this continuation is entered normally, or * (2) by 'abortExercises' if we unwind the stack through this continuation */ - private[speedy] final case class KCloseExercise(templateId: TypeConName, machine: Machine) - extends Kont { + private[speedy] final case class KCloseExercise(machine: Machine) extends Kont { def execute(exerciseResult: SValue) = { machine.withOnLedger("KCloseExercise") { onLedger => - val exerciseResultValue = onLedger.ptx.normValue(templateId, exerciseResult) - onLedger.ptx = onLedger.ptx.endExercises(exerciseResultValue) + onLedger.ptx = onLedger.ptx.endExercises(exerciseResult) checkAborted(onLedger.ptx) } machine.returnValue = exerciseResult diff --git a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/iterable/SExprIterable.scala b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/iterable/SExprIterable.scala index 0f6fce61cc8d..4578cb86230f 100644 --- a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/iterable/SExprIterable.scala +++ b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/iterable/SExprIterable.scala @@ -29,7 +29,7 @@ private[speedy] object SExprIterable { case SExpr.SEDamlException(_) => Iterator.empty case SExpr.SEImportValue(_, _) => Iterator.empty case SExpr.SETryCatch(body, handler) => Iterator(body, handler) - case SExpr.SEScopeExercise(_, body) => Iterator(body) + case SExpr.SEScopeExercise(body) => Iterator(body) case SExpr.SEBuiltin(_) => Iterator.empty case SExpr.SEBuiltinRecursiveDefinition(_) => Iterator.empty case SExpr.SELocA(_) => Iterator.empty diff --git a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/transaction/PartialTransaction.scala b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/transaction/PartialTransaction.scala index 3950b356599c..4d96f6a0ddfe 100644 --- a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/transaction/PartialTransaction.scala +++ b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/transaction/PartialTransaction.scala @@ -615,11 +615,12 @@ private[lf] case class PartialTransaction( /** Close normally an exercise context. * Must match a `beginExercises`. */ - def endExercises(value: Value): PartialTransaction = + def endExercises(value: SValue): PartialTransaction = context.info match { case ec: ExercisesContextInfo => + val result = normValue(ec.templateId, value) val exerciseNode = - makeExNode(ec).copy(children = context.children.toImmArray, exerciseResult = Some(value)) + makeExNode(ec).copy(children = context.children.toImmArray, exerciseResult = Some(result)) val nodeId = ec.nodeId copy( context = diff --git a/daml-lf/interpreter/src/test/scala/com/digitalasset/daml/lf/speedy/PartialTransactionSpec.scala b/daml-lf/interpreter/src/test/scala/com/digitalasset/daml/lf/speedy/PartialTransactionSpec.scala index 5e373bc29825..69817b90441b 100644 --- a/daml-lf/interpreter/src/test/scala/com/digitalasset/daml/lf/speedy/PartialTransactionSpec.scala +++ b/daml-lf/interpreter/src/test/scala/com/digitalasset/daml/lf/speedy/PartialTransactionSpec.scala @@ -74,7 +74,7 @@ class PartialTransactionSpec extends AnyWordSpec with Matchers with Inside { ) def endExercises_ : PartialTransaction = - ptx.endExercises(Value.ValueUnit) + ptx.endExercises(SValue.SUnit) private val dummyException = SArithmeticError("Dummy", ImmArray.Empty) From 514e8b50a3f901cd82b96ce17ee00f0ddf90dab3 Mon Sep 17 00:00:00 2001 From: nicu-da Date: Wed, 13 Oct 2021 03:34:45 -0700 Subject: [PATCH 07/13] Extract configuration_rejection.proto from daml_kvutils.proto [KVL-1090] (#11215) CHANGELOG_BEGIN CHANGELOG_END --- .../state/kvutils/daml_kvutils.proto | 21 ----------- .../kvutils/store/events/configuration.proto | 3 -- .../events/configuration_rejection.proto | 35 +++++++++++++++++++ .../state/kvutils/store/log_entry.proto | 3 +- .../state/kvutils/KeyValueConsumption.scala | 2 +- .../kvutils/committer/ConfigCommitter.scala | 5 ++- .../state/kvutils/KVUtilsConfigSpec.scala | 2 +- .../kvutils/KeyValueConsumptionSpec.scala | 2 +- 8 files changed, 44 insertions(+), 29 deletions(-) create mode 100644 ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/events/configuration_rejection.proto diff --git a/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/daml_kvutils.proto b/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/daml_kvutils.proto index 7290435387ae..a26933af4e74 100644 --- a/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/daml_kvutils.proto +++ b/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/daml_kvutils.proto @@ -20,27 +20,6 @@ import "google/protobuf/timestamp.proto"; import "com/daml/ledger/configuration/ledger_configuration.proto"; import "com/daml/ledger/participant/state/kvutils/store/state.proto"; -// A log entry describing a rejected configuration change. -message DamlConfigurationRejectionEntry { - // A unique string scoped to a particular participant for matching the - // request with the result. - string submission_id = 1; - - // Submitting participant's id. - string participant_id = 2; - - // The new proposed configuration that was rejected. - com.daml.ledger.configuration.LedgerConfiguration configuration = 3; - - oneof reason { - ParticipantNotAuthorized participant_not_authorized = 4; - GenerationMismatch generation_mismatch = 5; - Invalid invalid_configuration = 6; - TimedOut timed_out = 7; - Duplicate duplicate_submission = 8; - } -} - // Errors // diff --git a/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/events/configuration.proto b/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/events/configuration.proto index b0b2d277d382..3001fc1315cb 100644 --- a/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/events/configuration.proto +++ b/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/events/configuration.proto @@ -10,9 +10,6 @@ option csharp_namespace = "Com.Daml.Ledger.Participant.State.KVUtils.Store.Event import "com/daml/ledger/configuration/ledger_configuration.proto"; -// This message is in it's own file because `state.proto` depends on this message, -// and it would introduce a circular dependency if kept in `daml_kvutils.proto` - // Configuration entry that records a configuration change. // Also used in state to look up latest configuration. // When a configuration exists, only the participant that diff --git a/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/events/configuration_rejection.proto b/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/events/configuration_rejection.proto new file mode 100644 index 000000000000..1ba24c84118b --- /dev/null +++ b/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/events/configuration_rejection.proto @@ -0,0 +1,35 @@ +// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +syntax = "proto3"; + +package com.daml.ledger.participant.state.kvutils.store.events; + +option java_package = "com.daml.ledger.participant.state.kvutils.store.events"; +option java_multiple_files = true; +option csharp_namespace = "Com.Daml.Ledger.Participant.State.KVUtils.Store.Events"; + +import "com/daml/ledger/configuration/ledger_configuration.proto"; +import "com/daml/ledger/participant/state/kvutils/daml_kvutils.proto"; + +// This message is in it's own file because it would introduce a circular dependency if kept in `configuration.proto` + +// A log entry describing a rejected configuration change. +message DamlConfigurationRejectionEntry { + // A unique string scoped to a particular participant for matching the + // request with the result. + string submission_id = 1; + + // Submitting participant's id. + string participant_id = 2; + + // The new proposed configuration that was rejected. + com.daml.ledger.configuration.LedgerConfiguration configuration = 3; + + oneof reason { + ParticipantNotAuthorized participant_not_authorized = 4; + GenerationMismatch generation_mismatch = 5; + Invalid invalid_configuration = 6; + TimedOut timed_out = 7; + Duplicate duplicate_submission = 8; + } +} diff --git a/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/log_entry.proto b/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/log_entry.proto index 0a6ec8f1a086..18e1e43f283a 100644 --- a/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/log_entry.proto +++ b/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/log_entry.proto @@ -13,6 +13,7 @@ import "google/protobuf/empty.proto"; import "google/protobuf/timestamp.proto"; import "com/daml/ledger/participant/state/kvutils/daml_kvutils.proto"; import "com/daml/ledger/participant/state/kvutils/store/events/configuration.proto"; +import "com/daml/ledger/participant/state/kvutils/store/events/configuration_rejection.proto"; import "com/daml/ledger/participant/state/kvutils/store/events/package_upload.proto"; import "com/daml/ledger/participant/state/kvutils/store/events/party_allocation.proto"; import "com/daml/ledger/participant/state/kvutils/store/events/transaction.proto"; @@ -47,7 +48,7 @@ message DamlLogEntry { com.daml.ledger.participant.state.kvutils.store.events.DamlConfigurationEntry configuration_entry = 6; // A rejected configuration change. - DamlConfigurationRejectionEntry configuration_rejection_entry = 7; + com.daml.ledger.participant.state.kvutils.store.events.DamlConfigurationRejectionEntry configuration_rejection_entry = 7; // Allocation of a new Daml party and its assignment to a participant. com.daml.ledger.participant.state.kvutils.store.events.DamlPartyAllocationEntry party_allocation_entry = 8; diff --git a/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/KeyValueConsumption.scala b/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/KeyValueConsumption.scala index 3ec0b6a431d7..1ac37f62f854 100644 --- a/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/KeyValueConsumption.scala +++ b/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/KeyValueConsumption.scala @@ -6,9 +6,9 @@ package com.daml.ledger.participant.state.kvutils import com.daml.ledger.configuration.Configuration import com.daml.ledger.grpc.GrpcStatuses import com.daml.ledger.participant.state.kvutils.Conversions._ -import com.daml.ledger.participant.state.kvutils.DamlKvutils._ import com.daml.ledger.participant.state.kvutils.store.events.PackageUpload.DamlPackageUploadRejectionEntry import com.daml.ledger.participant.state.kvutils.store.events.{ + DamlConfigurationRejectionEntry, DamlPartyAllocationRejectionEntry, DamlTransactionBlindingInfo, DamlTransactionEntry, diff --git a/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/committer/ConfigCommitter.scala b/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/committer/ConfigCommitter.scala index 0aa139c1bb5a..d12220117954 100644 --- a/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/committer/ConfigCommitter.scala +++ b/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/committer/ConfigCommitter.scala @@ -11,12 +11,15 @@ import com.daml.ledger.participant.state.kvutils.Conversions.{ } import com.daml.ledger.participant.state.kvutils.DamlKvutils._ import com.daml.ledger.participant.state.kvutils.committer.Committer._ +import com.daml.ledger.participant.state.kvutils.store.events.{ + DamlConfigurationEntry, + DamlConfigurationRejectionEntry, +} import com.daml.ledger.participant.state.kvutils.store.{ DamlLogEntry, DamlStateValue, DamlSubmissionDedupValue, } -import com.daml.ledger.participant.state.kvutils.store.events.DamlConfigurationEntry import com.daml.ledger.participant.state.kvutils.wire.{DamlConfigurationSubmission, DamlSubmission} import com.daml.lf.data.Time.Timestamp import com.daml.logging.entries.LoggingEntries diff --git a/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/KVUtilsConfigSpec.scala b/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/KVUtilsConfigSpec.scala index d1243b249e4f..11f9b24c74e1 100644 --- a/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/KVUtilsConfigSpec.scala +++ b/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/KVUtilsConfigSpec.scala @@ -7,8 +7,8 @@ import java.time.Duration import com.codahale.metrics.MetricRegistry import com.daml.ledger.configuration.Configuration -import com.daml.ledger.participant.state.kvutils.DamlKvutils._ import com.daml.ledger.participant.state.kvutils.store.DamlLogEntry +import com.daml.ledger.participant.state.kvutils.store.events.DamlConfigurationRejectionEntry import com.daml.lf.data.Ref import com.daml.logging.LoggingContext import com.daml.metrics.Metrics diff --git a/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/KeyValueConsumptionSpec.scala b/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/KeyValueConsumptionSpec.scala index f9fb46d55595..3e27fd84b5df 100644 --- a/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/KeyValueConsumptionSpec.scala +++ b/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/KeyValueConsumptionSpec.scala @@ -8,7 +8,6 @@ import java.time.Instant import com.daml.ledger.configuration.Configuration import com.daml.ledger.grpc.GrpcStatuses import com.daml.ledger.participant.state.kvutils.Conversions.{buildTimestamp, parseInstant} -import com.daml.ledger.participant.state.kvutils.DamlKvutils._ import com.daml.ledger.participant.state.kvutils.KeyValueConsumption.{ TimeBounds, logEntryToUpdate, @@ -22,6 +21,7 @@ import com.daml.ledger.participant.state.kvutils.store.events.PackageUpload.{ } import com.daml.ledger.participant.state.kvutils.store.events.{ DamlConfigurationEntry, + DamlConfigurationRejectionEntry, DamlPartyAllocationEntry, DamlPartyAllocationRejectionEntry, DamlSubmitterInfo, From 909a1bf896fe5f70176df132ef271ed9d1b386c2 Mon Sep 17 00:00:00 2001 From: pbatko-da Date: Wed, 13 Oct 2021 14:19:10 +0200 Subject: [PATCH 08/13] [DPP-417][DDP-612] Adapt ApiSubmissionService to support V2 error codes (#11052) Adapt ApiSubmissionService to support self-service (v2) error codes CHANGELOG_BEGIN CHANGELOG_END --- .../error/definitions/LedgerApiErrors.scala | 17 ++++ .../definitions/RejectionGenerators.scala | 5 +- .../platform/apiserver/ApiServices.scala | 1 + .../apiserver/ErrorCodesVersionSwitcher.scala | 14 ++- .../services/ApiSubmissionService.scala | 60 +++++++++++-- .../services/ApiSubmissionServiceSpec.scala | 85 ++++++++++++------- 6 files changed, 141 insertions(+), 41 deletions(-) diff --git a/ledger/error/src/main/scala/com/daml/error/definitions/LedgerApiErrors.scala b/ledger/error/src/main/scala/com/daml/error/definitions/LedgerApiErrors.scala index e38ce3a14fe4..4d389a0b2f39 100644 --- a/ledger/error/src/main/scala/com/daml/error/definitions/LedgerApiErrors.scala +++ b/ledger/error/src/main/scala/com/daml/error/definitions/LedgerApiErrors.scala @@ -381,6 +381,23 @@ object LedgerApiErrors extends LedgerApiErrorGroup { } + @Explanation( + "The ledger configuration could not be retrieved. This could happen due to incomplete initialization of the participant or due to an internal system error." + ) + @Resolution("Contact the participant operator.") + object LedgerConfigurationNotFound + extends ErrorCode( + id = "LEDGER_CONFIGURATION_NOT_FOUND", + ErrorCategory.InvalidGivenCurrentSystemStateResourceMissing, + ) { + + case class Reject()(implicit + loggingContext: ErrorCodeLoggingContext + ) extends LoggingTransactionErrorImpl( + cause = "The ledger configuration is not available." + ) + } + } @Explanation("""This error occurs if the Daml transaction fails due to an authorization error. diff --git a/ledger/error/src/main/scala/com/daml/error/definitions/RejectionGenerators.scala b/ledger/error/src/main/scala/com/daml/error/definitions/RejectionGenerators.scala index 0827a978584b..d300745da067 100644 --- a/ledger/error/src/main/scala/com/daml/error/definitions/RejectionGenerators.scala +++ b/ledger/error/src/main/scala/com/daml/error/definitions/RejectionGenerators.scala @@ -56,7 +56,7 @@ class RejectionGenerators(conformanceMode: Boolean) { def commandExecutorError(cause: ErrorCauseExport)(implicit errorLoggingContext: ErrorCodeLoggingContext - ): Option[StatusRuntimeException] = { + ): StatusRuntimeException = { def processPackageError(err: LfError.Package.Error): BaseError = err match { case e: Package.Internal => LedgerApiErrors.InternalError.PackageInternal(e) @@ -172,12 +172,11 @@ class RejectionGenerators(conformanceMode: Boolean) { toGrpc(transformed) } - val rej = cause match { + cause match { case ErrorCauseExport.DamlLf(error) => processLfError(error) case x: ErrorCauseExport.LedgerTime => toGrpc(LedgerApiErrors.CommandPreparation.FailedToDetermineLedgerTime.Reject(x.explain)) } - Some(rej) } def submissionResult(result: Try[state.v2.SubmissionResult]): Option[Try[Unit]] = { diff --git a/ledger/participant-integration-api/src/main/scala/platform/apiserver/ApiServices.scala b/ledger/participant-integration-api/src/main/scala/platform/apiserver/ApiServices.scala index b1ad13208b25..240efff9e118 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/apiserver/ApiServices.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/apiserver/ApiServices.scala @@ -235,6 +235,7 @@ private[daml] object ApiServices { submissionConfig.enableDeduplication, ), metrics, + errorsVersionsSwitcher, ) // Note: the command service uses the command submission, command completion, and transaction diff --git a/ledger/participant-integration-api/src/main/scala/platform/apiserver/ErrorCodesVersionSwitcher.scala b/ledger/participant-integration-api/src/main/scala/platform/apiserver/ErrorCodesVersionSwitcher.scala index d8ae67eaa9fc..07f2689f0613 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/apiserver/ErrorCodesVersionSwitcher.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/apiserver/ErrorCodesVersionSwitcher.scala @@ -6,5 +6,17 @@ package com.daml.platform.apiserver import com.daml.error.ValueSwitch import io.grpc.StatusRuntimeException +import scala.concurrent.Future + +/** A mechanism to switch between the legacy error codes (v1) and the new self-service error codes (v2). + * This class is intended to facilitate transition to self-service error codes. + * Once the previous error codes are removed, this class should be dropped as well. + */ final class ErrorCodesVersionSwitcher(enableSelfServiceErrorCodes: Boolean) - extends ValueSwitch[StatusRuntimeException](enableSelfServiceErrorCodes) + extends ValueSwitch[StatusRuntimeException](enableSelfServiceErrorCodes) { + + def chooseAsFailedFuture[T]( + v1: => StatusRuntimeException, + v2: => StatusRuntimeException, + ): Future[T] = Future.failed(choose(v1 = v1, v2 = v2)) +} diff --git a/ledger/participant-integration-api/src/main/scala/platform/apiserver/services/ApiSubmissionService.scala b/ledger/participant-integration-api/src/main/scala/platform/apiserver/services/ApiSubmissionService.scala index 5b1260f1e79e..290cd55917fb 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/apiserver/services/ApiSubmissionService.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/apiserver/services/ApiSubmissionService.scala @@ -4,7 +4,8 @@ package com.daml.platform.apiserver.services import com.daml.api.util.TimeProvider -import com.daml.error.ErrorCause +import com.daml.error.definitions.{ErrorCauseExport, LedgerApiErrors, RejectionGenerators} +import com.daml.error.{DamlErrorCodeLoggingContext, ErrorCause} import com.daml.ledger.api.domain.{LedgerId, Commands => ApiCommands} import com.daml.ledger.api.messages.command.submission.SubmitRequest import com.daml.ledger.api.{DeduplicationPeriod, SubmissionIdGenerator} @@ -20,9 +21,9 @@ import com.daml.logging.LoggingContext.withEnrichedLoggingContext import com.daml.logging.{ContextualizedLogger, LoggingContext} import com.daml.metrics.Metrics import com.daml.platform.api.grpc.GrpcApiService -import com.daml.platform.apiserver.SeedService import com.daml.platform.apiserver.configuration.LedgerConfigurationSubscription import com.daml.platform.apiserver.execution.{CommandExecutionResult, CommandExecutor} +import com.daml.platform.apiserver.{ErrorCodesVersionSwitcher, SeedService} import com.daml.platform.server.api.services.domain.CommandSubmissionService import com.daml.platform.server.api.services.grpc.GrpcCommandSubmissionService import com.daml.platform.server.api.validation.ErrorFactories @@ -52,6 +53,7 @@ private[apiserver] object ApiSubmissionService { commandExecutor: CommandExecutor, configuration: ApiSubmissionService.Configuration, metrics: Metrics, + errorCodesVersionSwitcher: ErrorCodesVersionSwitcher, )(implicit executionContext: ExecutionContext, loggingContext: LoggingContext, @@ -68,6 +70,7 @@ private[apiserver] object ApiSubmissionService { commandExecutor, configuration, metrics, + errorCodesVersionSwitcher, ), ledgerId = ledgerId, currentLedgerTime = () => timeProvider.getCurrentTime, @@ -96,6 +99,7 @@ private[apiserver] final class ApiSubmissionService private[services] ( commandExecutor: CommandExecutor, configuration: ApiSubmissionService.Configuration, metrics: Metrics, + errorCodesVersionSwitcher: ErrorCodesVersionSwitcher, )(implicit executionContext: ExecutionContext, loggingContext: LoggingContext) extends CommandSubmissionService with ErrorFactories @@ -103,6 +107,9 @@ private[apiserver] final class ApiSubmissionService private[services] ( private val logger = ContextualizedLogger.get(this.getClass) + // TODO error codes: review conformance mode usages wherever RejectionGenerators is instantiated + private val rejectionGenerators = new RejectionGenerators(conformanceMode = true) + override def submit( request: SubmitRequest )(implicit telemetryContext: TelemetryContext): Future[Unit] = @@ -123,7 +130,7 @@ private[apiserver] final class ApiSubmissionService private[services] ( .transform(handleSubmissionResult) } case None => - Future.failed[Unit](ErrorFactories.missingLedgerConfig(definiteAnswer = Some(false))) + failedOnMissingLedgerConfiguration() } evaluatedCommand .andThen(logger.logErrorsOnCall[Unit]) @@ -155,9 +162,7 @@ private[apiserver] final class ApiSubmissionService private[services] ( } case _: CommandDeduplicationDuplicate => metrics.daml.commands.deduplicatedCommands.mark() - val exception = duplicateCommandException - logger.debug(exception.getMessage) - Future.failed(exception) + failedOnDuplicateCommand() } private def handleSubmissionResult(result: Try[state.SubmissionResult])(implicit @@ -185,7 +190,7 @@ private[apiserver] final class ApiSubmissionService private[services] ( result.fold( error => { metrics.daml.commands.failedCommandInterpretations.mark() - Future.failed(toStatusException(error)) + failedOnCommandExecution(error) }, Future.successful, ) @@ -283,7 +288,10 @@ private[apiserver] final class ApiSubmissionService private[services] ( .toScala } - private def toStatusException(errorCause: ErrorCause): StatusRuntimeException = + /** This method encodes logic related to legacy error codes (V1). + * Cf. self-service error codes (V2) in //ledger/error + */ + private def toStatusExceptionV1(errorCause: ErrorCause): StatusRuntimeException = errorCause match { case cause @ ErrorCause.DamlLf(error) => error match { @@ -302,6 +310,42 @@ private[apiserver] final class ApiSubmissionService private[services] ( ErrorFactories.aborted(cause.explain, definiteAnswer = Some(false)) } + private def failedOnMissingLedgerConfiguration()(implicit + loggingContext: LoggingContext + ): Future[Unit] = { + errorCodesVersionSwitcher.chooseAsFailedFuture( + v1 = ErrorFactories.missingLedgerConfig(definiteAnswer = Some(false)), + v2 = LedgerApiErrors.InterpreterErrors.LookupErrors.LedgerConfigurationNotFound + .Reject()(new DamlErrorCodeLoggingContext(logger, loggingContext, None)) + .asGrpcError, + ) + } + + private def failedOnDuplicateCommand()(implicit loggingContext: LoggingContext): Future[Unit] = { + errorCodesVersionSwitcher.chooseAsFailedFuture( + v1 = { + val exception = duplicateCommandException + logger.debug(exception.getMessage) + exception + }, + v2 = rejectionGenerators.duplicateCommand( + new DamlErrorCodeLoggingContext(logger, loggingContext, None) + ), + ) + } + + private def failedOnCommandExecution( + error: ErrorCause + )(implicit loggingContext: LoggingContext): Future[CommandExecutionResult] = { + errorCodesVersionSwitcher.chooseAsFailedFuture( + v1 = toStatusExceptionV1(error), + v2 = rejectionGenerators + .commandExecutorError(cause = ErrorCauseExport.fromErrorCause(error))( + new DamlErrorCodeLoggingContext(logger, loggingContext, None) + ), + ) + } + override def close(): Unit = () } 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 c41c60832bd9..1ff1d329ab34 100644 --- a/ledger/participant-integration-api/src/test/suite/scala/platform/apiserver/services/ApiSubmissionServiceSpec.scala +++ b/ledger/participant-integration-api/src/test/suite/scala/platform/apiserver/services/ApiSubmissionServiceSpec.scala @@ -3,22 +3,19 @@ package com.daml.platform.apiserver.services -import java.time.{Duration, Instant} -import java.util.UUID -import java.util.concurrent.CompletableFuture.completedFuture -import java.util.concurrent.atomic.AtomicInteger import com.codahale.metrics.MetricRegistry import com.daml.error.ErrorCause -import com.daml.ledger.api.{DeduplicationPeriod, DomainMocks} import com.daml.ledger.api.domain.{CommandId, Commands, LedgerId, PartyDetails, SubmissionId} import com.daml.ledger.api.messages.command.submission.SubmitRequest import com.daml.ledger.api.testing.utils.AkkaBeforeAndAfterAll +import com.daml.ledger.api.{DeduplicationPeriod, DomainMocks} import com.daml.ledger.configuration.{Configuration, LedgerTimeModel} import com.daml.ledger.participant.state.index.v2.{ CommandDeduplicationNew, IndexPartyManagementService, IndexSubmissionService, } +import com.daml.ledger.participant.state.v2.WriteService import com.daml.ledger.participant.state.{v2 => state} import com.daml.ledger.resources.TestResourceContext import com.daml.lf @@ -34,20 +31,24 @@ import com.daml.lf.transaction.{GlobalKey, NodeId, ReplayMismatch} import com.daml.lf.value.Value import com.daml.logging.LoggingContext import com.daml.metrics.Metrics -import com.daml.platform.apiserver.SeedService import com.daml.platform.apiserver.configuration.LedgerConfigurationSubscription import com.daml.platform.apiserver.execution.CommandExecutor import com.daml.platform.apiserver.services.ApiSubmissionServiceSpec._ +import com.daml.platform.apiserver.{ErrorCodesVersionSwitcher, SeedService} import com.daml.telemetry.{NoOpTelemetryContext, TelemetryContext} import com.google.rpc.status.{Status => RpcStatus} import io.grpc.Status import org.mockito.{ArgumentMatchersSugar, MockitoSugar} -import org.scalatest.Inside import org.scalatest.flatspec.AsyncFlatSpec import org.scalatest.matchers.should.Matchers +import org.scalatest.{Assertion, Inside} +import java.time.{Duration, Instant} +import java.util.UUID +import java.util.concurrent.CompletableFuture.completedFuture +import java.util.concurrent.atomic.AtomicInteger import scala.concurrent.{ExecutionContext, Future} -import scala.util.{Failure, Success} +import scala.util.{Failure, Success, Try} class ApiSubmissionServiceSpec extends AsyncFlatSpec @@ -229,18 +230,29 @@ class ApiSubmissionServiceSpec behavior of "submit" it should "return proper gRPC status codes for DamlLf errors" in { - val partyManagementService = mock[IndexPartyManagementService] - val writeService = mock[state.WriteService] + testProperGrpcStatusCodesForDamlLfErrors(useSelfServiceErrorCodes = false) + } + it should "return proper gRPC status codes for DamlLf errors (self service error codes a.k.a v2 error codes)" in { + testProperGrpcStatusCodesForDamlLfErrors(useSelfServiceErrorCodes = true) + } + + private def testProperGrpcStatusCodesForDamlLfErrors( + useSelfServiceErrorCodes: Boolean + ): Future[Assertion] = { + // given + val partyManagementService = mock[IndexPartyManagementService] + val writeService = mock[WriteService] + val mockCommandExecutor = mock[CommandExecutor] val tmplId = toIdentifier("M:T") - val errorsToStatuses = List( + val errorsToExpectedStatuses: Seq[(ErrorCause, Status)] = List( ErrorCause.DamlLf( LfError.Interpretation( LfError.Interpretation.DamlException(LfInterpretationError.ContractNotFound("#cid")), None, ) - ) -> Status.ABORTED, + ) -> ((Status.ABORTED, Status.ABORTED)), ErrorCause.DamlLf( LfError.Interpretation( LfError.Interpretation.DamlException( @@ -250,12 +262,12 @@ class ApiSubmissionServiceSpec ), None, ) - ) -> Status.ABORTED, + ) -> ((Status.ABORTED, Status.ALREADY_EXISTS)), ErrorCause.DamlLf( LfError.Validation( LfError.Validation.ReplayMismatch(ReplayMismatch(null, null)) ) - ) -> Status.ABORTED, + ) -> ((Status.ABORTED, Status.INTERNAL)), ErrorCause.DamlLf( LfError.Preprocessing( LfError.Preprocessing.Lookup( @@ -265,7 +277,7 @@ class ApiSubmissionServiceSpec ) ) ) - ) -> Status.INVALID_ARGUMENT, + ) -> ((Status.INVALID_ARGUMENT, Status.INVALID_ARGUMENT)), ErrorCause.DamlLf( LfError.Interpretation( LfError.Interpretation.DamlException( @@ -276,20 +288,27 @@ class ApiSubmissionServiceSpec ), None, ) - ) -> Status.INVALID_ARGUMENT, - ErrorCause.LedgerTime(0) -> Status.ABORTED, - ) - val mockCommandExecutor = mock[CommandExecutor] + ) -> ((Status.INVALID_ARGUMENT, Status.INVALID_ARGUMENT)), + ErrorCause.LedgerTime(0) -> ((Status.ABORTED, Status.ABORTED)), + ).map { case (key, (statusV1, statusV2)) => + if (useSelfServiceErrorCodes) { + (key, statusV2) + } else { + (key, statusV1) + } + } val service = newSubmissionService( writeService, partyManagementService, implicitPartyAllocation = true, commandExecutor = mockCommandExecutor, + useSelfServiceErrorCodes = useSelfServiceErrorCodes, ) - Future - .sequence(errorsToStatuses.map { case (error, code) => + // when + val results: Seq[Future[(Status, Try[Unit])]] = errorsToExpectedStatuses + .map { case (error, expectedStatus) => val submitRequest = newSubmitRequest() when( mockCommandExecutor.execute( @@ -298,17 +317,21 @@ class ApiSubmissionServiceSpec any[Configuration], )(any[ExecutionContext], any[LoggingContext]) ).thenReturn(Future.successful(Left(error))) + service + .submit(submitRequest) + .transform(result => Success(expectedStatus -> result)) + } + val sequencedResults: Future[Seq[(Status, Try[Unit])]] = Future.sequence(results) - service.submit(submitRequest).transform(result => Success(code -> result)) - }) - .map { results => - results.foreach { case (code, result) => - inside(result) { case Failure(exception) => - exception.getMessage should startWith(code.getCode.toString) - } + // then + sequencedResults.map { results: Seq[(Status, Try[Unit])] => + results.foreach { case (expectedStatus: Status, result: Try[Unit]) => + inside(result) { case Failure(exception) => + exception.getMessage should startWith(expectedStatus.getCode.toString) } - succeed } + succeed + } } behavior of "command deduplication" @@ -431,6 +454,7 @@ object ApiSubmissionServiceSpec { commandExecutor: CommandExecutor = null, deduplicationEnabled: Boolean = true, mockIndexSubmissionService: IndexSubmissionService = mock[IndexSubmissionService], + useSelfServiceErrorCodes: Boolean = false, )(implicit executionContext: ExecutionContext, loggingContext: LoggingContext, @@ -468,6 +492,9 @@ object ApiSubmissionServiceSpec { configuration = ApiSubmissionService .Configuration(implicitPartyAllocation, enableDeduplication = true), metrics = new Metrics(new MetricRegistry), + errorCodesVersionSwitcher = new ErrorCodesVersionSwitcher( + enableSelfServiceErrorCodes = useSelfServiceErrorCodes + ), ) } } From 7a88c7d97c68d07d7399e15cb87d3873e562d82a Mon Sep 17 00:00:00 2001 From: Robin Krom Date: Wed, 13 Oct 2021 14:22:10 +0200 Subject: [PATCH 09/13] trigger-service: dev-mode-unsafe flag (#11233) * trigger-service: dev-mode-unsafe flag This adds a `--dev-mode-unsafe` flag analogous to the trigger service analogous to its counterpart in the trigger runner. CHANGELOG_BEGIN CHANGELOG_END * fix tests --- triggers/service/BUILD.bazel | 2 ++ .../daml/lf/engine/trigger/Server.scala | 9 ++++++--- .../daml/lf/engine/trigger/ServiceConfig.scala | 13 +++++++++++++ .../daml/lf/engine/trigger/ServiceMain.scala | 4 ++++ .../lf/engine/trigger/TriggerServiceFixture.scala | 2 ++ 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/triggers/service/BUILD.bazel b/triggers/service/BUILD.bazel index 276905d26ce2..8313503e7dd9 100644 --- a/triggers/service/BUILD.bazel +++ b/triggers/service/BUILD.bazel @@ -95,6 +95,7 @@ binary_deps = [ "//daml-lf/archive:daml_lf_archive_reader", "//daml-lf/archive:daml_lf_dev_archive_proto_java", "//daml-lf/data", + "//daml-lf/interpreter", "//language-support/scala/bindings", "//ledger/ledger-api-common", "//libs-scala/contextualized-logging", @@ -161,6 +162,7 @@ da_scala_library( "//daml-lf/archive:daml_lf_archive_reader", "//daml-lf/archive:daml_lf_dev_archive_proto_java", "//daml-lf/data", + "//daml-lf/interpreter", "//language-support/scala/bindings-akka", "//ledger-api/rs-grpc-bridge", "//ledger-api/testing-utils", diff --git a/triggers/service/src/main/scala/com/digitalasset/daml/lf/engine/trigger/Server.scala b/triggers/service/src/main/scala/com/digitalasset/daml/lf/engine/trigger/Server.scala index d771f076fa8e..fe519c856512 100644 --- a/triggers/service/src/main/scala/com/digitalasset/daml/lf/engine/trigger/Server.scala +++ b/triggers/service/src/main/scala/com/digitalasset/daml/lf/engine/trigger/Server.scala @@ -44,6 +44,7 @@ import com.daml.auth.middleware.api.{ Request => AuthRequest, Response => AuthResponse, } +import com.daml.lf.speedy.Compiler import com.daml.scalautil.Statement.discard import com.daml.scalautil.ExceptionOps._ import com.typesafe.scalalogging.StrictLogging @@ -59,6 +60,7 @@ import scala.util.{Failure, Success, Try} class Server( authRoutes: Option[Directive1[AuthClient.Routes]], triggerDao: RunningTriggerDao, + compilerConfig: Compiler.Config, val logTriggerStatus: (UUID, String) => Unit, )(implicit ctx: ActorContext[Server.Message]) extends StrictLogging { @@ -67,7 +69,7 @@ class Server( // When running with a persistent store we also write the encoded packages so we can recover // our state after the service shuts down or crashes. val compiledPackages: MutableCompiledPackages = - ConcurrentCompiledPackages(speedy.Compiler.Config.Dev) + ConcurrentCompiledPackages(compilerConfig) private def addPackagesInMemory(pkgs: List[(PackageId, DamlLf.ArchivePayload)]): Unit = { // We store decoded packages in memory @@ -504,6 +506,7 @@ object Server { initialDars: List[Dar[(PackageId, DamlLf.ArchivePayload)]], jdbcConfig: Option[JdbcConfig], allowExistingSchema: Boolean, + compilerConfig: speedy.Compiler.Config, logTriggerStatus: (UUID, String) => Unit = (_, _) => (), ): Behavior[Message] = Behaviors.setup { implicit ctx => // Implicit boilerplate. @@ -540,11 +543,11 @@ object Server { val (dao, server, initializeF): (RunningTriggerDao, Server, Future[Unit]) = jdbcConfig match { case None => val dao = InMemoryTriggerDao() - val server = new Server(authRoutes, dao, logTriggerStatus) + val server = new Server(authRoutes, dao, compilerConfig, logTriggerStatus) (dao, server, Future.successful(())) case Some(c) => val dao = DbTriggerDao(c) - val server = new Server(authRoutes, dao, logTriggerStatus) + val server = new Server(authRoutes, dao, compilerConfig, logTriggerStatus) val initialize = for { _ <- dao.initialize(allowExistingSchema) packages <- dao.readPackages diff --git a/triggers/service/src/main/scala/com/digitalasset/daml/lf/engine/trigger/ServiceConfig.scala b/triggers/service/src/main/scala/com/digitalasset/daml/lf/engine/trigger/ServiceConfig.scala index 2af8b623b6b6..08e2c45f08b0 100644 --- a/triggers/service/src/main/scala/com/digitalasset/daml/lf/engine/trigger/ServiceConfig.scala +++ b/triggers/service/src/main/scala/com/digitalasset/daml/lf/engine/trigger/ServiceConfig.scala @@ -3,6 +3,8 @@ package com.daml.lf.engine.trigger +import com.daml.lf.speedy.Compiler + import java.nio.file.{Path, Paths} import java.time.Duration @@ -41,6 +43,7 @@ private[trigger] final case class ServiceConfig( jdbcConfig: Option[JdbcConfig], portFile: Option[Path], allowExistingSchema: Boolean, + compilerConfig: Compiler.Config, ) private[trigger] object ServiceConfig { @@ -53,6 +56,7 @@ private[trigger] object ServiceConfig { val DefaultAuthCallbackTimeout: FiniteDuration = FiniteDuration(1, duration.MINUTES) val DefaultMaxHttpEntityUploadSize: Long = RunnerConfig.DefaultMaxInboundMessageSize.toLong val DefaultHttpEntityUploadTimeout: FiniteDuration = FiniteDuration(1, duration.MINUTES) + val DefaultCompilerConfig: Compiler.Config = Compiler.Config.Default implicit val redirectToLoginRead: scopt.Read[AuthClient.RedirectToLogin] = scopt.Read.reads { _.toLowerCase match { @@ -190,6 +194,14 @@ private[trigger] object ServiceConfig { } .text("TTL in seconds used for commands emitted by the trigger. Defaults to 30s.") + opt[Unit]("dev-mode-unsafe") + .action((_, c) => c.copy(compilerConfig = Compiler.Config.Dev)) + .optional() + .text( + "Turns on development mode. Development mode allows development versions of Daml-LF language." + ) + .hidden() + implicit val jcd: DBConfig.JdbcConfigDefaults = DBConfig.JdbcConfigDefaults( supportedJdbcDrivers = supportedJdbcDriverNames, defaultDriver = Some("org.postgresql.Driver"), @@ -263,6 +275,7 @@ private[trigger] object ServiceConfig { jdbcConfig = None, portFile = None, allowExistingSchema = false, + compilerConfig = DefaultCompilerConfig, ), ) } diff --git a/triggers/service/src/main/scala/com/digitalasset/daml/lf/engine/trigger/ServiceMain.scala b/triggers/service/src/main/scala/com/digitalasset/daml/lf/engine/trigger/ServiceMain.scala index 9352b6a1f479..22f27c2de475 100644 --- a/triggers/service/src/main/scala/com/digitalasset/daml/lf/engine/trigger/ServiceMain.scala +++ b/triggers/service/src/main/scala/com/digitalasset/daml/lf/engine/trigger/ServiceMain.scala @@ -17,6 +17,7 @@ import com.daml.dbutils.JdbcConfig import com.daml.lf.archive.{Dar, DarReader} import com.daml.lf.data.Ref.PackageId import com.daml.lf.engine.trigger.dao.DbTriggerDao +import com.daml.lf.speedy.Compiler import com.daml.logging.ContextualizedLogger import com.daml.ports.{Port, PortFiles} import com.daml.scalautil.Statement.discard @@ -51,6 +52,7 @@ object ServiceMain { encodedDars: List[Dar[(PackageId, DamlLf.ArchivePayload)]], jdbcConfig: Option[JdbcConfig], allowExistingSchema: Boolean, + compilerConfig: Compiler.Config, logTriggerStatus: (UUID, String) => Unit = (_, _) => (), ): Future[(ServerBinding, ActorSystem[Server.Message])] = { @@ -71,6 +73,7 @@ object ServiceMain { encodedDars, jdbcConfig, allowExistingSchema, + compilerConfig, logTriggerStatus, ), "TriggerService", @@ -164,6 +167,7 @@ object ServiceMain { encodedDars, config.jdbcConfig, config.allowExistingSchema, + config.compilerConfig, ), "TriggerService", ) diff --git a/triggers/service/src/test/scala/com/digitalasset/daml/lf/engine/trigger/TriggerServiceFixture.scala b/triggers/service/src/test/scala/com/digitalasset/daml/lf/engine/trigger/TriggerServiceFixture.scala index 8c77e6db5739..dcaba78814a9 100644 --- a/triggers/service/src/test/scala/com/digitalasset/daml/lf/engine/trigger/TriggerServiceFixture.scala +++ b/triggers/service/src/test/scala/com/digitalasset/daml/lf/engine/trigger/TriggerServiceFixture.scala @@ -47,6 +47,7 @@ import com.daml.ledger.resources.{Resource, ResourceContext, ResourceOwner} import com.daml.lf.archive.Dar import com.daml.lf.data.Ref._ import com.daml.lf.engine.trigger.dao.DbTriggerDao +import com.daml.lf.speedy.Compiler import com.daml.platform.apiserver.SeedService.Seeding import com.daml.platform.apiserver.services.GrpcClientResource import com.daml.platform.common.LedgerIdMode @@ -524,6 +525,7 @@ trait TriggerServiceFixture encodedDars, jdbcConfig, false, + Compiler.Config.Dev, logTriggerStatus, ) } yield r From ce64cb2a13f2e1a3a75e6549c8e2a35fce395d2d Mon Sep 17 00:00:00 2001 From: Sofia Faro Date: Wed, 13 Oct 2021 13:36:53 +0100 Subject: [PATCH 10/13] interfaces: Do some TODOs (#11231) * interfaces: Do some TODOs - Add uniqueness check between fixed choices and virtual choices in haskell decoder. - Encode interface methods and fixed choices in scala encoder. - ExprIterable for interfaces. changelog_begin changelog_end * scalafmt --- .../src/DA/Daml/LF/Proto3/DecodeV1.hs | 23 ++++---- .../daml/lf/archive/testing/EncodeV1.scala | 59 +++++++++++++------ .../lf/validation/iterable/ExprIterable.scala | 44 +++++++++++++- 3 files changed, 95 insertions(+), 31 deletions(-) diff --git a/compiler/daml-lf-proto/src/DA/Daml/LF/Proto3/DecodeV1.hs b/compiler/daml-lf-proto/src/DA/Daml/LF/Proto3/DecodeV1.hs index 196f7067aac4..2ac6be6752c4 100644 --- a/compiler/daml-lf-proto/src/DA/Daml/LF/Proto3/DecodeV1.hs +++ b/compiler/daml-lf-proto/src/DA/Daml/LF/Proto3/DecodeV1.hs @@ -24,6 +24,7 @@ import Data.List import DA.Daml.LF.Mangling import qualified Com.Daml.DamlLfDev.DamlLf1 as LF1 import qualified Data.NameMap as NM +import qualified Data.HashSet as HS import qualified Data.Text as T import qualified Data.Text.Lazy as TL import qualified Data.Vector.Extended as V @@ -229,16 +230,18 @@ decodeModule (LF1.Module name flags synonyms dataTypes values templates exceptio <*> decodeNM DuplicateInterface decodeDefInterface interfaces decodeDefInterface :: LF1.DefInterface -> Decode DefInterface -decodeDefInterface LF1.DefInterface {..} = - DefInterface - <$> traverse decodeLocation defInterfaceLocation - <*> decodeDottedNameId TypeConName defInterfaceTyconInternedDname - <*> decodeNameId ExprVarName defInterfaceParamInternedStr - <*> decodeNM DuplicateChoice decodeInterfaceChoice defInterfaceChoices - <*> decodeNM DuplicateChoice decodeChoice defInterfaceFixedChoices - <*> decodeNM DuplicateMethod decodeInterfaceMethod defInterfaceMethods - -- TODO https://github.com/digital-asset/daml/issues/11137 - -- maybe also check that choice names are unique between virtual choices & fixed choices +decodeDefInterface LF1.DefInterface {..} = do + intLocation <- traverse decodeLocation defInterfaceLocation + intName <- decodeDottedNameId TypeConName defInterfaceTyconInternedDname + intParam <- decodeNameId ExprVarName defInterfaceParamInternedStr + intVirtualChoices <- decodeNM DuplicateChoice decodeInterfaceChoice defInterfaceChoices + intFixedChoices <- decodeNM DuplicateChoice decodeChoice defInterfaceFixedChoices + intMethods <- decodeNM DuplicateMethod decodeInterfaceMethod defInterfaceMethods + unless (HS.null (NM.namesSet intFixedChoices `HS.intersection` NM.namesSet intVirtualChoices)) $ + throwError $ ParseError $ unwords + [ "Interface", T.unpack (T.intercalate "." (unTypeConName intName)) + , "has collision between fixed choice and virtual choice." ] + pure DefInterface {..} decodeInterfaceChoice :: LF1.InterfaceChoice -> Decode InterfaceChoice decodeInterfaceChoice LF1.InterfaceChoice {..} = diff --git a/daml-lf/encoder/src/main/scala/com/digitalasset/daml/lf/archive/testing/EncodeV1.scala b/daml-lf/encoder/src/main/scala/com/digitalasset/daml/lf/archive/testing/EncodeV1.scala index 5345324fa630..06a59eac81f8 100644 --- a/daml-lf/encoder/src/main/scala/com/digitalasset/daml/lf/archive/testing/EncodeV1.scala +++ b/daml-lf/encoder/src/main/scala/com/digitalasset/daml/lf/archive/testing/EncodeV1.scala @@ -724,12 +724,35 @@ private[daml] class EncodeV1(minor: LV.Minor) { val (dottedName, interface) = nameWithDef val builder = PLF.DefInterface.newBuilder() builder.setTyconInternedDname(dottedNameTable.insert(dottedName)) + builder.setParamInternedStr(stringsTable.insert(interface.param)) builder.accumulateLeft(interface.virtualChoices.sortByKey)(_ addChoices _) - // TODO https://github.com/digital-asset/daml/issues/11006 - // encode interface methods as well + builder.accumulateLeft(interface.fixedChoices.sortByKey)(_ addFixedChoices _) + builder.accumulateLeft(interface.methods.sortByKey)(_ addMethods _) builder.build() } + private implicit def encodeInterfaceChoice( + nameWithChoice: (ChoiceName, InterfaceChoice) + ): PLF.InterfaceChoice = { + val (name, choice) = nameWithChoice + val b = PLF.InterfaceChoice.newBuilder() + b.setNameInternedString(stringsTable.insert(name)) + b.setConsuming(choice.consuming) + b.setArgType(choice.argType) + b.setRetType(choice.returnType) + b.build() + } + + private implicit def encodeInterfaceMethod( + nameWithMethod: (MethodName, InterfaceMethod) + ): PLF.InterfaceMethod = { + val (name, method) = nameWithMethod + val b = PLF.InterfaceMethod.newBuilder() + b.setMethodInternedName(stringsTable.insert(name)) + b.setType(method.returnType) + b.build() + } + private implicit def encodeSynonymDef(nameWithDef: (DottedName, DTypeSyn)): PLF.DefTypeSyn = { val (dottedName, typeSyn) = nameWithDef val builder = PLF.DefTypeSyn.newBuilder() @@ -783,18 +806,6 @@ private[daml] class EncodeV1(minor: LV.Minor) { b.build() } - private implicit def encodeInterfaceChoice( - nameWithChoice: (ChoiceName, InterfaceChoice) - ): PLF.InterfaceChoice = { - val (name, choice) = nameWithChoice - val b = PLF.InterfaceChoice.newBuilder() - b.setNameInternedString(stringsTable.insert(name)) - b.setConsuming(choice.consuming) - b.setArgType(choice.argType) - b.setRetType(choice.returnType) - b.build() - } - private implicit def encodeTemplateKey(key: TemplateKey): PLF.DefTemplate.DefKey = PLF.DefTemplate.DefKey .newBuilder() @@ -816,17 +827,27 @@ private[daml] class EncodeV1(minor: LV.Minor) { b.accumulateLeft(template.choices.sortByKey)(_ addChoices _) b.setObservers(template.observers) template.key.foreach(b.setKey(_)) - b.accumulateLeft(template.implements.values)(_ addImplements encodeTemplateImplements(_)) + b.accumulateLeft(template.implements.sortByKey)(_ addImplements _) b.build() } - // TODO https://github.com/digital-asset/daml/issues/11006 - // encode rest of TemplateImplements private implicit def encodeTemplateImplements( - impl: TemplateImplements + interfaceWithImplements: (TypeConName, TemplateImplements) ): PLF.DefTemplate.Implements = { + val (interface, implements) = interfaceWithImplements val b = PLF.DefTemplate.Implements.newBuilder() - b.setInterface(impl.interface) + b.setInterface(interface) + b.accumulateLeft(implements.methods.sortByKey)(_ addMethods _) + b.build() + } + + private implicit def encodeTemplateImplementsMethod( + nameWithMethod: (MethodName, TemplateImplementsMethod) + ): PLF.DefTemplate.ImplementsMethod = { + val (name, method) = nameWithMethod + val b = PLF.DefTemplate.ImplementsMethod.newBuilder() + b.setMethodInternedName(stringsTable.insert(name)) + b.setValue(method.value) b.build() } diff --git a/daml-lf/validation/src/main/scala/com/digitalasset/daml/lf/validation/iterable/ExprIterable.scala b/daml-lf/validation/src/main/scala/com/digitalasset/daml/lf/validation/iterable/ExprIterable.scala index dc22fe070f87..b01b16a2ba11 100644 --- a/daml-lf/validation/src/main/scala/com/digitalasset/daml/lf/validation/iterable/ExprIterable.scala +++ b/daml-lf/validation/src/main/scala/com/digitalasset/daml/lf/validation/iterable/ExprIterable.scala @@ -141,12 +141,13 @@ private[validation] object ExprIterable { choices, observers, key, - implements @ _, // TODO https://github.com/digital-asset/daml/issues/11006 + implements, ) => Iterator(precond, signatories, agreementText) ++ choices.values.iterator.flatMap(iterator(_)) ++ Iterator(observers) ++ - key.iterator.flatMap(iterator(_)) + key.iterator.flatMap(iterator(_)) ++ + implements.values.iterator.flatMap(iterator(_)) } private[iterable] def iterator(x: TemplateChoice): Iterator[Expr] = @@ -172,6 +173,43 @@ private[validation] object ExprIterable { Iterator(body, maintainers) } + private[iterable] def iterator(x: TemplateImplements): Iterator[Expr] = + x match { + case TemplateImplements( + interface @ _, + methods, + ) => + methods.values.iterator.flatMap(iterator(_)) + } + + private[iterable] def iterator(x: TemplateImplementsMethod): Iterator[Expr] = + x match { + case TemplateImplementsMethod( + name @ _, + value, + ) => + Iterator(value) + } + + private[iterable] def iterator(x: DefException): Iterator[Expr] = + x match { + case DefException( + message + ) => + Iterator(message) + } + + private[iterable] def iterator(x: DefInterface): Iterator[Expr] = + x match { + case DefInterface( + param @ _, + virtualChoices @ _, + fixedChoices, + methods @ _, + ) => + fixedChoices.values.iterator.flatMap(iterator(_)) + } + def apply(expr: Expr): Iterable[Expr] = new Iterable[Expr] { override def iterator: Iterator[Expr] = ExprIterable.iterator(expr) @@ -186,6 +224,8 @@ private[validation] object ExprIterable { new Iterable[Expr] { override def iterator: Iterator[Expr] = module.definitions.values.iterator.flatMap(ExprIterable.iterator(_)) ++ + module.exceptions.values.iterator.flatMap(ExprIterable.iterator(_)) ++ + module.interfaces.values.iterator.flatMap(ExprIterable.iterator(_)) ++ module.templates.values.iterator.flatMap(ExprIterable.iterator(_)) } } From 139b6f3b9eb5a253baf9db9ad721f01628c87611 Mon Sep 17 00:00:00 2001 From: Samir Talwar Date: Wed, 13 Oct 2021 14:55:20 +0200 Subject: [PATCH 11/13] CI: Set `PROJ_DIR` inside the bash lib, not outside. (#11236) * CI: Set `PROJ_DIR` inside the bash lib, not outside. We can't reference variables set outside. CHANGELOG_BEGIN CHANGELOG_END * CI: Remove an unnecessary `export`. --- ci/bash-lib.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ci/bash-lib.yml b/ci/bash-lib.yml index 73195ac836c5..b5f35bf9c97f 100644 --- a/ci/bash-lib.yml +++ b/ci/bash-lib.yml @@ -2,14 +2,14 @@ # SPDX-License-Identifier: Apache-2.0 parameters: - var_name: '' + var_name: "" steps: - bash: | set -euo pipefail TMP=$(mktemp) - PROJ_DIR="$(pwd)" - cat > $TMP <<'END' + cat > "$TMP" <<'END' + PROJ_DIR="$PWD" escape_slack() { local r r="$1" From 3c26852226c92b6b2e172027a7a02f7dd369a146 Mon Sep 17 00:00:00 2001 From: Remy Date: Wed, 13 Oct 2021 15:24:00 +0200 Subject: [PATCH 12/13] LF: Use template Id in exercise node of fixed choice. (#11229) * LF: Put template Id in exercise node of fixed choice. instead of interface id and fix ValueEnricher. CHANGELOG_BEGIN CHANGELOG_END --- .../damlc/tests/daml-test-files/Interface.daml | 16 +++++++--------- .../daml-test-files/InterfaceDesugared.daml | 16 +++++++--------- .../digitalasset/daml/lf/speedy/Compiler.scala | 6 ++---- .../digitalasset/daml/lf/speedy/SBuiltin.scala | 11 +++++++++++ .../daml/lf/language/PackageInterface.scala | 16 ++++++++++++++-- 5 files changed, 41 insertions(+), 24 deletions(-) diff --git a/compiler/damlc/tests/daml-test-files/Interface.daml b/compiler/damlc/tests/daml-test-files/Interface.daml index 58bc88ca6a64..ee785949da37 100644 --- a/compiler/damlc/tests/daml-test-files/Interface.daml +++ b/compiler/damlc/tests/daml-test-files/Interface.daml @@ -117,14 +117,12 @@ main = scenario do Some Asset {amount} -> amount === 5 - -- TODO https://github.com/digital-asset/daml/issues/11137 - -- uncomment once speedy supports fixed choices - -- cidToken4 <- exercise cidToken3 (GetRich 20) - -- token4 <- fetch cidToken4 - -- getAmount token4 === 25 - -- case fromToken token4 of - -- None -> abort "expected Asset" - -- Some Asset {amount} -> - -- amount === 25 + cidToken4 <- exercise cidToken3 (GetRich 20) + token4 <- fetch cidToken4 + getAmount token4 === 25 + case fromToken token4 of + None -> abort "expected Asset" + Some Asset {amount} -> + amount === 25 pure () diff --git a/compiler/damlc/tests/daml-test-files/InterfaceDesugared.daml b/compiler/damlc/tests/daml-test-files/InterfaceDesugared.daml index 07ccb7bf71da..8e6c138774d3 100644 --- a/compiler/damlc/tests/daml-test-files/InterfaceDesugared.daml +++ b/compiler/damlc/tests/daml-test-files/InterfaceDesugared.daml @@ -233,14 +233,12 @@ main = scenario do Some Asset {amount} -> amount === 5 - -- TODO https://github.com/digital-asset/daml/issues/11137 - -- uncomment once speedy supports fixed choices - -- cidToken4 <- exercise cidToken3 (GetRich 20) - -- token4 <- fetch cidToken4 - -- getAmount token4 === 25 - -- case fromToken token4 of - -- None -> abort "expected Asset" - -- Some Asset {amount} -> - -- amount === 25 + cidToken4 <- exercise cidToken3 (GetRich 20) + token4 <- fetch cidToken4 + getAmount token4 === 25 + case fromToken token4 of + None -> abort "expected Asset" + Some Asset {amount} -> + amount === 25 pure () diff --git a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Compiler.scala b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Compiler.scala index a4f3fea6391c..edf84e9ef05e 100644 --- a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Compiler.scala +++ b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Compiler.scala @@ -1034,10 +1034,8 @@ private[lf] final class Compiler( addExprVar(param, payloadPos) addExprVar(choice.argBinder._1, choiceArgPos) let( - // TODO https://github.com/digital-asset/daml/issues/10810: - // Here we insert an Exercise Node with the interface Id instead of the template Id. \ - // Review if that can cause issues. - SBUBeginExercise(ifaceId, choice.name, choice.consuming, byKey = false)( + SBResolveSBUBeginExercise(choice.name, choice.consuming, byKey = false)( + svar(payloadPos), svar(choiceArgPos), svar(cidPos), compile(choice.controllers), diff --git a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/SBuiltin.scala b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/SBuiltin.scala index d624c39ae96b..68bf560e8843 100644 --- a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/SBuiltin.scala +++ b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/SBuiltin.scala @@ -1128,6 +1128,17 @@ private[lf] object SBuiltin { } } + final case class SBResolveSBUBeginExercise( + choiceName: ChoiceName, + consuming: Boolean, + byKey: Boolean, + ) extends SBuiltin(1) { + override private[speedy] def execute(args: util.ArrayList[SValue], machine: Machine): Unit = + machine.ctrl = SEBuiltin( + SBUBeginExercise(getSRecord(args, 0).id, choiceName, consuming, byKey) + ) + } + // Return a definition matching the templateId of a given payload sealed class SBResolveVirtual(toDef: Ref.Identifier => SDefinitionRef) extends SBuiltin(1) { override private[speedy] def execute(args: util.ArrayList[SValue], machine: Machine): Unit = diff --git a/daml-lf/language/src/main/scala/com/digitalasset/daml/lf/language/PackageInterface.scala b/daml-lf/language/src/main/scala/com/digitalasset/daml/lf/language/PackageInterface.scala index a8bc7e7858ea..a1bd9d38ca7d 100644 --- a/daml-lf/language/src/main/scala/com/digitalasset/daml/lf/language/PackageInterface.scala +++ b/daml-lf/language/src/main/scala/com/digitalasset/daml/lf/language/PackageInterface.scala @@ -6,6 +6,7 @@ package language import com.daml.lf.data.Ref._ import com.daml.lf.language.Ast._ +import scalaz._, std.list._, std.either._, syntax.traverse._ private[lf] class PackageInterface(signatures: PartialFunction[PackageId, PackageSignature]) { @@ -197,8 +198,19 @@ private[lf] class PackageInterface(signatures: PartialFunction[PackageId, Packag chName: ChoiceName, context: => Reference, ): Either[LookupError, TemplateChoiceSignature] = - lookupTemplate(tmpName, context).flatMap( - _.choices.get(chName).toRight(LookupError(Reference.Choice(tmpName, chName), context)) + lookupTemplate(tmpName, context).flatMap(template => + template.choices.get(chName) match { + case Some(choice) => Right(choice) + case None => + // TODO https://github.com/digital-asset/daml/issues/10810 + // Improve lookup for fixed choices + for { + ifaces <- template.implements.keys.toList.traverse(lookupInterface(_, context)) + choices = ifaces.flatMap(_.fixedChoices.get(chName).toList) + choice <- + choices.headOption.toRight(LookupError(Reference.Choice(tmpName, chName), context)) + } yield choice + } ) def lookupChoice( From b7389885e8ae2e97c34b8cdbc7dc7b11d9330c64 Mon Sep 17 00:00:00 2001 From: Moritz Kiefer Date: Wed, 13 Oct 2021 15:27:14 +0200 Subject: [PATCH 13/13] Release 1.18 snapshot (#11234) changelog_begin changelog_end --- LATEST | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LATEST b/LATEST index 4de0c11cd833..91660801f609 100644 --- a/LATEST +++ b/LATEST @@ -1,4 +1,4 @@ -cfcdc13c6e05283d13d74fb9a7e980d294a078ea 1.18.0-snapshot.20211006.8003.0.cfcdc13c +514e8b50a3f901cd82b96ce17ee00f0ddf90dab3 1.18.0-snapshot.20211013.8071.0.514e8b50 e05be36512ade4d9cb6921614c23dadbde1747a3 1.17.1 49a75801fbafa1ffab3247ecfbb06a82925e8a0b 1.17.0 48050ad7836b9825c9dc7bd96fbc980b8eb9b6e5 1.16.0