Reading Chang’an Chain in One Article

In the alliance chain of the Chinese national team, there is also a very high-level and pivotal alliance chain, which is the Changan chain. In this article, the author has compiled relevant information about the Changan Chain to help readers fully understand the Changan Chain.

Changan Chain Background Information

The Changan Chain ChainMaker is jointly developed by Beijing Microchip Research Institute, Tsinghua University, Beijing University of Aeronautics and Astronautics, Tencent , Baidu and JD.com and other well-known universities and enterprises. The name “Chang’an Chain” is a metaphor for “Long-term peace and stability, creating greater brilliance, and linking the world.”

As the open source underlying software platform of the blockchain, Changan Chain includes the core framework of the blockchain, a rich component library and tool set, and is committed to efficiently and accurately solving the needs of differentiated blockchain implementation for users, building high-performance, high-reliability , A new type of high-security digital infrastructure, and it is also the country’s first independent and controllable blockchain software and hardware technology system.

Changan Chain Ecology

Construct a digital economy national main chain based on the Changan Chain ChainMaker, and build a Changan Chain ecological network based on major scene applications, gather data elements, enhance business collaboration, and prosper the new ecology of the digital economy.

Autonomous and controllable

Facing the frontiers of world science and technology, adhering to the principle of independent innovation, and bringing together a team of top domestic engineers and scientists, Changan Chain·ChainMaker has constructed a global original underlying technology framework. All key technology modules are self-developed, which has become a new driving force for the development of international blockchain technology. The national “new infrastructure” provides an autonomous, controllable and secure blockchain digital economy infrastructure. The original deep modularized, assembleable, high-performance parallel execution blockchain underlying technology architecture, covering domestic cryptographic algorithms, encrypted communications based on national secret certificates, and domestic CA certificate issuing and certification agencies.

Open source and open

Since its inception, Changan Chain has practiced the concept of open source and openness, and has combined production, learning, research, and use of various scientific research forces to the largest extent. It is jointly developed by top universities and well-known enterprises and other advantages. At the same time, it broadly embraces individual and corporate developers. Create a standard and normative system, and jointly build an open source, open and vibrant blockchain technology ecosystem;

Adopt friendly open source agreements, open software source codes, promote the standardization of multiple technical systems, and establish a development ecosystem under standardization.

Leading performance

Changan Chain has internationally leading blockchain underlying technologies such as efficient parallel scheduling algorithms, high-performance trusted and secure smart contract execution engines, and pipeline consensus algorithms. It has advanced technical advantages such as high concurrency, low latency, and large-scale node networking. Throughput capacity can reach 100,000 TPS, ranking the world’s leading level. Support memory-based data system to improve transaction processing performance.

Flexible assembly

Changan Chain standardizes and modularizes the blockchain execution process, and promotes the evolution of blockchain technology from manual operation mode to automatic assembly production mode, which is convenient for users to build blockchain systems according to different business needs, and provides the basis for the large-scale application of technology ; Pluggable, detachable, independent and controllable core framework, which can quickly access the superior underlying module/single customized development module.

Parallel scheduling

Under the overall proposal-verification framework, DAG-based intra-block transaction parallel scheduling proposals and parallel verification are supported; scheduling supports multiple parallel scheduling algorithms such as deterministic scheduling and random scheduling.

Wide area network

Based on the PubSub mechanism, it supports multiplexing and data isolation of P2P networks under multi-chain isolation; supports NAT penetration, large-scale node networking under complex network topologies, and supports dynamic management of network nodes.

Multi-chain architecture

Support parallel multiple chains to achieve data isolation between different participants; sub-chains can be flexibly expanded according to scenarios to support business and throughput requirements.

authority management

Define access rights for each operation on the chain, support fine-grained rights management strategies; combine organizations, roles, etc. to provide flexible identity rights configuration schemes.

Changan Chain Logical Architecture

