A blockchain data processing method, system and storage medium

By using an improved Merkel directed acyclic graph to store block data, blockchain nodes store partial data and retrieve target data through a multi-level search mechanism, solving the problems of high storage pressure and data expansion in blockchain systems, and achieving efficient data synchronization and storage optimization.

CN116932641BActive Publication Date: 2026-01-09NEUSOFT CORP
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310666682.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-06
Publication Date
2026-01-09
Estimated Expiration
2043-06-06

AI Technical Summary

Technical Problem

In a blockchain system, each node needs to synchronize data across the entire network, resulting in high storage pressure. Existing archiving and block data trimming methods are costly, difficult to query data, or may compromise data integrity.

Method used

An improved Merkel directed acyclic graph is used to store block data. Each blockchain node stores a portion of the data and retrieves the target block data through a routing table and a multi-level lookup mechanism, thus achieving distributed storage of the full amount of data.

Benefits of technology

It reduces the storage pressure on each blockchain node, improves data retrieval efficiency, avoids the ledger data bloat problem of traditional blockchain systems, and achieves data synchronization between nodes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116932641B_ABST
    Figure CN116932641B_ABST
Patent Text Reader

Abstract

The application discloses a kind of blockchain data processing method, system and storage medium, for relieving the storage pressure of blockchain system.The method is applied to blockchain system, including multiple blockchain nodes, and the blockchain node stores block data by Merkle directed acyclic graph, and the method comprises: the data acquisition request of target block data is obtained by the blockchain node, and the blockchain node is determined as current node;Current node determines linked blockchain node according to the routing table established;Data acquisition request is sent to linked blockchain node, so that linked blockchain node queries whether target block data is stored according to block identifier;If target block data is stored, linked blockchain node obtains target block data in Merkle directed acyclic graph and sends to blockchain node;If target block data is not stored, linked blockchain node is determined as current node, and the steps of determining linked blockchain node and subsequent steps are repeatedly executed.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of blockchain, in particular to a blockchain data processing method and system and a storage medium. BACKGROUND

[0002] The blockchain is a distributed ledger technology jointly maintained by multiple parties, using cryptography to ensure the security of transmission and access, and is integrated by a chain structure of time-stamped blocks, flexible programmable smart contracts, distributed data storage, consensus mechanism of distributed nodes, and a point-to-point transmission network, and has the characteristics of consistent data storage, difficulty in tampering, and prevention of repudiation.

[0003] In terms of storage, each blockchain node in the blockchain system needs to synchronize the entire network data, resulting in continuous increase of data in each blockchain node; in addition, each blockchain node in the blockchain system needs to save a copy of the same ledger data, causing great storage pressure on the blockchain system. SUMMARY

[0004] Therefore, the embodiments of the present application provide a blockchain data processing method and system and a storage medium to alleviate the storage pressure of the blockchain system.

[0005] To solve the above problems, the technical solutions provided by the embodiments of the present application are as follows:

[0006] A blockchain data processing method, applied to a blockchain system, the blockchain system comprising a plurality of blockchain nodes, each of the blockchain nodes storing block data through a Merkle directed acyclic graph, and the block data stored by each of the blockchain nodes collectively constituting full data of the blockchain system; the method comprising:

[0007] The blockchain node acquires a data acquisition request of target block data, determines the blockchain node as a current node, and the data acquisition request comprises a block identifier of the target block data;

[0008] The current node determines a linked blockchain node according to a routing table established;

[0009] The current node sends the data acquisition request to the linked blockchain node, so that the linked blockchain node queries whether to store the target block data according to the block identifier;

[0010] If the linked blockchain node stores the target block data, the linked blockchain node acquires the target block data in the Merkle directed acyclic graph and sends the target block data to the blockchain node;

[0011] If the linked blockchain node does not store the target block data, the current node determines the linked blockchain node as the current node, and repeats the steps of determining the linked blockchain node according to the established routing table and the subsequent steps.

[0012] In a possible implementation, the blockchain node stores block data through a Merkel directed acyclic graph, including:

[0013] The blockchain node calculates a hash value of the to-be-stored block data, and establishes a hash balanced binary tree according to the hash value of the to-be-stored block data.

[0014] The hash balanced binary tree is converted into a Merkel directed acyclic graph.

[0015] The to-be-stored block data is stored according to the Merkel directed acyclic graph.

[0016] In a possible implementation, the hash balanced binary tree is converted into a Merkel directed acyclic graph, including:

[0017] If the level of the left or right subtree of the hash balanced binary tree except the root node is less than 2, a group of left leaf nodes, right leaf nodes, and parent nodes are obtained from the hash balanced binary tree, the left leaf nodes and the parent nodes are hash-merged to obtain a first merged hash value, a right pointer of the first merged hash value is pointed to the right leaf node, and the first merged hash value and the right leaf node are hash-merged to obtain a second merged hash value, the second merged hash value is re-used as a left leaf node, and the steps of obtaining a group of left leaf nodes, right leaf nodes, and parent nodes from the hash balanced binary tree and the subsequent steps are repeated until the obtained parent node is the root node of the hash balanced binary tree, and a Merkel directed acyclic graph is generated.

[0018] In a possible implementation, the hash balanced binary tree is converted into a Merkel directed acyclic graph, including:

[0019] If the level of the left or right subtree of the hash balanced binary tree other than the root node is greater than or equal to 2, a group of first left leaf nodes, first right leaf nodes and first parent nodes are obtained from the left subtree of the hash balanced binary tree, the first left leaf nodes and the first parent nodes are hashed and merged to obtain a third merged hash value, the right pointer of the third merged hash value points to the first right leaf node, and the third merged hash value and the first right leaf node are hashed and merged to obtain a fourth merged hash value, the fourth merged hash value is re-taken as the first left leaf node, and the above steps are repeatedly executed until the obtained first parent node is the root node of the hash balanced binary tree.

