Error on one command in a CommandsSubmission batch

There isn’t an identifier to uniquely identify a single Command in a CommandsSubmission batch. So if one command fails due to any of the errors at https://docs.daml.com/2.0.1/app-dev/grpc/error-codes.html:

  1. Can these errors be caught and handled in Daml in any way?

  2. Is there anything else I can do except to retry the whole batch?

  3. If the error is related to a particular command, such as a duplicate contract key, or a fetch on an archived contract, I would need to retry the batch with that particular command removed form the batch - to do that, I would need to locate which command failed in the batch from the error thrown, but there is no identifier for a command in a batch, so what is the recommended approach here?

As a rule, no.

Most Daml ledger client workflows are well-served by “one at a time” command submissions. If you are truly building a client that benefits from bulk submissions, you should start “thinking in bulk”, i.e. using techniques that are generally useful for bulk data.

The applicable bulk technique that immediately comes to mind is “divide and conquer”. A simple “split in half” resubmission technique can submit 999,999 good commands successfully and find the 1 bad command in only 41 submits using this divide-and-conquer, while not assuming there is only one bad command, so this scales quite well to large numbers of commands, as 1 million is far more than an application ought to consider submitting in one go. A more tailored application can split far more aggressively to avoid waiting for so many aborts.

Thanks for your response @Stephen!

This is not true at all in our experience, unfortunately - any use case that requires even a few hundred ledger transactions per second ends up needing batching as that throughput is hard to hit with one-at-a-time command submissions + vertical scaling (assuming no horizontal scaling across participant nodes which we would consider as the last optimisation dimension)