Blockchain consensus method, device, system and electronic device
By updating node reputation values and electing new master nodes through blockchain servers, the problems of high computational complexity and poor master node trustworthiness in blockchain consensus algorithms are solved, achieving a more efficient and reliable consensus process.
Patent Information
- Application Number
- CN202211393272.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-08
- Publication Date
- 2026-11-20
- Estimated Expiration
- 2042-11-08
AI Technical Summary
Existing blockchain consensus algorithms involve large computational loads and have poor reliability in master node election, posing a risk of tampering with system key parameters.
The node reputation value is determined by the blockchain server. The node reputation value is updated based on the reputation value, the number of successful consensuses, and the number of timeouts. A new master node is elected and used for the next round of consensus, reducing the dependence on computing power and the number of coins.
It improves the credibility and consensus efficiency of master node election, reduces computational load, and minimizes the impact of malicious nodes.
Smart Images

Figure CN115834579B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of blockchain technology, and more specifically, to a blockchain consensus method, apparatus, system, and electronic device. Background Technology
[0002] Blockchain systems employ a distributed structure, exhibiting decentralized characteristics. Numerous network nodes record data. Given the possibility of a few nodes acting maliciously, all nodes need a mechanism to maintain data consistency and penalize malicious nodes, ensuring the blockchain system's security. Consensus algorithms, the core technology of blockchain, are used to guarantee data consistency across all nodes. Currently, there are two main types of blockchain consensus algorithms: one involves competing for block-producing rights based on computing power or the amount of cryptocurrency held, proving the validity of one's transactions; the other involves electing one or more trusted nodes to broadcast transactions, with other nodes acting as followers and voting to elect a leader. Multiple communications are required between the leader and follower nodes.
[0003] However, of the two consensus algorithms mentioned above, the first method involves a large amount of computation and has high requirements for the machine; the second method, in the process of voting and signing to elect the master node, has the possibility that some nodes collude with other nodes to tamper with the system's key parameters to forge signatures, and the trustworthiness of the master node itself will also have a certain impact on the security and efficiency of the system. Summary of the Invention
[0004] In view of this, the purpose of this application is to provide a blockchain consensus method, device, system and electronic device to solve the problems of large computational load and poor credibility of master node election in existing consensus algorithms.
[0005] In a first aspect, embodiments of this application provide a blockchain consensus method applied to a blockchain server, comprising:
[0006] The master node of the consensus unit is determined in this round of consensus process. The consensus unit includes multiple nodes, which are divided into master nodes and slave nodes. The consensus unit is used to describe the current state of a multi-replica system.
[0007] Based on the consensus process between the master node and the slave node, determine whether the update conditions for updating the node's reputation value are met.
[0008] If the update conditions are met, for each node, update the node's current reputation value based on the node's current reputation value, number of successful consensuses, and number of timeouts;
[0009] The probability of a node being selected is determined based on its updated current reputation value.
[0010] A new master node is elected based on the probability of different nodes being selected. The new master node is then used to switch to the next consensus unit, where the next round of consensus is carried out.
[0011] Optionally, before determining the master node of the consensus unit in this round of consensus process, the process further includes: assigning a corresponding initial reputation value to each node in the consensus unit based on the node information of that node; and selecting the node with the highest initial reputation value in the consensus unit as the initial master node.
[0012] Optionally, determining whether the update conditions for updating the node reputation value are met includes: determining whether the current consensus process has ended or whether the secondary node has detected an error in the primary node; if the current consensus process has ended or the secondary node has detected an error in the primary node, determining that the update conditions for updating the node reputation value are met.
[0013] Optionally, before updating the node's current reputation value based on the node's current reputation value, number of successful consensuses, and number of timeouts, the method further includes: determining the values of the success reward factor and the timeout penalty factor; determining whether the node has successfully reached consensus with other nodes during this round of consensus; if consensus is successfully reached, incrementing the node's number of successful consensuses by 1; if the node fails to reach consensus due to timeout, incrementing the node's number of timeouts by 1.
[0014] Optionally, the node's current reputation value is updated based on its current reputation value, the number of successful consensuses, and the number of timeouts. This includes: detecting whether the node engaged in malicious behavior during the current consensus process; if malicious behavior is found, setting the node's current reputation value to 0; if no malicious behavior is found, calculating the product of the success reward factor and the number of successful consensuses to obtain the successful consensus reputation value; calculating the product of the timeout penalty factor and the number of timeouts to obtain the timeout deduction reputation value; and calculating the sum of the node's current reputation value and the successful consensus reputation value, using the difference between the sum and the timeout deduction reputation value as the node's updated current reputation value.
[0015] Optionally, determining the selection probability of a node based on its updated current reputation value includes: calculating the sum of the updated current reputation values of all nodes; and using the ratio of the updated current reputation value of the node to the sum of the updated current reputation values of all nodes as the selection probability of the node.
[0016] Optionally, a new master node is elected based on the selection probability of different nodes, including: arranging the selection probabilities of different nodes in descending order, and selecting the node with the highest selection probability as the new master node.
[0017] Secondly, embodiments of this application also provide a blockchain consensus device, the device comprising:
[0018] The master node determination module is used to determine the master node of the consensus unit in this round of consensus process. The consensus unit includes multiple nodes, which are divided into master nodes and slave nodes. The consensus unit is used to describe the current state of a multi-replica system.
[0019] The update condition determination module is used to determine whether the update conditions for updating the reputation value of the node are met based on the consensus process between the master node and the slave node.
[0020] The reputation value calculation module is used to update the current reputation value of each node based on its current reputation value, number of successful consensuses, and number of timeouts if the update conditions are met.
[0021] The probability calculation module is used to determine the probability of a node being selected based on its updated current reputation value.
[0022] The unit update module is used to elect a new master node based on the selection probability of different nodes, and use the new master node to switch to the next consensus unit, and carry out the next round of consensus in the next consensus unit.
[0023] Thirdly, this application also provides a blockchain consensus system, the system comprising: a blockchain server and a consensus unit, the consensus unit comprising multiple nodes, the multiple nodes being divided into master nodes and slave nodes;
[0024] The blockchain server executes the aforementioned blockchain consensus method;
[0025] The master node of the consensus unit receives the voting signature sent by the slave node, generates new block information, and sends the new block information to the slave node;
[0026] The secondary node uses a multi-signature algorithm to verify the information of the new block. If the verification is successful, consensus is reached on the data in the new block.
[0027] Fourthly, embodiments of this application also provide an electronic device, including: a processor, a memory, and a bus. The memory stores machine-readable instructions executable by the processor. When the electronic device is running, the processor communicates with the memory via the bus. When the machine-readable instructions are executed by the processor, the steps of the blockchain consensus method described above are performed.
[0028] The embodiments of this application bring the following beneficial effects:
[0029] This application provides a blockchain consensus method, apparatus, system, and electronic device. The blockchain server determines whether to update the reputation value of each node and determines the current reputation value of each node based on its initial reputation value, number of successful consensuses, and number of timeouts. A new master node is elected based on the selection probability corresponding to the current reputation value. Thus, the new master node is elected by the blockchain server based on the current reputation values of different nodes, eliminating the need to compete for block production rights through computing power or the amount of coins held. This improves the credibility of master node election and consensus efficiency. Compared with existing blockchain consensus methods, this solves the problems of high computational load and poor credibility of master node election in existing consensus algorithms.
[0030] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0031] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0032] Figure 1 A flowchart of the blockchain consensus method provided in the embodiments of this application is shown;
[0033] Figure 2 A schematic diagram of the structure of the blockchain consensus device provided in the embodiments of this application is shown;
[0034] Figure 3 A schematic diagram of the structure of the blockchain consensus system provided in the embodiments of this application is shown;
[0035] Figure 4 A schematic diagram of the structure of the electronic device provided in the embodiments of this application is shown. Detailed Implementation
[0036] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. The components of the embodiments of this application described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely represents selected embodiments of this application. Based on the embodiments of this application, every other embodiment obtained by those skilled in the art without inventive effort falls within the scope of protection of this application.
[0037] It is worth noting that prior to this application, blockchain systems employed a distributed structure, exhibiting decentralized characteristics. Numerous network nodes recorded data, and given the possibility of a few nodes acting maliciously, all nodes needed a mechanism to maintain data consistency and punish malicious nodes, ensuring the security of the blockchain system. Consensus algorithms, which ensure data consistency across all nodes, are the core technology of blockchain. Currently, there are two main types of blockchain consensus algorithms: one involves competing for block production rights based on computing power or the amount of cryptocurrency held, proving the validity of one's transactions; the other involves electing one or more trusted nodes to broadcast transactions, with other nodes acting as followers and voting, requiring multiple communications between the primary and secondary nodes. However, the first method has a higher computational load and places higher demands on the machine; the second method, during the voting and signature election of the primary node, carries the risk of some nodes colluding with others to tamper with the system's key parameters to forge signatures, and the trustworthiness of the primary node itself can also negatively impact the system's security and efficiency.
[0038] Based on this, this application provides a blockchain consensus method to improve consensus efficiency and the credibility of master node election.
[0039] Please see Figure 1 , Figure 1 This is a flowchart illustrating a blockchain consensus method provided in an embodiment of this application. Figure 1 As shown in the embodiments of this application, the blockchain consensus method is applied to a blockchain server and includes:
[0040] Step S101: Determine the master node of the consensus unit in this round of consensus process.
[0041] In this step, a consensus unit can refer to a view, and the consensus process consists of one view after another. The consensus unit corresponding to the current round of consensus process can also be called the current consensus unit.
[0042] A consensus unit consists of multiple nodes, which are divided into master nodes and slave nodes. The consensus unit describes the current state of a multi-replica system. Furthermore, multiple nodes reach consensus on data within the same view; consensus cannot be achieved across views.
[0043] In a consensus unit, there is a defined master node that leads the consensus protocol and reaches a consensus through several stages of voting before switching to the next consensus unit to continue the consensus process.
[0044] In this embodiment, during the initial startup of the blockchain, all nodes in the blockchain are in a state of participating in the election of a master node. At this time, a certain reputation value is assigned to each node, and the initial master node for the first round of consensus is selected based on the reputation value. If the master node is to be selected for a consensus round after the first round, the master node for this round of consensus is determined based on the selection probability of each node. Here, "blockchain" refers to a consortium blockchain.
[0045] In an optional embodiment, before determining the master node of the consensus unit in this round of consensus process, the method further includes: assigning a corresponding initial reputation value to each node in the consensus unit based on the node information of that node; and selecting the node with the highest initial reputation value in the consensus unit as the initial master node.
[0046] Specifically, when a node joins the blockchain network, an initial reputation value is allocated based on the information provided by the node when it actually registered with the blockchain. For example, the initial reputation value is allocated based on the computer configuration parameters of the node when it registered with the blockchain. The higher the computer configuration parameters, the larger the initial reputation value allocated to the node, and the lower the computer configuration parameters, the lower the initial reputation value allocated to the node.
[0047] During the first round of consensus, the initial master node can be selected directly based on the initial reputation value of each node entering the network, with the node having the highest initial reputation value being selected as the initial master node.
[0048] Step S102: Based on the consensus process between the master node and the slave node, determine whether the update conditions for updating the node reputation value are met.
[0049] In this step, the consensus process can refer to a pipelined consensus process, which is similar to the HotStuff algorithm, but differs in the method of selecting the master node and the voting signature algorithm used each time.
[0050] Update conditions refer to the conditions under which a node's reputation value is updated. Update conditions are used to determine whether to update a node's reputation value.
[0051] The master node and slave node adopt a pipelined consensus process, which will be described in detail later.
[0052] In one optional embodiment, determining whether the update conditions for updating the node reputation value are met includes: determining whether the current consensus process has ended or whether the secondary node has detected an error in the primary node; if the current consensus process has ended or the secondary node has detected an error in the primary node, determining that the update conditions for updating the node reputation value are met.
[0053] Specifically, during this round of consensus, two situations may occur: one is that the consensus process ends because the master node and the slave node reach a consensus, and the other is that the consensus process times out because the master node makes a mistake. Therefore, when the above situations occur, the reputation value of each node needs to be updated so as to elect the master node for the next round of consensus.
[0054] Therefore, the completion of the current consensus process and whether the secondary node detects an error in the primary node are both update conditions. If either of these two conditions occurs, the reputation value of each node is updated to ensure the accuracy of the elected primary node for the next round of consensus. The completion of the current consensus process means that after the preparation, pre-commit, commit, and decision phases, all nodes correspond to a recognized blockchain, and the updated chain data on that blockchain indicates the end of the current consensus process. A secondary node detecting an error in the primary node means that the signature verification of the primary node's message is incorrect or the waiting time for the primary node's message times out.
[0055] Step S103: If the update conditions are met, for each node, update the current reputation value of the node based on the node's current reputation value, number of successful consensuses, and number of timeouts.
[0056] In this step, assuming that the current consensus process is the Ath round of consensus, and that node a's current reputation value is 10 before determining whether the update conditions are met, if the server determines that the node reputation value update conditions are met, then the server uses the current reputation value of 10, the number of successful consensuses, and the number of timeouts to update node a's current reputation value, and based on the updated current reputation value of node a and the updated current reputation values of other nodes, elects the master node in the A+1th round of consensus.
[0057] In an optional embodiment, before updating the node's current reputation value based on the node's current reputation value, the number of successful consensuses, and the number of timeouts, the method further includes: determining the values of the success reward factor and the timeout penalty factor; determining whether the node has successfully reached consensus with other nodes during this round of consensus; if consensus is successfully reached, incrementing the node's successful consensus count by 1; if the node fails to reach consensus due to timeout, incrementing the node's timeout count by 1.
[0058] Here, the success reward factor can refer to the reputation value reward coefficient given for successfully reaching consensus. The success reward factor is used to improve the reputation value of nodes that successfully reach consensus.
[0059] The timeout penalty factor refers to the reputation value penalty coefficient given for failing to reach consensus. The timeout penalty factor is used to reduce the reputation value of nodes that fail to reach consensus.
[0060] Specifically, before updating the current reputation value of a node, the values of two parameters are first determined: a success reward factor and a timeout penalty factor. A larger success reward factor results in a higher reputation value reward for reaching consensus, while a larger timeout penalty factor results in a higher reputation value penalty for failing to reach consensus. Both parameters are set values, and those skilled in the art can choose specific values for the success reward factor and timeout penalty factor based on actual circumstances; this application does not impose any limitations on these values. For each node in the consensus unit, if the node successfully reaches consensus in a certain round of consensus, its successful consensus count is incremented by 1; if the node fails to participate in consensus due to timeout in a certain round of consensus, its timeout count is incremented by 1. Thus, regardless of whether a node successfully reaches consensus, its successful consensus count or timeout count will change, representing the node's performance in a consensus process.
[0061] When a node joins the blockchain network, its number of successful consensus attempts and timeout attempts are initialized to 0.
[0062] In one optional embodiment, updating the node's current reputation value based on the node's current reputation value, the number of successful consensuses, and the number of timeouts includes: detecting whether the node engaged in malicious behavior during the current consensus process; if malicious behavior is found, setting the node's current reputation value to 0; if no malicious behavior is found, calculating the product of the success reward factor and the number of successful consensuses to obtain the successful consensus reputation value; calculating the product of the timeout penalty factor and the number of timeouts to obtain the timeout deduction reputation value; calculating the sum of the node's current reputation value and the successful consensus reputation value, and using the difference between the sum and the timeout deduction reputation value as the node's updated current reputation value.
[0063] Specifically, during a consensus process, it is necessary to detect malicious behavior on each node in real time. If malicious behavior is detected, the node's current reputation value is set to 0, and the node is refused participation in subsequent consensus processes. This node also has no right to elect a master node and cannot be elected as a master node. If no malicious behavior is detected, the node's current reputation value is updated according to the following formula:
[0064] C i_2 =C i_1 +αSucc i -βOve i ;
[0065] In the above formula, C i_2 C represents the current reputation value of the i-th node after the update. i_1 Let α represent the current reputation value before the i-th node is updated, β represent the success reward factor, and β represent the timeout penalty factor. i Ove represents the number of successful consensuses. i Indicates the number of times the timeout occurred.
[0066] Malicious behavior refers to nodes engaging in malicious attacks, such as tampering with information or receiving a correct ciphertext message but declaring it as an incorrect ciphertext message.
[0067] Step S104: Determine the probability of the node being selected based on the updated current reputation value of the node.
[0068] In this step, the probability of being selected can refer to the probability of being selected as a master node. The higher the probability of being selected, the higher the likelihood of being selected as a master node, and the lower the probability of being selected, the lower the likelihood of being selected as a master node.
[0069] In this embodiment of the application, each node corresponds to an updated current reputation value. The probability of a node being selected can be determined based on the updated current reputation value of each node. A new master node is selected based on the probability of each node being selected.
[0070] In one optional embodiment, determining the selection probability of a node based on its updated current reputation value includes: calculating the sum of the updated current reputation values of all nodes; and using the ratio of the updated current reputation value of the node to the sum of the updated current reputation values of all nodes as the selection probability of the node.
[0071] Specifically, calculate the sum of the updated current reputation values of all nodes, and take the quotient of the updated current reputation value of the i-th node and the sum of the updated current reputation values of all nodes as the probability of the i-th node being selected. The probability of selection can be calculated using the following formula:
[0072]
[0073] In the above formula, C i_2 P represents the current reputation value of the i-th node after the update. i This represents the probability of the i-th node being selected.
[0074] Step S105: Elect a new master node based on the selection probability of different nodes, switch to the next consensus unit using the new master node, and conduct the next round of consensus in the next consensus unit.
[0075] In this step, the current consensus process corresponds to the current consensus unit. Assuming node 'a' in the current consensus unit is the master node, after determining the selection probability of each node, the blockchain server elects a new master node based on the multiple selection probabilities of different nodes. Assuming node 'b' is elected as the new master node, the next consensus unit is generated with the new master node 'b', and a new round of consensus is conducted within this next consensus unit. The nodes within the next consensus unit remain unchanged; only the master node of the next consensus unit differs from that of the current consensus unit.
[0076] In addition, each consensus unit has its own number. If the current consensus unit number is 9, then the next consensus unit number will be 9+1=10.
[0077] In one optional embodiment, electing a new master node based on the selection probability of different nodes includes: arranging the selection probabilities of different nodes in descending order, and selecting the node with the highest selection probability as the new master node.
[0078] Specifically, assuming there are 50 nodes, these 50 nodes correspond to 50 probabilities of being selected. These probabilities of being selected are arranged in descending order. Suppose that the highest probability of being selected is the probability of node b, then node b is selected as the new master node, that is, as the master node of the next consensus unit.
[0079] In a preferred example, the selection probabilities of different nodes can also be arranged in descending order, and the nodes with the highest selected probabilities can be selected as candidate master nodes. Then, a node can be randomly selected from the candidate master nodes according to the selection probability as the new master node.
[0080] Compared with existing blockchain consensus methods, this application allows the blockchain server to determine whether to update the reputation value of each node, and to determine the current reputation value of each node based on its initial reputation value, the number of successful consensuses, and the number of timeouts. A new master node is elected based on the selection probability corresponding to the current reputation value. It can be seen that the new master node is elected by the blockchain server based on the current reputation values of different nodes, without the need to compete for block production rights through computing power or the amount of coins held. This improves the credibility of master node election and consensus efficiency, and solves the problems of large computational load and poor credibility of master node election in existing consensus algorithms.
[0081] Based on the same inventive concept, this application also provides a blockchain consensus device corresponding to the blockchain consensus method. Since the principle of the device in this application is similar to that of the blockchain consensus method described above in this application, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be described again.
[0082] Please see Figure 2 , Figure 2 This is a schematic diagram of a blockchain consensus device provided in an embodiment of this application. Figure 2 As shown, the blockchain consensus device 200 includes:
[0083] The master node determination module 201 is used to determine the master node of the consensus unit in the current consensus process. The consensus unit includes multiple nodes, which are divided into master nodes and slave nodes. The consensus unit is used to describe the current state of a multi-replica system.
[0084] The update condition determination module 202 is used to determine whether the update condition for updating the reputation value of the node is met based on the consensus process between the master node and the slave node.
[0085] The reputation value calculation module 203 is used to update the current reputation value of each node based on its current reputation value, number of successful consensuses, and number of timeouts if the update conditions are met.
[0086] The probability calculation module 204 is used to determine the probability of a node being selected based on its updated current reputation value.
[0087] The unit update module 205 is used to elect a new master node based on the selection probability of different nodes, and use the new master node to switch to the next consensus unit for the next round of consensus.
[0088] Please see Figure 3 , Figure 3 This is a schematic diagram of the structure of a blockchain consensus system provided in an embodiment of this application. Figure 3As shown in the figure, the blockchain consensus system 300 includes: a blockchain server 310 and a consensus unit 320. The consensus unit 320 includes multiple nodes, which are divided into master nodes and slave nodes.
[0089] Blockchain server 310 executes the above-described blockchain consensus method;
[0090] The master node of consensus unit 320 receives the voting signature sent by the slave node, generates new block information, and sends the new block information to the slave node;
[0091] The secondary node uses a multi-signature algorithm to verify the information of the new block. If the verification is successful, consensus is reached on the data in the new block.
[0092] The consensus process between nodes will be explained in detail below.
[0093] The main consensus process is similar to the HotStuff algorithm, but the algorithms for selecting the leader node and for each vote signature differ.
[0094] The consensus process is pipelined. Each message is a proposal, which includes information about the newly generated block and a quorum certificate (QC). The QC includes a signature generated by the leader node using a multi-signature algorithm, combining messages received from more than two-thirds of the nodes at each stage; the hash value of the new block; and the number of the current consensus unit. A proposal can be understood as a transaction or suggestion, and the QC can be understood as a consensus reached in this transaction or suggestion. The hash value of the new block is calculated based on the attributes of the new block. The hash value algorithm of the new block is existing technology and will not be elaborated here.
[0095] The following two situations will cause the current consensus process to end and switch to the next round of consensus process: one is that consensus is reached in this round, and the other is that the master node fails. Once a new master node is elected and integrated into the preparation phase, it indicates that the process has switched to the next round of consensus process.
[0096] Each round of consensus process is divided into four stages: preparation, pre-submission, submission, and decision. Each stage is explained below.
[0097] When switching consensus units, the server will notify each node which master node the new consensus unit is, and each node will send a New-view message to that master node.
[0098] Phase 1: Preparation Phase.
[0099] The preparation phase begins when the master node receives New-view messages from more than 2 / 3 of the nodes (including the master node itself). Each New-view message contains the latest prepare-QC (the signing certificate for the preparation phase).
[0100] The master node selects the QC with the largest consensus unit number from the prepare-QC as the high-QC and generates the corresponding new block.
[0101] The master node broadcasts a proposal message containing information about the new block to the slave node. After receiving the proposal message, the slave node verifies the proposal message according to the multi-signature algorithm to determine whether the proposal message is correct. If it is correct, it signs the proposal message and generates a prepare-vote message to return to the master node.
[0102] Phase Two: Precommit Phase.
[0103] After the master node receives prepare-vote messages from more than 2 / 3 of the nodes, it indicates that enough nodes have confirmed the state transition request. The master node, acting as the validator, verifies the validity of the signature. If valid, it aggregates the prepare-vote messages into prepare-QC messages to generate a precommit message, which is then broadcast to the slave nodes. The precommit message includes the prepare-QC message.
[0104] After receiving the precommit message, the secondary node verifies the precommit message according to the multi-signature algorithm to check if the precommit message is correct. If it is correct, it signs and generates a precommit-vote message and returns it to the primary node.
[0105] Phase 3: Commit phase.
[0106] Similar to the precommit phase, after receiving precommit-vote messages from more than 2 / 3 of the nodes, the master node verifies the validity of the signature in the precommit-vote message. If valid, it aggregates the precommit-votes into a precommit-QC to generate a commit message and broadcasts the commit message to the slave nodes. The commit message includes the precommit-QC.
[0107] After receiving the commit message, the secondary node verifies its correctness using a multi-signature algorithm. If correct, it generates a commit-vote and returns it to the primary node.
[0108] Simultaneously, the secondary node updates the lock-QC state of other locked new blocks to precommit-QC to maintain pipeline operation. Here, the consensus process of multiple blocks may have reached the commit stage, but the current secondary node can only reach consensus on the QC corresponding to one block, while the QCs of other blocks are in a locked state. Since the current consensus process is nearing completion, the QC locking state of other blocks can be released to facilitate subsequent consensus on other QCs.
[0109] Phase 4: The decision-making phase.
[0110] After the master node receives commit-vote messages from more than 2 / 3 of the nodes, it verifies the validity of the signature in the commit-vote message. If valid, it aggregates them into a commit-QC, generates a decide message, and broadcasts the decide message to the slave nodes. The decide message includes the commit-QC.
[0111] After receiving the decide message, the secondary node confirms its validity and executes the requirements in the block, that is, the secondary node executes the transaction in the proposal pointed to by commit-QC.
[0112] The consensus unit number is incremented by 1 to obtain the number of the next consensus unit, and the next round of consensus units is initiated. At the same time, the number of successful consensuses and the number of timeouts are updated to determine the current reputation value of each node. Then, the node with the highest selection probability is selected as the new master node, and each slave node sends a New-view message to the new master node to complete the replacement of the consensus unit.
[0113] The multi-signature algorithm is explained below.
[0114] The multi-signature algorithm, also known as the MuSig2 signature algorithm, ensures the validity and immutability of the signature through two rounds of communication.
[0115] First step, select signature parameters:
[0116] The signature parameters include: group parameters, hash function H_agg, hash function H_non, and hash function H_sig. The group parameters include: G, p, g, v, m, and n, where G represents a p-order cyclic group, p represents a λ-bit prime number, g represents the generator of G, v represents the number of random public-private key pairs that each node needs to generate in this signature, m is the message to be signed (i.e., the data to be agreed upon), and n is the number of nodes participating in the consensus. The value of v can be selected according to the actual situation. A larger value of v indicates that more random public-private key pairs need to be generated, resulting in higher security but lower computational efficiency; conversely, a smaller value of v indicates that fewer random public-private key pairs need to be generated, resulting in lower security but higher computational efficiency.
[0117] Among them, the domain to range of the three hash functions mentioned above is from [0,1]* to Z. p The `H_agg` function generates the aggregated public key, the `H_non` function aggregates the generated nonce pairs, and the `H_sig` function is used for the final signature. For example, the hash function can be either MD5 or SHA256.
[0118] The second step is to generate the key:
[0119] Each signer generates a random private key x, using the formula x ← $Z p And obtain the public key X corresponding to the random private key x, X = g x .
[0120] The third step is to aggregate the public keys:
[0121] First, let L = {X1, X2, ..., X} n} represents the set of public keys obtained by the n signing nodes in the previous step, where X is the public key X. i The aggregated public key can be calculated using the following formula for ∈L.
[0122] a i =H agg (L, X) i );
[0123]
[0124] In the above formula, a i Let be the aggregation coefficient of the i-th node.
[0125] Step 4, First round of signatures:
[0126] For j∈{1,…,v} (where v represents the number of random public-private key pairs in the group parameters, and j represents the nth public-private key pair), each signer node follows the formula r. 1,j ←$Z pGenerate a random private key r 1,j r 1,j This represents the j-th random private key of node number 1.
[0127] The following formula is used to calculate (R) 1,1 ,…,R 1,v ), and (R 1,1 ,…,R 1,v The result is sent to the master node, and the other nodes perform similar calculations to obtain (R). 2,1 ,…,R 2,v ),…,(R n,1 ,…,R n,v This is sent to the master node. The calculation formula is as follows:
[0128]
[0129] The master node receives (R) from other nodes i,1 ,…,R i,v ) calculate R j We get (R1,R2,…,R) v ), and set (R1,R2,…,R) v ) Broadcast to all signatories. Among them, R j The calculation formula is as follows:
[0130]
[0131] Where i∈{1,…,n}, j∈{1,…,v}.
[0132] Step 5, Second round of signatures:
[0133] Based on the (R1,R2,…,R) obtained during the first round of signing v ) and the aggregated public key The signature information s1 is calculated using the following formula:
[0134]
[0135]
[0136]
[0137]
[0138] In the above formula, m is a parameter in the group parameters, representing the information to be signed, a1 represents the aggregation coefficient of node number 1, p is a parameter in the group parameters, representing the λ-bit prime number, and x1 is the signer's private key.
[0139] After obtaining the signature information s1, the master node broadcasts s1 to other nodes, and the other nodes perform the same calculation. The master node then receives the signature information (s2, ..., s1) returned by the other nodes. n After that, the master node uses the signature information from each node to calculate the signature. The formula for calculating s is as follows:
[0140]
[0141] Step 6, Verification:
[0142] The verifier uses the given aggregate public key. Message m and signature like This proves the signature. Returns true if valid, otherwise returns false. The validator can be either a master node or a slave node.
[0143] Please see Figure 4 , Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 4 As shown, the electronic device 400 includes a processor 410, a memory 420, and a bus 430.
[0144] The memory 420 stores machine-readable instructions executable by the processor 410. When the electronic device 400 is running, the processor 410 communicates with the memory 420 via the bus 430. When the machine-readable instructions are executed by the processor 410, they can perform the operations described above. Figure 1 The steps of the blockchain consensus method in the illustrated method embodiment can be found in the method embodiment for specific implementation, and will not be repeated here.
[0145] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0146] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Additionally, the shown or discussed mutual couplings, direct couplings, or communication connections may be through some communication interfaces; indirect couplings or communication connections between devices or units may be electrical, mechanical, or other forms.
[0147] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0148] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0149] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a processor-executable, non-volatile, computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0150] Finally, it should be noted that the above-described embodiments are merely specific implementations of this application, used to illustrate the technical solutions of this application, and not to limit them. The scope of protection of this application is not limited thereto. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features, within the scope of the technology disclosed in this application. Such modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be covered within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A blockchain consensus method, characterized in that, Applied to a blockchain server, the method includes: In this round of consensus process, the master node of the consensus unit is determined. The consensus unit includes multiple nodes, which are divided into master nodes and slave nodes. The consensus unit is used to describe the current state of a multi-replica system. Based on the consensus process between the master node and the slave node, determine whether the update conditions for updating the node reputation value are met. If the update conditions are met, for each node, update the node's current reputation value based on the node's current reputation value, number of successful consensuses, and number of timeouts; The probability of a node being selected is determined based on its updated current reputation value. A new master node is elected based on the selection probability of different nodes, and the new master node is used to switch to the next consensus unit for the next round of consensus. Before updating the node's current reputation value based on its current reputation value, number of successful consensuses, and number of timeouts, the following steps are also included: Determine the values of the success reward factor and the timeout penalty factor; Determine whether the node has successfully reached a consensus with other nodes during this round of consensus process; If consensus is successfully reached, the success count of that node will be incremented by 1. If a node fails to reach consensus due to timeout, the timeout count for that node will be incremented by 1. The process of updating the node's current reputation value based on its current reputation value, number of successful consensuses, and number of timeouts includes: Detect whether the node engaged in malicious behavior during this consensus process; If malicious behavior is detected, the node's current reputation value will be set to 0. If there is no malicious behavior, the reputation value of the current master node is updated based on the current reputation value, the product of the success reward factor and the number of successful consensuses, and the product of the timeout penalty factor and the number of timeouts.
2. The method according to claim 1, characterized in that, Before determining the master node of the consensus unit in this round of consensus process, the following is also included: For each node in the consensus unit, an initial reputation value is assigned to that node based on its node information; The node with the highest initial reputation value in the consensus unit is selected as the initial master node.
3. The method according to claim 1, characterized in that, The determination of whether the update conditions for updating the node reputation value are met includes: Determine whether the current consensus process has ended or whether the secondary node has detected an error in the primary node; If the current consensus process ends or the secondary node detects an error in the primary node, it is determined that the conditions for updating the node's reputation value have been met.
4. The method according to claim 1, characterized in that, The step of updating the reputation value of the current master node based on the current reputation value, the product of the success reward factor and the number of successful consensuses, and the product of the timeout penalty factor and the number of timeouts includes: The success consensus reputation value is obtained by multiplying the success reward factor by the number of successful consensuses. The timeout penalty factor is calculated by multiplying it by the number of timeouts to obtain the timeout deduction reputation value; Calculate the sum of the node's current reputation value and the successful consensus reputation value, and use the difference between the sum and the reputation value deducted for timeout as the node's updated current reputation value.
5. The method according to claim 1, characterized in that, The process of determining the probability of a node being selected based on its updated current reputation value includes: Calculate the sum of the updated current reputation values of all nodes; The probability of a node being selected is the ratio of its updated current reputation value to the sum of the updated current reputation values of all nodes.
6. The method according to claim 1, characterized in that, The election of a new master node based on the selection probability of different nodes includes: The nodes with the highest probability of being selected are arranged in descending order, and the node with the highest probability of being selected is selected as the new master node.
7. A blockchain consensus device, characterized in that, include: The master node determination module is used to determine the master node of the consensus unit in the current consensus process. The consensus unit includes multiple nodes, which are divided into master nodes and slave nodes. The consensus unit is used to describe the current state of a multi-replica system. The update condition determination module is used to determine whether the update condition for updating the reputation value of the node is met based on the consensus process between the master node and the slave node. The reputation value calculation module is used to update the current reputation value of each node based on its current reputation value, number of successful consensuses, and number of timeouts if the update conditions are met. The probability calculation module is used to determine the probability of a node being selected based on its updated current reputation value. The unit update module is used to elect a new master node based on the selection probability of different nodes, and use the new master node to switch to the next consensus unit for the next round of consensus. The blockchain consensus device is also used for: Determine the values of the success reward factor and the timeout penalty factor; Determine whether the node has successfully reached a consensus with other nodes during this round of consensus process; If consensus is successfully reached, the success count of that node will be incremented by 1. If a node fails to reach consensus due to timeout, the timeout count for that node will be incremented by 1. The reputation value calculation module is specifically used for: Detect whether the node engaged in malicious behavior during this consensus process; If malicious behavior is detected, the node's current reputation value will be set to 0. If there is no malicious behavior, the reputation value of the current master node is updated based on the current reputation value, the product of the success reward factor and the number of successful consensuses, and the product of the timeout penalty factor and the number of timeouts.
8. A blockchain consensus system, characterized in that, The system includes: a blockchain server and a consensus unit, wherein the consensus unit includes multiple nodes, and the multiple nodes are divided into master nodes and slave nodes; The blockchain server executes the blockchain consensus method as described in any one of claims 1 to 6; The master node of the consensus unit receives the voting signature sent by the slave node, generates new block information, and sends the new block information to the slave node; The secondary node uses a multi-signature algorithm to verify the information of the new block. If the verification is successful, consensus is reached on the data in the new block.
9. An electronic device, characterized in that, include: The device includes a processor, a storage medium, and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the storage medium via the bus, and the processor executes the machine-readable instructions to perform the steps of the blockchain consensus method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Dynamic hierarchical Byzantine fault-tolerant consensus method based on credit
CN110677485A
Improved PBFT block chain consensus method
CN111414420A
Node reputation consensus method based on block chain
CN112039964A
