1. 程式人生 > >Relational data on a blockchain using SQL

Relational data on a blockchain using SQL

Relational data on a blockchain using SQL

Creating shared truth between organisations while speaking a familiar language

The interesting thing about blockchains is that while it usually fills the role of a database, there are no blockchain implementations as of yet that actually act like a database. The ones that do are not designed to store relational data, and do not speak the language that we are familiar with when using relational databases: SQL.

Catena is an attempt to fill this void: it provides an SQL database on top of a blockchain, providing all the benefits of blockchains (resiliency, distributed operation, openness) while providing a familiar interface to its users.

Catena is a distributed SQL database built on top of a blockchain. This allows organisations to reliably share consistent and trustworthy information without relying on centralized trust.

Why is this important? The most important technology for custom applications on a blockchain right now is Ethereum. Ethereum provides both the storage as well as business logic capabilities that allow for complex applications to be written on top of a blockchain. There are however several fundamental issues with Ethereum’s design that make it less attractive for actual business adoption:

  • The technology is complex and doesn’t fit well with existing enterprise technology. Smart contracts for Ethereum are written in a special programming language. In practice, the business logic in the contract is kept to a minimum, with other business logic residing in special ‘Dapps’ that interact with (and call smart contract ‘functions’ on) the chain.
  • All operations on Ethereum are paid for in ‘ether’, the network’s currency. As ether is also a asset used for speculation, your computations become exponentially expensive over time.

Catena attempts to solve both of these issues by providing a blockchain that just provides what it does best: a distributed database with access control. In Catena, users interact with the blockchain through SQL. Applications can even connect to Catena over the PostgreSQL wire protocol, which means that in most programming language, accessing a Catena database can be done in a few lines of code.

Blocks in Catena store SQL transactions that are verified and replayed by each client locally. Querying the Catena database is done locally — only mutating SQL transactions are appended to the chain. Such transactions are authenticated with a public-private keypair. A ‘grants’ system determines whether a transactions signed by a particular public key is actually allowed to execute. It is possible to grant execution rights based on parametrized template queries as well — e.g. the following grant would allow someone to transfer a software license registered in a Catena blockchain to someone else, but only for transferable licenses:

UPDATE licenses SET owner = ?newOwner WHERE id=?id AND owner=$invoker AND transferable = 1;

So why would miners participate in a Catena blockchain? First of all, Catena is great for semi-private blockchains where different organisations commit resources. Catena does not provide a concept of a ‘currency’ — instead, the grants system determines a user’s rights to append to the chain. Incentives can be created for miners, e.g. the insertion or update to a record in the database as reward. Organisations can outsource mining to their customers and provide them with relevant rewards in the process.

To a developer, Catena works like any other database. In fact it comes with a friendly web interface that looks a lot like phpMyAdmin.

This screenshot shows what it looks like to add a row to a Catena table using a standard SQL ‘insert’ query.

Some other technical details:

  • Catena stores transactions in SQL on the chain. Catena parses each SQL transaction it receives (from a user or in a block) with its own SQL parser, that is also used to determine the required privileges. When execution is allowed, transactions are translated to SQL for a backend database (currently SQLite).
  • Catena peers communicate over HTTP and WebSocket. End-users can talk to Catena over HTTP and submit queries using the PostgreSQL wire protocol (i.e. using the command line ‘psql’ command)
  • For authentication, Catena uses Ed25519 public-private keys. Like in Bitcoin, addresses are encoded and displayed using base58check-encoding.
  • The proof of work used in the current version of Catena is a simple SHA256 ‘leading zero bits’ implementation. In the future, Catena will provide different options for PoW as well as a configurable and dynamic difficulty level.

Catena is open source – try it today!

Media coverage & discussion