[0020] A group of second left leaf nodes, second right leaf nodes and second parent nodes are obtained from the right subtree of the hash balanced binary tree, the second left leaf nodes and the second parent nodes are hashed and merged to obtain a fifth merged hash value, the right pointer of the third merged hash value points to the second right leaf node, and the fifth merged hash value and the second right leaf node are hashed and merged to obtain a sixth merged hash value, the sixth merged hash value is re-taken as the second left leaf node, and the above steps are repeatedly executed until the obtained second parent node is the root node of the right subtree of the hash balanced binary tree.

[0021] The right pointer of the last generated third merged hash value or fourth merged hash value points to the last generated fifth merged hash value or sixth merged hash value, and the last generated third merged hash value or fourth merged hash value and the last generated fifth merged hash value or sixth merged hash value are hashed and merged to obtain a hash value of a Merkle directed acyclic graph, and the Merkle directed acyclic graph is generated.

[0022] In a possible implementation, the method further includes:

[0023] If the number of the to-be-stored block data is greater than a preset threshold, the to-be-stored block data is divided into multiple groups.

[0024] The blockchain node calculates a hash value of the to-be-stored block data, and establishes a hash balanced binary tree according to the hash value of the to-be-stored block data, including:

[0025] The blockchain node calculates a hash value of each group of to-be-stored block data, and respectively establishes a hash balanced binary tree according to the hash value of each group of to-be-stored block data.

[0026] In a possible implementation, the routing table comprises m blockchain nodes, a hash value of an (i+1)th blockchain node is greater than n times of a hash value of an ith blockchain node, where n is a natural number greater than 1, m and i are positive integers, and i+1 is less than or equal to m.

[0027] In a possible implementation, the method further comprises:

[0028] After the target block data is received by the blockchain node, the target block data is verified.

[0029] If the target block data passes the verification, a data acquisition cancellation message is sent to other blockchain nodes.

[0030] A blockchain system comprises a plurality of blockchain nodes.

[0031] Each of the blockchain nodes is configured to store block data in a Merkle directed acyclic graph, and the block data stored by each of the blockchain nodes collectively constitutes full data of the blockchain system.

[0032] The blockchain node is configured to acquire a data acquisition request for target block data, determine the blockchain node as a current node, and the data acquisition request comprises a block identifier of the target block data.

[0033] The current node is configured to determine a linked blockchain node according to a routing table established.

[0034] The current node is configured to send the data acquisition request to the linked blockchain node, so that the linked blockchain node queries whether the target block data is stored according to the block identifier.

[0035] If the linked blockchain node stores the target block data, the linked blockchain node is configured to acquire the target block data in the Merkle directed acyclic graph and send the target block data to the blockchain node.

[0036] If the linked blockchain node does not store the target block data, the current node is configured to determine the linked blockchain node as a current node, and repeat the current node determining a linked blockchain node according to the routing table established and subsequent steps.

[0037] A blockchain system comprises a plurality of blockchain nodes, and the blockchain node comprises a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the blockchain data processing method is implemented.

[0038] A computer readable storage medium, the computer readable storage medium has instructions stored therein, when the instructions run on a terminal device, make the terminal device execute the blockchain data processing method as described above.

[0039] Therefore, the embodiments of the present application have the following beneficial effects:

[0040] The embodiments of the present application store block data by using improved Merkle DAG in the blockchain nodes of the blockchain system, and the block data stored by each blockchain node collectively constitutes the full amount of data of the blockchain system, so that each blockchain node only stores part of the data, reducing the storage pressure of the blockchain node. In the case of storing part of the data in each blockchain node, when a certain target block data needs to be obtained, the target block data can be obtained by the way of multi-level layer-by-layer searching of the target block data in the blockchain nodes, which relieves the storage pressure of the blockchain system while still realizing data synchronization between the blockchain nodes. BRIEF DESCRIPTION OF DRAWINGS

[0041] Figure 1 A schematic diagram of an exemplary application scenario provided by the embodiments of the present application;

[0042] Figure 2 A flowchart of a blockchain data processing method provided by the embodiments of the present application;

[0043] Figure 3 A schematic diagram of a hash balanced binary tree in the embodiments of the present application;

[0044] Figure 4 A schematic diagram of a Merkle DAG in the embodiments of the present application;

[0045] Figure 5 A schematic diagram of another hash balanced binary tree in the embodiments of the present application;

[0046] Figure 6 A schematic diagram of another Merkle DAG in the embodiments of the present application;

[0047] Figure 7 A schematic diagram of a blockchain system provided by the embodiments of the present application. DETAILED DESCRIPTION

[0048] In order to make the above-mentioned purposes, features and advantages of the embodiments of the present application more obvious and easy to understand, the embodiments of the present application will be further described in detail below in combination with the drawings and specific embodiments.

[0049] In order to facilitate understanding and explaining the technical solutions provided by the embodiments of the present application, the background art of the embodiments of the present application will be described first.

[0050] Blockchain is a distributed ledger technology jointly maintained by multiple parties, using cryptography to ensure secure transmission and access.

[0051] In terms of storage, since each blockchain node in the blockchain system needs to synchronize the data of the entire network, the data of each blockchain node is always increasing. In addition, each blockchain node in the blockchain system needs to save a copy of the same ledger data, resulting in a large storage pressure of the blockchain system, that is, there is a problem of ledger data bloating in the blockchain system.

[0052] The prior art usually solves the problem of ledger data bloating in the blockchain system from two aspects. One way is archiving, which transfers historical block data to the cold storage of the blockchain node. This way is low in cost and simple to implement, but it causes difficulties in querying historical block data, synchronizing historical data for newly added blockchain nodes, and recovering historical data after the collapse of the blockchain node. Another way is block data pruning, which allows some blockchain systems to delete early block data to save storage space. The main defect of this way is to destroy the integrity of the data, resulting in some historical data being unable to be traced.

