What affects the hash code of a DAML's package

G-d willing

Hello,
During my coding with DAML, I noticed 2 scenarios where the content of a DAML package was changed, but its hash code didn’t. These 2 scenarios are. The first scenario was when I added a dependency to the daml.yaml file, but without actually using any of the resources of that package.
The second scenario was when in the dependent package there were code changes that weren’t being used in the actual package. So, in other words, the only resource my package was dependent on, that was not “really” changed. The reason I wrote really with the double quotes is that it was changed, but whatever was changed, was not being used in the package.
I mean, let’s say I have package A that is dependent on package B.
Package B defines 2 types, type Address, and type Phone.
Package A uses only the Address type. So, even when making changes to the Phone type, and even adding new types to package B, the actual hash code of package A did not change.

Since this issue is coupled with contract upgrades, I need to know what else affects it.

Thanks,

@cohen.avraham, can you try re-running your second scenario? I’m getting different results. Here is what I did:

I created a pair of projects – app and lib. I created a multi-package.yaml file to build them both. I compared the package ids of four versions of app:

  1. Without any data-dependency.
  2. After adding an unused data-dependency.
  3. After referring to a template from the data-dependency.
  4. After editing an unused record in the data-dependency.

The package ids for 1 and 2 are identical, as you have observed.

For me, the package ids changed from 2 to 3 and from 3 to 4.

This all seems consistent with the docs here and here.

Raw results

# all edits are commented out

> cat app/daml.yaml | grep data
# data-dependencies:

> cat app/daml.yaml | grep lib
#   - ../lib/.daml/dist/lib-0.0.1.dar

> cat app/daml/Main.daml| grep LAsset
-- type LAssetId = ContractId L.Asset

> cat lib/daml/Lib.daml| grep Wallace
-- data WallaceWasHere = YES

> daml build --all
Running multi-package build of all packages

> mv app/.daml/dist/app-0.0.1.dar app-0.0.1.1.dar

# the unused data dependency has been added

> cat app/daml.yaml | grep lib
  - ../lib/.daml/dist/lib-0.0.1.dar

> daml build --all
Running multi-package build of all packages

> mv app/.daml/dist/app-0.0.1.dar app-0.0.1.2.dar

# the data-dependency has been referenced

> cat app/daml/Main.daml| grep LAsset
type LAssetId = ContractId L.Asset

> daml build --all
Running multi-package build of all packages

> mv app/.daml/dist/app-0.0.1.dar app-0.0.1.3.dar

# the data-dependency has been edited

> cat lib/daml/Lib.daml| grep Wallace
data WallaceWasHere = YES

> daml build --all
Running multi-package build of all packages

> mv app/.daml/dist/app-0.0.1.dar app-0.0.1.4.dar

# display the four package ids

> daml damlc inspect-dar --json app-0.0.1.1.dar | jq -r .main_package_id
308ef3763a1d1ec6bca606735aa027c81c61aa9423aa3ad657078925f53d65fb

> daml damlc inspect-dar --json app-0.0.1.2.dar | jq -r .main_package_id
308ef3763a1d1ec6bca606735aa027c81c61aa9423aa3ad657078925f53d65fb

> daml damlc inspect-dar --json app-0.0.1.3.dar | jq -r .main_package_id
1686c7a11bf6b18c34dae188c2c4a54bf3938400416c690a9f3f4ce6966f9462

> daml damlc inspect-dar --json app-0.0.1.4.dar | jq -r .main_package_id
3f7a739f9ce407b7150bcaf21112d810bbfd08f4d0d861c8e96f9e8e85995a69