-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hash submitters in the deduplication key [DPP-347] #9417
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
507d242
A ledger-api-test-tool test case for too large deduplication key fail…
kamil-da b30b098
Hashing submitters in the deduplication key
kamil-da 2d2cc4b
Separate ValueLimitsIT test suite for the ledger-api-test-tool
kamil-da 8ea6c8e
Excluded ValueLimitsIT for sandbox and ledger-on-sql conformance tests
kamil-da 3c33fcf
Checking contract creation result in the test case
kamil-da 9ef8dcb
Update index on participant_command_completions table
kamil-da 1ecaf9c
Added a delay for more consistent results
kamil-da 0b579a6
Fixed submitting a command
kamil-da cd49103
Simplified the test case
kamil-da 3008af9
Reverted changing indexes
kamil-da 5b0fae8
Dedicated object for making deduplication keys
kamil-da 4883383
Ported hashing deduplication keys to the appendonlydao
kamil-da 368b6d6
Removed ValueLimitIT suite.
kamil-da 3bf7912
Additional unit test for hashing deduplication keys
kamil-da File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...participant-integration-api/src/main/scala/platform/store/dao/DeduplicationKeyMaker.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.platform.store.dao | ||
|
||
import com.daml.ledger.api.domain | ||
import com.daml.lf.data.Ref | ||
|
||
import java.security.MessageDigest | ||
import scalaz.syntax.tag._ | ||
|
||
object DeduplicationKeyMaker { | ||
def make(commandId: domain.CommandId, submitters: List[Ref.Party]): String = | ||
commandId.unwrap + "%" + hashSubmitters(submitters.sorted(Ordering.String).distinct) | ||
|
||
private def hashSubmitters(submitters: List[Ref.Party]): String = { | ||
MessageDigest | ||
.getInstance("SHA-256") | ||
.digest(submitters.mkString.getBytes) | ||
.mkString | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...t-integration-api/src/test/suite/scala/platform/store/dao/DeduplicationKeyMakerSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.platform.store.dao | ||
|
||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatest.wordspec.AnyWordSpec | ||
import com.daml.ledger.api.domain.CommandId | ||
import com.daml.lf.data.Ref | ||
import org.scalatest.prop.TableDrivenPropertyChecks | ||
|
||
import java.util.UUID | ||
import scala.util.Random | ||
import scalaz.syntax.tag._ | ||
|
||
class DeduplicationKeyMakerSpec extends AnyWordSpec with Matchers with TableDrivenPropertyChecks { | ||
|
||
val commandId: CommandId = CommandId(Ref.LedgerString.assertFromString(UUID.randomUUID.toString)) | ||
|
||
"DeduplicationKeyMaker" should { | ||
"make a deduplication key starting with a command ID in plain-text" in { | ||
DeduplicationKeyMaker.make(commandId, List(aParty())) should startWith(commandId.unwrap) | ||
} | ||
|
||
"make different keys for different sets of submitters" in { | ||
val aCommonParty = aParty() | ||
val cases = Table( | ||
("Submitters for key1", "Submitters for key2"), | ||
(List(aParty()), List(aParty())), | ||
(List(aCommonParty, aParty()), List(aCommonParty, aParty())), | ||
(List(aParty(), aParty()), List(aParty(), aParty())), | ||
) | ||
|
||
forAll(cases) { case (key1Submitters, key2Submitters) => | ||
val key1 = DeduplicationKeyMaker.make(commandId, key1Submitters) | ||
val key2 = DeduplicationKeyMaker.make(commandId, key2Submitters) | ||
|
||
key1 shouldNot equal(key2) | ||
} | ||
} | ||
|
||
"make a deduplication key with a limited length for a large number of submitters" in { | ||
val submitters = (1 to 50).map(_ => aParty()).toList | ||
|
||
/** The motivation for the MaxKeyLength is to avoid problems with putting deduplication key in a database | ||
* index (e.g. for Postgres the limit for the index row size is 2712). | ||
* The value 200 is set arbitrarily to provide some space for other data. | ||
*/ | ||
val MaxKeyLength = 200 | ||
DeduplicationKeyMaker.make(commandId, submitters).length should be < MaxKeyLength | ||
} | ||
|
||
"make the same deduplication key for submitters of different order" in { | ||
val submitter1 = aParty() | ||
val submitter2 = aParty() | ||
val submitter3 = aParty() | ||
|
||
val key1 = DeduplicationKeyMaker.make(commandId, List(submitter1, submitter2, submitter3)) | ||
val key2 = DeduplicationKeyMaker.make(commandId, List(submitter1, submitter3, submitter2)) | ||
|
||
key1 shouldBe key2 | ||
} | ||
|
||
"make the same deduplication key for duplicated submitters" in { | ||
val submitter1 = aParty() | ||
val submitter2 = aParty() | ||
|
||
val key1 = DeduplicationKeyMaker.make(commandId, List(submitter1, submitter2)) | ||
val key2 = DeduplicationKeyMaker.make( | ||
commandId, | ||
List(submitter1, submitter1, submitter2, submitter2, submitter2), | ||
) | ||
|
||
key1 shouldBe key2 | ||
} | ||
|
||
def aParty(): Ref.Party = Ref.Party.assertFromString(Random.alphanumeric.take(100).mkString) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This constant seems arbitrary, but the value is fine. It's smaller than the maximum length for indexed string columns in both Postgres and Oracle (which was the reason for this change). Maybe add a comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point - I'll comment on motivation for this limit.