[0053] Therefore, the embodiments of the present application provide a blockchain data processing method and system based on distributed storage for compressing blockchain ledger data. In the embodiments of the present application, each blockchain node stores part of the block data using an improved Merkle directed acyclic graph, which can improve the retrieval efficiency. Through the search of the block data by the multi-level blockchain nodes, any block data can be obtained under the condition that part of the block data is stored in each blockchain node. Thus, the full amount of data of the blockchain system can be distributed and stored in the blockchain nodes, reducing the storage pressure of each blockchain node and avoiding the problem of ledger data bloating in the traditional blockchain system.

[0054] In order to facilitate understanding of the blockchain data processing method provided by the embodiments of the present application, the following will be described in conjunction with the scene example shown in Figure 1 Figure 1 As shown in the figure, the figure is a schematic diagram of an exemplary application scenario provided by the embodiments of the present application.

[0055] The embodiments of the present application are applied to a blockchain system, which includes a plurality of blockchain nodes, and the blockchain nodes can communicate with each other. Each blockchain node stores a plurality of block data through an improved Merkle directed acyclic graph, and the block data can be understood as ledger data stored by block. The data stored by each blockchain node collectively constitutes the full amount of data of the blockchain system, that is, the full amount of data of the blockchain system is distributed and stored in each blockchain node, thereby reducing the storage pressure of each blockchain node.

[0056] ​When a certain blockchain node needs to obtain target block data, the blockchain node determines, according to the established routing table, the linked blockchain nodes having a routing relationship with the blockchain node, and sends a data obtaining request to the linked blockchain nodes. The linked blockchain nodes query whether the target block data is stored, and if the target block data is stored, the target block data is obtained through the Merkle DAG of the linked blockchain nodes and returned to the original blockchain node. If the linked blockchain nodes do not store the target block data, the linked blockchain nodes having a routing relationship with the linked blockchain nodes are determined, and the above process is repeated. That is, each blockchain node is searched according to the level, and finally the target block data is obtained. In the case that each blockchain node stores part of the block data, any block data can also be obtained.

[0057] Those skilled in the art can understand that, Figure 1 The framework diagram shown is only one example in which the embodiments of the present application can be implemented. The scope of application of the embodiments of the present application is not limited by any aspect of the framework.

[0058] In order to facilitate understanding of the present application, a blockchain data processing method provided by the embodiments of the present application is described below with reference to the accompanying drawings.

[0059] Referring to Figure 2 As shown in the figure, the figure is a flowchart of a blockchain data processing method provided by the embodiments of the present application, which can include S200-S205: Figure 2

[0060] S200: Each blockchain node stores block data through a Merkle DAG, and the block data stored by each blockchain node collectively constitutes the full amount of data of the blockchain system.

[0061] The blockchain data processing method provided by the embodiments of the present application can be applied to a blockchain system including a plurality of blockchain nodes, and the blockchain nodes can communicate with each other. Each blockchain node corresponds to a node identifier, which can be a hash value of the blockchain node. The hash value is related to the block data stored in the blockchain node.

[0062] S200 can be considered as a preliminary step of the blockchain data processing method provided by the embodiments of the present application. Each blockchain node pre-establishes an improved Merkle DAG to store block data through the Merkle DAG. Each block data corresponds to a block identifier, which can be a hash value related to the block data. In actual application, the node identifier of the blockchain node is greater than the block identifier of each block data stored in the blockchain node.

[0063] ​Each blockchain node stores a part of the block data, and the block data stored by each blockchain node collectively constitutes the full amount of data of the blockchain system. That is, all the ledger data of the blockchain system is distributed and stored in each blockchain node. Without changing the structure and function of the blockchain, by using a storage optimization method to distribute the block data in the blockchain nodes, the local storage of the blockchain nodes can be reduced, the storage pressure of the blockchain nodes can be reduced, and the problem of ledger data inflation caused by full redundancy storage in the traditional blockchain system can be avoided.

[0064] The specific implementation of the blockchain node in storing the block data by using the Merkle DAG can be referred to the description of subsequent embodiments, and will not be described here.

[0065] S201: The blockchain node obtains a data acquisition request of target block data, determines the blockchain node as a current node, and the data acquisition request includes a block identifier of the target block data.

[0066] When the blockchain node needs to query and acquire target block data, the data acquisition request of the target block data is obtained, the target block data can be one or more block data, and the data acquisition request includes the block identifier of each target block data. Then the blockchain node is determined as a current node, and the subsequent steps are executed.

[0067] S202: The current node determines the linked blockchain node according to the established routing table.

[0068] The embodiment of the application proposes a DHT (Distributed Hash Table)-based block retrieval network for determining a blockchain node storing target block data. Each blockchain node can be sorted according to a node identifier, and the node identifiers form a full node identifier ring in ascending order, forming a sorted set of the DHT block retrieval network. Each blockchain node in the blockchain system maintains a routing table, which stores related information of the linked blockchain nodes. The linked blockchain nodes have a routing relationship with the current node. Through the routing table of each blockchain node, all blockchain nodes can be connected together. Thus, the current node can determine the linked blockchain nodes of the current node according to the established routing table.

[0069] In a possible implementation, the routing table includes m blockchain nodes, and the hash value of the (i+1)th blockchain node is greater than n times of the hash value of the ith blockchain node, where n is a natural number greater than 1, m and i are positive integers, and i+1 is less than or equal to m.

