In order to adapt to the blockchain model proposed in this paper, we also designed an efficient consensus algorithm to match it and achieve the purpose of trade parallelization and fast processing. By designing this consensus algorithm, the parallel processing of transactions can be realized in the data transaction of Internet of Things devices, which can improve throughput and speed up the transaction.
According to the actual characteristics of our proposed multilayer blockchain model, the required consensus algorithm should have high throughput, low latency, high transaction efficiency, and low power consumption as its design principles.
3.7.2. Low Power Consumption
Since the platform system was designed on the basis of blockchain technology, and blockchain is based on the distributed concept, participating in consensus in the distributed system requires the joint participation of multiple nodes, so it is more energy-consuming than a traditional central-platform system. Therefore, it is very important to design a consensus algorithm with relatively low energy consumption. Take bitcoin consensus algorithm PoW as an example. The general idea of this algorithm is that a miner node continuously calculates random values through hash functions and finally obtains the hash value that meets the requirements. The miner node that calculates the result first gains the right to block. From this, we can see that the PoW consensus algorithm requires the miner node to perform repeated hash calculations all the time. It was proven that, although this consensus algorithm guarantees extremely strong security, its annual power consumption is equivalent to the annual power consumption of a country [
35], so this algorithm is very resource-consuming.
Through the above analysis, we can set weights to evaluate the merits of the consensus algorithm; the weight formula is as follows.
Since the alliance chain is responsible for trading, according to the design principle of consensus algorithm, this algorithm was optimized in dealing with trading speed and reducing energy consumption. The introduction of the message-queue and book-storage technology because the same node can join different channels in a transaction at the same time, a trade-agreement-generated book number depends on the number of the channels. As a result, the algorithm can implement trade parallelization to improve system throughput and speed up the transaction confirmation time. At the same time, this algorithm abandons the traditional way of acquiring accounting rights through comparative computing power, increases the endorsement node’s participation in consensus, accepts the transaction data of message queue, sorts the transaction data, and forms the ledger data. Compared with PoW, this method can greatly save power.
The nodes in the alliance-chain network are collectively referred to as peer nodes, and a peer may play different roles in the consensus mechanism. Therefore, all role concepts in the consensus mechanism are first introduced.
Client: a client to use the SDK with the multilayer blockchain model for information transmission, then submit trading information, construct good data structure after the delivery trade endorsement node of the operation, the endorsed node is legally requested back to the client, the client obtains a certain number of endorsers after support can send a legal trade request, and the trading order node is sent to sorting work.
Endorser peer: The endorsement node is responsible for receiving data information sent by the client to apply for the transaction. The node mainly carries out legality detection and ACL simulation transaction permission checks on the transaction through the platform’s certificate mechanism. If the verification is passed, the transaction message is signed, and the signed transaction message is returned to the client.
Committer peer: The submission node is responsible for maintaining ledger data, receiving the ordered transaction information sent by the order node, and checking the status of these transactions, generating blocks, and recording them in the ledger.
Order peer: The sorting node is responsible for receiving transaction information from the message queue, sorting the received transaction information, and sending the sorted transaction to the committer node via the message queue for subsequent verification.
There are many peer nodes in a body of the alliance chain, among which the peer node can act as both endorser and committer peer.
The consensus process of the alliance chain is shown in
Figure 12, and can be roughly divided into five stages:
Certificate application: The user accesses the multilayer blockchain model system through APP or SDK, and the newly registered user obtains the identity-authentication and transaction certificates through a CA. After obtaining the certificate, the user can publish the transaction information in the model.
Endorsement verification: The client submits the transaction request to the endorsement node, and the endorsement node checks transaction information according to the endorsement mechanism and gives the endorsement result, support or reject. The authentication process of an endorsement node is as follows: First, verifying that the signature of the transaction application submitted by the client is correct. Second, a channel channel ACL check is performed against the identity and transaction certificates to verify that the transaction can take place on the specified channel. Then, the endorsement node performs a simulated transaction to verify whether the transaction conforms to the rules. Finally, the endorsement node endorses the transaction information requested by the verified client, adds the digital signature of the endorsement node, and resends the modified transaction information to the client. A transaction in which a client invokes a smart contract must be endorsed to be considered legal. The transaction may require the unanimous consent of a principal member, or have more than a certain number of individual nodes agree. The deployed chain code on the endorsement node is responsible for details of these policies.
Client-verification stage: The client obtains the transaction information sent by the endorsement node, and first verifies whether the digital signature of the endorsement node is correct. Second, the messages sent by all endorsement nodes are compared. Finally, it checks if the transaction conforms to the endorsement policy. The client sends the transaction that conforms to the endorsement policy to the ordering peer, and also sends transaction information to the endorsement node.
Consensus-sequencing stage: The sequencing node orders peers to only perform the sorting operation and does not read the specific content of the transaction. Generally, the sorting service is provided by the sorting node cluster set up by the authority in the alliance chain. Sort nodes in the cluster are capable of sorting services for different transactions on different channels, which are mainly completed by back-end plug-ins provided by a Kafka message queue. The ordering node orders peers to sort the transactions according to certain rules, processing transactions in units of a period of time or a certain amount of transaction information.
Check sort: After dealing with the orders, peer-sorted trading blocks are sent to the committer node, the node data blocks the deal for the final validation of the work to first verify the structural integrity of transaction data blocks. If the endorsement signature is in line with the endorsement mechanism in the transaction data, it checks whether the current data are trading effectively, and so on. The chunk of data that are checked by the committer node are written to the ledger, and the node broadcasts synchronous ledger data to the node that participates in the corresponding channel for the transaction.
3.7.3. Order-Node Communication-Process Design
A Kafka message queue is a distributed and efficient data queue with its own reliability and fault-tolerant ability to manage data information and ensure consistency between data. An order peer that provides sorting services, uses the enhanced disaster-recovery capabilities of Kafka message queues. When the node machine sends data information to an order peer, if the order-peer server fails and goes down, the data are locally backed up in the Kafka message queue to avoid data loss and other problems. The deployment of order peers and Kafka message queues is shown in
Figure 13.
In order to improve the efficiency of transaction sequencing, a cluster of order-peer nodes is generally constructed for processing. This cluster needs to add a Kafka message queue to provide data-transmission and fault-tolerance support. Zookeeper manages Kafka. As shown in the figure above, order peers communicate bidirectionally with Kafka, but the peer does not communicate with another peer. The client can communicate with multiple order peers through the Kafka message queue, which can support the parallel processing of multiple transaction sorts, improve data throughput, reduce transaction delay, and accelerate transaction processing speed.
The BroadCast communication of the Kafka message queue is mainly applied to order peers to obtain transaction data sent by a peer and generate a series of transaction blocks. The peer first sends a message through the gRPC protocol to actively connect with the order peer. After the connection is completed, the transaction information is sent to the order peer. The order peer receives transaction-data information through the recv function and pushes the information to the Kafka message queue. The consumer side of the Kafka message queue achieves sorts by obtaining the transaction data. The sorted trade data are packaged into a trade block by the CreateNextBlock function and written to the block by the WriteBlock function. The detailed process is shown in
Figure 14.
As shown in
Figure 15 below, the delivery method of the Kafka message queue is mainly used for peers to initiate a request from an order peer to obtain a sorted transaction data block. First, the peer initiates a connection with the order peer by using the gRPC protocol, obtaining data through interface function ‘get’. The order peer using interface function recv () to obtain the data, in the form of files saved in the latest book data. The order peer calls the SeekInfo interface to obtain a book-data entry, cycle through call iterators get all blocks of book data, returns the block information to the peer, and finally sends the data to the peer to obtain status information.