How do you manage time on your distributed ledger?

i.e. how do you make sure smart contracts trigger events at given date/time? - is my assumption correct here, using heartbeats in Daml triggers?

What controls the heartbeat time- domain? or participant nodes?

thanks

The intent of triggers is that they react to the state of the ledger. Think enforcing invariants, rather than “doing” stuff. In that sense, they’re not conceptually a great fit for making things happen at exact times.

You could try to use triggers for that, but you’ll be fighting against the grain. For one thing, the heartbeat mechanism is a duration, not a point in time, i.e. you can express something like “every 5 minutes after the deployment of this tigger”, but not “on every hour 35 minutes”, like you could with a cron.

If you really need to trigger events at specific times, my recommendation would be to use an external cron. You may still be able to write your logic in Daml if you can fit your logic within the limits of Daml Script, but otherwise you might need to consider using another language calling the ledger API (gRPC or JSON).

2 Likes

@Vivek_Srivastava … to add some Daml Hub specific detail to @Gary_Verhaegen 's comment, Hub has some built in support for timed operations in the form of an integration.

There’s a timer integration in the “Core Integration Pack” that can issue ledger commands at a periodic interval. It’s configured with a template ID, a choice name, and a period, and can issue either exercises against existing contracts or “Create and Exercises” if a contract isn’t already there.

No support yet for cron strings, but they are on the roadmap.

(Not directly related to how you use Hub, but one of the internal patterns we use in Hub are cron jobs that issue HTTP requests to trigger various on ledger operations. It works well, and has the benefit of decoupling timing concerns from ledger interaction concerns. One general principal here is that your jobs should be idempotent to the extent possible.)

1 Like