A consensus method and device for blockchain

By adopting a multi-partition structure and leadership node interaction mechanism in the blockchain, the problem of reduced block generation efficiency caused by the increase of consensus nodes is solved, the block generation efficiency and credibility of the blockchain are improved, and the efficiency of the financial industry is met with high efficiency in the financial industry. Operational requirements.

CN113343274BActive Publication Date: 2024-11-12WEBANK (CHINA)
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110738775.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-06-30
Publication Date
2024-11-12
Estimated Expiration
2041-06-30

AI Technical Summary

Technical Problem

The increase in the number of consensus nodes in the blockchain results in a decrease in block generation efficiency, which cannot meet the efficient operation needs of the financial industry.

Method used

Adopt a multi-partition blockchain network, each partition has a leader node and a non-leader node. Through the leader node, the main block to be recognized when the preset conditions are met, and interact with the leader nodes of other partitions, the data transmission between nodes is reduced and the data transmission is improved. The overall blockchain block credibility.

Benefits of technology

It improves block generation efficiency, reduces data transmission between nodes, enhances the overall block credibility of the blockchain, and meets the efficient operation needs of the financial industry.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113343274B_ABST
    Figure CN113343274B_ABST
Patent Text Reader

Abstract

The present invention discloses a consensus method and device for blockchain, which is applied to a blockchain network including multiple partitions, each partition including a leader node and a non-leader node, and the method is: determining a first leader node in a first partition, the first leader node participating in the consensus of a first sub-block in the first partition, after the first leader node determines that the consensus of the first sub-block is successful, if a preset condition is met, a first main block to be agreed upon is generated according to the first sub-block and the second sub-block of at least one second partition, and a second main block to be agreed upon from a second leader node of the at least one second partition is obtained, and the second main block to be agreed upon is participated in the consensus of the second main block in the blockchain network. When the above method is applied to financial technology (Fintech), the overall block credibility of the blockchain is improved while ensuring that data transmission between nodes is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of blockchain in the field of financial technology (Fintech), and in particular to a consensus method and device for blockchain. Background Art

[0002] With the development of computer technology, more and more technologies are applied in the financial field. The traditional financial industry is gradually transforming to Fintech and blockchain. However, due to the security and real-time requirements of the financial industry, higher requirements are also placed on technology. At present, based on the immutability of blockchain, transactions are often conducted through blockchain in the field of financial technology.

[0003] Each time a block is generated in the blockchain, consensus is required among the consensus nodes. As more consensus nodes are added to the blockchain, the data that each consensus node needs to transmit is increasing, which will lead to lower efficiency in block generation. This is a problem that needs to be solved urgently. Summary of the invention

[0004] The present invention provides a blockchain consensus method and device, which solves the problem of low efficiency of block generation in the prior art.

[0005] In a first aspect, the present invention provides a consensus method of a blockchain, applied to a blockchain network including multiple partitions, wherein each partition includes a leader node and a non-leader node, the method comprising:

[0006] Determining a first leader node in a first partition, where the first partition is any partition among the plurality of partitions;

[0007] The first leader node participates in the consensus of the first sub-block in the first partition; the consensus node of the first sub-block is a node in the first partition;

[0008] After the first leader node determines that the first sub-block consensus succeeds, if the number of sub-blocks that succeed in consensus or the cumulative number of sub-blocks that succeed in consensus in the first partition after the first main block consensus succeeds meets the preset conditions, the first leader node generates a first main block to be consensused based on the first sub-block and the second sub-block of at least one second partition; the first main block is the latest main block on which the blockchain network currently succeeds in consensus, the multiple partitions include the first partition and the at least one second partition, and the second sub-block of any second partition is the latest sub-block on which the second partition succeeds in consensus;

[0009] The first leader node broadcasts the first main block to be agreed upon to the at least one second partition, and obtains a second main block to be agreed upon from a second leader node of the at least one second partition; wherein the second main block to be agreed upon of any second partition is the latest main block generated by the second partition;

[0010] The first leader node participates in the consensus of the second main block in the blockchain network based on the first main block to be agreed upon and the second main block to be agreed upon of the second leader node of the at least one second partition; the consensus nodes of the second main block include the first leader node and the second leader node of the at least one second partition.

[0011] In the above method, the blockchain includes multiple partitions, and each partition has both a leader node and a non-leader node. For any first partition, when the sub-block consensus in the first partition is reached, the consensus node only involves the nodes in the first partition. Therefore, when the sub-block consensus between the first main block and the second main block is reached, it is only necessary to reach a consensus with the nodes of the partition, and when the preset conditions are met, the first leader node generates a first main block to be consensus, and obtains a second main block to be consensus from the second leader node of the at least one second partition. It is only necessary to transmit data to each other through some leader nodes of each partition, and the consensus on the second main block also reduces the data transmission between nodes. The sub-blocks between the first main block and the second main block are reached through the second main block, thereby ensuring that the data transmission between nodes is reduced, thereby improving the overall block credibility of the blockchain.

[0012] Optionally, the verification content of the second main block includes at least one item in a block hash list, a transaction root hash, a receipt root hash, and a signature information list;

[0013] The block hash list of the second main block is obtained according to the block hash of the first sub-block and the block hash of the second sub-block of the at least one second partition;

[0014] The transaction root hash of the second main block is obtained according to the transaction root hash of the first sub-block and the transaction root hash of the second sub-block of the at least one second partition;

[0015] The receipt root hash of the second main block is obtained according to the receipt root hash of the first sub-block and the receipt root hash of the second sub-block of the at least one second partition;

[0016] The signature information list of the second main block is obtained according to the signature of the first leader node and the signature of the second leader node of the at least one second partition.

[0017] In the above method, any item in the block hash list, transaction root hash, receipt root hash and signature information list is obtained based on the information in the first sub-block and the second sub-block of the at least one second partition, so that the consensus of each partition sub-block can be verified and the consensus situation within each partition can be checked.

