daml icon indicating copy to clipboard operation
daml copied to clipboard

[BUG] Triggers show already completed commands as in-flight

Open bame-da opened this issue 3 years ago • 9 comments

I confirm that, if this is a bug that has security implications, I already contacted [email protected] and followed the responsible disclosure policy.

I confirm that this is not a question or a request for technical support by the community, for which the Daml forum is available.

Affected Daml version

1.18.0

Bug description

The getCommandsInFlight function in the trigger rule returns commands for which a successful completion was already seen in the trigger update.

Specifically, I have this code in my automation (blinded for clarity)

type SettlementState = (_, _ , Map.Map CommandId Completion)

settlementInit : TriggerInitializeA SettlementState
settlementInit = return (..., ..., Map.empty)

settlementUpdate : Message -> TriggerUpdateA SettlementState ()
settlementUpdate m = do
  case m of
    MCompletion c -> do
      (..., ..., completions) <- get
      case ... of
        ... -> put (..., ..., Map.insert c.commandId c completions)
    _ -> return () 

settlementRule : Party -> TriggerA SettlementState ()
settlementRule p = do
  ...
  commandsInFlight <- getCommandsInFlight
  let commandIds = Map.keys commandsInFlight
    forA_ commandIds (\commandId -> do
      case Map.lookup commandId completions of
        None -> return ()
        Some completion -> error $ "In-flight CommandId " <> show commandId <> " has already completed with completion " <> show completion
  ...

I don't think that error should ever occur, but it does, and with a successful completion:

15:20:09.019 [TriggerService-akka.actor.default-dispatcher-5] ERROR com.daml.lf.engine.trigger.Machine$ - Error: Unhandled exception: DA.Exception.GeneralError:GeneralError@86828b98{ message = "In-flight CommandId CommandId "5d294eba-2a37-4c4f-9365-373a12054ff4" has already completed with completion Completion {commandId = CommandId "5d294eba-2a37-4c4f-9365-373a12054ff4", status = Succeeded {transactionId = TransactionId "0A2436323538646563322D343766352D333030392D623561662D626532313039643662323634"}}" }

To reproduce

Repo/Branch https://github.com/DACH-NY/asset-refapp/tree/trade-sharder contains a WIP trigger for some fancy settlement logic. To reproduce, follow //SettlementDemo/Main/Readme.md, but instead of ./start_sequential.sh defaultSequentialConfig.json, run ./start_partyasset.sh defaultPartyAssetConfig.json.

Expected behavior

Don't throw any errors in the section of code after -- BUG? in PartyAssetSettler.daml.

Additional context

Add here any other context about the problem here. This includes but is not limited to:

  • OS information
  • Daml code relevant to reproduce the faulty behavior
  • logs in textual format containing relevant information
  • for Navigator or the documentation: screenshots

bame-da avatar Dec 22 '21 14:12 bame-da