Blockchain-based Data Traceability Query Method and Device

By searching in memory for traceability storage data after transaction data reconstructed with adjacent tables and maps in the transaction chain, the problem of low efficiency of blockchain traceability query is solved, and efficient and secure traceability query and subsequent transaction data are achieved.

CN114625751BActive Publication Date: 2025-05-30TSINGHUA UNIVERSITY
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210178934.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-25
Publication Date
2025-05-30
Estimated Expiration
2042-02-25

AI Technical Summary

Technical Problem

When conducting traceability query on the blockchain, the existing technology is inefficient and is not conducive to the security audit of subsequent transaction data.

Method used

By searching in memory for traceability storage data after the transaction data in the transaction chain reconstructed with adjacent tables and maps, the traceability query results can be quickly obtained and the query results and related information can be stored in the traceability chain.

Benefits of technology

It improves the efficiency and accuracy of traceability query, ensures the security audit and management of subsequent transaction data, and enhances the security and efficiency of traceability query.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114625751B_ABST
    Figure CN114625751B_ABST
Patent Text Reader

Abstract

The present invention provides a blockchain-based data traceability query method and device. The method includes: obtaining the query permission and query conditions of the user based on the user's traceability query request; searching the traceability storage data in the memory according to the query permission and the query conditions to obtain a query result and a query timestamp; wherein the traceability storage data includes data stored after reconstructing the transaction data in the transaction chain with an adjacency list and a mapping graph respectively; feeding back the traceability query result to the user, and storing the query permission, the query conditions, the query result and the query timestamp into the traceability chain. Using the method of the present invention can not only achieve the purpose of facilitating subsequent security audits and transaction data management, but also improve the security and efficiency of traceability queries, thereby flexibly meeting various traceability requirements.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of blockchain technology, and in particular, to a method and device for querying data traceability based on blockchain. Background Art

[0002] In recent years, due to its advantages such as anti-tampering, full-process traceability, traceability, and openness and transparency, blockchain technology has been widely used in the traceability query of various business data, such as traceability query applications for product supply, product processing, and luxury goods origin. Therefore, how to quickly and accurately query data traceability has become a hot research direction.

[0003] In the related art, blockchain adopts a chain structure and stores a large amount of transaction data. When a traceability query request is received, all transactions in the blocks in the blockchain are sequentially verified, or a Merkle directed acyclic graph reconstructed from the transaction data in the blockchain is traced and queried to obtain a traceability query result.

[0004] However, when the prior art performs traceability query based on blockchain, it is necessary to traverse the entire block or the reconstructed Merkle directed acyclic graph each time. Therefore, when there are a large number of blocks and a large amount of transaction data on the blockchain, not only the traceability query efficiency is low, but also it is not conducive to the subsequent security audit of transaction data. Summary of the Invention

[0005] The present invention provides a method and device for querying data traceability based on blockchain, which are used to solve the defects of low traceability query efficiency and unfavorable subsequent security audit of transaction data when the prior art performs traceability query based on blockchain, and realize safe and efficient traceability query of transaction data and facilitate subsequent security audit of transaction data.

[0006] The present invention provides a method for querying data traceability based on blockchain, including:

[0007] Based on the traceability query request of the user, obtain the query permission and query conditions of the user;

[0008] According to the query permission and the query conditions, search the traceability storage data in the memory to obtain a query result and a query timestamp; wherein, the traceability storage data includes data stored after reconstructing the transaction data in the transaction chain with an adjacency list and a mapping graph respectively;

[0009] Feed back the traceability query result to the user, and store the query permission, the query conditions, the query result, and the query timestamp into the traceability chain.

[0010] According to a blockchain-based data traceability query method provided by the present invention, before the step of obtaining the user's query permission and query conditions from the traceability chain based on the user's traceability query request, the method further includes:

[0011] Using a directed acyclic graph to reconstruct the transaction data in the transaction chain to obtain a traceability directed graph; wherein, the traceability directed graph includes a reverse traceability directed graph and a forward traceability directed graph;

[0012] Using an adjacency list to reconstruct the traceability directed graph into a traceability adjacency list;

[0013] Using a mapping graph to reconstruct the relationship between the vertices of the traceability adjacency list and the numbers of the vertices into a traceability mapping table;

[0014] Determine the traceability adjacency list and the traceability mapping table as traceability storage data, and store the traceability storage data in the memory.

[0015] According to a blockchain-based data traceability query method provided by the present invention, after the step of storing the traceability storage data in the memory, the method further includes:

[0016] Store the traceability adjacency list and the traceability mapping table in the form of files on the local hard disk, and store the hash value of the files on the local hard disk in the traceability chain.

[0017] According to a blockchain-based data traceability query method provided by the present invention, before the step of obtaining the user's query permission and query conditions from the traceability chain based on the user's traceability query request, the method further includes:

[0018] Based on a restart instruction, check whether the hash value of the files on the local hard disk is consistent with the hash value on the traceability chain;

[0019] If the hash value of the files on the local hard disk is consistent with the hash value on the traceability chain, load the traceability adjacency list and the traceability mapping table in the local hard disk into the memory, and execute the step of obtaining the user's query permission and query conditions based on the user's traceability query request.

[0020] According to a blockchain-based data traceability query method provided by the present invention, if the hash value of the files on the local hard disk is inconsistent with the hash value on the traceability chain, update the files on the local hard disk.

[0021] According to a blockchain-based data traceability query method provided by the present invention, before the step of obtaining the user's query permission and query conditions from the traceability chain based on the user's traceability query request, the method further includes:

[0022] Based on the received new block, update the traceability storage data in the memory, update the files in the local hard disk, store the hash value of the updated file into the traceability chain, and then execute the step of obtaining the query permission and query conditions of the user based on the traceability query request of the user.

[0023] According to a blockchain-based data traceability query method provided by the present invention, the process of updating the files in the local hard disk includes:

