-
Notifications
You must be signed in to change notification settings - Fork 52
Added store_id to validator_internal_config #3214
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
Merged
pasindutennage-da
merged 32 commits into
main
from
pasindutennage/fix-db-internal-config-fix-store-id/451
Nov 21, 2025
Merged
Changes from 23 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
e2b300b
Added store_id to validator_internal_config
pasindutennage-da a99ca68
Reset table
pasindutennage-da c66009b
Added new db update schema
pasindutennage-da 04dc84f
Moved StoreDescriptor from DbMultiDomainAcsStore
pasindutennage-da fdd8e3f
Moved trates from DbMultiDomainACsStore
pasindutennage-da 9e4a962
Moved initiatiolation logic for store descriptor
pasindutennage-da abc4bb3
Added stuff from previous PR
pasindutennage-da 4f3bb0f
Added init logic for ValidatorInternalConfig
pasindutennage-da 262ad84
Added store_id to queries
pasindutennage-da fe199e9
Test passing
pasindutennage-da cb9d121
Removed .iml
pasindutennage-da f318d9a
Updated .gitignore
pasindutennage-da dff1129
Addressed comments, added a new test
pasindutennage-da 6cb410e
Merge branch 'main' into pasindutennage/fix-db-internal-config-fix-st…
pasindutennage-da d8b9163
Missing imports
pasindutennage-da 442e085
Merge conflicts resolved
pasindutennage-da 650ffd5
Removed DSO Party from validator internal store store descriptor
pasindutennage-da 6fbb09f
Updated primary key of config sql
pasindutennage-da 38f50e6
Fixed implicits
pasindutennage-da 16b8d00
Renamed
pasindutennage-da 3bf6e12
Code refactorted
pasindutennage-da b3c4038
Merge branch 'main' into pasindutennage/fix-db-internal-config-fix-st…
pasindutennage-da 385a207
Nits
pasindutennage-da d59c6e7
Adding missed files from merge
pasindutennage-da 9afa622
Nits
pasindutennage-da 7c232d0
Nits
pasindutennage-da 2a8e67b
Added participant Id to private config descrirptor
pasindutennage-da 2ecb55f
Removed participant ID from descriptor
pasindutennage-da dd23d0b
Added back participant
pasindutennage-da 676d69b
Added Db Init
pasindutennage-da 790598e
Code refactorted
pasindutennage-da 3c4b3f1
Code refactored
pasindutennage-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 hidden or 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 |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| .daml | ||
| *.dar | ||
| !daml/dars/* | ||
| *.iml | ||
| *.log | ||
| *.clog | ||
| .DS_Store | ||
|
|
||
17 changes: 17 additions & 0 deletions
17
...c/main/resources/db/migration/canton-network/postgres/stable/V052__update_scan_config.sql
This file contains hidden or 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,17 @@ | ||
| ALTER TABLE validator_internal_config | ||
| ADD COLUMN store_id integer; | ||
|
|
||
| ALTER TABLE validator_internal_config | ||
| DROP CONSTRAINT uc_validator_internal_config; | ||
|
|
||
| ALTER TABLE validator_internal_config | ||
| ALTER COLUMN store_id SET NOT NULL; | ||
pasindutennage-da marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ALTER TABLE validator_internal_config | ||
| ADD CONSTRAINT uc_validator_internal_config | ||
| PRIMARY KEY (store_id, config_key); | ||
|
|
||
| ALTER TABLE validator_internal_config | ||
| ADD CONSTRAINT fk_store_id | ||
| FOREIGN KEY (store_id) | ||
| REFERENCES store_descriptors(id); | ||
This file contains hidden or 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 hidden or 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
101 changes: 101 additions & 0 deletions
101
...common/src/main/scala/org/lfdecentralizedtrust/splice/store/db/StoreDescriptorStore.scala
This file contains hidden or 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,101 @@ | ||
| // Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package org.lfdecentralizedtrust.splice.store.db | ||
|
|
||
| import com.digitalasset.canton.config.CantonRequireTypes.String256M | ||
| import com.digitalasset.canton.lifecycle.CloseContext | ||
| import com.digitalasset.canton.resource.DbStorage | ||
| import com.digitalasset.canton.topology.{ParticipantId, PartyId} | ||
| import com.digitalasset.canton.tracing.TraceContext | ||
| import io.circe.Json | ||
| import org.lfdecentralizedtrust.splice.store.StoreErrors | ||
| import slick.jdbc.canton.ActionBasedSQLInterpolation.Implicits.actionBasedSQLInterpolationCanton | ||
| import com.digitalasset.canton.lifecycle.FutureUnlessShutdown | ||
|
|
||
| /** Identifies an instance of a store. | ||
| * | ||
| * @param version The version of the store. | ||
| * Bumping this number will cause the store to forget all previously ingested data | ||
| * and start from a clean state. | ||
| * Bump this number whenever you make breaking changes in the ingestion filter or | ||
| * TxLog parser, or if you want to reset the store after fixing a bug that lead to | ||
| * data corruption. | ||
| * @param name The name of the store, usually the simple name of the corresponding scala class. | ||
| * @param party The party that owns the store (i.e., the party that subscribes | ||
| * to the update stream that feeds the store). | ||
| * @param participant The participant that serves the update stream that feeds this store. | ||
| * @param key A set of named values that are used to filter the update stream or | ||
| * can otherwise be used to distinguish between different instances of the store. | ||
| */ | ||
| case class StoreDescriptor( | ||
| version: Int, | ||
| name: String, | ||
| party: PartyId, | ||
| participant: ParticipantId, | ||
| key: Map[String, String], | ||
| ) { | ||
| def toJson: io.circe.Json = { | ||
| Json.obj( | ||
| "version" -> Json.fromInt(version), | ||
| "name" -> Json.fromString(name), | ||
| "party" -> Json.fromString(party.toProtoPrimitive), | ||
| "participant" -> Json.fromString(participant.toProtoPrimitive), | ||
| "key" -> Json.obj(key.map { case (k, v) => k -> Json.fromString(v) }.toSeq*), | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| sealed trait InitializeDescriptorResult[StoreId] | ||
| case class StoreHasData[StoreId]( | ||
| storeId: StoreId, | ||
| lastIngestedOffset: Long, | ||
| ) extends InitializeDescriptorResult[StoreId] | ||
| case class StoreHasNoData[StoreId]( | ||
| storeId: StoreId | ||
| ) extends InitializeDescriptorResult[StoreId] | ||
| case class StoreNotUsed[StoreId]() extends InitializeDescriptorResult[StoreId] | ||
|
|
||
| object StoreDescriptorStore extends StoreErrors { | ||
|
|
||
| def getStoreIdForDescriptor( | ||
| descriptor: StoreDescriptor, | ||
| storage: DbStorage, | ||
| )(implicit | ||
| traceContext: TraceContext, | ||
| executionContext: scala.concurrent.ExecutionContext, | ||
| closeContext: CloseContext, | ||
| ): FutureUnlessShutdown[Int] = { | ||
| // Notes: | ||
| // - Postgres JSONB does not preserve white space, does not preserve the order of object keys, and does not keep duplicate object keys | ||
| // - Postgres JSONB columns have a maximum size of 255MB | ||
| // - We are using noSpacesSortKeys to insert a canonical serialization of the JSON object, even though this is not necessary for Postgres | ||
| // - 'ON CONFLICT DO NOTHING RETURNING ...' does not return anything if the row already exists, that's why we are using two separate queries | ||
| val descriptorStr = String256M.tryCreate(descriptor.toJson.noSpacesSortKeys) | ||
| for { | ||
| _ <- storage | ||
| .update( | ||
| sql""" | ||
| insert into store_descriptors (descriptor) | ||
| values (${descriptorStr}::jsonb) | ||
| on conflict do nothing | ||
| """.asUpdate, | ||
| "initializeDescriptor.1", | ||
| ) | ||
|
|
||
| newStoreId <- storage | ||
| .querySingle( | ||
| sql""" | ||
| select id | ||
| from store_descriptors | ||
| where descriptor = ${descriptorStr}::jsonb | ||
| """.as[Int].headOption, | ||
| "initializeDescriptor.2", | ||
| ) | ||
| .getOrRaise( | ||
| new RuntimeException(s"No row for $descriptor found, which was just inserted!") | ||
| ) | ||
|
|
||
| } yield newStoreId | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.