Data processing method and device, consensus node and storage medium
By introducing mapping processing and smart contracts into blockchain consensus nodes to generate target hash values, the problem of wasted computing resources during the consensus process is solved, consensus efficiency and flexibility are improved, and the application scalability of the blockchain network is promoted.
Patent Information
- Application Number
- CN202110992110.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-26
- Publication Date
- 2025-12-12
- Estimated Expiration
- 2041-08-26
AI Technical Summary
In existing blockchain consensus processes, there is a serious waste of computing resources, resulting in wasted computing power and low consensus efficiency.
By introducing mapping processing and smart contracts into consensus nodes, a target hash value is generated, and candidate answers are used to assist in hash value generation, reducing the waste of computing resources and improving consensus efficiency.
It effectively reduces the waste of computing resources of consensus nodes, improves the efficiency and flexibility of consensus processing, supports the solution of more real-life problems, and promotes the application scalability of blockchain networks.
Smart Images

Figure CN115718794B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computers, and in particular to a data processing method and device, a consensus node, and a storage medium. BACKGROUND
[0002] With the continuous development of blockchain network technology, the security and tamper resistance of data storage based on the blockchain, many data are requested to be stored on the chain, and when data is stored on the chain, the data is usually stored in a block, and then the block is stored on the chain after consensus. The existing consensus process for blocks is mostly by calculating a reference hash value less than a target hash value, and directly storing on the chain after generating the reference hash value. Using such a consensus mechanism can cause waste of computing resources in the consensus process. Therefore, how to avoid waste of computing resources in the consensus process of blocks has become a research hotspot. SUMMARY
[0003] The embodiments of the present application provide a data processing method and device, a consensus node, and a storage medium, which can effectively reduce the waste of computing resources in the consensus processing of the consensus node.
[0004] In one aspect, the embodiments of the present application provide a data processing method, comprising:
[0005] In the process of consensus processing of the target block, a first hash value and a problem to be solved are obtained; wherein the first hash value is generated based on the target block;
[0006] In the solution space of the problem, the first hash value is mapped to obtain a candidate answer of the problem;
[0007] The target hash value of the target block is generated according to the candidate answer and the first hash value;
[0008] The target hash value is verified, and the target block is added to the blockchain after verification.
[0009] In another aspect, the embodiments of the present application provide a data processing device, comprising:
[0010] The obtaining unit is configured to obtain a first hash value and a problem to be solved in the process of consensus processing of a target block; wherein the first hash value is generated based on the target block;
[0011] The processing unit is configured to map the first hash value in the solution space of the problem to obtain a candidate answer of the problem;
[0012] The processing unit is further configured to generate a target hash value of the target block according to the candidate answer and the first hash value.
[0013] The processing unit is further configured to check the target hash value, and add the target block to a block chain after the check is successful.
[0014] In another aspect, an embodiment of the present application provides a consensus node, comprising a processor, an input device, an output device and a memory, which are connected to each other, wherein the memory is configured to store a computer program supporting the consensus node to execute the method, the computer program comprises program instructions, and the processor is configured to invoke the program instructions to perform the following steps:
[0015] In the process of consensus processing on the target block, a first hash value and a problem to be solved are obtained, wherein the first hash value is generated based on the target block;
[0016] In the solution space of the problem, the first hash value is mapped to obtain a candidate answer of the problem;
[0017] The target hash value of the target block is generated according to the candidate answer and the first hash value;
[0018] The target hash value is checked, and the target block is added to a block chain after the check is successful.
[0019] In another aspect, an embodiment of the present application provides a computer readable storage medium, wherein the computer readable storage medium stores program instructions, and the program instructions are executed by a processor to perform the data processing method of the first aspect.
[0020] In the embodiment of the present application, in the process of consensus processing of the target block, the consensus node can generate a first hash value based on the target block, and map the first hash value based on the obtained solution space of the problem to be solved to obtain a candidate answer of the problem, and then generate a target hash value of the target block according to the candidate answer and the first hash value, so that the consensus node can find the hash value for verification, and the introduction of the solution process of the problem to be solved is realized, so that the consensus node can calculate the hash value to be checked, not only the hash operation, but also the calculation of the actual useful problem in production and life by the computing power. Because the solution of the problem in actual life can improve the efficiency of the user in actual life, the consensus node can assist the actual production and life of the user by solving the problem related to the actual life in the process of consensus processing of the target block, so it can be understood that the computing power of the consensus node can help the actual production and life of the user in the process of consensus processing of the target block, that is, the waste of computing resources of the consensus node is reduced. In addition, because the problem to be solved obtained by the consensus node is represented by the smart contract, and the smart contract is used to represent the problem to be solved, it has more flexibility, can improve the flexibility in representing the problem, and can represent the problem more widely, so as to improve the universality and expansibility of the consensus node in the process of consensus combined with the solution process of the problem. BRIEF DESCRIPTION OF DRAWINGS
[0021] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.
[0022] Figure 1 is a schematic diagram of a blockchain system provided by an embodiment of the present application;
[0023] Figure 2 is a schematic flow chart of a data processing method provided by an embodiment of the present application;
[0024] Figure 3a is a schematic diagram of the structure of a target block provided by an embodiment of the present application;
[0025] Figure 3b is a schematic diagram of a blockchain provided by an embodiment of the present application;
[0026] Figure 3c is a schematic diagram of a smart contract provided by an embodiment of the present application;
[0027] Figure 4 This is a schematic flowchart of a data processing method provided in an embodiment of the present invention;
[0028] Figure 5 This is a schematic diagram of a consensus processing procedure provided in an embodiment of the present invention;
[0029] Figure 6 This is a schematic block diagram of a data processing device provided in an embodiment of the present invention;
[0030] Figure 7 This is a schematic block diagram of a consensus node provided in an embodiment of the present invention. Detailed Implementation
[0031] This application proposes a data processing method. After a consensus node packages data into a target block, the node can use a proof-of-work consensus mechanism to add the target block to the blockchain and obtain corresponding reward electronic resources. In other words, the process of the consensus node performing proof-of-work is the process of consensus processing for the target block. During this consensus processing, the consensus node can use candidate answers obtained from solving the problem to assist in generating the target hash value of the target block. The consensus result can then be determined based on the verification of the target hash value. Thus, the consensus node, during the proof-of-work process (i.e., the consensus processing), not only reflects its main computing power at the level of calculating the block hash value but also at the level of solving the problem. This allows the consensus node's computing power to be invested in meaningful problem-solving calculations, reducing the waste of its computing resources. In one embodiment, the consensus node is any consensus node in the blockchain network. It can be understood that any node in the blockchain network (including the consensus node) can be composed of a single computer device or terminal device, or it can be a cluster of devices composed of multiple computer devices or multiple terminal devices. Blockchain networks are a type of data-sharing system, such as... Figure 1 As shown, the data sharing system 100 refers to a system for data sharing between nodes. This system may include multiple nodes 101. Each node 101, during normal operation, can receive input information and maintain shared data within the system based on the received input information. To ensure information exchange within the data sharing system, each node in the system 100 can have an information connection, allowing for information transmission between nodes. For example, when any node in the data sharing system receives input information, other nodes in the system obtain this input information according to a consensus algorithm and store it as data in the shared data, ensuring consistency of data stored on all nodes in the system.
[0032] When storing data in the blockchain network, the block storing the data is first consensus processed based on a consensus mechanism to ensure that the data recorded by each node in the blockchain network is consistent. Since the blockchain network is distributed, any node in the blockchain network stores a ledger, and there is no central node to ensure that the ledgers on the distributed nodes are the same. Therefore, the consensus mechanism can be used to ensure that the data recorded in different nodes is consistent. In an embodiment, common consensus mechanisms include Proof Of Work (POW) mechanism, Proof of Stake mechanism, and Delegated Proof of Stake mechanism. In the present embodiment, the POW mechanism is mainly used as the consensus processing mechanism for the block.
[0033] In an embodiment, when the consensus node in the blockchain network performs the proof of work to prove that the consensus node is not an attack node of the blockchain network, the consensus node can continuously change the nonce to obtain different hash values based on the hash value (or nonce) of the block header of the block. Since the consensus mechanism needs to calculate a hash value that is less than a certain target value (or check value, or check hash value), the consensus node in the blockchain network performs proof of work based on the calculation of the hash value, that is, the process of finding a hash value less than the check value. In other words, after the consensus node finds a hash value less than the check value, the proof of work is completed, and it is proved that the consensus node is not an attack node of the blockchain network. Therefore, the consensus node can broadcast the generated target block to other nodes. After the other nodes verify and confirm the hash value generated by the consensus node, the newly generated target block is added to the blockchain for storage.
[0034] In order to further improve the data security problem of the consensus node in the process of finding the hash value less than the check value, and in order to prevent the waste of computing resources of the consensus node, the consensus node can also allocate computing resources to solve the problem in the process of finding the hash value less than the check value, and the candidate answer of the problem obtained by calculation can assist in generating the block hash value. It can be understood that the generated block hash value is the hash value found by the consensus node for comparison with the check value. When the block hash value is less than the check value, it means that the consensus node has found a hash value less than the check value, so it can be determined that the target block is checked and the target block is stored on the chain. In order to prevent the consensus node from consuming too much computing power in the process of solving the answer of the problem, thereby delaying the speed of the target block being chained, or the problem being an unsolvable problem, thereby causing the consensus node to be unable to solve the answer of the problem, thereby causing the target block to be unable to be chained, when setting the problem to be solved, the problem to be solved can be set as an easy-to-verify but difficult-to-solve problem (NP problem). The NP problem is a problem that can be verified in polynomial time to obtain a correct solution, that is, without knowing the specific content of the correct answer to the problem, but for a given candidate answer, the candidate answer can be verified in polynomial time (that is, relatively easily) whether it is the correct answer to the corresponding problem. That is, the consensus node does not need to exhaust the answer to the NP problem when solving the answer to the NP problem, but only needs to find a candidate answer that satisfies being verified as a correct answer in polynomial time.
[0035] Among them, the polynomial time refers to the calculation time of a problem not greater than the polynomial multiple of the size of the problem, that is, if a problem includes n items, the size of the problem can be considered as n, and if the problem is solved and the correct answer is obtained, the time satisfies the polynomial n j , it can be considered that the problem can be solved in polynomial time, and if the problem is solved and the correct answer is obtained, the time satisfies the polynomial j n , the problem cannot be solved in polynomial time, where j is a positive integer greater than or equal to 1. That is, based on the difference in problem size, the time required to solve the corresponding problem is also different, and the larger the problem (such as the number of items included in the problem), the longer the time required for the solving process. Therefore, in order to shorten the solving process of the NP problem of the consensus node, a correct answer can be found in polynomial time, without finding all correct answers to the NP problem, thereby reducing the computing pressure of the consensus node.
[0036] Please refer to Figure 2This is a schematic flowchart illustrating a data processing method proposed in an embodiment of this application. This data processing method can be executed by the aforementioned consensus node, wherein the consensus node can be any consensus node in the blockchain network, such as... Figure 2 As shown, the method may include:
[0037] S201, during the consensus processing of the target block, obtain the first hash value and the problem to be solved; wherein, the first hash value is generated based on the target block.
[0038] The target block stores the target data. After obtaining the target data, when the consensus node needs to store the target data on the blockchain, it can first package the target data into the target block. The block structure of the target block can be as follows: Figure 3a As shown, the target block includes a block header and a block body. The block header stores information such as input feature values, version number, timestamp, and difficulty value. The block body is mainly used to store the data to be stored in the blockchain network. The blockchain stored in each node of the blockchain network is a chain structure composed of multiple blocks, such as... Figure 3b As shown, the multiple blocks that make up this blockchain are linked together by linking the header of the next block with the header of the previous block. After the consensus node stores the data to be stored in the blockchain network into the target block, it can first perform consensus processing on the target block. After consensus is passed, the data to be stored can be stored on the chain. When performing consensus processing on the target block, the consensus node can first generate a first hash value based on the target block. In a specific implementation, the consensus node can generate this first hash value based on the block header data stored in the target block's header and a generated random number (nonce). When generating the first hash value based on the block header data and the random number, the consensus node can perform a hash operation on the block header data and the random number, using the hash result as the first hash value. Alternatively, the consensus node can also use an encryption algorithm to encrypt the block header data and the random number, and use the ciphertext generated based on the block header data and the random number as the first hash value.
[0039] In one embodiment, in order to carry out the proof of work and realize the on-chain storage of the data stored in the target block, after the consensus node generates a first hash value based on the block header data and a random number of the target block, the consensus node needs to further find a target hash value less than the check value based on the first hash value. In the process of finding the target hash value less than the check value based on the first hash value, in order not to waste the computing power (or computing power) of the consensus node, the consensus node can obtain a problem from the to-be-solved problem as a problem to be solved, so as to solve the problem, so as to generate the target hash value according to the candidate answer of the problem obtained by solving and the first hash value.
[0040] In one embodiment, the problem obtained by the consensus node is obtained from a problem queue to be solved, wherein the consensus node can obtain the problem arranged at the front of the problem queue based on the arrangement order of the problem queue to solve, or the consensus node can also randomly obtain a problem from the problem queue to be solved to solve. The problems in the problem queue are published by any node in the blockchain network, and in order to enable the problems published by any node in the blockchain network to be selected by the consensus node to solve, the any node will use a smart contract to represent the problem when publishing the problem and deploy the smart contract to the blockchain. Therefore, since any consensus node in the blockchain network can call the smart contract on the blockchain, the representation of the problem by the smart contract can enable the consensus node to read the to-be-solved problem by calling the smart contract during the process of solving the target block, and solve the problem.
[0041] After the consensus node obtains the first hash value of the target block and the problem to be solved, the problem can be solved to obtain the candidate answer of the problem, that is, the consensus node can execute step S202.
[0042] S202, mapping the first hash value in the solution space of the problem to obtain the candidate answer of the problem.
[0043] After obtaining the problem to be solved, the consensus node can map the first hash value based on the solution space of the problem to obtain a candidate answer of the problem. Since the problem is represented by a smart contract and published to the chain, the smart contract representing the problem includes a solution space obtaining function (get SpaceInfo) associated with the problem. When the consensus node obtains the problem by calling the smart contract, it also obtains the solution space obtaining function of the problem. Then, based on the solution space obtaining function, the correct answer range of the problem, i.e., the solution space of the problem, can be obtained. After the consensus node determines the solution space of the problem, the first hash value can be mapped to obtain a candidate answer of the problem.
[0044] In one embodiment, if the problem to be solved obtained by the consensus node is a Diophantine problem, i.e., finding three numbers whose cubes sum to 42 in a certain range, the smart contract created by publishing the Diophantine problem to the blockchain can be as shown in Figure 3c In the smart contract, get SpaceInfo is used to indicate the solution space of the Diophantine problem, i.e., the solution space range of the three solutions X, Y, and Z required is [-1*10 20 , 1*10 20 ]. After determining the solution space range, mapping can be performed based on the solution space range of each solution, i.e., mapping X, Y, and Z based on the solution space [-1*10 20 , 1*10 20 ]. If the mapped values correspond to X1, Y1, and Z1, the consensus node can determine that the candidate answer of the problem is X1, Y1, and Z1. Figure 3cIf the candidate answer is verified based on the verification function and the candidate answer passes the verification, it indicates that the consensus node finds a correct answer to the problem, otherwise, the candidate answer is not a correct answer to the problem. That is, when the consensus node determines that the candidate answer to the Diophantine problem is X1, Y1 and Z1, the consensus node can verify the candidate answer X1, Y1 and Z1 by substituting X1, Y1 and Z1 into the solve function, wherein the solve function returns verification result indication information after verifying the candidate answer X1, Y1 and Z1, and the verification result indication information is True if the solve function determines that the candidate answer X1, Y1 and Z1 passes the verification, and the verification result indication information is False if the solve function determines that the candidate answer X1, Y1 and Z1 fails the verification. Correspondingly, if the verification result indication information obtained by the consensus node from the solve function is True, it indicates that the candidate answer X1, Y1 and Z1 is a correct answer to the Diophantine problem, and if the verification result indication information obtained by the consensus node from the solve function is False, it indicates that the candidate answer X1, Y1 and Z1 is not a correct answer to the Diophantine problem.
[0045] In an embodiment, when the consensus node performs mapping processing to obtain the candidate answer to the problem, the consensus node can perform mapping processing by using modulo operation, or can perform mapping processing by using random mapping. After the computer device obtains the candidate answer to the problem, the computer device can further generate a target hash value based on the candidate answer and the first hash value, so as to prove the computing power based on the generated target hash value. In an embodiment, the process of proving the computing power of the consensus node based on the target hash value is the process of proving the work of the consensus node based on the target hash value. When the consensus node proves the computing power based on the generated target hash value, if the target hash value passes the verification, it is determined that the consensus node obtains the right to record the target block, and then the consensus node adds the target block to the blockchain. If the target hash value fails the verification, it is determined that the consensus node cannot obtain the right to record the target block.
[0046] S203, generating a target hash value of a target block based on the candidate answer and the first hash value.
[0047] S204, verifying the target hash value, and adding the target block to the blockchain after the verification succeeds.
[0048] In steps S203 and S204, after obtaining the candidate answer of the problem to be solved based on the mapping processing of the first hash value, the consensus node can further verify the correctness of the candidate answer of the problem, and in the process of verifying the correctness of the candidate answer, the target hash value of the target block is generated according to the candidate answer and the first hash value. It can be understood that the target hash value generated by the consensus node according to the candidate answer and the first hash value is the hash value found by the consensus node in the consensus process, which is used to compare with the check value and to prove the work. Then it can be further understood that after the consensus node generates the target hash value of the target block, it can check the target hash value based on the check value, so that after the target hash value is verified successfully, it can be determined that the consensus of the target block is completed, and the target block is added to the block chain for storage. It can be understood that based on the on-chain of the target block, that is, the on-chain of the data stored in the target block is realized, thereby realizing the uploading of the data to the block chain network for storage.
[0049] In an embodiment, since the problem to be solved is represented by a smart contract, in order to enable the consensus node to generate the target hash value of the target block based on the candidate answer and the first hash value in the process of verifying the correctness of the candidate answer, the consensus node can call the smart contract through a blockchain virtual machine (e.g., Ethereum virtual machine) when calling the smart contract to obtain the problem to be solved and verifying the correctness of the candidate answer of the problem through the smart contract. In an embodiment, the blockchain virtual machine is a stack-based virtual machine, and the stack-based blockchain virtual machine includes one or more stack frames, and each stack frame stores one or more reference elements. Therefore, when the consensus node calls the smart contract through the blockchain virtual machine, the operation of the blockchain virtual machine can be implemented, and through the operation of the blockchain virtual machine, the consensus node can further determine the target sampling frequency of the blockchain virtual machine based on the candidate answer, and then the consensus node can sample the blockchain virtual machine based on the target sampling frequency, and select reference elements from the sampled stack frames of the blockchain virtual machine to aggregate to obtain the second hash value. When the consensus node samples the blockchain virtual machine based on the target sampling frequency and selects the corresponding reference elements based on the sampling, the consensus node can determine the top stack frame from the sampled stack frames of the blockchain virtual machine in the process of sampling the blockchain virtual machine based on the target sampling frequency, and select the elements in the top stack frame (i.e., the top of the stack) as the reference elements. Alternatively, the computer device can randomly select the stored elements from the sampled stack frames as the reference elements based on the sampling process. In an embodiment, the number of reference elements selected by the consensus node can be one or more, and after the computer device selects one or more reference elements, the computer device can perform hash operation on the selected one or more reference elements to obtain the second hash value. In which, the consensus node can perform combined hash operation on the one or more reference elements using a non-cryptographic hash function to obtain the second hash value, or the consensus node can perform pairwise hash operation on the one or more reference elements in sequence to finally obtain the second hash value.
[0050] Since early blockchain platforms do not support Turing-complete lambda-calculus paradigm, which limits the development of blockchain technology, most of the subsequent blockchain platforms support Turing-complete smart contracts to meet the needs of various business scenarios. By introducing smart contracts and lambda-calculus logic on the blockchain, custom execution logic (such as the above-mentioned problem to be solved) can be placed on the blockchain for running instead of simple transaction transfers. With the advent of smart contracts, the application of the blockchain system is more diverse and practical, and the custom program function supported by the blockchain system makes the system more powerful and flexible. In an embodiment, a smart contract is deployed on the chain after being compiled into bytecode and runs in a blockchain virtual machine, so that the consensus node can call the deployed smart contract through the blockchain virtual machine.
[0051] After the consensus node aggregates the second hash value based on the sampling of the blockchain virtual machine, the consensus node can generate the target hash value of the target block based on the first hash value and the second hash value. Since the determination process of the second hash value is determined by the candidate answer, the consensus node realizes the generation process of the target hash value of the target block assisted by the candidate answer obtained by solving the answer. Since the generated target hash value is the hash value found by the consensus node for matching, the consensus node can determine whether the target block is successfully consensus by verifying the target hash value after generating the target hash value of the target block, and determine that the target block is successfully consensus when the target hash value is verified successfully, so that the target block can be added to the blockchain for storage. The process of generating the target hash value based on the first hash value and the second hash value is also the hash operation of the consensus node on the first hash value and the second hash value. When the consensus node performs the hash operation on the first hash value and the second hash value, it can be operated by using the above-mentioned non-cryptographic hash function, or it can also be operated by using other hash functions on the first hash value and the second hash value.
[0052] In the embodiments of the present application, in the process of consensus processing of the target block, the consensus node can generate a first hash value based on the target block, and map the first hash value based on the obtained solution space of the problem to be solved to obtain a candidate answer of the problem, and then generate a target hash value of the target block according to the candidate answer and the first hash value, so that when the consensus node searches for the hash value for verification, the introduction of the solving process of the problem to be solved is realized, so that the consensus node can calculate the hash value to be checked not only by performing hash operation, but also by investing computing power to calculate useful problems in actual production and life to be solved. Since the solution of the problem in actual life can improve the efficiency of the user in actual life, the consensus node can assist the actual production and life of the user by solving the problem related to the actual life in the process of consensus processing of the target block. Therefore, it can be understood that since the computing power of the consensus node realizes the assistance to the actual production and life of the user in the process of consensus processing of the target block, the waste of computing resources of the consensus node is reduced. In addition, since the problem to be solved obtained by the consensus node is represented by the smart contract, and the problem to be solved is represented by the smart contract, it has more flexibility, can improve the flexibility in representing the problem, can represent the problem more widely, and can improve the universality and expansibility of the consensus node in the process of consensus combined with the solving process of the problem.
[0053] In an embodiment, the problem to be solved obtained by the consensus node can be a problem closely related to actual production and life, and the consensus node can solve the problem related to actual production and life in the process of consensus processing on the target block, so as to realize the purpose of assisting the actual production and life of the user by transferring part of the computing power of the consensus node to the solving process of the problem related to actual production and life. The problem to be solved can be an NP problem uploaded by the user to the blockchain network and not yet solved, or can be an actual application problem uploaded by the user to the blockchain network. The node device can solve (or verify) the NP problem not yet solved, which is conducive to the verification of mathematical problems in actual life, thereby promoting the development of mathematical process. Solving (or verifying) the actual application problem can enable the user to improve the corresponding production and life based on the answer to the problem. In an embodiment, the actual problem can be a production problem, such as a problem of selecting a specific user from a user set or a problem of production efficiency of a computer device. After the consensus node solves the actual problem and obtains an answer, the answer can be fed back to the corresponding user through the blockchain network, so that the user can perform subsequent production and life processes based on the feedback answer, thereby improving the efficiency of the user and achieving the purpose of assisting the actual production and life of the user. In addition, when the user submits an actual problem, the blockchain network can directly add the problem submitted by the user to the problem sequence for solving by the consensus node after receiving the actual problem, or the blockchain network can first convert the actual problem into an NP problem after receiving the actual problem submitted by the user, and then add the converted problem to the problem sequence for solving.
[0054] Please refer to Figure 4 , which is a schematic flowchart of a data processing method according to an embodiment of the present application, as shown in Figure 4 , the method can include:
[0055] S401, in the process of consensus processing on the target block, obtaining a first hash value and a problem to be solved; wherein the first hash value is generated based on the target block.
[0056] S402, in the solution space of the problem, mapping the first hash value to obtain a candidate answer of the problem.
[0057] In step S401 and step S402, the target block is a block including the to-be-stored data. After the consensus node receives the to-be-stored data, the consensus node can first store the to-be-stored data in the target block, and then store the target block on a chain after completing the consensus of the target block, so as to store the to-be-stored data in the blockchain network. In an embodiment, when the consensus node performs the consensus on the target block, the consensus node can perform the consensus on the target block by using the proof-of-work consensus mechanism. In order to avoid wasting the computing power of the consensus node when the consensus is performed by using the proof-of-work consensus mechanism, the consensus node can solve a problem in the consensus process. Specifically, the consensus node can first obtain a first hash value generated based on the target block. When obtaining the first hash value, the consensus node can first obtain block header data from a block header of the target block and generate a random number (nonce). Then, the consensus node can perform a hash operation on the block header data and the random number, and take the result of the hash operation as the first hash value. In other implementations, when obtaining the first hash value, the consensus node can also perform a hash operation on all block data of the target block and a generated random number, and take the result of the hash operation on the all block data and the random number as the first hash value.
[0058] In the process of performing the consensus on the target block by the consensus node, in addition to obtaining the first hash value, the problem to be solved also needs to be obtained to avoid wasting the computing power of the consensus node. Since each problem to be solved is represented by a smart contract and published to the blockchain network, the consensus node can obtain the problem to be solved by calling the smart contract. After the consensus node obtains the problem to be solved, the consensus node can also determine the solution space of the problem, and then map the first hash value based on the solution space to obtain the candidate answer of the problem. In an embodiment, when obtaining the solution space of the problem, the consensus node can first obtain the smart contract corresponding to the problem from the blockchain network, and obtain the solution space acquisition function (such as the above-mentioned get SpaceInfo function) associated with the problem according to the smart contract. Further, the consensus node can call the solution space acquisition function to obtain the answer range of the problem, and take the obtained answer range as the solution space of the problem.
[0059] After the consensus node obtains the solution space of the question, the consensus node can perform mapping processing on the first hash value in the solution space, so as to obtain the candidate answer of the question. In a specific implementation, the consensus node can first obtain the answer range of the question indicated by the solution space of the question, and perform modulo operation on the first hash value according to the answer range; and then the consensus node can take the result of the modulo operation as the candidate answer of the question. In an embodiment, if the consensus node calculates the first hash value as H, and the solution space of the question to be solved obtained satisfies: {1 < x < 10, 2 < y < 100, 3 < z < 300}, then the consensus node can obtain the candidate answer of the question by performing mapping processing on the first hash value H based on the solution space, which can satisfy formula (1), and A in formula (1) is the candidate answer of the question.
[0060] A = {x1 = H%9 + 1, y1 = H%98 + 2, z1 = H%297 + 3} Formula (1)
[0061] After the consensus node obtains the candidate answer of the question, the consensus node can verify the candidate answer, and in the verification process, the target hash value of the target block is generated, that is, the consensus node can perform step S403.
[0062] S403, obtaining a constraint condition required to be satisfied by the correct answer of the question, and verifying the candidate answer by using the constraint condition to verify the correctness of the candidate answer.
[0063] S404, in the process of verifying the candidate answer by using the constraint condition, generating a second hash value according to the candidate answer, and generating a target hash value of a target block according to the second hash value and the first hash value.
[0064] In step S403 and step S404, when the consensus node checks the candidate answer to the question, the constraint condition required to be met by the correct answer to the question can be obtained, so that the constraint condition can be used to check the candidate answer. In an embodiment, the constraint condition may, for example, be the condition that the cube sum of the answer in the Diophantine equation question is 42, or the condition that the answer in the right triangle solving question satisfies the Pythagorean theorem, etc. Wherein the constraint condition required to be met by the correct answer to the question is associated with the question, and when the question is submitted, the constraint condition required to be met by the correct answer associated with the corresponding question is submitted together, then the consensus node can obtain the constraint condition required to be met by the correct answer to the question when obtaining the question to be solved. In addition, since the question is represented by the smart contract, the constraint condition required to be met by the correct answer to the question can also be represented by the smart contract, wherein the constraint condition required to be met by the correct answer can be recorded in the smart contract by using the solve function. It can be understood that the consensus node obtains the constraint condition required to be met by the correct answer by calling the smart contract.
[0065] In one embodiment, since the constraint condition is also recorded in the smart contract, and the smart contract is deployed in the blockchain virtual machine, that is, the constraint condition is deployed in the blockchain virtual machine, wherein the blockchain virtual machine includes one or more stack frames, and one or more reference elements are stored in any stack frame, when the consensus node generates the second hash value according to the candidate answer in the process of verifying the candidate answer by using the constraint condition, the incentive resource (i.e. gas) required for verifying the candidate answer in the process of verifying the candidate answer by using the constraint condition can be determined. In one embodiment, the incentive resource is stored in the blockchain virtual machine as a count for work amount calculation, and when the count reaches a preset value, the running of the smart contract will be terminated and the running of the blockchain virtual machine will be exited. After the smart contract is deployed in the blockchain virtual machine (EVM) for running, since the blockchain virtual machine is a stack-based virtual machine, which contains a series of instructions such as Load (load instruction), store (store instruction), push (exit instruction), etc., in order to prevent malicious contracts (such as smart contracts containing endless loops) from running infinitely in the blockchain virtual machine, the stack-based virtual machine introduces a GAS mechanism (i.e. exit mechanism) to avoid the situation of infinite running of the blockchain virtual machine. Among them, the GAS mechanism specifies the amount of incentive resource consumed by each instruction, then when the user needs to call the corresponding smart contract to execute in the blockchain virtual machine, the user needs to send a certain amount of incentive resource to the blockchain virtual machine first, and the blockchain virtual machine will trigger the calling of the smart contract only after obtaining the corresponding amount of incentive resource, and the stack-based blockchain virtual machine will terminate the running of the smart contract and exit after determining that the incentive resource sent by the user is consumed, thereby effectively preventing the blockchain virtual machine from being in an endless loop execution state, and avoiding malicious attacks on the blockchain network.
[0066] After the consensus node determines the incentive resource required for checking the candidate answer, the target sampling frequency of the blockchain virtual machine can be determined according to the incentive resource; wherein, if the consensus node determines that the solve function (or solve instruction) of the smart contract needs to be called for checking the candidate answer, and the execution of the solve function needs to consume 10000 gas, then the consensus node can determine that the incentive resource required for checking the candidate answer is 10000 gas, and further, based on the required 10000 gas, the target sampling frequency of the blockchain virtual machine can be determined to be 10%. It can be understood that after the consensus node determines the target sampling frequency, the target sampling frequency can be used to sample and process one or more stack frames to select a target stack frame from the one or more stack frames, and generate a second hash value according to the reference element stored in the target stack frame. Wherein, the selected target stack frame is the stack frame associated with the candidate answer. Wherein, if the target sampling frequency determined by the consensus node is 10%, then the consensus node will sample the stack of the blockchain virtual machine every 1000 gas (10% sampling rate), and if the target stack frame determined by the consensus node after sampling is the stack of the blockchain virtual machine, then the second hash value can be generated based on the reference element stored in the top of the stack.
[0067] In one embodiment, the number of reference elements stored in the target stack frame of the blockchain virtual machine can be one or more. When the number of reference elements stored in the target stack frame is multiple, the consensus node can perform hash aggregation processing on any two of the multiple reference elements stored in the target stack frame until an intermediate aggregation element is obtained. In one embodiment, if the reference elements stored in the target stack frame of the blockchain virtual machine include <s1, s2, s3, s4>, then the consensus node can perform two-by-two hash operation on the reference elements using a non-cryptographic hash function (FNV function), that is, the FNV function can be used to perform hash calculation on the reference elements s1 and s2 to obtain FNV(s1, s2), and the FNV function can be used to perform hash calculation on the reference elements s3 and s4 to obtain FNV(s3, s4), and after obtaining FNV(s1, s2) and FNV(s3, s4), the intermediate aggregation element S_cur can be obtained, wherein the intermediate aggregation element satisfies formula (2).
[0068] S_cur = FNV(FNV(s1, s2), FNV(s3, s4)) Formula (2)
[0069] After obtaining the intermediate aggregation element, the consensus node can obtain the aggregation parameter generated in the last round of aggregation process according to the target sampling frequency, and generate a second hash value according to the aggregation parameter generated in the last round of aggregation process and the intermediate aggregation element. The last round of aggregation process is the process of generating the aggregation parameter based on the candidate answer of the previous problem selected from the problem queue to solve the problem. In an embodiment, if the consensus node obtains the aggregation parameter generated in the last round of aggregation process as S_pre, the consensus node generates a second hash value based on the aggregation parameter S_pre generated in the last round of aggregation process and the intermediate aggregation element S_cur obtained in the current round of aggregation process, which can be denoted as S, wherein the second hash value S satisfies formula (3).
[0070] S = FNV (S_pre, S_cur) = FNV (S_pre, FNV (s1, s2), FNV (s3, s4)) Formula (3)
[0071] The process of the consensus node verifying the correctness of the candidate answer is the process of substituting the candidate answer into the solve function of the smart contract for running. Since the stack frame of the blockchain virtual machine will be sampled and aggregated according to the target sampling frequency to obtain the second hash value S, and the second hash value S and the first hash value H will be further hashed to obtain the target hash value H1 of the target block, wherein H1 satisfies formula (4).
[0072] H1 = Hash (S, H) Formula (4)
[0073] Wherein, when the consensus node calculates the solve function each time, if the return value is True, it indicates that the candidate answer is a correct answer to the problem. When it is determined that the candidate answer is a correct answer, the consensus node will not directly chain the target block, but will select a new problem from the problem queue for solving until the target hash value is successfully verified (i.e. H1 is less than the check hash value). In an embodiment, the problem is any problem in the problem queue, and the problem queue includes a plurality of problems to be solved. Then, after the consensus node generates the second hash value, it can also determine that the candidate answer passes the verification by using the constraint condition, and then select another problem from the problem queue for solving to obtain another candidate answer of the problem until the target hash value generated based on the candidate answer of the problem and the first hash value is successfully verified. That is, in the process of substituting the candidate answer into the solve function of the smart contract for running, the consensus node will obtain the second hash value based on the sampling and aggregation of the blockchain virtual machine, and in the process of operating the second hash value, it can be ensured that the consensus node has solved the problem, rather than randomly generated answers. At the same time, it can also avoid the security problems caused by directly chaining the target block based on the verification of the solution to the problem.
[0074] S405, check the target hash value, and add the target block to the block chain after the check is successful.
[0075] After generating the target hash value H1 of the target block, the consensus node can compare the target hash value with the check hash value target to check the target hash value H1. When the target hash value H1 is less than the check hash value target, it is determined that the target hash value is checked successfully, so that the target block can be chained. In an embodiment, when checking the target hash value, the consensus node can obtain the check hash value and compare the target hash value with the check hash value. Then, when the target hash value is less than the check hash value, it is determined that the check of the target hash value is successful; otherwise, it is determined that the check of the target hash value fails. The target hash value is generated according to a random number. In an embodiment, if the consensus node determines that the check of the target hash value fails, the random number can be updated to obtain an updated random number (nonce), and the first hash value is regenerated using the updated random number. The update of the random number includes: performing an add-one operation on the random number, and taking the random number after the add-one operation as the updated random number, or generating a new random number less than the random number as the updated random number, so that a new round of calculation of the target hash value can be performed based on the updated random number.
[0076] Next, the consensus processing flow of the target block will be described in detail. Figure 5 The consensus node can first generate a random number nonce, and calculate a first hash value H based on the block header data of the target block, that is, H = Hash (nonce, block header data of the target block). In addition, the consensus node can obtain the smart contract corresponding to the problem to be solved from the problem queue, and call the get SpaceInfo function in the smart contract to obtain the solution space of the problem, so that the candidate answer (x1, y1, z1) of the problem to be solved can be obtained by taking the modulus of H based on the solution space, and the candidate answer (x1, y1, z1) can be substituted into the solve function of the smart contract to obtain a second hash value S by sampling and aggregating the block chain virtual machine. After obtaining the second hash value S, the block hash value H1 of the target block can be further calculated based on the first hash value H, and when the block hash value H1 is less than the check hash value target, the target block is chained, otherwise, the random number is updated and a new round of hash operation is started. In an embodiment, since the necessary condition for the consensus node to chain the target block is that the final hash value H1 is less than the check hash value target, and H1 is obtained by hashing H and S, which is unpredictable, the consensus node cannot control the difficulty of the problem to affect the block generation of the network.
[0077] Further, in order to obtain an H1, the consensus node will select a random number nonce at the beginning of each round of calculation, and calculate the corresponding H, and map H to the candidate answer, and then sample and aggregate the blockchain virtual machine to obtain S, to finally obtain H1. In this calculation process, since the problem is extracted from the problem queue, the consensus node cannot predict the generation of H, S and H1, so that the consensus node cannot obtain an advantage in computing power by controlling the difficulty of the problem. That is, even if the consensus node issues a problem with no solution, in order to calculate a legal H1 that meets the conditions, the consensus node cannot avoid checking the candidate answer of the problem, that is, the calculation of solve, so the consensus node cannot obtain an advantage in computing power by means of a problem with no solution, and can effectively avoid the attack of the consensus node on the blockchain network. Taking Ethereum as an example, the blockchain network can adjust the verification hash value (target) to make the block chaining speed (i.e. block generation speed) the same as that of the Ethereum main network, that is, to generate a block every 15 seconds. Then, the full network computing power in these 15 seconds is used for two parts of calculation, one part for hash calculation, and the other part for useful problem calculation (i.e. including the operation of the candidate answer of the problem to be solved, and the correctness verification of the candidate answer), so as to put part of the computing power in the proof of work process of the consensus node into meaningful problem calculation, so as to reduce the waste of computing power resources.
[0078] In the embodiment of the present application, in the process of consensus processing of the target block, by obtaining the first hash value and the problem to be solved, the consensus node can map the first hash value based on the solution space of the problem, so as to obtain the candidate answer of the problem. Since the problem is represented by a smart contract, the means of representing the problem is more flexible, which can widen the application range of the present application. After the consensus node obtains the candidate answer of the problem, the consensus node can verify the candidate answer based on the constraint condition required to be met by the correct answer of the problem, and generate a second hash value in the verification process. Since the constraint condition and the problem are represented by a smart contract, and the smart contract is deployed in a blockchain virtual machine, the consensus node can combine the verification process of the candidate answer of the problem and the aggregation sampling process of the blockchain virtual machine in the process of verifying the candidate answer of the problem, so as to ensure the security of the blockchain network, and also enable the consensus node to use computing power to calculate meaningful problems in the consensus process, thereby reducing the waste of computing power resources of the consensus node. In addition, after generating the second hash value, the consensus node generates a target hash value based on the second hash value and the first hash value, and determines whether to chain the target block by comparing the target hash value with the verification hash value. Since the second hash value is generated based on the stack sampling of the blockchain virtual machine, and a non-cryptographic hash function is used for sampling aggregation in the stack sampling process, it is finally determined whether the target block can be chained. Therefore, by combining the calculation problem of the blockchain virtual machine and the stack sampling problem, the consensus node must verify the problem to generate a block, thereby avoiding the problem of obtaining computing power advantage by the consensus node through unsolvable problems, and further ensuring the security of the blockchain system.
[0079] Based on the description of the above data processing method embodiment, the embodiment of the present application further proposes a data processing device, which can be a computer program (including program code) running in the above consensus node. The data processing device can be used to execute the data processing method as described in Figure 2 and Figure 4 . Please refer to Figure 6 , the data processing device includes an acquisition unit 601 and a processing unit 602.
[0080] The acquisition unit 601 is configured to acquire a first hash value and a problem to be solved in the process of consensus processing of a target block, wherein the first hash value is generated based on the target block.
[0081] The processing unit 602 is configured to map the first hash value in the solution space of the problem to obtain a candidate answer of the problem.
[0082] The processing unit 602 is further configured to generate a target hash value of the target block according to the candidate answer and the first hash value.
[0083] The processing unit 602 is further configured to verify the target hash value, and add the target block to a block chain after verification.
[0084] In an embodiment, the obtaining unit 601 is specifically configured to:
[0085] obtain block header data from a block header of the target block, and generate a random number;
[0086] perform a hash operation on the block header data and the random number, and take a result of the hash operation as the first hash value.
[0087] In an embodiment, the obtaining unit 601 is further configured to obtain a smart contract corresponding to the question from a block chain network, and obtain a solution space obtaining function associated with the question according to the smart contract;
[0088] The obtaining unit 601 is further configured to call the solution space obtaining function, obtain an answer range of the question, and take the obtained answer range as the solution space of the question.
[0089] In an embodiment, the processing unit 602 is specifically configured to:
[0090] obtain an answer range of the question indicated by the solution space of the question, and perform a modulo operation on the first hash value according to the answer range;
[0091] take a result of the modulo operation as a candidate answer of the question.
[0092] In an embodiment, the processing unit 602 is specifically configured to:
[0093] obtain a constraint condition required to be satisfied by a correct answer of the question, and verify the candidate answer by using the constraint condition to verify correctness of the candidate answer;
[0094] In the process of verifying the candidate answer by using the constraint condition, a second hash value is generated according to the candidate answer, and a target hash value of the target block is generated according to the second hash value and the first hash value.
[0095] In an embodiment, the constraint condition is deployed in a block chain virtual machine, the block chain virtual machine includes one or more stack frames, and one or more reference elements are stored in any stack frame; and the processing unit 602 is specifically configured to:
[0096] In the process of verifying the candidate answer by using the constraint condition, an incentive resource required for verifying the candidate answer is obtained, and a target sampling frequency of the blockchain virtual machine is determined according to the incentive resource;
[0097] The one or more stack frames are sampled at the target sampling frequency, so as to select a target stack frame from the one or more stack frames; wherein the target stack frame is a stack frame associated with the candidate answer;
[0098] A second hash value is generated according to a reference element stored in the target stack frame.
[0099] In an embodiment, if the number of reference elements stored in the target stack frame is multiple; the processing unit 602 is specifically configured to:
[0100] Any two of the multiple reference elements stored in the target stack frame are subjected to hash aggregation processing until an intermediate aggregation element is obtained;
[0101] According to the target sampling frequency, an aggregation parameter generated in a previous aggregation process is obtained, and a second hash value is generated according to the aggregation parameter generated in the previous aggregation process and the intermediate aggregation element; the previous aggregation process is a process of generating an aggregation parameter based on a candidate answer of a previous problem selected before the problem in the problem queue.
[0102] In an embodiment, the problem is any problem in a problem queue, and the problem queue includes multiple problems to be solved; the processing unit 602 is further configured to, if the candidate answer passes the verification by using the constraint condition, select another problem from the problem queue for solving, obtain a candidate answer of the another problem, and repeat the process until a target hash value generated based on the candidate answer of the problem and the first hash value is successfully verified.
[0103] In an embodiment, the processing unit 602 is specifically configured to:
[0104] A verification hash value is obtained, and the target hash value and the verification hash value are compared;
[0105] When the target hash value is less than the verification hash value, it is determined that the verification of the target hash value is successful; otherwise, it is determined that the verification of the target hash value fails.
[0106] In an embodiment, the target hash value is generated according to a random number; the processing unit 602 is further configured to, when it is determined that the verification of the target hash value fails, update the random number to obtain an updated random number, and regenerate the first hash value by using the updated random number.
[0107] The updating of the random number includes: performing an addition operation on the random number, and taking the random number after the addition operation as the updated random number, or regenerating a new random number smaller than the random number as the updated random number.
[0108] In the embodiment of the present application, in the process of consensus processing on the target block, the obtaining unit 601 can first obtain the first hash value generated based on the target block, so that the processing unit 602 can map the first hash value based on the obtained solution space of the problem to be solved, to obtain the candidate answer of the problem, and then the processing unit 602 can generate the target hash value of the target block according to the candidate answer and the first hash value, so that when the hash value for verification is found, the introduction based on the solving process of the problem to be solved is realized, so that the calculation of the useful problem in actual production and life by the computing power is also realized in addition to the hash operation when calculating the hash value to be checked. Since the solution of the problem in actual life can improve the efficiency of the user in actual life, the solution of the problem related to actual life can assist the actual production and life of the user in the process of consensus processing on the target block, so it can be understood that the computing power can assist the actual production and life of the user in the process of consensus processing on the target block, that is, the waste of computing resources of the consensus node is reduced. In addition, since the problem to be solved obtained by the obtaining unit 601 is represented by the smart contract, and the smart contract is used to represent the problem to be solved, it has more flexibility, can improve the flexibility in representing the problem, and can represent the problem more widely, so as to improve the universality and expansibility of the consensus node in the process of block hash operation combined with the solution process of the problem in the consensus process.
[0109] Please refer to Figure 7 , which is a structural schematic diagram of a consensus node provided by an embodiment of the present application. As Figure 7 shown, the consensus node in the embodiment can include: one or more processors 701, one or more input devices 702, one or more output devices 703, and a memory 704. The above-mentioned processor 701, input device 702, output device 703 and memory 704 are connected through bus 705. The memory 704 is used to store a computer program, the computer program includes program instructions, and the processor 701 is used to execute the program instructions stored in the memory 704.
[0110] The memory 704 can include volatile memory, such as random-access memory (RAM); the memory 704 can also include non-volatile memory, such as flash memory, solid-state drive (SSD), etc.; the memory 704 can also include a combination of the above-mentioned kinds of memory.
[0111] The processor 701 can be a central processing unit (CPU). The processor 701 can further include a hardware chip. The hardware chip can be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), etc. The PLD can be a field-programmable gate array (FPGA), a generic array logic (GAL), etc. The processor 701 can also be a combination of the above-mentioned structures.
[0112] In the embodiment of the application, the memory 704 is configured to store a computer program, the computer program including program instructions; the processor 701 is configured to execute the program instructions stored in the memory 704, so as to implement the steps of the above-mentioned method. Figure 2 and Figure 4
[0113] In one embodiment, the processor 701 is configured to invoke the program instructions, so as to execute the following:
[0114] In the process of consensus processing on the target block, a first hash value and a problem to be solved are obtained; the first hash value is generated based on the target block;
[0115] In the solution space of the problem, the first hash value is mapped to obtain a candidate answer of the problem;
[0116] According to the candidate answer and the first hash value, a target hash value of the target block is generated;
[0117] The target hash value is checked, and the target block is added to the block chain after the check is successful.
[0118] In one embodiment, the processor 701 is configured to invoke the program instructions, so as to execute the following:
[0119] obtaining block header data from a block header of the target block, and generating a random number;
[0120] performing a hash operation on the block header data and the random number, and taking a result of the hash operation as a first hash value.
[0121] In an embodiment, the processor 701 is configured to invoke the program instructions to perform:
[0122] obtaining a smart contract corresponding to the problem from a blockchain network, and obtaining a solution space obtaining function associated with the problem according to the smart contract;
[0123] invoking the solution space obtaining function to obtain an answer range of the problem, and taking the obtained answer range as a solution space of the problem.
[0124] In an embodiment, the processor 701 is configured to invoke the program instructions to perform:
[0125] obtaining an answer range of the problem indicated by the solution space of the problem, and performing a modulo operation on the first hash value according to the answer range;
[0126] taking a result of the modulo operation as a candidate answer of the problem.
[0127] In an embodiment, the processor 701 is configured to invoke the program instructions to perform:
[0128] obtaining a constraint condition to be satisfied by a correct answer of the problem, and verifying the candidate answer using the constraint condition to verify the correctness of the candidate answer;
[0129] In the process of verifying the candidate answer using the constraint condition, generating a second hash value according to the candidate answer, and generating a target hash value of the target block according to the second hash value and the first hash value.
[0130] In an embodiment, the constraint condition is deployed in a blockchain virtual machine, the blockchain virtual machine includes one or more stack frames, and one or more reference elements are stored in any stack frame; the processor 701 is configured to invoke the program instructions to perform:
[0131] In the process of verifying the candidate answer using the constraint condition, obtaining an incentive resource required when verifying the candidate answer, and determining a target sampling frequency of the blockchain virtual machine according to the incentive resource;
[0132] sample the one or more stack frames according to the target sampling frequency to select a target stack frame from the one or more stack frames; wherein the selected target stack frame is a stack frame associated with the candidate answer;
[0133] generate a second hash value according to a reference element stored in the target stack frame.
[0134] In one embodiment, if the number of reference elements stored in the target stack frame is multiple; the processor 701 is configured to invoke the program instructions for performing:
[0135] performing hash aggregation processing on any two of the multiple reference elements stored in the target stack frame until an intermediate aggregation element is obtained;
[0136] According to the target sampling frequency, the aggregation parameter generated in the last round of aggregation process is obtained, and the second hash value is generated according to the aggregation parameter generated in the last round of aggregation process and the intermediate aggregation element; the last round of aggregation process is the process of generating aggregation parameter based on the candidate answer of the previous question selected before the question in the question queue.
[0137] In one embodiment, the question is any question in the question queue, and the question queue includes multiple questions to be solved; the processor 701 is configured to invoke the program instructions for performing:
[0138] If the candidate answer is determined to pass the verification by using the constraint condition, another question is selected from the question queue for solving to obtain the candidate answer of the another question, until the target hash value generated based on the candidate answer of the question and the first hash value is successfully verified.
[0139] In one embodiment, the processor 701 is configured to invoke the program instructions for performing:
[0140] Obtaining a verification hash value and comparing the target hash value with the verification hash value;
[0141] When the target hash value is less than the verification hash value, it is determined that the verification of the target hash value is successful; otherwise, it is determined that the verification of the target hash value fails.
[0142] In one embodiment, the target hash value is generated according to a random number; the processor 701 is configured to invoke the program instructions for performing:
[0143] When it is determined that the verification of the target hash value fails, the random number is updated to obtain an updated random number, and the first hash value is regenerated by using the updated random number;
[0144] The updating of the random number includes: performing an addition operation on the random number, and taking the random number after the addition operation as the updated random number, or regenerating a new random number smaller than the random number as the updated random number.
[0145] The embodiment of the present application provides a computer program product or a computer program, the computer program product or the computer program comprising computer instructions stored in a computer readable storage medium. A processor of a consensus node reads the computer instructions from the computer readable storage medium, and the processor executes the computer instructions, so that the consensus node executes the method embodiment as shown in the above. Figure 2 Or Figure 4 The computer readable storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0146] The above only discloses partial embodiments of the present application, and of course cannot limit the scope of the rights of the present application. Those skilled in the art can understand that all or part of the above-mentioned embodiments can be implemented, and equivalent changes made according to the claims of the present application still belong to the scope of the present application.
Claims
1. A data processing method, characterized by, The method comprises the following steps: In the process of consensus processing of a target block, a first hash value and a problem to be solved are obtained; the first hash value is generated based on the target block; In the solution space of the problem, the first hash value is mapped to obtain a candidate answer of the problem; A constraint condition required for obtaining a correct answer of the problem is obtained, and the candidate answer is checked using the constraint condition to check the correctness of the candidate answer; the constraint condition is deployed in a blockchain virtual machine, the blockchain virtual machine comprises one or more stack frames, and one or more reference elements are stored in any stack frame; in the process of checking the candidate answer using the constraint condition, the incentive resources required for checking the candidate answer are obtained, and the target sampling frequency of the blockchain virtual machine is determined according to the incentive resources; the one or more stack frames are sampled according to the target sampling frequency to select a target stack frame from the one or more stack frames; wherein the selected target stack frame is the stack frame associated with the candidate answer; a second hash value is generated according to the reference elements stored in the target stack frame, and a target hash value of the target block is generated according to the second hash value and the first hash value; The target hash value is checked, and the target block is added to the blockchain after the checking is successful.
2. The method of claim 1, wherein, The first hash value is obtained by: obtaining block header data from the block header of the target block, and generating a random number; hashing the block header data and the random number, and taking the result of the hashing operation as the first hash value.
3. The method of claim 1, wherein, The method further comprises: obtaining a smart contract corresponding to the problem from the blockchain network, and obtaining a solution space obtaining function associated with the problem according to the smart contract; calling the solution space obtaining function, obtaining the answer range of the problem, and taking the obtained answer range as the solution space of the problem.
4. The method of claim 1, wherein, In the solution space of the problem, the first hash value is mapped to obtain a candidate answer of the problem, comprising: obtaining the answer range of the problem indicated by the solution space of the problem, and performing modulo operation on the first hash value according to the answer range; taking the result of the modulo operation as the candidate answer of the problem.
5. The method of claim 1, wherein, If the number of reference elements stored in the target stack frame is more than one; the second hash value is generated according to the reference elements stored in the target stack frame, comprising: hash aggregation processing is performed on any two of the plurality of reference elements stored in the target stack frame until an intermediate aggregation element is obtained; according to the target sampling frequency, an aggregation parameter generated in the last round of aggregation process is obtained, and a second hash value is generated according to the aggregation parameter generated in the last round of aggregation process and the intermediate aggregation element; the last round of aggregation process is the process of generating an aggregation parameter based on a candidate answer of a previous problem selected from the problem queue before the problem to be solved.
6. The method of claim 1, wherein, The problem is any problem in a problem queue, and the problem queue comprises a plurality of problems to be solved; the method further comprises: If the candidate answer is determined to pass the verification by using the constraint condition, another question is selected from the question queue for solving, and a candidate answer of the another question is obtained, until a target hash value generated based on the candidate answer of the question and the first hash value is successfully verified.
7. The method of claim 1, wherein, The verification on the target hash value comprises: obtaining a verification hash value, and comparing the target hash value with the verification hash value; when the target hash value is less than the verification hash value, it is determined that the verification on the target hash value is successful; otherwise, it is determined that the verification on the target hash value fails.
8. The method of claim 7, wherein, The target hash value is generated according to a random number; and the method further comprises: when it is determined that the verification on the target hash value fails, the random number is updated to obtain an updated random number, and the first hash value is regenerated by using the updated random number; wherein, the updating of the random number comprises: performing a plus one operation on the random number, and taking the random number after the plus one operation as the updated random number, or regenerating a new random number less than the random number as the updated random number.
9. A data processing apparatus, characterized by, comprises: an obtaining unit, configured to obtain a first hash value and a question to be solved in a process of consensus processing on a target block; the first hash value is generated based on the target block; a processing unit, configured to perform mapping processing on the first hash value in a solution space of the question, to obtain a candidate answer of the question; the processing unit is further configured to obtain a constraint condition required to be met by a correct answer of the question, and verify the candidate answer by using the constraint condition, to verify the correctness of the candidate answer; the constraint condition is deployed in a blockchain virtual machine, the blockchain virtual machine comprises one or more stack frames, and one or more reference elements are stored in any stack frame; in the process of verifying the candidate answer by using the constraint condition, an incentive resource required when verifying the candidate answer is obtained, and a target sampling frequency of the blockchain virtual machine is determined according to the incentive resource; the one or more stack frames are sampled according to the target sampling frequency, to select a target stack frame from the one or more stack frames; the selected target stack frame is a stack frame associated with the candidate answer; a second hash value is generated according to the reference elements stored in the target stack frame, and a target hash value of the target block is generated according to the second hash value and the first hash value; the processing unit is further configured to verify the target hash value, and add the target block to a blockchain after the verification is successful.
10. A consensus node, characterized in that, The consensus node comprises a computer device, the computer device comprises a processor, an input device, an output device and a memory, the processor, the input device, the output device and the memory are connected with each other, wherein the memory is used to store a computer program, the computer program comprises program instructions, the processor is configured to invoke the program instructions, and the method in any one of claims 1-8 is executed.
11. A computer readable storage medium, characterized in that, The computer readable storage medium stores a computer program, the computer program comprising program instructions which, when executed by a processor, cause the processor to perform the method of any one of claims 1-8.
Citation Information
Patent Citations
Block chain consensus mechanism based on optimization problem
CN110232167A
Segmented block chain storage method and segmented block chain storage device
CN111414421A