[0070] Specifically, the m blockchain nodes in the routing table have the following characteristics: the hash value of the i+1th blockchain node is greater than n times of the hash value of the ith blockchain node, and n needs to be greater than 1. For example, n = 2, in the m blockchain nodes, the hash value of the 1st blockchain node is 1000, then the hash value of the 2nd blockchain node needs to be greater than or equal to 2000, if the hash value of the 2nd blockchain node is 2000, then the hash value of the 3rd blockchain node needs to be greater than or equal to 4000, if the hash value of the 3rd blockchain node is 4000, and so on. The value of m can be set in advance to make each blockchain node have a limited number of linked blockchain nodes. In actual application, the blockchain nodes meeting the requirements can be found along the ordered set of the DHT block retrieval network to establish the routing table of the blockchain nodes.

[0071] The routing table is set in the manner that the hash value of the i+1th blockchain node is greater than n times of the hash value of the ith blockchain node, which can ensure that the linked blockchain nodes of the current node are distributed relatively dispersedly, and avoid that the communication is concentrated on the blockchain nodes with higher ranking in the ordered set of the DHT block retrieval network when the current node sends a data acquisition request to the linked blockchain nodes.

[0072] S203: The current node sends a data acquisition request to the linked blockchain node, so that the linked blockchain node queries whether the target block data is stored according to the block identifier.

[0073] The current node sends a data acquisition request to the linked blockchain node, and the linked blockchain node acquires the block identifier from the data acquisition request after receiving the data acquisition request. Since the node identifier of the blockchain node is greater than the block identifier of each block data stored in the blockchain node, it can be determined whether the linked blockchain node may store the target block data by comparing the block identifier in the data acquisition request with the node identifier of the linked blockchain node. For example, the block identifier is 5000, and the node identifier of the linked blockchain node is 4000, so the linked blockchain node does not store the target block data. The block identifier is 2000, and the node identifier of the linked blockchain node is 4000, so the linked blockchain node may store the target block data, which can be further determined whether the target block data is stored in the Merkle DAG.

[0074] S204: If the linked blockchain node stores the target block data, the linked blockchain node acquires the target block data in the Merkle DAG and sends it to the blockchain node.

[0075] If the target block data is stored in the linked blockchain node, the target block data is obtained through the Merkle DAG and sent to the blockchain node that initially sent the data obtaining request, so that the blockchain node obtains the target block data requested to be obtained. The process of obtaining the target block data through the Merkle DAG will be described in subsequent embodiments.

[0076] S205: If the target block data is not stored in the linked blockchain node, the current node determines the linked blockchain node as the current node, and returns to S202 to repeat the process of determining the linked blockchain node according to the established routing table and the subsequent steps.

[0077] If the target block data is not stored in the linked blockchain node, the linked blockchain node is re-determined as the current node, the linked blockchain node is determined according to the established routing table, and the subsequent steps are performed. It is equivalent to continuing to pass the data obtaining request to other level blockchain nodes along the routing table when the target block data is not stored in the linked blockchain node, until the target block data is found or all blockchain nodes receive the data obtaining request, and the target block data is obtained.

[0078] In a possible implementation, the method can further include:

[0079] A1: After the blockchain node receives the target block data, the target block data is verified.

[0080] A2: If the target block data is verified, a data obtaining cancellation message is sent to other blockchain nodes.

[0081] After the blockchain node that initially sent the data obtaining request receives the target block data, the verification of the target block data is completed. After it is determined that the target block data is verified, that is, the required data is correctly obtained, a data obtaining cancellation message is sent to other blockchain nodes. The data obtaining cancellation message also includes the block identifier of the target block data. After receiving the data obtaining cancellation message, other blockchain nodes can stop continuing to distribute the data obtaining request of the target block data, reducing the communication and retrieval process of other blockchain nodes.

[0082] Based on the description of S200-S205, in the embodiments of the present application, the blockchain nodes of the blockchain system store the block data by using the improved Merkle DAG, and the block data stored by each blockchain node collectively constitutes the full amount of data of the blockchain system, so that each blockchain node only stores part of the data, thereby reducing the storage pressure of the blockchain node. In the case that each blockchain node stores part of the data, when a certain target block data needs to be obtained, the target block data can be obtained by means of multi-level layer-by-layer searching of the target block data by the blockchain nodes, thereby relieving the storage pressure of the blockchain system while still realizing the data synchronization among the blockchain nodes.

[0083] Taking an actual application as an example, the blockchain data processing method provided by the embodiments of the present application is further described.

[0084] When the blockchain node needs to query and obtain the target block data, the blockchain node can be understood as a data demand node. The data demand node generates a data acquisition request (want-have message), and the data acquisition request includes the block identifier of the target block data. The target block data can be multiple, and the block identifier of the target block data can constitute a want-list (demand list). That is, the data acquisition request can carry the want-list.

[0085] The data demand node broadcasts the data acquisition request to its linked blockchain nodes, and the linked blockchain nodes receive the data acquisition request. In a possible implementation manner, the message can be received with a probability P, and the calculation formula of the probability P is as follows: P = 1-1 / (1+exp(6-3*(blocks_sent / (blocks_recv+1)))). Wherein, blocks_sent represents the total number of data sent by the blockchain node, blocks_recv represents the total number of data received by the blockchain node, exp is the x power of e, and x is a positive integer. If a blockchain node only accepts data and does not share data, the probability of other blockchain nodes sending data to it will become lower and lower (after reaching a certain value, it will sharply decrease close to 0), and if the blockchain node continuously maintains data sharing, the probability of other blockchain nodes sending data to it will become larger and larger. Thus, the blockchain nodes are encouraged to share data, and the difficulty of data acquisition caused by the inaction of individual blockchain nodes is avoided.

[0086] After the linked blockchain node receives the data acquisition request, the want-list is acquired, and have or dont-have messages are returned to the data demand node according to whether each block data in the want-list is stored.

