Hi team,
While doing some test, I am facing an error LOCAL_VERDICT_LOCKED_CONTRACTS
.
Reason is because there are multiple commands that will update the same in my Batch when it is being submitted to the command service.
e.g:
public void exerciseBatchCmdList(List<Command> cmdList) {
try {
damlRepository.getDamlLedgerClientInstance().getCommandClient().submitAndWait(MyChoice,
"APP",
UUID.randomUUID().toString(),
damlRepository.fetchPartyIdByClient(PARTY_A),
cmdList).blockingGet();
)
} catch (Exception ex) {
ex.printStackTrace();
}
}
How would you serialise a batch of command in Java so it doesn’t have this locked contention issues?
Thanks and Regards,
Jean-Paul
Hello @jaypeeda
It is a bit hard to know as we do not see the actual commands your submitting and what they are locking. My suggestion though would be to convert your Daml code to take as input the batched payloads so that you have only one command.
For example if your command list has 10 create, I would write a Daml function which takes as argument the same payloads as a list, but then calls a createAndExercise which create’s the 10 underlying contracts. I doubt that that kind of example can cause the contention you’re experiencing; you probably have consuming exercises. But the general approach would force you to realize that some actions need to be appropriately chained on the ledger, if you want to process such a large payload.
But be warned, there are trade-offs with this approach. Large, batched payloads can take longer to interpret and validate with Canton, then the individual commands.
1 Like
Hi @jaypeeda
The “LOCKED” rejection is a result of two “independent” command trying to archive the same contract or update the same contract key.
So, if we have command1 and command2 which both archive a contract, then obviously only one can succeed.
submit command1 (&& immediately) submit command2 → command2 will likely fail with LOCKED
submit command1 (&& later on) submit command2 → CONTRACT_NOT_FOUND
submit [command1, command2] → CONTRACT_NOT_FOUND
If you have a similar situation with two commands updating the same key, then:
submit command1 (&& immediately) submit command2 → LOCKED (KEY or CONTRACT)
submit command1 (&& later on) submit command2 → success
submit [command1, command2] → success
Does that help?
1 Like
Thanks a lot @Leonid_Rozenberg and @Ratko_Veprek, that is very helpful !