Time and Deterministic Code

I just started reading the official documentation and I have a question about Motoko.

It mentions here the below quote:

An execution environment that calculates the deterministic computation involved in executing a program and processes the messages it receives from the message routing layer.

I assume that this means that all canisters that run the same code in a sub-net should return the same result.

Now when I read about Time here, I find this statement:

The system times of different canisters are unrelated, and calls from one canister to another may appear to travel “backwards in time”

Which makes sense, because time is different in a distributed system.

But that also means that if I use something like the below function (silly pseudo-code):

myTimeIsInThePast (Int myTime) returns boolean {
    let now : () -> Int
    return myTime < now

This function will most likely return different results on different replicas running the same canister, because the nodes will most likely have different times.

So my question is: Doesn’t that contradict with the first quote in my post (about deterministic execution).

I’m an expert on Corda’s DLT (well at least I like to think so lol), their contracts are deterministic; so when a contract (that validates a transaction) runs on different nodes (no matter at which point in time), it will always return the same result.

They achieved that with the following solutions:

  1. They don’t use a specific point in time, instead they use time-windows and the notary (that prevents double-spends and finalizes transactions) is the time-stamping authority, meaning when you create a transaction (e.g. a sales offer); you can add a time-window to that transaction outside of which the offer is considered expired and cannot be accepted, so when the notary receives the signed transaction it will check that it received that transaction within that time-window.
  2. In recent versions of Corda, they introduced a deterministic JVM (DJVM) which excludes all non-deterministic code (date, time, random numbers, etc…).
  3. If you enable using DJVM you’ll get compile time errors if your code includes non-deterministic code.
  4. You can also enable an option in your node to only accept running code that was compiled/built using a DJVM.
1 Like

That sentence should be revised, but yes, your interpretation is correct, the IC is deterministic. All replicas within a subnet apply the same sequence of messages to canister state. A timestamp provided by a block-maker is included in a block header, which all replicas in the subnet must agree on. Different subnets run on different clock cycles, so time, observed by one canister and relative to another, can jump forwards, jump backwards, speed up, or slow down. There isn’t any contradiction, we just need to be more descriptive in our documentation. Thanks for pointing this out. I’m not particularity familiar with Corda; will take a look.


Thanx @enzo for the clarification.

Does this imply that applications just can’t see a high-resolution clock, i.e. with more than a couple of seconds of precision?

That seems like it might be a problem for Dfinity’s aspirations to replace all existing computing infrastructure?

Correct, applications cannot access a high resolution clock. I don’t know of anyone making claims about replacing “all existing computing infrastructure”. The Internet Computer is conceived as a secure network protocol that allows untrusted data centers to host trusted applications at scale. It is a general purpose computing platform, which is optimized to perform certain tasks very well, but sometimes at the expense of others.


There is this guy Dominic, who in this Reddit thread, says

and so on and on (emphasis mine)

or on his LinkedIn profile

Are you saying he’s wrong and you anticipate people using the IC for only a subset of functionality, in combination with regular computing platforms?

I know Dominic well and his comment is spot on. The internet computer is a general purpose computing platform with powerful tools for abstraction, and yes, for a vast number of use cases, you don’t need anything else. Like most complex pieces of software, it makes trade-offs, and optimizes for some things at the expense of others. Unfortunately, there is no access to a high resolution clock. Dominic has also indicated limitations around certain computationally intensive tasks like machine learning. That said, it’s a compelling platform for many of the reasons he states. Comments and criticism for design choices are always welcome, but please create a different thread so we can stay focused on the discussion topic. Thank you kindly.

1 Like