[0018] Optionally, the first leader node participates in the consensus of the second main block in the blockchain network based on the first main block to be agreed upon and the second main block to be agreed upon of the second leader node of the at least one second partition, including:

[0019] For any second partition, if the first leader node determines that the verification content of the first main block to be agreed upon is the same as the verification content of the second main block to be agreed upon of the second partition, then it is determined that the verification of the second main block to be agreed upon of the second partition has passed;

[0020] If the first leader node determines that the number of the second main blocks to be agreed upon that have passed verification meets the preset consensus condition, it is determined that the consensus of the second main block is successful.

[0021] In the above manner, the consensus of the second main block does not need to repackage transactions. It only needs to determine whether the verification content of the first main block to be consensus is the same as the verification content of the second main block to be consensus in the second partition and the number of verification passes meets the preset consensus conditions, so that the consensus is more efficient.

[0022] Optionally, if the number of sub-blocks on which consensus succeeds in the first partition after the first main block consensus succeeds meets a preset condition, the adjacent sub-blocks after the first main block include the first sub-block on which consensus succeeds in the multiple partitions after the first main block consensus is generated, and the adjacent sub-blocks before the second main block include the last sub-block on which consensus succeeds in the multiple partitions after the first main block consensus is generated.

[0023] In the above method, if the number of sub-blocks on which the first partition has successfully reached consensus after the first main block has successfully reached consensus meets a preset condition, a chain of multiple sub-blocks is connected between the first main block and the second main block, so that the sub-blocks in multiple partitions cannot be tampered with.

[0024] Optionally, the preset condition is: after the first main block consensus is successful, the number of sub-blocks on which consensus succeeds or the cumulative number of sub-blocks on which consensus succeeds in the first partition is greater than or equal to a quantity threshold; the quantity threshold is obtained based on the cumulative number of sub-blocks on which consensus succeeds and\or the cumulative number of main blocks on which consensus succeeds in the blockchain.

[0025] In the above manner, the quantity threshold is obtained according to the cumulative number of sub-blocks on the blockchain that have successfully reached consensus and / or the cumulative number of main blocks on the blockchain that have successfully reached consensus. Therefore, the quantity threshold can be set based on the historical consensus success situations, making it more efficient.

[0026] Optionally, the first leader node broadcasts the first sub-block to the second leader node of the at least one second partition; and the first leader node obtains the second sub-block from the second leader node of the at least one second partition.

[0027] Optionally, the first leader node participates in the consensus of the first sub-block in the first partition, including:

[0028] The first leader node generates a first sub-block to be agreed upon;

[0029] The first leader node broadcasts the first sub-block to be agreed upon to consensus nodes other than the first leader node in the first partition;

[0030] The first leader node performs consensus on the first sub-block according to the verification information of the first sub-block to be agreed upon obtained in the first partition.

[0031] Optionally, the first leader node is the only leader node in the first partition; the first leader node is selected based on a polling method.

[0032] In the above method, only one leader node is needed for a partition, so only one leader node is needed within the partition to reach consensus on the main block with other partitions, and it is selected based on the polling method. Therefore, each node takes turns to be elected as the leader node, making the load more balanced.

[0033] Optionally, the first leader node participates in the consensus of the second main block in the blockchain network based on the first main block to be agreed upon and the second main block to be agreed upon of the second leader node of the at least one second partition, including:

[0034] The first leader node participates in the consensus of the second main block in the blockchain network based on the first main block to be agreed upon and the second main block to be agreed upon of the second leader node of the at least one second partition in accordance with the Practical Byzantine Fault Tolerance (PBFT) algorithm.

[0035] When the above partition consensus method is combined with the PBFT algorithm, since the PBFT algorithm requires about 2 / 3 of the nodes to verify the block, the partition consensus method can reduce data transmission more significantly.

[0036] In a second aspect, the present invention provides a consensus device for a blockchain, applied to a blockchain network including multiple partitions, wherein each partition includes a leader node and a non-leader node, the device is a first leader node of a first partition, and the device includes:

[0037] a determination module, configured to determine a first leader node in a first partition, wherein the first partition is any partition among the plurality of partitions;

[0038] A consensus module, used to participate in the consensus of the first sub-block in the first partition; the consensus node of the first sub-block is a node in the first partition;

[0039] The consensus module is used to generate a first main block to be consensused according to the first sub-block and at least one second sub-block of the second partition after the consensus of the first main block is successful through the determination module. If the number of sub-blocks that have successfully reached consensus or the cumulative number of sub-blocks that have successfully reached consensus in the first partition after the consensus of the first main block is successful through the determination module meets a preset condition, the first main block is the latest main block that has successfully reached consensus in the blockchain network, the multiple partitions include the first partition and the at least one second partition, and the second sub-block of any second partition is the latest sub-block that has successfully reached consensus in the second partition;

[0040] The consensus module is further used to broadcast the first main block to be agreed upon to the at least one second partition, and obtain the second main block to be agreed upon from the second leader node of the at least one second partition; wherein the second main block to be agreed upon of any second partition is the latest main block generated by the second partition; and

[0041] The second main block to be agreed upon based on the first main block to be agreed upon and the second leader node of the at least one second partition participates in the consensus of the second main block in the blockchain network; the consensus nodes of the second main block include the first leader node and the second leader node of the at least one second partition.

[0042] Optionally, the verification content of the second main block includes at least one item in a block hash list, a transaction root hash, a receipt root hash, and a signature information list;

[0043] The block hash list of the second main block is obtained according to the block hash of the first sub-block and the block hash of the second sub-block of the at least one second partition;

[0044] The transaction root hash of the second main block is obtained according to the transaction root hash of the first sub-block and the transaction root hash of the second sub-block of the at least one second partition;

