RChain Blog

RChain cutting into the database circuit?


August 11, 2020 – Originally published in Chinese. Author: Dimworm

https://zhuanlan.zhihu.com/p/157127721

In 1970 mathematician Edgar Frank Codd published his paper, “A Relational Model for Large Shared Database Data,” which introduced the relational model. The relational model decoupled query and data storage, freeing programmers to focus on query statements without caring about the format in which the data was stored, which greatly freed up programmer productivity. The following decades relational databases and the corresponding SQL language ruled the era of stand-alone databases.

The Internet explosion of 2000 brought a transformative force to database technology. To cope with the exponential growth in the number of users, the Internet giants had to “shatter” their databases, storing data on multiple hosts, and sharding was a viable solution to the scalability problem, using the well-known Impossible Triangle, or CAP principle (Consistency, Availability). Availability, Partition Tolerance) explanation, is to give up consistency in order to solve the scalability problem. In such a context, NoSQL has become a trend, NoSQL gives up the relational model, give up the transaction, give up the index, give up the join, give up the data consistency, just to solve the scalability problem.

NoSQL includes four categories: key-value database, column family database, document database and graph database. The key-value database is a key-value table, which is suitable for a large number of write operations. Key-value databases are inherently scalable and can theoretically be expanded horizontally to achieve unlimited capacity.

Since then, database technology has two options: the choice of sql database, we must give up scalability; the choice of NoSQL database, we must give up transactions and strong consistency. 2010, people are tired of the choice of SQL or NoSQL, people are asking: can not be both NoSQL scalability and to SQL transactions and strong consistency? It can be! NewSQL is a SQL database that can run in a distributed environment, so it can also be called distributed SQL.

NewSQL wants to pick up everything that NoSQL gave up, SQL is good, I want it! Piece by piece for horizontal scalability, I want it! Data synchronization mechanism based on Raft or Paxos consensus protocols, I want it! Read-write lock or MVCC-based transaction atomicity, I want it!

When NewSQL has all these weapons at its disposal, have you noticed that it’s becoming more and more like a blockchain? Are blockchain, which focuses on security, and database, which focuses on high performance, becoming more and more alike? The two tracks are getting closer and closer together. Let’s look at it from a different angle, many blockchain projects are actually trying along the same direction. For example, BigChainDB aims to be a decentralized database that uses the Tendermint consensus protocol and integrates a set of MongoDB instances for storage. Catena, for example, embeds a SQL database into the POW blockchain, with the goal of allowing you to do transactions on the blockchain using SQL statements. But these attempts were elementary, and mechanical additions couldn’t lead to substantial performance breakthroughs.

Now, it’s time for RChain to change the stereotype of the blockchain. People will find that blockchain can be a better database.What makes RChain different from other blockchains is that instead of following the blockchain architecture in general, it starts with a completely new data storage architecture and redesigns the blockchain.RChain can be understood as RSpace storage layer + Rholang contract layer + Comms network layer + CBC- Casper Consensus Layer. A distributed, fault-tolerant data storage scheme.

RSpace Storage Layer.

It is based on the Scala implementation of Tuplespace, which was developed by Professor Gelernter at Yale University. Tuplespace is a shared-memory paradigm for distributed computing systems, proposed by Professor Gelernter of Yale University. Existence.

  1. Rholang contractual layer

Rholang is the smart contract language on RChain, and Rholang is also well known. It started with the Turing Award winner Robin Milner’s proposal of Pi arithmetic, which is the equivalent of lambda arithmetic in serial computing, in distributed computing. Whereas lambda arithmetic says that everything is a function, Pi arithmetic says that everything is a process, and lambda arithmetic says that a computation is a call between functions, Pi arithmetic says that a computation is a channel through which processes communicate with each other.

Greg, the founder of RChain, added reflexivity to Pi and came up with Rho, the cornerstone of the Rholang language, which is powerful because it converts code to data, data to code, and code to pass back and forth between processes.

Rholang’s built-in pattern matching and behavior type system make it a very imaginative query language, and Rholang can correspond semantics directly to the stored semantics of RSpace. This is the heart of what CBC is all about: build-as-correct, ensuring that there is no possibility of SQL injection attacks.

SQL also supports concurrency, but it’s hard to control SQL concurrency; there’s nothing you can do about it but lock it. Another similarity between Rholang and SQL is that Rholang’s comm rule supports transaction mechanism. A transaction is a function that operates on multiple statements as a whole. If the transaction fails, no changes are made to the database data. Transactions have ACID characteristics: (Atomicity, Consistency, Isolation, Durability).

  1. Comms Network Layer + CBC Capser Consensus Layer

RChain’s Comms network layer uses gRPC as the transport layer, using the Kademlia protocol for node discovery. rchain’s consensus layer is the famous CBC Casper. cbc Capser is a Byzantine fault-tolerant protocol that can deal with naughty nodes. The Raft and other protocols used by NewSQL are CFT crash-tolerant protocols, which can only deal with errors caused by equipment or network failures, and can do nothing about evil nodes.

In summary, you can see that RChain is a combination of NoSQL and NewSQL respective advantages, both swords together a new generation of storage architecture. Not only has the NoSQL key-value storage structure to achieve unlimited horizontal expansion, and configuration and SQL can be compared to a structured query language and a more robust consensus protocol based transaction atomicity.

Is RChain a database disguised as a blockchain? No, RChain is a much more forward-thinking blockchain. At some point in the future, the two tracks – blockchain and database – will converge, and it will be then that the elegance of RChain’s architecture will be deeply understood.

Talk is cheap, show me the code.

RSpace, which has been wrapped into the Scala library:

RSpace is part of the RChain codebase and can be used on its own. Instructions for use: rchain/rchaingithub.com

  1. god Dan Connolly’s Zulip backend rewrite proves the feasibility of doing SQL operations on RChain. Daedalus changed the backend of the chat software to RChain, and the chat messages go straight up as if they were written to a SQL database: rchain-community/rv2020github.com

Welcome to the “Rholang Chinese Community” public website.

Developers are welcome to join “RChain Developers” WeChat group. Please add lowbird WeChat to join the group. Non-developers please do not join, there will be a round of testing, and only those who pass will be admitted.