[0087] When the linked blockchain node returns the have message, the block data possessed by the linked blockchain node is sent to the data demand node, and the block identifier of the block data possessed by the linked blockchain node is removed from the want-list, and the want-list is updated. The linked blockchain node continues to determine the linked blockchain node, and broadcasts the data acquisition request to the linked blockchain node, so that the linked blockchain node receives the data acquisition request, acquires the want-list, and so on.

[0088] After the data demand node acquires the target block data, whether the target block data is correct is verified according to the hash value of the target block data. After one target block data is correctly transmitted, a cancel data acquisition message corresponding to the target block data is broadcasted to the outside, so as to prevent other blockchain nodes from repeatedly sending the target block data. After the data demand node receives all the target block data in the want-list, a closing message is sent to other blockchain nodes, so that the blockchain node sending data and the blockchain node receiving data are disconnected, and the generated state is cleared.

[0089] When the block data is distributed and stored in multiple blockchain nodes, the embodiments of the present application can acquire all the required block data from multiple blockchain nodes, which can alleviate the storage pressure of the blockchain system, and still realize data synchronization between the blockchain nodes.

[0090] In a possible implementation, the specific implementation of the S200 blockchain node storing block data through the Merkle directed acyclic graph can include:

[0091] B1: The blockchain node calculates the hash value of the to-be-stored block data, and establishes a hash balanced binary tree according to the hash value of the to-be-stored block data.

[0092] The blockchain node acquires the to-be-stored block data required to be stored by the current blockchain node, calculates the hash value of each to-be-stored block data, and establishes a hash balanced binary tree according to the hash value of the to-be-stored block data. Referring to Figure 3 or Figure 5 , a schematic diagram of the established hash balanced binary tree is shown. Taking Figure 3 for example, for example, the hash values of the to-be-stored block data are 3, 5, 8, 10, and 14, and a hash balanced binary tree is established according to the sorting of the hash values, as shown in Figure 3The hash balanced binary tree is shown.

[0093] B2: converting the hash balanced binary tree into a Merkle DAG.

[0094] The hash balanced binary tree is converted into a Merkle DAG, which represents the index of the block data to be stored. As shown in Figure 4 or Figure 6 , a schematic diagram of the Merkle DAG is shown. The nodes in the Merkle DAG have left and right pointers, which identify the range of the nodes in the Merkle DAG, for example, in Figure 4 , the left and right pointers of Hash 35 are 3 and 5, representing the hash value range of the block data under this node is 3-5, and the left and right pointers of Hash 358,10.14 are 3 and 14, representing the hash value range of the block data under this node is 3-14. Meanwhile, the nodes in the Merkle DAG also have a right pointer, which points to the right node in the same level.

[0095] The improved Merkle DAG provided by the embodiments of the present application supports level query, multiple thread parallel query, and when no specified value is found within the range of any index node, the right node can be jumped through the dashed right pointer. As long as any thread traverses to the last pointed block data, it can return that there is no target block data, or the found target block data, thereby improving the retrieval efficiency through multi-thread parallel and fast return when the target block data does not exist.

[0096] B3: storing the block data to be stored according to the Merkle DAG.

[0097] The nodes of the Merkle DAG represent the index of the block data, and according to the structure of the Merkle DAG, each node corresponds to the corresponding block data, thereby realizing the storage of the block data to be stored by the block chain node.

[0098] In a possible implementation, the specific implementation of B2 for converting the hash balanced binary tree into a Merkle DAG can include:

[0099] If the level of the left or right subtree of the hash balanced binary tree except the root node is less than 2, a set of left leaf nodes, right leaf nodes and parent nodes are obtained from the hash balanced binary tree, the left leaf nodes and the parent nodes are hash-merged to obtain a first merged hash value, a right pointer of the first merged hash value points to the right leaf nodes, and the first merged hash value and the right leaf nodes are hash-merged to obtain a second merged hash value, the second merged hash value is re-taken as the left leaf node, and the subsequent steps of obtaining a set of left leaf nodes, right leaf nodes and parent nodes from the hash balanced binary tree are repeatedly executed until the parent node obtained is the root node of the hash balanced binary tree, and a Merkle DAG is generated.

[0100] That is, in the embodiment of the present application, if the level of the left or right subtree of the hash balanced binary tree except the root node is less than 2, a set of left leaf nodes, right leaf nodes and parent nodes are obtained from the hash balanced binary tree, the left leaf nodes and the parent nodes are hash-merged, Hash(tmp1)=Hash(left)∪Hash(parent), at this time Hash(tmp1) is a first merged hash value, for example Figure 4 In the above, the left leaf node Hash3 and the parent node Hash5 are hash-merged to obtain Hash35. Then the obtained first merged hash value is pointed to the right leaf node Hash(tmp1).LP=Hash(right), LP represents a right pointer, for example, Hash35 performs the right leaf node Hash8. Then the obtained merged hash value first and the right leaf node are hash-merged again, Hash(tmp2)=Hash(tmp1)∪Hash(right), at this time Hash(tmp2) is a second merged hash value, for example, Hash35 and the right leaf node Hash8 are hash-merged to obtain Hash358. The second merged hash value is re-taken as the left leaf node, for example, Hash358 continues to be hash-merged with the parent node Hash10 to obtain Hash358,10, and Hash358,10 and Hash14 are hash-merged to obtain Hash358,10,14. In this way, until a set of left leaf nodes, right leaf nodes and parent nodes are obtained, the parent node is the root node of the hash balanced binary tree, and a Merkle DAG is generated.

[0101] In a possible implementation, the specific implementation of B2 in converting the hash balanced binary tree into the Merkle DAG can include:

[0102] If the level of the left sub-tree or the right sub-tree of the hash balanced binary tree other than the root node is greater than or equal to 2, a group of first left leaf nodes, first right leaf nodes and first parent nodes are obtained from the left sub-tree of the hash balanced binary tree, the first left leaf nodes and the first parent nodes are hash-merged to obtain a third merged hash value, the right pointer of the third merged hash value points to the first right leaf node, and the third merged hash value and the first right leaf node are hash-merged to obtain a fourth merged hash value, the fourth merged hash value is re-taken as the first left leaf node, and the steps of obtaining a group of first left leaf nodes, first right leaf nodes and first parent nodes from the left sub-tree of the hash balanced binary tree and subsequent steps are repeatedly executed until the obtained first parent node is the root node of the hash balanced binary tree;

[0103] A group of second left leaf nodes, second right leaf nodes and second parent nodes are obtained from the right sub-tree of the hash balanced binary tree, the second left leaf nodes and the second parent nodes are hash-merged to obtain a fifth merged hash value, the right pointer of the third merged hash value points to the second right leaf node, and the fifth merged hash value and the second right leaf node are hash-merged to obtain a sixth merged hash value, the sixth merged hash value is re-taken as the second left leaf node, and the steps of obtaining a group of second left leaf nodes, second right leaf nodes and second parent nodes from the right sub-tree of the hash balanced binary tree and subsequent steps are repeatedly executed until the obtained second parent node is the root node of the right sub-tree of the hash balanced binary tree.

[0104] The right pointer of the last generated third merged hash value or fourth merged hash value points to the last generated fifth merged hash value or sixth merged hash value, and the last generated third merged hash value or fourth merged hash value and the last generated fifth merged hash value or sixth merged hash value are hash-merged to obtain a hash value of the Merkle DAG, and the Merkle DAG is generated.

[0105] In the embodiments of the present application, if the level of the left sub-tree or the right sub-tree of the hash balanced binary tree other than the root node is greater than or equal to 2, the left sub-tree and the root node part are processed, for example, referring to Figure 6 , the nodes Hash3 to Hash20 are processed in the same way as Figure 4 , and the right sub-tree part is processed, the nodes Hash27 to Hash50 are processed in the same way as Figure 4The corresponding processing mode is the same. Finally, the two parts are combined together to generate the Merkel directed acyclic graph. For example, for the left subtree and the root node part, the last generated third combined hash value or fourth combined hash value is Hash 358, 10, 14, 20, for the right subtree part, the last generated fifth combined hash value or sixth combined hash value is Hash 27, 30, 50, Hash 358, 10, 14, 20 is directed to Hash 27, 30, 50, and Hash 358, 10, 14, 20 and Hash 27, 30, 50 are combined to obtain the hash value Hash 3-50 of the Merkel directed acyclic graph, thereby generating the improved Merkel directed acyclic graph.

[0106] In addition, in order to avoid too many levels of the Merkel directed acyclic graph, in a possible implementation, the method further includes: if the number of the to-be-stored block data is greater than a preset threshold, dividing the to-be-stored block data into multiple groups.

[0107] The B1 blockchain node calculates the hash value of the to-be-stored block data, and the specific implementation of establishing the hash balanced binary tree according to the hash value of the to-be-stored block data includes:

[0108] The blockchain node calculates the hash value of each group of to-be-stored block data, and establishes a hash balanced binary tree according to the hash value of each group of to-be-stored block data.

[0109] That is, when the number of to-be-stored block data is large, the to-be-stored block data can be grouped to avoid too many levels of the finally established Merkel directed acyclic graph, thereby affecting the retrieval efficiency.

[0110] In the embodiment of the application, the block data in the blockchain node is organized by the improved Merkel directed acyclic graph, which can improve the retrieval efficiency of the block data.

[0111] Based on the block chain data processing method provided in the above method embodiment, the embodiment of the application further provides a block chain system, which will be described below with reference to the accompanying drawings.

[0112] Referring to Figure 7 As shown in the figure, the figure is a structural schematic diagram of a block chain system provided by an embodiment of the application. As Figure 7 As shown in the figure, the block chain system includes a plurality of block chain nodes 700;

[0113] Each of the block chain nodes is configured to store block data by a Merkel directed acyclic graph, and the block data stored by each of the block chain nodes collectively constitutes the full amount of data of the block chain system.

[0114] The blockchain node is configured to acquire a data acquisition request of target block data, determine the blockchain node as a current node, and the data acquisition request includes a block identifier of the target block data.

[0115] The current node is configured to determine a linked blockchain node according to the established routing table.

[0116] The current node is configured to send the data acquisition request to the linked blockchain node, so that the linked blockchain node queries whether the target block data is stored according to the block identifier.

[0117] If the linked blockchain node stores the target block data, the linked blockchain node is configured to acquire the target block data in the Merkle DAG and send the target block data to the blockchain node.

[0118] If the linked blockchain node does not store the target block data, the current node is configured to determine the linked blockchain node as a current node, repeatedly execute the current node to determine a linked blockchain node according to the established routing table, and subsequent steps.

[0119] In a possible implementation, the blockchain node is specifically configured to:

[0120] The blockchain node calculates a hash value of to-be-stored block data, and establishes a hash balanced binary tree according to the hash value of the to-be-stored block data.

[0121] The hash balanced binary tree is converted into a Merkle DAG.

[0122] The to-be-stored block data is stored according to the Merkle DAG.

[0123] In a possible implementation, the blockchain node is specifically configured to:

[0124] If a level of a left subtree or a right subtree of the hash balanced binary tree except a root node is less than 2, a group of left leaf nodes, right leaf nodes and parent nodes are acquired from the hash balanced binary tree, a first combined hash value is obtained by performing hash combination on the left leaf nodes and the parent nodes, a right pointer of the first combined hash value is pointed to the right leaf nodes, a second combined hash value is obtained by performing hash combination on the first combined hash value and the right leaf nodes, the second combined hash value is re-used as a left leaf node, and the steps of acquiring a group of left leaf nodes, right leaf nodes and parent nodes from the hash balanced binary tree and subsequent steps are repeatedly executed until the acquired parent node is a root node of the hash balanced binary tree, and a Merkle DAG is generated.