[0045] The receipt root hash of the second main block is obtained according to the receipt root hash of the first sub-block and the receipt root hash of the second sub-block of the at least one second partition;

[0046] The signature information list of the second main block is obtained according to the signature of the first leader node and the signature of the second leader node of the at least one second partition.

[0047] Optionally, the consensus module is specifically used to: for any second partition, if it is determined that the verification content of the first main block to be agreed upon is the same as the verification content of the second main block to be agreed upon of the second partition, then it is determined that the second main block to be agreed upon of the second partition has passed the verification; if it is determined that the number of second main blocks to be agreed upon that have passed the verification meets a preset consensus condition, then it is determined that the consensus of the second main block has succeeded.

[0048] Optionally, if the number of sub-blocks on which consensus succeeds in the first partition after the first main block consensus succeeds meets a preset condition, the adjacent sub-blocks after the first main block include the first sub-block on which consensus succeeds in the multiple partitions after the first main block consensus is generated, and the adjacent sub-blocks before the second main block include the last sub-block on which consensus succeeds in the multiple partitions after the first main block consensus is generated.

[0049] Optionally, the preset condition is: after the first main block consensus is successful, the number of sub-blocks on which consensus succeeds or the cumulative number of sub-blocks on which consensus succeeds in the first partition is greater than or equal to a quantity threshold; the quantity threshold is obtained based on the cumulative number of sub-blocks on which consensus succeeds and\or the cumulative number of main blocks on which consensus succeeds in the blockchain.

[0050] Optionally, the consensus module is also used to:

[0051] Broadcasting the first sub-block to the second leader node of the at least one second partition; and obtaining the second sub-block from the second leader node of the at least one second partition.

[0052] Optionally, the consensus module is also used to:

[0053] Generate a first sub-block to be agreed upon; broadcast the first sub-block to be agreed upon to consensus nodes other than the first leader node in the first partition; and perform consensus on the first sub-block according to verification information of the first sub-block to be agreed upon obtained in the first partition.

[0054] Optionally, the first leader node is the only leader node in the first partition; the first leader node is selected based on a polling method.

[0055] Optionally, the consensus module is specifically used for:

[0056] According to the Practical Byzantine Fault Tolerance (PBFT) algorithm, the second main block to be agreed upon based on the first main block to be agreed upon and the second leader node of the at least one second partition participates in the consensus of the second main block in the blockchain network.

[0057] The beneficial effects of the above-mentioned second aspect and each optional device of the second aspect can refer to the beneficial effects of the above-mentioned first aspect and each optional method of the first aspect, and will not be repeated here.

[0058] In a third aspect, the present invention provides a computer device, including a program or an instruction, which, when executed, is used to execute the above-mentioned first aspect and each optional method of the first aspect.

[0059] In a fourth aspect, the present invention provides a storage medium, comprising a program or an instruction, which, when executed, is used to execute the above-mentioned first aspect and each optional method of the first aspect.

[0060] These and other aspects of the present invention will become more apparent from the following description of the embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0061] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0062] Figure 1 A schematic diagram of a process flow corresponding to a consensus method of a blockchain provided by an embodiment of the present invention;

[0063] Figure 2 A schematic diagram of partitioned transaction acquisition in a blockchain consensus method provided by an embodiment of the present invention;

[0064] Figure 3 A schematic diagram of a sub-block structure of a partition in a consensus method of a blockchain provided by an embodiment of the present invention;

[0065] Figure 4 A schematic diagram of the structure of a block header of a partitioned sub-block in a consensus method of a blockchain provided by an embodiment of the present invention;

[0066] Figure 5 A schematic diagram of the specific structure of a block header of a partitioned sub-block in a consensus method of a blockchain provided by an embodiment of the present invention;

[0067] Figure 6A schematic diagram of the overall structure of a block header of a partitioned sub-block in a consensus method of a blockchain provided by an embodiment of the present invention;

[0068] Figure 7 A schematic diagram of the structure of a blockchain in a blockchain consensus method provided by an embodiment of the present invention;

[0069] Figure 8 A schematic diagram of the structure of a main block in a consensus method of a blockchain provided by an embodiment of the present invention;

[0070] Fig. 9 A schematic diagram of the structure of a signature information list in a main block in a consensus method of a blockchain provided by an embodiment of the present invention;

[0071] Fig.10 A schematic diagram of the structure of a consensus device for a blockchain provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0072] In order to make the purpose, technical scheme and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0073] When financial institutions (banking institutions, insurance institutions or securities institutions) conduct business (such as bank loan business, deposit business, etc.), transactions are often conducted through blockchain. Every time a block is generated in the blockchain, consensus is required among the consensus nodes. As more consensus nodes are added to the blockchain, more and more data needs to be transmitted by each consensus node, which will lead to lower efficiency in block generation. This situation does not meet the needs of banks and other financial institutions, and cannot guarantee the efficient operation of various businesses of financial institutions.

[0074] like Figure 1 As shown, a consensus method of a blockchain provided by an embodiment of the present application is applied to a blockchain network including multiple partitions, wherein each partition includes a leader node and a non-leader node. The method can be performed according to the following steps:

[0075] Step 101: Determine a first leader node in a first partition, where the first partition is any partition among the multiple partitions.

[0076] Step 102: A first leader node in a first partition participates in the consensus of a first sub-block in the first partition.

[0077] The consensus nodes of the first sub-block are nodes within the first partition.

[0078] After the first leader node determines that the first sub-block consensus is successful, if the number of sub-blocks that have successfully reached consensus after the first main block consensus is successful or the cumulative number of sub-blocks that have successfully reached consensus in the first partition meets a preset condition, step 103 is executed.

[0079] Step 103: The first leader node generates a first main block to be agreed upon based on the first sub-block and at least one second sub-block of the second partition.