The logical architecture of Changan Chain is shown in the figure below. It mainly contains the following elements:

Consensus node: A node that participates in consensus voting, transaction execution, block verification and accounting in the blockchain network.

Synchronization node (sync node): or witness node, participates in block and transaction synchronization, block verification, transaction execution, and records complete ledger data, but does not participate in consensus voting.

Light node: A node that participates in synchronization and verification of block header information, and verifies the existence of transactions.

SDK: Help users connect to the blockchain network through RPC to complete functions such as contract creation, invocation, and chain management.

Block chain browser (ChainMaker broswer): Display block information, transaction information, node information and other block chain information for users through a visual interface.

Management platform: Through a visual interface, it is convenient for users to manage the chain, browse information, and monitor resources.

Contract IDE (contract IDE): an online development environment for smart contracts. All contract languages ​​supported by Changan Chain can be developed and compiled on this IDE.

Command line tool set (ChainMaker CLI, cmc): allows users to deploy and manage the chain using command lines, such as certificate generation, chain configuration, transaction sending, etc.

2k7i2DYHZiwO4DhoapnWQ5qaW0lpZhjYPiqu1ubK.png

From bottom to top, the Changan Chain is composed of the following levels:

Infrastructure layer: public cloud, private cloud, including virtual machines, physical machines, etc., to provide the basic operating environment for the Changan chain.

Storage resource layer: Provides data storage services for Changan chain nodes. For details, please refer to the chapter on data storage.

Basic component layer: Provides general technical components such as cryptography, configuration, log, and common data structure for Changan chain nodes. For details, see the chainmaker-common project.

Core module layer: Changan Chain consensus algorithm, core engine, virtual machine and other core modules, all core modules adopt pluggable design to lay the foundation for the assemblable blockchain.

Access layer: Multi-language chain SDK, which is convenient for application developers to interact with the chain.

Front-end application layer: including blockchain management platform, blockchain browser, contract development IDE, etc., to facilitate users to directly access the underlying blockchain platform.

Block generation process of Changan Chain

The core process of Changan chain block generation is shown in the following figure, mainly including:

Propose candidate blocks. The block proposal node selects a batch of transactions from the transaction pool, schedules and executes the results in parallel, generates a DAG, and broadcasts the block and DAG.

Consensus candidate block. Based on the consensus mechanism on the chain, consensus voting is performed on candidate blocks.

Verify the candidate block. In the consensus process, other nodes in the network verify the correctness of the proposed candidate block.

Execute candidate blocks. Submit the block that completed the consensus voting to the ledger and remove it from the transaction cache.

The virtual machine of Changan Chain

The virtual machine bytecode currently supported by Changan Chain in software includes two types: WASM (WebAssembly) and EVM bytecode.

WebAssembly has a complete set of semantics. In fact, wasm is a small and fast-loading binary format. Its goal is to give full play to hardware capabilities to achieve native execution efficiency. WebAssembly has designed an unconventional text format for development, debugging, testing, and optimization.

EVM bytecode is a virtual machine bytecode originally used on Ethereum . It has been widely used on many blockchain platforms and is supported by relatively mature development tools.

Changan Chain’s Smart Contract SDK

Generally speaking, the smart contracts written by users in high-level languages ​​require access to data on the blockchain and API support. ChainMaker provides different SDKs for different high-level languages. Of course, the basic capabilities provided by these SDKs are the same, including reading data, writing data, and querying some statuses of the blockchain.

SDKs in different languages ​​are limited by the characteristics of the language and the support capabilities of the compiler. For example, the Go language supports functions to return multiple data at the same time, while the tinygo compiler has defects in garbage collection support, and the blockchain system itself provides smart contracts. The running memory size is limited and the call stack depth is limited. Users need to pay attention to these characteristics when writing contracts.

Currently, the smart contract development SDKs ChainMaker has supported include Rust, Go, C++ and Solidity.

Changan Chain’s consensus agreement

