"Learning is learning. Sometimes it's the struggle that we learn from."
- Chris G from Blink Labs
How to build a resilient blockchain:
The Cardano blockchain is evolving beyond its initial association with Haskell. Today, developers around the world are working in a wide array of languages to implement essential Cardano architecture. Examples include the growing plurality of on-chain languages like Aiken, Plu-TS, Helios, Opshin and Scalus or the transaction libraries that continue to evolve like Apollo, Mesh and Butane, among others.
Even more recently, TxPipe, Blink Labs, Harmonic Labs and independent developers are spearheading the development of alternative implementations of the Cardano Node itself. The Dolos node from TxPipe, and the Go Node from Blink Labs are just two examples.
Why is it possible to build Cardano Architecture in (m)any langauges?
Why is it possible in the first place to implement Cardano architecture in different programming languages?
Cardano is built on the Ouroboros consensus protocol. Ouroboros defines how new transactions can be added to blocks, and how those blocks are to be validated and added to the blockchain. When a stake pool operator runs a block-producing Cardano Node, all nodes are communicating according to the set of rules defined in Ouroboros. When anyone sends a transaction on Cardano, that transaction is formatted according to the rules defined in Ouroboros.
In order for every computer running a Cardano Node to communicate as expected, block and transaction data must be translated into a single format. Cardano uses a format is called CBOR. The process of converting data into a binary format like CBOR is called serialization. The serialization process is carefully defined by Cardano’s CDDL, providing a blueprint that developers can implement in any language.
Owing to all of this, we are able to build libraries in any language. The work is ongoing. On the one hand, all we have to do is implement the rules. On the other hand, the work is full of challenging details, because the rules are continually evolving and different languages have different idiosyncracies when it comes to serializing and deserializing data.
This week at Cardano Go Live Coding, we got a first-hand look at how it's all still a work in progress. In case you missed it, here's the video on YouTube. You should definitley watch this lesson if you want to understand what it looks like to troubleshoot transaction serialization on Cardano.
Terminology:
Serialization is the process of converting data in a bytestring that be easily transmitted across a network.
CDDL stands for Concise Data Definition Language. An updated CDDL specification is provided for each era on the Cardano Ledger. For example, here is the Conway-era CDDL.
CBOR stands for Concise Binary Object Representation.
This week's live coding session:
During the live coding session, we focused on the nuances of transaction serialization using Go libraries. Despite facing challenges with the transaction builder, the session offered invaluable insights and a practical hands-on experience.
Andamio CLI is currently being built in Go, and we are using Apollo in the implementation. Mix provided an update on the status of building a transaction that can be used to deploy reference UTxOs to the blockchain. It still doesn't quite work as expected, and Mix gave a hands-on demo of how to diagnose why.
So how did he do it? By investigating transaction CBOR and decoding it. What followed was a deeper dive into transaction serialization using Go libraries. It was a great chance to take a peek "under the hood".
Step by Step: How to Study a Transaction
We will expand on this example, and provide specific examples written in Go, in the upcoming Cardano Go PBL Course
Here is an outline of the process you'll see in the recording of this live coding session. Try to follow it on your own:
- Build a transaction by any method. As an example, here is a simple transaction built using Cardano CLI:
At live coding sessions, we will continue to look at examples of transactions built in Go.
- Get the string CBOR string that is output by your function. In the example above, the contents of
simple-tx.signed
will look something like this:
Here, cborHex
is the CBOR string representation of this transaction. In a more complex transaction, this string will be longer. As a rough rule of thumb, the longer the CBOR string, the greater the transaction fee will (although that's not all that goes into fee calculation).
- Decode the CBOR. CQuisitor is a great new tool for the job. Or, in the video, you'll see that Mix has some local libraries for decoding CBOR - let us know if you'd like to set these up on your own.
- Finally, try to compare your decoded CBOR to the CDDL.
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