[0080] Step 104: The first leader node broadcasts the first main block to be agreed upon to the at least one second partition, and obtains a second main block to be agreed upon from a second leader node of the at least one second partition.

[0081] Step 105: The first leader node participates in the consensus of the second main block in the blockchain network based on the first main block to be agreed upon and the second main block to be agreed upon of the second leader node of the at least one second partition.

[0082] In steps 101 to 105, the first main block is the latest main block on which the blockchain network currently has a successful consensus, the multiple partitions include the first partition and the at least one second partition, wherein the second sub-block of any second partition is the latest sub-block on which the second partition has a successful consensus, the multiple partitions include the first partition and the at least one second partition, wherein the second main block to be consensused of any second partition is the latest main block generated by the second partition; the consensus nodes of the second main block include the first leader node and the second leader node of the at least one second partition.

[0083] In step 102, it can be performed as follows:

[0084] The first leader node generates a first sub-block to be agreed upon; the first leader node broadcasts the first sub-block to be agreed upon to consensus nodes other than the first leader node in the first partition; the first leader node performs consensus on the first sub-block according to verification information of the first sub-block to be agreed upon obtained in the first partition.

[0085] It should be noted that the consensus of the first sub-block in the first partition can also be achieved through other methods, as long as the consensus nodes involved are nodes in the first partition.

[0086] After step 102, the first leader node may exchange sub-blocks in the following manner:

[0087] The first leader node broadcasts the first sub-block to the second leader node of the at least one second partition; the first leader node obtains the second sub-block from the second leader node of the at least one second partition.

[0088] Correspondingly, the second leader node of any second partition can also send the second sub-block of the second partition to the leader node of any partition other than the second partition in the blockchain network by broadcasting.

[0089] It should be noted that the blockchain network is formed by connecting multiple blockchain nodes, and some of the blockchain nodes are locally connected to form a partition. For example, the blockchain network includes blockchain node 1, blockchain node 2, blockchain node 3, blockchain node 4, blockchain node 5, blockchain node 6, blockchain node 7, blockchain node 8, blockchain node 9, and blockchain node 10. Blockchain node 1, blockchain node 2, and blockchain node 3 form partition 1, blockchain node 4, blockchain node 5, blockchain node 6, and blockchain node 7 form partition 2, and blockchain node 8, blockchain node 9, and blockchain node 10 form partition 3. Each of the multiple partitions can only generate sub-blocks of the partition by internal consensus. When the amount of data of the consensus sub-block meets the preset conditions, consensus can be reached between the partitions to generate the main block. Each of the multiple partitions has both leader nodes and non-leader nodes. In the process of consensus sub-blocks, both leader nodes and non-leader nodes can participate, while in the process of consensus main block, leader nodes must participate, and non-leader nodes may not participate.

[0090] It should be noted that the second main block may be generated after the first main block is generated, or it may be the first main block generated. When the second main block is generated after the first main block is generated, for example, in the first partition, the first main block is main block x, x is a natural number, indicating the sequence number of the main block generation, after the first main block is generated, i sub-blocks are generated, i is a positive integer, and sub-blocks (x, 1), ..., sub-block (x, i) can be generated, then sub-block (x, i) is the first sub-block, and main block x+1 is the second sub-block; similarly, in the second partition, the second sub-block corresponds to the generation order of sub-block (x, i), then the temporary main block in the main block x+1 consensus process is the first main block to be consensus and the second main block to be consensus of the second leader node of the at least one second partition. In addition, the consensus nodes of the sub-blocks can be some nodes in the first partition or all nodes in the first partition, and the consensus nodes of the main block can be the leader node of each partition in the blockchain network or the leader node and non-leader node of each partition in the blockchain network. Among them, the first leader node can be the only leader node in the first partition; the first leader node can be selected in a polling manner, that is, when each partition generates a main block, a leader node can be selected in turn.

[0091] For example, the consensus nodes in the blockchain network are partitioned. There are 8 consensus nodes in the blockchain network (at this time, the consensus nodes of the blockchain network are all the nodes of the blockchain network). The 8 consensus nodes are divided into two partitions A and B, with 4 consensus nodes in each partition; if there are new consensus nodes, they can choose to join the existing partition, or create a new partition.

[0092] Transactions are usually packaged from the client and sent to a partition consensus node in the blockchain network for consensus execution, such as Figure 2 As shown, the existing transaction transaction_1 is sent to the consensus node nodeA, nodeA belongs to partition A, and reaches consensus with other consensus nodes belonging to partition A. The consensus algorithm is PBFT. PBFT (Practical Byzantine Fault Tolerance): consensus algorithm, reaching consensus in scenarios where a few nodes act maliciously (such as forging messages). It uses cryptographic algorithms such as signatures, signature verification, and hashing to ensure tamper-proof, anti-forgery, and non-repudiation during message transmission, and optimizes previous work to reduce the complexity of the Byzantine fault tolerance algorithm from exponential to polynomial level. In a system composed of (3*f+1) nodes, as long as no less than (2*f+1) non-malicious nodes work normally, the system can reach consensus, and f is a positive integer.

[0093] Specifically, the process of packaging transactions at each consensus node can be as follows: Each consensus node maintains a transaction pool, which contains two lists, one of which is the packaged transaction list of the entire network, PackagedTrList, and the other is the transaction list to be packaged in the current partition, WaitingTrList. After transaction transaction_1 is submitted to node nodeA, the following steps will be executed:

[0094] Determine whether transaction_1 is in PackagedTrList. If it is, discard the current transaction. If it is not, store transaction_1 in WaitingTrList of nodeA and wait for packaging. Package transaction_1 and broadcast it across the entire network. The nodes that receive transaction_1 store the current transaction_1 in the PackagedTrList of their respective nodes.

