1. Description
The blockchain is a transparent, immutable model-based decentralized system whose core is a distributed ledger that records all transactions that occur on the network.
There are three main types of blockchain networks: public blockchains, consortium blockchains, and private blockchains; digital currencies such as Bitcoin and Ethereum that we are familiar with are actually public blockchain platforms;
The one to be introduced today Fabric
is a consortium chain type; Fabric is an enterprise-level distributed ledger technology platform and the most widely used blockchain project.
This article will sort out the core concepts and key functions of the blockchain technology platform Fabric
.
2. Features
Compared with other blockchain platforms, Fabric has the following characteristics:
- Open source: It is a heavyweight blockchain platform under the Linux Foundation.
- Identity management: The difference between fabric and other blockchain systems is that it is private and authorized for access, not a public system that allows unidentified participants to enter the network; it provides a membership service that uses to manage all participants and permissions on the network.
- Privacy and confidentiality: The concept of a channel provides transaction privacy and confidentiality. A Fabric network can create multiple channels, and any unauthorized network members cannot see or access any data on the channel; it can be understood as It supports multi-tenancy, and the data between channels is isolated.
- Chaincode function: Smart contracts are called chaincodes in Fabric, which are used to access the ledger, such as writing transaction information, querying data, and so on.
- Modular design: Fabric implements a modular architecture, such as identity, sorting, chain code and other services and functions, which are optional and pluggable and very flexible.
3. System function
A functional architecture diagram of Fabric:
- The identity management function is to realize the management of members, permissions and certificates through the PKI system and CA module.
- The distributed ledger is the core function of the blockchain network, which records all transaction information.
- The ordering service is similar to the role of a referee. Because different transaction orders have a great impact on the final transaction result, this ordering service is mainly to allow all nodes to reach a unified consensus and ultimately achieve data consistency.
- In terms of network communication, the point-to-point communication between nodes is based on the grpc protocol, and then the gossip algorithm is used to achieve decentralized broadcasting, which means that there is no need for a central node. way to spread the news to the whole network.
- Endorsement verification refers to the endorsement strategy. There are many endorsement strategies. For example, I specify the strategy as the majority of nodes agree, which means that a transaction must be completed by more than half of the nodes, which can effectively prevent some malicious. 's transaction.
- The chaincode service is an independent application that runs in an isolated Docker container and automatically generates a Docker image of the chaincode when the chaincode is deployed.
4. Component logical relationship
- The light blue square in the
N
represents the entire blockchain network; - The bottom of the network
C
is通道
is equivalent to a sub-chain. A blockchain network can create multiple channels. multi-tenant system; - Multiple
Peer 节
P2
P1
deployed on aPeer 节
point composition; - Each
Peer 节
point has a full copy of账本
ac703aa5ed257ae61936b21922e3bc2c--- in redL1
and then智能合约
is deployed on each node is yellowS1
, one node can deploy multiple智能合约
; - Finally, the white square A outside the blockchain network refers to accessing the
应用
, and the application trades with the ledger on the node through the channel.
5. Ledger
A ledger is an important concept in Hyperledger Fabric that stores important factual information about business objects, including both the current values of object properties and the history of the transactions that produced those current values.
The ledger consists of a blockchain (chain) and stores immutable, ordered records in blocks; it also contains a state database to record the current Fabric state. Each 通道
has 一个账本
in it. Each node will save a copy of the channel 账本副本
for each channel it belongs to.
As shown in the figure below, the ledger in Hyperledger Fabric consists of two parts: "world state" and "blockchain":
World state: The world state is implemented in the form of a database. The default is LevelDB, which is a KeyValue database; the latest value of the business object is recorded in it; the smart contract mainly interacts with the world state in the ledger.
Blockchain: Implemented in the form of files, recording transaction log details, which is equivalent to a transaction ledger.
For example, in a bank account, if one deposit and three withdrawal operations occur, the final log will record four records in the blockchain, while the world state will record only one record, which is the latest balance of the current account.
6. Smart Contract
智能合约
is an application running on the ledger, which can encode assets, and the transaction instructions (or business logic) can also be used to modify assets.
After Fabric2.0
a new lifecycle was introduced to manage contracts:
- The first step is to develop the contract: you need to rely on the native contract sdk, which supports three development languages including Java, js and Golang.
- After opening the contract, the administrator can use the package subcommand to package the contract and generate the package file. The default program of the packaging command is the golang language, and you can use the -l parameter to specify other languages.
- One package can be installed multiple times, and then use the install command to install the contract on the specified peer node.
- After the installation is successful, use the approveformyorg command to approve the contract on behalf of the institution and specify the endorsement policy.
- Finally, use the commit command to submit the contract definition to the specified channel. After executing this step, the smart contract is successfully deployed and officially takes effect.
- Next, we can write an application to conduct transactions with the blockchain network. Fabric encapsulates a set of gateway SDK for the application to use, and interacts with the blockchain network through a series of simple APIs.
For the development of Java smart contracts, see my previous article " Hyperledger Fabric 2.x Custom Smart Contracts "
7. Transaction process
- First, the blockchain application initiates a transaction;
- Then
背书节点
verifies the signature of the transaction and returns the verification result; - The client encapsulates the endorsement result and sends it to the Peer node, and then submits it to the Order node for data synchronization;
- The Order node synchronizes the transaction information to other peer nodes for verification and submission in sequence;
- The final ledger is updated to complete the entire transaction.
Scan the code to follow for a surprise!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。