[0125] In a possible implementation, the blockchain node is specifically configured to:

[0126] If the height of the left or right subtree of the hash balanced binary tree other than the root node is greater than or equal to 2, a group of first left leaf nodes, first right leaf nodes and first parent nodes are obtained from the left subtree of the hash balanced binary tree, the first left leaf nodes and the first parent nodes are hashed and merged to obtain a third merged hash value, the right pointer of the third merged hash value points to the first right leaf node, and the third merged hash value and the first right leaf node are hashed and merged to obtain a fourth merged hash value, the fourth merged hash value is re-taken as a first left leaf node, and the above steps are repeatedly performed until the obtained first parent node is the root node of the hash balanced binary tree.

[0127] A group of second left leaf nodes, second right leaf nodes and second parent nodes are obtained from the right subtree of the hash balanced binary tree, the second left leaf nodes and the second parent nodes are hashed and merged to obtain a fifth merged hash value, the right pointer of the third merged hash value points to the second right leaf node, and the fifth merged hash value and the second right leaf node are hashed and merged to obtain a sixth merged hash value, the sixth merged hash value is re-taken as a second left leaf node, and the above steps are repeatedly performed until the obtained second parent node is the root node of the right subtree of the hash balanced binary tree.

[0128] The right pointer of the last generated third merged hash value or fourth merged hash value points to the last generated fifth merged hash value or sixth merged hash value, and the last generated third merged hash value or fourth merged hash value and the last generated fifth merged hash value or sixth merged hash value are hashed and merged to obtain a hash value of the Merkle DAG, and the Merkle DAG is generated.

[0129] In a possible implementation, the blockchain node is further configured to:

[0130] If the number of the to-be-stored block data is greater than a preset threshold, the to-be-stored block data is divided into a plurality of groups.

[0131] The blockchain node is specifically configured to:

[0132] The blockchain node calculates a hash value of each group of to-be-stored block data, and establishes a hash balanced binary tree according to the hash value of each group of to-be-stored block data.

[0133] In a possible implementation, the routing table comprises m blockchain nodes, and a hash value of an (i+1)th blockchain node is greater than n times of a hash value of an ith blockchain node, where n is a natural number greater than 1, m and i are positive integers, i+1 is less than or equal to m.

[0134] In a possible implementation, the blockchain node is further configured to, after receiving the target block data, verify the target block data.

[0135] If the target block data passes the verification, the blockchain node sends a data acquisition cancellation message to other blockchain nodes.

[0136] In addition, the embodiments of the present disclosure further provide a blockchain system, comprising a plurality of blockchain nodes, wherein each of the blockchain nodes comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the blockchain data processing method according to any one of the preceding embodiments when executing the computer program.

[0137] In addition, the embodiments of the present disclosure further provide a computer readable storage medium, which stores instructions, and the instructions, when executed on a terminal device, cause the terminal device to perform the blockchain data processing method according to any one of the preceding embodiments.

[0138] In this way, the embodiments of the present disclosure use the improved Merkle DAG to store block data in the blockchain nodes of the blockchain system, and the block data stored in each blockchain node collectively constitutes the full data of the blockchain system, so that each blockchain node only stores part of the data, thereby reducing the storage pressure of the blockchain node. In the case that each blockchain node stores part of the data, when a target block data is needed, the target block data can be obtained by means of multi-level layer-by-layer searching of the target block data in the blockchain nodes, thereby relieving the storage pressure of the blockchain system while still achieving data synchronization between the blockchain nodes.

[0139] It should be noted that the embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same or similar parts of each embodiment can be referred to each other. For the system or device disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple, and the related parts can be referred to the method part.

[0140] It should be understood that, in the application, "at least one" means one or more, "multiple" means two or more. "And / or" is used to describe the association relationship of the associated objects, which means that there can be three relationships, for example, "A and / or B" can mean: only A, only B, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally represents an "or" relationship between the associated objects before and after it. "At least one of the following" or similar expressions means any combination of these items, including any combination of single or multiple items. For example, at least one of a, b or c, can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.

[0141] It should also be noted that the relationship terms such as first and second, etc. used in this text are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between the entities or operations. Moreover, the terms "include", "contain" or any other variant thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, method, article or device. Without more limitations, the element defined by the statement "including a" does not exclude the presence of another identical element in the process, method, article or device including the element.

[0142] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of the two. The software module can be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0143] The above description of the disclosed embodiments enables a person skilled in the art to implement or use the application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the application. Therefore, the application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A blockchain data processing method, characterized in that, The method is applied to a blockchain system, the blockchain system comprising a plurality of blockchain nodes, each of the blockchain nodes calculating a hash value of to-be-stored block data and establishing a hash balanced binary tree according to the hash value of the to-be-stored block data; and converting the hash balanced binary tree into a Merkle directed acyclic graph; storing the to-be-stored block data according to the Merkle directed acyclic graph, and the block data stored by each of the blockchain nodes collectively constituting full data of the blockchain system; the method comprising: The blockchain node obtains a data acquisition request of target block data, determines the blockchain node as a current node, and the data acquisition request comprises a block identifier of the target block data; The current node determines a linked blockchain node according to the established routing table; The current node sends the data acquisition request to the linked blockchain node, so that the linked blockchain node queries whether the target block data is stored according to the block identifier; If the linked blockchain node stores the target block data, the linked blockchain node acquires the target block data in the Merkle directed acyclic graph and sends the target block data to the blockchain node; If the linked blockchain node does not store the target block data, the current node determines the linked blockchain node as a current node, and repeats the current node determining a linked blockchain node according to the established routing table and subsequent steps; The conversion of the hash balanced binary tree into the Merkle directed acyclic graph comprises: If the level of the left or right subtree of the hash balanced binary tree except the root node is less than 2, a group of left leaf nodes, right leaf nodes and parent nodes are obtained from the hash balanced binary tree, the left leaf nodes and the parent nodes are combined to obtain a first combined hash value, the right pointer of the first combined hash value points to the right leaf nodes, and the first combined hash value and the right leaf nodes are combined to obtain a second combined hash value, the second combined hash value is used as a left leaf node again, and the steps of obtaining a group of left leaf nodes, right leaf nodes and parent nodes from the hash balanced binary tree and subsequent steps are repeated until the obtained parent node is the root node of the hash balanced binary tree, and a Merkle directed acyclic graph is generated.

