Skip to content

Add DB versions of Splice.Amulet.CryptoHash#4662

Merged
adetokunbo merged 17 commits into
adetokunbo/feature-cip-104-scan-computationfrom
adetokunbo/cip-104-add-compute-hashes-db-hash-function
Apr 6, 2026
Merged

Add DB versions of Splice.Amulet.CryptoHash#4662
adetokunbo merged 17 commits into
adetokunbo/feature-cip-104-scan-computationfrom
adetokunbo/cip-104-add-compute-hashes-db-hash-function

Conversation

@adetokunbo
Copy link
Copy Markdown
Contributor

First part the changes that address #4382

  • split out because it's a specific change that can be reviewed on its own

Pull Request Checklist

Cluster Testing

  • If a cluster test is required, comment /cluster_test on this PR to request it, and ping someone with access to the DA-internal system to approve it.
  • If a hard-migration test is required (from the latest release), comment /hdm_test on this PR to request it, and ping someone with access to the DA-internal system to approve it.
  • If a logical synchronizer upgrade test is required (from canton-3.5), comment /lsu_test on this PR to request it, and ping someone with access to the DA-internal system to approve it.

PR Guidelines

  • Include any change that might be observable by our partners or affect their deployment in the release notes.
  • Specify fixed issues with Fixes #n, and mention issues worked on using #n
  • Include a screenshot for frontend-related PRs - see README or use your favorite screenshot tool

Merge Guidelines

  • Make the git commit message look sensible when squash-merging on GitHub (most likely: just copy your PR description).

@adetokunbo adetokunbo added this to the Traffic-Based App Rewards milestone Mar 26, 2026
@adetokunbo adetokunbo self-assigned this Mar 26, 2026
object DbCryptoHashFunctionsTest {

/** Scala reimplementation of Daml's CryptoHash module (Splice.Amulet.CryptoHash).
* Used as the test oracle to verify plpgsql hash functions produce identical output.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add a corresponding test that calls the actual Daml functions.

I'd do so by adding a Splice.Amulet.TestTemplates module defining a template CryptoHashProxy that allows evaluating calls to crypto hashes.

Copy link
Copy Markdown
Contributor Author

@adetokunbo adetokunbo Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.
Needed to

  • change the build files to allow com.digitalasset.canton.util.TestEngine to be run by splice tests cdf0afe
  • inline the daml functions in the proxy class; they will be removed when this branch is merged with the actual daml changes (part of 80cc9d9)

Copy link
Copy Markdown
Contributor

@rautenrieth-da rautenrieth-da left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I'm only slightly nervous about the test strategy. We are comparing the SQL output to a re-implementation of the daml code in scala, with only two hardcoded hashes manually copied from the daml output. I think it's still fine because we don't expect changes in #3964, but I'd like to hear input on this from @meiersi-da.

Unfortunately I don't think it's possible to execute arbitrary daml functions from scala code. We have an in-memory daml engine (com.digitalasset.canton.util.TestEngine) but that takes a command and produces a transaction.

@meiersi-da
Copy link
Copy Markdown
Contributor

Looks good, I'm only slightly nervous about the test strategy. We are comparing the SQL output to a re-implementation of the daml code in scala, with only two hardcoded hashes manually copied from the daml output. I think it's still fine because we don't expect changes in #3964, but I'd like to hear input on this from @meiersi-da.

Unfortunately I don't think it's possible to execute arbitrary daml functions from scala code. We have an in-memory daml engine (com.digitalasset.canton.util.TestEngine) but that takes a command and produces a transaction.

We can and should test the equivalence to the Daml implementation.

I'd suggest to do this as follows:

  1. Add module Splice.Testing.AmuletComputationProxies to splice-amulet-test
  2. Add the following template to that module (and fix the bugs due to sketching this directly here)
template ComputeCryptoHash with
  owner : Party
  where
    nonconsuming choice ComputeCryptoHash_HashMintingBalances : Hash
      with
        input : MintingBalances
      controller owner
      do pure (hash input)

   ... add choices for the other calls you want to check
  1. Create one instance of it, and then submit commands against it to get the exercise result and thus the Daml compute value.

@adetokunbo adetokunbo force-pushed the adetokunbo/cip-104-add-compute-hashes-db-hash-function branch from 63dcc69 to 56f1b77 Compare March 30, 2026 03:40
@adetokunbo adetokunbo force-pushed the adetokunbo/cip-104-add-compute-reward-totals branch from 77ce31d to 05e30d8 Compare March 30, 2026 03:44
@adetokunbo
Copy link
Copy Markdown
Contributor Author

@rautenrieth-da , @meiersi-da all comments addressed, PTAL

@adetokunbo adetokunbo changed the title [ci] Add DB versions of Splice.Amulet.CryptoHash Add DB versions of Splice.Amulet.CryptoHash Mar 30, 2026
Copy link
Copy Markdown
Contributor

@rautenrieth-da rautenrieth-da left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, test coverage looks good now!

(don't forget to add the signed-off-by to the last commit)

Comment thread daml/splice-amulet-test/daml/Splice/Testing/CryptoHashProxy.daml
Comment thread project/BuildCommon.scala Outdated
Base automatically changed from adetokunbo/cip-104-add-compute-reward-totals to adetokunbo/feature-cip-104-scan-computation March 31, 2026 04:16
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
- the new test does three-way testing between db, daml and a scala oracle

Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
- no need for dependencies on Canton

Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
…eded

Signed-off-by: Tim Emiola <adetokunbo@emio.la>
…est uses

Signed-off-by: Tim Emiola <adetokunbo@emio.la>
@adetokunbo adetokunbo force-pushed the adetokunbo/cip-104-add-compute-hashes-db-hash-function branch from 43cc969 to c32cf53 Compare March 31, 2026 07:27
Copy link
Copy Markdown
Contributor

@rautenrieth-da rautenrieth-da left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job removing the dependency on the daml engine!

Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
@adetokunbo adetokunbo merged commit f090592 into adetokunbo/feature-cip-104-scan-computation Apr 6, 2026
125 of 127 checks passed
@adetokunbo adetokunbo deleted the adetokunbo/cip-104-add-compute-hashes-db-hash-function branch April 6, 2026 10:43
adetokunbo added a commit that referenced this pull request Apr 13, 2026
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
adetokunbo added a commit that referenced this pull request Apr 13, 2026
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
adetokunbo added a commit that referenced this pull request Apr 14, 2026
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
adetokunbo added a commit that referenced this pull request Apr 16, 2026
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
adetokunbo added a commit that referenced this pull request Apr 17, 2026
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
rautenrieth-da added a commit that referenced this pull request Apr 17, 2026
Merges the feature branch for the scan computation part of CIP-104, consisting of the following individual PRs:

* Add app activity computation store and schema (#4372)
* Compute aggregateActivityTotals, add ComputeAppRewardTrigger, expose new endpoints (#4420)
* Adds computeRewardTotals to DbScanAppRewardsStore (#4639)
* Add DB versions of Splice.Amulet.CryptoHash (#4662)
* Expand GetRewardAccountingActivityTotalsResponse (#4859)
* Add counters to RewardComputationTrigger (#4860)
* Compute Hashes (#4847)


Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Timothy Emiola <adetokunbo@users.noreply.github.com>
Co-authored-by: Simon Meier <simon@digitalasset.com>
Co-authored-by: Robert Autenrieth <31539813+rautenrieth-da@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants