If the currency block chain technology represented by the Bitcoin is 1.0, and the contract block chain technology represented by the Ether Square is 2.0, then the Hyperledger project which realizes the complete permission control and the security guarantee will undoubtedly represent the arrival of the block Chain Technology 3.0 ERA.
The Hyperledger project currently consists of fabric, sawtooth lake,iroha,blockchain-explorer four sub projects. Let's take a look at the core sub project fabric The latest version is the 1.0 architecture, principles and a typical transaction process, and finally summed up the advantages of fabric.
Introduction to Fabric1.0 architecture
As shown in the figure above, the core of the fabric architecture consists of three parts: Identity, ledger and transactions, and Smart contact.
Identity
Identity, that is to identify management, fabric is so far in the design of the most closely linked to the chain of thought block chain. Alliance chain taking into account the need for security, privacy, regulation, auditing, and performance in commercial applications, and increasing access thresholds, members must be allowed to join the network. Fabric Member Management services provide identity management, privacy, confidentiality, and auditable services for the entire block chain network. The Member Management Service makes the unlicensed block chain into a permissive block chain through PKI and the centralized consensus mechanism of the public key infrastructure. Smart Contract
Fabric Intelligent Contract Smart contract, called chain Code Chaincode, is a piece of code that handles the business logic that network members agree on. Compared with the Ethernet square, fabric chain code and the bottom ledger is separate, upgrade chain code does not need to migrate the ledger data to the new chain code, the real realization of the separation of logic and data.
Chain code can be written in Go, Java, Node.js language. The chain code is compiled into a stand-alone application, and the fabric uses the Docker container to run the Chaincode, where the base mirrors are signed security mirrors, including the OS layer and the Development Chaincode language, runtime, and SDK layers. Once the Chaincode container is started, it is connected via GRPC with the peer node that initiates the Chaincode.
Ledger | Transactions
Fabric uses Peer-to-peer protocols based on HTTP/2 to manage distributed ledger accounts. Adopt pluggable ways to set up consensus agreements, such as PBFT,RAFT,POW and POS, according to specific requirements.
Ledger
As shown in the figure above, the ledger ledger consists of two main pieces: Blockchain and state. Blockchain is a series of blocks linked together to record historical transactions. State corresponds to the current status of the ledger, it is a key-value database, fabric defaults to level DB, can be replaced by other Key-value database, such as Couch DB. Give an example. We use block chain to achieve a marble trading system. We developed a chaincode, each marble has the following attributes: Name, owner, color, size. You can define a JSON object, use name to do key, and JSON object to do value, stored in level db or couchdb.
transcation
The transction transactions on fabric are divided into two types, the deployment of transactions and the invocation of transactions.
Deployment transactions:
Deploy the Chaincode to the peer node and ready to be invoked, and when a deployment transaction executes successfully, Chaincode is deployed to each peer node. It's like deploying a Web service or EJB to a different instance on the application server.
Call Transaction:
The client application uses the API provided by the fabric to invoke a function of a previously deployed Chaincode to execute the transaction and read and write to the KV database accordingly, returning success or failure.
Apis,events,sdks
Fabric provides APIs for easy application development, Chaincode for server-side, currently supported with Go, Java or node.js development. For client applications, fabric currently provides node.js and Java SDK. Future plans to provide Python and go sdk,fabric also provide restapi. For developers, it is also possible to quickly test chaincode through the CLI, or to inquire about transaction status. In block chain networks, nodes and Chaincode send events to trigger some listening actions to facilitate integration with other external systems.
Fabric 1.0 Application Development process
As shown in the following illustration, the developer creates the client application and the smart Contract (Chaincode), Chaincode deployed to the peer node of the block chain network. By Chaincode to manipulate the ledger, when you call a transaction transaction, you are actually calling a function method in Chaincode that implements the business logic and makes the get, put, and delete operations on the ledger. The client application provides a user interface and submits the transaction to the block chain network.
Fabric 1.0 Business Network
Business Network, also known as consensus network or block chain network, composed of different nodes. node is the communication entity of block chain, node is a logical concept, different types of nodes can run on the same physical server. These nodes may be deployed on top of the cloud or locally. May come from a different company or organization. There are two types of nodes in the block chain network: The peer node and the Orderer node, as shown in the following illustration.
Peer node:
Chaincode is deployed on the peer node, which reads and writes the ledger. A peer node can act as a variety of roles, such as Endorser endorser, submitter committer. There will be multiple peer nodes in a block chain network.
Orderer node:
Sort transactions, bulk package, generate blocks, and send to peer nodes. There will be multiple orderer nodes in a block chain network, which together provide a sorting service. Sorting services can be implemented in many different ways, from a centralized service (used for development and testing, such as solo), to distributed protocols such as Kafka.
The sort service provides a shared communication channel to the client and peer nodes. Provides message broadcast services (broadcast and deliver) that contain transactions. The client can broadcast (broadcast) messages to all nodes through this channel. The channel can post (deliver) messages to the node that is connected to the channel.
The sort service supports multiple channels, similar to the topic topic in the Publish/Subscribe messaging system. The client and peer nodes can connect to a given point channel and send and receive messages through a given channel. Multi-channel allows peer nodes to subscribe to any number of channels based on the application of access control policies; That is, the application sets up the channel in a subset of the specified peer nodes. These peer comprise a collection of stakeholders submitted to the channel transaction, and only these peer can receive blocks containing the relevant transactions, completely isolated from other transactions, and data isolation and confidentiality are achieved.
In addition, a subset of peers submits these private blocks to different ledger books, allowing them to protect these private transactions from other peers subsets of the ledger. The application decides to send transactions to 1 or more channels based on business logic.
For example, as shown in the figure above, peer 1,2 and n subscribe to the red channel and jointly maintain the red Ledger; Peer 1 and N subscribe to the blue channel and maintain the blue ledger; Similarly, peer 2 and peer n are on the black channel and maintain the black ledger.
In this example, Peer n subscribes to all channels and we see that each channel has a related ledger. In other words, in a block chain network, each node can have multiple ledger.
Fabric 1.0 Trading Process
Fabric1.0 A typical trading process is shown in the following illustration:
1. Client structuring Transaction proposal
The client application constructs the transaction proposal propose using any SDK (Node.js,java,python). The proposal is a request to call the function function of the smart contract to verify which data can be read or written to the ledger.
The client sends the transaction proposal to one or more peer nodes, and the transaction proposal contains the contract identifier, the contract method and the parameter information, and the client's signature, etc. to be invoked in the transaction.
The SDK packages the transaction proposal in a recognizable format (such as the Protocolbuffer on GRPC) and uses the user's encryption credentials to generate a unique signature for the transaction proposal.
2. Endorsement node Simulation execution transaction
Endorsement node endorser after receiving the transaction proposal, verify the signature and determine whether the submitter has permission to perform the action. The endorsement node takes the parameters of the transaction proposal as input, executes the transaction on the current state KV database, generates the transaction result containing the execution return value, the read operation set and the write operation set (the ledger is not updated at this time), the collection of these values, the signature of the endorsement node and the endorsement result NO) As a result of the proposal returned to the client SDK,SDK parse the information to determine whether it should be used for subsequent transactions.
3. The client sends the transaction to the consensus service
The application (SDK) validates the endorsement node signature and compares the results of the proposals returned by each node to determine whether the proposal results are consistent and whether it is performed in reference to the specified endorsement policy.
The client receives each endorsement node's reply, packs together to form a transaction and the signature, sends to orderers.
4. Consensus sequencing, generating new blocks, submitting transactions
Orderers the received transactions to the consensus ordering, and then according to the Block generation strategy, a batch of transactions packaged together to generate new blocks, call the deliver API delivery message, sent to the submission node.
After the submission node receives the block, it verifies each transaction in the block, checks whether the input output of the transaction depends on the status of the current block chain, appends the chunk to the local block chain, and modifies the K-V state database.
Farbric 1.0 Advantage Summary
complete access control and safety assurance
Members must be licensed to join the network, through certificates, encryption, signature and other means to ensure security. The multi-channel function ensures that only the nodes participating in the transaction can access the data, and the other nodes cannot see it. Meet the legal and regulatory requirements for data protection. In some industries, you need to know who has access to specific data.
Modular design, pluggable architecture
For example, a state database can take either level db or couch db, or another Key-value database.
Identity Management (Identity MA