Block generation method and device and computer equipment
By using preset hash algorithm and modulus operation in the Merkel tree to calculate the hash change amount and update the hash value of the ancestor node, the problem of low update efficiency of Merkel tree is solved, and the block generation efficiency is improved. System performance.
Patent Information
- Application Number
- CN202411056536.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-02
- Publication Date
- 2024-12-06
AI Technical Summary
In the prior art, the update efficiency of Merkel trees is low, which affects the efficiency of block generation and leads to performance bottlenecks in the blockchain network.
By introducing preset hashing algorithms and modulus operations in the Merkel tree, the hash change of the leaf node is calculated, and the hash value of the ancestor node is updated based on this, the node update sequence is decoupled, and multi-threaded parallel calculation is used. The amount of change is desired to improve the update efficiency.
It significantly improves the update efficiency and block generation speed of Merkel trees, increases the flexibility and concurrency of the system, and improves the performance of the blockchain network.
Smart Images

Figure CN119094359A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a block generation method, device and computer equipment. Background Art
[0002] In the field of blockchain, when any block is generated, it is necessary to determine the Merkle root based on the transaction data to be packaged corresponding to the block, so that the generated block contains the packaged data and the Merkle root of the transaction data. The Merkle root refers to the hash value stored in the root node of the Merkle tree, which is usually obtained by updating the Merkle tree on the blockchain based on each transaction data to be packaged. It can be seen that the update efficiency of the Merkle tree has an important impact on the block generation efficiency. Therefore, how to improve the block generation efficiency by improving the update efficiency of the Merkle tree has become a key research topic in the current blockchain field. Summary of the invention
[0003] The embodiments of the present application provide a block generation method, apparatus, and computer device, which can improve the block generation efficiency by improving the concurrency and efficiency in the Merkle tree update process.
[0004] On the one hand, an embodiment of the present application provides a block generation method, in which a Merkle tree used in a block generation process corresponding to the method is used, a hash value of a leaf node is obtained by performing a hash operation on node data of the leaf node using a preset hash algorithm, and performing a modulo operation on the hash operation result, and a hash value of a parent node in the Merkle tree is obtained by performing a sum operation based on the hash values of its child nodes, and performing a modulo operation on the sum operation result; the method includes:
[0005] In response to a block generation request, the leaf nodes in the Merkle tree are updated with the transaction data packaged to generate the target block, and a current hash value of the leaf node after the data update is obtained;
[0006] The difference between the current hash value and the historical hash value of the leaf node is used as the hash change of the leaf node, where the historical hash value refers to the hash value of the leaf node before the current data update;
[0007] Obtaining location information of path nodes on a target path, wherein the target path refers to a path from the leaf node to the root node of the Merkle tree, and the path nodes include the leaf node and its ancestor nodes;
[0008] Based on the hash change of the leaf node and the position information of the path node, determine the hash change generated by the ancestor node corresponding to the leaf node, and update the hash value stored in the ancestor node based on the hash change corresponding to the ancestor node to obtain an updated Merkle tree;
[0009] The transaction data is packaged, and the target block is generated based on the packaged data and the hash value of the root node in the updated Merkle tree.
[0010] On the other hand, an embodiment of the present application provides a block generation device, wherein in a Merkle tree used in a block generation process corresponding to the block generation device, a hash value of a leaf node is obtained by performing a hash operation on node data of the leaf node using a preset hash algorithm, and performing a modulo operation on the hash operation result, and a hash value of a parent node in the Merkle tree is obtained by performing a sum operation based on the hash values of its child nodes, and performing a modulo operation on the sum operation result; the block generation device includes:
[0011] A request response unit, configured to respond to a block generation request, update the leaf nodes in the Merkle tree using the transaction data packaged to generate the target block, and obtain the current hash value of the leaf nodes after the data is updated;
[0012] A first calculation unit, configured to use a difference between the current hash value and a historical hash value of the leaf node as a hash change amount of the leaf node, wherein the historical hash value refers to a hash value of the leaf node before the current data update;
[0013] A position information calculation unit, used to obtain position information of path nodes on a target path, wherein the target path refers to a path from the leaf node to the root node of the Merkle tree, and the path nodes include the leaf node and its ancestor node;
[0014] A second calculation unit is used to determine the hash change amount generated by the ancestor node corresponding to the leaf node based on the hash change amount of the leaf node and the position information of the path node, and update the hash value stored in the ancestor node based on the hash change amount corresponding to the ancestor node to obtain an updated Merkle tree;
[0015] The block packaging unit is used to package the transaction data and generate the target block based on the packaged data and the hash value of the root node in the updated Merkle tree.
[0016] On the other hand, an embodiment of the present application provides a computer device, including:
[0017] a processor adapted to implement one or more computer programs;
[0018] A storage medium storing one or more computer programs, wherein the one or more computer programs are suitable for being loaded by the processor and executing the method according to the first aspect.
[0019] On the other hand, an embodiment of the present application provides a storage medium, wherein the storage medium stores one or more computer programs, and the one or more computer programs are suitable for being loaded by a processor and executing the method of the first aspect.
[0020] On the other hand, an embodiment of the present application provides a program product, which includes a computer program, and the computer program is suitable for being loaded by a processor and executing the method of the first aspect.
[0021] In the embodiment of the present application, the update of the ancestor node is realized based on the total amount of hash changes generated by the ancestor node corresponding to each leaf node, so that the update of the ancestor node can be directly performed based on the update of the leaf node, without relying on the update of its child nodes, which decouples the node update order in the Merkle tree and increases the flexibility of the Merkle tree update process. Since the total amount of hash changes is the sum of the hash changes generated by the ancestor node corresponding to each leaf node, and the sum operation satisfies the commutative law, when calculating the hash changes generated by the ancestor node corresponding to each leaf node, multiple threads can be used to independently and parallelly calculate each hash change, which greatly improves the concurrency of the ancestor node update, thereby effectively improving the update efficiency of the Merkle tree. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0023] Figure 1a is a schematic diagram of a binary Merkle tree provided in an embodiment of the present application;
[0024] Figure 1b is a schematic diagram of a multi-fork Merkle tree provided in an embodiment of the present application;
[0025] Figure 2 is a schematic flow chart of a block generation method provided in an embodiment of the present application;
[0026] Figure 3 is a schematic flow chart of another block generation method provided in an embodiment of the present application;
[0027] Figure 4is a schematic diagram of a quad Merkle tree provided in an embodiment of the present application;
[0028] Figure 5 It is a schematic diagram of a concurrent update process of a Merkle tree provided in an embodiment of the present application;
[0029] Figure 6 It is a structural schematic diagram of a block generation device provided in an embodiment of the present application;
[0030] Figure 7 It is a structural diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0031] It should be noted in advance that, in order to enable those skilled in the art to better understand the technical solutions proposed in the embodiments of the present application, the embodiments of the present application will be combined with one or more drawings to clearly and completely describe the implementation of the technical solutions proposed in the embodiments of the present application. In addition, the various drawings shown in the embodiments of the present application are only exemplary illustrations, and the execution order of the various steps in the drawings, for example, can be adaptively adjusted according to the actual application scenario. In addition, in the embodiments of the present application, the block diagrams, modules and units shown in the drawings are only functional entities, which do not necessarily correspond to physically independent entities, and each module or unit can be a part of an overall module or unit containing the function of the module or unit. That is, the term "module" or "unit" mentioned in the embodiments of the present application refers to a computer program or a part of a computer program with a predetermined function, which can work with other related parts to achieve a predetermined goal, and can also be implemented in whole or in part by using software, hardware (such as a processing circuit or memory) or a combination thereof, or implemented in different networks and / or processor devices and / or microcontroller devices. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units.
[0032] In order to improve the efficiency of block generation in the blockchain network, this application proposes a block generation scheme in combination with the update of the Merkle tree. In the Merkle tree to which this scheme applies, the hash value of the leaf node is obtained by performing a hash operation on the node data of the leaf node using a preset hash algorithm, and then performing a modulo operation on the hash operation result. The hash value of the parent node (a node with child nodes in the tree) is obtained by performing a sum operation based on the hash values of its child nodes, and then performing a modulo operation on the sum operation result. The Merkle tree is a commonly used data structure in computer technology. Taking a Merkle tree with a depth of 2 as an example, its specific structure can be as follows: Figure 1a or Figure 1b As shown. Among them, Figure 1aThe Merkle tree shown is a binary Merkle tree. The nodes at the last level in the tree are called leaf nodes. Each node except the leaf nodes in the binary Merkle tree has two child nodes. Figure 1b The Merkle tree shown is a multi-branch Merkle tree, in which each node except a leaf node has N child nodes, where N is an integer greater than 2.
[0033] The block scheme proposed in the embodiment of the present application can be applied to any of the aforementioned Merkle trees, and the principle used for block generation can be roughly as follows:
[0034] When it is necessary to generate a target block, the transaction data packaged to generate the target block is used to update the leaf nodes in the Merkle tree, wherein one transaction data is usually used to update one leaf node. After the leaf node is updated, the hash value of the leaf node after the data update (hereinafter referred to as the current hash value) is calculated according to the hash value calculation method of the leaf node, and then the difference between the current hash value and the historical hash value corresponding to the leaf node before this data update is used as the hash change of the leaf node. Since the hash value of the leaf node in the Merkle tree changes, the hash values of the ancestor nodes of the leaf node will also fluctuate accordingly. In order to improve the efficiency of updating the hash value of the ancestor node, this scheme will implement the hash value update of the ancestor node by calculating the hash change of the ancestor node corresponding to the hash change of the leaf node.
[0035] Specifically, after calculating the hash change of the leaf node, obtain the location information of the path node on the path from the leaf node to the root node (hereinafter referred to as the target path), the path node includes the leaf node and the ancestor node of the leaf node, so that the location of the ancestor node that needs to be updated based on the update of the leaf node can be determined. Then, based on the hash change of the leaf node and the location information of the path node, calculate the hash change generated by the determined ancestor node corresponding to the leaf node, and then update the hash value of the ancestor node based on the hash change corresponding to the ancestor node, so as to obtain the updated Merkle tree. Finally, based on the packaged data obtained after packaging the transaction data and the hash value of the root node in the updated Merkle tree, the target block can be generated.
[0036] It can be seen that the update of the ancestor node in this scheme is achieved by obtaining the hash change amount. Since the ancestor node must be a node with child nodes in the Merkle tree, the hash value calculation method of the ancestor node is also implemented according to the hash value calculation method of the aforementioned parent node. The hash value update of the ancestor node needs to be based on the total amount of hash changes generated by it corresponding to each leaf node. The update of the ancestor node can be directly based on the update of the leaf node without relying on the update of its child nodes, which decouples the node update order in the Merkle tree and increases the flexibility of the Merkle tree update process. In addition, it is not difficult to understand that the total amount of hash changes is the sum of the hash changes generated by the ancestor node corresponding to each leaf node. Since the sum operation satisfies the commutative law, when calculating the hash changes generated by the ancestor node corresponding to each leaf node, multiple threads can be used to independently and parallelly calculate each hash change, which greatly improves the concurrency of the ancestor node update, thereby effectively improving the update efficiency of the Merkle tree.
[0037] In actual application scenarios, this solution can select a single computer device or a composite computer device to execute according to business deployment requirements. Among them, a single computer device refers to a single electronic device with data processing capabilities, such as a server or a terminal device. A composite computer device refers to a computer device composed of at least two electronic devices with data processing capabilities, such as multiple servers or multiple terminal devices at the same time, or at least one server and at least one terminal device at the same time. Among them, the aforementioned terminal devices may specifically refer to smart phones, portable computers, desktop computers, smart wearable devices, etc.; servers may refer to independent physical servers, server clusters or distributed systems composed of multiple physical servers, cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network) and big data and artificial intelligence platforms and other basic cloud services cloud servers, etc., the embodiments of this application do not impose specific restrictions on this.
[0038] See also Figure 2 , Figure 2 : is a schematic flow chart of a block generation method proposed in an embodiment of the present application based on the above technical solution. Specifically, Figure 2 The method shown may be executed by the aforementioned computer device, and may include steps S201-S205:
[0039] S201. In response to a block generation request, the leaf nodes in the Merkle tree are updated with the transaction data packaged to generate the target block, and the current hash value of the leaf nodes after the data update is obtained.
[0040] In a specific embodiment, the block generation request may be generated by an accounting node in a blockchain network, and the transaction data required to be packaged to generate the target block is usually selected by the accounting node from the transaction cache pool in the blockchain network. In general, there are multiple transaction data required to be packaged to generate a block, and one transaction data is used to update the data of a leaf node in the Merkle tree, and the specific update method may be to replace the node data currently stored in the leaf node with the transaction data. Optionally, leaf nodes are usually used to store transaction data in the form of key-value pairs, and non-leaf nodes are used to store unique reference values calculated based on the transaction data of each leaf node to prevent data tampering on the blockchain. In actual application scenarios, the unique reference value can be called a hash value.
[0041] It can be understood that when the node data stored in the leaf node changes, the hash value corresponding to the leaf node will also change accordingly. In the embodiment of the present application, the hash value corresponding to the leaf node after the data is updated is called the current hash value. Specifically, the current hash value can be calculated by: using a preset hash algorithm to perform a hash operation on the transaction data stored in the leaf node, and then performing a modulus operation on the hash operation result, and using the modulus operation result as the calculated current hash value. Among them, the preset hash algorithm can be SHA-256, SHA-1, SHA-3, MD5, etc.
[0042] Exemplarily, the hash value of a leaf node can be calculated using Formula 1. In Formula 1, H Leaf represents the hash value of the leaf node, Hash() represents the preset hash algorithm, and Value represents the value of the node data in the form of a key-value pair stored in the leaf node, that is, the Value in Key-Value. mod refers to the modulus operation, N is the degree of the Merkle tree, and d max It refers to the maximum node depth of the Merkle tree, that is, the node depth where the leaf node is located.
[0043]
[0044] Using a preset hash algorithm for hash operations can make the calculation of the hash value corresponding to the leaf node irreversible, thereby increasing the difficulty of cracking or tampering with the transaction data stored in the leaf node. On this basis, using modulus operations on the hash operation results can reduce the data size of the hash value of the leaf node, reduce the data processing burden during the Merkle tree update process, and thus improve the update efficiency of the Merkle tree to a certain extent.
[0045] S202: The difference between the current hash value and the historical hash value of the leaf node is used as the node hash change of the leaf node. The historical hash value refers to the hash value of the leaf node before the current data update.
[0046] In a specific embodiment, the number of historical hash values is one, specifically referring to the hash value corresponding to the leaf node before the current data update.
[0047] S203, obtaining location information of the path nodes on the target path, where the target path refers to the path from the leaf node to the root node of the Merkle tree, and the path nodes include the leaf node and its ancestor node.
[0048] In a specific embodiment, each node on the target path from the leaf node to the root node is referred to as a path node. The location information of the path node may include the coordinate indication information and the node depth of the node on the Merkle tree. In addition, in an actual application scenario, there are usually multiple path nodes on the target path from the leaf node to the root node, and specifically include the leaf node and its ancestor nodes.
[0049] With the aforementioned Figure 1a Taking the Merkle tree shown as an example, for the leaf node "node a_1", the path leading to the root node includes node a_1, node A, and the root node. In this case, node a_1, node A, and the root node are all path nodes, and node A and the root node are the ancestor nodes of node a_1. For another example, for the leaf node "node a_2", the path leading to the root node includes node a_2, node A, and the root node. In this case, node a_2, node A, and the root node are all path nodes, and node A and the root node are the ancestor nodes of node a_2.
[0050] S204. Based on the hash change of the leaf node and the location information of the path node, determine the hash change generated by the ancestor node corresponding to the leaf node, and update the hash value stored in the ancestor node based on the hash change corresponding to the ancestor node to obtain an updated Merkle tree.
[0051] In a specific embodiment, steps S201-S204 can be regarded as a method of updating the Merkle tree based on a leaf node after data update. In practical applications, there may be multiple leaf nodes with updated data. At this time, the hash change corresponding to each ancestor node of each leaf node can be calculated in accordance with steps S201-S204 to determine the hash change of each node that needs to be updated in the Merkle tree, thereby achieving a complete update of the Merkle tree.
[0052] S205: Pack the transaction data, and generate a target block based on the packed data and the hash value of the root node in the updated Merkle tree.
[0053] In a specific embodiment, the generated target block includes the packaged data and the hash value of the root node. In the block generation scenario, the account in the blockchain network can also verify whether a certain transaction data exists in a certain block. This verification is usually called existence verification. One way of existence verification is based on the construction principle of the Merkle tree, calculating whether there is a cryptographic relationship involved in the construction principle between the Merkle root in the block header and the leaf node where the transaction data to be verified is located, so as to determine whether the transaction data exists on the blockchain.
[0054] In one implementation, when existence verification is required, since the hash value of the parent node in the embodiment of the present application is obtained by summing the hash values of its child nodes and performing a modulo operation on the summation result, the transaction data of all leaf nodes can be provided to re-derive the Merkle root when verifying the existence of the transaction data.
[0055] In another implementation, when existence verification is required, the embodiment of the present application can be combined with the multi-signature or supervisor mode to determine the existence of an intermediate node on the Merkle tree, so that the existence verification of certain transaction data can be achieved by obtaining the transaction data of all leaf nodes under the intermediate node and performing corresponding hash value calculations, thereby reducing the computational overhead and complexity of existence verification.
[0056] Specifically, when applying the multi-signature or supervisor mode to verify the existence of the target transaction data under the target block, the target leaf node storing the target transaction data can be first determined in the Merkle tree, and then the trusted tree node corresponding to the target leaf node in the Merkle tree can be determined. The trusted tree node is the ancestor node (i.e., the intermediate node) of the target leaf node, and the trusted tree node has a trusted credential for its hash value, which is used to indicate that the hash value of the trusted tree node has passed the hash value authenticity verification of multiple blockchain nodes or preset supervisors. Among them, each blockchain node can sign the hash value after passing the authenticity verification of its hash value, and the use of multiple blockchain nodes to verify the authenticity of its hash value is the multi-signature mechanism mentioned above. In addition, the preset supervisor can be a trusted authority or organization, which is not limited here.
[0057] After obtaining the trusted tree node, the hash value of each leaf node under the trusted tree node is obtained to calculate the reference hash of the trusted tree node based on the hash value of each leaf node. When the reference hash is the same as the hash value indicated by the trusted credential, it is considered that the existence verification of the target transaction data has passed, and then a verification result indicating that the target transaction data exists in the target block can be generated.
[0058] In other implementations, the embodiments of the present application can also be mainly used in block generation scenarios that do not require existence verification, such as business scenarios for applying alliance chains, so as to give full play to the business effects brought by the Merkle tree update efficiency in blockchain business.
[0059] In the embodiment of the present application, the update of the ancestor node is realized based on the total amount of hash changes generated by the ancestor node corresponding to each leaf node, so that the update of the ancestor node can be directly performed based on the update of the leaf node, without relying on the update of its child nodes, which decouples the node update order in the Merkle tree and increases the flexibility of the Merkle tree update process. Since the total amount of hash changes is the sum of the hash changes generated by the ancestor node corresponding to each leaf node, and the sum operation satisfies the commutative law, when calculating the hash changes generated by the ancestor node corresponding to each leaf node, multiple threads can be used to independently and parallelly calculate each hash change, which greatly improves the concurrency of the ancestor node update, thereby effectively improving the update efficiency of the Merkle tree.
[0060] See also Figure 3 , Figure 3 is a schematic flow chart of another block generation method proposed in the embodiment of the present application based on the above technical solution. This method can be regarded as Figure 2 A supplementary description of the method shown, which can be continued by the aforementioned Figure 2 Specifically, Figure 3 The method shown may include steps S301-S306:
[0061] S301. In response to a block generation request, the leaf nodes in the Merkle tree are updated with the transaction data packaged to generate the target block, and the current hash value of the leaf nodes after the data update is obtained.
[0062] In a specific embodiment, the implementation of step S301 may refer to the related embodiments of the aforementioned step S201, which will not be described in detail here.
[0063] S302: The difference between the current hash value and the historical hash value of the leaf node is used as the hash change of the leaf node. The historical hash value refers to the hash value of the leaf node before the current data update.
[0064] In a specific embodiment, the implementation of step S302 may refer to the related embodiments of the aforementioned step S202, which will not be described in detail here.
[0065] S303, obtaining the location information of the path nodes on the target path, where the target path refers to the path from the leaf node to the root node of the Merkle tree, and the path nodes include the leaf node and its ancestor node.
[0066] In a specific embodiment, the node data in the leaf node can be stored in the form of a key-value pair (i.e., key-value), and illustratively, the key (i.e., key) in the key-value pair is generated based on the storage address of the transaction data and the keyword of the transaction data. For example, assume that there is currently a transaction data indicating that: the first account transfers money to the second account, and the balance of the first account after the transfer is the first balance, and the balance of the second account is the second balance. Then, the key in the transaction data can be the concatenation result of the account address of the first account and the index keyword of the transaction data (such as the field identifier used to indicate the value), and the value can be the first balance.
[0067] In addition, the location information may specifically include at least coordinate indication information, which is used to indicate the node coordinates of the node in the Merkle tree. When the node data in the leaf node is stored in the form of a key-value pair, if the coordinate indication information of the leaf node needs to be determined, the key in the key-value pair corresponding to the node data of the leaf node can be obtained, and a preset hash algorithm is used to perform a hash operation on the obtained key to obtain a hash operation result, and then a modulus operation is performed on the obtained hash operation result, and finally the modulus operation result is used as the coordinate indication information of the leaf node.
[0068] As an example, in practical applications, the calculation method of the coordinate indication information of the leaf node can be as shown in Formula 2. In Formula 2, P Leaf Indicates the coordinate information of the leaf node, Hash() indicates the preset hash algorithm, key indicates the key in the node data in the form of key-value pairs stored in the leaf node. mod refers to the modulus operation, N is the degree of the Merkle tree, d max It refers to the maximum node depth of the Merkle tree, that is, the node depth where the leaf node is located.
[0069] P Leaf =Hash(key)mod N dmax Formula 2
[0070] On this basis, if the coordinate indication information of the ancestor node of the leaf node needs to be determined, the node depth of the ancestor node in the Merkle tree can be obtained to calculate based on the coordinate indication information of the ancestor node, i.e., the leaf node. As an example, the calculation method of the coordinate indication information of the ancestor node can be as shown in Formula 3.
[0071]
[0072] In formula 3, P Leaf Indicates the coordinate information of the leaf node, P j Represents the coordinate indication information of the ancestor node with a node depth of j, mod refers to the modulo operation, and N is the degree of the Merkle tree.
[0073] S304: Based on the hash change of each leaf node and the position information of the path nodes, determine the hash change generated by the ancestor node corresponding to each leaf node.
[0074] In a specific embodiment, there may be multiple leaf nodes with updated data in the Merkle tree. In this case, one leaf node corresponds to one target path. The path nodes on the target path corresponding to each leaf node may include one or more ancestor nodes of the leaf node, and the location information of the path nodes may include coordinate indication information and node depth. In addition, for each leaf node, the same principle is used to determine the hash change amount generated by each ancestor node of the leaf node corresponding to the leaf node.
[0075] In a feasible implementation, taking any ancestor node of any leaf node as an example, when a computer device determines the hash change amount generated by the ancestor node corresponding to the leaf node, the main process may be as follows:
[0076] (1) Determine the node depth of the ancestor node in the Merkle tree, and determine each target path node from the path nodes whose node depth is greater than the node depth of the ancestor node. It can be understood that the path node here refers to: a tree node on the target path from the leaf node corresponding to the ancestor node to the root node.
[0077] by Figure 4 Taking the Merkle tree shown in the figure as an example, assuming that the hash changes of each ancestor node of the leaf node 3.2 need to be calculated, then: Figure 4 The target path from the leaf node to the root node can be expressed as (node 3.2, node 2.1, node 1.1, root node). Among them, node 3.2, node 2.1, node 1.1 and the root node are all path nodes, and node 2.1, node 1.1 and the root node are all ancestor nodes of the leaf node (i.e. node 3.2). If the ancestor node for which the hash change amount needs to be calculated is node 2.1, the target path node only includes node 3.2; if the ancestor node for which the hash change amount needs to be calculated is node 1.1, the target path node includes node 2.1 and node 3.2.
[0078] (2) Obtaining unique parameters preset for the node depth of each target path node, wherein there is a one-to-one correspondence between the unique parameters and the node depth, and illustratively, the unique parameters may be prime numbers (or prime numbers), such as the unique parameter corresponding to the node depth 1 is 2, the unique parameter corresponding to the node depth 2 is 3, the unique parameter corresponding to the node depth 3 is 5, ..., which are not listed here.
[0079] (3) Based on the unique parameters corresponding to each target path node, the location information of each target node and the hash change of the leaf node, the hash change generated by the ancestor node corresponding to the leaf node is calculated.
[0080] Exemplarily, the hash change amount may be calculated using the calculation method shown in Formula 4.
[0081]
[0082] In Equation 4, ΔH j Indicates the hash change of the ancestor node with node depth j corresponding to the leaf node, ΔH Leaf Indicates the hash change of the leaf node, ∏ is the multiplication operator, d max is the maximum depth of the Merkle tree, that is, the depth of the node where the leaf node is located. k is the unique parameter corresponding to the node depth k, mod is the modulus operator, and N is the degree of the Merkle tree. k It is the coordinate indication information of the ancestor node with a node depth of k. The specific calculation method can refer to the above formula 3 and will not be described in detail here.
[0083] By calculating the hash change of the ancestor node through the above implementation method, the hash change of each ancestor node can be independently calculated based on the hash change of its leaf node, without relying on the various child nodes of the ancestor node, thereby decoupling the node update order in the Merkle tree. On the one hand, the flexibility of the Merkle tree update process can be increased, and on the other hand, the concurrency in the Merkle tree update process can be increased, thereby improving the update efficiency.
[0084] In another feasible implementation, still taking any ancestor node of any leaf node as an example, when the computer device determines the hash change amount generated by the ancestor node corresponding to the leaf node, the main process may be as follows:
[0085] (1) Determine the target child node of the ancestor node, where the target child node refers to the child node that is a path node among the child nodes of the ancestor node.
[0086] Continue with Figure 4 Taking the Merkle tree shown in the figure as an example, assuming that the hash changes of each ancestor node of the leaf node 3.2 need to be calculated, then: Figure 4Node 3.2, node 2.1, node 1.1 and the root node in are all current path nodes, and node 2.1, node 1.1 and the root node are all ancestor nodes of the leaf node. In this case, if the ancestor node for which the hash change needs to be calculated is node 2.1, the child nodes of the ancestor node include nodes 3.1 and 3.2, and only node 3.2 is a path node, so the target path node is node 3.2. Similarly, if the ancestor node for which the hash change needs to be calculated is node 1.1, the target path node is node 2.1.
[0087] (2) Obtain the hash change of the target child node, and determine the unique parameter preset for the node depth of the target child node. The unique parameter preset for the node depth can be understood by referring to the relevant description in the previous implementation method, which will not be repeated here.
[0088] (3) Based on the unique parameter corresponding to the target child node, the hash change of the target child node and the location information of the target child node, the hash change generated by the ancestor node corresponding to the leaf node is calculated. For example, the hash change can be calculated using the calculation method shown in Formula 5.
[0089]
[0090] In Equation 5, ΔH j Indicates the hash change of the ancestor node with node depth j corresponding to the leaf node, ΔH j+1 Indicates the hash change of the target child node, G j+1 represents the unique parameter corresponding to the node depth j+1 (i.e., the unique parameter corresponding to the node depth of the target child node), P j+1 is the coordinate indication information of the target child node, mod is the modulus operator, d max is the maximum depth of the Merkle tree.
[0091] Based on Formula 5, it is not difficult to see that when determining the hash change of the ancestor node of any node depth corresponding to the leaf node, it is necessary to obtain the hash change generated by the target child node of the ancestor node corresponding to the leaf node, so that the hash changes of each ancestor node of the leaf node need to be performed recursively, ensuring the orderliness of the Merkle tree during update, minimizing the storage of intermediate results and reducing update failures caused by data storage errors.
[0092] In addition, based on Figure 5 It is not difficult to see that the hash changes generated by the same ancestor node corresponding to different leaf nodes can be calculated using different threads. Figure 5The principle is to perform independent recursive calculations based on the hash changes of different leaf nodes, so that the update process of the Merkle tree has a high concurrency. For example, when Figure 4 When both leaf nodes 3.1 and 3.2 have data updates, their common ancestor node includes node 2.1, and the hash change amount generated by node 2.1 corresponding to the leaf node 3.1 and the hash change amount generated by node 2.1 corresponding to the leaf node 3.2 can be calculated independently, and therefore can also be performed simultaneously.
[0093] In summary, by using this implementation method to calculate the hash change of the ancestor node, the Merkle tree can be updated efficiently and orderly.
[0094] S305. The sum of the hash changes generated by the ancestor node corresponding to each leaf node is used as the total hash change of the ancestor node, and the total hash change is used to update the hash value stored in the ancestor node to obtain an updated Merkle tree.
[0095] In a specific embodiment, in order to reduce the number of updates to the same ancestor node, the computer device may perform a one-time update on the ancestor node based on the sum of the hash changes after counting the hash changes generated by the ancestor node corresponding to each leaf node.
[0096] S306: Pack the transaction data, and generate a target block based on the packed data and the hash value of the root node in the updated Merkle tree.
[0097] In a specific embodiment, the implementation of step S306 can refer to the relevant embodiment in the aforementioned step S205, which will not be repeated here.
[0098] In an embodiment of the present application, when calculating the hash changes generated by the same ancestor node corresponding to multiple different leaf nodes, the hash changes generated by the ancestor node corresponding to each leaf node can be calculated in parallel in a multi-threaded manner. For example, one thread is used to calculate the hash change generated by the ancestor node corresponding to a leaf node, and then after counting the sum of the hash changes of the ancestor node corresponding to each leaf node, the hash value stored in the ancestor node is updated. This can avoid competition among multiple threads for the update lock of the same ancestor node, thereby reducing thread blocking and improving the concurrency of the Merkle tree during the update process, ultimately effectively improving the update efficiency of the Merkle tree.
[0099] In order to facilitate those skilled in the art to quickly apply the embodiments of the present application, the concurrent update process of the Merkle tree will be described in detail below in combination with actual application scenarios and specific examples.
[0100] Exemplarily, in this example, the computer device can configure a unique parameter for each node depth in the Merkle tree, the unique parameter is a prime number, and the unique parameters corresponding to different node depths are different. In addition, in the Merkle tree to which this example is applicable, the hash value calculation of the leaf node can adopt the principle shown in the aforementioned formula 1, and the hash value of the parent node is summed based on the hash values of its child nodes, and the summation result is obtained by performing a modulo operation.
[0101] Specifically, the hash value of the parent node can be calculated using Formula 6. In Formula 6, H x For a node with a depth of x (where x is less than d max )’s tree node (which can be called the parent node), d max is the maximum depth of the Merkle tree, N is the degree of the Merkle tree (that is, the number of child nodes of the parent node), i is the number of the i-th child node of the parent node, H x_N+i is the hash value of the i-th child node of the parent node, and mod is the modulus operator.
[0102]
[0103] For example, suppose there is a four-branch Merkle tree (i.e. N=4), and the maximum node depth of the Merkle tree is 4, and the hash value of the root node is H0. Further, suppose the unique parameter G2 is configured for node depth 2, and G2=3, and the hash values of each child node of a parent node with a node depth of 2 are H1, H2, H3, and H4 respectively. Then, if you want to calculate the hash value H of the parent node x , then the specific calculation formula used can be Formula 7.
[0104]
[0105] Next, see Figure 5 , Figure 5 A schematic diagram of a concurrent update process of a Merkle tree is shown. Figure 5 As shown, the concurrent update process of the Merkle tree may mainly include steps S501-S504:
[0106] S501, using multiple threads to parallelly calculate the position information of the path nodes on the target path corresponding to each leaf node, and one thread processes one leaf node.
[0107] When there are multiple leaf nodes in the Merkle tree with updated data, multiple threads can be created to calculate the location information of the path nodes corresponding to each leaf node. For example, one thread can be used to process one leaf node, and each thread can process according to the principles shown in Formula 2 and Formula 3 in the aforementioned step S303 when determining the target path corresponding to the corresponding leaf node, which will not be repeated here.
[0108] S502: After any thread completes the calculation of the corresponding position information, it triggers the calculation of the hash change of the leaf node, and the hash changes of each leaf node are calculated in parallel.
[0109] The execution order of step S501 and step S502 is not fixed. That is, in practical applications, step S502 can be executed first to calculate the hash change of each leaf node, and then step S501 can be executed to calculate the position information of each path node on the target path corresponding to each leaf node.
[0110] S503: After any thread calculates the hash change of the corresponding leaf node, it triggers the calculation of the hash change of the ancestor node corresponding to the leaf node, and the hash changes of the ancestor nodes corresponding to each leaf node are calculated in parallel.
[0111] Among them, the hash change amount generated by the ancestor node corresponding to a leaf node can be calculated specifically according to the principle shown in Formula 4 or Formula 5 in the aforementioned step S304, and the specific application of the principle can refer to the relevant implementation method in the step S304, which will not be repeated here.
[0112] Here, the principle shown in Formula 4 is taken as an example. The hash changes of each path node on the target path corresponding to the leaf node k can be calculated according to Table 1. The definitions of the various parameters in Table 1 can refer to the above description of Formula 4. However, it should be noted that in order to simplify the formula expression in Table 1, d in Formula 4 is max In Table 1, it is indicated by d.
[0113] Table 1
[0114]
[0115] S504: Taking the node whose hash value needs to be updated on the Merkle tree as a unit, the total hash change amount of each node is calculated in parallel, and the node is updated using the total hash change amount to obtain an updated Merkle tree.
[0116] After obtaining the hash change amount generated by the data update of each leaf node corresponding to each node on the tree, the total hash change amount of the node can be counted to use the total hash change amount to perform a one-time update on the node, effectively reducing the number of updates to the node, and thus saving computing overhead. It can be understood that in this case, the execution of step S504 can be performed after all threads have completed the calculation in step S503.
[0117] It should be noted that in practical applications, Figure 2 , Figure 4 and Figure 5 The addition and exponential operations involved in the algorithm can be replaced by the addition and exponential operations related to elliptic curves, respectively. Since the operations of elliptic curves are unidirectional (the results can be derived from the data changes, but the data changes cannot be inferred from the results), the confidentiality of the on-chain data can be enhanced.
[0118] In the embodiment of the present application, the hash value calculation method of the parent node is constructed based on the exponential operation of prime numbers and the addition operation, which can reduce the traditional hash operation in the update process of the Merkle tree, thereby saving the calculation overhead. At the same time, because the addition operation satisfies the commutative law, the update dependency of the nodes on each path in the Merkle tree can be decoupled, so that the hash value of each node can be updated in parallel, which improves the concurrency of the Merkle tree update, thereby effectively improving the update efficiency.
[0119] Based on the above Figure 2 and Figure 3 Related to various method embodiments, the present application also discloses a block generation device for performing the following steps: Figure 2 and Figure 3 The steps shown in . Specifically, in the Merkle tree used in the block generation process corresponding to the device, the hash value of the leaf node is obtained by performing a hash operation on the node data of the leaf node using a preset hash algorithm, and performing a modulo operation on the hash operation result. The hash value of the parent node in the Merkle tree is obtained by performing a sum operation based on the hash values of its child nodes, and performing a modulo operation on the sum operation result. In addition, the device can be a computer program (including program code) running in a computer device.
[0120] See also Figure 6 , the device may include Figure 6 The request response unit 601, the first calculation unit 602, the position information calculation unit 603, the second calculation unit 604 and the block packaging unit 605 in the embodiment include:
[0121] The request response unit 601 is used to respond to the block generation request, update the leaf nodes in the Merkle tree with the transaction data packaged for generating the target block, and obtain the current hash value of the leaf node after the data is updated;
[0122] A first calculation unit 602 is configured to use a difference between the current hash value and a historical hash value of the leaf node as a hash change amount of the leaf node, where the historical hash value refers to a hash value of the leaf node before the current data update;
[0123] A position information calculation unit 603 is used to obtain position information of path nodes on a target path, wherein the target path refers to a path from the leaf node to the root node of the Merkle tree, and the path nodes include the leaf node and its ancestor node;
[0124] A second calculation unit 604 is used to determine the hash change amount generated by the ancestor node corresponding to the leaf node based on the hash change amount of the leaf node and the position information of the path node, and update the hash value stored in the ancestor node based on the hash change amount corresponding to the ancestor node to obtain an updated Merkle tree;
[0125] The block packaging unit 605 is used to package the transaction data and generate the target block based on the packaged data and the hash value of the root node in the updated Merkle tree.
[0126] In one implementation, the second calculation unit 604 may also be used to calculate the hash value of the parent node in the Merkle tree, and the calculation may be specifically used to execute:
[0127] Obtain the node depth of the parent node in the Merkle tree, and the hash value and node number of each child node of the parent node;
[0128] Obtaining a unique parameter preset for the node depth of the parent node, where the unique parameter and the node depth are in a one-to-one correspondence;
[0129] Using the unique parameter of the parent node and the node number of each child node, the hash value of each child node is uniquely processed to obtain a unique hash value of each child node;
[0130] The unique hash values of the child nodes are summed up, and a modulus operation is performed on the summation result to obtain the hash value of the parent node.
[0131] In another embodiment, the node data in the leaf node is stored in the form of a key-value pair, and the key in the key-value pair is generated based on the storage address of the transaction data and the keyword of the transaction data; the location information includes coordinate indication information, and the coordinate indication information is used to indicate the node coordinates of the node in the Merkle tree; when the location information calculation unit 603 is used to obtain the location information of the leaf node, it can specifically perform:
[0132] Obtaining the key in the key-value pair corresponding to the node data of the leaf node, and performing a hash operation on the obtained key using the preset hash algorithm to obtain a hash operation result;
[0133] A modulo operation is performed on the obtained hash operation result, and the modulo operation result is used as the coordinate indication information of the leaf node.
[0134] In yet another implementation, when the location information calculating unit 603 is used to obtain the location information of the ancestor node, it may specifically perform:
[0135] Obtaining the node depth of the ancestor node in the Merkle tree;
[0136] The coordinate indication information of the ancestor node is calculated based on the node depth of the ancestor node and the coordinate indication information of the leaf node.
[0137] In another embodiment, the location information includes coordinate indication information and node depth, the path node includes multiple ancestor nodes of the leaf node, and for any ancestor node, the second calculation unit 604, when used to determine the hash change amount generated by any ancestor node corresponding to the leaf node based on the hash change amount of the leaf node and the location information of the path node, can specifically perform:
[0138] Determine a target child node of any ancestor node, wherein the target child node refers to: a child node belonging to the path node among the child nodes of any ancestor node;
[0139] Obtaining a hash change of the target child node, and determining a unique parameter preset for the node depth of the target child node;
[0140] Based on the unique parameter corresponding to the target child node, the hash change of the target child node and the position information of the target child node, the hash change generated by any ancestor node corresponding to the leaf node is calculated.
[0141] In another embodiment, the location information includes coordinate indication information and node depth, and the path node includes multiple ancestor nodes of the leaf node; for any ancestor node, the second calculation unit 604, when used to determine the hash change amount generated by any ancestor node corresponding to the leaf node based on the hash change amount of the leaf node and the location information of the path node, can specifically perform:
[0142] Determining a node depth of any of the ancestor nodes in the Merkle tree, and determining each target pathway node from the pathway nodes having a node depth greater than a node depth of any of the ancestor nodes;
[0143] Determining unique parameters preset for the node depth of each target pathway node, wherein there is a one-to-one correspondence between the unique parameters and the node depth;
[0144] Based on the unique parameters corresponding to each target path node, the location information of each target node and the hash change of the leaf node, the hash change generated by any ancestor node corresponding to the leaf node is calculated.
[0145] In yet another embodiment, the block packaging unit 605 may also be configured to execute:
[0146] In response to a request for existence verification of target transaction data under the target block, determining a target leaf node storing the target transaction data in the Merkle tree;
[0147] Determine the trusted tree node corresponding to the target leaf node in the Merkle tree, and obtain the hash value of each leaf node under the trusted tree node; wherein the trusted tree node is the ancestor node of the target leaf node, and the trusted tree node has a trusted credential for its hash value, and the trusted credential is used to indicate that the hash value of the trusted tree node has passed the hash value authenticity verification of multiple blockchain nodes or preset supervisors;
[0148] A reference hash of the trusted tree node is calculated based on the hash value of each leaf node, and when the reference hash is the same as the hash value indicated by the trusted credential, a verification result is generated indicating that the target transaction data exists in the target block.
[0149] In another embodiment, the number of the leaf nodes is one or more, and when the second calculation unit 604 updates the hash value stored in the ancestor node based on the hash change amount corresponding to the leaf node, it can specifically perform:
[0150] Determine the hash change amount generated by the ancestor node corresponding to each leaf node;
[0151] The sum of the hash changes generated by the ancestor node corresponding to each leaf node is used as the total hash change amount of the ancestor node;
[0152] The total amount of hash changes is used to update the hash value stored in the ancestor node.
[0153] In a specific embodiment of the present application, Figure 6 The various units in the device shown are divided based on logical functions, and the above-mentioned various units can be separately or all combined into one or several other units to constitute, or one (some) of the units can be further divided into multiple smaller functional units to constitute, which can achieve the same operation without affecting the realization of the technical effects of the embodiments of the present application. In other embodiments of the present application, the above-mentioned device may also include other units, and in practical applications, these functions can be implemented with the assistance of one or more other units.
[0154] In another specific embodiment of the present application, the program can be executed on a general computing device such as a computer device including a central processing unit (CPU), a random access memory (RAM), a read-only memory (ROM), and other processing elements and storage elements. Figure 2 or Figure 3 The computer program (including program code) of each step involved in the method shown in FIG. Figure 6 The apparatus shown in the figure is used to implement the corresponding method in the embodiment of the present application. The computer program can be recorded on a storage medium, for example, and loaded into the above-mentioned computer device through the storage medium, and can be run therein.
[0155] In the embodiment of the present application, the update of the ancestor node is realized based on the total amount of hash changes generated by the ancestor node corresponding to each leaf node, so that the update of the ancestor node can be directly performed based on the update of the leaf node, without relying on the update of its child nodes, which decouples the node update order in the Merkle tree and increases the flexibility of the Merkle tree update process. Since the total amount of hash changes is the sum of the hash changes generated by the ancestor node corresponding to each leaf node, and the sum operation satisfies the commutative law, when calculating the hash changes generated by the ancestor node corresponding to each leaf node, multiple threads can be used to independently and parallelly calculate each hash change, which greatly improves the concurrency of the ancestor node update, thereby effectively improving the update efficiency of the Merkle tree.
[0156] Based on the relevant description of the above method embodiment and the device embodiment, the present application embodiment also provides a computer device, see Figure 7The computer device at least includes a processor 701 and a storage medium 702, and the processor 701 and the storage medium 702 are connected via a bus or other means. In addition, the processor 701 can load and execute one or more computer programs stored in the storage medium 702 to implement the above-mentioned Figure 2 or Figure 3 Corresponding method steps in the method embodiment shown.
[0157] The storage medium 702 mentioned above is a memory device in a computer device, which is used to store programs and data. It is understandable that the storage medium 702 here can include both built-in storage media in the computer device and extended storage media supported by the computer device. The storage medium 702 provides a storage space, which stores the operating system of the computer device. In addition, one or more computer programs suitable for being loaded and executed by the processor 701 are also stored in the storage space. These computer programs can be one or more program codes.
[0158] It should be noted that the above storage medium can be a high-speed RAM memory or a non-volatile memory, such as at least one disk memory; optionally, it can also be at least one storage medium located away from the above processor. Processor 701 (or CPU (Central Processing Unit)) is the computing core and control core of the computer device, which is suitable for implementing one or more computer programs, and is specifically suitable for loading and executing one or more computer programs to implement corresponding method flows or corresponding functions.
[0159] Optionally, the computer device may also be in communication connection with one or more target output devices 703 (such as mobile terminal devices, etc.), and may trigger the existence verification by interacting with the target output device 703 .
[0160] In addition, the present application also provides a storage medium, which stores the above Figure 2 or Figure 3 The one or more computer programs corresponding to the block generation method shown can implement the description of the corresponding method in the embodiment when one or more processors load and execute the one or more computer programs, which will not be repeated here.
[0161] The present application also provides a program product or a computer program, the program product includes a computer program, the computer program is stored in a storage medium. A processor in a computer device can read the computer program from the storage medium, and then execute the computer program, thereby enabling the computer device to perform the above Figure 2 or Figure 3 Various alternatives for the steps involved in the method shown.
[0162] It can be understood by those skilled in the art that all or part of the processes in the above embodiments can be completed by instructing the relevant hardware through a computer program, and the corresponding technical effects can be seen in the above description of the embodiments. Figure 2 or Figure 3 With reference to the related description in the specification, the technical effects corresponding to the various embodiments adopting the same principle will not be repeated here.
[0163] It can also be understood that what is disclosed above is only a partial embodiment of the present application, and it certainly cannot be used to limit the scope of rights of the present application. Ordinary technicians in this field can understand that all or part of the processes of implementing the above embodiments and equivalent changes made according to the claims of this application are still within the scope of the invention.
Claims
1. A block generation method, characterized in that: In the Merkle tree used in the block generation process, the hash value of the leaf node is obtained by performing a hash operation on the node data of the leaf node using a preset hash algorithm, and performing a modulo operation on the hash operation result. The hash value of the parent node in the Merkle tree is obtained by performing a sum operation based on the hash values of its child nodes, and performing a modulo operation on the sum operation result. The method includes: In response to a block generation request, the leaf nodes in the Merkle tree are updated with the transaction data packaged to generate the target block, and a current hash value of the leaf node after the data update is obtained; The difference between the current hash value and the historical hash value of the leaf node is used as the hash change of the leaf node, where the historical hash value refers to the hash value of the leaf node before the current data update; Obtaining location information of path nodes on a target path, wherein the target path refers to a path from the leaf node to the root node of the Merkle tree, and the path nodes include the leaf node and its ancestor nodes; Based on the hash change of the leaf node and the position information of the path node, determine the hash change generated by the ancestor node corresponding to the leaf node, and update the hash value stored in the ancestor node based on the hash change corresponding to the ancestor node to obtain an updated Merkle tree; The transaction data is packaged, and the target block is generated based on the packaged data and the hash value of the root node in the updated Merkle tree.
2. The method according to claim 1, characterized in that The calculation method of the hash value of the parent node in the Merkle tree includes: Obtain the node depth of the parent node in the Merkle tree, and the hash value and node number of each child node of the parent node; Obtaining a unique parameter preset for the node depth of the parent node, where the unique parameter and the node depth are in a one-to-one correspondence; Using the unique parameter of the parent node and the node number of each child node, the hash value of each child node is uniquely processed to obtain a unique hash value of each child node; The unique hash values of the child nodes are summed up, and a modulus operation is performed on the summation result to obtain the hash value of the parent node.
3. The method according to claim 1, characterized in that The node data in the leaf node is stored in the form of a key-value pair, and the key in the key-value pair is generated based on the storage address of the transaction data and the keyword of the transaction data; the location information includes coordinate indication information, and the coordinate indication information is used to indicate the node coordinates of the node in the Merkle tree; Methods for obtaining the location information of the leaf node include: Obtaining the key in the key-value pair corresponding to the node data of the leaf node, and performing a hash operation on the obtained key using the preset hash algorithm to obtain a hash operation result; A modulo operation is performed on the obtained hash operation result, and the modulo operation result is used as the coordinate indication information of the leaf node.
4. The method according to claim 3, characterized in that Methods for obtaining the location information of the ancestor node include: Obtaining the node depth of the ancestor node in the Merkle tree; The coordinate indication information of the ancestor node is calculated based on the node depth of the ancestor node and the coordinate indication information of the leaf node.
5. The method according to any one of claims 1 to 4, characterized in that: The location information includes coordinate indication information and node depth, the path node includes multiple ancestor nodes of the leaf node, and for any ancestor node, based on the hash change amount of the leaf node and the location information of the path node, a method for determining the hash change amount generated by any ancestor node corresponding to the leaf node includes: Determine a target child node of any ancestor node, wherein the target child node refers to: a child node belonging to the path node among the child nodes of any ancestor node; Obtaining a hash change of the target child node, and determining a unique parameter preset for the node depth of the target child node; Based on the unique parameter corresponding to the target child node, the hash change of the target child node and the position information of the target child node, the hash change generated by any ancestor node corresponding to the leaf node is calculated.
6. The method according to any one of claims 1 to 4, characterized in that: The location information includes coordinate indication information and node depth, and the path node includes multiple ancestor nodes of the leaf node; for any ancestor node, based on the hash change amount of the leaf node and the location information of the path node, a method for determining the hash change amount generated by any ancestor node corresponding to the leaf node includes: Determining a node depth of any of the ancestor nodes in the Merkle tree, and determining each target pathway node from the pathway nodes having a node depth greater than a node depth of any of the ancestor nodes; Determining unique parameters preset for the node depth of each target pathway node, wherein there is a one-to-one correspondence between the unique parameters and the node depth; Based on the unique parameters corresponding to each target path node, the location information of each target node and the hash change of the leaf node, the hash change generated by any ancestor node corresponding to the leaf node is calculated.
7. The method according to claim 1, characterized in that The method further comprises: In response to a request for existence verification of target transaction data under the target block, determining a target leaf node storing the target transaction data in the Merkle tree; Determine the trusted tree node corresponding to the target leaf node in the Merkle tree, and obtain the hash value of each leaf node under the trusted tree node; wherein the trusted tree node is the ancestor node of the target leaf node, and the trusted tree node has a trusted credential for its hash value, and the trusted credential is used to indicate that the hash value of the trusted tree node has passed the hash value authenticity verification of multiple blockchain nodes or preset supervisors; A reference hash of the trusted tree node is calculated based on the hash value of each leaf node, and when the reference hash is the same as the hash value indicated by the trusted credential, a verification result is generated indicating that the target transaction data exists in the target block.
8. The method according to claim 1, characterized in that: The number of the leaf nodes is one or more, and the method of updating the hash value stored in the ancestor node based on the hash change amount corresponding to the leaf node includes: Determine the hash change amount generated by the ancestor node corresponding to each leaf node; The sum of the hash changes generated by the ancestor node corresponding to each leaf node is used as the total hash change amount of the ancestor node; The total amount of hash changes is used to update the hash value stored in the ancestor node.
9. A block generation device, characterized in that: In the Merkle tree used in the block generation process corresponding to the block generation device, the hash value of the leaf node is obtained by performing a hash operation on the node data of the leaf node using a preset hash algorithm, and performing a modulo operation on the hash operation result. The hash value of the parent node in the Merkle tree is obtained by performing a sum operation based on the hash values of its child nodes and performing a modulo operation on the sum operation result. The block generation device includes: A request response unit, configured to respond to a block generation request, update the leaf nodes in the Merkle tree using the transaction data packaged to generate the target block, and obtain the current hash value of the leaf nodes after the data is updated; A first calculation unit, configured to use a difference between the current hash value and a historical hash value of the leaf node as a hash change amount of the leaf node, wherein the historical hash value refers to a hash value of the leaf node before the current data update; A position information calculation unit, used to obtain position information of path nodes on a target path, wherein the target path refers to a path from the leaf node to the root node of the Merkle tree, and the path nodes include the leaf node and its ancestor node; A second calculation unit is used to determine the hash change amount generated by the ancestor node corresponding to the leaf node based on the hash change amount of the leaf node and the position information of the path node, and update the hash value stored in the ancestor node based on the hash change amount corresponding to the ancestor node to obtain an updated Merkle tree; The block packaging unit is used to package the transaction data and generate the target block based on the packaged data and the hash value of the root node in the updated Merkle tree.
10. A computer device, characterized in that: include: a processor adapted to implement one or more computer programs; A storage medium storing one or more computer programs, wherein the one or more computer programs are suitable for being loaded by the processor and executing the method according to any one of claims 1 to 8.
Citation Information
Cited By
Sparse Merkel tree storage and verification method and device, medium and equipment
CN120950508A