[0095] For example, when consensus sub-blocks are being generated in the current partition A, if the consensus adopts the PBFT algorithm, the consensus process can be divided into three stages for each consensus node, as follows:

[0096] Pre-prepare phase: responsible for executing sub-blocks, generating signature packages, and broadcasting the signature packages to other consensus nodes in partition A.

[0097] Prepare phase: responsible for collecting signature packages. After a node collects 2*f+1 signature packages, it indicates that it has reached the state where it can submit sub-blocks and starts broadcasting confirmation packages.

[0098] Consensus phase: responsible for collecting Commit packages. After a node collects 2*f+1 Commit packages, it directly submits the latest sub-block cached locally to the local storage.

[0099] The sub-block structure can be specifically as follows Figure 3 As shown, the sub-block contains the block header, transaction details, block header hash, signature information, and transaction receipt list. The block header hash of the sub-block can be calculated as: the hash value after the recursive length prefix (RLP) encoding of the block header information. RLP encoding is an encoding rule that can be used to encode arbitrarily nested binary array data. The result of RLP encoding is also a binary sequence, and RLP encoding can serialize / deserialize data.

[0100] The block header of the sub-block contains information such as the height of the sub-block, which can be specifically Figure 4As shown. If the current main block height is 0 (the height of the main block can represent the generation sequence of the main block, such as starting from 0, main block 0 is the first generated main block), then the transaction is generated after the consensus of the nodes of partition A as partition A block (0_1), the height is marked as 0_1, and the block header of this sub-block contains the hash value of main block 0. The block header structure of sub-block (0_1) of partition A is as follows: Figure 5 shown.

[0101] The transaction root hash value is the root hash value of the transaction tree of the subblock (0_1) of partition A, which is obtained by constructing a Merkle tree based on the transaction; the receipt root hash value is the root hash value of the receipt tree of the current block, which is obtained by constructing a Merkle tree based on the receipt. For the transaction in the block 0_1 of partition A above, the calculation steps of the root hash value of the transaction tree and the root hash of the receipt tree can be as follows:

[0102] 1. Encode the transaction subscript in RLP and concatenate it with the transaction hash as a leaf node.

[0103] 2. Divide the node elements (e.g., for 4 transactions, n is 2) into groups of n, concatenate them together to calculate the hash value, and use it as the node elements of the previous layer.

[0104] 3. Repeat step 2 until there is only one element, that is, the root hash is obtained and the calculation process ends.

[0105] The overall structure of the sub-block (0_1) of partition A is as follows Figure 6 shown.

[0106] For any consensus node of partition A, after the consensus node obtains the sub-block (such as sub-block (0_1)), it broadcasts the sub-block in partition A. Similarly, when multiple transactions are sent to their respective consensus nodes, the partition where the current consensus node is located is selected for packaging consensus. After completion, a sub-block is generated and added to the current blockchain. When the number of sub-blocks meets the preset conditions, the main block can be generated. Optionally, the preset condition is: the number of sub-blocks that have successfully reached consensus in the first partition after the first main block consensus is successful or the cumulative number of sub-blocks that have successfully reached consensus is greater than or equal to the number threshold; the number threshold is obtained based on the cumulative number of sub-blocks that have successfully reached consensus on the blockchain and\or the cumulative number of main blocks that have successfully reached consensus on the blockchain.

[0107] For example, in the first partition, when the number of sub-blocks that have successfully reached consensus after the first main block consensus is greater than or equal to the threshold (such as 3), the transaction is stopped from being packaged, and the whole network consensus is started to generate the main block. The rules for the construction of the main block can be agreed upon. When the number of sub-blocks that have successfully reached consensus after the first main block consensus is greater than or equal to 3, the partition generates a sub-block at a certain time interval t, and a main block is constructed every 3*t. It can also be set according to a certain sequence.

[0108] The quantity threshold is obtained based on the cumulative number of sub-blocks and / or main blocks of the blockchain that have successfully reached consensus, such as being negatively correlated with the cumulative number of sub-blocks and / or main blocks of the blockchain that have successfully reached consensus. The quantity threshold can also be changed according to a preset rule, such as a 3, 2 cycle, that is, if the current quantity threshold is 3, the next quantity threshold is 2.

[0109] The consensus process of the main block is described in detail below:

[0110] It should be noted that the nodes in each partition can obtain the leader node responsible for the main block consensus of the entire network through the following formula:

[0111] leader_index=blockNumber%node_num;

[0112] Where blockNumber is the current main block height, node_num is the number of nodes in the current partition, and leader_index is the partition node index. The index is the number of each node and increases from 0. For example, if there are four nodes in partition A, namely nodeA, nodeB, nodeC, and nodeD, the node indexes are 0, 1, 2, and 3 respectively, and the node_num of partition A is 4.

[0113] For example, if there are five nodes in partition B, namely nodeE, nodeF, nodeG, nodeH, and nodeI, the node indexes are 0, 1, 2, 3, and 4 respectively, and the node_num of partition B is 5.

[0114] It should be noted that, in a possible scenario, if the number of sub-blocks on which the first partition successfully reaches consensus after the first main block consensus succeeds meets a preset condition, then the adjacent sub-blocks after the first main block include the first sub-block on which the multiple partitions successfully reach consensus after the first main block consensus is generated, and the adjacent sub-blocks before the second main block include the last sub-block on which the multiple partitions successfully reach consensus after the first main block consensus is generated.

[0115] Therefore, the specific structure of the blockchain can be as follows Figure 7As shown. Among them, partition A block (0_1), partition A block (0_2), partition A block (0_3), partition A block (1_1), partition B block (0_1), partition B block (0_2), partition B block (0_3), partition B block (1_1) are sub-blocks, and main block (height 0) and main block (height 1) are main blocks. Obviously, if the main block (height 0) is the first main block, and partition A block (0_3) is the first sub-block, then partition B block (0_3) is the second sub-block, and the main block (height 1) is the second main block.