[0024] For the j-th file in the local hard disk, query that the latest block number included in the j-th file is t, and determine that the current latest version of the j-th file is j t , and determine whether the hash value of the j-th file stored on the traceability chain at version j t is the same as the hash value of the j-th file in the local hard disk at version j t ;

[0025] If the hash value of the j-th file stored on the traceability chain at version j t is the same as the hash value of the j-th file in the local hard disk at version j t , reconstruct the j-th file in the local hard disk based on the blocks in the transaction chain with numbers greater than t;

[0026] If the hash value of the j-th file stored on the traceability chain at version j t is not the same as the hash value of the j-th file in the local hard disk at version j t , determine whether the hash value of the j-th file stored on the traceability chain at version j t-1 is the same as the hash value of the j-th file in the local hard disk at version j t-1 ;

[0027] Until the hash value of the j-th file stored on the traceability chain at version j t-x is the same as the hash value of the j-th file in the local hard disk at version j t-x ; then reconstruct the j-th file in the local hard disk based on the blocks in the transaction chain with numbers greater than t - x; where t, x, and j are all positive integers, and j is a file in the local hard disk.

[0028] According to a blockchain-based data traceability query method provided by the present invention, the step of searching the traceability storage data in the memory according to the query permission and the query conditions to obtain a query result and a query time includes:

[0029] When the traceability storage data in the memory includes a traceability adjacency list and a traceability mapping table that characterize the dependency relationships between transaction data in the transaction chain, perform a breadth-first search on the traceability storage data in the memory according to the query permission and the query condition to obtain a query result and a query time.

[0030] According to a data traceability query method based on a blockchain provided by the present invention, obtaining the query permission and query condition of the user based on the traceability query request of the user includes:

[0031] Based on the traceability query request of the user, obtain the query permission of the user from the traceability chain;

[0032] Obtain the query condition input by the user from the traceability query request.

[0033] The present invention also provides a data traceability query device based on a blockchain, including:

[0034] An acquisition module, configured to obtain the query permission and query condition of the user based on the traceability query request of the user;

[0035] A query module, configured to search the traceability storage data in the memory according to the query permission and the query condition to obtain a query result and a query timestamp; wherein, the traceability storage data includes data stored after reconstructing the transaction data in the transaction chain with an adjacency list and a mapping graph respectively;

[0036] A processing module, configured to feedback the traceability query result to the user, and store the query permission, the query condition, the query result, and the query timestamp into the traceability chain.

[0037] The data traceability query method and device based on blockchain provided by the present invention. The data traceability query method based on blockchain, based on the received traceability query request of the user, first obtains the query permission and query conditions of the user, and based on the query permission and query conditions, searches the traceability storage data already stored in the memory, so as to obtain the query result and the query timestamp. Since the traceability storage data includes the data stored after reconstructing the transaction data in the transaction chain with an adjacency list and a mapping graph respectively, therefore, by searching the traceability storage data in the memory for the traceability query process, not only can the traceability query time be greatly saved, but also the high efficiency and high accuracy of the traceability query can be ensured; further, when the query result is fed back to the user, the query permission, query conditions, query result and query timestamp for the user's current traceability query request are stored in the traceability chain. In this way, by combining the storage of transaction data with dependency relationships in the transaction chain and the traceability storage data stored in the traceability chain, the purpose of facilitating subsequent security audits and transaction data management can be achieved, and the security and efficiency of the traceability query can also be improved, thereby being able to flexibly meet various traceability requirements. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0039] Figure 1 is a schematic flowchart of the data traceability query method based on blockchain provided by the present invention;

[0040] Figure 2 is a schematic structural diagram of the traceability directed graph provided by the present invention;

[0041] Figure 3 is a schematic structural diagram of the traceability adjacency list provided by the present invention;

[0042] Figure 4 is a schematic structural diagram of the traceability mapping table provided by the present invention;

[0043] Figure 5 is a schematic structural diagram of the data traceability query device based on blockchain provided by the present invention;

[0044] Figure 6 is a schematic structural diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0045] To make the objectives, technical solutions, and advantages of the present invention clearer, the technical solutions in the present invention will be clearly and completely described below with reference to the accompanying drawings in the present invention. Apparently, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present invention without creative efforts shall fall within the protection scope of the present invention.

[0046] The following combines Figures 1 - 6 to describe the blockchain-based data traceability query method and device of the present invention. Among them, the execution subject of the blockchain-based data traceability query method can be any one of all full nodes on the blockchain. The full node can be other electronic devices such as a personal computer (PC), a portable device, a laptop computer, a smart phone, a tablet computer, and a portable wearable device, or can be a server or a server cluster composed of multiple servers, a cloud computing center, etc. The present invention does not limit the specific form of the full node.

[0047] It should be noted that the execution subject of the following method embodiments can be part or all of the above full nodes. The following method embodiments are described by taking the execution subject as a full node as an example, and the full node is any one of all full nodes on the blockchain.

[0048] Figure 1 is a schematic flowchart of the blockchain-based data traceability query method provided by the present invention. As Figure 1 shown, the blockchain-based data traceability query method includes the following steps:

[0049] Step 110: Based on the user's traceability query request, obtain the user's query permission and query conditions.

[0050] Specifically, when the full node is running normally, it can receive the user's traceability query request, obtain the user's query permission and query conditions. The query permission can be obtained after authorization is applied through unique identifiers or information referring to the user's identity such as the account, personal identity document number (Identity document, id) entered by the user. The query conditions can be extracted based on the traceability query requirements input by the user. For example, the traceability query requirements input by the user can be the data id or data hash value required for traceability query, or can be specific data such as the data type or data range required for traceability query to limit the query range.

[0051] Step 120: According to the query permission and the query conditions, search the traceability storage data in the memory to obtain a query result and a query timestamp.

[0052] Among them, the traceability storage data includes the data stored after reconstructing the transaction data in the transaction chain with an adjacency list and a mapping graph respectively.