Since the open source version v1.1.0, Changan Chain supports four consensus types: Solo, Raft, TBFT, and HotStuff. The four consensuses are compared as follows:

7HIZUiF2xFwfhpxzwtghAhekIKmL1TPeb1iHhVcH.png

The peer-to-peer network of Changan Chain

The network module of the Changan Chain 2.0 version is implemented and improved based on the v0.6.4 version of libp2p. The network address of the node follows the libp2p address format protocol; in order to meet the data isolation requirements of the Changan chain network message in the multi-chain scenario, we modified the libp2p-gossip-pubsub module source code, added the node whitelist mechanism, and accurately controlled the routing table. Each chain on the node enjoys an independent Pubsub service, which ensures that the broadcast data will only be transmitted to the nodes in the chain; in order to meet the support of the national secret encryption algorithm, we have also modified the libp2p-core core package. Added support for national secret TLS certificate.

Improvements based on libp2p:

The core package adds support for the national secret SM algorithm;

The libp2p-gossip-pubsub function module adds a whitelist function to control the Gossip routing table and achieve the effect of broadcast message isolation;

Introduce StreamPool to achieve stream multiplexing to improve performance and network throughput capacity to automatically expand.

Peer-to-peer network features include:

Large-scale node networking;

Dynamic node and connection management;

Proprietary network penetration connection;

Multi-chain network isolation.

Changan Chain’s networking mode

The Changan chain supports automatic discovery and automatic connection networking. By default, each node online can serve as a seed node to provide network discovery services for other nodes, and each seed node will record the node address information in the network. When a new node connects to a seed node, the new node will query the seed node for the addresses of other connectable nodes in the network. After obtaining the addresses of other nodes, the new node will actively try to establish connections with these nodes; in addition, the seed node After the node accepts the new node link, it will notify other online seed nodes of the new node’s address through the network discovery service, and other nodes will also actively try to establish a connection with the new node after obtaining the new node address.

In theory, the Changan chain can realize the simultaneous online networking of tens of thousands or even more nodes.

Storage of Changan Chain

Changan Chain supports commonly used databases to store ledger data, such as LevelDB, RocksDB, MySQL and other databases. The business can choose any of these databases to deploy the blockchain.

Ledger data is mainly divided into 5 categories:

Block data, record block meta information and transaction data:

Block metadata includes: block header, block DAG, txid list of transactions in the block, additionalData, etc.;

Transaction data is the serialized transaction body. In order to provide query on single transaction data, transaction data is stored separately.

State data, which records the state data on the chain read and written in the smart contract, which is the world state.

Historical data, Changan Chain can record the status change history, contract call history, and account initiation transaction history of each transaction during the execution process, which can be used for subsequent retrospective transactions and the change process of status data.

The contract execution result reads and writes the set data, and the Changan Chain separately saves the state data set read and written during the execution of each transaction, which is convenient for other nodes to perform fast data synchronization.

Event data, event log generated during the execution of the contract.

For the above 5 types of ledger data, Changan Chain has implemented 5 DB types respectively: Block DB, State DB, History DB, Result DB and Contract Event DB. After using multiple databases, it is necessary to maintain data consistency between the databases to avoid program interruption after only part of the databases are submitted, which will cause data inconsistencies between different databases. Therefore, Changan Chain introduced the Block binary log component to persist. The original content of the storage block is used for data recovery during the restart process, similar to the write-ahead log (wal) function in the database. It should be noted that historical data and result data are not necessary for each node to save. The node can enable or disable the historical database and result database in the configuration file according to its own business needs.

Posted by:CoinYuppie,Reprinted with attribution to:https://coinyuppie.com/reading-changan-chain-in-one-article/
Coinyuppie is an open information publishing platform, all information provided is not related to the views and positions of coinyuppie, and does not constitute any investment and financial advice. Users are expected to carefully screen and prevent risks.

Leave a Reply