[0116] The construction process of the main block of the entire network is as follows:

[0117] When the current main block height is 0, after calculation by the above formula, the leader node of partition A is nodeA, and the leader node of partition B is nodeE; the leader node nodeA of partition A broadcasts the sub-block (0_3) of the current partition A to the entire network, and the leader node nodeE of partition B broadcasts the sub-block (0_3) of the current partition B to the entire network, and the leader node list {nodeA, nodeE} can be obtained. When the leader nodes nodeA and nodeE each collect the information of the sub-block (0_3) of each partition, they begin to pack the sub-blocks of these partitions and generate the main block Main_Block-1 respectively.

[0118] Optionally, the verification content of the second main block includes at least one item from a block hash list, a transaction root hash, a receipt root hash, and a signature information list.

[0119] The block hash list of the second main block is obtained based on the block hash of the first sub-block and the block hash of the second sub-block of the at least one second partition; the transaction root hash of the second main block is obtained based on the transaction root hash of the first sub-block and the transaction root hash of the second sub-block of the at least one second partition; the receipt root hash of the second main block is obtained based on the receipt root hash of the first sub-block and the receipt root hash of the second sub-block of the at least one second partition; the signature information list of the second main block is obtained based on the signature of the first leader node and the signature of the second leader node of the at least one second partition.

[0120] Optionally, the second main block may also include only the hash of one sub-block.

[0121] Specifically, the structure of the main block is as follows Figure 8 shown.

[0122] The main block Main_Block-1 contains the block header (height and other information), the hash list of sub-blocks in each partition part_block_hash_list, the hash value of the main block, the transaction root hash and the receipt root hash information. Among them, part_block_hash_list is the hash set of the partition block (0_3) in the network. For example, the block hash of block 0_3 of partition A is pre_HA, and the hash of block 0_3 of partition B is pre_HB, then part_block_hash_list stores {pre_HA, pre_HB...}.

[0123] The block header of the main block Main_Block-1 contains the current block hash value, marked as current_block_hash, which is calculated by performing a hash operation on part_block_hash_list.

[0124] current_block_hash=hash(pre_HA+pre_HB);

[0125] The transaction root and receipt root hash in the main block Main_Block-1 are calculated from the transaction root and receipt root hash of all partition blocks (0_3), and the calculation method is as follows:

[0126] current_tran_hash=hash(pre_tranA+pre_tranB);

[0127] current_recip_hash=hash(pre_recipA+pre_recipB).

[0128] The main block Main_Block-1 also includes the signature information of the node private key on the current main block. The first leader node will broadcast the packaged Main_Block-1 in the partition leader node of the blockchain network.

[0129] Step 105 may be specifically as follows:

[0130] For any second partition, if the first leader node determines that the verification content of the first main block to be agreed upon is the same as the verification content of the second main block to be agreed upon of the second partition, then it is determined that the second main block to be agreed upon of the second partition has passed the verification; if the first leader node determines that the number of second main blocks to be agreed upon that have passed the verification meets the preset consensus condition, then it is determined that the consensus of the second main block has succeeded.

[0131] Specifically:

[0132] The leader nodes of each partition in the blockchain network verify the received main block Main_Block-1. The verification process includes verifying the signature of the main block to see if it is issued by the leader node of the partition in the blockchain network. Each leader node saves the public keys of other consensus nodes in the blockchain network and uses the public keys to verify the signature in the received main block Main_Block-1.

[0133] Verify whether the hash of the main block is the same as the hash of the main block received from other leader nodes. If they are the same, it means that the information of the main block is correct. For example, if the hash value of Main_Block-1 received from the leader node nodeA of partition A is M_HA, and the hash value of Main_Block-1 calculated by the current leader node is M_HB, if M_HA=M_HB, it means that the hash verification of the main block has passed.

[0134] The verified signature information will be added to the signature information list in Main_Block-1.

[0135] As in the above example, the signature of the leader node nodeA of partition A for Main_Block-1 is sig_A, and the signature of the leader node nodeE of partition B for Main_Block-1 is sig_B. The signature information list of the current consensus main block Main_Block-1 is as follows: Fig. 9 shown.

[0136] The number of partition leader nodes participating in the full network consensus is marked as L. When the partition leader node verifies L / 2 (rounded down) + 1 Main_Block-1 main blocks, it will save the main block Main_Block-1 to the local blockchain and broadcast the main block information within each partition. For example, there are two partitions in the current blockchain network, partition A and partition B, and the number of partition leader nodes participating in the full network consensus in the network is 2. When the partition leader node verifies 2 Main_Block-1 main blocks, it will put the main block on the chain. Similarly, if the number of partition leader nodes in the blockchain network is 3, the number of blocks to be verified is: 3 / 2+1=2. The main block Main_Block-1 consensus is completed, and the next round of partition transaction consensus blocks (1_1, 1_2, 1_3 blocks) begins.

[0137] It should be noted that in the method of step 101 to step 105, the consensus nodes in the network are divided by consensus in the partition, and a transaction is consensused in the specified partition. The partition generates sub-blocks. When a certain height is reached, a consensus of the entire blockchain network is performed, and a block is constructed for each partition to generate a main block. The partition parallel consensus can solve the problem of increasing the number of consensus nodes in the blockchain network and improving the efficiency of network consensus block generation; at the same time, when dealing with high-concurrency scenarios of massive transactions, the consensus node expansion method can be used to improve the efficiency of network block generation and improve network throughput.

