Node consensus method and apparatus, and electronic device, storage medium and program product
By recording the number of proposal generation times in the distributed system, screening abnormal nodes, and using the voting mechanism to delete faulty nodes, the problem of faulty nodes affecting performance in the distributed system is solved, and the efficiency and stability of the blockchain network are improved.
Patent Information
- Application Number
- PCT/CN2023/132503
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-04-20
- Filing Date
- 2023-11-20
- Publication Date
- 2024-10-24
AI Technical Summary
When there are faulty nodes in the distributed system, the performance of the consensus network is reduced. It is difficult for existing technology to effectively identify and delete abnormal nodes, which affects the efficiency of the blockchain network.
By recording the number of proposal generation times in the consensus node, nodes with a number of proposal generation times lower than the threshold are filtered out as abnormal nodes, and the node identification is carried for voting in the pre-voting and pre-submission phases to reach consensus and delete abnormal nodes.
It ensures that the nodes participating in the consensus are all normal nodes, improves the performance and stability of the entire blockchain network, and achieves safe and correct deletion of faulty nodes.
Smart Images

Figure CN2023132503_24102024_PF_FP_ABST
Abstract
Description
Node consensus method, device, electronic device, storage medium, and program product
[0001] This application claims priority to the Chinese patent application with application number 202310458586.5 filed on April 20, 2023, and invention name “Node consensus method and related device”. Technical Field
[0002] The present application relates to the field of computer technology and provides a node consensus method, device, electronic device, storage medium and program product. Background Art
[0003] With the continuous development of computer technology, distributed systems are now widely used computing systems, and are applied in many fields such as blockchain and the ZooKeeper distributed service framework. During the operation of distributed systems, it is necessary to reach a consensus on the pending messages from client devices.
[0004] In related technologies, consensus mainly includes three stages: proposal, prevote, and precommit. Taking four consensus nodes as an example (which can include one master node and three slave nodes), the consensus process is as follows:
[0005] After receiving the consensus request from the client device, the master node generates a proposal and then broadcasts it to each slave node. After receiving the proposal, each slave node enters the pre-voting phase, where it generates a prevote vote (if the slave node does not receive a proposal within the timer, it generates a prevote vote for an empty proposal) and broadcasts its prevote vote to other nodes.
[0006] After receiving more than 2 / 3+1≈3 prevote votes, each node enters the pre-commit phase, generates a precommit vote, and broadcasts its own precommit vote to other nodes.
[0007] After receiving 2 / 3+1≈3 precommit votes, each node enters the submission phase. During the submission phase, if the consensus proposal is an empty proposal, the proposal will not be submitted.
[0008] Summary of the Invention
[0009] The embodiments of the present application provide a node consensus method and related devices to improve consensus efficiency and enhance the performance of distributed systems.
[0010] In a first aspect, an embodiment of the present application provides a node consensus method, applied to a consensus node, the method comprising:
[0011] When the target proposal is obtained and the total number of proposal generation recorded locally reaches the total number threshold, based on the proposal generation numbers corresponding to each of the multiple consensus nodes in the distributed system recorded locally, the abnormal nodes that meet the set node abnormality conditions are screened out from the multiple consensus nodes, where the multiple consensus nodes include the consensus node;
[0012] Sending a first vote of a pre-voting phase to other consensus nodes among the multiple consensus nodes except the consensus node, and receiving one or more first votes of the pre-voting phase sent by the other consensus nodes, wherein the first vote sent by the consensus node carries a node identifier of the abnormal node;
[0013] When the number of the first votes carrying the node identifier of the abnormal node in the received one or more first votes reaches a first vote threshold, sending a second vote in the pre-commit phase to the other consensus nodes, and receiving one or more second votes in the pre-commit phase sent by the other consensus nodes, wherein the second vote sent by the consensus node carries the node identifier of the abnormal node;
[0014] When the number of second votes carrying the node identifier of the abnormal node in the received one or more second votes reaches a second vote threshold, it is determined that consensus is reached on the target proposal, and the abnormal node is deleted from the multiple consensus nodes recorded locally.
[0015] In a second aspect, an embodiment of the present application provides a node consensus device, including:
[0016] a screening unit configured to, when a target proposal is acquired and the total number of proposal generation recorded locally reaches a total number threshold, screen out abnormal nodes that meet a set node abnormality condition from a plurality of consensus nodes in the distributed system based on the number of proposal generation times corresponding to the respective consensus nodes recorded locally, wherein the plurality of consensus nodes include the consensus node;
[0017] a pre-voting unit, configured to send a first vote of a pre-voting phase to other consensus nodes among the plurality of consensus nodes except the consensus node, and receive one or more first votes of the pre-voting phase sent by the other consensus nodes, wherein the first vote sent by the consensus node carries a node identifier of the abnormal node;
[0018] a pre-submission unit, configured to, when the number of first votes carrying the node identifier of the abnormal node in the received one or more first votes reaches a first vote threshold, send a second vote of the pre-submission phase to the other consensus nodes, and receive one or more second votes of the pre-submission phase sent by the other consensus nodes, wherein the second vote sent by the consensus node carries the node identifier of the abnormal node;
[0019] A node adjustment unit is configured to determine that a consensus has been reached on the target proposal when the number of second votes carrying the node identifier of the abnormal node in one or more received second votes reaches a second vote threshold, and to delete the abnormal node from the multiple consensus nodes recorded locally.
[0020] As a possible implementation manner, the screening unit is further configured to:
[0021] During each round of consensus, if the multiple consensus nodes reach a consensus on a non-empty proposal generated by the master node, the number of proposal generation times corresponding to the master node is accumulated and the total number of proposal generation times is updated, where the master node is one of the multiple consensus nodes.
[0022] As a possible implementation, the consensus node locally records node proposal mapping information, where the node proposal mapping information includes: node identifiers of the plurality of consensus nodes and corresponding proposal generation times;
[0023] The screening unit is used to determine the total number of proposal generation times recorded locally by:
[0024] From the node proposal mapping information, obtain the number of proposal generation times corresponding to each of the multiple consensus nodes; and determine the total number of proposal generation times based on the obtained number of proposal generation times corresponding to each of the multiple consensus nodes.
[0025] As a possible implementation, based on the locally recorded number of proposal generation times corresponding to the multiple consensus nodes in the distributed system, when screening out abnormal nodes that meet the set node abnormality conditions from the multiple consensus nodes, the screening unit is specifically configured to:
[0026] Selecting, from the plurality of consensus nodes, at least one consensus node whose number of proposal generation is lower than a proposal generation threshold;
[0027] A consensus node among the at least one consensus node is determined as an abnormal node that meets a set node abnormality condition.
[0028] As a possible implementation manner, when determining one of the at least one consensus node as an abnormal node that meets the set node abnormality condition, the screening unit is specifically configured to:
[0029] If the number of the at least one consensus node is one, the selected consensus node is regarded as an abnormal node that meets the set node abnormality condition;
[0030] If the number of the at least one consensus node is more than one, then based on the number of proposal generation times corresponding to each of the at least one consensus nodes, one consensus node is determined from the more than one consensus nodes screened out, and the determined consensus node is used as an abnormal node that meets the set node abnormality condition.
[0031] As a possible implementation manner, after deleting the abnormal node from the multiple consensus nodes, the screening unit is further configured to:
[0032] Reset the locally recorded number of proposal generation times corresponding to the remaining consensus nodes in the distributed system;
[0033] Resets the local record of the total number of proposals generated.
[0034] As a possible implementation manner, the screening unit is further configured to:
[0035] If the consensus node is a master node, after obtaining a consensus request for target transaction information from a client device, generating the target proposal for the target transaction information;
[0036] If the consensus node is a slave node, the target proposal is obtained through the master node.
[0037] As a possible implementation, when obtaining the target proposal through the master node, the screening unit is specifically configured to:
[0038] If a proposal is received from the master node within a set time period starting from when the master node obtains the consensus request from the client device, the proposal from the master node is used as the target proposal;
[0039] If no proposal is received from the master node within a set time period starting from when the master node obtains the consensus request from the client device, an empty proposal is used as the target proposal.
[0040] In a third aspect, an embodiment of the present application provides an electronic device comprising a processor and a memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the above-mentioned node consensus method.
[0041] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, which includes a computer program. When the computer program is run on an electronic device, the computer program is used to enable the electronic device to execute the steps of the above-mentioned node consensus method.
[0042] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a computer program stored in a computer-readable storage medium. The processor of an electronic device reads and executes the computer program from the computer-readable storage medium, so that the electronic device performs the steps of the above-mentioned node consensus method.
[0043] In an embodiment of the present application, when one of the multiple consensus nodes in a distributed system obtains a target proposal and the total number of proposal generation times recorded locally reaches a total number threshold, the consensus node is screened out from the multiple consensus nodes based on the number of proposal generation times corresponding to each of the multiple consensus nodes recorded locally. Then, the consensus node carries the node identifier of the abnormal node in its first vote in the pre-voting phase and broadcasts its own first vote to the other consensus nodes in the multiple consensus nodes except the consensus node. At the same time, the consensus node also receives the first votes sent by other consensus nodes in the pre-voting phase. When the number of received first votes carrying the node identifier of the abnormal node reaches a first vote threshold, the consensus node broadcasts the second vote of the pre-submission phase carrying the node identifier of the abnormal node and receives the second votes of the pre-submission phase sent by other consensus nodes. Further, when the number of received second votes carrying the node identifier of the abnormal node reaches a second vote threshold, the consensus node determines that a consensus has been reached on the target proposal and deletes the abnormal node from the multiple consensus nodes recorded locally.
[0044] In this way, the consensus nodes in the distributed system analyze the historical proposal records and attach the node identifiers of abnormal nodes in the first and second votes. Finally, through the security guarantee of the Byzantine consensus protocol itself, all nodes are guaranteed to consistently kick abnormal nodes out of the consensus node list. Therefore, when facing node failures, the entire consensus network can safely and correctly delete abnormal nodes, and ultimately ensure that the nodes participating in the consensus are normal nodes as much as possible, thereby greatly improving the performance of the entire blockchain network.
[0045] Other features and advantages of the present application will be described in the following description, and in part will become apparent from the description, or will be understood by practicing the present application. The purposes and other advantages of the present application can be realized and obtained by the structures particularly pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0047] FIG1 is a schematic diagram of the structure of a data sharing system provided in an embodiment of the present application;
[0048] FIG2A is a schematic diagram of the structure of a blockchain provided in an embodiment of the present application;
[0049] FIG2B is a logic diagram of a block generation process provided in an embodiment of the present application;
[0050] FIG3 is a schematic diagram of a process flow of a node consensus method provided in an embodiment of the present application;
[0051] FIG4 is a logical diagram of a node consensus process provided in an embodiment of the present application;
[0052] FIG5 is a schematic diagram of a node proposal map provided in an embodiment of the present application;
[0053] FIG6 is a logic diagram of another node consensus process provided in an embodiment of the present application;
[0054] FIG7 is a schematic diagram of an initial node proposal map provided in an embodiment of the present application;
[0055] FIG8 is a logical diagram of the first round of consensus process provided in an embodiment of the present application;
[0056] FIG9 is a schematic diagram of a node proposal map after the first round of consensus provided in an embodiment of the present application;
[0057] FIG10 is a schematic diagram of a node proposal map during a multi-round consensus process provided in an embodiment of the present application;
[0058] FIG11 is a logic diagram of the fourth round of consensus process provided in an embodiment of the present application;
[0059] FIG12A is a logical diagram of a consensus process provided in an embodiment of the present application;
[0060] FIG12B is a schematic diagram of a node proposal map after abnormal nodes are deleted, provided in an embodiment of the present application;
[0061] FIG13 is a schematic diagram of the structure of a node consensus device provided in an embodiment of the present application;
[0062] FIG14 is a schematic structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0063] To make the purpose, technical solutions, and advantages of the embodiments of the present application clearer, the technical solutions of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the technical solutions of the present application, not all of them. Based on the embodiments described in this application document, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the technical solutions of the present application.
[0064] The terms "first" and "second" in the embodiments of the present application are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or device that includes a series of steps or modules is not limited to the listed steps or modules, but may optionally include steps or modules that are not listed, or may optionally include other steps or modules that are inherent to the process, method, product, or device.
[0065] In this application, "multiple" can mean at least two, for example, two, three, or more, and this is not a limitation in the embodiments of this application. "And / or" describes the relationship between associated objects, indicating that three relationships can exist. For example, A and / or B can mean: A exists alone, A and B exists simultaneously, and B exists alone. The character " / " generally indicates that the associated objects are in an "or" relationship.
[0066] As mentioned above, in related technologies, consensus mainly includes three stages: Proposal, Prevote, and Precommit (different Byzantine algorithms may have different names, but their core processing flow is the same). Taking four consensus nodes as an example (which can include one master node and three slave nodes), the consensus process is as follows:
[0067] After receiving the consensus request from the client device, the master node generates a proposal and then broadcasts it to each slave node. After receiving the proposal, each slave node enters the pre-voting phase, where it generates a prevote vote (if the slave node does not receive a proposal within the timer, it generates a prevote vote for an empty proposal) and broadcasts its prevote vote to other nodes.
[0068] After receiving three prevote votes, each node enters the pre-commit phase, generates a precommit vote, and broadcasts its own precommit vote to other nodes.
[0069] After each node receives 3 precommit votes, it enters the submission phase. During the submission phase, if the consensus proposal is an empty proposal, the proposal will not be submitted.
[0070] To ensure fairness and security, a node is typically switched to become the master node after each consensus is completed. However, if a faulty node among the consensus nodes becomes the master node, it will be unable to generate proposals and send them to other nodes for consensus. This will cause other nodes to cast blank votes after a timer expires, leading to a null consensus. A healthy node will then be switched to become the master node, generating proposals and reaching consensus. Obviously, the presence of faulty nodes in a distributed system significantly degrades its performance.
[0071] In an embodiment of the present application, when one of the multiple consensus nodes in a distributed system obtains a target proposal and the total number of proposal generation times recorded locally reaches a total number threshold, the consensus node is screened out from the multiple consensus nodes based on the number of proposal generation times corresponding to each of the multiple consensus nodes recorded locally. Then, the consensus node carries the node identifier of the abnormal node in its first vote in the pre-voting phase and broadcasts its own first vote to the other consensus nodes in the multiple consensus nodes except the consensus node. At the same time, the consensus node also receives the first votes sent by other consensus nodes in the pre-voting phase. When the number of received first votes carrying the node identifier of the abnormal node reaches a first vote threshold, the consensus node broadcasts the second vote of the pre-submission phase carrying the node identifier of the abnormal node and receives the second votes of the pre-submission phase sent by other consensus nodes. Further, when the number of received second votes carrying the node identifier of the abnormal node reaches a second vote threshold, the consensus node determines that a consensus has been reached on the target proposal and deletes the abnormal node from the multiple consensus nodes recorded locally. In this way, the consensus nodes in the distributed system analyze historical proposal records and include the node identifiers of abnormal nodes in the first and second votes. Finally, through the security guarantees of the Byzantine consensus protocol itself, all nodes are guaranteed to consistently remove abnormal nodes from the consensus node list. Therefore, in the face of node failures, the entire consensus network can safely and correctly remove abnormal nodes, ultimately ensuring that all nodes participating in the consensus are normal nodes as much as possible, significantly improving the performance of the entire blockchain network.
[0072] Refer to Figure 1, which is a structural diagram of a data sharing system provided in an embodiment of the present application. A data sharing system 200 refers to a system for sharing data between nodes. The data sharing system may include multiple nodes 201, and multiple nodes 201 may refer to, for example, individual client devices in the data sharing system. Each node 201 can receive input information when performing normal operation, and maintain the shared data in the data sharing system based on the received input information. In order to ensure information intercommunication within the data sharing system, an information connection may exist between each node in the data sharing system, and information can be transmitted between nodes through the above-mentioned information connection. For example, when any node in the data sharing system receives input information, other nodes in the data sharing system obtain the input information according to the consensus algorithm, and store the input information as data in the shared data, so that the data stored on all nodes in the data sharing system are consistent.
[0073] Each node in the data sharing system has a corresponding node identifier, and each node in the data sharing system can store the node identifiers of other nodes in the data sharing system so that the generated blocks can be broadcast to other nodes in the data sharing system based on the node identifiers of other nodes. Each node can maintain a node identifier list as shown in the following table, and store the node name and node identifier in the node identifier list accordingly. Among them, the node identifier can be the Internet Protocol (IP) address of the interconnection protocol between networks or any other information that can be used to identify the node. Table 1 only uses the IP address as an example for explanation.
[0074] Table 1 Node identification list
[0075] Each node in the data sharing system stores an identical blockchain. Figure 2A is a schematic diagram of the structure of a blockchain provided in an embodiment of the present application. Referring to Figure 2A, a blockchain is composed of multiple blocks. The earliest block constructed in the blockchain is called the genesis block. The genesis block includes a block header and a block body. The block header stores the input information feature value, version number, timestamp, and difficulty value, while the block body stores the input information. The next block of the genesis block uses the genesis block as its parent block. This next block also includes a block header and a block body. The block header stores the input information feature value of the current block, the block header feature value, version number, timestamp, and difficulty value of the parent block. Similarly, the block data stored in each block in the blockchain is associated with the block data stored in the parent block, ensuring the security of the input information in the block.
[0076] Figure 2B is a logical diagram of a block generation process provided in an embodiment of the present application. Referring to Figure 2B, when generating each block in the blockchain, the node where the blockchain is located (for example, the current node) verifies the input information when receiving the input information from the entire network. After completing the verification, the input information is stored in the memory pool and the hash tree used to record the input information is updated. Afterwards, the current node updates the update timestamp to the time when the input information is received, and tries different random numbers, performing eigenvalue calculations multiple times so that the calculated eigenvalues can satisfy the following formula: SHA256(SHA256(version+prev_hash+merkle_root+ntime+nbits+x))<TARGET
[0077] Among them, SHA256 is the eigenvalue algorithm used to calculate the eigenvalue; version (version number) is the version information of the relevant block protocol in the blockchain; prev_hash is the block header eigenvalue of the parent block of the current block; merkle_root is the eigenvalue of the input information; ntime is the update time of the update timestamp; nbits is the current difficulty, which is a fixed value within a period of time and is determined again after exceeding the fixed time period; x is a random number; TARGET is the eigenvalue threshold, which can be determined based on nbits.
[0078] Thus, when a random number (x) that satisfies the above formula is calculated, the input information can be stored accordingly, generating a block header and block body, and obtaining the current block. Subsequently, the current node sends the newly generated block to other nodes in the data sharing system based on the node identifiers of other nodes in the data sharing system. The other nodes verify the newly generated block and, after verification, add it to the blockchain stored by the other nodes.
[0079] See Figure 3, which is a schematic diagram of a node consensus method provided in an embodiment of the present application. This process is applied to consensus node x. Consensus node x can be any consensus node among multiple consensus nodes in a distributed system. The specific process of the node consensus method is as follows.
[0080] S301: When a target proposal is obtained and the total number of proposal generation recorded locally reaches a total number threshold, consensus node x selects abnormal nodes that meet a set node abnormality condition from multiple consensus nodes in the distributed system based on the locally recorded number of proposal generation times corresponding to each of the multiple consensus nodes. The multiple consensus nodes include consensus node x.
[0081] For example, before executing S301, during each round of consensus, if multiple consensus nodes reach a consensus on a non-empty proposal generated by a master node, the number of proposals generated by the master node is accumulated, and the total number of proposals generated is updated. The master node is one of the multiple consensus nodes.
[0082] Specifically, multiple consensus nodes reaching a consensus on a non-empty proposal generated by the master node may, for example, mean that multiple consensus nodes reach a consensus on a proposal generated by the master node in the pre-submission phase, and the proposal is a non-empty proposal; or it may mean that multiple consensus nodes reach a consensus on a proposal generated by the master node in the submission phase (if the proposal reached consensus on in the pre-submission phase is an empty proposal, the consensus nodes will not submit this empty proposal).
[0083] The total number of proposal generation times is the sum of the number of proposal generation times corresponding to multiple consensus nodes.
[0084] The number of proposals generated is accumulated each time (each round of consensus). For example, during a round of consensus, if multiple consensus nodes reach a consensus on a non-empty proposal generated by the master node, the number of proposals generated by the master node is increased by 1 (the set value is 1), and the total number of proposals generated is increased by 1 accordingly.
[0085] Figure 4 is a logical diagram of a node consensus process provided in an embodiment of the present application. Referring to Figure 4, the node consensus process is illustrated by taking node 1, node 2, node 3 and node 4 as examples. In a round of consensus, node 1 becomes the master node. After receiving a consensus request from a client device, node 1 generates proposal 1 and broadcasts proposal 1 to node 2, node 3 and node 4, entering the pre-voting stage. In the pre-voting stage, node 1 generates a prevote vote and broadcasts its own prevote vote to node 2, node 3 and node 4. After receiving proposal 1, each node in node 2, node 3 and node 4 enters the pre-voting stage. In the pre-voting stage, it generates a prevote vote and broadcasts its own prevote vote to other nodes. After receiving a prevote vote of 2×4 / 3+1≈3, each node in node 1, node 2, node 3 and node 4 enters the pre-commit stage, generates a precommit vote, and broadcasts its own precommit vote to other nodes. After receiving 2×4 / 3+1≈3 precommit votes, each of Nodes 1, 2, 3, and 4 enters the commit phase. During the commit phase, if Proposal 1 is not an empty proposal, each of Nodes 1, 2, 3, and 4 commits the proposal. This means that Nodes 1, 2, 3, and 4 reach consensus on Proposal 1. Each node then adds 1 to the number of proposals generated for Node 1 and updates the total number of proposals generated by 1.
[0086] As a possible implementation, the number of proposals generated by each consensus node and the total number of proposals generated by all consensus nodes can be recorded in the node proposal mapping information, that is, the node proposal mapping information is recorded locally. The node proposal mapping table contains: the node identifiers of multiple consensus nodes and their corresponding proposal generation counts.
[0087] For example, the node proposal mapping information takes the form of key-value pairs. Node proposal mapping information can also be called a node map, where the key is the node identifier of each consensus node and the value is the number of proposals generated by the corresponding consensus node. The proposal generation number is a natural number, with an initial value of 0.
[0088] Each node identifier is used to uniquely identify a consensus node. The node identifier can be represented by a serial number (ID) or an Internet Protocol (IP) address, but is not limited thereto.
[0089] Figure 5 is a schematic diagram of a node proposal map provided in an embodiment of the present application. For example, referring to Figure 5, in the node mapping map, the key includes the node identifiers: nodeID1, nodeID2, nodeID3, and nodeID4, and the value is the number of proposals generated by the consensus node corresponding to the node identifier. For example, nodeID1 is the node identifier of node 1, nodeID2 is the node identifier of node 2, nodeID3 is the node identifier of node 3, and nodeID4 is the node identifier of node 4. Assume that the initial value of value is 0. During the first round of consensus, each consensus node reaches a consensus on the non-empty proposal generated by node 1, and the number of proposals generated by node 1, node 2, node 3, and node 4 are 1, 0, 0, 0, respectively. Then, value is 1, 0, 0, 0. During the second round of consensus, each consensus node reaches a consensus on the non-empty proposal generated by node 2, and the number of proposals generated by node 1, node 2, node 3, and node 4 are 1, 1, 0, 0, respectively. Then, value is 1, 1, 0, 0.
[0090] In an embodiment of the present application, the total number of proposal generation recorded locally can be determined by the following method: obtaining the number of proposal generation corresponding to each consensus node from the node proposal mapping table; and determining the total number of proposal generation based on the obtained number of proposal generation.
[0091] For example, referring to Table 5, after the second round of consensus, from the node proposal mapping table, the proposal generation times of node 1, node 2, node 3, and node 4 are 1, 1, 0, and 0 respectively. Based on the obtained proposal generation times, the total proposal generation times are determined to be 2.
[0092] In the embodiment of the present application, when obtaining a target proposal, there are but are not limited to the following two possible situations:
[0093] Case 1: Consensus node x is the master node. After receiving the consensus request for the target transaction information from the client device, it generates a target proposal for the target transaction information.
[0094] In this embodiment of the present application, target transaction information refers to information that requires consensus among multiple consensus nodes. Target transaction information includes, but is not limited to, electronic currency transaction records, shared ledger operation records, smart contracts, etc.
[0095] For example, if the consensus node x is node 1, assuming that node 1 is the master node, then after receiving the consensus request for the target transaction information from the client device, node 1 generates a target proposal for the target transaction information.
[0096] Case 2: Consensus node x is a slave node, and the target proposal is obtained through the master node.
[0097] To ensure stable algorithm operation, each consensus node uses a timer during the Proposal phase to wait for the master node to generate a proposal. If a slave node does not receive a proposal from the master node within a set time (measured by the timer), the slave node will vote on an empty proposal to ensure the algorithm can continue and enter the next round of consensus as quickly as possible.
[0098] In the embodiment of the present application, in order to ensure that the master node can generate a proposal on time, the set time length is generally set to a longer value, such as 30 seconds (s).
[0099] Specifically, for a slave node, if a proposal is received from the master node within the set time from the time the master node obtains the consensus request from the client device, the proposal will be used as the target proposal; if no proposal is received from the master node within the set time from the time the master node obtains the consensus request from the client device, an empty proposal will be used as the target proposal.
[0100] For example, let's assume that consensus node x is node 2. Assume that node 1 is the master node, node 2 is the slave node, and the set duration is 30 seconds. If node 2 receives a proposal from node 1 within the set duration from receiving the consensus request from the client device from node 1, it uses that proposal as the target proposal. If it does not receive a proposal from node 1 within the set duration from receiving the consensus request from the client device from node 1, it uses an empty proposal as the target proposal.
[0101] Specifically, during S301, when the target proposal is obtained and the total number of proposal generation recorded locally reaches the total number threshold, consensus node x selects at least one consensus node from multiple consensus nodes whose proposal generation number is lower than the proposal generation threshold. Consensus node x then identifies one of the at least one consensus nodes as an abnormal node that meets the set node abnormality condition. The proposal generation threshold is determined based on the proposal generation number corresponding to each consensus node.
[0102] Specifically, when consensus node x identifies one of at least one consensus node as an abnormal node that meets the set node abnormality condition, it may adopt, but is not limited to, the following methods:
[0103] If the number of at least one consensus node is one, then the consensus node x will select one of the consensus nodes as an abnormal node that meets the set node abnormality conditions;
[0104] If there is more than one consensus node, consensus node x determines one consensus node from the selected consensus nodes based on the number of proposals generated by the at least one consensus node, and regards the determined consensus node as an abnormal node that meets the set node abnormality conditions.
[0105] The proposal generation threshold can be determined based on the average number of proposal generation times corresponding to each consensus node. For example, 1 / 10 of the average number of proposal generation times of all consensus nodes (the total number of proposal generation times, for example, equal to the total number threshold) can be used as the proposal generation threshold. In the embodiment of the present application, only the average number of proposal generation times of all consensus nodes is used as an example. In actual application, other statistical values such as the median can also be used.
[0106] When determining a consensus node from the multiple consensus nodes screened out, the consensus node with the least number of proposal generation times can be used as the determined consensus node; or any consensus node from the multiple consensus nodes screened out can be used as the determined consensus node. There is no limitation on this and it will not be elaborated here.
[0107] Take the total number threshold of 1000 as an example. Since each consensus node records the situation of the most recent 1000 proposals generated, when a node becomes the master node, other nodes analyze the situation of the most recent 1000 proposals generated. Under normal circumstances, the number of proposals generated by each consensus node should be average in the records of the most recent 1000 proposals generated. If the number of proposals generated by a consensus node in the records of the most recent 1000 proposals generated is lower than the proposal generation threshold (for example, 1 / 10 of the average number of proposals generated), then this node is an abnormal node (also called a faulty node). Consensus nodes can vote to kick abnormal nodes out of consensus, thereby ensuring that all consensus nodes participating in the consensus are normal nodes.
[0108] Take four consensus nodes as an example. For the last 1000 proposals generated, if the consensus node is a node with normal system resources and normal operation, then the number of proposals generated by this node should be close to 250. However, if a consensus node only generates 25 proposals in the last 1000 proposals, then other nodes can determine that this consensus node is an abnormal node. An abnormal node may be operating abnormally due to a downtime or network failure. If it is a node with normal system resources and normal operation, its last 1000 historical proposals will not be only 1 / 10 of the average number of proposals generated. Therefore, when the 1001th proposal is generated, based on the historical proposals, the consensus nodes can vote to kick out the abnormal node whose last 1000 proposals are less than 1 / 10 of the average number of proposals generated.
[0109] For example, let's assume that node 1 is the master node, and nodes 2, 3, and 4 are all slave nodes. The total number of times threshold is 1000, and the proposal generation threshold is 1 / 10 of the average number of proposal generation times, which is 1000 / 4 × 1 / 10 = 25. For example, the proposal generation times for nodes 1, 2, 3, and 4 are 340, 320, 320, and 20, respectively. Let's take node 1 as an example. When node 1 obtains the target proposal and the total number of proposal generation times recorded in its local record reaches 1000, node 1 selects at least one consensus node from all consensus nodes whose proposal generation times are less than 25. This selected consensus node is node 4. At this point, node 1 identifies node 4 as an abnormal node that meets the set node abnormality conditions.
[0110] For another example, suppose node 1 is the master node, and nodes 2, 3, and 4 are all slave nodes. The total number of times is 1000, and the proposal generation threshold is 1 / 10 of the average number of proposal generation times, which is 1000 / 4 × 1 / 10 = 25. For example, the proposal generation times of nodes 1, 2, 3, and 4 are 476, 480, 24, and 20, respectively. Taking node 1 as an example, when node 1 obtains the target proposal and the total number of proposal generation times recorded in node 1's local records reaches 1000, node 1 selects at least one consensus node from each consensus node with a proposal generation time of less than 25. These selected consensus nodes include nodes 3 and 4. Based on the proposal generation times of nodes 3 and 4, consensus node 1 selects node 4, the consensus node with the lowest proposal generation time, as the single consensus node and identifies node 4 as an abnormal node that meets the set node abnormality conditions.
[0111] Each consensus node among the multiple consensus nodes can obtain the node proposal times of each of the multiple consensus nodes from the locally recorded node proposal map, and then filter out the consensus nodes whose value is less than 1 / 10 of the average number of proposal generation times from the multiple consensus nodes, and then identify the abnormal nodes from the filtered consensus nodes.
[0112] S302: Consensus node x sends a first vote of the pre-voting phase to other consensus nodes among the plurality of consensus nodes except consensus node x, and receives one or more first votes of the pre-voting phase sent by other consensus nodes. The first vote sent by consensus node x carries the node identifier of the abnormal node.
[0113] In an embodiment of the present application, the first vote in the pre-voting stage can also be called a prevote vote. Each consensus node among the multiple consensus nodes will generate a prevote vote in the prevote stage, and add the node ID that needs to be kicked out, that is, the node identifier of the abnormal node, to the voting content of the prevote vote. Furthermore, each consensus node broadcasts the prevote vote generated by itself to other nodes among the multiple consensus nodes, and receives the prevote votes sent by other nodes. The embodiment of the present application does not limit the order in which consensus node x generates and broadcasts prevote votes and receives prevote votes sent by other nodes, and the two can be carried out in parallel.
[0114] Figure 6 is a logical diagram of another node consensus process provided in an embodiment of the present application. Take the consensus node x as node 1 as an example. Referring to Figure 6, it is assumed that the abnormal node determined in S301 is node 4. In the prevote phase of the Byzantine consensus, node 1 generates a prevote vote, and the prevote vote carries the node identifier of node 4: nodeID4. Then, node 1 broadcasts the prevote vote generated by itself to nodes 2, 3, and 4, and receives the prevote votes sent by nodes 2, 3, and 4. The embodiment of the present application does not limit the order in which node 1 generates and broadcasts prevote votes and receives prevote votes sent by other nodes, and the two can be performed in parallel.
[0115] S303: When the number of first votes carrying the node identifier of the abnormal node in the one or more received first votes reaches a first vote threshold, consensus node x sends a second vote in the pre-commit phase to other consensus nodes, and receives one or more second votes in the pre-commit phase sent by other consensus nodes. The second vote sent by the consensus node carries the node identifier of the abnormal node.
[0116] In an embodiment of the present application, the second vote in the pre-commit phase may also be referred to as a precommit vote. The first vote threshold may be 2n / 3+1, where n represents the number of consensus nodes. When the value of 2n / 3+1 is not an integer, the first vote threshold may be obtained by rounding down. For example, when there are four consensus nodes, the first vote threshold is 2n / 3+1, and consensus node x enters the precommit phase when the number of first votes received carrying node identifiers of abnormal nodes reaches three.
[0117] If each first vote received by consensus node x may include a first vote generated by consensus node x itself, the first vote threshold may be 2n / 3 + 1. If each first vote received by consensus node x may also not include a first vote generated by consensus node x itself, the first vote threshold may be 2n / 3, without limitation.
[0118] For each consensus node among multiple consensus nodes, if at least 2n / 3+1 prevote votes carrying the same node identifier (i.e., the node identifier of the abnormal node) are received in the second stage (prevote stage), then in the third stage (precommit stage), a precommit vote is generated, and the node ID to be kicked out, i.e., the node identifier of the abnormal node, is added to the voting content of the precommit vote. Then, the precommit vote generated by itself is broadcast to other nodes among the multiple consensus nodes, and precommit votes sent by other nodes are received. Take the consensus node x as an example, which is node 1. Referring to Figure 6, it is assumed that the abnormal node determined in S301 is node 4. In the prevote stage of the Byzantine consensus, node 1 receives prevote votes from nodes 2, 3, and 4, and the prevote votes of nodes 2, 3, and 4 all carry nodeID4, then it is determined that the number of first votes received carrying nodeID4 reaches 2. Node 1 then sends a precommit vote to nodes 2, 3, and 4, with the precommit vote carrying node ID 4, and receives the precommit votes sent by nodes 2, 3, and 4. Since node 4 is abnormal, it cannot participate in the vote, that is, it cannot receive or send prevote or precommit votes. Therefore, the process of sending a vote to node 4 is not shown in Figure 6.
[0119] In an embodiment of the present application, if the number of first votes carrying the node identifier of an abnormal node in each received first vote does not reach the first vote threshold, and each received first vote reaches the first vote threshold, then consensus node x can directly enter the precommit stage and generate a precommit vote that does not carry the node identifier. The embodiment of the present application does not limit the order in which consensus node x generates and broadcasts precommit votes and receives precommit votes sent by other nodes, and the two can be performed in parallel.
[0120] S304. When the number of second votes carrying the node identifier of the abnormal node in the received one or more second votes reaches a second vote threshold, consensus node x determines that consensus is reached on the target proposal and deletes the abnormal node from the multiple consensus nodes recorded locally.
[0121] The second vote threshold may be the same as or different from the first vote threshold. Herein, the second vote threshold is described as being the same as the first vote threshold.
[0122] For each consensus node in the multiple consensus nodes, if at least 2n / 3+1 precommit votes carrying the same node ID (i.e., the node ID of the abnormal node) are received in the third phase (precommit phase), consensus is determined to be reached on the target proposal, and the abnormal node is deleted from the multiple consensus nodes. Furthermore, if the target proposal reached by consensus is an empty proposal, the target proposal will not be committed; if the target proposal reached by consensus is a non-empty proposal, the target proposal will be committed.
[0123] Let's still take the case where consensus node x is node 1. Referring to Figure 6, assume that the abnormal node identified in S301 is node 4. In the precommit phase of the Byzantine consensus, the second vote threshold is 3. Node 1 receives precommit votes from nodes 2, 3, and 4, and all of these precommit votes carry nodeID 4. Therefore, it is determined that the number of first votes received carrying nodeID 4 has reached 3. Node 1 then determines that consensus has been reached on the target proposal and deletes nodeID 4 from the locally recorded consensus nodes. The deleted consensus nodes include: nodes 1, 2, and 3.
[0124] Furthermore, after deleting or adding a node, the consensus node resets the number of proposals generated corresponding to the remaining consensus nodes in the distributed system recorded locally, and resets the total number of proposals generated recorded locally.
[0125] The consensus node resets the locally recorded number of proposal generation times and the total number of proposal generation times corresponding to the multiple consensus nodes in the distributed system to the initial value. For example, the initial value is 0.
[0126] Assuming that consensus node x is node 1, as shown in Figure 6, the node proposal map recorded locally by node 1 deletes the node identifier of node 4 and its corresponding value, and the proposal generation counts for nodes 1, 2, and 3 recorded in the node proposal map are reset to 0. Since the sum of the proposal generation counts for each consensus node is the total number of proposal generation counts, the total number of proposal generation counts is also reset to 0.
[0127] In the embodiment of the present application, by analyzing historical proposal records, the node IDs of the nodes to be kicked out (i.e., the node identifiers of abnormal nodes) are included in the node votes (prevote and precommit votes), and finally, through the security guarantee of the Byzantine consensus protocol itself, all nodes are guaranteed to kick out the nodes that need to be kicked out of the consensus. In this way, when facing a node failure, the entire consensus network can safely and correctly kick out the faulty node, and ultimately ensure that the nodes participating in the consensus are normal nodes as much as possible, thereby significantly improving the performance of the entire blockchain network.
[0128] The following describes the method in conjunction with a specific embodiment.
[0129] Figure 7 is a schematic diagram of an initial node proposal map provided in an embodiment of the present application. Referring to Figure 7 , the distributed system includes six consensus nodes, namely Node 1 through Node 6. Each of Nodes 1 through Node 6 maintains a local node proposal map. Each node maintains a node proposal map containing the node IDs of Nodes 1 through Node 6. The value corresponding to each node ID is initialized to 0.
[0130] Assume that node 4 becomes an abnormal node due to downtime or other reasons, and the other five nodes are all normal nodes.
[0131] Figure 8 is a logical diagram of the first round of consensus process provided in an embodiment of the present application. During the first round of consensus, Node 1 becomes the master node. As shown in Figure 8 , Node 1 is a normal node. Therefore, after receiving a consensus request from a client device, Node 1 generates a proposal and broadcasts it to Nodes 2 through 6. Furthermore, during the pre-voting phase, Node 1 generates a prevote vote and broadcasts its own prevote vote to Nodes 2 through 6.
[0132] Nodes 2, 3, 5, and 6 are all normal nodes. Therefore, after receiving the proposal from Node 1, each of Nodes 2, 3, 5, and 6 generates a prevote vote in the pre-voting phase and broadcasts its prevote vote to other nodes.
[0133] After receiving 2×6 / 3+1=5 prevotes, each of Node 1, Node 2, Node 3, Node 5, and Node 6 generates a precommit vote in the precommit phase and broadcasts its precommit vote to other nodes.
[0134] After the number of precommit votes received by each node in Node 1, Node 2, Node 3, Node 5 and Node 6 reaches 2×6 / 3+1=5, it determines that a consensus has been reached on the proposal, and submits the proposal when the proposal is not an empty proposal. After submitting the proposal, Node 1 to Node 6 all add the value of the node id of Node 1 with the key as key + 1 in the node proposal map they maintain, that is, the number of times Node 1 generates a proposal + 1. Figure 9 is a schematic diagram of the node proposal map after the first round of consensus provided in an embodiment of the present application. Referring to Figure 9, after consensus is finally reached, the node proposal map of each node and the value of each node id are as follows: the number of proposals generated corresponding to Node 1 to Node 6 is 1, 0, 0, 0, 0, 0.
[0135] In the second round of consensus, node 2 becomes the master node. After node 2 generates a proposal, nodes 1 to 6 reach a consensus on the proposal generated by node 2. Since the process of reaching a consensus on the proposal generated by node 2 is the same as the process of reaching a consensus on the proposal generated by node 2, it will not be repeated here. Figure 10 is a schematic diagram of the node proposal map in the multi-round consensus process provided in the embodiment of the present application. Referring to Figure 10, after the consensus is finally reached, the node proposal map of each node and the value of each node id are as follows: the number of proposals generated corresponding to nodes 1 to 6 is 1, 1, 0, 0, 0, 0.
[0136] During the third round of consensus, node 3 becomes the master node. After node 3 generates a proposal, nodes 1 through 6 reach consensus on the proposal generated by node 3. Since the consensus process for node 3's proposal is identical, it will not be repeated here. Referring to Figure 10, after consensus is finally reached, the node proposal map for each node and the value of each node ID are as follows: the number of proposals generated for nodes 1 through 6 is 1, 1, 1, 0, 0, 0.
[0137] FIG11 is a logical diagram of the fourth round of consensus process provided in an embodiment of the present application. Referring to FIG11 , in the fourth round of consensus process, node 4 becomes the master node. Since node 4 is a faulty node, it is impossible for it to generate a proposal. Therefore, starting from when node 4 receives the consensus request from the client device, nodes 1, 2, 3, 5, and 6 will start a timer while waiting for node 4 to generate a proposal. If a proposal generated by node 4 is not received within the set time, then nodes 1, 2, 3, 5, and 6 will generate a vote for an empty proposal and reach a consensus on the empty proposal.
[0138] Because nodes 1, 2, 3, 5, and 6 did not receive the proposal, they ultimately did not add 1 to the value of node 4 in their respective node proposal maps. After consensus was reached on the empty proposal, the empty proposal was not submitted to the blockchain, and a new node was switched to generate the proposal. Therefore, when node 4 did not generate a proposal, and the other nodes eventually reached consensus by voting on the empty proposal after the timeout, the value of node 4 remained unchanged. The values of each node ID in their node proposal maps were as follows: the number of proposals generated for nodes 1 through 6 was 1, 1, 1, 0, 0, 0.
[0139] As consensus continues, the values of nodes 1, 2, 3, 5, and 6 will continue to increase. However, node 4 is faulty, so its value will not increase, or will increase more slowly due to network and machine performance issues. When the value of all nodes reaches 1000, the value of node 4 has not reached 16, which is 1 / 10 of the average number of proposals generated (166). Suppose that the values of the node IDs in the node proposal map are as follows: 200, 200, 200, 15, 200, 185.
[0140] Figure 12A is a logical diagram of a round of consensus process provided in an embodiment of the present application. Referring to Figure 12A, when the target proposal is obtained and the sum of the values of each node ID in the locally recorded node proposal map reaches 1000 (that is, the total number of proposal generation reaches 1000), each node screens out consensus nodes with proposal generation times less than 16 from multiple consensus nodes as abnormal nodes. The abnormal node is node 4. Afterwards, each node generates a prevote vote, which carries nodeID4, and broadcasts the prevote vote generated by itself to other nodes, and receives prevote votes sent by other nodes. When each node receives no less than 2×6 / 3+1=5 prevote votes carrying the same node identifier, it generates a precommit vote, which carries nodeID4, and broadcasts the precommit vote generated by itself to other nodes, and receives precommit votes sent by other nodes. When each node receives no fewer than 2×6 / 3+1=5 precommit votes with the same node identifier, it determines that consensus has been reached on the proposal and removes node 4 from the consensus nodes. In this embodiment of the application, since node 4 cannot receive and send votes, Figure 12A does not show the process of each node sending votes to node 4.
[0141] FIG12B is a schematic diagram of the node proposal map after deleting abnormal nodes provided in an embodiment of the present application. Further, referring to FIG12B , for the node proposal map recorded locally by each node, the node identifier of node 4 and its corresponding value are deleted from the node proposal map, and the number of proposal generation times corresponding to each of node 1, node 2, node 3, node 5, and node 6 recorded in the node proposal map is reset to 0. Since the sum of the number of proposal generation times corresponding to each of the multiple consensus nodes is the total number of proposal generation times, the total number of proposal generation times is also reset to 0.
[0142] With this implementation, when a node becomes faulty, its value won't increase after several consensus passes. However, other healthy nodes will generate proposals, causing their value to increase. After 1,000 proposals, the faulty node's value will be very low. If it's lower than 1 / 10 of the average number of proposals generated, it can be considered faulty and voted out of the consensus process. This ensures that only healthy nodes participate in consensus, restoring blockchain performance.
[0143] Based on the same inventive concept, the present embodiment provides a node consensus device. As shown in FIG13 , it is a schematic diagram of the structure of the node consensus device 1300, which may include:
[0144] A screening unit 1301 is configured to, when a target proposal is obtained and the total number of proposal generation recorded locally reaches a total number threshold, screen out abnormal nodes that meet a set node abnormality condition from a plurality of consensus nodes in the distributed system based on the locally recorded number of proposal generation corresponding to each of the plurality of consensus nodes, wherein the plurality of consensus nodes include the consensus node;
[0145] A pre-voting unit 1302 is configured to send a first vote of a pre-voting phase to other consensus nodes among the multiple consensus nodes except the consensus node, and receive one or more first votes of the pre-voting phase sent by the other consensus nodes, wherein the first vote sent by the consensus node carries a node identifier of the abnormal node;
[0146] The pre-submission unit 1303 is configured to send a second vote of the pre-submission phase to the other consensus nodes when the number of first votes carrying the node identifier of the abnormal node in the received one or more first votes reaches a first vote threshold, and receive one or more second votes of the pre-submission phase sent by the other consensus nodes, wherein the second vote sent by the consensus node carries the node identifier of the abnormal node;
[0147] The node adjustment unit 1304 is used to determine that a consensus is reached on the target proposal when the number of second votes carrying the node identifier of the abnormal node in one or more received second votes reaches a second vote threshold, and delete the abnormal node from the multiple consensus nodes recorded locally.
[0148] As a possible implementation, when the target proposal is obtained and the total number of proposal generation recorded locally reaches the total number threshold, based on the locally recorded number of proposal generation corresponding to each of the multiple consensus nodes in the distributed system, before screening out abnormal nodes that meet the set node abnormality conditions from the multiple consensus nodes, the screening unit 1301 is further configured to:
[0149] During each round of consensus, if the multiple consensus nodes reach a consensus on a non-empty proposal generated by the master node, the number of proposal generation times corresponding to the master node is accumulated and the total number of proposal generation times is updated, where the master node is one of the multiple consensus nodes.
[0150] As a possible implementation, the consensus node locally records node proposal mapping information, where the node proposal mapping information includes: node identifiers of the plurality of consensus nodes and corresponding proposal generation times;
[0151] The screening unit 1301 is configured to determine the total number of proposal generation times recorded locally by:
[0152] From the node proposal mapping information, obtain the number of proposal generation times corresponding to each of the multiple consensus nodes; and determine the total number of proposal generation times based on the obtained number of proposal generation times corresponding to each of the multiple consensus nodes.
[0153] As a possible implementation, based on the locally recorded number of proposal generation times corresponding to the multiple consensus nodes in the distributed system, when screening out abnormal nodes that meet the set node abnormality conditions from the multiple consensus nodes, the screening unit 1301 is specifically configured to:
[0154] Selecting, from the plurality of consensus nodes, at least one consensus node whose number of proposal generation is lower than a proposal generation threshold;
[0155] A consensus node among the at least one consensus node is determined as an abnormal node that meets a set node abnormality condition.
[0156] As a possible implementation, when determining one of the at least one consensus node as an abnormal node that meets the set node abnormality condition, the screening unit 1301 is specifically configured to:
[0157] If the number of the at least one consensus node is one, the selected consensus node is regarded as an abnormal node that meets the set node abnormality condition;
[0158] If the number of the at least one consensus node is more than one, then based on the number of proposal generation times corresponding to each of the at least one consensus nodes, one consensus node is determined from the more than one consensus nodes screened out, and the determined consensus node is used as an abnormal node that meets the set node abnormality condition.
[0159] As a possible implementation manner, after deleting the abnormal node from the multiple consensus nodes recorded locally, the screening unit 1301 is further configured to:
[0160] Reset the locally recorded number of proposal generation times corresponding to the remaining consensus nodes in the distributed system;
[0161] Resets the local record of the total number of proposals generated.
[0162] As a possible implementation, the screening unit 1301 is further configured to:
[0163] If the consensus node is a master node, after obtaining a consensus request for target transaction information from a client device, generating the target proposal for the target transaction information;
[0164] If the consensus node is a slave node, the target proposal is obtained through the master node.
[0165] As a possible implementation, when obtaining the target proposal through the master node, the screening unit 1301 is specifically configured to:
[0166] If a proposal is received from the master node within a set time period starting from when the master node obtains the consensus request from the client device, the proposal from the master node is used as the target proposal;
[0167] If no proposal is received from the master node within a set time period starting from when the master node obtains the consensus request from the client device, an empty proposal is used as the target proposal.
[0168] For the convenience of description, the above parts are divided into modules (or units) according to their functions and described separately. Of course, when implementing this application, the functions of each module (or unit) can be implemented in the same or multiple software or hardware.
[0169] Regarding the apparatus in the above embodiment, the specific manner in which each unit executes the request has been described in detail in the embodiment of the method, and will not be elaborated on here.
[0170] Those skilled in the art will appreciate that various aspects of the present application can be implemented as systems, methods, or program products. Therefore, various aspects of the present application can be specifically implemented in the following forms: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or an implementation that combines hardware and software aspects, which may be collectively referred to herein as a "circuit," "module," or "system."
[0171] Based on the same inventive concept, an embodiment of the present application further provides an electronic device. In one embodiment, the electronic device can be a server or a terminal device. Referring to FIG. 14 , which is a schematic diagram of the structure of a possible electronic device provided in an embodiment of the present application, electronic device 1400 includes a processor 1410 and a memory 1420.
[0172] Among them, the memory 1420 stores a computer program that can be executed by the processor 1410. The processor 1410 can execute the steps of the above-mentioned node consensus method by executing the instructions stored in the memory 1420.
[0173] Memory 1420 may be a volatile memory, such as random-access memory (RAM); a non-volatile memory, such as read-only memory (ROM), flash memory, a hard disk drive (HDD), or a solid-state drive (SSD); or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but is not limited thereto. Memory 1420 may also be a combination of the aforementioned memories.
[0174] The processor 1410 may include one or more central processing units (CPUs) or digital processing units, etc. The processor 1410 is configured to implement the above-mentioned node consensus method when executing the computer program stored in the memory 1420 .
[0175] In some embodiments, the processor 1410 and the memory 1420 may be implemented on the same chip. In some embodiments, they may also be implemented on separate chips.
[0176] The specific connection medium between the processor 1410 and the memory 1420 is not limited in the embodiments of the present application. In the embodiments of the present application, the bus connection between the processor 1410 and the memory 1420 is used as an example. The bus is depicted as a bold line in FIG14 . The connection methods between other components are merely illustrative and are not intended to be limiting. Buses can be divided into address buses, data buses, control buses, etc. For ease of description, FIG14 depicts only a single bold line, but this does not imply that there is only one bus or only one type of bus.
[0177] Based on the same inventive concept, an embodiment of the present application provides a computer-readable storage medium, which includes a computer program. When the computer program is run on an electronic device, the computer program is used to cause the electronic device to perform the steps of the above-mentioned node consensus method. In some possible implementations, various aspects of the node consensus method provided by the present application can also be implemented in the form of a program product, which includes a computer program. When the program product is run on an electronic device, the computer program is used to cause the electronic device to perform the steps in the above-mentioned node consensus method. For example, the electronic device can perform the steps shown in Figure 3.
[0178] The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or component, or any combination thereof. More specific examples (a non-exhaustive list) of readable storage media include: an electrical connection having one or more wires, a portable disk, a hard disk, RAM, ROM, an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.
[0179] The program product of the embodiments of the present application may be a CD-ROM and include a computer program, and may be run on an electronic device. However, the program product of the present application is not limited thereto. In this document, a readable storage medium may be any tangible medium that contains or stores a computer program that can be used by or in conjunction with a command execution system, apparatus, or device.
[0180] A readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries a readable computer program. Such a propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A readable signal medium may also be any readable medium other than a readable storage medium that can transmit, propagate, or transfer a computer program for use by or in conjunction with a command execution system, apparatus, or device.
[0181] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present application.
[0182] Obviously, those skilled in the art may make various changes and modifications to this application without departing from the spirit and scope of this application. Thus, if these modifications and variations of this application fall within the scope of the claims of this application and their equivalents, this application is intended to include these modifications and variations.
Claims
1. A node consensus method, characterized in that: Applied to a consensus node, the method comprises: When the target proposal is obtained and the total number of proposals generated recorded locally reaches the total number threshold, based on the number of proposals generated corresponding to each of the multiple consensus nodes in the distributed system recorded locally, the abnormal nodes that meet the set node abnormality conditions are screened out from the multiple consensus nodes, wherein the multiple consensus nodes include the consensus node; Sending a first vote in a pre-voting phase to other consensus nodes among the multiple consensus nodes except the consensus node, and receiving one or more first votes in the pre-voting phase sent by the other consensus nodes, wherein the first vote sent by the consensus node carries a node identifier of the abnormal node; When the number of first votes carrying the node identifier of the abnormal node in the received one or more first votes reaches a first vote number threshold, sending a second vote in the pre-submission phase to the other consensus nodes, and receiving one or more second votes in the pre-submission phase sent by the other consensus nodes, wherein the second vote sent by the consensus node carries the node identifier of the abnormal node; When the number of second votes carrying the node identifier of the abnormal node in the received one or more second votes reaches a second vote threshold, it is determined that a consensus is reached on the target proposal, and the abnormal node is deleted from the multiple consensus nodes recorded locally.
2. The method according to claim 1, characterized in that The method further comprises: In each round of consensus, if the multiple consensus nodes reach a consensus on the non-empty proposal generated by the master node, the number of proposal generation times corresponding to the master node is accumulated and the total number of proposal generation times is updated, wherein the master node is a consensus node among the multiple consensus nodes.
3. The method according to claim 2, characterized in that The consensus node locally records node proposal mapping information, and the node proposal mapping information includes: node identifiers of the multiple consensus nodes and their corresponding proposal generation times; The total number of proposals generated locally is determined as follows: Obtaining the proposal generation times corresponding to each of the plurality of consensus nodes from the node proposal mapping information; Based on the acquired proposal generation times corresponding to each of the multiple consensus nodes, the total proposal generation times is determined.
4. The method according to claim 1, 2 or 3, characterized in that: The proposal generation times corresponding to the multiple consensus nodes in the distributed system based on the local record, and the abnormal nodes that meet the set node abnormality conditions are screened out from the multiple consensus nodes, including: Filtering at least one consensus node whose number of proposal generation is lower than a proposal generation threshold from the multiple consensus nodes; A consensus node among the at least one consensus node is determined as an abnormal node that meets the set node abnormality condition.
5. The method according to claim 4, characterized in that The step of determining a consensus node among the at least one consensus node as an abnormal node that meets the set node abnormality condition includes: If the number of the at least one consensus node is one, the selected consensus node is used as an abnormal node that meets the set node abnormality condition; If the number of the at least one consensus node is more than one, based on the number of proposal generation corresponding to each of the at least one consensus nodes, a consensus node is determined from the more than one consensus nodes screened out, and the determined consensus node is used as an abnormal node that meets the set node abnormality condition.
6. The method according to any one of claims 1 to 5, characterized in that: After deleting the abnormal node from the multiple consensus nodes recorded locally, the method further includes: Reset the number of proposals generated by the remaining consensus nodes in the distributed system recorded locally; Reset the local record of total number of proposals generated.
7. The method according to any one of claims 1 to 6, characterized in that: The target proposal is obtained in the following way: If the consensus node is a master node, after obtaining a consensus request for target transaction information from a client device, generating the target proposal for the target transaction information; If the consensus node is a slave node, the target proposal is obtained through the master node.
8. The method according to claim 7, characterized in that The obtaining the target proposal through the master node includes: If a proposal is received from the master node within a set time period starting from when the master node obtains the consensus request from the client device, the proposal from the master node is used as the target proposal; If no proposal is received from the master node within a set time period starting from when the master node obtains the consensus request from the client device, an empty proposal is used as the target proposal.
9. A node consensus device, characterized in that: include: A screening unit, configured to screen out abnormal nodes that meet the set node abnormality condition from the multiple consensus nodes based on the proposal generation times corresponding to each of the multiple consensus nodes in the distributed system recorded locally, when a target proposal is obtained and the total number of proposal generation times recorded locally reaches a total number threshold, wherein the multiple consensus nodes include the consensus node; A pre-voting unit, configured to send a first vote of a pre-voting phase to other consensus nodes among the multiple consensus nodes except the consensus node, and receive one or more first votes of the pre-voting phase sent by the other consensus nodes, wherein the first vote sent by the consensus node carries a node identifier of the abnormal node; A pre-submission unit is configured to send a second vote in the pre-submission phase to the other consensus nodes when the number of first votes carrying the node identifier of the abnormal node in the received one or more first votes reaches a first vote threshold, and receive one or more second votes in the pre-submission phase sent by the other consensus nodes, wherein the second vote sent by the consensus node carries the node identifier of the abnormal node; A node adjustment unit is used to determine that a consensus is reached on the target proposal when the number of second votes carrying the node identifier of the abnormal node in one or more received second votes reaches a second vote threshold, and delete the abnormal node from the multiple consensus nodes recorded locally.
10. An electronic device, characterized in that: It comprises a processor and a memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of any one of the methods of claims 1 to 8.
11. A computer-readable storage medium, characterized in that: It includes a computer program. When the computer program is run on an electronic device, the computer program is used to enable the electronic device to execute the steps of any method described in claims 1 to 8.
12. A computer program product, characterized in that It includes a computer program, which is stored in a computer-readable storage medium. The processor of the electronic device reads and executes the computer program from the computer-readable storage medium, so that the electronic device executes the steps of any method described in claims 1 to 8.
Citation Information
Patent Citations
Block chain consensus method and device with optimized bandwidth and electronic equipment
CN110012100A
Consensus method, device and system of block chain and electronic equipment
CN110708163A
Voting information processing method and device, equipment and storage medium
CN111654395A
A proposal timeout threshold dynamic adjustment method and device and electronic equipment
CN112232954A
Chandra-toueg consensus in a content centric network
WO2017123649A1
