From 3a0e7a848411936a3c593f1910e015aa5b610153 Mon Sep 17 00:00:00 2001 From: Nicu Reut Date: Tue, 2 Nov 2021 14:54:00 +0100 Subject: [PATCH 1/3] Save the submission time in the command deduplication value within the committer context CHANGELOG_BEGIN CHANGELOG_END --- .../participant/state/kvutils/store/state.proto | 3 +++ .../transaction/TransactionCommitter.scala | 13 +++++++------ .../transaction/TransactionCommitterSpec.scala | 17 ++++++++++++++++- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/state.proto b/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/state.proto index e6da75aae88b..d3d0bdddd300 100644 --- a/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/state.proto +++ b/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/state.proto @@ -57,6 +57,9 @@ message DamlCommandDedupValue { // the time until when future commands with the same // deduplication key will be rejected due to a duplicate submission google.protobuf.Timestamp deduplicated_until = 2; + //The submission time of the initial command + // We use submission time because record time is not available during pre-execution + google.protobuf.Timestamp submission_time = 3; } message DamlSubmissionDedupKey { diff --git a/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/committer/transaction/TransactionCommitter.scala b/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/committer/transaction/TransactionCommitter.scala index 0e938e47c592..d36860fbc724 100644 --- a/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/committer/transaction/TransactionCommitter.scala +++ b/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/committer/transaction/TransactionCommitter.scala @@ -328,13 +328,14 @@ private[kvutils] class TransactionCommitter( if (!transactionEntry.submitterInfo.hasDeduplicationDuration) { throw Err.InvalidSubmission("Deduplication duration is not set.") } - val commandDedupBuilder = DamlCommandDedupValue.newBuilder.setDeduplicatedUntil( - Conversions.buildTimestamp( - transactionEntry.submissionTime - .add(parseDuration(transactionEntry.submitterInfo.getDeduplicationDuration)) - .add(config.timeModel.minSkew) - ) + val deduplicateUntil = Conversions.buildTimestamp( + transactionEntry.submissionTime + .add(parseDuration(transactionEntry.submitterInfo.getDeduplicationDuration)) + .add(config.timeModel.minSkew) ) + val commandDedupBuilder = DamlCommandDedupValue.newBuilder + .setDeduplicatedUntil(deduplicateUntil) + .setSubmissionTime(Conversions.buildTimestamp(transactionEntry.submissionTime)) // Set a deduplication entry. commitContext.set( commandDedupKey(transactionEntry.submitterInfo), diff --git a/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/committer/transaction/TransactionCommitterSpec.scala b/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/committer/transaction/TransactionCommitterSpec.scala index e15ca54f07e3..eec590609d7d 100644 --- a/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/committer/transaction/TransactionCommitterSpec.scala +++ b/ledger/participant-state/kvutils/src/test/suite/scala/com/daml/ledger/participant/state/kvutils/committer/transaction/TransactionCommitterSpec.scala @@ -237,9 +237,9 @@ class TransactionCommitterSpec "setting dedup context" should { val deduplicateUntil = protobuf.Timestamp.newBuilder().setSeconds(30).build() val submissionTime = protobuf.Timestamp.newBuilder().setSeconds(60).build() + val deduplicationDuration = time.Duration.ofSeconds(3) "calculate deduplicate until based on deduplication duration" in { - val deduplicationDuration = time.Duration.ofSeconds(3) val (context, transactionEntrySummary) = buildContextAndTransaction( submissionTime, @@ -257,6 +257,21 @@ class TransactionCommitterSpec .build() } + "set the submission time in the committer context" in { + val (context, transactionEntrySummary) = + buildContextAndTransaction( + submissionTime, + _.setDeduplicationDuration(Conversions.buildDuration(deduplicationDuration)), + ) + transactionCommitter.setDedupEntry(context, transactionEntrySummary) + context + .get(Conversions.commandDedupKey(transactionEntrySummary.submitterInfo)) + .map( + _.getCommandDedup.getSubmissionTime + ) + .value shouldBe submissionTime + } + "throw an error for unsupported deduplication periods" in { forAll( Table[DamlSubmitterInfo.Builder => DamlSubmitterInfo.Builder]( From c8721de0b5247ba1aa446681fe8b3ca366689bbe Mon Sep 17 00:00:00 2001 From: nicu-da Date: Wed, 3 Nov 2021 05:42:35 -0700 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: fabiotudone-da --- .../ledger/participant/state/kvutils/store/state.proto | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/state.proto b/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/state.proto index d3d0bdddd300..d71a1ddcc084 100644 --- a/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/state.proto +++ b/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/state.proto @@ -54,12 +54,11 @@ message DamlCommandDedupKey { message DamlCommandDedupValue { reserved 1; // was record_time - // the time until when future commands with the same - // deduplication key will be rejected due to a duplicate submission + // The time until when future commands with the same + // deduplication key will be rejected due to a duplicate submission. google.protobuf.Timestamp deduplicated_until = 2; - //The submission time of the initial command - // We use submission time because record time is not available during pre-execution - google.protobuf.Timestamp submission_time = 3; + // The submission time of the initial command. + // We use submission time because record time is not available during pre-execution. } message DamlSubmissionDedupKey { From 72c4e28b8f7e1c8d2329f3b0bef299faeecba1c6 Mon Sep 17 00:00:00 2001 From: Nicu Reut Date: Wed, 3 Nov 2021 14:26:00 +0100 Subject: [PATCH 3/3] Revert removal of field --- .../com/daml/ledger/participant/state/kvutils/store/state.proto | 1 + 1 file changed, 1 insertion(+) diff --git a/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/state.proto b/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/state.proto index d71a1ddcc084..03f92b71f6c6 100644 --- a/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/state.proto +++ b/ledger/participant-state/kvutils/src/main/protobuf/com/daml/ledger/participant/state/kvutils/store/state.proto @@ -59,6 +59,7 @@ message DamlCommandDedupValue { google.protobuf.Timestamp deduplicated_until = 2; // The submission time of the initial command. // We use submission time because record time is not available during pre-execution. + google.protobuf.Timestamp submission_time = 3; } message DamlSubmissionDedupKey {