digital-asset / digital-asset/daml

Cannot reconstruct transactions referencing contracts in the same transaction via the Ledger API

Open
#9,155 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
916
Forks
263
Avg merge
1d 22h
Merged PRs (30d)
45

Description

For things like Daml Script dumps, you want to be able to turn the root commands of a transaction tree into Ledger API commands. This seems easy at first, create -> create command, exercise -> exercise command but it runs into issues once one command references an earlier contract created in the same transaction. You can in some cases translate this into `createAndExercise` but this falls apart if the exercise does not follow the create immediately. Here is a concrete example. Bob does not see the exercise but he sees `cid <- create`, `cid2 <- create`, `exercise cid …` which is not possible via the ledger API directly.

I see two options for Daml Script dumpsd
1. Just error out, clearly not a great solutoin.
2. We can generate a helper template and call `createAndExercise` on that but that doesn’t produce the original transaction structure so that’s kind of crappy and it’s also rather confusing.

I don’t really like either option but 2 seems slightly better.

```
module Main where

import Daml.Script

template T1
with
p : Party
where
signatory p
choice Create : ContractId T2
with
p' : Party
controller p
do cid <- create T2 with p1 = p, p2 = p'
create T2 with p1 = p, p2 = p'
exercise cid C

template T2
with
p1 : Party
p2 : Party
where
signatory p1
observer p2
choice C : ContractId T2
controller p1
do create this

test = do
let Some alice = partyFromText "Alice"
let Some bob = partyFromText "Bob"
cid <- submit alice $ createCmd (T1 alice)
submit alice $ exerciseCmd cid (Create bob)
```

Contributor guide

Open the contributing guide

Research direction

Start by tracing the Daml Script dump path that reconstructs transaction trees into Ledger API commands, using the concrete T1/T2 example as the failing case. Determine how same-transaction contract references are represented and agree on the desired behavior between the two options described; done means the example can be handled through the Ledger API without silently changing the transaction structure.

Written by the indexing model from the issue text.

Assessment

Domain
backend-api-design, distributed-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.