[0138] The above-mentioned partition consensus method can improve the consensus efficiency of the entire network (the entire blockchain network) while increasing the concurrency, solving the problem of low consensus efficiency when the number of consensus nodes increases. The entire network consensus is carried out at regular intervals. The entire network consensus does not involve the execution and packaging of transactions. It only reaches consensus on the hash value of the sub-block of the previous partition, which is time-consuming and has low network overhead. The construction of the packaged transaction pool PackagedTrList and the waiting transaction pool WaitingTrList can improve the fault tolerance of transaction consensus and effectively prevent duplicate transactions.

[0139] like Fig.10 As shown, the present invention provides a consensus device of a blockchain, which is applied to a blockchain network including multiple partitions, wherein each partition includes a leader node and a non-leader node, and the device is a first leader node of the first partition, and the device includes:

[0140] A determination module 1001 is used to determine a first leader node in a first partition, wherein the first partition is any partition among the multiple partitions;

[0141] A consensus module 1002 is used to participate in the consensus of the first sub-block in the first partition; the consensus node of the first sub-block is a node in the first partition;

[0142] The consensus module 1002 is used to generate a first main block to be consensused according to the first sub-block and at least one second sub-block of the second partition after the consensus of the first main block is successful through the determination module 1001. If the number of sub-blocks that have successfully reached consensus or the cumulative number of sub-blocks that have successfully reached consensus in the first partition after the consensus of the first main block is successful or the number of sub-blocks that have successfully reached consensus in the first partition determines through the determination module 1001 to meet a preset condition, the first main block is the latest main block that has successfully reached consensus in the current blockchain network, the multiple partitions include the first partition and the at least one second partition, and the second sub-block of any second partition is the latest sub-block that has successfully reached consensus in the second partition;

[0143] The consensus module 1002 is further used to broadcast the first main block to be agreed upon to the at least one second partition, and obtain the second main block to be agreed upon from the second leader node of the at least one second partition; wherein the second main block to be agreed upon of any second partition is the latest main block generated by the second partition; and

[0144] The second main block to be agreed upon based on the first main block to be agreed upon and the second leader node of the at least one second partition participates in the consensus of the second main block in the blockchain network; the consensus nodes of the second main block include the first leader node and the second leader node of the at least one second partition.

[0145] Optionally, the verification content of the second main block includes at least one item in a block hash list, a transaction root hash, a receipt root hash, and a signature information list;

[0146] The block hash list of the second main block is obtained according to the block hash of the first sub-block and the block hash of the second sub-block of the at least one second partition;

[0147] The transaction root hash of the second main block is obtained according to the transaction root hash of the first sub-block and the transaction root hash of the second sub-block of the at least one second partition;

[0148] The receipt root hash of the second main block is obtained according to the receipt root hash of the first sub-block and the receipt root hash of the second sub-block of the at least one second partition;

[0149] The signature information list of the second main block is obtained according to the signature of the first leader node and the signature of the second leader node of the at least one second partition.

[0150] Optionally, the consensus module 1002 is specifically used to: for any second partition, if it is determined that the verification content of the first main block to be consensus is the same as the verification content of the second main block to be consensus of the second partition, then determine that the second main block to be consensus of the second partition has passed the verification; if it is determined that the number of second main blocks to be consensus that have passed the verification meets a preset consensus condition, then determine that the consensus of the second main block is successful.

[0151] Optionally, if the number of sub-blocks on which consensus succeeds in the first partition after the first main block consensus succeeds meets a preset condition, the adjacent sub-blocks after the first main block include the first sub-block on which consensus succeeds in the multiple partitions after the first main block consensus is generated, and the adjacent sub-blocks before the second main block include the last sub-block on which consensus succeeds in the multiple partitions after the first main block consensus is generated.

[0152] Optionally, the preset condition is: after the first main block consensus is successful, the number of sub-blocks on which consensus succeeds or the cumulative number of sub-blocks on which consensus succeeds in the first partition is greater than or equal to a quantity threshold; the quantity threshold is obtained based on the cumulative number of sub-blocks on which consensus succeeds and\or the cumulative number of main blocks on which consensus succeeds in the blockchain.

[0153] Optionally, the consensus module 1002 is further used for:

[0154] Broadcasting the first sub-block to the second leader node of the at least one second partition; and obtaining the second sub-block from the second leader node of the at least one second partition.

[0155] Optionally, the consensus module 1002 is further used for:

[0156] Generate a first sub-block to be agreed upon; broadcast the first sub-block to be agreed upon to consensus nodes other than the first leader node in the first partition; and perform consensus on the first sub-block according to verification information of the first sub-block to be agreed upon obtained in the first partition.

[0157] Optionally, the first leader node is the only leader node in the first partition; the first leader node is selected based on a polling method.

[0158] Optionally, the consensus module 1002 is specifically used for:

[0159] According to the Practical Byzantine Fault Tolerance (PBFT) algorithm, the second main block to be agreed upon based on the first main block to be agreed upon and the second leader node of the at least one second partition participates in the consensus of the second main block in the blockchain network.

[0160] Based on the same inventive concept, an embodiment of the present invention further provides a computer device, including a program or instructions. When the program or instructions are executed, the consensus method of the blockchain provided in the embodiment of the present invention and any optional method are executed.

[0161] Based on the same inventive concept, an embodiment of the present invention also provides a computer-readable storage medium, including a program or instructions. When the program or instructions are executed, the consensus method of the blockchain provided in the embodiment of the present invention and any optional method are executed.

[0162] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention 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.

[0163] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0164] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0165] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0166] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.

[0167] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.

Claims

