status

Understanding Transaction Finality

Published 31.10.2023

Cardano's Ouroboros PoS uses probabilistic finality, where a block is considered final when enough blocks have been appended behind it. How many blocks must be appended and what actually happens to the transaction after the user submits it to the network? In the article, we will explain the concepts of transaction latency and finality.

Transaction Story

Alice wants to send Bob 10 ADA. Let's describe what happens with a transaction from creation to block finalization.

Alice creates a transaction in her wallet or application. This involves specifying the details of the transaction, such as Bob's address and the amount of ADA to be transferred.

Alice must sign the transaction with her private key. If she uses a HW wallet, she must confirm the transaction by holding down a button, for example. This provides proof of authenticity and ensures that only the owner of ADA coins can initiate a transaction.

The signed transaction is broadcast to the Cardano network. It is picked up by Cardano nodes, which validate the transaction according to the protocol rules.

Once the transaction is validated, it is added to a pool (mem-pool) of valid transactions waiting to be included in a new block.

In Cardano's Ouroboros PoS consensus mechanism, time is divided into epochs and slots. A slot leader is randomly selected for each slot based on their stake. The slot leader selects transactions from the pool, verifies them, and mints a new block.

The new block, containing Alice's transaction along with other transactions, is appended to the local ledger and broadcast to the network.

The block is picked up by Cardano nodes, which validate it (including all transactions) according to the protocol rules. Each node maintains its own ledger and autonomously decides which block to append to it.

The process of selecting transactions and minting a new block is repeated approximately every 20 seconds. Although a block is added to the ledger by most nodes in the network, the transaction cannot still be considered final.

Transaction Latency and Finality

Note that a transaction cannot be considered settled or valid once submitted to the network by Alice. Bob can be sure that he owns ADA coins only at the moment when the transaction is final.

There are two important periods in the described process: transaction latency and transaction finality.

Simply put, transaction latency is the time between when a transaction is submitted and when it appears in the ledger (in a new block). Transaction finality is the time between appearing in the first block until the transaction is immutable.

Let's describe it in more detail and with examples.

Transaction latency is the time period from when a transaction is submitted to the network until the slot leader inserts it into a new block. Most of the time, a transaction is waiting in a pool with other transactions.

Cardano treats transactions on a first-come, first-served basis. However, if there are more transactions in the pool than can fit in the block, Alice's transaction may not be inserted into the block by the slot leader and will have to wait in the pool for the next round.

Another slot leader already has Alice's transaction in his pool. As soon as it receives a new block, it can remove from its pool those transactions that are in the block. In a new round, Alice's transaction gets inserted into a new block.

Transaction latency varies based on when exactly Alice submits the transaction and the number of previously submitted transactions in the pool. The transaction is diffused in the network within a few seconds. Under normal circumstances, both the transaction and the block (which is larger) reach 95% of nodes within 5 seconds.

If Alice submits a transaction right before a new block is minted and it gets into the slot leader's pool, the latency can be literally a few seconds. A few seconds after submitting the transaction, Alice sees that it is contained in the block (it is in the ledger). Alice was lucky.

However, Alice may be less lucky and submit the transaction just after a new block is minted. In this case, the transaction can wait in the pool for approximately 15 seconds (when 5 seconds took the diffusion) before the slot leader inserts it into a new block. If the network is heavily used and the pool is full, it may take several blocks before a transaction is inserted by the slot leader into a new block. Alice can wait a few minutes before she sees the transaction in the block.

Once the transaction is in the block and gets into the ledger, the finality of the transaction comes into play.

Cardano uses probabilistic finality, meaning that a block is considered final when enough blocks have been appended that it becomes prohibitively expensive or impractical to deliberately start a parallel chain and try to roll back the canonical chain. In other words, probabilistic finality refers to the idea that the probability of a transaction being reversed decreases as the block containing that transaction sinks deeper into the chain.

The user has no assurance that a newly added block to the ledger will remain in it forever. It may happen that several blocks with the same height will be minted in one slot, or in two slots close to each other. In such a case, a so-called fork is created. One of the blocks will be preserved while the other will be orphaned. Transactions in an orphaned block are reversed.

The finality of a block (that is, of all transactions in it) is 100% guaranteed by Ouroboros PoS after K blocks, where K is the network parameter set to 2160. Finality is guaranteed after 12 hours.

Fortunately, users don't have to wait that long. Although forks occur relatively frequently in the network, they are usually resolved within a few blocks.

In the picture you can see the blocks and the slots in which they were minted. 2 blocks were minted in slot N+40. A fork has occurred. The slot leader randomly drawn in slot N+60 will append a new block to the red block because it has a lower VRF output. If other slot leaders have all the blocks available, it is easy for them to decide which chain to follow.

A high degree of certainty regarding the finality of the block (transaction immutability) represents about 70 blocks, which is about 25 minutes. However, a relatively large degree of certainty is only 5 blocks, which is roughly 2 minutes.

If Alice were to send Bob 10M ADA, Bob would have almost absolute certainty of ownership of coins only after 25 minutes. In the case of 10 ADA, 2 minutes is enough.

Each user can define their own level of certainty. This is not quite an ideal recommendation, but for consensus with probabilistic finality, there is no better solution.

All honest nodes behaving according to the uniform rules of the protocol accept valid blocks. All nodes behave autonomously and do not know how the other nodes in the network decided (what blocks they added to the ledger). Slot leaders decide which block to follow. Passive nodes that only synchronize blocks do not make decisions about finality (although they do decide to accept blocks themselves).

In most cases (if possible), the slot manager chooses the previous block (if available). This is the block that was minted by the previous slot leader. If the current block leader has not received a previous block, it will continue with what it considers to be the most recent block. In this case, forks are created.

Forks are resolved according to simple rules and if most nodes behave honestly, a block can be considered final if there are 5 more blocks behind it. The finality increases with each additional newly added block. A block with 25 more blocks behind it is almost certainly final (all transactions in it are immutable). Absolute certainty is 2160 blocks.

Conclusion

When a user submits a transaction to the network, they usually look in the blockchain explorer and wait for it to appear in the ledger. This is transactional latency. After that, we usually wait for the number of confirmations, which is essentially the number of blocks that are appended to the block in which the user's transaction is. This is usually how users who use the Nakamoto consensus network behave, so similar processes take place in the Bitcoin network. However, there are networks with faster finality, as it is possible for nodes to provide 'approves' either before or after a block is minted.

Featured:

Related articles

Did you enjoy this article? Other great articles by the same author