# Daml 3 Contract Keys and lookupNByKey completeness?

**URL:** <https://forum.canton.network/t/daml-3-contract-keys-and-lookupnbykey-completeness/9251>\
**Category:** App Development\
**Tags:** contract-keys, canton\
**Created:** [September 30, 2026, 1:01pm UTC](https://forum.canton.network/t/daml-3-contract-keys-and-lookupnbykey-completeness/9251 "2026-09-30T13:01:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![WallaceKelly](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/wallacekelly/32/5046_2.png) [@WallaceKelly](https://forum.canton.network/u/WallaceKelly)\
**Post date:** [September 30, 2026, 1:01pm UTC](https://forum.canton.network/t/daml-3-contract-keys-and-lookupnbykey-completeness/9251/1 "2026-09-30T13:01:21Z")

</div>

What are some scenarios in which we know that `lookupAllByKey` will return _all contracts for a given key_?

For example, is this such a scenario:

- A single synchronizer (i.e., the contracts never cross “domains”) 1
- A single-hosted maintainer (i.e., the same participant node is used for all submissions and validations by the maintainer) 2

If so, can we push the single-synchronizer scenario further?

- What if the maintainer is multi-hosted, but always submits through the same participant node? 3
- What if the maintainer is multi-hosted, but might submit to any of its hosting nodes? 4

Related to: [Canton 3 Contract Keys](https://forum.canton.network/t/canton-3-contract-keys/8176)

---

<div class="post-metadata">

**Author:** ![Andreas\_Lochbihler](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/andreas_lochbihler/32/34_2.png) [@Andreas\_Lochbihler](https://forum.canton.network/u/Andreas_Lochbihler)\
**Post date:** [September 30, 2026, 1:55pm UTC](https://forum.canton.network/t/daml-3-contract-keys-and-lookupnbykey-completeness/9251/2 "2026-09-30T13:55:46Z")

</div>

Even a single synchronizer and a single-hosted maintainer submitting through its one participant node does not suffice here. That’s because `lookupAllByKey` will not return any contracts created by commands that are in flight concurrently to the submission. Say if the maintainer submits a command to create a contract `c` with a key `k` and while this command is making its way through the Canton protocol, the maintainer submits another command with `lookupAllByKey`. This second command will not find the contract `c` even though by the time the second command appears as an accepted transaction on the ledger API, `c` is active. You can in theory prevent such concurrency problems in this scenario by using the same command ID for deduplication on all commands that create/lookup a particular key, but that’s not particularly scalable.

Moreover, the maintainer should not grant any other party (hosted on another node) the right to create such contracts via a Daml delegation contracts because this would again open up such concurrency problems again.

---

<div class="post-metadata">

**Author:** ![b\_heather](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/b_heather/32/7839_2.png) [@b\_heather](https://forum.canton.network/u/b_heather)\
**Post date:** [October 7, 2026, 1:33pm UTC](https://forum.canton.network/t/daml-3-contract-keys-and-lookupnbykey-completeness/9251/3 "2026-10-07T13:33:02Z")

</div>

> [@Andreas\_Lochbihler](#):
>
> That’s because `lookupAllByKey` will not return any contracts created by commands that are in flight concurrently to the submission.

@Andreas_Lochbihler Could this be solved by using a consuming choice on a single factory contract that performs the lookup? This would prevent concurrent submissions.

I realize this still has the same scalability concerns but they’re not relevant for our use case.

---

<div class="post-metadata">

**Author:** ![Andreas\_Lochbihler](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/andreas_lochbihler/32/34_2.png) [@Andreas\_Lochbihler](https://forum.canton.network/u/Andreas_Lochbihler)\
**Post date:** [October 7, 2026, 3:01pm UTC](https://forum.canton.network/t/daml-3-contract-keys-and-lookupnbykey-completeness/9251/4 "2026-10-07T15:01:43Z")

</div>

> Could this be solved by using a consuming choice on a single factory contract that performs the lookup? This would prevent concurrent submissions.

This very much depends on the concrete implementation of the approach and the particular deployment of Canton. Ledger API commands are converted into transactions not against a snapshot of the ledger state. For example, you could have the case where you first perform a lookupByKey or fetchByKey operation that gives you a list of resolved contracts and then later perform the `lookupAllByKey` through the factory contract, whose creating transaction just has been ingested into the DB. Then the interpreter may refer to the cached resolution without rechecking that another contract has only been created.

Essentially, such an approach would rely on implementation details in the indexer that are not officially specified and therefore could change in the future as part of how things are implemented there.

---

<div class="post-metadata">

**Author:** ![b\_heather](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/b_heather/32/7839_2.png) [@b\_heather](https://forum.canton.network/u/b_heather)\
**Post date:** [October 7, 2026, 7:20pm UTC](https://forum.canton.network/t/daml-3-contract-keys-and-lookupnbykey-completeness/9251/5 "2026-10-07T19:20:08Z")

</div>

Interesting. To use a concrete example to ensure I understand:

```haskell
template Item
  with
    a : Party
    b : Party
    id : Text
  where
    signatory a, b
    key (a, id) : (Party, Text)
    maintainer key._1

template ItemFactory
  with
    a : Party
    b : Party
  where
    signatory a, b

    choice ItemFactory_Create : (ContractId Item, ContractId ItemFactory)
      with id : Text
      controller a, b
      do
        existing <- lookupByKey @Item (a, id)
        assertMsg ("Item " <> id <> " already exists") (isNone existing)
        (,) <$> create Item with a, b, id
            <*> create this

template Service
  with
    a : Party
    b : Party
  where
    signatory a, b

    nonconsuming choice Service_CreateItem : (ContractId Item, ContractId ItemFactory)
      with
        factoryCid : ContractId ItemFactory
        id : Text
      controller b
      do exercise factoryCid ItemFactory_Create with id

```

`b` submits `Service_CreateItem` as the only command; nothing else in the transaction touches the key, and all `Item` creates go through `ItemFactory_Create`. Since the factory is fetched before `lookupByKey` runs, does the interpreter guarantee that the lookup sees any `Item` created by the transaction that produced this factory version? Or could the key lookup still be served from a stale cache or index, so two `Item`s with the same key could end up being created?

---

<div class="post-metadata">

**Author:** ![asarpeshkar](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/asarpeshkar/32/1601_2.png) [@asarpeshkar](https://forum.canton.network/u/asarpeshkar)\
**Post date:** [October 13, 2026, 4:29pm UTC](https://forum.canton.network/t/daml-3-contract-keys-and-lookupnbykey-completeness/9251/6 "2026-10-13T16:29:28Z")

</div>

@Andreas_Lochbihler  
Given a single synchronizer and single-hosted maintainer, what additional conditions are required for a `lookupAllByKey` to be exhaustive with regard to previously committed transactions (leaving the problem of in-flight submissions aside)?