1. A consensus method for blockchain, characterized in that: Applied to a blockchain network comprising a plurality of partitions, wherein each partition comprises a leader node and a non-leader node, the method comprises: Determining a first leader node in a first partition, where the first partition is any partition among the plurality of partitions; The first leader node participates in the consensus of the first sub-block in the first partition; the consensus node of the first sub-block is a node in the first partition; After the first leader node determines that the first sub-block consensus is successful, if the number of sub-blocks that have successfully reached consensus in the first partition after the first main block consensus is successful meets a preset condition, the first leader node generates a first main block to be reached based on the first sub-block and the second sub-block of at least one second partition; the first main block is the latest main block that has successfully reached consensus in the current blockchain network, the multiple partitions include the first partition and the at least one second partition, and the second sub-block of any second partition is the latest sub-block that has successfully reached consensus in the second partition; The first leader node broadcasts the first main block to be agreed upon to the at least one second partition, and obtains a second main block to be agreed upon from a second leader node of the at least one second partition; wherein the second main block to be agreed upon of any second partition is the latest main block generated by the second partition; The first leader node participates in the consensus of the second main block in the blockchain network based on the first main block to be agreed upon and the second main block to be agreed upon of the second leader node of the at least one second partition; the consensus nodes of the second main block include the first leader node and the second leader node of the at least one second partition; The first leader node participates in the consensus of the second main block in the blockchain network based on the first main block to be agreed upon and the second main block to be agreed upon of the second leader node of the at least one second partition, including: For any second partition, if the first leader node determines that the verification content of the first main block to be agreed upon is the same as the verification content of the second main block to be agreed upon of the second partition, then it is determined that the verification of the second main block to be agreed upon of the second partition has passed; If the first leader node determines that the number of the second main blocks to be agreed upon that have passed verification meets the preset consensus condition, it is determined that the consensus of the second main block is successful.

2. The method according to claim 1, characterized in that The verification content of the second main block includes at least one item in the block hash list, the transaction root hash, the receipt root hash and the signature information list; The block hash list of the second main block is obtained according to the block hash of the first sub-block and the block hash of the second sub-block of the at least one second partition; The transaction root hash of the second main block is obtained according to the transaction root hash of the first sub-block and the transaction root hash of the second sub-block of the at least one second partition; The receipt root hash of the second main block is obtained according to the receipt root hash of the first sub-block and the receipt root hash of the second sub-block of the at least one second partition; The signature information list of the second main block is obtained according to the signature of the first leader node and the signature of the second leader node of the at least one second partition.

3. The method according to claim 1, characterized in that If the number of sub-blocks on which the first partition has successfully reached consensus after the first main block has successfully reached consensus meets a preset condition, the adjacent sub-blocks after the first main block include the first sub-block on which the multiple partitions have successfully reached consensus after the first main block has reached consensus, and the adjacent sub-blocks before the second main block include the last sub-block on which the multiple partitions have successfully reached consensus after the first main block has reached consensus.

4. The method according to claim 1, characterized in that The preset condition is: after the first main block consensus succeeds, the number of sub-blocks of the first partition that succeed in consensus is greater than or equal to the number threshold; The quantity threshold is obtained according to the cumulative number of sub-blocks on which consensus has been successfully reached and / or the cumulative number of main blocks on which consensus has been successfully reached.

5. The method according to any one of claims 1 to 4, characterized in that: Also includes: The first leader node broadcasts the first sub-block to a second leader node of the at least one second partition; The first leader node obtains a second sub-block from a second leader node of the at least one second partition.

6. The method according to any one of claims 1 to 4, characterized in that: The first leader node participates in the consensus of the first sub-block in the first partition, including: The first leader node generates a first sub-block to be agreed upon; The first leader node broadcasts the first sub-block to be agreed upon to consensus nodes other than the first leader node in the first partition; The first leader node performs consensus on the first sub-block according to the verification information of the first sub-block to be consensus obtained in the first partition.

7. The method according to any one of claims 1 to 4, characterized in that: The first leader node is the only leader node in the first partition; the first leader node is selected according to a polling method.

8. The method according to any one of claims 1 to 4, characterized in that: The first leader node participates in the consensus of the second main block in the blockchain network based on the first main block to be agreed upon and the second main block to be agreed upon of the second leader node of the at least one second partition, including: The first leader node participates in the consensus of the second main block in the blockchain network based on the first main block to be agreed upon and the second main block to be agreed upon of the second leader node of the at least one second partition in accordance with the Practical Byzantine Fault Tolerance (PBFT) algorithm.

9. A consensus device for blockchain, characterized in that: Applied to a blockchain network including multiple partitions, wherein each partition includes a leader node and a non-leader node, the device is a first leader node of a first partition, and the device includes: A determination module, configured to determine a first leader node in a first partition, wherein the first partition is any partition among the plurality of partitions; A consensus module, used to participate in the consensus of the first sub-block in the first partition; the consensus node of the first sub-block is a node in the first partition; The consensus module is used to generate a first main block to be consensused according to the first sub-block and at least one second sub-block of the second partition after the consensus of the first main block succeeds, if the number of sub-blocks that succeed in consensus in the first partition after the consensus of the first main block succeeds meets a preset condition determined by the determination module through the determination module; the first main block is the latest main block that succeeds in consensus in the current blockchain network, the multiple partitions include the first partition and the at least one second partition, and the second sub-block of any second partition is the latest sub-block that succeeds in consensus in the second partition; The consensus module is further used to broadcast the first main block to be agreed upon to the at least one second partition, and obtain the second main block to be agreed upon from the second leader node of the at least one second partition; wherein the second main block to be agreed upon of any second partition is the latest main block generated by the second partition; and to participate in the consensus of the second main block in the blockchain network based on the first main block to be agreed upon and the second main block to be agreed upon of the second leader node of the at least one second partition; the consensus node of the second main block includes the first leader node and the second leader node of the at least one second partition; and specifically used to, for any second partition, if the first leader node determines that the verification content of the first main block to be agreed upon is the same as the verification content of the second main block to be agreed upon of the second partition, then determine that the second main block to be agreed upon of the second partition has passed the verification; if the first leader node determines that the number of the second main blocks to be agreed upon that have passed the verification meets the preset consensus condition, then determine that the consensus of the second main block is successful.