[0053] Specifically, the data reconstructed from the transaction data with dependency relationships in the transaction chain are pre-stored in the memory of the full node with an adjacency list and a mapping graph respectively. Therefore, it is possible to directly search based on the user's query permission and query conditions, and quickly search for query results that match the query permission and query conditions. The query timestamp can be directly displayed when the query result is found and is used to represent the time of the query result. The query result is the result that meets the scope of the user's query permission.

[0054] Step 130: Feed back the traceability query result to the user, and store the query permission, the query conditions, the query result, and the query timestamp into the traceability chain.

[0055] Specifically, when the full node obtains a query result that matches the user's query permission and query conditions after searching the traceability storage data in its memory, it can feed back the query result to the user. At the same time, it can also form a traceability query record for the user's current traceability query request, including the query permission, the query conditions, the query result, and the query timestamp, and store it into the traceability chain, so as to ensure that all traceability queries can be recorded and ensure the security of traceability queries.

[0056] The data traceability query method based on blockchain provided by the present invention, based on the received user's traceability query request, first obtains the user's query permission and query conditions, and searches the traceability storage data already stored in the memory based on the query permission and query conditions, so as to obtain the query result and the query timestamp. Since the traceability storage data includes the data stored after reconstructing the transaction data in the transaction chain with an adjacency list and a mapping graph respectively, the traceability query process by searching the traceability storage data in the memory not only greatly saves the traceability query time, but also ensures the high efficiency and high accuracy of the traceability query; further, when feeding back the query result to the user, the query permission, the query conditions, the query result, and the query timestamp for the user's current traceability query request are stored into the traceability chain. In this way, by combining the storage of transaction data with dependency relationships in the transaction chain and the traceability storage data stored in the traceability chain, it can not only achieve the purpose of facilitating subsequent security audits and transaction data management, but also improve the security and efficiency of traceability queries, and thus can flexibly meet various traceability requirements.

[0057] Optionally, before step 110, the method may further include:

[0058] First, a directed acyclic graph is used to reconstruct the transaction data in the transaction chain to obtain a traceability directed graph; wherein, the traceability directed graph includes a reverse traceability directed graph and a forward traceability directed graph; secondly, an adjacency list is used to reconstruct the traceability directed graph into a traceability adjacency list; then, a mapping graph is used to reconstruct the relationship between the vertices of the traceability adjacency list and the numbers of the vertices into a traceability mapping table; finally, the traceability adjacency list and the traceability mapping table are determined as traceability storage data, and the traceability storage data is stored in the memory.

[0059] Specifically, the transaction data with dependency relationships in the transaction chain is first reconstructed into a traceability directed graph using a directed acyclic graph, as Figure 2 shown. The traceability directed graph includes Figure 2 the reverse traceability directed graph shown in (a) in Figure 2 and the forward traceability directed graph shown in (b) in Figure 3 . Then, an adjacency list is used to reconstruct the traceability directed graph into a traceability adjacency list, and the traceability adjacency list is stored in the memory using a preset data structure. The preset data structure can at least satisfy the push function and the function of expandable data structure length. The push function can add new data to the end of the array and return the new length, and can change the length of the array. For example, when the preset data structure is a two-dimensional vector data structure in the C++ language, the Figure 4 reverse traceability directed graph shown in (a) and the forward traceability directed graph shown in (b) in

