A consensus method and device for blockchain system
By combining Raft and PBFT consensus algorithms in the blockchain system, electing master nodes and reducing participating nodes solves the problem of complexity and scalability of the PBFT algorithm, achieving a more efficient consensus process and a larger-scale blockchain network. .
Patent Information
- Application Number
- CN202111138341.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-27
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2041-09-27
AI Technical Summary
The network complexity of the PBFT consensus algorithm in the existing blockchain system is proportional to the square of the node size, resulting in a limited blockchain network scale and a large amount of calculations in the consensus process, which limits the scalability of the blockchain system.
Combining the Raft consensus algorithm and the PBFT consensus algorithm, by electing master nodes in the node organization and reducing the number of nodes participating in the PBFT consensus algorithm, the calculation amount and network complexity of the consensus process are reduced, and the scale and scalability of the blockchain network are improved.
It effectively reduces the calculation amount and network complexity of the consensus process in the blockchain system, improves the scale and scalability of the blockchain network, and ensures data consistency and security.
Smart Images

Figure CN113837758B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of financial technology (Fintech), and in particular to a consensus method and device for a blockchain system. Background Art
[0002] With the development of computer technology, more and more technologies (such as blockchain, cloud computing or big data) are being applied in the financial field. The traditional financial industry is gradually transforming into financial technology, and big data technology is no exception. However, due to the security and real-time requirements of the financial and payment industries, higher requirements are also placed on the consensus of the blockchain system in big data technology.
[0003] In the existing technology, the blockchain system is a decentralized, open, distributed system that can be used to register and issue digital assets, property rights certificates, points, etc., and to transfer, pay, and trade in a peer-to-peer manner. Compared with the traditional centralized ledger system, the blockchain system has the advantages of being completely open, tamper-proof, and preventing multiple payments, and does not rely on any trusted third party.
[0004] Due to the high network latency in peer-to-peer networks, the order of transactions observed by each node is often not completely consistent. Therefore, the blockchain system needs to design a mechanism to reach a consensus on the order of transactions that occurred at about the same time. This algorithm that reaches a consensus on the order of transactions within a time window is called a "consensus mechanism."
[0005] At present, the PBFT (Practical Byzantine Fault Tolerance) consensus algorithm is adopted by various blockchain systems because of its high security, ability to solve the Byzantine problem, high throughput, transaction confirmation latency as low as seconds, and eventual consistency guarantee. It is suitable for blockchain systems as a safe and reliable consensus algorithm.
[0006] However, the network complexity of the PBFT consensus algorithm is proportional to the square of the node size (for example, the network complexity is the square of the number of nodes), the supported blockchain network size is limited, and the amount of computation required in the consensus process is large, which limits the scalability of the blockchain system. Summary of the invention
[0007] The embodiments of the present invention provide a consensus method and device for a blockchain system, which are used to reduce the computational complexity of the consensus process in the blockchain system, reduce the complexity of the PBFT consensus algorithm network, increase the supportable blockchain network scale, and improve the scalability of the blockchain system.
[0008] In a first aspect, an embodiment of the present invention provides a consensus method for a blockchain system, wherein the blockchain system includes a plurality of node organizations, each of which has a plurality of nodes; the method includes:
[0009] For at least one node organization, a first master node in the node organization generates an election certificate and sends it to a first election node in the node organization; the first master node is determined by each node in the node organization based on the Raft consensus algorithm;
[0010] The first master node generates an election certificate transaction based on the received multiple election certificate signatures and the election certificate; the election certificate signature is obtained by signing the election certificate after the first election node determines that the election certificate meets the first verification requirement;
[0011] The first master node serves as a PBFT consensus node of the blockchain system after the blockchain system determines that the election proof transaction consensus is successful based on the PBFT consensus algorithm.
[0012] In the above technical solution, the first master node is equivalent to the master node Leader voted by each election node in the node organization when the blockchain system is initialized; by selecting the consensus nodes participating in the PBFT consensus algorithm in the node organization of the blockchain system, not all nodes in the blockchain system are used as consensus nodes participating in the PBFT consensus algorithm, thereby reducing the number of consensus nodes participating in the PBFT consensus algorithm, thereby reducing the amount of computation in the consensus process in the blockchain system, reducing the complexity of the PBFT consensus algorithm network, increasing the supportable blockchain network scale, and improving the scalability of the blockchain system; and the nodes participating in the PBFT consensus algorithm ensure data consistency in the blockchain system, because the consensus nodes participating in the PBFT consensus algorithm are the master nodes selected in the node organization according to the Raft consensus algorithm, and the master nodes are used to send block consensus results to the election nodes in the node organization, thereby ensuring data consistency of each node in the node organization.
[0013] Optionally, after serving as a PBFT consensus node of the blockchain system, it also includes:
[0014] Writing the identifier of the first master node into the system consensus node record;
[0015] The first master node receives a first information packet to be agreed upon;
[0016] After the first master node determines that the sender of the first information packet to be agreed upon is a consensus node in the system consensus node record, consensus is performed on the first information packet to be agreed upon based on the PBFT consensus algorithm.
[0017] In the above technical solution, after the first master node serves as the PBFT consensus node of the blockchain system, it is equivalent to that the first master node has been verified by each node of the blockchain system, ensuring the security of the first master node. Each node writes the first master node into the local system consensus node record of each node, so that when the first master node is not switched, it is only necessary to determine that the first master node is the consensus node in the system consensus node record, and then use the first master node as the PBFT consensus node of the blockchain system, avoiding the first master node repeatedly generating election certificates and other operations each time consensus is reached on a block to be agreed upon, thereby reducing computing overhead.
[0018] Optionally, the first master node in the node organization generates an election certificate, including:
[0019] The first master node in the node mechanism determines the sequence number of the block with the largest block height in the blockchain system;
[0020] The first master node generates a first verification sequence number based on the sequence number of the block with the largest block height;
[0021] The first master node signs the first verification serial number and the identifier of the first master node to obtain a first election signature;
[0022] The first master node generates the election certificate according to the first verification serial number, the identifier of the first master node and the first election signature;
[0023] The first verification requirement includes:
[0024] The node identification in the election certificate is consistent with the identification of the master node in the node organization;
[0025] The verification sequence number in the election certificate and the sequence number of the block with the largest block height meet the preset conditions;
[0026] The election signature in the said election certificate is valid.
[0027] In the above technical case, the first verification serial number is used to ensure that each election certificate is unique, preventing malicious nodes from replaying the election certificate.
[0028] Optionally, the first master node generates an election certificate transaction based on the received multiple election certificate signatures and the election certificate, including:
[0029] When the first master node determines that the number of received election proof signatures is not less than half of the number of nodes in the node organization, the first master node synthesizes the received election proof signatures into a signature list;
[0030] The first master node generates an election proof transaction based on the signature list and the election proof.
[0031] In the above technical solution, the signature list is generated by the first master node when it determines that the number of received election proof signatures is not less than half of the number of nodes in the node organization. Based on the minority obeys majority feature of the Raft consensus algorithm, the security and accuracy of the first master node in the node organization is guaranteed.
[0032] Optionally, determining that the election certification transaction consensus is successful based on the PBFT consensus algorithm includes:
[0033] Determining that the verification sequence number of the election certificate in the election certificate transaction and the sequence number of the block with the largest block height meet a preset condition;
[0034] Determining that the number of election proof signatures in the signature list in the election proof transaction is not less than half the number of nodes in the node authority;
[0035] Determine that each election certification signature in the signature list in the election certification transaction is valid.
[0036] Optionally, the method further includes:
[0037] After the first master node of the node organization rotates to the second master node, the second master node generates a switching certificate and sends it to the second election node in the node organization; the second master node is determined by each node in the node organization based on the Raft consensus algorithm; the second election node is each node in the node organization except the second master node;
[0038] The second master node generates switching proof information based on the received multiple switching proof signatures and the switching proof; the switching proof signature is obtained by signing the switching proof after the second election node determines that the switching proof meets the first verification requirement;
[0039] If the switching proof information meets the second verification requirement, the second master node reaches a consensus on the second message packet to be agreed upon based on the PBFT consensus algorithm in the blockchain system.
[0040] In the above technical solution, the second master node is equivalent to the new master node Leader that is rotated after an abnormality occurs in the first master node; after the master node in the node organization is switched, switching proof information is generated and sent to each consensus node in the block system, so that each node in the blockchain system can determine that the second master node after the switch can be used as a consensus node for consensus on the second consensus message packet using the PBFT consensus algorithm, thereby improving the flexibility of the technical solution of the present invention.
[0041] Optionally, the method further includes:
[0042] After the first master node of the node organization rotates to the second master node, the second master node generates a switching certificate and sends it to the second election node in the node organization; the second master node is determined by each node in the node organization based on the Raft consensus algorithm; the second election node is each node in the node organization except the second master node;
[0043] The second master node generates a handover proof transaction based on the received multiple handover proof signatures and the handover proof; the handover proof signature is obtained by signing the handover proof after the second election node determines that the handover proof meets the first verification requirement;
[0044] After the blockchain system determines that the switching proof transaction consensus is successful based on the PBFT consensus algorithm, the second master node serves as the PBFT consensus node of the blockchain system.
[0045] In the above technical solution, for the second master node after switching, a switching proof transaction is generated based on the received multiple switching proof signatures and the switching proof, which is equivalent to taking the switching proof information as a transaction, and consensus is reached by each node in the blockchain system. If the consensus is successful, the second master node is written into the local system consensus node record of each node, so as to avoid sending switching proof information every time participating in the PBFT consensus, prevent repeated consensus on the second master node after switching, reduce computing resources and the complexity of consensus verification, and improve consensus efficiency.
[0046] Optionally, the second master node generates a switching certificate, including:
[0047] The second master node determines the sequence number of the block with the largest block height in the blockchain system, and generates a second verification sequence number based on the sequence number of the block with the largest block height;
[0048] The second master node signs the second verification serial number and the identifier of the second master node to obtain a second election signature;
[0049] The second master node generates a switching certificate according to the second verification serial number, the identifier of the first master node, the identifier of the second master node, and the second election signature;
[0050] The second verification requirement includes:
[0051] The identifier of the first master node in the switching proof information is recorded in the system consensus node record;
[0052] The second verification sequence number in the switching proof information and the sequence number of the block with the largest block height meet a preset condition;
[0053] The second election signature of the switching certificate in the switching certificate information is valid;
[0054] The number of handover proof signatures in the signature list in the handover proof information is not less than half of the number of nodes in the node organization;
[0055] Each switching proof signature in the signature list in the switching proof information is valid.
[0056] In a second aspect, an embodiment of the present invention provides a consensus device of a blockchain system, wherein the blockchain system includes a plurality of node organizations, each of which has a plurality of nodes; the device includes:
[0057] A generation module, for generating, for at least one node organization, an election certificate of a first master node in the node organization and sending the certificate to a first election node in the node organization; the first master node is determined by each node in the node organization based on a Raft consensus algorithm;
[0058] A receiving module, configured to receive a plurality of election certificate signatures and the election certificate;
[0059] a processing module, configured to generate an election certificate transaction based on the received multiple election certificate signatures and the election certificate; the election certificate signature is obtained by signing the election certificate after the first election node determines that the election certificate meets the first verification requirement;
[0060] After the blockchain system determines that the election certification transaction consensus is successful based on the PBFT consensus algorithm, it serves as the PBFT consensus node of the blockchain system.
[0061] Optionally, the processing module is further used for:
[0062] After serving as the PBFT consensus node of the blockchain system, the identifier of the first master node is written into the system consensus node record;
[0063] Controlling the receiving module to receive the first consensus-to-be information packet;
[0064] After determining that the sender of the first information packet to be agreed upon is a consensus node in the system consensus node record, consensus is performed on the first information packet to be agreed upon based on the PBFT consensus algorithm.
[0065] Optionally, the generating module is specifically used for:
[0066] Determine the serial number of the block with the largest block height in the blockchain system;
[0067] Generate a first verification sequence number based on the sequence number of the block with the largest block height;
[0068] Signing the first verification serial number and the identifier of the first master node to obtain a first election signature;
[0069] generating the election certificate according to the first verification serial number, the identifier of the first master node and the first election signature;
[0070] The first verification requirement includes:
[0071] The node identification in the election certificate is consistent with the identification of the master node in the node organization;
[0072] The verification sequence number in the election certificate and the sequence number of the block with the largest block height meet the preset conditions;
[0073] The election signature in the said election certificate is valid.
[0074] Optionally, the processing module is specifically used for:
[0075] When it is determined that the number of received election proof signatures is not less than half of the number of nodes in the node organization, synthesizing the received election proof signatures into a signature list;
[0076] Based on the signature list and the election proof, a proof-of-election transaction is generated.
[0077] Optionally, determining that the election certification transaction consensus is successful based on the PBFT consensus algorithm includes:
[0078] Determining that the verification sequence number of the election certificate in the election certificate transaction and the sequence number of the block with the largest block height meet a preset condition;
[0079] Determining that the number of election proof signatures in the signature list in the election proof transaction is not less than half the number of nodes in the node authority;
[0080] Determine that each election certification signature in the signature list in the election certification transaction is valid.
[0081] Optionally, also include:
[0082] After the first master node of the node mechanism rotates to the second master node, the generating module is further used for:
[0083] Generate a handover certificate and send it to a second election node in the node organization; the second master node is determined by each node in the node organization based on the Raft consensus algorithm; the second election node is each node in the node organization except the second master node;
[0084] The processing module is also used for:
[0085] Generate switching proof information based on the received multiple switching proof signatures and the switching proof; the switching proof signature is obtained by signing the switching proof after the second election node determines that the switching proof meets the first verification requirement;
[0086] If the switching proof information meets the second verification requirement, the second master node reaches a consensus on the second message packet to be agreed upon based on the PBFT consensus algorithm in the blockchain system.
[0087] Optionally, also include:
[0088] After the first master node of the node mechanism rotates to the second master node, the generation module is used to:
[0089] Generate a handover certificate and send it to a second election node in the node organization; the second master node is determined by each node in the node organization based on the Raft consensus algorithm; the second election node is each node in the node organization except the second master node;
[0090] The processing module is used for:
[0091] Based on the received multiple handover proof signatures and the handover proof, a handover proof transaction is generated; the handover proof signature is obtained by signing the handover proof after the second election node determines that the handover proof meets the first verification requirement;
[0092] After the blockchain system determines that the switching proof transaction consensus is successful based on the PBFT consensus algorithm, it serves as the PBFT consensus node of the blockchain system.
[0093] The generation module is specifically used for:
[0094] Determine the sequence number of the block with the largest block height in the blockchain system, and generate a second verification sequence number based on the sequence number of the block with the largest block height;
[0095] Signing the second verification serial number and the identifier of the second master node to obtain a second election signature;
[0096] Generate a switching certificate according to the second verification serial number, the identifier of the first master node, the identifier of the second master node, and the second election signature;
[0097] The second verification requirement includes:
[0098] The identifier of the first master node in the switching proof information is recorded in the system consensus node record;
[0099] The second verification sequence number in the switching proof information and the sequence number of the block with the largest block height meet a preset condition;
[0100] The second election signature of the switching certificate in the switching certificate information is valid;
[0101] The number of handover proof signatures in the signature list in the handover proof information is not less than half of the number of nodes in the node organization;
[0102] Each switching proof signature in the signature list in the switching proof information is valid.
[0103] In a third aspect, an embodiment of the present invention further provides a computer device, including:
[0104] A memory for storing program instructions;
[0105] The processor is used to call the program instructions stored in the memory and execute the consensus method of the blockchain system according to the obtained program.
[0106] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the consensus method of the above-mentioned blockchain system. BRIEF DESCRIPTION OF THE DRAWINGS
[0107] 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 creative work.
[0108] Figure 1 A schematic diagram of a system architecture provided by an embodiment of the present invention;
[0109] Figure 2 A schematic diagram of a consensus method for a blockchain system provided by an embodiment of the present invention;
[0110] Figure 3 A schematic diagram of the structure of a consensus device of a blockchain system provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0111] 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.
[0112] In the prior art, consensus algorithms for blockchain include Raft, PBFT, POW (Proof of Work), POS (Proof of Stake), DPOS (Delegated Proof of Stake), etc.
[0113] Among them, the PBFT consensus algorithm can reach consensus in scenarios where a few nodes act maliciously (such as forging messages). PBFT uses cryptographic algorithms such as signatures, signature verification, and hashing to ensure tamper-proof, anti-forgery, and non-repudiation during message transmission, reducing the complexity of the Byzantine fault-tolerant algorithm from exponential to polynomial levels. 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. For example, in a blockchain system with 7 nodes, 2 nodes are allowed to have Byzantine errors.
[0114] However, the network complexity of the PBFT consensus algorithm is proportional to the square of the node size (for example, the network complexity is the square of the number of nodes), the supported blockchain network size is limited, and the amount of computation required in the consensus process is large, which limits the scalability of the blockchain system.
[0115] The Raft consensus algorithm is a consensus algorithm that manages replica logs, such as leader election, log replication, security, and state machines. Raft also provides a new mechanism to change cluster members to ensure security. The Raft consensus algorithm can tolerate no more than half of the non-Byzantine errors.
[0116] However, the Raft consensus algorithm cannot prevent the Byzantine problem.
[0117] Therefore, in order to reduce the amount of computation in the consensus process in the blockchain system, reduce the complexity of the PBFT consensus algorithm network, increase the supportable blockchain network scale, and improve the scalability of the blockchain system, an embodiment of the present invention provides a consensus method for a blockchain system that combines the Raft consensus algorithm and the PBFT consensus algorithm.
[0118] Figure 1 A system architecture applicable to an embodiment of the present invention is exemplarily shown, wherein the system architecture includes a plurality of node mechanisms, and each node mechanism has a plurality of nodes.
[0119] In the embodiment of the present invention, Figure 1Only three node organizations are shown as examples, namely node organization 1, node organization 2 and node organization 3. Each node organization includes three nodes, including one master node and two election nodes. The master node in the node organization is determined according to the Raft consensus algorithm, and the PBFT consensus algorithm is used between the master nodes of each node organization to reach consensus on the consensus block.
[0120] It should be noted that the above Figure 1 The structure shown is only an example and is not limited to this embodiment of the present invention.
[0121] Based on the above description, Figure 2 A schematic flow chart of a consensus method for a blockchain system provided by an embodiment of the present invention is exemplarily shown, and the flow chart can be executed by a consensus device of the blockchain system.
[0122] like Figure 2 As shown in the figure, the process specifically includes:
[0123] Step 210: For at least one node organization, the first master node in the node organization generates an election certificate and sends it to the first election node in the node organization.
[0124] In the embodiment of the present invention, the first master node is determined by each node in the node mechanism based on the Raft consensus algorithm.
[0125] In step 220, the first master node generates an election certificate transaction based on the received multiple election certificate signatures and the election certificate.
[0126] In the embodiment of the present invention, the election certificate signature is obtained by signing the election certificate after the first election node determines that the election certificate meets the first verification requirement.
[0127] Step 230, after the blockchain system determines that the election certification transaction consensus is successful based on the PBFT consensus algorithm, the first master node serves as the PBFT consensus node of the blockchain system.
[0128] In an embodiment of the present invention, the conditions for consensus on the election certificate transaction include: a verification serial number of the election certificate in the election certificate transaction, the number of election certificate signatures in a signature list in the election certificate transaction, and a consensus on the validity of each election certificate signature in the signature list in the election certificate transaction.
[0129] In order to better explain the technical solution of the present invention, some nouns that appear are explained below:
[0130] In the embodiment of the present invention, when the blockchain system is initialized, for any node organization in the blockchain system, the node organization includes multiple election nodes, and the election node is equivalent to the Follower state in the Raft consensus algorithm. Then, through voting, a unique first master node is selected. The first master node is equivalent to the Leader state in the Raft consensus algorithm. The first election node is equivalent to other nodes in the node organization to which the first master node belongs, and the first election node participates in the election of the first master node.
[0131] In the Raft consensus algorithm, if the election mechanism meets the preset election conditions (such as no heartbeat request sent by the Leader has been received after the election timer has expired, etc.), it is necessary to re-elect a new master node, which is equivalent to the second master node described in the embodiment of the present invention. The second election node is equivalent to other nodes in the node organization to which the second master node belongs, and the second election node participates in the election of the second master node.
[0132] In step 210, before the first master node generates an election certificate and sends it to the first election node in the node organization, each node organization independently runs the Raft consensus algorithm to elect the first master node Leader.
[0133] For example, for any node in any node organization, a voting request is sent to other nodes in the node organization. When a node obtains votes from half of the nodes in the node organization, the node is determined to be the leader.
[0134] After the first master node is determined, the first master node generates an election certificate, wherein the election certificate is generated based on the serial number of the block and the identifier of the first master node; the increasing serial number in the blockchain prevents malicious nodes from replaying the election certificate.
[0135] Specifically, the first master node in the node organization determines the serial number of the block with the largest block height in the blockchain system; the first master node generates a first verification serial number based on the serial number of the block with the largest block height; the first master node signs the first verification serial number and the identifier of the first master node to obtain a first election signature; the first master node generates the election certificate according to the first verification serial number, the identifier of the first master node and the first election signature.
[0136] For example, the first master node determines the block with the largest block height from the blockchain system, that is, the latest block, and based on the nonce value (serial number) of the block, adds a preset value (such as 1, 2, etc.) to determine the first verification serial number, such as the first verification serial number = nonce1+1; in an implementable manner, the nonce value can also be multiplied by the preset value to determine the first verification serial number, which is not specifically limited here.
[0137] Then the first master node uses its own private key to sign the identifier of the first master node (such as Leader Node ID1) and the first verification sequence number (nonce1+1) to obtain a first election signature; for example, the first election signature is sig(LeaderNode ID1, nonce1+1).
[0138] Then, the first verification serial number, the identifier of the first master node and the first election signature are combined to generate an election certificate; for example, the election certificate is Vote Proof{Leader Node ID1, nonce1+1, sig(Leader Node ID1, nonce1+1)}.
[0139] After determining the election certificate, the first master node sends the election certificate to other election nodes of the node organization to which the first master node belongs, that is, each first election node in the node organization.
[0140] In step 220, before the first master node signs the multiple election certificates received, each first election node verifies the election certificate of the first master node. When any first election node determines that the election certificate of the first master node meets the first verification condition, it uses its own private key to sign the election certificate, obtains the election certificate signature, and returns it to the first master node.
[0141] Among them, the first verification requirement includes three conditions, specifically:
[0142] The node identification in the election certificate is consistent with the identification of the master node in the node organization; the verification sequence number in the election certificate and the sequence number of the block with the largest block height meet the preset conditions; the election signature in the election certificate is valid.
[0143] For example, for any first election node, after obtaining the election certificate, the first verification serial number, the identifier of the first master node and the first election signature in the election certificate are verified respectively.
[0144] Specifically, the first election node obtains the serial number nonce` of the block with the largest block height from the blockchain system. If it is determined that the first verification serial number (nonce1+1) is greater than the serial number nonce`, it is determined that the first verification serial number has been verified successfully. In an implementable manner, a difference value can also be determined based on nonce` and (nonce1+1). If the difference value is equal to a preset value (such as 1), it is determined that the first verification serial number has been verified successfully.
[0145] The first election node determines whether the identifier of the first master node (Leader Node ID1) is the Node ID of the master node elected by the node organization to which it belongs according to the Raft consensus algorithm. If so, the identifier verification of the first master node is passed.
[0146] The first election node uses the public key of the first master node to decrypt the first election signature sig(Leader Node ID1, nonce1+1). If the decryption is successful, it is determined that the first election signature verification has passed.
[0147] In an embodiment of the present invention, if any of the above verification conditions is verified to be passed, the node organization switches the master node; if the first election node verifies the election certificate, the first election node uses its own private key to sign the election certificate Vote Proof{Leader Node ID1, nonce1+1, sig(Leader Node ID1, nonce1+1)}, obtains the election certificate signature, and sends it to the first master node.
[0148] Based on the characteristics of the Raft consensus algorithm, the first master node needs to synthesize the received election proof signatures into a signature list when the number of received election proof signatures is not less than half of the number of nodes in the node organization; to represent the first master node as the master node determined by the node organization according to the Raft consensus algorithm to ensure the security of the master node election, and then generate an election proof transaction based on the signature list.
[0149] Specifically, when the first master node determines that the number of received election certificate signatures is not less than half of the number of nodes in the node organization, it synthesizes the received election certificate signatures into a signature list; based on the signature list and the election certificate, generates an election certificate transaction.
[0150] For example, the first master node aggregates multiple election proof signatures to generate a signature list (VoteProof SigList), and then aggregates the signature list (Vote Proof SigList) and the election proof (Vote Proof) to generate an election proof transaction (Trigger Leader Vote).
[0151] In step 230, the consensus on the election certificate transaction is reached by each node in the blockchain system. That is, after generating the election certificate transaction, the first master node needs to broadcast the election certificate transaction to the blockchain system, such as packaging the election certificate transaction into the first consensus information package of the consensus block, and then broadcasting the first consensus information package to the blockchain system; after obtaining the election certificate transaction in the first consensus information package, the nodes in the blockchain system reach a consensus on the election certificate transaction.
[0152] Among them, if the node determines that the election proof transaction meets the following conditions, it is determined that the election proof transaction consensus is successful.
[0153] Condition 1: Determine that the verification serial number of the election certificate in the election certificate transaction and the serial number of the block with the largest block height meet the preset conditions;
[0154] Condition 2: Determine that the number of election proof signatures in the signature list in the election proof transaction is not less than half the number of nodes in the node organization;
[0155] Condition 3: Determine that each election certification signature in the signature list in the election certification transaction is valid.
[0156] Regarding condition 1, as stated above for the first verification requirement, it will not be repeated here.
[0157] For condition 2, when it is determined that the number of election proof signatures in the signature list in the election proof transaction is not less than half of the number of nodes in the node organization to which the first master node belongs, the first master node is determined to be the master node elected by the node organization according to the Raft consensus algorithm, and therefore the verification passes.
[0158] For condition 3, for any election proof signature in the signature list, the node uses the public key of the first election node corresponding to the election proof signature to decrypt the election proof signature. If the decryption is successful, it is determined that the election proof signature verification has passed.
[0159] For any node in the blockchain, after determining that the election proof transaction consensus is successful, the identifier of the first master node is written into the local system consensus node record; to indicate that the first master node is the consensus node that reaches consensus on the first consensus information packet based on the PBFT consensus algorithm.
[0160] Among them, the system consensus node record is also used to verify the nodes of the parameter PBFT consensus. Specifically, the first master node receives the first information packet to be agreed upon; after determining that the sender of the first information packet to be agreed upon is the consensus node in the system consensus node record, consensus is reached on the first information packet to be agreed upon based on the PBFT consensus algorithm.
[0161] That is to say, if the first master node determines that the sender of the first information packet to be agreed upon is not a consensus node in the system consensus node record, the first information packet to be agreed upon is rejected.
[0162] Exemplarily, after receiving the first information packet to be agreed upon, in addition to verifying whether the sender of the first information packet to be agreed upon is a consensus node in the system consensus node record, the first master node will also verify the information packet signature in the first information packet to be agreed upon based on the public key of the sender of the first information packet to be agreed upon. If the verification fails, the first information packet to be agreed upon is rejected. The information packet signature is obtained by the sender signing the hash value of the first information packet to be agreed upon using his own private key.
[0163] In an embodiment of the present invention, for the first master node that has been recorded in the system consensus node record, before the subsequent PBFT consensus, it is only necessary to determine that the identifier of the node is recorded in the system consensus node record, so that the node can be used as the PBFT consensus node of the blockchain system, thereby avoiding the first master node from repeatedly generating election certificates, election certificate transactions and other operations, thereby improving the consensus efficiency of the blockchain system.
[0164] In one application scenario, the first master node in a node organization may be in an abnormal state due to network disconnection, machine downtime, or being hacked by malicious attackers. In order to ensure the consistency and reliability of the blockchain system and enable the blockchain system to reach a normal consensus even when the first master node is abnormal, the present invention proposes a master node rotation mechanism. That is to say, when the first master node of a node organization is abnormal, a new master node (second master node) can be re-selected as the consensus node to continue participating in the PBFT consensus.
[0165] Specifically, after the first master node of the node organization rotates to the second master node, the second master node generates a switching certificate and sends it to the second election node in the node organization; the second master node is determined by each node in the node organization based on the Raft consensus algorithm; the second election node is each node in the node organization except the second master node.
[0166] The second master node generates switching proof information based on the received multiple switching proof signatures and the switching proof; the switching proof signature is obtained by signing the switching proof after the second election node determines that the switching proof meets the first verification requirement;
[0167] If the switching proof information meets the second verification requirement, the second master node reaches a consensus on the second message packet to be agreed upon based on the PBFT consensus algorithm in the blockchain system.
[0168] In the embodiment of the present invention, the second master node is different from the first master node in that the switching certificate generated by the second master node includes the identifier of the first master node.
[0169] Further, the second master node determines the serial number of the block with the largest block height in the blockchain system, and generates a second verification serial number based on the serial number of the block with the largest block height; the second master node signs the second verification serial number and the identifier of the second master node to obtain a second election signature; the second master node generates a switching certificate according to the second verification serial number, the identifier of the first master node, the identifier of the second master node, and the second election signature;
[0170] For example, the second master node determines the block with the largest block height from the blockchain system, that is, the latest block, and based on the nonce value (serial number) of the block, increases the preset value (such as 1, 2, etc.) to determine the first verification serial number, such as the first verification serial number = nonce2+1.
[0171] The second master node uses its own private key to sign the identifier of the second master node (such as New Leader ID) and the first verification sequence number (nonce2+1) to obtain a second election signature; for example, the second election signature is sig(New Leader ID, nonce2+1).
[0172] Then, the handover proof is generated by combining the second verification serial number, the identifier of the first master node, the identifier of the second master node and the first election signature; for example, the handover proof is Hand Over Proof{Last Leader ID(Leader Node ID1), NewLeader ID, nonce2+1, sig(New Leader ID, nonce2+1)}.
[0173] After determining the switching certificate, the second master node sends the switching certificate to other election nodes of the node organization to which the second master node belongs, that is, each second election node in the node organization.
[0174] For any second election node, the second election node verifies the switching certificate of the second master node. When it is determined that the switching certificate of the second master node meets the first verification condition, it uses its own private key to sign the switching certificate, obtains the switching certificate signature, and returns it to the second master node. Among them, the first verification condition is as described above and will not be repeated here. That is to say, the switching certificate is similar to the election certificate, that is, the second verification serial number, the identifier of the second master node and the second election signature in the switching certificate are verified.
[0175] If the second election node passes the verification of the handover proof, the second election node uses its own private key to sign the handover proof Hand Over Proof, obtains the handover proof signature, and sends it to the second master node.
[0176] Based on the characteristics of the Raft consensus algorithm, the second master node will synthesize the received handover proof signatures into a signature list (Hand OverProof SignList) when the number of received handover proof signatures is not less than half of the number of nodes in the node organization to which the second master node belongs; this is used to characterize the second master node as the new master node determined by the node organization according to the Raft consensus algorithm.
[0177] The second master node then aggregates the signature list Hand Over Proof SignList and the handover proof Hand Over Proof to generate handover proof information Hand Over Info; that is, Hand Over Info = {HandOver Proof SignList, Hand Over Proof}.
[0178] Before conducting PBFT consensus, each consensus node that needs to participate in the PBFT consensus needs to verify the switching proof information of the second master node. When it is determined that the switching proof information meets the second verification condition, it is determined that the switching proof information verification has passed; after the verification passes, the second master node is allowed to participate in the PBFT consensus.
[0179] The second verification requirement includes the following conditions:
[0180] Condition 1: The identifier of the first master node in the switching proof information is recorded in the system consensus node record.
[0181] Condition 2: The second verification sequence number in the switching proof information and the sequence number of the block with the largest block height meet the preset conditions.
[0182] Condition 3: The election signature of the switch certificate in the switch certificate information is valid.
[0183] Condition 4: The number of handover proof signatures in the signature list in the handover proof information is not less than half of the number of nodes in the node organization;
[0184] Condition 5: Each switching proof signature in the signature list in the switching proof information is valid.
[0185] The specific verification method is similar to the above verification method and will not be described in detail here. In the embodiment of the present invention, when the second master node participates in the PBFT consensus and the new block consensus is successful, each node will add the handover proof information HandOver Info to the new block when uploading the new block to verify the legitimacy of the second consensus node.
[0186] The characteristic of the above method is that the second master node needs to send switching proof information each time it participates in the PBFT consensus to ensure the security and correctness of the second master node.
[0187] In one feasible method, after determining the switching proof, the second master node generates a switching proof transaction and broadcasts the switching proof transaction to the blockchain system; after determining that the switching proof transaction consensus is successful, the nodes in the blockchain system write the second master node into the system consensus node record, which is equivalent to replacing the first master node with the second master node. In this way, when participating in the PBFT consensus in the future, there is no need to send the switching proof information, which reduces the complexity of consensus verification and improves the consensus efficiency of the blockchain system.
[0188] Specifically, after the first master node of the node organization rotates to the second master node, the second master node generates a switching certificate and sends it to the second election node in the node organization; the second master node is determined by each node in the node organization based on the Raft consensus algorithm; the second election node is each node in the node organization except the second master node;
[0189] The second master node generates a handover proof transaction based on the received multiple handover proof signatures and the handover proof; the handover proof signature is obtained by signing the handover proof after the second election node determines that the handover proof meets the first verification requirement;
[0190] After the blockchain system determines that the switching proof transaction consensus is successful based on the PBFT consensus algorithm, the second master node serves as the PBFT consensus node of the blockchain system.
[0191] Based on the same technical concept, Figure 3 The structure diagram of a consensus device of a blockchain system provided by an embodiment of the present invention is exemplarily shown, and the device can execute the process of the consensus method of the blockchain system.
[0192] The blockchain system includes multiple node organizations, each of which has multiple nodes; Figure 3 As shown, the device specifically includes:
[0193] A generation module 310 is used to generate, for at least one node organization, an election certificate of a first master node in the node organization and send it to a first election node in the node organization; the first master node is determined by each node in the node organization based on the Raft consensus algorithm;
[0194] A receiving module 320, configured to receive a plurality of election certificate signatures and the election certificate;
[0195] A processing module 330 is configured to generate an election certificate transaction based on the received multiple election certificate signatures and the election certificate; the election certificate signature is obtained by signing the election certificate after the first election node determines that the election certificate meets the first verification requirement;
[0196] After the blockchain system determines that the election certification transaction consensus is successful based on the PBFT consensus algorithm, it serves as the PBFT consensus node of the blockchain system.
[0197] Optionally, the processing module 330 is further used for:
[0198] After serving as the PBFT consensus node of the blockchain system, the identifier of the first master node is written into the system consensus node record;
[0199] Controlling the receiving module 320 to receive the first consensus-to-be information packet;
[0200] After determining that the sender of the first information packet to be agreed upon is a consensus node in the system consensus node record, consensus is performed on the first information packet to be agreed upon based on the PBFT consensus algorithm.
[0201] Optionally, the generating module 310 is specifically used for:
[0202] Determine the serial number of the block with the largest block height in the blockchain system;
[0203] Generate a first verification sequence number based on the sequence number of the block with the largest block height;
[0204] Signing the first verification serial number and the identifier of the first master node to obtain a first election signature;
[0205] generating the election certificate according to the first verification serial number, the identifier of the first master node and the first election signature;
[0206] The first verification requirement includes:
[0207] The node identification in the election certificate is consistent with the identification of the master node in the node organization;
[0208] The verification sequence number in the election certificate and the sequence number of the block with the largest block height meet the preset conditions;
[0209] The election signature in the said election certificate is valid.
[0210] Optionally, the processing module 330 is specifically used for:
[0211] When it is determined that the number of received election proof signatures is not less than half of the number of nodes in the node organization, synthesizing the received election proof signatures into a signature list;
[0212] Based on the signature list and the election proof, a proof-of-election transaction is generated.
[0213] Optionally, determining that the election certification transaction consensus is successful based on the PBFT consensus algorithm includes:
[0214] Determining that the verification sequence number of the election certificate in the election certificate transaction and the sequence number of the block with the largest block height meet a preset condition;
[0215] Determining that the number of election proof signatures in the signature list in the election proof transaction is not less than half the number of nodes in the node authority;
[0216] Determine that each election certification signature in the signature list in the election certification transaction is valid.
[0217] Optionally, also include:
[0218] After the first master node of the node mechanism rotates to the second master node, the generating module 310 is further used for:
[0219] Generate a handover certificate and send it to a second election node in the node organization; the second master node is determined by each node in the node organization based on the Raft consensus algorithm; the second election node is each node in the node organization except the second master node;
[0220] The processing module 330 is further used for:
[0221] Generate switching proof information based on the received multiple switching proof signatures and the switching proof; the switching proof signature is obtained by signing the switching proof after the second election node determines that the switching proof meets the first verification requirement;
[0222] If the switching proof information meets the second verification requirement, the second master node reaches a consensus on the second message packet to be agreed upon based on the PBFT consensus algorithm in the blockchain system.
[0223] Optionally, also include:
[0224] After the first master node of the node mechanism rotates to the second master node, the generation module 310 is used to:
[0225] Generate a handover certificate and send it to a second election node in the node organization; the second master node is determined by each node in the node organization based on the Raft consensus algorithm; the second election node is each node in the node organization except the second master node;
[0226] The processing module 330 is used for:
[0227] Based on the received multiple handover proof signatures and the handover proof, a handover proof transaction is generated; the handover proof signature is obtained by signing the handover proof after the second election node determines that the handover proof meets the first verification requirement;
[0228] After the blockchain system determines that the switching proof transaction consensus is successful based on the PBFT consensus algorithm, it serves as the PBFT consensus node of the blockchain system.
[0229] The generating module 310 is specifically used for:
[0230] Determine the sequence number of the block with the largest block height in the blockchain system, and generate a second verification sequence number based on the sequence number of the block with the largest block height;
[0231] Signing the second verification serial number and the identifier of the second master node to obtain a second election signature;
[0232] Generate a switching certificate according to the second verification serial number, the identifier of the first master node, the identifier of the second master node, and the second election signature;
[0233] The second verification requirement includes:
[0234] The identifier of the first master node in the switching proof information is recorded in the system consensus node record;
[0235] The second verification sequence number in the switching proof information and the sequence number of the block with the largest block height meet a preset condition;
[0236] The second election signature of the switching certificate in the switching certificate information is valid;
[0237] The number of handover proof signatures in the signature list in the handover proof information is not less than half of the number of nodes in the node organization;
[0238] Each switching proof signature in the signature list in the switching proof information is valid.
[0239] Based on the same technical concept, an embodiment of the present invention further provides a computer device, including:
[0240] A memory for storing program instructions;
[0241] The processor is used to call the program instructions stored in the memory and execute the consensus method of the blockchain system according to the obtained program.
[0242] Based on the same technical concept, an embodiment of the present invention also provides a computer-readable storage medium, which stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the consensus method of the above-mentioned blockchain system.
[0243] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0244] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes 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.
[0245] 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.
[0246] 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 1A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0247] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A consensus method for a blockchain system, characterized in that: The blockchain system includes multiple node organizations, each of which has multiple nodes; the method includes: For at least one node organization, the first master node in the node organization generates an election certificate and sends it to the first election node in the node organization; the first master node is the node in the node organization based on Raft Determined by the consensus algorithm; The first master node generates an election certificate transaction based on the received multiple election certificate signatures and the election certificate; after the blockchain system determines that the election certificate transaction consensus is successful based on the PBFT consensus algorithm, the first master node, as a PBFT consensus node of the blockchain system, signs the election certificate after the first election node determines that the election certificate meets the first verification requirement; The first master node is based on the blockchain system PBFT After the consensus algorithm determines that the election certification transaction consensus is successful, the blockchain system PBFT Consensus nodes; As the blockchain system PBFT After the consensus node, it also includes: Writing the identifier of the first master node into the system consensus node record; The first master node receives a first information packet to be agreed upon; After the first master node determines that the sender of the first consensus information packet is a consensus node in the system consensus node record, based on PBFT The consensus algorithm reaches consensus on the first information package to be agreed upon; The first master node in the node organization generates an election certificate, including: The first master node in the node mechanism determines the sequence number of the block with the largest block height in the blockchain system; The first master node generates a first verification sequence number based on the sequence number of the block with the largest block height; The first master node signs the first verification serial number and the identifier of the first master node to obtain a first election signature; The first master node generates the election certificate according to the first verification serial number, the identifier of the first master node and the first election signature; The first verification requirement includes: The node identification in the election certificate is consistent with the identification of the master node in the node organization; The verification sequence number in the election certificate and the sequence number of the block with the largest block height meet the preset conditions; The election signature in the said election certificate is valid; The first master node generates an election proof transaction based on the received multiple election proof signatures and the election proof, including: When the first master node determines that the number of received election proof signatures is not less than half of the number of nodes in the node organization, the first master node synthesizes the received election proof signatures into a signature list; The first master node generates an election certificate transaction based on the signature list and the election certificate; based on PBFT The consensus algorithm determines that the election certification transaction consensus is successful, including: Determining that the verification sequence number of the election certificate in the election certificate transaction and the sequence number of the block with the largest block height meet a preset condition; Determining that the number of election proof signatures in the signature list in the election proof transaction is not less than half the number of nodes in the node authority; Determine that each election certification signature in the signature list in the election certification transaction is valid.
2. The method according to claim 1, characterized in that The method further comprises: After the first master node of the node organization rotates to the second master node, the second master node generates a switching certificate and sends it to the second election node in the node organization; the second master node is the node organization based on Raft Determined by a consensus algorithm; the second election node is each node in the node organization except the second master node; The second master node generates switching proof information based on the received multiple switching proof signatures and the switching proof; the switching proof signature is obtained by signing the switching proof after the second election node determines that the switching proof meets the first verification requirement; If the switching proof information meets the second verification requirement, the second master node in the blockchain system PBFT The consensus algorithm reaches consensus on the second consensus message package.
3. The method according to claim 1, characterized in that The method further comprises: After the first master node of the node organization rotates to the second master node, the second master node generates a switching certificate and sends it to the second election node in the node organization; the second master node is the node organization based on Raft Determined by a consensus algorithm; the second election node is each node in the node organization except the second master node; The second master node generates a handover proof transaction based on the received multiple handover proof signatures and the handover proof; the handover proof signature is obtained by signing the handover proof after the second election node determines that the handover proof meets the first verification requirement; The second master node is based on the blockchain system PBFT After the consensus algorithm determines that the switch proof transaction consensus is successful, the blockchain system PBFT Consensus node.
4. The method according to claim 2, characterized in that The second master node generates a switching certificate, including: The second master node determines the sequence number of the block with the largest block height in the blockchain system, and generates a second verification sequence number based on the sequence number of the block with the largest block height; The second master node signs the second verification serial number and the identifier of the second master node to obtain a second election signature; The second master node generates a switching certificate according to the second verification serial number, the identifier of the first master node, the identifier of the second master node, and the second election signature; The second verification requirement includes: The identifier of the first master node in the switching proof information is recorded in the system consensus node record; The second verification sequence number in the switching proof information and the sequence number of the block with the largest block height meet a preset condition; The second election signature of the switching certificate in the switching certificate information is valid; The number of handover proof signatures in the signature list in the handover proof information is not less than half of the number of nodes in the node organization; Each switching proof signature in the signature list in the switching proof information is valid.
5. A consensus device for a blockchain system, characterized in that: The blockchain system includes a plurality of node organizations, each of which has a plurality of nodes; the device includes: A generation module is used to generate, for at least one node organization, an election certificate of a first master node in the node organization and send it to a first election node in the node organization; the first master node is a node in the node organization based on Raft Determined by the consensus algorithm; A receiving module, configured to receive a plurality of election certificate signatures and the election certificate; a processing module, configured to generate an election certificate transaction based on the received multiple election certificate signatures and the election certificate; the election certificate signature is obtained by signing the election certificate after the first election node determines that the election certificate meets the first verification requirement; In the blockchain system based on PBFT After the consensus algorithm determines that the election certification transaction consensus is successful, the blockchain system PBFT Consensus nodes; The processing module is further used to: write the identifier of the first master node into the system consensus node record; receive the first consensus information packet; after determining that the sender of the first consensus information packet is the consensus node in the system consensus node record, based on PBFT The consensus algorithm reaches consensus on the first information package to be agreed upon; The generation module is specifically used to: determine the serial number of the block with the largest block height in the blockchain system; generate a first verification serial number based on the serial number of the block with the largest block height; sign the first verification serial number and the identifier of the first master node to obtain a first election signature; generate the election certificate according to the first verification serial number, the identifier of the first master node and the first election signature; the first verification requirement includes: the identifier of the node in the election certificate is consistent with the identifier of the master node in the node organization; the verification serial number in the election certificate and the serial number of the block with the largest block height meet preset conditions; the election signature in the election certificate is valid; The processing module is specifically used to: when it is determined that the number of received election certificate signatures is not less than half of the number of nodes in the node organization, synthesize the received election certificate signatures into a signature list; based on the signature list and the election certificate, generate an election certificate transaction; The processing unit is specifically used to: determine that the verification serial number of the election certificate in the election certificate transaction and the serial number of the block with the largest block height meet preset conditions; determine that the number of election certificate signatures in the signature list in the election certificate transaction is not less than half of the number of nodes in the node organization; determine that each election certificate signature in the signature list in the election certificate transaction is valid.
6. A computer device, characterized in that: include: A memory for storing program instructions; A processor, configured to call the program instructions stored in the memory, and execute the method according to any one of claims 1 to 4 according to the obtained program.
Citation Information
Patent Citations
Distributed system and message processing method
CN106789095A
Raft-algorithm-based block chain consensus mechanism
CN106878071A
A block chain consensus device and algorithm
CN109039713A
Log transmission method and related equipment
CN110162511A
Block chain system, message processing method and storage medium
CN110430064A
