Andamio Logo

ANDAMIO BLOG

Cardano Go Live Coding Session #007

2024-04-23: by James Dunseith

Talking about Time

How long does it take for the average transaction to propogate across all Cardano Nodes? That's the question that Manuel from Cardano Foundation is currently working on, and he brought it to this week's Cardano Go Live Coding session. Together, we took a look at how time is handled on Cardano and some of the implications. In case you missed it, here is a link to the recording.

On Cardano, time is measured is "slots". Currently on Cardano, 1 second = 1 slot. This is a parameter than can be changed in the future.

In general, Cardano developers can define time validitity intervals in two places:

  • in a validator
  • in a transaction

Why do we use intervals to account for time in smart contracts and transactions?

We can inspect the details of any block on a Cardano blockchain. We can use Cardano CLI, for example to view a block on Preprod:

Or we can view block details on a block explorer:

block example source: Preprod Cardano Explorer Beta

The key thing to notice is that when a block is minted on-chain, a very specific time is written on it. In the case above, it's "slot": 57310766. However, when we build a transaction, we cannot know for sure exactly what time it will be included on-chain. That is why we specify time intervals in validator code and in transactions.

Why use TTL in a transaction? Should all transactions include TTL?

When developing an application for production, it is helpful to include TTL in every transaction. This ensures that users of your application are prevented from building transactions then waiting to submit them.

For simple transactions, it's not explicitly necessary to specify TTL, but if you're building an application that other people will use, it's usually worthwhile to include it.

If you are interacting with a Cardano application, you can see whether a transaction specifies a TTL by looking for the details in the Eternl transaction preview, which shows a validity interval like this:

eternl valid for

Other considerations for building a diagnostic tool

Now back to the original question. Suppose that we want to measure the average time it takes for a transaction that is submitted on a local node for it to be included in any block on the chain. The Cardano Foundation has convened a team to measure on-chain block propogation and wants to measure network congestion. They're already monitoring block propogation, and they want to do the same for transaction propogation.

In order to design a monitoring solution, we'll need to ask a few more questions:

  • Do we start measuing time when the transaction is added to the mempool, or when the user submits it?
  • How much time passes between the moment that the transaction is built and the moment it is signed?
  • From there, how much time passes between the signing and submission steps?
  • We need to ask this because if we want to place a timestamp in metadata, it will have to be added when the transaction is built.

Here are some other questions that came up during the live coding session:

  • How do we interpret the time that passes for a given transaction? Was it waiting for a block to be minted? Was it stuck in the mempool? Did something else happen?
  • Mainnet is steady enough at regular blocks, but sometimes on a test network like preprod, a few minutes can pass without a block being minted.

Blink Labs provides tools for mempool monitoring

About this Session

App developers and the libraries they use are growing up side by side. It's both thrilling and daunting to be a Cardano developer right now, and we find that getting together is helpful along the journey! That's why we meet on Mondays at 1300 for Cardano Go Live Coding.

Everyone is welcome. For links to Live Coding sessions visit: https://www.andamio.io/calendar