[0060] can be correspondingly reconstructed into the reverse traceability adjacency list shown in (a) and the forward traceability adjacency list shown in (b) in Figure 2 . In addition, a mapping graph can be used to establish a one-to-one correspondence between the numbers of the vertices of the traceability adjacency list and the vertices, and between the vertices of the traceability adjacency list and the numbers of the vertices. The numbers start incrementing from 0. The obtained traceability mapping table includes the correspondence between the numbers of the vertices of the traceability adjacency list and the vertices shown in (a) in 1 ,v 1 ,(3,e 2 ,v 1 ),1→{(4,e 3 ,v 2 Figure 4 and the correspondence between the vertices of the traceability adjacency list and the numbers of the vertices shown in (b). Then, the traceability adjacency list and the traceability mapping table are further stored in the memory as traceability storage data. At this time, the correspondence between the numbers of the vertices of the traceability adjacency list and the vertices, and the correspondence between the vertices of the traceability adjacency list and the numbers of the vertices are both corresponding to the reverse traceability adjacency list and the forward traceability adjacency list, facilitating subsequent direct access to the memory for traceability query.

[0060] It should be noted that, as Figure 2 shown, the traceability adjacency list is an adjacency list with the blockchain block number as a version mark and is expressed as {0→{(1,e 1 ,v 1 ,(3,e 2 ,v 1 )},1→{(4,e 3 ,v 2)},...} where 0, 1, 2,... represent different numbers of vertices in the traceability adjacency list; e 1 , e 2 , e 3 ,... represent different edges in the traceability adjacency list, that is, the transaction relationships between vertices, which can be in the form of numerical values, text, etc.; v 1 , v 2 ,... represent the heights or versions of different blocks, v 1 represents the first block, v 2 represents the second block, and so on with the numbering increasing; 0 → {(1, e 1 , v 1 )} means that the transaction data pointing from vertex 0 in the traceability adjacency list to vertex 1 with edge e 1 appears in the first block v 1 . For example, when user A is vertex 0, user B is vertex 1, and e 1 represents that user A transfers 50 yuan to user B, 0 → {(1, e 1 , v 1 )} can represent that the transaction data of user A transferring 50 yuan to user B is recorded in the first block v 1 .

[0061] In addition, the corresponding relationship between the vertices of the traceability adjacency list and the numbers of the vertices can be expressed as {(hash 1 , (num 1 , v 0 )), ((hash 2 , (num 2 , v 0 )), ((hash 3 , (num 3 , v 0 )),...} relationship, and the corresponding relationship between the numbers of the vertices of the traceability adjacency list and the vertices can be expressed as {(num 1 , (hash 1 , v 0 )), (num 2 , (hash 2 , v 0 )), (num 3 , (hash 3 , v 0 )),...} relationship. As Figure 4 shown, hash 1 , hash 2 ,... represent the vertices in the traceability adjacency list with different hash values, num 1 , num 2 , num 3, … represents the numbers corresponding to the vertices in the traceability adjacency list. Each vertex corresponds to a unique number, and each number also corresponds to a unique vertex. The numbers increase incrementally starting from 1. When a new vertex is added to the traceability adjacency list, the number is incremented by 1. In particular, Figure 4 the numbers in Figure 3 correspond to the subscripts of the preset data structure that stores the traceability adjacency list.

[0062] The data traceability query method based on blockchain provided by the present invention obtains a traceability directed graph by reconstructing the transaction data in the transaction chain using a directed acyclic graph, reconstructs the traceability directed graph into a traceability adjacency list using an adjacency list, and reconstructs the relationship between the vertices of the traceability adjacency list and the numbers of the vertices into a traceability mapping table using a mapping graph. Then, the traceability adjacency list and the traceability mapping table are stored in memory as traceability storage data, so that when a full node in normal operation receives a traceability query request from a user, it can quickly and accurately execute the traceability query by directly and quickly accessing the traceability storage data in memory, thereby improving the efficiency and accuracy of the traceability query.

[0063] Optionally, after performing the step of storing the traceability storage data in memory, the method may further include:

[0064] Storing the traceability adjacency list and the traceability mapping table in the form of files on the local hard disk, and storing the hash value of the files on the local hard disk in the traceability chain.

[0065] Among them, the files on the local hard disk include the traceability adjacency list (including the reverse traceability adjacency list and the forward traceability adjacency list) file, the file of the correspondence between the numbers and vertices of the traceability adjacency list, and the file of the correspondence between the vertices and numbers of the traceability adjacency list.

[0066] Specifically, after storing the traceability storage data containing the traceability adjacency list and the traceability mapping table in memory, a smart contract can also be used to represent the traceability adjacency list and the traceability mapping table as adjacency list-related files in the form of files, then store the adjacency list-related files on the local hard disk, and store the hash value of the adjacency list-related files on the local hard disk in the traceability chain. Based on this, it can be known that in addition to storing query permissions, query conditions, query results, and query timestamps, the traceability chain can also store the hash value of the adjacency list-related files on the local hard disk.

[0067] The data traceability query method based on blockchain provided by the present invention not only improves the functional diversity of the traceability chain by storing the traceability adjacency list and the traceability mapping table in the form of files on the local hard disk and storing the hash value of the files on the local hard disk in the traceability chain, but also facilitates the subsequent verification of the authenticity of the files on the local hard disk.

[0068] Optionally, before step 110, the method may further include:

[0069] Based on the restart instruction, check whether the hash value of the file in the local hard disk is consistent with the hash value on the traceability chain; if the hash value of the file in the local hard disk is consistent with the hash value on the traceability chain, load the traceability adjacency list and traceability mapping table in the local hard disk into the memory, and execute the step of obtaining the query permission and query conditions of the user based on the traceability query request of the user.

[0070] Specifically, considering that when a full node has abnormal situations such as power failure or failure resulting in stopping running or shutting down, the full node will be restarted after handling the abnormal situation. After the full node receives the restart instruction and restarts, it can first check whether the hash value of the file in the local hard disk is consistent with the hash value on the traceability chain. When it is determined that the hash value of the file in the local hard disk is consistent with the hash value on the traceability chain, load the traceability adjacency list and traceability mapping table in the local hard disk into the memory, and based on the synchronization mechanism contained in the blockchain itself, perform a synchronization operation on the restarted full node to make the version of the current full node consistent with the versions of other full nodes in the normal state, so as to facilitate subsequent execution of the corresponding traceability query operation when receiving the traceability query request. Among them, the restart instruction can be generated based on manually touching the power-on button, or can be automatically generated when the abnormal fault is processed, and no specific limitation is made here.

[0071] It should be noted that usually there are many full nodes on the blockchain. When one of the full nodes shuts down due to a fault for a period of time and then restarts, even if it passes the data verification, it only means that the stored data before the power failure is okay, and does not include the data of the newly added blocks during the disconnection process, that is, it cannot ensure that the current version is consistent with the latest versions of other full nodes. Therefore, the synchronization mechanism provided by the blockchain can be used for synchronization operations to make the versions of all full nodes on the entire blockchain consistent.

[0072] For the data traceability query method provided by the present invention, in response to the restart instruction of the full node, when it is checked that the hash value of the file in the local hard disk is consistent with the hash value on the traceability chain, by loading the traceability adjacency list and traceability mapping table in the local hard disk into the memory, the subsequent operation of normally receiving the traceability query request and executing the traceability query is realized, thereby ensuring the efficiency of the traceability query and saving time.

[0073] Optionally, when checking whether the hash value of the file in the local hard disk is consistent with the hash value on the traceability chain, the method may further include:

[0074] If the hash value of the file in the local hard disk is inconsistent with the hash value on the traceability chain, update the file in the local hard disk.

[0075] Specifically, when it is determined that the hash value of a file in the local hard disk is inconsistent with the hash value on the traceability chain, it can be considered that the hash value of a certain block in the local hard disk is inconsistent with the hash value of the corresponding block on the blockchain. At this time, the transaction data before this block is correct and has not been changed, and the transaction data after this block has changed, and it is not clear which data change has caused the hash value inconsistency. Considering that the transaction content on the transaction chain will not change, it is possible to find the changed data from the transaction chain, that is, the transaction data of all blocks after this block can be used to update the traceability adjacency list and the traceability mapping table in the local hard disk until it is consistent with the hash value on the traceability chain.

[0076] For the data traceability query method based on blockchain provided by the present invention, when checking whether the hash value of a file in the local hard disk is consistent with the hash value on the traceability chain, if it is determined that the hash value of the file in the local hard disk is inconsistent with the hash value on the traceability chain, by updating the file in the local hard disk, the file in the local hard disk is made to reach the latest version and be consistent with the hash value on the traceability chain, thereby ensuring the security and efficiency of subsequent traceability queries.

[0077] Optionally, before step 110, the method may further include:

[0078] Based on the received new block, update the traceability storage data in the memory, and update the file in the local hard disk, and store the hash value of the updated file into the traceability chain, and then execute the step of obtaining the query permission and query conditions of the user based on the traceability query request of the user.

[0079] Specifically, when a full node receives a new block, it can first update the traceability storage data based on the dependency relationship of the transaction data in the newly received block, that is, add the transaction data of the new block to the current traceability adjacency list of the traceability storage data in the form of an adjacency list of a directed acyclic graph, so as to update the traceability adjacency list, and based on the updated traceability adjacency list, update the traceability mapping table accordingly, thereby realizing the update of the traceability storage data.

[0080] Then, store the updated traceability adjacency list and the updated traceability mapping table in the local hard disk in the form of a file, so as to realize the update of the file in the local hard disk, and store the hash value of the updated file into the traceability chain, so as to facilitate the execution of the corresponding traceability query operation when receiving a traceability query request subsequently.

[0081] The data traceability query method based on blockchain provided by the present invention updates the traceability storage data in the memory and the files in the local hard disk for the new block received by the full node, and stores the hash value of the updated file into the traceability chain, so as to realize that every time a new block is received on the blockchain, the traceability storage data in the memory, the files in the local hard disk and the hash value on the traceability chain can be updated in a timely and rapid manner, thereby ensuring the reliable stability and accurate efficiency of the traceability query.

[0082] Optionally, the process of updating the file in the local hard disk includes:

[0083] For the j-th file in the local hard disk, query that the latest block number included in the j-th file is t, and determine that the current latest version of the j-th file is j t , and determine whether the hash value of the j-th file stored on the traceability chain at version j t is consistent with the hash value of the j-th file in the local hard disk at version j t ; if the hash value of the j-th file stored on the traceability chain at version j t is consistent with the hash value of the j-th file in the local hard disk at version j t , then reconstruct the j-th file in the local hard disk based on the blocks in the transaction chain with numbers greater than t; if the hash value of the j-th file stored on the traceability chain at version j t is inconsistent with the hash value of the j-th file in the local hard disk at version j t , then determine whether the hash value of the j-th file stored on the traceability chain at version j t-1 is consistent with the hash value of the j-th file in the local hard disk at version j t-1 ; until the hash value of the j-th file stored on the traceability chain at version j t-x is consistent with the hash value of the j-th file in the local hard disk at version j t-x ; then reconstruct the j-th file in the local hard disk based on the blocks in the transaction chain with numbers greater than t - x; where t, x, and j are all positive integers, and j is a file in the local hard disk.

[0084] Specifically, for the update of files in the local hard disk, the present invention adopts the rollback method for updating. It is set that the files in the local hard disk include four files: the forward traceability adjacency list file, the reverse traceability adjacency list file, the file of the numbers of the vertices of the traceability adjacency list and the vertex correspondence, and the file of the correspondence between the vertices and the numbers of the vertices of the traceability adjacency list. Let j be one of the four files in the local hard disk. First, find that the maximum version number in the files stored by the full node is t, and t corresponds to the block number in the transaction chain. Therefore, it also means that the full node currently contains at most the transaction data before block t. Then, compare the hash values of the four files stored by the full node with the hash values of the corresponding files on the traceability chain at the latest version in turn. That is, for the j-th file in the local hard disk, query that the latest block number contained in the j-th file is t, and determine that the current latest version of the j-th file is j t , and then judge whether the hash value of the j-th file stored on the traceability chain at version j t is the same as the hash value of the j-th file in the local hard disk at version j t . If the hash value of the j-th file stored on the traceability chain at version j t is the same as the hash value of the j-th file in the local hard disk at version j t , then reconstruct the j-th file in the local hard disk based on the blocks in the transaction chain with numbers greater than, and directly load the j-th file into the memory of the full node; otherwise, if the hash value of the j-th file stored on the traceability chain at version j t is not the same as the hash value of the j-th file in the local hard disk at version j t , then update the j-th file to be the same as the corresponding file on the traceability chain at version j t and then load it into the memory, that is, delete the content with the j t version mark in the j-th file, make the j-th file roll back to version t - 1, and then judge whether the hash value of the j-th file stored on the traceability chain at version t - 1 is the same as the hash value of the j-th file in the local hard disk at version t - 1. If the hash value of the j-th file stored on the traceability chain at version t - 1 is still not the same as the hash value of the j-th file in the local hard disk at version t - 1, then make the j-th file roll back to version v t-2 . And so on, until the hash value of the j-th file stored on the traceability chain at version t - x is the same as the hash value of the j-th file in the local hard disk at version t - x. Finally, reconstruct the j-th file in the local hard disk based on the blocks with numbers greater than t - x. In this way, the update of each file in the local hard disk is realized. Among them, 0 ≤ t - x ≤ m, 0 ≤ x ≤ t, t, x, and j are all positive integers, j = 1, 2, 3, 4, and m is the number of the highest or latest block in the blockchain.

[0085] It should be noted that the hash value verification, the storage and update of the traceability storage data in the memory, the storage and update of the files in the local hard disk, the operation of uploading the transaction data to the blockchain, etc. in the present invention are all automatically completed by the smart contract deployed on the blockchain.

[0086] The data traceability query method based on the blockchain provided by the present invention determines whether the hash value of the file in the local hard disk at the current latest version is consistent with the hash value of the corresponding file on the traceability chain at the latest version, and when the determination is inconsistent, the version of the file is rolled back and the hash value comparison is performed again until the comparison result is consistent. In this way, the purpose of quickly and timely updating the files in the local hard disk and the traceability storage data in the memory when the full node restarts or receives a new block is achieved, thereby ensuring the accurate reliability and flexible effectiveness of the traceability query when the full node is running normally.

[0087] Optionally, the implementation process of step 120 may include:

[0088] When the traceability storage data in the memory includes a traceability adjacency list and a traceability mapping table representing the dependency relationship between transaction data in the transaction chain, according to the query permission and the query condition, perform a breadth-first search on the traceability storage data in the memory to obtain a query result and a query time.

[0089] Specifically, when the traceability storage data in the memory includes a traceability adjacency list representing the dependency relationship between transaction data in the transaction chain, it can be exemplified as Figure 3 The reverse traceability adjacency list and the forward traceability adjacency list shown, where the vertices are represented by hash values and refer to user addresses, processed data, etc., and the edges can represent the relationship between the vertices and the relationship can be transfer, processing, operation, etc. Using Figure 3 When performing reverse traceability on the vertex with the given hash value of hash 6 using the reverse traceability adjacency list shown in (a) of 6 , the query result represented in triple form is {(hash 3 , hash 5 , e 6 ), (hash 4 , hash 6 , e 3 ), (hash 0 , hash 2 ), (hash 4 , hash 1 , e 3 )}, and when performing forward traceability on the vertex with the given hash value of hash Figure 3 using the forward traceability adjacency list shown in (b) of 0 , the query result of the forward traceability is obtained and can be represented as {(hash0 , hash 2 , e 1 ), (hash 0 , hash 3 , e 2 ), (hash 2 , hash 5 , e 4 ), (hash 3 , hash 6 , e 5 )}。

[0090] When the traceability mapping table is the vertex number and vertex correspondence of the traceability adjacency list as shown in Figure 4 and the vertex and vertex number correspondence of the traceability adjacency list, Figure 3 it stores the reverse traceability adjacency list and forward traceability adjacency list formed by the reverse traceability digraph and forward traceability digraph in a preset data structure, Figure 2 as shown in Figure 4 It is a one-to-one mapping of vertices in the dependency relationship of the reverse traceability adjacency list and forward traceability adjacency list as shown in Figure 3 and maps the hash value to a digital number, and the digital number corresponds to the subscript of the traceability adjacency list as shown in Figure 3 to facilitate access to the vertices in the traceability adjacency list. For example, when performing a traceability query on the vertex with the input of hash Figure 3 in the reverse traceability adjacency list shown in (a) of 6 , the process can be described as follows: First, find the vertex number corresponding to hash Figure 4 in the vertex and vertex number correspondence of the traceability adjacency list shown in (b) of 6 is 6; then find the successor nodes of 6 in the reverse traceability adjacency list shown in (a) of Figure 3 which are 3 and 4, and output them in the form of a triple as {(6, 3, e 5 ), (6, 4, e 6 )}; then find the successor nodes of nodes 3 and 4 and output them in the form of a triple as {(3, 0, e 2 ), (4, 1, e 3 )}; thus obtaining the total query result of hash 6 as {(6, 3, e 5 ), (6, 4, e 6 ), (3, 0, e 2 ), (4, 1, e 3 )}; finally, based on the vertex number and vertex correspondence of the traceability adjacency list shown in (a) of Figure 4 , the query result of hash 6 can be obtained as {(hash6 , hash 3 , e 5 ), (hash 6 , hash 4 , e 6 ), (hash 3 , hash 0 , e 2 ), (hash 4 , hash 1 , e 3 )}, and while displaying the query result, feedback the query timestamp for obtaining the query result.

[0091] For the data traceability query method based on blockchain provided by the present invention, when the traceability storage data in the memory includes a traceability adjacency list and a traceability mapping table representing the dependency relationship between transaction data in the transaction chain, by performing a breadth-first search on the traceability storage data, the query result and the query time can be quickly obtained, thereby improving the efficiency and reliability of the traceability query.

[0092] Optionally, the specific implementation process of step 110 may include:

[0093] Based on the user's traceability query request, obtain the user's query permission from the traceability chain; obtain the query condition input by the user from the traceability query request.

[0094] Specifically, in the traceability chain of the present invention, the traceability query permission information corresponding to each user within the scope of the blockchain may be stored. Therefore, the query permission for the corresponding query scope can be obtained from the traceability chain through the personal identity information input by the user. Based on this, when the full node receives the user's traceability query request, the query permission of the user can be obtained from the traceability chain. For example, an authorization application is made based on personal identity information such as the user's input account and password, and when the application is approved, the query permission corresponding to the user's query scope will be feedback. And the full node can extract the query condition input by the user from the traceability query request. For example, a traceability query request is generated based on the query condition and personal identity information input by the user. The query condition may be the data id or data hash value of the data to be traced, or specific data such as the data type or data range for limiting the query scope. Therefore, the query condition input by the user can be extracted from the traceability query request.

[0095] For the data traceability query method based on blockchain provided by the present invention, by obtaining the user's query permission from the traceability chain and extracting the query condition input by the user based on the user's traceability query request, the security and reliability of the traceability query are ensured.

[0096] The data traceability query device based on blockchain provided by the present invention will be described below. The data traceability query device based on blockchain described below can be correspondingly referred to the data traceability query method based on blockchain described above.

[0097] Figure 5 An example of a data traceability query device based on blockchain is as Figure 5 shown. The data traceability query device 500 based on blockchain includes:

[0098] An acquisition module 510, configured to obtain the query permission and query conditions of the user based on the traceability query request of the user; a query module 520, configured to search the traceability storage data in the memory according to the query permission and the query conditions to obtain a query result and a query timestamp; wherein, the traceability storage data includes the data stored after reconstructing the transaction data in the transaction chain with an adjacency list and a mapping graph respectively; a processing module 530, configured to feedback the traceability query result to the user, and store the query permission, the query conditions, the query result and the query timestamp into the traceability chain.

[0099] Optionally, the device may further include a reconstruction module, configured to reconstruct the transaction data in the transaction chain with a directed acyclic graph to obtain a traceability directed graph; wherein, the traceability directed graph includes a reverse traceability directed graph and a forward traceability directed graph; use an adjacency list to reconstruct the traceability directed graph into a traceability adjacency list; use a mapping graph to reconstruct the relationship between the vertices of the traceability adjacency list and the numbers of the vertices into a traceability mapping table; determine the traceability adjacency list and the traceability mapping table as traceability storage data, and store the traceability storage data into the memory.

[0100] Optionally, the device may further include a storage module, configured to store the traceability adjacency list and the traceability mapping table in the form of files in a local hard disk, and store the hash value of the files in the local hard disk into the traceability chain.

[0101] Optionally, the device may further include a verification module, configured to verify whether the hash value of the files in the local hard disk is consistent with the hash value on the traceability chain based on a restart instruction; if the hash value of the files in the local hard disk is consistent with the hash value on the traceability chain, load the traceability adjacency list and the traceability mapping table in the local hard disk into the memory, and execute the step of obtaining the query permission and query conditions of the user based on the traceability query request of the user.

[0102] Optionally, the verification module may further be configured to update the files in the local hard disk if the hash value of the files in the local hard disk is inconsistent with the hash value on the traceability chain.

[0103] Optionally, the device may further include an update module, configured to update the traceability storage data in the memory based on the received new block, update the files in the local hard disk, store the hash value of the updated file into the traceability chain, and then execute the steps of obtaining the query permission and query conditions of the user based on the traceability query request of the user.

[0104] Optionally, the update module may further be configured to, for the j-th file in the local hard disk, query that the latest block number included in the j-th file is t, determine that the current latest version of the j-th file is j t , and determine whether the hash value of the j-th file stored on the traceability chain at version j t is consistent with the hash value of the j-th file in the local hard disk at version j t ;

[0105] If the hash value of the j-th file stored on the traceability chain at version j t is consistent with the hash value of the j-th file in the local hard disk at version j t , reconstruct the j-th file in the local hard disk based on the blocks in the transaction chain with block numbers greater than t;

[0106] If the hash value of the j-th file stored on the traceability chain at version j t is inconsistent with the hash value of the j-th file in the local hard disk at version j t , determine whether the hash value of the j-th file stored on the traceability chain at version j t-1 is consistent with the hash value of the j-th file in the local hard disk at version j t-1 ;

[0107] Until the hash value of the j-th file stored on the traceability chain at version j t-x is consistent with the hash value of the j-th file in the local hard disk at version j t-x ; then reconstruct the j-th file in the local hard disk based on the blocks in the transaction chain with block numbers greater than t - x; where t, x, and j are all positive integers, and j is a file in the local hard disk.

[0108] Optionally, the query module 520 may specifically be configured to, when the traceability storage data in the memory includes a traceability adjacency list and a traceability mapping table representing the dependency relationship between transaction data in the transaction chain, perform a breadth-first search on the traceability storage data in the memory according to the query permission and the query conditions to obtain a query result and a query time.

[0109] Optionally, the obtaining module 510 can be specifically configured to obtain the query permission of the user from the traceability chain based on the user's traceability query request; and obtain the query condition input by the user from the traceability query request.

[0110] Figure 6 FIG. illustrates a schematic physical structure diagram of an electronic device, as Figure 6 shown. The electronic device 600 may include: a processor 610, a communications interface 620, a memory 630, and a communication bus 640. Among them, the processor 610, the communications interface 620, and the memory 630 communicate with each other through the communication bus 640. The processor 610 may call the logical instructions in the memory 630 to execute a data traceability query method based on a blockchain. The method includes:

[0111] Based on the user's traceability query request, obtain the query permission and query condition of the user;

[0112] According to the query permission and the query condition, search the traceability storage data in the memory to obtain a query result and a query timestamp; wherein, the traceability storage data includes the data stored after reconstructing the transaction data in the transaction chain with an adjacency list and a mapping graph respectively;

[0113] Feed back the traceability query result to the user, and store the query permission, the query condition, the query result, and the query timestamp into the traceability chain.

[0114] In addition, when the logical instructions in the above-mentioned memory 630 are implemented in the form of software functional units and sold or used as an independent product, they can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention. The foregoing storage medium includes: various media such as a USB flash drive, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk, or an optical disc that can store program codes.

[0115] On the other hand, the present invention also provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the blockchain-based data traceability query method provided by the above-mentioned various methods. The method includes:

[0116] Based on the user's traceability query request, obtain the user's query permission and query conditions;

[0117] According to the query permission and the query conditions, search the traceability storage data in the memory to obtain a query result and a query timestamp; wherein, the traceability storage data includes the data stored after reconstructing the transaction data in the transaction chain with an adjacency list and a mapping graph respectively;

[0118] Feed back the traceability query result to the user, and store the query permission, the query conditions, the query result and the query timestamp into the traceability chain.

[0119] In yet another aspect, the present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it implements the blockchain-based data traceability query method provided by the above-mentioned various methods. The method includes:

[0120] Based on the user's traceability query request, obtain the user's query permission and query conditions;

[0121] According to the query permission and the query conditions, search the traceability storage data in the memory to obtain a query result and a query timestamp; wherein, the traceability storage data includes the data stored after reconstructing the transaction data in the transaction chain with an adjacency list and a mapping graph respectively;

[0122] Feed back the traceability query result to the user, and store the query permission, the query conditions, the query result and the query timestamp into the traceability chain.

[0123] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art can understand and implement it without creative labor.

[0124] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on such an understanding, the essence of the above technical solution, or the part that contributes to the prior art, can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0125] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements for some of the technical features. These modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A data traceability query method based on blockchain, characterized in that, it includes: Based on the user's traceability query request, obtain the user's query permission and query conditions; According to the query permission and the query conditions, search the traceability storage data in the memory to obtain a query result and a query timestamp; wherein, the traceability storage data includes data stored after reconstructing the transaction data in the transaction chain with an adjacency list and a mapping graph respectively; Feed back the traceability query result to the user, and store the query permission, the query conditions, the query result and the query timestamp into the traceability chain; Wherein, before the step of obtaining the user's query permission and query conditions from the traceability chain based on the user's traceability query request, the method further includes: Adopt a directed acyclic graph to reconstruct the transaction data in the transaction chain to obtain a traceability directed graph; wherein, the traceability directed graph includes a reverse traceability directed graph and a forward traceability directed graph; Adopt an adjacency list to reconstruct the traceability directed graph into a traceability adjacency list; Adopt a mapping graph to reconstruct the relationship between the vertices of the traceability adjacency list and the numbers of the vertices into a traceability mapping table; Determine the traceability adjacency list and the traceability mapping table as traceability storage data, and store the traceability storage data into the memory; After the step of storing the traceability storage data into the memory, the method further includes: Store the traceability adjacency list and the traceability mapping table in the form of files on the local hard disk, and store the hash value of the files on the local hard disk into the traceability chain.

2. The data traceability query method based on blockchain according to claim 1, characterized in that, before the step of obtaining the user's query permission and query conditions based on the user's traceability query request, the method further includes: Based on a restart instruction, check whether the hash value of the file on the local hard disk is consistent with the hash value on the traceability chain; If the hash value of the file on the local hard disk is consistent with the hash value on the traceability chain, load the traceability adjacency list and the traceability mapping table on the local hard disk into the memory, and execute the step of obtaining the user's query permission and query conditions based on the user's traceability query request.

3. The data traceability query method based on blockchain according to claim 2, characterized in that, the method further includes: If the hash value of the file on the local hard disk is inconsistent with the hash value on the traceability chain, update the file on the local hard disk.

4. The data traceability query method based on blockchain according to claim 1, characterized in that, before the step of obtaining the user's query permission and query conditions based on the user's traceability query request, the method further includes: Based on the received new block, update the traceability storage data in the memory, and update the file on the local hard disk, and store the hash value of the updated file into the traceability chain, and then execute the step of obtaining the user's query permission and query conditions based on the user's traceability query request.

5. The data traceability query method based on blockchain according to claim 3 or 4, It is characterized in that The process of updating the files in the local hard disk includes: For the j-th file in the local hard disk, query that the latest block number contained in the j-th file is t, and determine that the current latest version of the j-th file is j t , and determine whether the hash value of the j-th file stored on the traceability chain at version j t is the same as the hash value of the j-th file in the local hard disk at version j t ; If the hash value of the j-th file stored on the traceability chain at version j t is the same as the hash value of the j-th file in the local hard disk at version j t then reconstruct the j-th file in the local hard disk based on the blocks in the transaction chain with numbers greater than t; If the hash value of the j-th file stored on the traceability chain at version j t is inconsistent with the hash value of the j-th file in the local hard disk at version j t , it is determined whether the hash value of the j-th file stored on the traceability chain at version j t-1 is consistent with the hash value of the j-th file in the local hard disk at version j t-1 ; until the hash value of the j-th file stored on the traceability chain at the j t-x -th version is the same as the hash value of the j-th file in the local hard disk at the j t-x -th version; then reconstruct the j-th file in the local hard disk based on the blocks in the transaction chain with numbers greater than t - x; where t, x, and j are all positive integers, and j is a file in the local hard disk.

6. The method for querying data traceability based on blockchain according to claim 1, It is characterized in that The step of searching the traceability storage data in the memory according to the query permission and the query condition to obtain a query result and a query time includes: When the traceability storage data in the memory includes a traceability adjacency list and a traceability mapping table representing the dependency relationship between transaction data in the transaction chain, perform a breadth-first search on the traceability storage data in the memory according to the query permission and the query condition to obtain a query result and a query time.

7. The method for querying data traceability based on blockchain according to claim 1, It is characterized in that The step of obtaining the query permission and query condition of the user based on the traceability query request of the user includes: Based on the traceability query request of the user, obtain the query permission of the user from the traceability chain; Obtain the query condition input by the user from the traceability query request.

8. A data traceability query device based on blockchain, It is characterized in that It includes: An acquisition module for obtaining the query permission and query condition of the user based on the traceability query request of the user; A query module for searching the traceability storage data in the memory according to the query permission and the query condition to obtain a query result and a query timestamp; wherein, the traceability storage data includes data stored after reconstructing the transaction data in the transaction chain with an adjacency list and a mapping graph respectively; A processing module for feeding back the traceability query result to the user and storing the query permission, the query condition, the query result and the query timestamp into the traceability chain; The data traceability query device based on blockchain further includes a reconstruction module for reconstructing the transaction data in the transaction chain with a directed acyclic graph to obtain a traceability directed graph before the step of obtaining the query permission and query condition of the user from the traceability chain based on the traceability query request of the user; wherein, the traceability directed graph includes a reverse traceability directed graph and a forward traceability directed graph; reconstruct the traceability directed graph into a traceability adjacency list with an adjacency list; reconstruct the relationship between the vertices of the traceability adjacency list and the numbers of the vertices into a traceability mapping table with a mapping graph; determine the traceability adjacency list and the traceability mapping table as traceability storage data and store the traceability storage data into the memory; The data traceability query device based on blockchain further includes a storage module for storing the traceability adjacency list and the traceability mapping table in the form of files in the local hard disk and storing the hash value of the files in the local hard disk into the traceability chain after the step of storing the traceability storage data into the memory.

Citation Information

Patent Citations

  • Data query method and device and computer readable storage medium

    CN112905595A

  • Query method and device under non-whole-network consensus block chain and storage medium

    CN113901144A