A Consensus Method, Device and Computer Readable Storage Medium for Blockchain
By using simulated annealing algorithm in the blockchain consensus algorithm for the election process, the problem of low consensus efficiency and high resource consumption in the existing technology is solved, and efficient consensus and good expansion in a large number of node systems are achieved.
Patent Information
- Application Number
- CN202210031768.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-12
- Publication Date
- 2025-07-01
- Estimated Expiration
- 2042-01-12
AI Technical Summary
While ensuring good consensus efficiency, existing blockchain consensus algorithms cannot avoid consuming a large amount of system resources. Especially in blockchain systems with a large number of nodes, the consensus speed of negotiated consensus algorithms is slower and the network expansion is low.
The election process is carried out using a simulated annealing algorithm, and the election request is sent to the blockchain node through a consensus device. The nodes randomly generate recursive vouchers to determine whether the election requirements are met, determine the candidate node and select the leadership node.
The simulation annealing algorithm avoids falling into local optimal solutions, has fast calculation speed, can maintain good consensus efficiency throughout the process, is suitable for blockchain systems with a large number of nodes, and has good scalability.
Smart Images

Figure CN114416873B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of blockchain technology, and in particular, to a consensus method, apparatus, and computer-readable storage medium for a blockchain. Background Art
[0002] A blockchain is a decentralized database that contains a list called blocks, with continuously growing and neatly arranged records. Each block contains a timestamp and a link to the previous block, and once the data is recorded in the block, it cannot be tampered with.
[0003] The blockchain uses a consensus algorithm to achieve data consistency among distributed nodes on the blockchain, and determines the bookkeeping right of the current block through the consensus algorithm. The consensus algorithms in the prior art mainly include two types. The first is a competitive consensus algorithm, where nodes on the chain compete for the bookkeeping right of the block by consuming computing power. The second is a negotiation-based consensus algorithm, where nodes on the chain negotiate and select the leading node of the current block through a certain election method, and the leading node is responsible for the bookkeeping and block generation of this round of consensus.
[0004] The competitive consensus algorithm requires each node to consume a large amount of resources to obtain computing power for calculation, with extremely low efficiency and a very high resource consumption rate. The consensus speed of the negotiation-based consensus algorithm is relatively slow, and the network scalability is relatively low, which is not suitable for blockchain systems with a large number of nodes. Currently, there is no algorithm that can avoid consuming a large amount of system resources while ensuring good consensus efficiency. Summary of the Invention
[0005] This application provides a consensus method, apparatus, and computer-readable storage medium for a blockchain, which can avoid consuming a large amount of system resources while ensuring good consensus efficiency.
[0006] In a first aspect, a consensus method for a blockchain is provided, including: the consensus apparatus sends an election request to each node in the blockchain to start an election process based on the simulated annealing algorithm; in each iteration round of the simulated annealing algorithm, the consensus apparatus obtains the recursive certificates randomly generated by each node in the blockchain, and determines whether each node meets the election requirements according to the recursive certificates randomly generated by each node; after the simulated annealing algorithm runs to completion, the consensus apparatus determines N candidate nodes according to the number of times each node meets the election requirements, where N is a positive integer greater than 1; the consensus apparatus selects a leading node from the N candidate nodes based on a preset leading node selection rule.
[0007] The technical solution provided by this application has at least the following beneficial effects: Since in each iteration of the simulated annealing algorithm, if the current solution is not better than the optimal solution, the algorithm will still adopt the current solution with a certain probability, thus avoiding falling into a local optimal solution. Moreover, compared with the traditional neural network algorithm, the simulated annealing algorithm does not require training of the model, has a fast calculation speed, and can quickly and well optimize the solution. Therefore, in the consensus process of this application, by using the simulated annealing algorithm, each node only needs to generate corresponding recursive certificates in each iteration round according to the process, and the number of operations, algorithms, and complexity of all nodes in the whole process are the same, without consuming a large amount of system resources, and can maintain good consensus efficiency and ensure the credibility of the information in the block. It is applicable to blockchain systems with a large number of nodes and has good scalability.
[0008] Optionally, the consensus device determines N candidate nodes according to the number of times each node meets the election requirements, including: The consensus device selects the N nodes with the most times of meeting the election requirements as candidate nodes according to the number of times each node meets the election requirements.
[0009] Optionally, the consensus device determines whether each node meets the election requirements according to the recursively generated certificates randomly generated by each node, including the following steps:
[0010] S1. Determine the average recursively generated certificate of the current iteration round according to the recursively generated certificates randomly generated by each node in the current iteration round;
[0011] S2. Calculate the average recursively generated certificate change value according to the average recursively generated certificate of the current iteration round and the optimal average recursively generated certificate determined in the previous iteration round. The average recursively generated certificate change value is equal to the average recursively generated certificate of the current iteration round minus the optimal average recursively generated certificate;
[0012] S3. Determine whether the average recursively generated certificate change value is less than 0; if so, execute step S4; if not, execute step S5;
[0013] S4. Update the optimal average recursively generated certificate with the average recursively generated certificate of the current iteration round; and for each node in the blockchain, if the recursively generated certificate randomly generated by the node in the current iteration round is less than the average recursively generated certificate of the current iteration round, it is determined that the node meets the election requirements; if the recursively generated certificate randomly generated by the node in the current iteration round is greater than or equal to the average recursively generated certificate of the current iteration round, it is determined that the node does not meet the election requirements;
[0014] S5. Calculate the Boltzmann probability according to the average recursively generated certificate change value; if the Boltzmann probability is greater than or equal to the randomly generated probability threshold, execute step S6; if the Boltzmann probability is less than the probability threshold, execute step S7;
[0015] S6. Reject updating the optimal average recursive certificate with the average recursive certificate of the current iteration round, and determine that each node in the blockchain does not meet the election requirements;
[0016] S7. Update the optimal average recursive certificate with the average recursive certificate of the current iteration round; and for each node in the blockchain, if the recursive certificate randomly generated by the node in the current iteration round is less than the average recursive certificate of the current iteration round, determine that the node meets the election requirements; if the recursive certificate randomly generated by the node in the current iteration round is greater than or equal to the average recursive certificate of the current iteration round, determine that the node does not meet the election requirements.
[0017] Optionally, the consensus device selects a leader node from N candidate nodes based on a preset leader node selection rule, including: the consensus device sends notification messages to the N candidate nodes respectively, so that each candidate node performs block packaging and broadcasts the packaged block to other nodes in the blockchain; the consensus device obtains the verification data of each candidate node, and the verification data of the candidate node includes the verification results of each node in the blockchain on the block packaged by the candidate node; the consensus device selects a leader node from the N candidate nodes according to the verification data of each candidate node.
[0018] Optionally, the block packaged by the candidate node includes a block header, and the block header includes multiple recursive certificates generated by the candidate node in the election process and the relevant data used for generating the recursive certificate each time.
[0019] Optionally, before the consensus device obtains the verification data of each candidate node, the method further includes: the consensus device broadcasts iteration data to each node in the blockchain, so that each node in the blockchain verifies the block packaged by the candidate node according to the iteration data; where the iteration data includes the optimal average recursive certificate of each iteration round of the simulated annealing algorithm and the judgment results of each candidate node in each iteration round, and the judgment results are used to indicate whether the candidate node meets the election requirements.
[0020] Optionally, the consensus device selects a leader node from the N candidate nodes according to the verification data of each candidate node, including: the consensus device determines the arrangement order of the N candidate nodes according to the number of times each candidate node meets the election requirements; the consensus device sequentially judges whether the verification data of the candidate nodes meet the verification requirements according to the arrangement order of the N candidate nodes; the consensus device determines the candidate node whose first verification data meets the verification requirements as the leader node.
[0021] Optionally, the verification requirements include: the ratio between the number of verification results indicating passing verification in the verification data and the total number of verification results included in the verification data is greater than a preset ratio threshold.
[0022] Optionally, before the consensus device sends an election request to each node in the blockchain, the method further includes: the consensus device sends a first request message to the current leader node in the blockchain, where the first request message is used to request the generation of an initial temperature value; the consensus device receives a first temperature value from the current leader node in the blockchain; the consensus device uses the first temperature value as the initial temperature value used in the simulated annealing algorithm.
[0023] Optionally, the consensus device sends a second request message to each node in the blockchain, where the second request message is used to request the generation of a target cooling temperature value; the consensus device receives second response messages from each node in the blockchain, and the second response messages include second temperature values; the consensus device determines a third temperature value based on the second temperature values of each node; the consensus device uses the third temperature value as the target cooling temperature value used in the simulated annealing algorithm.
[0024] Optionally, the recursive certificate is generated based on a first hash grouping table and a second hash grouping table. The first hash grouping table is used to record the hash values corresponding to each block in the Rr blocks randomly selected by the node on the current blockchain, and the second hash grouping table is used to record the hash values corresponding to each block in the other blocks on the current blockchain except for the Rr blocks, where Rr is a positive integer.
[0025] Optionally, the recursive certificate is specifically determined based on a first coordinate value and a second coordinate value. The first coordinate value is determined based on the first hash grouping table, and the second coordinate value is determined based on the second hash grouping table.
[0026] In a second aspect, a consensus device for a blockchain is provided, including: a sending module, configured to send an election request to each node in the blockchain to start an election process based on the simulated annealing algorithm; an obtaining module, configured to obtain, in each iteration round of the simulated annealing algorithm, the recursive certificates randomly generated by each node in the blockchain, and determine whether each node meets the election requirements based on the recursive certificates randomly generated by each node; a processing module, configured to, after the simulated annealing algorithm runs to completion, determine N candidate nodes based on the number of times each node meets the election requirements, where N is a positive integer greater than 1; and select a leader node from the N candidate nodes based on a preset leader node selection rule.
[0027] In a third aspect, a consensus device for a blockchain is provided, including one or more processors and one or more memories; the one or more memories are coupled to the one or more processors, and the one or more memories are configured to store computer program code, where the computer program code includes computer instructions. When the one or more processors execute the computer instructions, the consensus device executes the consensus method in the first aspect and its options described above.
[0028] Fourthly, a computer-readable storage medium is provided, including computer instructions, which, when running on a computer, cause the computer to execute the consensus method described in the first aspect and its optional aspects above.
[0029] For the beneficial effects described in the second to fourth aspects of this application, reference can be made to the analysis of the beneficial effects of the first aspect, which will not be elaborated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Figure 1 A schematic diagram of a blockchain system provided by an embodiment of this application;
[0031] Figure 2 A schematic flowchart of a consensus method for a blockchain provided by an embodiment of this application;
[0032] Figure 3 A schematic flowchart of another consensus method for a blockchain provided by an embodiment of this application;
[0033] Figure 4 A schematic flowchart of another consensus method for a blockchain provided by an embodiment of this application;
[0034] Figure 5 A schematic flowchart of another consensus method for a blockchain provided by an embodiment of this application;
[0035] Figure 6 A schematic flowchart of another consensus method for a blockchain provided by an embodiment of this application;
[0036] Figure 7 A schematic flowchart of a method for generating a recursive credential provided by an embodiment of this application;
[0037] Figure 8 A schematic flowchart of another method for generating a recursive credential provided by an embodiment of this application;
[0038] Figure 9 A schematic flowchart of yet another method for generating a recursive credential provided by an embodiment of this application;
[0039] Figure 10 A schematic diagram of the composition of a consensus device for a blockchain provided by an embodiment of this application;
[0040] Figure 11 A schematic diagram of the hardware structure of a consensus device for a blockchain provided by an embodiment of this application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0041] To facilitate the understanding of this application, relevant elements involved in this application are described below.
[0042] Blockchain: Also known as distributed ledger technology, it is a new technology in which several computing devices jointly participate in "keeping accounts" (i.e., recording transaction data) and jointly maintain a complete distributed database. Due to the characteristics of blockchain technology such as decentralization (i.e., no central node), openness and transparency, each computing device can participate in database recording, and data synchronization can be quickly carried out between computing devices, blockchain technology has been widely applied in many fields.
[0043] In blockchain, transaction data is permanently stored in the form of electronic records, and the file storing these electronic records is called a "block". Blocks are generated one after another in chronological order. Each block records all transactions that occurred during its creation, and all blocks are summarized to form a chained record collection. Since the throughput of blockchain nodes in different blockchain systems is different, the size of blocks may also be different in different blockchain systems.
[0044] A block usually consists of a block header and a block body. Among them, the block header is mainly used to record the characteristic values of the current block, which may include at least one of the information such as the identifier of the current block (such as the block number), the hash value of the block body in the current block, the timestamp (used to represent the generation time of the block), the number of transactions, and the random number. In addition, the block header may also include the hash value of the previous block (specifically, the hash value of the block header in the previous block). The block body may include multiple transaction data.
[0045] Simulated annealing algorithm: Since traditional optimization algorithms are prone to falling into local optimal values, resulting in unsatisfactory overall optimization effects. With the further development of the concept of collective programming, people introduced the concept of "annealing" on the basis of the hill-climbing method and proposed the simulated annealing algorithm. That is, after each iteration of the algorithm, if the current solution is not better than the optimal solution, the algorithm will still adopt the current solution with a certain probability, and this probability is related to the temperature and the difference between the two solutions. After each iteration, the temperature is decreased according to the set parameters. The simulated annealing algorithm performs very prominently in avoiding falling into local optimal solutions and seeking the optimal solution within the interval. Moreover, compared with traditional neural network algorithms, the simulated annealing algorithm does not require training of the model, has a fast calculation speed, and can quickly and well optimize recursive vouchers.
[0046] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
[0047] In the description of this application, unless otherwise specified, " / " means "or", for example, A / B can mean A or B. "And / or" in this article is merely a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, "at least one" means one or more, and "plurality" means two or more. The words "first", "second", etc. do not limit the quantity and execution order, and the words "first", "second", etc. do not limit them to be different.
[0048] It should be noted that, in this application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in this application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.
[0049] As described in the background technology, the competitive consensus algorithm requires each node to consume a lot of resources to obtain computing power for calculation, which is extremely inefficient and has a very high resource consumption rate. The consensus speed of the negotiation consensus algorithm is slow and the network scalability is low, which is not suitable for blockchain systems with a large number of nodes. Currently, there is no algorithm that can avoid consuming a large amount of system resources while ensuring good consensus efficiency.
[0050] Based on the above problems, the embodiment of the present application provides a consensus algorithm for blockchain. Since the simulated annealing algorithm adopts the current solution with a certain probability at each iteration, if the current solution is not better than the optimal solution, the algorithm will still adopt the current solution with a certain probability, thus avoiding falling into the local optimal solution. Compared with the traditional neural network algorithm, the simulated annealing algorithm does not need to train the model, has a fast calculation speed, and can optimize the solution quickly and well. Therefore, in the consensus process of the present application, by using the simulated annealing algorithm, each node only needs to generate the corresponding recursive voucher in each iteration round according to the process, and the operation process, algorithm, and complexity of all nodes in the whole process are the same, without consuming a large amount of system resources, and can maintain good consensus efficiency and ensure the credibility of information in the block. It is suitable for blockchain systems with a large number of nodes and has good scalability.
[0051] Figure 1 The blockchain system to which the embodiment of the present application is applied is shown, and the system includes a consensus device 100 and a blockchain node 200. Among them, the blockchain node 200 includes multiple nodes, and multiple nodes in the consensus device 100 and the blockchain node 200 can communicate with each other.
[0052] The consensus device 100 can be a device with data processing and data storage capabilities. Exemplarily, the consensus device 100 can be a server, or a server cluster composed of multiple servers, or a cloud computing service center, which is not limited herein.
[0053] The blockchain node 200 is a device with communication and storage functions, such as a device storing a blockchain. Each blockchain node can both receive information and generate information.
[0054] In one implementation, the blockchain node 200 can be a physical device, such as a server or a terminal device. In another implementation, the blockchain node 200 can be a virtual computer; a virtual computer is a general term for a running environment virtualized by software in all types of virtualization devices, including virtual machines and containers. In other implementations, the blockchain node 200 can be a process or a thread; a thread is the smallest unit that the operating system can perform operation scheduling on, and a thread is included in a process and is the actual operating unit in the process; a process is a running activity of a program in a computer with respect to a certain data set and is the basic unit for the system to allocate and schedule resources.
[0055] In the embodiments of the present application, the consensus device 100 obtains the recursive certificates generated by each node in the blockchain node 200, and respectively determines whether each node meets the election requirements according to the recursive certificates of each node, so as to select multiple candidate nodes, and select a leader node from the multiple candidate nodes to complete the consensus of the blockchain.
[0056] The embodiments of the present application will be specifically described below with reference to the accompanying drawings of the specification.
[0057] As shown in Figure 2 the embodiments of the present application provide a consensus method for a blockchain, and the method includes the following steps:
[0058] S101. The consensus device sends an election request to each node in the blockchain to start an election process based on the simulated annealing algorithm.
[0059] Optionally, since the simulated annealing algorithm mainly determines whether to end the iterative process by the temperature value, when performing the election process based on the simulated annealing algorithm, it is necessary to obtain the initial temperature, the target cooling temperature, the cooling parameters in the cooling function, etc. first.
[0060] As a possible implementation, the consensus device sends a first request message for requesting to generate an initial temperature value to the current leader node in the blockchain, and the current leader node in the blockchain randomly generates a first temperature value according to the first request message and sends the first temperature value to the consensus device, and the consensus device uses the first temperature value as the initial temperature value used by the simulated annealing algorithm.
[0061] Further, the consensus device sends second request information for requesting the generation of a target cooling temperature value to each node in the blockchain. Each node in the blockchain randomly generates a second temperature value (the second temperature value should be much smaller than the initial temperature value) according to the second request information, and sends the second temperature value to the consensus device. After receiving the second temperature values sent by each node, the consensus device assigns the largest second temperature value and the smallest second temperature value in the second temperature values to 0, and then according to the formula to determine the third temperature value, which is the target cooling temperature value used in the simulated annealing algorithm. Wherein, T f represents the third temperature value, M represents the number of nodes in the blockchain, and a m represents the second temperature value of the m-th node among the M nodes.
[0062] Optionally, the consensus device randomly generates a decay parameter and uses the decay parameter as the cooling parameter used in the cooling function of the simulated annealing algorithm. Wherein, the cooling function is T = r × T0, T represents the temperature after being cooled by the cooling function, r represents the cooling parameter, 0.95 ≤ r < 1, and T0 represents the temperature value of the current iteration round.
[0063] The embodiments of the present application use a random method to enable each node in the blockchain to randomly generate and calculate the relevant parameters for simulated annealing, so as to prevent some nodes from using a derivable method to calculate the relevant parameters in advance and perform the consensus step in advance, thereby causing cheating.
[0064] S102. In each iteration round of the simulated annealing algorithm, the consensus device obtains the recursive certificates randomly generated by each node in the blockchain, and determines whether each node meets the election requirements according to the recursive certificates randomly generated by each node.
[0065] Wherein, the recursive certificate is a random number generated by each node in the blockchain according to a certain rule and is used for the iteration in the simulated annealing algorithm.
[0066] Optionally, before each iteration round of the simulated annealing algorithm, the consensus device sends a recursive certificate request message to each node in the blockchain; each node generates a recursive certificate according to the recursive certificate request message and sends the recursive certificate to the consensus device.
[0067] Of course, the recursive certificate in the present application is only an exemplary name, and the recursive certificate can also be called an iteration certificate, an election certificate, a consensus certificate, etc.
[0068] It should be understood that before the iterative process of the simulated annealing algorithm, the consensus device first obtains the initialization recursive certificates sent by each node in the blockchain and determines the average value of the initialization recursive certificates, and starts to execute the iterative process based on this.
[0069] The iterative process of the simulated annealing algorithm is introduced below. As Figure 3 shown, steps S1 - S7 are used for the consensus device to determine whether each node meets the election requirements based on the recursive certificates randomly generated by each node.
[0070] S1. Determine the average recursive certificate for the current iteration round based on the recursive certificates randomly generated by each node in the current iteration round.
[0071] Optionally, after the consensus device receives the recursive certificates sent by each node, it stores them in the recursive certificate array where represents the recursive certificate generated by node n in the k - th iteration at temperature T.
[0072] Furthermore, calculate the average recursive certificate for the current iteration round where represents the average recursive certificate for the k - th iteration round at temperature T, n represents the number of nodes in the blockchain, represents the recursive certificate generated by the i - th node in the k - th iteration at temperature T.
[0073] It should be noted that if a certain node does not return any recursive certificate within the set time threshold, its recursive certificate is assigned a value of 0, and the node with a recursive certificate of 0 is excluded when calculating the average value of the recursive certificates.
[0074] S2. Calculate the average recursive certificate change value based on the average recursive certificate for the current iteration round and the optimal average recursive certificate determined in the previous iteration round. The average recursive certificate change value is equal to the average recursive certificate for the current iteration round minus the optimal average recursive certificate.
[0075] S3. Determine whether the average recursive certificate change value is less than 0; if so, execute step S4; if not, execute step S5.
[0076] S4. Update the optimal average recursive certificate with the average recursive certificate for the current iteration round; and for each node in the blockchain, if the recursive certificate randomly generated by the node in the current iteration round is less than the average recursive certificate for the current iteration round, it is determined that the node meets the election requirements; if the recursive certificate randomly generated by the node in the current iteration round is greater than or equal to the average recursive certificate for the current iteration round, it is determined that the node does not meet the election requirements.
[0077] Optionally, when a node meets the election requirements, the consensus device records that the number of times the node meets the election requirements is incremented by 1. When a node does not meet the election requirements, the consensus device records that the number of times the node meets the election requirements is decremented by 1.
[0078] S5. Calculate the Boltzmann probability based on the average recursive certificate change value; if the Boltzmann probability is greater than or equal to the randomly generated probability threshold, execute step S6; if the Boltzmann probability is less than the probability threshold, execute step S7.
[0079] Optionally, according to the formula calculate the Boltzmann probability, where boltz represents the Boltzmann probability, Δcost represents the average recursive certificate change value, k represents the Boltzmann constant, and T represents the temperature value of the current iteration round.
[0080] S6. Reject updating the optimal average recursive certificate with the average recursive certificate of the current iteration round, and determine that each node in the blockchain does not meet the election requirements.
[0081] Optionally, when rejecting to update the optimal average recursive certificate with the average recursive certificate of the current iteration round, the consensus device records that the number of times all nodes on the blockchain meet the election requirements is -1.
[0082] S7. Update the optimal average recursive certificate with the average recursive certificate of the current iteration round; and, for each node in the blockchain, if the randomly generated recursive certificate of the node in the current iteration round is less than the average recursive certificate of the current iteration round, determine that the node meets the election requirements; if the randomly generated recursive certificate of the node in the current iteration round is greater than or equal to the average recursive certificate of the current iteration round, determine that the node does not meet the election requirements.
[0083] S8. Determine whether the current iteration number is less than or equal to the maximum iteration number at the current temperature; if so, perform the next iteration and return to step S1; if not, execute step S9.
[0084] S9. Reduce the temperature by r times according to the cooling parameter to obtain the reduced target temperature.
[0085] S10. Determine whether the target temperature is less than or equal to the target cooling temperature; if so, return to step S1; if not, the iteration ends and step S103 is executed.
[0086] The operation process of the above simulated annealing algorithm will be represented in the form of pseudocode below.
[0087]
[0088]
[0089] As can be seen from the above, the selection of candidate nodes is only related to the recursive certificates calculated by each node during each iteration, and is directly determined by the number of times the conditions are met. During the election process, each node uses the same algorithm, the same parameters, the same blockchain information, and ensures the randomness of the bookkeeping right allocation through random sampling and random numbers, regardless of the number of times a certain node has kept accounts, network speed, computing power, and the number of equity shares. Therefore, this consensus algorithm can ensure the fairness of the bookkeeping right allocation to the greatest extent. At the same time, even if several new nodes are added to the blockchain, it will not affect the iterative process of the simulated annealing algorithm. It only requires the new nodes to synchronize with other nodes and return their recursive certificates during the iteration process. Although the collected and statistical values increase, it does not affect the data processing flow, does not affect the data collection time, and the impact on data comparison can also be ignored. Therefore, this algorithm has good scalability and is suitable for scenarios with a large number of nodes.
[0090] S103. After the simulated annealing algorithm finishes running, the consensus device determines N candidate nodes according to the number of times each node meets the election requirements, where N is a positive integer greater than 1.
[0091] As a possible implementation, the consensus device selects the N nodes with the most times of meeting the election requirements as candidate nodes according to the number of times each node meets the election requirements.
[0092] S104. The consensus device selects a leader node from the N candidate nodes based on a preset leader node selection rule.
[0093] Since the simulated annealing algorithm will still adopt the current solution with a certain probability in each iteration if the current solution is not better than the optimal solution, it avoids falling into a local optimal solution. And compared with the traditional neural network algorithm, the simulated annealing algorithm does not need to train the model, has a fast calculation speed, and can quickly and well optimize the solution. Therefore, in the consensus process of this application, by using the simulated annealing algorithm, each node only needs to generate corresponding recursive certificates within a certain time according to the process and continuously iterate according to the steps. And in the whole process, the number of operations, algorithms, and complexity of all nodes are the same, without consuming a large amount of system resources, can maintain good consensus efficiency and ensure the credibility of the information in the block, is suitable for blockchain systems with a large number of nodes, and has good scalability.
[0094] Optionally, as Figure 4 shown, step S104 can be specifically implemented as steps S1041 - S1043:
[0095] S1041. The consensus device sends notification messages to the N candidate nodes respectively, so that each candidate node packs the block and broadcasts the packed block to other nodes in the blockchain.
[0096] Among them, the block packaged by the candidate node includes a block header, and the block header includes multiple recursive certificates generated by the candidate node during the election process, as well as the relevant data used for generating recursive certificates each time.
[0097] Optionally, the relevant data used for generating recursive certificates each time includes multiple first hash grouping tables, second hash grouping tables, and random number Rc generated by the candidate node during the election process, the identity information of the node, the hash value of the previous block, the Merkle root (MT), the timestamp information, etc.
[0098] Optionally, the block packaged by the candidate node further includes a block body, and the block body includes the number of bytes occupied by the transactions of the candidate node, the number of transactions in the block, the transaction data stored in the block, etc.
[0099] S1042. The consensus device obtains the verification data of each candidate node.
[0100] Among them, the verification data of the candidate node includes the verification results of each node in the blockchain on the block packaged by the candidate node.
[0101] Optionally, the verification results of each node in the blockchain on the block packaged by the candidate node include 1 or 0. Among them, 1 indicates that the candidate node passes the verification of the node, and 0 indicates that the candidate node fails to pass the verification of the node.
[0102] Exemplarily, when there are 10 nodes in the blockchain in total, the verification data of the candidate node may be 1, 1, 1, 1, 1, 0, 0, 1, 0, 0.
[0103] S1043. The consensus device selects a leader node from the N candidate nodes according to the verification data of each candidate node.
[0104] Optionally, before step S1042, as Figure 5 shown, it further includes step S1044:
[0105] S1044. The consensus device broadcasts iterative data to each node in the blockchain, so that each node in the blockchain verifies the block packaged by the candidate node according to the iterative data.
[0106] Among them, the iterative data includes the optimal average recursive certificate of each iteration round of the simulated annealing algorithm, and the judgment results of each candidate node in each iteration round, and the judgment results are used to indicate whether the candidate node meets the election requirements.
[0107] Optionally, after each node in the blockchain receives the iterative data, each node respectively parses the information contained in the block header of the block packaged by the candidate node, extracts multiple recursive certificates generated by the candidate node in the election process, the first hash grouping table, the second hash grouping table, and the values of all Rc, and randomly selects Rv groups of data. Each group of data is arranged in the order of [the first hash grouping table, the second hash grouping table, the recursive certificate, Rc]. It should be understood that each group of data in the Rv groups of data represents the data of the same iteration round in the simulated annealing algorithm.
[0108] Further, each node verifies whether the recursive certificate of the candidate node in the corresponding iteration round is correct according to the first hash grouping table, the second hash grouping table, and Rc of each group of data in the Rv groups of data, and verifies whether the number of times the candidate node meets the election requirements in this iteration round is correct by comparing the recursive certificate of the candidate node in each iteration round with the optimal average recursive certificate of this iteration round. If both the recursive certificate and the number of times of meeting the election requirements are correct, the node records the verification value of this group of data as 1, otherwise records it as 0.
[0109] After each node completes the verification of the Rv groups of data of the candidate node, each node multiplies the verification values of the Rv groups of data to obtain the verification result of each node for the block packaged by the candidate node, and each node respectively sends the verification result to the consensus device.
[0110] It should be understood that when any one node verifies the Rv groups of data of the candidate node, as long as the verification value of one group of data is 0, the verification result of this node for the candidate node indicates that the verification fails. Only when the verification values of the Rv groups of data of the candidate node are all 1, the verification result of this node for the candidate node indicates that the verification passes.
[0111] In the above embodiment, by verifying whether the recursive certificates of each candidate node in the election process and the number of times of meeting the election requirements are correct, nodes that cause the number of times the candidate node meets the verification requirements to be incorrect due to calculation errors in the election process can be screened out, so as to ensure that the finally selected leader node is the optimal node.
[0112] Optionally, as Figure 6 shown, step S1044 can be specifically implemented as steps S10441 - S10443:
[0113] S10441. The consensus device determines the arrangement order of the N candidate nodes according to the number of times each candidate node meets the election requirements.
[0114] Exemplarily, there are currently 3 candidate nodes A, B, and C. The number of times node A meets the election requirements is 16 times, the number of times node B meets the election requirements is 21 times, and the number of times node C meets the election requirements is 22 times. Then the arrangement order of the 3 candidate nodes is C, B, A.
[0115] S10442. The consensus device sequentially determines whether the verification data of the candidate nodes meets the verification requirements according to the arrangement order of the N candidate nodes.
[0116] Optionally, the consensus device first verifies whether the candidate node with the most times of meeting the election requirements meets the verification requirements according to the arrangement order of the N candidate nodes.
[0117] Among them, the verification requirements include: the ratio between the number of verification results indicating passing the verification in the verification data and the total number of verification results included in the verification data is greater than a preset ratio threshold.
[0118] Exemplarily, if the preset ratio threshold is 2 / 3 and there are 10 nodes on the blockchain, the verification results of the first candidate node sent by the 10 nodes to the consensus device are 1, 1, 1, 1, 0, 1, 1, 0, 1, 1 respectively. Among them, the number of verification results passing the verification is 8, and the ratio between the number of verification results passing the verification and the total number of verification results included in the verification data is 4 / 5, which is greater than the preset ratio threshold. This indicates that the verification data of the first candidate node meets the verification requirements.
[0119] S10443. The consensus device determines the candidate node whose first verification data meets the verification requirements as the leader node.
[0120] It should be understood that if the verification data of the first candidate node does not meet the verification requirements, the consensus device continues to determine whether the verification data of the second candidate node meets the verification requirements until the consensus device determines a candidate node whose verification data meets the verification requirements and determines it as the leader node.
[0121] As can be seen from the above embodiments, according to the number of times each candidate node meets the election requirements, the candidate node with the most times of meeting the election requirements is verified first, so as to ensure that the leader node is the optimal node.
[0122] Optionally, since the simulated annealing algorithm is based on recursive vouchers and selects the leader node through iterative selection of recursive vouchers, an exemplary method for generating recursive vouchers is given below, as Figure 7 shown, the method includes the following steps:
[0123] S501. The first node generates a first hash grouping table and a second hash grouping table.
[0124] Among them, the first hash grouping table and the second hash grouping table are used to store the hash values of the blocks on the blockchain.
[0125] Optionally, before the start of each iteration round of the simulated annealing algorithm, the first node receives a recursive credential request message sent by the consensus device. After receiving the recursive credential request message, the first node generates a random number Rr, where Rr is a positive integer and 1 ≤ Rr ≤ H, and H represents the total height of the blocks in the blockchain.
[0126] Furthermore, the first node randomly selects Rr blocks and stores the hash values of the Rr blocks in the first hash grouping table, and stores the hash values corresponding to the other blocks except the Rr blocks on the current blockchain in the second hash grouping table.
[0127] It should be understood that all the blocks in the blockchain and their corresponding hash values can be obtained according to the first hash grouping table and the second hash grouping table.
[0128] S502. The first node generates a recursive credential according to the first hash grouping table and the second hash grouping table.
[0129] As a possible implementation, as Figure 8 shown, step S502 can be implemented as steps S5021 - S5023:
[0130] S5021. The first node generates a first coordinate value according to the first hash grouping table.
[0131] Optionally, as Figure 9 shown, step S5021 can be specifically implemented as steps S50211 - S50214:
[0132] S50211. The first node obtains a random number Rc,
[0133] where Rc is an integer greater than or equal to 0 and less than or equal to 15.
[0134] Optionally, the random number Rc can be generated by the consensus device and sent to the first node.
[0135] S50212. The first node performs a hash operation on the first hash grouping table to obtain a first hash value.
[0136] Optionally, the method of the hash operation can adopt MD5, SHA - 256, or SHA - 512, etc. in the prior art, as long as all the nodes in the blockchain adopt a unified hash operation method. The embodiments of the present application do not make limitations here.
[0137] S50213. The first node compares each hexadecimal value in the first hash value with Rc to determine the number of hexadecimal values in the first hash value that are greater than Rc.
[0138] Optionally, since Rc is a decimal value, first convert Rc from a decimal value to a hexadecimal value.
[0139] S50214. The first node uses the number of hexadecimal values in the first hash value that are greater than Rc as the first coordinate value.
[0140] Exemplarily, if Rc is 6 and the first hash value is 54afe54ec1, it can be seen that the number of hexadecimal values in the first hash value that are greater than Rc is 5, that is, the first coordinate value is 5.
[0141] S5022. The first node generates a second coordinate value according to the second hash grouping table.
[0142] Similarly, for the specific implementation manner of step S5022, reference can be made to steps S50211 - S50214, and details will not be elaborated here.
[0143] S5023. The first node generates a recursive certificate according to the first coordinate value and the second coordinate value.
[0144] In a possible implementation manner, the first node calculates the recursive certificate according to the formula where represents the recursive certificate generated by node n in the k - th iteration at temperature T, x represents the first coordinate value, and y represents the second coordinate value.
[0145] It should be understood that the above - mentioned method for generating the recursive certificate is only a possible implementation manner given in the embodiments of the present application. In addition, the first node can also generate a first hash grouping table, a second hash grouping table, and a third hash grouping table, and generate a recursive certificate according to the first hash grouping table, the second hash grouping table, and the third hash grouping table. Of course, those skilled in the art can also think of other equivalent alternative ways or obvious variant ways. As long as the solutions can achieve the same technical effects, they all fall within the protection scope of the present application.
[0146] Since the generation of the first hash grouping table and the second hash grouping table is random, uncertain, and unpredictable, any node cannot predict the elements and arrangement order of the first hash grouping table and the second hash grouping table of other nodes. Therefore, it is impossible to predict the recursive certificates of other nodes, and thus it is impossible to determine whether the obtained recursive certificate meets the election requirements, which ensures the feasibility of recursive certificate optimization and also ensures the feasibility and fairness of the consensus algorithm.
[0147] Optionally, before step S102, the consensus device first needs to verify whether the values of the initial temperature, target cooling temperature, and cooling parameters involved in step S101 are appropriate to ensure the feasibility of the actual consensus algorithm and prevent the core steps of the consensus algorithm from being executed too quickly due to improper parameter selection in the consensus step, which may further lead to insufficient fairness in selecting winning nodes or the algorithm execution process being too slow, resulting in a significant decline in system performance.
[0148] Specifically, after the consensus device obtains the initial parameters, it sets the maximum number of iterations at the initial temperature. After setting, it starts the pre-execution step and records the start time of the pre-execution step.
[0149] For pre-execution, since the main purpose is to detect whether the selected parameters are appropriate rather than finding the optimal solution, there is no need to perform the optimal solution solving step. It only needs to complete the iterative process of the simulated annealing algorithm according to the initial parameters to detect whether the system running time and complexity in the simplest mode are reasonable. Therefore, at the initial temperature T0, to give the simplest model and greatly reduce the pre-execution time, the average recursive certificate change value for each iteration is set to 1, and there is no need to solve.
[0150] After completing all iterations at the initial temperature T0, the current temperature is reduced through the cooling function to obtain the reduced temperature value T1. The simulated annealing algorithm is executed again at temperature T1. After completing all iterations at temperature T1, the temperature is reduced again through the cooling function until the reduced temperature is lower than the target cooling temperature, and the pre-execution step ends, and the end time of the pre-execution step is obtained.
[0151] Furthermore, the theoretical minimum execution time in the simplest model is calculated based on the start time and end time of the pre-execution step, and the consensus device determines whether this time meets the preset requirements to judge whether the consensus method is feasible under these parameters. If it meets the preset requirements, the consensus method is feasible, and the consensus device starts the node election process. Otherwise, the node election process is rejected and the parameter selection is restarted to prevent waste of system resources.
[0152] As a possible implementation method, the implementation process of the consensus device for pre-execution is as follows:
[0153]
[0154]
[0155] The embodiment of this application introduces a feasibility verification link, uses the negotiated simulated annealing parameters, and uses the simplest model to verify the overall feasibility of the simulated annealing. If its running time is too long, the overall running time of the algorithm can be controlled by adjusting the initial temperature T0, the target cooling temperature Tf, and the cooling function parameter r.
[0156] As can be seen, the above mainly introduced the solution provided by the embodiments of the present application from the perspective of methods. To implement the above functions, it includes the corresponding hardware structures and / or software modules for executing each function. Those skilled in the art should easily realize that, in combination with the modules and algorithm steps of each example described in the embodiments disclosed in this article, the embodiments of the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a certain function is executed in the way of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present invention.
[0157] The embodiments of the present application can divide the function modules of the control device according to the above method examples. For example, each function module can be divided corresponding to each function, or two or more functions can be integrated into one processing module. The above integrated modules can be implemented in the form of hardware or in the form of software function modules. Optionally, the division of modules in the embodiments of the present application is illustrative, and is only a logical function division. There can be other division methods in actual implementation.
[0158] As Figure 10 shown, the embodiments of the present application provide a schematic composition diagram of a consensus device for a blockchain. The device includes: a sending module 701, an obtaining module 702, and a processing module 703.
[0159] The sending module 701 is used to send an election request to each node in the blockchain to start the election process based on the simulated annealing algorithm;
[0160] The obtaining module 702 is used to obtain the recursive certificates randomly generated by each node in the blockchain in each iteration round of the simulated annealing algorithm, and determine whether each node meets the election requirements according to the recursive certificates randomly generated by each node;
[0161] The processing module 703 is used to determine N candidate nodes after the simulated annealing algorithm runs to completion, where N is a positive integer greater than 1; and select a leader node from the N candidate nodes based on a preset leader node selection rule.
[0162] As Figure 11 shown, the present application also provides a schematic hardware structure diagram of a consensus device 80 for a blockchain, including a processor 801 and a memory 802. Optionally, the processor 801 and the memory 802 are connected by a bus 804.
[0163] The processor 801 may be a central processing unit (CPU), a general-purpose processor, a network processor (NP), a digital signal processor (DSP), a microprocessor, a microcontroller, a programmable logic device (PLD), or any combination thereof. The processor may also be any other device with processing capabilities, such as a circuit, a device, or a software module. The processor 801 may also include multiple CPUs, and the processor 801 may be a single-CPU processor or a multi-CPU processor. The processor here may refer to one or more devices, circuits, or processing cores for processing data (such as computer program instructions).
[0164] The memory 802 may be a read-only memory (ROM) or other type of static storage device that can store static information and instructions, a random access memory (RAM), or other type of dynamic storage device that can store information and instructions. It may also be an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM), or other optical disc storage (including compressed optical discs, laser discs, optical discs, digital versatile discs, Blu-ray discs, etc.), a magnetic disk storage medium, or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer. The embodiments of the present application do not impose any restrictions on this. The memory 802 may exist independently or be integrated with the processor 801. Among them, the memory 802 may contain computer program code. The processor 801 is used to execute the computer program code stored in the memory 802, thereby implementing the method provided by the embodiments of the present application.
[0165] The communication interface 803 may be used to communicate with other devices or communication networks (such as Ethernet, radio access network (RAN), wireless local area networks (WLAN), etc.).
[0166] The bus 804 can be a peripheral component interconnect (PCI) bus, an extended industry standard architecture (EISA) bus, or the like. The bus 804 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 11 it is only represented by a thick line in Figure 11 , but it does not mean that there is only one bus or one type of bus.
[0167] An embodiment of the present invention also provides a computer-readable storage medium. The computer-readable storage medium includes computer-executable instructions. When the computer-executable instructions run on a computer, the computer is caused to execute the consensus method provided in the above embodiment.
[0168] An embodiment of the present invention also provides a computer program product. The computer program product can be directly loaded into a memory and contains software code. After the computer program product is loaded and executed by a computer, it can implement the consensus method provided in the above embodiment.
[0169] In the above embodiment, it can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using a software program, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer-executable instructions. When the computer-executable instructions are loaded and executed on a computer, the processes or functions described in the embodiments of the present application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer-executable instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer-executable instructions can be transmitted from a website, a computer, a server, or a data center to another website, a computer, a server, or a data center by wire (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wirelessly (such as infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server, a data center, etc. that contains one or more integrated media. The available medium can be a magnetic medium (such as a floppy disk, a hard disk, a magnetic tape), an optical medium (such as a DVD), or a semiconductor medium (such as a solid state disk (SSD)), etc.
[0170] Although the present application has been described in connection with various embodiments, it will be understood by those skilled in the art that other variations of the disclosed embodiments can be understood and effected while practicing the claimed application, by reference to the drawings, the disclosure, and the appended claims. In the claims, the term "comprising" does not exclude other elements or steps, the word "a" or "an" does not exclude a plurality of instances, and a single processor or other unit may fulfill the functions recited in several claims. Certain measures are recited in mutually different dependent claims, but this does not indicate that these measures cannot be combined to advantage.
[0171] Although the present application has been described in connection with specific features and their embodiments, it will be apparent that various modifications and combinations can be made without departing from the spirit and scope of the present application. Accordingly, the specification and drawings are merely exemplary illustrations of the application defined by the appended claims and are considered to cover any and all modifications, variations, combinations, or equivalents within the scope of the present application.
[0172] The above are only specific embodiments of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application should be covered by the protection scope of the present application. Therefore, the protection scope of the present application should be determined by the protection scope of the claims.
Claims
1. A consensus method for a blockchain, characterized in that, The method includes: The consensus device sends an election request to each node in the blockchain to start the election process based on the simulated annealing algorithm; In each iteration round of the simulated annealing algorithm, the consensus device obtains the recursive certificates randomly generated by each node in the blockchain, and determines whether each node meets the election requirements according to the recursive certificates randomly generated by each node; After the simulated annealing algorithm runs to completion, the consensus device determines N candidate nodes according to the number of times each node meets the election requirements, where N is a positive integer greater than 1; The consensus device selects a leader node from the N candidate nodes based on a preset leader node selection rule; Among them, the consensus device determines N candidate nodes according to the number of times each node meets the election requirements, including: the consensus device selects the N nodes with the most times of meeting the election requirements as candidate nodes according to the number of times each node meets the election requirements; The consensus device determines whether each node meets the election requirements according to the recursive certificates randomly generated by each node, including the following steps: S1. Determine the average recursive certificate of the current iteration round according to the recursive certificates randomly generated by each node in the current iteration round; S2. Calculate the average recursive certificate change value according to the average recursive certificate of the current iteration round and the optimal average recursive certificate determined in the previous iteration round, where the average recursive certificate change value is equal to the average recursive certificate of the current iteration round minus the optimal average recursive certificate; S3. Determine whether the average recursive certificate change value is less than 0; if so, execute step S4; if not, execute step S5; S4. Update the optimal average recursive certificate with the average recursive certificate of the current iteration round; and for each node in the blockchain, if the recursive certificate randomly generated by the node in the current iteration round is less than the average recursive certificate of the current iteration round, it is determined that the node meets the election requirements; if the recursive certificate randomly generated by the node in the current iteration round is greater than or equal to the average recursive certificate of the current iteration round, it is determined that the node does not meet the election requirements; S5. Calculate the Boltzmann probability according to the average recursive certificate change value; if the Boltzmann probability is greater than or equal to the randomly generated probability threshold, execute step S6; if the Boltzmann probability is less than the probability threshold, execute step S7; S6. Reject updating the optimal average recursive certificate with the average recursive certificate of the current iteration round, and determine that each node in the blockchain does not meet the election requirements; S7. Update the optimal average recursive certificate with the average recursive certificate of the current iteration round; and for each node in the blockchain, if the recursive certificate randomly generated by the node in the current iteration round is less than the average recursive certificate of the current iteration round, it is determined that the node meets the election requirements; if the recursive certificate randomly generated by the node in the current iteration round is greater than or equal to the average recursive certificate of the current iteration round, it is determined that the node does not meet the election requirements.
2. The method according to claim 1, wherein The consensus device selects a leader node from the N candidate nodes based on a preset leader node selection rule, including: The consensus device sends notification messages to the N candidate nodes respectively, so that each candidate node packs a block and broadcasts the packed block to other nodes in the blockchain; The consensus device obtains the verification data of each candidate node, and the verification data of the candidate node includes the verification results of each node in the blockchain on the block packed by the candidate node; The consensus device selects a leader node from the N candidate nodes according to the verification data of each candidate node.
3. The method according to claim 2, wherein The block packed by the candidate node includes a block header, and the block header includes a plurality of recursive certificates generated by the candidate node in the election process and the relevant data used for generating the recursive certificate each time.
4. The method according to claim 3, characterized in that, Before the consensus device obtains the verification data of each candidate node, the method further includes: The consensus device broadcasts iteration data to each node in the blockchain, so that each node in the blockchain verifies the block packed by the candidate node according to the iteration data; wherein, the iteration data includes the optimal average recursive certificate of each iteration round of the simulated annealing algorithm and the judgment results of each candidate node in each iteration round, and the judgment results are used to indicate whether the candidate node meets the election requirements.
5. The method according to claim 2, wherein The consensus device selects a leader node from the N candidate nodes according to the verification data of each candidate node, including: The consensus device determines the arrangement order of the N candidate nodes according to the number of times each candidate node meets the election requirements; The consensus device sequentially determines whether the verification data of the candidate nodes meet the verification requirements according to the arrangement order of the N candidate nodes; The consensus device determines the candidate node whose verification data meets the verification requirements first as the leader node.
6. The method according to claim 5, wherein The verification requirements include: the ratio between the number of verification results indicating passing verification in the verification data and the total number of verification results included in the verification data is greater than a preset ratio threshold.
7. The method according to claim 1, characterized in that, Before the consensus device sends an election request to each node in the blockchain, the method further includes: The consensus device sends a first request message to the current leader node in the blockchain, and the first request message is used to request to generate an initial temperature value; The consensus device receives a first temperature value from the current leader node in the blockchain; The consensus device uses the first temperature value as the initial temperature value used by the simulated annealing algorithm.
8. The method according to claim 7, characterized in that The method further includes: The consensus device sends a second request message to each node in the blockchain, and the second request message is used to request to generate a target cooling temperature value; The consensus device receives second response messages from each node in the blockchain, and the second response messages include second temperature values; The consensus device determines a third temperature value according to the second temperature values of each node; The consensus device uses the third temperature value as the target cooling temperature value used by the simulated annealing algorithm.
9. The method according to claim 1, wherein The recursive certificate is generated according to a first hash grouping table and a second hash grouping table. The first hash grouping table is used to record the hash values corresponding to each of the Rr blocks on the current blockchain randomly selected by a node. The second hash grouping table is used to record the hash values corresponding to each of the other blocks on the current blockchain except the Rr blocks. Rr is a positive integer.
10. The method according to claim 9, wherein The recursive certificate is specifically determined according to a first coordinate value and a second coordinate value. The first coordinate value is determined according to the first hash grouping table. The second coordinate value is determined according to the second hash grouping table.
11. A consensus device for a blockchain, characterized in that, The device includes: a sending module, configured to send an election request to each node in the blockchain to start an election process based on the simulated annealing algorithm; an obtaining module, configured to, in each iteration round of the simulated annealing algorithm, obtain the recursive certificates randomly generated by each node in the blockchain, and determine whether each node meets the election requirements according to the recursive certificates randomly generated by each node; a processing module, configured to, after the simulated annealing algorithm runs to completion, determine N candidate nodes according to the number of times each node meets the election requirements, where N is a positive integer greater than 1; and select a leader node from the N candidate nodes based on a preset leader node selection rule; wherein, the consensus device determines N candidate nodes according to the number of times each node meets the election requirements, including: the consensus device selects the N nodes with the most times of meeting the election requirements as candidate nodes according to the number of times each node meets the election requirements; The consensus device determines whether each node meets the election requirements according to the recursive certificates randomly generated by each node, including the following steps: S1. Determine the average recursive certificate of the current iteration round according to the recursive certificates randomly generated by each node in the current iteration round; S2. Calculate an average recursive certificate change value according to the average recursive certificate of the current iteration round and the optimal average recursive certificate determined in the previous iteration round. The average recursive certificate change value is equal to the average recursive certificate of the current iteration round minus the optimal average recursive certificate; S3. Determine whether the average recursive certificate change value is less than 0; if so, execute step S4; if not, execute step S5; S4. Update the optimal average recursive certificate with the average recursive certificate of the current iteration round; and for each node in the blockchain, if the recursive certificate randomly generated by the node in the current iteration round is less than the average recursive certificate of the current iteration round, determine that the node meets the election requirements; if the recursive certificate randomly generated by the node in the current iteration round is greater than or equal to the average recursive certificate of the current iteration round, determine that the node does not meet the election requirements; S5. Calculate a Boltzmann probability according to the average recursive certificate change value; if the Boltzmann probability is greater than or equal to a randomly generated probability threshold, execute step S6; if the Boltzmann probability is less than the probability threshold, execute step S7; S6. Reject updating the optimal average recursive certificate with the average recursive certificate of the current iteration round, and determine that each node in the blockchain does not meet the election requirements; S7. Update the optimal average recursive certificate with the average recursive certificate of the current iteration round; and for each node in the blockchain, if the recursive certificate randomly generated by the node in the current iteration round is less than the average recursive certificate of the current iteration round, it is determined that the node meets the election requirements; if the recursive certificate randomly generated by the node in the current iteration round is greater than or equal to the average recursive certificate of the current iteration round, it is determined that the node does not meet the election requirements.
12. A computer-readable storage medium, characterized in that It includes computer instructions that implement the consensus method as described in any one of claims 1-10 when the computer instructions run on a computer.
Citation Information
Patent Citations
System for realizing optimization operation by using block chain consensus computing power
CN110705773A
Decentralized latent semantic index using distributed average consensus
US20190228025A1