I’m reading the Contract Keys in Canton chapter of the docs.
The main message of the chapter for me is that “contract key uniqueness will soon be deprecated, as uniqueness can not be enforced among multiple domains. We encourage to build your models already anticipating this change”.
From which follows the question: what are contract keys good for, without guaranteed uniqueness?
You write that contract keys have the following two functions:
- Simplifying the modeling of mutable state in Daml.
Daml contracts are immutable and can be only created and archived. Mutating a contract
C
is modeled by archivingC
and creating a new contractC'
which is a modified version ofC
. Other than keys, Daml offers no means to capture the relation betweenC
andC'
. After archivingC
, any contractD
that contains the contract ID ofC
is left with a dangling reference. This makes it cumbersome to model mutable state that is split across multiple contracts. Keys provide mutable references in Daml; givingC
andC'
the same keyK
allowsD
to storeK
as a reference that will start pointing toC'
after archivingC
.
- Checking that no active contract with a given key exists at some point in time.
This mainly serves to provide uniqueness guarantees, which are useful in many cases. One is that they can serve to de-duplicate data coming from external sources. Another one is that they allow “natural” mutable references, e.g., referring to a user by their username or e-mail.
You also write that “In non-unique-keys mode, contract keys in Canton provide the first, but not the second function”.
I don’t understand how contract keys, without guaranteed uniqueness, can be useful for the modelling of mutable state. State representation, in any meaningful sense of the word, must be unique.
I also don’t understand, how you can use fetchByKey
commands in the Workarounds for Recovering Uniqueness section while the behavior of fetchByKey
is undefined:
“When evaluated against an active contract set, a fetchByKey k
may result in a Fetch c
action for any active contract c
with the key k
(in Canton, there can be multiple such contracts).”