2. The method of claim 1, wherein, The conversion of the hash balanced binary tree into the Merkle directed acyclic graph comprises: If the height of the left or right subtree of the hash balanced binary tree other than the root node is greater than or equal to 2, a group of first left leaf nodes, first right leaf nodes and first parent nodes are obtained from the left subtree of the hash balanced binary tree, the first left leaf nodes and the first parent nodes are hashed and merged to obtain a third merged hash value, the right pointer of the third merged hash value points to the first right leaf node, and the third merged hash value and the first right leaf node are hashed and merged to obtain a fourth merged hash value, the fourth merged hash value is re-taken as a first left leaf node, and the above steps are repeated until the first parent node obtained is the root node of the hash balanced binary tree. A group of second left leaf nodes, second right leaf nodes and second parent nodes are obtained from the right subtree of the hash balanced binary tree, the second left leaf nodes and the second parent nodes are hashed and merged to obtain a fifth merged hash value, the right pointer of the third merged hash value points to the second right leaf node, and the fifth merged hash value and the second right leaf node are hashed and merged to obtain a sixth merged hash value, the sixth merged hash value is re-taken as a second left leaf node, and the above steps are repeated until the second parent node obtained is the root node of the right subtree of the hash balanced binary tree. The right pointer of the last generated third merged hash value or fourth merged hash value points to the last generated fifth merged hash value or sixth merged hash value, and the last generated third merged hash value or fourth merged hash value and the last generated fifth merged hash value or sixth merged hash value are hashed and merged to obtain a hash value of a Merkle DAG, and the Merkle DAG is generated.

3. The method of claim 1, wherein, The method further comprises: If the number of the to-be-stored block data is greater than a preset threshold, the to-be-stored block data is divided into multiple groups. The blockchain node calculates a hash value of the to-be-stored block data, and establishes a hash balanced binary tree according to the hash value of the to-be-stored block data, comprising: The blockchain node calculates a hash value of each group of to-be-stored block data, and establishes a hash balanced binary tree according to the hash value of each group of to-be-stored block data.

4. The method of claim 1, wherein, The routing table comprises m blockchain nodes, and the hash value of the (i+1)th blockchain node is greater than n times of the hash value of the ith blockchain node, wherein n is a natural number greater than 1, m and i are positive integers, and i+1 is less than or equal to m.

5. The method of claim 1, wherein, The method further comprises: After receiving the target block data, the blockchain node verifies the target block data; If the target block data passes the verification, a data acquisition cancellation message is sent to other blockchain nodes.

6. A blockchain system, characterized by, The blockchain system comprises a plurality of blockchain nodes; Each of the blockchain nodes is configured to calculate a hash value of to-be-stored block data, establish a hash balanced binary tree according to the hash value of the to-be-stored block data, and convert the hash balanced binary tree into a Merkle directed acyclic graph. The to-be-stored block data is stored according to the Merkle directed acyclic graph, and the block data stored by each of the blockchain nodes collectively constitutes full data of the blockchain system. The blockchain node is configured to obtain a data acquisition request of target block data, determine the blockchain node as a current node, and the data acquisition request includes a block identifier of the target block data. The current node is configured to determine a linked blockchain node according to a routing table. The current node is configured to send the data acquisition request to the linked blockchain node, so that the linked blockchain node queries whether the target block data is stored according to the block identifier. If the linked blockchain node stores the target block data, the linked blockchain node is configured to obtain the target block data in the Merkle directed acyclic graph and send the target block data to the blockchain node. If the linked blockchain node does not store the target block data, the current node is configured to determine the linked blockchain node as a current node, and repeatedly execute the current node determining a linked blockchain node according to a routing table and subsequent steps. The blockchain node is specifically configured to: If the level of the left subtree or the right subtree of the hash balanced binary tree except the root node is less than 2, obtain a group of left leaf nodes, right leaf nodes and parent nodes from the hash balanced binary tree, perform hash merging on the left leaf nodes and the parent nodes to obtain a first merged hash value, point a right pointer of the first merged hash value to the right leaf node, perform hash merging on the first merged hash value and the right leaf node to obtain a second merged hash value, and reuse the second merged hash value as a left leaf node. Repeat the above steps until the obtained parent node is the root node of the hash balanced binary tree, and generate a Merkle directed acyclic graph.

7. A blockchain system, characterized by, The blockchain system includes a plurality of blockchain nodes; the blockchain node includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and when the processor executes the computer program, the blockchain data processing method of any one of claims 1-5 is implemented.

8. A computer-readable storage medium, characterized in that, The computer readable storage medium stores instructions, and when the instructions run on the terminal device, the terminal device executes the blockchain data processing method of any one of claims 1-5.

Citation Information

Patent Citations

  • Block chain-based data management method and device, and medium

    CN112988852A

  • File fragment backup method and device based on IPFS, equipment and storage medium

    CN115495428A