A consensus method, consensus node and electronic device for blockchain
By using the erasure coding algorithm and the RBC protocol in the blockchain to amortize the transmission of transaction data, and using the Merkle tree proof in the RAFT protocol for consensus, the problems of large leader node bandwidth overhead and low consensus efficiency are solved, and the district efficiency is improved. Consensus efficiency of blockchain.
Patent Information
- Application Number
- CN202111124488.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-24
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2041-09-24
AI Technical Summary
In the blockchain's replication and fault-tolerant RAFT consensus protocol, the leader node needs to send N-1 pieces of proposal data, resulting in high network bandwidth overhead. As the blockchain business grows, the consensus efficiency decreases.
The erasure coding algorithm is used to split the transaction set into N data blocks, and the transmission is shared among the consensus nodes of the blockchain through the RBC protocol, and the Merkel tree is used to prove the consensus proposal in the RAFT protocol, reducing the number of leaders Node bandwidth overhead and consensus time.
It effectively reduces the bandwidth overhead of the leader node, improves the consensus efficiency of the blockchain, and adapts to the growth needs of the blockchain business.
Smart Images

Figure CN113852691B_ABST
Abstract
Description
Technical Field
[0001] This document relates to the field of data processing technology, and in particular to a blockchain consensus method, consensus node and electronic device. Background Art
[0002] Based on the characteristics of blockchain, in the consensus protocol of replication and fault-tolerant RAFT, the proposal data of each round of consensus proposal is packaged by the leader node and synchronously transmitted to each follower node of the blockchain. Assuming that the number of consensus nodes in the blockchain is N (both the leader node and the follower node are consensus nodes), for one round of consensus proposal, the leader node needs to send N-1 copies of proposal data, which generates a huge overhead for the network bandwidth of the leader node.
[0003] With the explosive growth of blockchain business in the future, to achieve higher throughput, it is necessary to reach consensus on more data per unit time, which will put a greater burden on the leader node and lead to a decrease in consensus efficiency. Therefore, there is an urgent need for a technical solution that can reduce the bandwidth consumed by the leader node to initiate a consensus proposal. Summary of the invention
[0004] The purpose of the embodiments of this specification is to provide a blockchain consensus method, consensus node and electronic device, which can complete the blockchain consensus with a smaller bandwidth overhead on the leader node side.
[0005] In order to achieve the above purpose, the embodiments of this specification are implemented as follows:
[0006] First, a blockchain consensus method is provided, including:
[0007] When the preset conditions are triggered, the target consensus node of the blockchain executes the reliable broadcast transmission RBC protocol on the transaction set that has not been synchronized in the transaction pool of the target consensus node, so as to split the selected transaction set into N data blocks corresponding to the consensus node of the blockchain using the erasure code algorithm, and send the corresponding data blocks to other consensus nodes of the blockchain based on the Rval message, wherein the data blocks into which the transaction set is split correspond to the Merkle tree proof calculated based on the erasure code algorithm, and N is the number of consensus nodes of the blockchain;
[0008] Other consensus nodes respond to the RBC protocol executed by the target consensus node to forward the corresponding data blocks received from the Rval message in the blockchain through an Echo message, and after receiving N-2f Echo messages, restore the received data blocks generated by the RBC protocol executed by the target consensus node into the corresponding transaction set in the transaction pool of the target consensus node based on the erasure code algorithm, where f is the consensus node fault tolerance number of the blockchain;
[0009] When the target consensus node becomes the leader node of the blockchain, it sequentially selects at least one Merkle tree certificate from the consensus execution queue of the target consensus node as a consensus object to initiate a consensus proposal of the replication and fault-tolerant RAFT protocol, wherein the consensus execution queue of the target consensus node sequentially stores the Merkle tree certificates of the data blocks generated by the target consensus node executing the RBC protocol;
[0010] When the target consensus node becomes the leader node, the other consensus nodes of the blockchain respond to the consensus proposal initiated by the target consensus node as follower nodes to reach consensus on at least one Merkle tree proof in the consensus proposal initiated by the target consensus node;
[0011] After the consensus proposal initiated by the target consensus node is completed, the target consensus node and other consensus nodes match the transactions corresponding to the Merkle tree proofs that have reached consensus from their respective determined transaction sets to perform block write operations on the matched transactions.
[0012] Second, a blockchain consensus method is provided, including:
[0013] When the preset conditions are triggered, the target consensus node executes the reliable broadcast transmission RBC protocol on the transaction set that has not been synchronized in the transaction pool of the target consensus node, so as to split the selected transaction set into N data blocks corresponding to the consensus nodes of the blockchain using the erasure code algorithm, and sends the corresponding data blocks to other consensus nodes of the blockchain based on the Rval message, wherein the data blocks into which the transaction set is split correspond to the Merkle tree proof calculated based on the erasure code algorithm, N is the number of consensus nodes of the blockchain, and other consensus nodes respond to the RBC protocol executed by the target consensus node to forward the corresponding data blocks received from the Rval message in the blockchain through the Echo message, and after receiving N-2f Echo messages, restore the received data blocks generated by the splitting of the target consensus node by executing the RBC protocol to the corresponding transaction set in the transaction pool of the target consensus node based on the erasure code algorithm, and f is the consensus node fault tolerance number of the blockchain;
[0014] The target consensus node responds to the RBC protocol executed by the target other consensus node, so that after receiving the Rval message sent by the target other consensus node to the target consensus node, the corresponding data block received from the Rval message is forwarded in the blockchain through the Echo message, and the received data block generated by the splitting of the RBC protocol executed by the target other consensus node is restored into the corresponding transaction set in the transaction pool of the target other consensus node, wherein the target other consensus node executes the RBC protocol to use the erasure code algorithm to split the transaction set selected from the transaction pool of the target other consensus node into N data blocks corresponding to the consensus node of the blockchain, and sends the corresponding data block to the consensus node other than the target other consensus node in the blockchain based on the Rval message;
[0015] When the target consensus node becomes the leader node of the blockchain, it selects at least one Merkle tree certificate from the consensus execution queue of the target consensus node in order as a consensus object to initiate a consensus proposal of the replication and fault-tolerant RAFT protocol, wherein the consensus execution queue of the target consensus node stores in order the Merkle tree certificates of the data blocks generated by the target consensus node executing the RBC protocol, and when the target consensus node becomes the leader node, the other consensus nodes of the blockchain respond to the consensus proposal initiated by the target consensus node as follower nodes to reach consensus on at least one Merkle tree certificate in the consensus proposal initiated by the target consensus node;
[0016] After the consensus proposal initiated by the target consensus node is completed, the target consensus node matches the transaction corresponding to the Merkle tree proof that has reached consensus from the determined transaction set, so as to perform a write block operation on the matched transaction;
[0017] When the target other consensus node becomes the leader node, the target consensus node responds to the consensus proposal initiated by the target other consensus node to reach a consensus on at least one Merkle tree proof in the consensus proposal initiated by the target other consensus node, wherein when the target other consensus node becomes the leader node of the blockchain, it sequentially selects at least one Merkle tree proof from the consensus execution queue of the target other consensus node as a consensus object to initiate a consensus proposal of the RAFT protocol, and the consensus execution queue of the target other consensus node sequentially stores the Merkle tree proofs of the data blocks generated by the splitting of the target other consensus node by executing the RBC protocol;
[0018] After the consensus proposal initiated by the target other consensus nodes is completed, the target consensus node matches the transaction corresponding to the Merkle tree proof of consensus from the determined transaction set to perform a write block operation on the matched transaction.
[0019] Thirdly, a consensus node of a blockchain is provided, including:
[0020] The RBC initiation module, when the preset conditions are triggered, executes the reliable broadcast transmission RBC protocol on the transaction set that has not been synchronized in the transaction pool of the target consensus node, so as to use the erasure code algorithm to split the selected transaction set into N data blocks corresponding to the consensus node of the blockchain, and sends the corresponding data blocks to other consensus nodes of the blockchain based on the Rval message, wherein the data blocks into which the transaction set is split correspond to the Merkle tree proof calculated based on the erasure code algorithm, N is the number of consensus nodes of the blockchain, and other consensus nodes respond to the RBC protocol executed by the target consensus node to forward the corresponding data blocks received from the Rval message in the blockchain through the Echo message, and after receiving N-2f Echo messages, restore the received data blocks generated by the RBC protocol split by the target consensus node to the corresponding transaction set in the transaction pool of the target consensus node based on the erasure code algorithm, and f is the consensus node fault tolerance number of the blockchain;
[0021] A RAFT initiating module, when the target consensus node becomes the leader node of the blockchain, sequentially selects at least one Merkle tree certificate from the consensus execution queue of the target consensus node as a consensus object to initiate a consensus proposal of a replication and fault-tolerant RAFT protocol, wherein the consensus execution queue of the target consensus node sequentially stores the Merkle tree certificates of the data blocks generated by the target consensus node executing the RBC protocol, and when the target consensus node becomes the leader node, the other consensus nodes of the blockchain, as follower nodes, respond to the consensus proposal initiated by the target consensus node to reach a consensus on the at least one Merkle tree certificate sequentially selected from the consensus execution queue of the target consensus node;
[0022] The first block writing module, after the consensus proposal initiated by the RAFT initiating module is completed, matches the transaction corresponding to the Merkle tree proof that has reached consensus from the determined transaction set, so as to perform a block writing operation on the matched transaction;
[0023] An RBC response module responds to the RBC protocol executed by the target other consensus node, so as to forward the corresponding data block received from the Rval message in the blockchain through an Echo message after receiving the Rval message sent by the target other consensus node to the target consensus node, and restore the received data block generated by the splitting of the RBC protocol executed by the target other consensus node into the corresponding transaction set in the transaction pool of the target other consensus node, wherein the target other consensus node executes the RBC protocol to use the erasure code algorithm to split the transaction set selected from the transaction pool of the target other consensus node into N data blocks corresponding to the consensus node of the blockchain, and sends the corresponding data block to the consensus node in the blockchain other than the target other consensus node based on the Rval message;
[0024] A RAFT response module, when the target other consensus node becomes a leader node, responds to a consensus proposal initiated by the target other consensus node, so as to reach a consensus on at least one Merkle tree proof in the consensus proposal initiated by the target other consensus node, wherein when the target other consensus node becomes the leader node of the blockchain, at least one Merkle tree proof is sequentially selected from the consensus execution queue of the target other consensus node as a consensus object, so as to initiate a consensus proposal of the RAFT protocol, and the consensus execution queue of the target other consensus node sequentially stores the Merkle tree proofs of the data blocks generated by the splitting of the target other consensus node by executing the RBC protocol;
[0025] The second block writing module, after the consensus proposal initiated by the target other consensus nodes is completed, matches the transactions corresponding to the Merkle tree proof that has reached consensus from the determined transaction set, so as to perform a block writing operation on the matched transactions.
[0026] In a fourth aspect, an electronic device is provided, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is executed by the processor:
[0027] When the preset condition is triggered, the reliable broadcast transmission RBC protocol is executed on the transaction set that has not been synchronized in the transaction pool of the target consensus node, so as to use the erasure code algorithm to split the selected transaction set into N data blocks corresponding to the consensus node of the blockchain, and send the corresponding data blocks to other consensus nodes of the blockchain based on the Rval message, wherein the data blocks into which the transaction set is split correspond to the Merkle tree proof calculated based on the erasure code algorithm, N is the number of consensus nodes of the blockchain, and other consensus nodes respond to the RBC protocol executed by the target consensus node to forward the corresponding data blocks received from the Rval message in the blockchain through the Echo message, and after receiving N-2f Echo messages, restore the received data blocks generated by the RBC protocol split by the target consensus node to the corresponding transaction set in the transaction pool of the target consensus node based on the erasure code algorithm, and f is the consensus node fault tolerance number of the blockchain;
[0028] When the target consensus node becomes the leader node of the blockchain, at least one Merkle tree certificate is selected in sequence from the consensus execution queue of the target consensus node as a consensus object to initiate a consensus proposal of the replication and fault-tolerant RAFT protocol, wherein the consensus execution queue of the target consensus node stores in sequence the Merkle tree certificates of the data blocks generated by the target consensus node executing the RBC protocol, and when the target consensus node becomes the leader node, the other consensus nodes of the blockchain respond to the consensus proposal initiated by the target consensus node as follower nodes to reach a consensus on at least one Merkle tree certificate selected in sequence from the consensus execution queue of the target consensus node;
[0029] After the consensus proposal initiated for at least one Merkle tree certificate selected from the consensus execution queue of the target consensus node is completed, the transaction corresponding to the Merkle tree certificate that has reached consensus is matched from the determined transaction set to perform a write block operation on the matched transaction;
[0030] Responding to the RBC protocol executed by the target other consensus node, after receiving the Rval message sent by the target other consensus node to the target consensus node, forwarding the corresponding data block received from the Rval message in the blockchain through the Echo message, and restoring the received data block generated by the splitting of the RBC protocol executed by the target other consensus node into the corresponding transaction set in the transaction pool of the target other consensus node, wherein the target other consensus node executes the RBC protocol to use the erasure code algorithm to split the transaction set selected from the transaction pool of the target other consensus node into N data blocks corresponding to the consensus node of the blockchain, and sending the corresponding data block to the consensus nodes in the blockchain other than the target other consensus node based on the Rval message;
[0031] When the target other consensus node becomes a leader node, respond to the consensus proposal initiated by the target other consensus node to reach a consensus on at least one Merkle tree proof in the consensus proposal initiated by the target other consensus node, wherein when the target other consensus node becomes the leader node of the blockchain, it sequentially selects at least one Merkle tree proof from the consensus execution queue of the target other consensus node as a consensus object to initiate a consensus proposal of the RAFT protocol, and the consensus execution queue of the target other consensus node sequentially stores the Merkle tree proofs of the data blocks generated by the splitting of the target other consensus node by executing the RBC protocol;
[0032] After the consensus proposal initiated by the target other consensus nodes is completed, the transactions corresponding to the Merkle tree proofs that have reached consensus are matched from the determined transaction set to perform block write operations on the matched transactions.
[0033] In a fifth aspect, a computer-readable storage medium is provided, wherein a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the following steps are implemented:
[0034] When the preset condition is triggered, the reliable broadcast transmission RBC protocol is executed on the transaction set that has not been synchronized in the transaction pool of the target consensus node, so as to use the erasure code algorithm to split the selected transaction set into N data blocks corresponding to the consensus node of the blockchain, and send the corresponding data blocks to other consensus nodes of the blockchain based on the Rval message, wherein the data blocks into which the transaction set is split correspond to the Merkle tree proof calculated based on the erasure code algorithm, N is the number of consensus nodes of the blockchain, and other consensus nodes respond to the RBC protocol executed by the target consensus node to forward the corresponding data blocks received from the Rval message in the blockchain through the Echo message, and after receiving N-2f Echo messages, restore the received data blocks generated by the RBC protocol split by the target consensus node to the corresponding transaction set in the transaction pool of the target consensus node based on the erasure code algorithm, and f is the consensus node fault tolerance number of the blockchain;
[0035] When the target consensus node becomes the leader node of the blockchain, at least one Merkle tree certificate is selected in sequence from the consensus execution queue of the target consensus node as a consensus object to initiate a consensus proposal of the replication and fault-tolerant RAFT protocol, wherein the consensus execution queue of the target consensus node stores in sequence the Merkle tree certificates of the data blocks generated by the target consensus node executing the RBC protocol, and when the target consensus node becomes the leader node, the other consensus nodes of the blockchain respond to the consensus proposal initiated by the target consensus node as follower nodes to reach a consensus on at least one Merkle tree certificate selected in sequence from the consensus execution queue of the target consensus node;
[0036] After the consensus proposal initiated for at least one Merkle tree certificate selected from the consensus execution queue of the target consensus node is completed, the transaction corresponding to the Merkle tree certificate that has reached consensus is matched from the determined transaction set to perform a write block operation on the matched transaction;
[0037] Responding to the RBC protocol executed by the target other consensus node, after receiving the Rval message sent by the target other consensus node to the target consensus node, forwarding the corresponding data block received from the Rval message in the blockchain through the Echo message, and restoring the received data block generated by the splitting of the RBC protocol executed by the target other consensus node into the corresponding transaction set in the transaction pool of the target other consensus node, wherein the target other consensus node executes the RBC protocol to use the erasure code algorithm to split the transaction set selected from the transaction pool of the target other consensus node into N data blocks corresponding to the consensus node of the blockchain, and sending the corresponding data block to the consensus nodes in the blockchain other than the target other consensus node based on the Rval message;
[0038] When the target other consensus node becomes a leader node, respond to the consensus proposal initiated by the target other consensus node to reach a consensus on at least one Merkle tree proof in the consensus proposal initiated by the target other consensus node, wherein when the target other consensus node becomes the leader node of the blockchain, it sequentially selects at least one Merkle tree proof from the consensus execution queue of the target other consensus node as a consensus object to initiate a consensus proposal of the RAFT protocol, and the consensus execution queue of the target other consensus node sequentially stores the Merkle tree proofs of the data blocks generated by the splitting of the target other consensus node by executing the RBC protocol;
[0039] After the consensus proposal initiated by the target other consensus nodes is completed, the transactions corresponding to the Merkle tree proofs that have reached consensus are matched from the determined transaction set to perform block write operations on the matched transactions.
[0040] Based on the scheme of the embodiment of this specification, the consensus nodes of the blockchain can complete transaction synchronization through the RBC protocol and complete transaction consensus through the RAFT protocol. In the RBC protocol stage, each consensus node uses the erasure code transmission mechanism of the RBC protocol to split the local transaction set to be used as the proposal data into data blocks corresponding to other consensus nodes, and sends the split data blocks to the corresponding other consensus nodes, and then the other consensus nodes forward them to each other, thereby realizing the shared transmission of the proposal data. Afterwards, each consensus node stores the Merkle tree proof obtained from the local RBC protocol execution result in the locally maintained consensus execution queue to initiate a consensus proposal when it becomes a leader node later. In the RAFT protocol stage, the leader node selects the Merkle tree proof from the local consensus execution queue in sequence as the consensus object to initiate a consensus proposal, so as to match the Merkle tree proof that has reached consensus back to the corresponding transaction to complete the write block operation. Since the amount of data of the Merkle tree proof is relatively small, the execution time of the RAFT protocol can be effectively reduced, thereby improving the consensus efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the embodiments of this specification or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the embodiments of this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0042] Figure 1 A flowchart of a consensus method for a blockchain provided in an embodiment of this specification.
[0043] Figure 2 A schematic diagram of the structure of a consensus node provided in an embodiment of this specification.
[0044] Figure 3 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this specification. DETAILED DESCRIPTION
[0045] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this specification.
[0046] As mentioned above, in the existing RAFT protocol consensus, the proposal data of each round of consensus proposals is packaged by the leader node and synchronously transmitted to each follower node of the blockchain. Assuming that the number of consensus nodes in the blockchain is N, for one round of consensus proposals, the leader node needs to send N-1 copies of proposal data, which creates a huge overhead for the network bandwidth of the leader node. With the explosive growth of blockchain business in the future, in order to achieve higher throughput, it is necessary to reach a consensus on more data per unit time, which is more burdensome for the leader node, resulting in a decrease in consensus efficiency. In view of this, this document aims to propose a technical solution that can achieve blockchain consensus with a smaller leader node bandwidth overhead to meet the needs of future blockchain business growth.
[0047] Figure 1 It is a flow chart of the consensus method of the blockchain embodiment of this specification. Figure 1 The method shown can be performed by the corresponding device below, including the following steps:
[0048] S102, when the preset conditions are triggered, the target consensus node of the blockchain executes the reliable broadcast transmission RBC protocol on the transaction set that has not been synchronized in the transaction pool of the target consensus node, so as to use the erasure code algorithm to split the selected transaction set into N data blocks corresponding to the consensus nodes of the blockchain, and send the corresponding data blocks to other consensus nodes of the blockchain based on the Rval message, wherein the data blocks into which the transaction set is split correspond to the Merkle tree proof calculated based on the erasure code algorithm, and N is the number of consensus nodes of the blockchain.
[0049] Erasure coding (EC) is a method of data fault tolerance protection that divides data into fragments, expands and encodes redundant data blocks, and stores them in different locations, such as disks, storage nodes, or other geographical locations. From a data function perspective, the protection provided by erasure coding can be expressed as follows: x = k + y. The variable x represents the value of the original data or symbol. The variable y represents the value of the additional or redundant symbols added to provide protection after the failure. The variable x represents the total value of the symbols created after the erasure coding process. For example, in an EC 10 / 16 configuration, 6 additional symbols (variable m) are added to the 10 original symbols (variable k). These 16 data fragments (variable n) can be spread across 16 drives, nodes, or geographical locations, and the original file can be reconstructed from the 10 verified fragments. In other words, even if 6 drives, nodes, or geographical locations are lost or unavailable, the original file can still be recovered. It can be seen that erasure coding only requires a small amount of redundancy to achieve data recovery.
[0050] In the embodiment of this specification, the target consensus node executes the RBC protocol in order to use the erasure coding technology to synchronize the transaction set that needs consensus in its own transaction pool (subsequently used as proposal data) to other consensus nodes. Based on the erasure coding technology, after the target consensus node splits the transaction set in its own transaction pool into data blocks corresponding to each consensus node of the blockchain, it only needs to send the data block corresponding to the other consensus node itself to each other consensus node. In other words, during this synchronization process, the amount of data sent by the target consensus node is only the amount of data in a transaction set.
[0051] In actual applications, the consensus nodes in the blockchain can poll each other to execute the RBC protocol. In other words, the above-mentioned target consensus node triggering preset conditions include: the blockchain polls the target consensus node to execute the RBC protocol.
[0052] or,
[0053] The consensus nodes in the blockchain can also execute the RBC protocol independently. For example, the target consensus node can execute the RBC protocol round by round, and correspondingly, the preset conditions for triggering the target consensus node can include: the target consensus node completes the execution of the previous round of the RBC protocol; for another example, the target consensus node can execute the RBC protocol periodically, and correspondingly, the preset conditions for triggering the target consensus node can include: the target consensus node's execution interval timing of the RBC protocol reaches the execution cycle of the RBC protocol.
[0054] S104, other consensus nodes respond to the RBC protocol executed by the target consensus node to forward the corresponding data blocks received from the Rval message in the blockchain through Echo messages, and after receiving N-2f Echo messages, restore the received data blocks generated by the RBC protocol executed by the target consensus node into the corresponding transaction sets in the transaction pool of the target consensus node based on the erasure code algorithm, where f is the consensus node fault tolerance number of the blockchain.
[0055] As mentioned above, each other consensus node in the embodiment of this specification only obtains its own corresponding data block through the Rval message of the target consensus node. Therefore, in order to further obtain the complete first intersection
[0056] The target consensus node executes the RBC protocol and provides the data blocks corresponding to the follower node to other consensus nodes through the Rval message. In order for other consensus nodes to obtain the complete transaction set in the target consensus node's transaction pool, in this step, other consensus nodes also need to forward the corresponding data blocks received from the Rval message in the blockchain through the Echo message of the RBC protocol to ensure that each follower node of the blockchain can receive data blocks sufficient to restore the transaction set based on the erasure code algorithm.
[0057] Here, when any other consensus node receives N-2f Echo messages, it can restore the data blocks generated by the RBC protocol executed by the target consensus node received into the corresponding transaction set in the transaction pool of the target consensus node based on the erasure code algorithm, thereby realizing the synchronization of the transaction set in the target consensus node's own transaction pool to other consensus nodes.
[0058] From the above process of realizing transaction set synchronization based on the RBC protocol, it can be seen that other consensus nodes also consume network bandwidth to assist the target consensus node in forwarding its corresponding data blocks, thereby sharing the transmission pressure of the target consensus node.
[0059] S106, when the target consensus node becomes the leader node of the blockchain, it selects at least one Merkle tree certificate from the consensus execution queue of the target consensus node in order as a consensus object to initiate a consensus proposal for the replication and fault-tolerant RAFT protocol, wherein the consensus execution queue of the target consensus node stores in order the Merkle tree certificates of the data blocks generated by the target consensus node executing the RBC protocol.
[0060] It should be noted that the orderliness of blockchain transaction execution is very important. For example, in a transaction scenario, user A needs to remit 10,000 yuan to user B, and then user B remits 5,000 yuan to user C. Assuming that user B's initial balance is 3,000 yuan, if the transaction is not executed in order, that is, user B first remits 5,000 yuan to user C, and user A then remits 10,000 yuan to user B, then there will be a transaction logic error in which user B fails to remit money to user C.
[0061] The embodiment of this specification can determine the order of blockchain transactions by storing the order of Merkle tree proofs in the consensus execution queue, and can subsequently ensure that blockchain transactions can be executed in order, thereby avoiding problems similar to the above-mentioned transaction logic errors.
[0062] In actual applications, if the target consensus node cannot reach consensus through a single consensus proposal from the Merkle tree proofs in the consensus execution queue (for example, the number of Merkle tree proofs in the consensus execution queue exceeds the upper limit of the number of Merkle tree proofs supported by one round of blockchain consensus), multiple consensus proposals can be initiated to ensure that the Merkle tree proofs in the consensus execution queue can reach consensus.
[0063] It should be understood that the target consensus node can also remove the Merkle tree proofs that have completed consensus from its own consensus execution queue.
[0064] In addition, based on the above, the target consensus node can also persist the data of the local consensus execution queue. If the target consensus node goes down, the consensus execution queue of the target consensus node can be restored to the state before the restart based on the persistent data of the target consensus node after restart.
[0065] S108, when the target consensus node becomes the leader node, the other consensus nodes of the blockchain, as follower nodes, respond to the consensus proposal initiated by the target consensus node to reach a consensus on at least one Merkle tree proof in the consensus proposal initiated by the target consensus node.
[0066] It should be understood that in the embodiments of this specification, the consensus object of the RAFT protocol is replaced by the Merkle tree proof from the traditional transaction set data, but the consensus principle has not changed, so the consensus can be completed based on the traditional RAFT protocol logic.
[0067] S110, after the consensus proposal initiated by the target consensus node is completed, the target consensus node and other consensus nodes match the transactions corresponding to the Merkle tree proofs that have reached consensus from their respective determined transaction sets, and perform block write operations on the matched transactions.
[0068] Compared with the traditional RAFT protocol, since the consensus object is replaced by the Merkle tree proof from the transaction set data, the result of the RAFT protocol determines the Merkle tree proof of consensus. The consensus nodes of the blockchain need to match the corresponding transactions from their respective determined transaction sets, and then perform block write operations on the matched transactions.
[0069] It should be understood here that the transaction set on the other consensus node side in this step is synchronized by the target consensus node executing the RBC protocol, while the transaction set of the target consensus node itself comes from the transaction pool of the target consensus node.
[0070] Based on the method of the embodiment of this specification, the consensus nodes of the blockchain can complete transaction synchronization through the RBC protocol and complete transaction consensus through the RAFT protocol. In the RBC protocol stage, each consensus node uses the erasure code transmission mechanism of the RBC protocol to split the local transaction set to be used as the proposal data into data blocks corresponding to other consensus nodes, and sends the split data blocks to the corresponding other consensus nodes, and then the other consensus nodes forward them to each other, thereby realizing the shared transmission of the proposal data. Afterwards, each consensus node stores the Merkle tree proof obtained from the local RBC protocol execution result in the locally maintained consensus execution queue to initiate a consensus proposal when it becomes a leader node later. In the RAFT protocol stage, the leader node selects the Merkle tree proof in sequence from the local consensus execution queue as the consensus object to initiate a consensus proposal, so as to match the Merkle tree proof that has reached consensus back to the corresponding transaction to complete the write block operation. Since the amount of data of the Merkle tree proof is relatively small, the execution time of the RAFT protocol can be effectively reduced, thereby improving the consensus efficiency.
[0071] It should be understood that other consensus nodes in the embodiments of this specification may also perform the above Figure 1 The consensus method shown is to put the transactions in its own transaction pool on the chain.
[0072] That is, on the basis of the above, the target other consensus nodes can also execute the RBC protocol on the transaction set that has not been synchronized in the transaction pool of the target other consensus nodes when the preset conditions are triggered, so as to use the erasure code algorithm to split the transaction set selected from the transaction pool of the target other consensus nodes into N data blocks corresponding to the consensus nodes of the blockchain, and send the corresponding data blocks to the consensus nodes in the blockchain except the target other consensus nodes based on the Rval message.
[0073] Correspondingly, the target consensus node responds to the RBC protocol executed by the target other consensus nodes, so that after receiving the Rval message sent by the target other consensus node to the target consensus node, it forwards the corresponding data block received from the Rval message in the blockchain through the Echo message, and restores the received data block generated by the splitting of the RBC protocol executed by the target other consensus node into the corresponding transaction set in the transaction pool of the target other consensus node.
[0074] When the target other consensus node becomes the blockchain leader node, it can also select at least one Merkle tree proof in order from the consensus execution queue of the target other consensus node as the consensus object to initiate a consensus proposal of the RAFT protocol (the consensus execution queue of the target other consensus node also stores in order the data blocks split and generated by the target other consensus node executing the RBC protocol).
[0075] Correspondingly, when the target other consensus node becomes the leader node, the target consensus node, as a follower node, responds to the consensus proposal initiated by the target other consensus node to reach a consensus on at least one Merkle tree proof in the consensus proposal initiated by the target other consensus node. And, after the consensus proposal initiated by the target other consensus node is completed, the target consensus node matches the transaction corresponding to the Merkle tree proof that reaches consensus from the determined transaction set to perform a write block operation on the matched transaction.
[0076] In addition, it should be understood that in the embodiments of this specification, the target consensus node can asynchronously execute the RBC protocol and the RAFT protocol.
[0077] That is to say, when the target consensus node executes the RBC protocol on a transaction set that has not yet been synchronized in the transaction pool of the target consensus node, if it becomes the leader node of the blockchain, it can execute in parallel to select at least one Merkle tree proof in sequence from the consensus execution queue of the target consensus node as a consensus object to initiate a consensus proposal of the RAFT protocol.
[0078] The consensus method of the embodiment of this specification is introduced in detail below.
[0079] In the method of the embodiment of this specification, each consensus node of the blockchain realizes the consensus on-chain of transactions based on the RBC protocol + RAFT protocol. Assume that the number of consensus nodes of the blockchain is N, the number of Byzantine consensus node fault tolerance is f, and N>=3f+1.
[0080] The RAFT protocol divides consensus nodes into three types: Leader, Follower, and Candidate:
[0081] Leader: responsible for log synchronization management, processing requests from clients, and maintaining heartbeat contact with followers;
[0082] Follower: When it is first started, all consensus nodes are in Follower state; they respond to the Leader's log synchronization request; they respond to the Candidate's request and forward the transaction requested to the Follower to the Leader;
[0083] Candidate: Responsible for election voting. When RAFT is first started, a node switches from Follower to Candidate to initiate an election. After the Leader is elected, the node switches from Candidate to Leader state.
[0084] In addition, the RAFT protocol divides time into terms of arbitrary lengths. Terms are represented by consecutive numbers. Each term begins with an election, where one or more candidates attempt to become the leader. If a candidate wins the election, it will serve as the leader for the remainder of the term.
[0085] Taking the target consensus node as an example, the corresponding consensus chain process is as follows:
[0086] RBC Protocol Phases:
[0087] The target consensus node selects several transactions to be agreed upon from the transaction pool of the target consensus node to form the first transaction set.
[0088] The target consensus node uses the erasure coding algorithm to split the first transaction set into N ordered data blocks corresponding to the consensus nodes of the blockchain in a one-to-one manner according to the consensus order. Here, each data block contains at least one transaction in the first transaction set and corresponds to a Merkle tree certificate (root hash) calculated by the erasure coding algorithm.
[0089] For ease of understanding, assume that the blockchain is set with 6 consensus nodes including the target consensus node (the rest are follower nodes), and there are 20 transactions in the first transaction set, namely tx1 to tx20, then the first transaction set can be split into 6 data blocks, namely root hash 1 to root hash 6. Correspondingly, the correspondence between the Merkle tree proof and the transaction is as follows:
[0090] root hash 1: {tx1, tx2, tx3, tx4}
[0091] root hash 2:{tx5,tx6,tx7}
[0092] root hash 3: {tx8, tx9, tx10}
[0093] root hash 4: {tx11, tx12, tx13}
[0094] root hsh 5:{tx14, tx15, tx16}
[0095] root hash 6: {tx17, tx18, tx19, tx20}
[0096] Afterwards, the target consensus node Rval message sends the corresponding data block to other consensus nodes of the blockchain.
[0097] Here, consensus node 1 is used as the target consensus node. If consensus node 2 corresponds to a data block with a Merkle tree proof of roothash 2, then the Rval message sent by consensus node 1 to consensus node 2 carries the Merkle tree proof of roothash 2; similarly, consensus node 3 corresponds to a data block with a Merkle tree proof of root hash 3, then the Rval message sent by consensus node 1 to consensus node 3 carries the Merkle tree proof of root hash 3; ...consensus node 6 corresponds to a data block with a Merkle tree proof of root hash 6, then the Rval message sent by consensus node 1 to consensus node 6 carries the Merkle tree proof of root hash 6.
[0098] Afterwards, after receiving the Rval message from the target consensus node, each other consensus node forwards the Merkle tree proof in the Rval message in the blockchain through the Echo message.
[0099] For example, consensus node 2 sends an Echo message carrying root hash 2 to consensus nodes 1, 3, 4, 5, and 6; consensus node 3 sends an Echo message carrying root hash 3 to consensus nodes 1, 2, 4, 5, and 6, and so on; consensus node 6 sends an Echo message carrying root hash 6 to consensus nodes 1, 2, 3, 4, and 5.
[0100] After receiving N-2f Echo messages, any other consensus node attempts to use the erasure code algorithm to restore the received data blocks (data blocks obtained from Rval messages and Echo messages) back to the first transaction set, and reconstruct the Merkle tree of the first transaction set to verify whether the reconstructed Merkle tree is consistent with the received Merkle tree proof. If consistent, the Ready message is broadcast to the blockchain.
[0101] In addition, based on the above, if the data blocks obtained by any other consensus node from the Echo message and the Rval message are insufficient to restore the first transaction set, it can also obtain the data blocks in the Rval message received by other shared nodes from other consensus nodes outside itself to try to restore the first transaction set.
[0102] Afterwards, for each consensus node, when it receives f+1 identical Ready messages from different nodes, it determines whether it has broadcast the Ready message. If not, it broadcasts the Ready message. When it receives 2f+1 Ready messages from different consensus nodes, it means that the correct first intersection has been received, that is, the target consensus node correctly synchronizes the first intersection in its own transaction pool to the follower node.
[0103] Here, the target consensus node maintains a consensus execution queue locally, which is used to store the Merkle tree proofs of all data blocks in the first transaction set in order.
[0104] The above is an introduction to one round of RBC agreement process.
[0105] Afterwards, the target consensus node can also initiate a new round of RBC protocol process, that is, select a number of transactions to be agreed upon from the transaction pool of the target consensus node to form a second transaction set, and execute the RBC protocol on the second transaction set to complete the synchronization.
[0106] After the target consensus node uses the erasure code algorithm to split the second transaction set into data blocks, it is also necessary to add the Merkle tree proofs of all data blocks in the second transaction set to the locally maintained consensus execution queue in order. It should be understood that based on the storage order of the consensus execution queue, the newly added Merkle tree proof will complete the consensus later than other Merkle tree proofs.
[0107] RAFT protocol phase:
[0108] RAFT protocol phase:
[0109] First, the leader node uses the Merkle tree proofs of each data block in the first transaction set as proposal data and initiates a consensus proposal. The consensus process includes:
[0110] The leader node distributes the Merkle tree proof of each data block of the first transaction set in the form of a log and tries to copy it to the follower node for storage. In addition, the log also contains the command, the corresponding Terms epoch number and the index of the log. The additional information in the log helps the followers determine the legitimacy of the log and the subsequent data synchronization security logic.
[0111] The fact that the log is copied to the follower node does not mean that the commands contained in the log are effective. The copied log needs to go through a confirmation and commit process. When the Leader confirms that the log has been successfully copied by the majority of consensus nodes, the instructions contained in the log can be formally submitted and take effect.
[0112] When the leader node believes that data reliability is guaranteed (provided that replication is completed on more than half of the nodes), the Leader notifies other consensus nodes (including itself) to submit this instruction in their respective state machines (i.e. execute it in the state machine). As long as the state machine conversion logic of each consensus node is consistent and the executed instructions are consistent (including the order), the state consistency between all RAFT nodes can be guaranteed, thereby achieving consensus.
[0113] After all the Merkle tree proofs in the consensus execution queue of the leader node have reached consensus, the leader node and the follower node match the transactions corresponding to the Merkle tree proofs that have reached consensus from their respective first transaction sets to perform block write operations on the matched transactions.
[0114] For ease of understanding, assuming that the Merkle tree proofs of root hash 1 and root hash 5 in the first intersection of the above example reach consensus in this round of consensus proposal, the leader node and the follower node perform block write operations on the transactions {tx1, tx2, tx3, tx4} corresponding to root hash 1 and the transactions {tx14, tx15, tx16} corresponding to root hsh 5, that is, the transactions {tx1, tx2, tx3, tx4 tx14, tx15, tx16} are completed on the chain.
[0115] The above is an introduction to a round of RAFT protocol process.
[0116] It should be understood that if the blockchain does not change the term of the RAFT protocol (i.e., the leader node is not changed), the target leader node, as the leader node, can also select a certain number of Merkle tree proofs in sequence from the local consensus execution queue to initiate a new round of consensus proposals (the Merkle tree proofs that have completed the consensus will be removed from the consensus execution queue).
[0117] The above is an introduction to the method of the embodiment of this specification. It should be understood that appropriate changes can be made without departing from the above principles, and these changes should also be regarded as the protection scope of the embodiment of this specification.
[0118] With the above Figure 1 Corresponding to the consensus method shown, the embodiment of this specification also provides a consensus node of a blockchain. Figure 2: is a structural diagram of the consensus node 200 of the embodiment of this specification, including:
[0119] The RBC initiation module 210, when a preset condition is triggered, executes the reliable broadcast transmission RBC protocol on the transaction set that has not been synchronized in the transaction pool of the target consensus node, so as to use the erasure code algorithm to split the selected transaction set into N data blocks corresponding to the consensus node of the blockchain, and sends the corresponding data blocks to other consensus nodes of the blockchain based on the Rval message, wherein the data blocks into which the transaction set is split correspond to the Merkle tree proof calculated based on the erasure code algorithm, N is the number of consensus nodes of the blockchain, and other consensus nodes respond to the RBC protocol executed by the target consensus node to forward the corresponding data blocks received from the Rval message in the blockchain through the Echo message, and after receiving N-2f Echo messages, restore the data blocks received by the target consensus node to the corresponding transaction set in the transaction pool of the target consensus node based on the erasure code algorithm, and f is the consensus node fault tolerance number of the blockchain.
[0120] The RAFT initiating module 220, when the target consensus node becomes the leader node of the blockchain, sequentially selects at least one Merkle tree certificate from the consensus execution queue of the target consensus node as a consensus object to initiate a consensus proposal for the replication and fault-tolerant RAFT protocol, wherein the consensus execution queue of the target consensus node sequentially stores the Merkle tree certificates of the data blocks generated by the target consensus node executing the RBC protocol, and when the target consensus node becomes the leader node, the other consensus nodes of the blockchain, as follower nodes, respond to the consensus proposal initiated by the target consensus node to reach a consensus on the at least one Merkle tree certificate sequentially selected from the consensus execution queue of the target consensus node.
[0121] After the consensus proposal initiated by the RAFT initiating module is completed, the first block writing module 230 matches the transaction corresponding to the Merkle tree proof that reaches consensus from the determined transaction set, so as to perform a block writing operation on the matched transaction.
[0122] The RBC response module 240 responds to the RBC protocol executed by the target other consensus node, so as to forward the corresponding data block received from the Rval message in the blockchain through an Echo message after receiving the Rval message sent by the target other consensus node to the target consensus node, and restore the received data blocks generated by the splitting of the RBC protocol executed by the target other consensus node into the corresponding transaction set in the transaction pool of the target other consensus node, wherein the target other consensus node executes the RBC protocol to use the erasure code algorithm to split the transaction set selected from the transaction pool of the target other consensus node into N data blocks corresponding to the consensus nodes of the blockchain, and sends the corresponding data blocks to the consensus nodes in the blockchain other than the target other consensus node based on the Rval message.
[0123] The RAFT response module 250 responds to the consensus proposal initiated by the target other consensus node when the target other consensus node becomes the leader node, so as to reach a consensus on at least one Merkle tree proof in the consensus proposal initiated by the target other consensus node, wherein, when the target other consensus node becomes the leader node of the blockchain, it sequentially selects at least one Merkle tree proof from the consensus execution queue of the target other consensus node as a consensus object to initiate a consensus proposal of the RAFT protocol, and the consensus execution queue of the target other consensus node sequentially stores the Merkle tree proofs of the data blocks generated by the splitting of the RBC protocol by the target other consensus node.
[0124] The second block writing module 260, after the consensus proposal initiated by the target other consensus nodes is completed, matches the transaction corresponding to the Merkle tree proof that has reached consensus from the determined transaction set, so as to perform a block writing operation on the matched transaction.
[0125] The consensus nodes of the embodiments of this specification can complete transaction synchronization through the RBC protocol and complete transaction consensus through the RAFT protocol. In the RBC protocol stage, each consensus node uses the erasure code transmission mechanism of the RBC protocol to split the local transaction set to be used as the proposal data into data blocks corresponding to other consensus nodes, and sends the split data blocks to the corresponding other consensus nodes, which are then forwarded to each other by other consensus nodes, thereby realizing the shared transmission of the proposal data. Afterwards, each consensus node stores the Merkle tree proof obtained from the local RBC protocol execution result in the locally maintained consensus execution queue to initiate a consensus proposal when it becomes a leader node later. In the RAFT protocol stage, the leader node selects the Merkle tree proof from the local consensus execution queue in sequence as the consensus object to initiate a consensus proposal, so as to match the Merkle tree proof that has reached consensus back to the corresponding transaction to complete the write block operation. Since the amount of data of the Merkle tree proof is relatively small, the execution time of the RAFT protocol can be effectively reduced, thereby improving the consensus efficiency.
[0126] Optionally, the RBC initiation module 210 and the RAFT initiation module 220 are asynchronously executed modules. That is, when the RBC initiation module 210 becomes the leader node of the blockchain when executing the RBC protocol on the transaction set that has not been synchronized in the transaction pool of the target consensus node, the RAFT initiation module 220 can execute in parallel with the RBC initiation module 210: sequentially select at least one Merkle tree certificate from the consensus execution queue of the target consensus node as a consensus object to initiate the consensus proposal step of the RAFT protocol.
[0127] Optionally, the consensus node of the embodiment of this specification also includes:
[0128] The persistence module performs data persistence on the consensus execution queue of the target consensus node. If the target consensus node is restarted, the consensus execution queue of the target consensus node is restored to the state before the restart based on the persistent data of the target consensus node.
[0129] Obviously, the consensus node in the embodiment of this specification can be used as the above Figure 1 The execution subject in the consensus method shown can realize the consensus method in Figure 1 Since the principle is the same, this article will not repeat it.
[0130] Figure 3 This is a schematic diagram of the structure of an electronic device according to an embodiment of this specification. Figure 3At the hardware level, the electronic device includes a processor, and optionally also includes an internal bus, a network interface, and a memory. The memory may include a memory, such as a high-speed random access memory (RAM), and may also include a non-volatile memory (non-volatile memory), such as at least one disk storage. Of course, the electronic device may also include hardware required for other services.
[0131] The processor, network interface and memory can be interconnected through an internal bus, which can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 3 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0132] The memory is used to store the program. Specifically, the program may include a program code, and the program code includes a computer operation instruction. The memory may include a memory and a non-volatile memory, and provides instructions and data to the processor.
[0133] The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it, forming a consensus device of the blockchain at the logical level. The consensus device can be used as a consensus node of the blockchain or a component in the consensus node. The processor executes the program stored in the memory and is specifically used to perform the following operations:
[0134] When the preset condition is triggered, the reliable broadcast transmission RBC protocol is executed on the transaction set that has not been synchronized in the transaction pool of the target consensus node, so as to use the erasure code algorithm to split the selected transaction set into N data blocks corresponding to the consensus node of the blockchain, and send the corresponding data blocks to other consensus nodes of the blockchain based on the Rval message, wherein the data blocks into which the transaction set is split correspond to the Merkle tree proof calculated based on the erasure code algorithm, N is the number of consensus nodes of the blockchain, and other consensus nodes respond to the RBC protocol executed by the target consensus node to forward the corresponding data blocks received from the Rval message in the blockchain through the Echo message, and after receiving N-2f Echo messages, restore the data blocks received by the target consensus node to the corresponding transaction set in the transaction pool of the target consensus node based on the erasure code algorithm, and f is the consensus node fault tolerance number of the blockchain.
[0135] When the target consensus node becomes the leader node of the blockchain, at least one Merkle tree certificate is selected in sequence from the consensus execution queue of the target consensus node as a consensus object to initiate a consensus proposal for the replication and fault-tolerant RAFT protocol, wherein the consensus execution queue of the target consensus node stores in sequence the Merkle tree certificates of the data blocks generated by the target consensus node executing the RBC protocol, and when the target consensus node becomes the leader node, the other consensus nodes of the blockchain respond to the consensus proposal initiated by the target consensus node as follower nodes to reach consensus on at least one Merkle tree certificate selected in sequence from the consensus execution queue of the target consensus node.
[0136] After the consensus proposal initiated for at least one Merkle tree certificate selected from the consensus execution queue of the target consensus node is completed, the transaction corresponding to the Merkle tree certificate that has reached consensus is matched from the determined transaction set to perform a write block operation on the matched transaction.
[0137] Responding to the RBC protocol executed by the target other consensus node, after receiving the Rval message sent by the target other consensus node to the target consensus node, forwarding the corresponding data block received from the Rval message in the blockchain through the Echo message, and restoring the received data blocks generated by the splitting of the RBC protocol executed by the target other consensus node into the corresponding transaction set in the transaction pool of the target other consensus node, wherein the target other consensus node executes the RBC protocol to use the erasure code algorithm to split the transaction set selected from the transaction pool of the target other consensus node into N data blocks corresponding to the consensus nodes of the blockchain, and sending the corresponding data blocks to the consensus nodes in the blockchain other than the target other consensus node based on the Rval message.
[0138] When the target other consensus node becomes the leader node, it responds to the consensus proposal initiated by the target other consensus node to reach a consensus on at least one Merkle tree proof in the consensus proposal initiated by the target other consensus node, wherein, when the target other consensus node becomes the leader node of the blockchain, it sequentially selects at least one Merkle tree proof from the consensus execution queue of the target other consensus node as a consensus object to initiate a consensus proposal of the RAFT protocol, and the consensus execution queue of the target other consensus node sequentially stores the Merkle tree proofs of the data blocks generated by the splitting of the RBC protocol by the target other consensus node.
[0139] After the consensus proposal initiated by the target other consensus nodes is completed, the transactions corresponding to the Merkle tree proofs that have reached consensus are matched from the determined transaction set to perform block write operations on the matched transactions.
[0140] The above is as in this manual Figure 1The consensus method disclosed in the illustrated embodiment can be applied to a processor or implemented by a processor. The processor may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by an integrated logic circuit of hardware in the processor or instructions in the form of software. The above processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of this specification can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiments of this specification can be directly embodied as a hardware decoding processor for execution, or can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium mature in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware.
[0141] It should be understood that the electronic device of the embodiment of this specification can realize the consensus node in Figure 1 The functions of the illustrated embodiments will not be described in detail herein.
[0142] Of course, in addition to software implementation, the electronic device of this specification does not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc., that is to say, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0143] In addition, the present specification also provides a computer-readable storage medium, which stores one or more programs, and the one or more programs include instructions. When the above instructions are executed by a portable electronic device including multiple application programs, the portable electronic device can realize Figure 1 The method of the embodiment shown is specifically used to perform the following steps:
[0144] When the preset condition is triggered, the reliable broadcast transmission RBC protocol is executed on the transaction set that has not been synchronized in the transaction pool of the target consensus node, so as to use the erasure code algorithm to split the selected transaction set into N data blocks corresponding to the consensus node of the blockchain, and send the corresponding data blocks to other consensus nodes of the blockchain based on the Rval message, wherein the data blocks into which the transaction set is split correspond to the Merkle tree proof calculated based on the erasure code algorithm, N is the number of consensus nodes of the blockchain, and other consensus nodes respond to the RBC protocol executed by the target consensus node to forward the corresponding data blocks received from the Rval message in the blockchain through the Echo message, and after receiving N-2f Echo messages, restore the data blocks received by the target consensus node to the corresponding transaction set in the transaction pool of the target consensus node based on the erasure code algorithm, and f is the consensus node fault tolerance number of the blockchain.
[0145] When the target consensus node becomes the leader node of the blockchain, at least one Merkle tree certificate is selected in sequence from the consensus execution queue of the target consensus node as a consensus object to initiate a consensus proposal for the replication and fault-tolerant RAFT protocol, wherein the consensus execution queue of the target consensus node stores in sequence the Merkle tree certificates of the data blocks generated by the target consensus node executing the RBC protocol, and when the target consensus node becomes the leader node, the other consensus nodes of the blockchain respond to the consensus proposal initiated by the target consensus node as follower nodes to reach consensus on at least one Merkle tree certificate selected in sequence from the consensus execution queue of the target consensus node.
[0146] After the consensus proposal initiated for at least one Merkle tree certificate selected from the consensus execution queue of the target consensus node is completed, the transaction corresponding to the Merkle tree certificate that has reached consensus is matched from the determined transaction set to perform a write block operation on the matched transaction.
[0147] Responding to the RBC protocol executed by the target other consensus node, after receiving the Rval message sent by the target other consensus node to the target consensus node, forwarding the corresponding data block received from the Rval message in the blockchain through the Echo message, and restoring the received data blocks generated by the splitting of the RBC protocol executed by the target other consensus node into the corresponding transaction set in the transaction pool of the target other consensus node, wherein the target other consensus node executes the RBC protocol to use the erasure code algorithm to split the transaction set selected from the transaction pool of the target other consensus node into N data blocks corresponding to the consensus nodes of the blockchain, and sending the corresponding data blocks to the consensus nodes in the blockchain other than the target other consensus node based on the Rval message.
[0148] When the target other consensus node becomes the leader node, it responds to the consensus proposal initiated by the target other consensus node to reach a consensus on at least one Merkle tree proof in the consensus proposal initiated by the target other consensus node, wherein, when the target other consensus node becomes the leader node of the blockchain, it sequentially selects at least one Merkle tree proof from the consensus execution queue of the target other consensus node as a consensus object to initiate a consensus proposal of the RAFT protocol, and the consensus execution queue of the target other consensus node sequentially stores the Merkle tree proofs of the data blocks generated by the splitting of the RBC protocol by the target other consensus node.
[0149] After the consensus proposal initiated by the target other consensus nodes is completed, the transactions corresponding to the Merkle tree proofs that have reached consensus are matched from the determined transaction set to perform block write operations on the matched transactions.
[0150] It should be understood that when the above instructions are executed by a portable electronic device including multiple applications, the leader node described above can be implemented. Figure 1 The functions of the illustrated embodiment will not be described in detail herein.
[0151] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems or computer program products. Therefore, this specification may take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware. Moreover, this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0152] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0153] The above are only embodiments of this specification and are not intended to limit this specification. For those skilled in the art, this specification may be subject to various changes and modifications. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of this specification shall be included in the scope of the claims of this specification. In addition, all other embodiments obtained by ordinary technicians in this field without creative work shall fall within the scope of protection of this document.
Claims
1. A consensus method for blockchain, include: When the preset conditions are triggered, the target consensus node of the blockchain executes the reliable broadcast transmission RBC protocol on the transaction set that has not been synchronized in the transaction pool of the target consensus node, so as to split the selected transaction set into N data blocks corresponding to the consensus node of the blockchain using the erasure code algorithm, and send the corresponding data blocks to other consensus nodes of the blockchain based on the Rval message, wherein the data blocks into which the transaction set is split correspond to the Merkle tree proof calculated based on the erasure code algorithm, and N is the number of consensus nodes of the blockchain; Other consensus nodes respond to the RBC protocol executed by the target consensus node to forward the corresponding data blocks received from the Rval message in the blockchain through an Echo message, and after receiving N-2f Echo messages, restore the received data blocks generated by the RBC protocol executed by the target consensus node into the corresponding transaction set in the transaction pool of the target consensus node based on the erasure code algorithm, where f is the consensus node fault tolerance number of the blockchain; When the target consensus node becomes the leader node of the blockchain, it sequentially selects at least one Merkle tree certificate from the consensus execution queue of the target consensus node as a consensus object to initiate a consensus proposal of the replication and fault-tolerant RAFT protocol, wherein the consensus execution queue of the target consensus node sequentially stores the Merkle tree certificates of the data blocks generated by the target consensus node executing the RBC protocol; When the target consensus node becomes the leader node, the other consensus nodes of the blockchain, as follower nodes, respond to the consensus proposal initiated by the target consensus node to reach a consensus on at least one Merkle tree proof in the consensus proposal initiated by the target consensus node; After the consensus proposal initiated by the target consensus node is completed, the target consensus node and other consensus nodes match the transactions corresponding to the Merkle tree proofs that have reached consensus from their respective determined transaction sets to perform block write operations on the matched transactions.
2. The method according to claim 1, further comprising: include: The target consensus node responds to the RBC protocol executed by the target other consensus nodes, so that after receiving the Rval message sent by the target other consensus node to the target consensus node, the target consensus node forwards the corresponding data block received from the Rval message in the blockchain through the Echo message, and restores the received data blocks generated by the splitting of the RBC protocol executed by the target other consensus node into the corresponding transaction set in the transaction pool of the target other consensus node, wherein the target other consensus node executes the RBC protocol to use the erasure code algorithm to split the transaction set selected from the transaction pool of the target other consensus node into N data blocks corresponding to the consensus nodes of the blockchain, and sends the corresponding data blocks to the consensus nodes in the blockchain other than the target other consensus node based on the Rval message.
3. The method according to claim 2, further comprising: include: When the target other consensus node becomes the leader node of the blockchain, it selects at least one Merkle tree certificate from the consensus execution queue of the target other consensus node in order as a consensus object to initiate a consensus proposal of the RAFT protocol, wherein the consensus execution queue of the target other consensus node stores in order the Merkle tree certificates of the data blocks generated by the splitting of the target other consensus node by executing the RBC protocol; When the target other consensus node becomes the leader node, the target consensus node, as a follower node, responds to the consensus proposal initiated by the target other consensus node to reach consensus on at least one Merkle tree proof in the consensus proposal initiated by the target other consensus node; After the consensus proposal initiated by the target other consensus node is completed, the target consensus node matches the transaction corresponding to the Merkle tree proof of consensus from the determined transaction set to perform a write block operation on the matched transaction.
4. The method according to claim 1, When the target consensus node becomes the leader node of the blockchain when executing the RBC protocol on a transaction set that has not yet been synchronized in the transaction pool of the target consensus node, at least one Merkle tree proof is selected in sequence from the consensus execution queue of the target consensus node as a consensus object in parallel to initiate a consensus proposal of the RAFT protocol.
5. The method according to claim 1, The consensus nodes in the blockchain poll each other to execute the RBC protocol, and the target consensus node triggers the preset condition include: The blockchain polls the target consensus node to execute the RBC protocol; or, The consensus nodes in the blockchain independently execute the RBC protocol, and the preset conditions for triggering the target consensus node include: the target consensus node completes the execution of the previous round of the RBC protocol or the execution interval timing of the RBC protocol by the target consensus node reaches the execution cycle of the RBC protocol.
6. The method according to claim 1, The consensus execution queue of the target consensus node is used as the persistent data of the target consensus node. The method also include: If the target consensus node is restarted, the consensus execution queue of the target consensus node is restored to the state before the restart based on the persistent data of the target consensus node.
7. The method according to claim 1, When the target consensus node initiates a consensus proposal of the RAFT protocol for at least one Merkle tree proof, the target consensus node sends the Merkle tree proof as the object of this round of consensus to other consensus nodes based on the pre-prepared message of the RAFT protocol.
8. A consensus node of blockchain, include: The RBC initiation module, when the preset conditions are triggered, executes the reliable broadcast transmission RBC protocol on the transaction set that has not been synchronized in the transaction pool of the target consensus node, so as to use the erasure code algorithm to split the selected transaction set into N data blocks corresponding to the consensus node of the blockchain, and sends the corresponding data blocks to other consensus nodes of the blockchain based on the Rval message, wherein the data blocks into which the transaction set is split correspond to the Merkle tree proof calculated based on the erasure code algorithm, N is the number of consensus nodes of the blockchain, and other consensus nodes respond to the RBC protocol executed by the target consensus node to forward the corresponding data blocks received from the Rval message in the blockchain through the Echo message, and after receiving N-2f Echo messages, restore the received data blocks generated by the RBC protocol split by the target consensus node to the corresponding transaction set in the transaction pool of the target consensus node based on the erasure code algorithm, and f is the consensus node fault tolerance number of the blockchain; A RAFT initiating module, when the target consensus node becomes the leader node of the blockchain, sequentially selects at least one Merkle tree certificate from the consensus execution queue of the target consensus node as a consensus object to initiate a consensus proposal of a replication and fault-tolerant RAFT protocol, wherein the consensus execution queue of the target consensus node sequentially stores the Merkle tree certificates of the data blocks generated by the target consensus node executing the RBC protocol, and when the target consensus node becomes the leader node, the other consensus nodes of the blockchain, as follower nodes, respond to the consensus proposal initiated by the target consensus node to reach a consensus on the at least one Merkle tree certificate sequentially selected from the consensus execution queue of the target consensus node; The first block writing module, after the consensus proposal initiated by the RAFT initiating module is completed, matches the transaction corresponding to the Merkle tree proof that has reached consensus from the determined transaction set, so as to perform a block writing operation on the matched transaction; An RBC response module responds to the RBC protocol executed by the target other consensus node, so as to forward the corresponding data block received from the Rval message in the blockchain through an Echo message after receiving the Rval message sent by the target other consensus node to the target consensus node, and restore the received data block generated by the splitting of the RBC protocol executed by the target other consensus node into the corresponding transaction set in the transaction pool of the target other consensus node, wherein the target other consensus node executes the RBC protocol to use the erasure code algorithm to split the transaction set selected from the transaction pool of the target other consensus node into N data blocks corresponding to the consensus node of the blockchain, and sends the corresponding data block to the consensus node in the blockchain other than the target other consensus node based on the Rval message; A RAFT response module, when the target other consensus node becomes a leader node, responds to a consensus proposal initiated by the target other consensus node, so as to reach a consensus on at least one Merkle tree proof in the consensus proposal initiated by the target other consensus node, wherein when the target other consensus node becomes the leader node of the blockchain, at least one Merkle tree proof is sequentially selected from the consensus execution queue of the target other consensus node as a consensus object, so as to initiate a consensus proposal of the RAFT protocol, and the consensus execution queue of the target other consensus node sequentially stores the Merkle tree proofs of the data blocks generated by the splitting of the target other consensus node by executing the RBC protocol; The second block writing module, after the consensus proposal initiated by the target other consensus nodes is completed, matches the transactions corresponding to the Merkle tree proof that has reached consensus from the determined transaction set, so as to perform a block writing operation on the matched transactions.
9. An electronic device include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is executed by the processor: When the preset condition is triggered, the reliable broadcast transmission RBC protocol is executed on the transaction set that has not been synchronized in the transaction pool of the target consensus node, so as to use the erasure code algorithm to split the selected transaction set into N data blocks corresponding to the consensus nodes of the blockchain, and send the corresponding data blocks to other consensus nodes of the blockchain based on the Rval message, wherein the data blocks into which the transaction set is split correspond to the Merkle tree proof calculated based on the erasure code algorithm, N is the number of consensus nodes of the blockchain, and other consensus nodes respond to the RBC protocol executed by the target consensus node to forward the corresponding data blocks received from the Rval message in the blockchain through the Echo message, and after receiving N-2f Echo messages, the received data blocks generated by the splitting of the target consensus node by executing the RBC protocol are restored to the corresponding transaction set in the transaction pool of the target consensus node based on the erasure code algorithm, and f is the consensus node fault tolerance number of the blockchain; When the target consensus node becomes the leader node of the blockchain, at least one Merkle tree certificate is selected in sequence from the consensus execution queue of the target consensus node as a consensus object to initiate a consensus proposal of the replication and fault-tolerant RAFT protocol, wherein the consensus execution queue of the target consensus node stores in sequence the Merkle tree certificates of the data blocks generated by the target consensus node executing the RBC protocol, and when the target consensus node becomes the leader node, the other consensus nodes of the blockchain respond to the consensus proposal initiated by the target consensus node as follower nodes to reach a consensus on the at least one Merkle tree certificate selected in sequence from the consensus execution queue of the target consensus node; After the consensus proposal initiated for at least one Merkle tree certificate selected from the consensus execution queue of the target consensus node is completed, the transaction corresponding to the Merkle tree certificate that has reached consensus is matched from the determined transaction set to perform a write block operation on the matched transaction; Responding to the RBC protocol executed by the target other consensus node, after receiving the Rval message sent by the target other consensus node to the target consensus node, forwarding the corresponding data block received from the Rval message in the blockchain through the Echo message, and restoring the received data block generated by the splitting of the RBC protocol executed by the target other consensus node into the corresponding transaction set in the transaction pool of the target other consensus node, wherein the target other consensus node executes the RBC protocol to use the erasure code algorithm to split the transaction set selected from the transaction pool of the target other consensus node into N data blocks corresponding to the consensus nodes of the blockchain, and sending the corresponding data blocks to the consensus nodes in the blockchain other than the target other consensus node based on the Rval message; When the target other consensus node becomes a leader node, respond to the consensus proposal initiated by the target other consensus node to reach a consensus on at least one Merkle tree proof in the consensus proposal initiated by the target other consensus node, wherein when the target other consensus node becomes the leader node of the blockchain, it sequentially selects at least one Merkle tree proof from the consensus execution queue of the target other consensus node as a consensus object to initiate a consensus proposal of the RAFT protocol, and the consensus execution queue of the target other consensus node sequentially stores the Merkle tree proofs of the data blocks generated by the splitting of the target other consensus node by executing the RBC protocol; After the consensus proposal initiated by the target other consensus nodes is completed, the transactions corresponding to the Merkle tree proofs that have reached consensus are matched from the determined transaction set to perform block write operations on the matched transactions.
10. A computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the following steps: When the preset conditions are triggered, the reliable broadcast transmission RBC protocol is executed on the transaction set that has not been synchronized in the transaction pool of the target consensus node, so as to split the selected transaction set into N data blocks corresponding to the consensus nodes of the blockchain using the erasure code algorithm, and send the corresponding data blocks to other consensus nodes of the blockchain based on the Rval message. in, The data blocks into which the transaction set is split correspond to the Merkle tree proof calculated based on the erasure code algorithm, N is the number of consensus nodes of the blockchain, and other consensus nodes respond to the RBC protocol executed by the target consensus node to forward the corresponding data blocks received from the Rval message in the blockchain through the Echo message, and after receiving N-2f Echo messages, restore the received data blocks generated by the RBC protocol executed by the target consensus node to the corresponding transaction set in the transaction pool of the target consensus node based on the erasure code algorithm, and f is the consensus node fault tolerance number of the blockchain; When the target consensus node becomes the leader node of the blockchain, at least one Merkle tree certificate is selected in sequence from the consensus execution queue of the target consensus node as a consensus object to initiate a consensus proposal of the replication and fault-tolerant RAFT protocol, wherein the consensus execution queue of the target consensus node stores in sequence the Merkle tree certificates of the data blocks generated by the target consensus node executing the RBC protocol, and when the target consensus node becomes the leader node, the other consensus nodes of the blockchain respond to the consensus proposal initiated by the target consensus node as follower nodes to reach a consensus on the at least one Merkle tree certificate selected in sequence from the consensus execution queue of the target consensus node; After the consensus proposal initiated for at least one Merkle tree certificate selected from the consensus execution queue of the target consensus node is completed, the transaction corresponding to the Merkle tree certificate that has reached consensus is matched from the determined transaction set to perform a write block operation on the matched transaction; Responding to the RBC protocol executed by the target other consensus node, after receiving the Rval message sent by the target other consensus node to the target consensus node, forwarding the corresponding data block received from the Rval message in the blockchain through the Echo message, and restoring the received data block generated by the splitting of the RBC protocol executed by the target other consensus node into the corresponding transaction set in the transaction pool of the target other consensus node, wherein the target other consensus node executes the RBC protocol to use the erasure code algorithm to split the transaction set selected from the transaction pool of the target other consensus node into N data blocks corresponding to the consensus node of the blockchain, and sending the corresponding data block to the consensus nodes in the blockchain other than the target other consensus node based on the Rval message; When the target other consensus node becomes a leader node, respond to the consensus proposal initiated by the target other consensus node to reach a consensus on at least one Merkle tree proof in the consensus proposal initiated by the target other consensus node, wherein when the target other consensus node becomes the leader node of the blockchain, it sequentially selects at least one Merkle tree proof from the consensus execution queue of the target other consensus node as a consensus object to initiate a consensus proposal of the RAFT protocol, and the consensus execution queue of the target other consensus node sequentially stores the Merkle tree proofs of the data blocks generated by the splitting of the target other consensus node by executing the RBC protocol; After the consensus proposal initiated by the target other consensus nodes is completed, the transactions corresponding to the Merkle tree proofs that have reached consensus are matched from the determined transaction set to perform block write operations on the matched transactions.
Citation Information
Patent Citations
Block-chain-based transaction consensus processing method and device, and electronic device
CN109345386A
Transaction consensus processing method and device based on blockchain and electronic equipment
CN109379397A
