CN112765181A - Data tracing query method based on block index structure - Google Patents

Data tracing query method based on block index structure Download PDF

Info

Publication number
CN112765181A
CN112765181A CN202110109990.2A CN202110109990A CN112765181A CN 112765181 A CN112765181 A CN 112765181A CN 202110109990 A CN202110109990 A CN 202110109990A CN 112765181 A CN112765181 A CN 112765181A
Authority
CN
China
Prior art keywords
block
node
transaction
data
tracing
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202110109990.2A
Other languages
Chinese (zh)
Other versions
CN112765181B (en
Inventor
宋杰
那美玉
张彭奕
郭朝鹏
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Northeastern University China
Original Assignee
Northeastern University China
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Northeastern University China filed Critical Northeastern University China
Priority to CN202110109990.2A priority Critical patent/CN112765181B/en
Publication of CN112765181A publication Critical patent/CN112765181A/en
Application granted granted Critical
Publication of CN112765181B publication Critical patent/CN112765181B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2246Trees, e.g. B+trees
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2282Tablespace storage structures; Management thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2458Special types of queries, e.g. statistical queries, fuzzy queries or distributed queries
    • G06F16/2471Distributed queries
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • G06F21/62Protecting access to data via a platform, e.g. using keys or access control rules
    • G06F21/6218Protecting access to data via a platform, e.g. using keys or access control rules to a system of files or objects, e.g. local or distributed file system or database
    • G06F21/6245Protecting personal data, e.g. for financial or medical purposes
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • G06F21/64Protecting data integrity, e.g. using checksums, certificates or signatures
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/382Payment protocols; Details thereof insuring higher security of transaction
    • G06Q20/3827Use of message hashing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/382Payment protocols; Details thereof insuring higher security of transaction
    • G06Q20/3829Payment protocols; Details thereof insuring higher security of transaction involving key management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Business, Economics & Management (AREA)
  • Software Systems (AREA)
  • Computer Security & Cryptography (AREA)
  • Data Mining & Analysis (AREA)
  • Accounting & Taxation (AREA)
  • Health & Medical Sciences (AREA)
  • Bioethics (AREA)
  • General Health & Medical Sciences (AREA)
  • Computer Hardware Design (AREA)
  • Finance (AREA)
  • Strategic Management (AREA)
  • General Business, Economics & Management (AREA)
  • Fuzzy Systems (AREA)
  • Mathematical Physics (AREA)
  • Probability & Statistics with Applications (AREA)
  • Computational Linguistics (AREA)
  • Computing Systems (AREA)
  • Medical Informatics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention provides a data source tracing query method based on a block index structure, and relates to the technical field of block chains. The method improves the traceability query capability of the block chain by modifying a bottom data storage structure of the block chain, and specifically comprises four contents of block index structure definition, index creation, traceability query and index update; in order to realize the improvement of the block chain traceability query capability, an index structure is divided into two layers: firstly, external indexes of blocks are used for realizing skip among the blocks; and secondly, block internal indexing is adopted, and the transaction detail query capability of fine granularity in the block is improved. The index creation is to create an index for tracing the block chain, i.e. create a new block; tracing and querying: firstly, inquiring a cache table, then inquiring a temporary table, and then inquiring an MB + tree in the improved block chain to obtain a target inquiry result. The method accelerates the tracing process by improving the bottom storage structure of the block chain, so that the block chain can essentially support efficient tracing query.

Description

Data tracing query method based on block index structure
Technical Field
The invention relates to the technical field of block chains, in particular to a data source tracing query method based on a block index structure.
Background
In recent years, the traditional information traceability system has the problems of difficulty in information acquisition, non-uniform standard and structural centralization. Business logic implementations all rely on traditional databases, which become the limiting bottleneck for such schemes, and once it is tampered or destroyed, its impact is catastrophic, global. Aiming at the bottleneck of the scheme, the distributed storage structure of the block chain technology ensures the authenticity and the integrity of the information, so that all the information on the supply chain can be linked by using the block chain technology, and the problems in the information traceability system can be solved in a targeted manner. The existing information tracing system schemes are mainly divided into two types: firstly, by utilizing the traceability of a block chain, namely searching the block chain in a full disk, the information traceability system is well understood; secondly, the safety of the information traceability system is ensured by using the block chain, and the real traceability query of the block chain is realized by means of external technology, mainly by means of the internet of things (IoT) technology.
However, if the traceability of the blockchain itself is utilized, the traceability query performance of the traceability system is obviously poor. The traceability system with external devices entails the cost of purchasing and maintaining these devices, and in all these traceability systems, the blockchain itself is not used to support efficient traceability tracking queries.
Disclosure of Invention
The technical problem to be solved by the present invention is to provide a data tracing query method based on a block index structure, which enables a user to implement data tracing without using external devices based on the block index structure.
In order to solve the technical problems, the technical scheme adopted by the invention is as follows: a data source-tracing query method based on a block index structure stores transaction data in an MB + tree of a block chain, creates an index aiming at the block chain source-tracing, and comprises four parts of content including block index structure definition, index creation, source-tracing query and index update, and specifically comprises the following steps:
firstly, defining a block index structure as a double-layer index structure: the first layer is a block external index; the second layer is block internal index;
the block external index is realized by creating a temporary table, and a tracing object ID, a transaction ID of the last transaction data with the tracing object ID and a block number preBlockNum of the transaction data are stored in the temporary table; storing the temporary table on a storage by using a B + tree, wherein the key word is a traceable object ID;
the intra-block indexing is implemented by creating an index structure named MB + tree to replace Merkle tree in the block; in the MB + tree, leaf nodes are responsible for storing all data, including transaction ID, tracing object ID, transaction time, last block number, transaction data, Hash values of the transaction ID, tracing object ID, transaction time, last block number and transaction data, and intermediate nodes and root nodes are responsible for storing keyword information, pointers, keyword information, pointers and Hash values of all sub-nodes;
secondly, creating an index aiming at the block chain source tracing, namely creating a new block;
step 1: when the quantity of the transaction data does not reach a set threshold value, firstly storing the data into a cache table; when the transaction data quantity reaches a set threshold value, repeatedly executing the step 2-4;
step 2: when first transaction data is inserted, firstly, a temporary table of a block index structure is inquired according to a traceability object ID in the transaction data to obtain a block number preBlockNum field, the block number of a current block is stored in the block number preBlockNum field, and the temporary table is updated; then, the transaction data and the block number preBlockNum field are packaged into a leaf node, and the leaf node is also a root node at the moment; when the leaf nodes are packaged, 5 parts of the traceable object ID, the transaction time, the previous block number and the transaction data are used as parameters to calculate the Hashvalue LeafNodeHash of the leaf nodes, and the following formula is shown:
LeafNodeHash=Hash(ProductId,TransationId,Time,PreBlockNum,Data)
the ProductId, the transactioniD, the Time, the PreBlockNum and the Data respectively represent a traceability object ID, a transaction Time, a previous block number and transaction Data;
and step 3: inserting transaction data other than the first transaction data; for each transaction datum, inquiring a temporary table of a block index structure according to a traceability object ID in the transaction datum to obtain a block number preBlockNum field, storing the block number of the current block into the block number preBlockNum field, and updating the temporary table; then, the transaction data is packaged into leaf nodes, then the insertion positions are found according to the value of the transaction ID, and the leaf nodes are inserted into the MB + tree; after insertion, if the number of the keywords of the current node is less than or equal to M-1, and M is the order of the MB + tree, the insertion is finished; otherwise, splitting the leaf node into a left leaf node and a right leaf node, wherein the left leaf node comprises data stored in the first M/2 leaf nodes, the right leaf node comprises the rest data, carrying the keywords of the M/2+1 th record into the father node, the left pointer of the keywords carried into the father node points to the left leaf node, and the right pointer points to the right leaf node; then executing the step 4;
and 4, step 4: for nodes of the intermediate node type: if the number of the current node keywords is less than or equal to M-1, ending the insertion; otherwise, splitting the current intermediate node into two intermediate nodes, wherein the left intermediate node comprises front (M-1)/2 keywords, the right intermediate node comprises M- (M-1)/2 keywords, carrying the M/2-th keyword into the father node, the left pointer of the keyword carried into the father node points to the left intermediate node, and the right pointer of the keyword carried into the father node points to the right intermediate node; pointing the pointer of the current node to the father node, then executing the step 3 again, and executing the insertion of the next transaction data until all the transaction data are inserted into the MB + tree;
the Hash values stored in the intermediate node and the root node are calculated by the following formula:
MidNodeHash=Hash(Pointers,ChildNodeHashs,ProductIds)
wherein, Pointers, child node hashs and product ids respectively represent the Hash value and keyword information of the pointer and the sub-node;
and 5: when all transaction data are built into the MB + tree, a new block is generated and is linked to the previous block of the block chain;
thirdly, tracing and inquiring; firstly, inquiring a cache table, then inquiring a temporary table, and then inquiring an MB + tree in an improved block chain to obtain a target inquiry result, wherein the specific method comprises the following steps:
step S1: for a certain tracing object, firstly traversing and querying a cache table of local cache data, namely transaction data which is not added to a block, if the transaction data is found in the cache table, storing a query result into a query result set, and then executing a step S2, otherwise, directly executing a step S2;
step S2: inquiring the temporary table, if the tracing object is not found in the temporary table, returning an inquiry result set, and if the tracing object is found and verified correctly, searching block data in a corresponding block number in the result searched by the temporary table;
step S2.1: judging whether the current node is a leaf node, if so, comparing whether the ID of the traceability object to be searched is the same as the keyword of the current node, and if so, executing the step S3; if the keywords are different, quitting the query and returning to a query result set;
step S2.2: if not, comparing the ID of the tracing object to be inquired with the key word size of the node; if the traceable object ID is smaller than the minimum keyword of the node, the step S2.1 is repeatedly executed, and the searching is continued to the leftmost sub-tree of the current node; if the tracing object ID is larger than the maximum keyword of the node, the step S2.1 is repeatedly executed, and the searching is continued to the rightmost sub-tree of the current node; otherwise, step S2.1 is executed repeatedly, and the searching is continued to the middle subtree of the current node;
step S3: inquiring and verifying the MB + tree of the block corresponding to the retrieved block number;
step S3.1: judging whether the current node is a leaf node, if so, judging whether a block number preBlockNum field is empty, if so, storing transaction data packaged by the leaf node into a result set, meanwhile, comparing whether the block number preBlockNum field is the same as the corresponding block number preBlockNum field in the temporary table, if so, directly returning to an inquiry result set, and finishing the inquiry; if not, after updating the temporary table, returning to the query result set, and quitting the query; if the block number preBlockNum field is not empty, comparing whether the block number preBlockNum field is the same as the corresponding block number preBlockNum field in the temporary table or not, if not, updating the temporary table, and then inquiring a previous block according to the block number preBlockNum field; otherwise, directly inquiring the previous block according to the block number prebockNum field;
step S3.2: if not, comparing the transaction ID corresponding to the traceability object ID to be searched with the key word size of the node; if the transaction ID corresponding to the traceable object ID is smaller than the minimum keyword of the node, the step S3.1 is repeatedly executed, and the searching is continued to the leftmost sub-tree of the current node; if the transaction ID corresponding to the traceable object ID is larger than the maximum keyword of the node, the step S3.1 is repeatedly executed, and the searching is continued to the rightmost subtree of the current node; otherwise, step S3.1 is executed repeatedly, and the searching is continued to the middle subtree of the current node;
step S4: query the MB + tree: when a Merkle tree in a block is searched, the searched leaf node stores a preBlockNum field, if the field is empty, the transaction data packaged by the leaf node is stored into a result set, then the query is finished, and if the preBlockNum is not empty, the block data in the corresponding block number is continuously searched;
step S4.1: judging whether the current node is a leaf node, if so, judging whether a block number preBlockNum field is empty, if so, storing transaction data packaged by the leaf node into an inquiry result set, returning the inquiry result set, and finishing the inquiry, otherwise, retrieving the MB + tree of the block corresponding to the block number preBlockNum field;
s4.2, if the trace source object ID is not a leaf node, comparing the transaction ID corresponding to the trace source object ID to be searched with the key word size of the current node; if the transaction ID corresponding to the tracing object ID is smaller than the minimum keyword of the current node, the step S4.1 is repeatedly executed, and the searching is continued to the leftmost sub-tree of the current node; if the transaction ID corresponding to the tracing object ID is larger than the maximum keyword of the current node, the step S4.1 is repeatedly executed, and the searching is continued to the rightmost subtree of the current node; otherwise, step S4.1 is executed repeatedly, and the searching is continued to the middle subtree of the current node;
fourthly, index updating: updating and creating the internal index of the block are the same, and updating of the external index of the block occurs when the internal data of the blockchain is different from the temporary table data or when the traceable object ID does not exist; when the tracing object ID does not exist, updating the external index of the block is the same as the method for creating the temporary table; when the internal data of the block chain is different from the data of the temporary table, the temporary table is tampered, so that the temporary table needs to be updated at the moment, and the specific updating method comprises the following steps:
three fields for the data in the temporary table: updating a temporary table according to three tampering conditions of a transaction ID, a tracing object ID and a previous block number, which specifically comprise:
if the transaction ID is changed, changing the transaction ID field of the temporary table node;
if the previous block number field is changed, changing the previous block number field of the temporary table node;
if the tracing object ID is changed, adjusting the B + tree storing the temporary table, firstly deleting the leaf node storing the wrong tracing object ID, and then executing a temporary table insertion algorithm to update the temporary table.
Adopt the produced beneficial effect of above-mentioned technical scheme to lie in: according to the data tracing query method based on the block index structure, a user does not need to rely on external equipment to realize data tracing, so that the cost of purchasing and maintaining the equipment is not needed. Compared with a system for realizing the source tracing query based on the block chain, the method provided by the invention also improves the rate of the source tracing query.
Drawings
FIG. 1 is a block external index diagram according to an embodiment of the present invention, in which (a) is a temporary table and (B) is a B + tree;
fig. 2 is a schematic diagram of a leaf node storage structure of an MB + tree according to an embodiment of the present invention;
fig. 3 is a schematic diagram of a storage structure of an intermediate node and a root node of an MB + tree according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of an improved bit-coin block internal index according to an embodiment of the present invention;
fig. 5 is a flowchart of a tracing query according to an embodiment of the present invention.
Detailed Description
The following detailed description of embodiments of the present invention is provided in connection with the accompanying drawings and examples. The following examples are intended to illustrate the invention but are not intended to limit the scope of the invention.
In the embodiment, the mutton tracing process is taken as an example, and the mutton is traced and queried by using the data tracing and querying method based on the block index structure.
A data source-tracing query method based on a block index structure stores transaction data in an MB + tree of a block chain, creates an index aiming at the block chain source-tracing, and comprises four parts of content including block index structure definition, index creation, source-tracing query and index update, and specifically comprises the following steps:
firstly, defining a block index structure as a double-layer index structure: the first layer is a block external index; the second layer is block internal index;
the external block index is implemented by creating a temporary table, as shown in fig. 1, in the temporary table, storing a traceable object ID, a transaction ID of the transaction data having the traceable object ID, and a block number preBlockNum where the transaction data is located; in storage, in order to accelerate query, the temporary table is stored by using a B + tree, and a keyword is a traceable object ID;
the intra-block indexing is implemented by creating an index structure named MB + tree to replace Merkle tree in the block; the MB + tree combines the characteristics of the Merkle tree and the B + tree, and in the MB + tree, the MB + tree has all the characteristics of the B + tree, the leaf nodes are responsible for storing all data, as shown in fig. 2, including transaction ID (keyword Key), traceable object ID, transaction time, previous block number, transaction data and Hash values of the transaction ID, traceable object ID, transaction time, previous block number and transaction data, and the intermediate nodes and the root nodes are responsible for storing keyword information, pointers and Hash values of each sub-node, as shown in fig. 3;
secondly, creating an index aiming at the block chain source tracing, namely creating a new block; the process of creating an index is also the process of creating a new tile;
step 1: when the quantity of the transaction data does not reach a set threshold value, firstly storing the data into a cache table; when the transaction data quantity reaches a set threshold value, repeatedly executing the step 2-4;
step 2: when first transaction data is inserted, firstly, a temporary table of a block index structure is inquired according to a traceability object ID in the transaction data to obtain a block number preBlockNum field, the block number of a current block is stored in the block number preBlockNum field, and the temporary table is updated; then, the transaction data and the block number preBlockNum field are packaged into a leaf node, and the leaf node is also a root node at the moment; when the leaf nodes are packaged, 5 parts of the traceable object ID, the transaction time, the previous block number and the transaction data are used as parameters to calculate the Hashvalue LeafNodeHash of the leaf nodes, and the following formula is shown:
LeafNodeHash=Hash(ProductId,TransationId,Time,PreBlockNum,Data)
the ProductId, the transactioniD, the Time, the PreBlockNum and the Data respectively represent a traceability object ID, a transaction Time, a previous block number and transaction Data;
and step 3: inserting transaction data other than the first transaction data; in the insertion process of the MB + tree, for each transaction data, inquiring a temporary table of a block index structure according to the ID of a traceable object in the transaction data to obtain a block number preBlockNum field, storing the block number of the current block into the block number preBlockNum field, and updating the temporary table; then, the transaction data is packaged into leaf nodes, then the insertion positions are found according to the value of the transaction ID, and the leaf nodes are inserted into the MB + tree; after insertion, if the number of the keywords of the current node is less than or equal to M-1, and M is the order of the MB + tree, the insertion is finished; otherwise, splitting the leaf node into a left leaf node and a right leaf node, wherein the left leaf node and the right leaf node comprise data stored in the first M/2 leaf nodes, the right leaf node and the left child node comprise the rest data, carrying the keywords of the M/2+1 th record into the father node (the father node is necessarily an intermediate node type), wherein the left pointer of the keywords carried into the father node points to the left leaf node, and the right pointer points to the right leaf node; then executing the step 4;
and 4, step 4: for nodes of the intermediate node type: if the number of the current node keywords is less than or equal to M-1, ending the insertion; otherwise, splitting the current intermediate node into two intermediate nodes, wherein the left intermediate node comprises front (M-1)/2 keywords, the right intermediate node comprises M- (M-1)/2 keywords, carrying the M/2-th keyword into the father node, the left pointer of the keyword carried into the father node points to the left intermediate node, and the right pointer of the keyword carried into the father node points to the right intermediate node; pointing the pointer of the current node to the father node, then executing the step 3 again, and executing the insertion of the next transaction data until all the transaction data are inserted into the MB + tree;
the Hash values stored in the intermediate node and the root node are calculated by the following formula:
MidNodeHash=Hash(Pointers,ChildNodeHashs,ProductIds)
wherein, Pointers, child node hashs and product ids respectively represent the Hash value and keyword information of the pointer and the sub-node;
and 5: when all transaction data are built into the MB + tree, a new block is generated and is linked to the previous block of the block chain;
in this embodiment, the data collected during the sheep breeding and production process are firstly: integrating data such as sheep number (namely a traceability object ID in the method), type, sex, time, type of fed feed, temperature and the like, and temporarily storing the integrated data into a local cache table; and then generating a new block according to the method in the step 2-5 to store the collected sheep data, and linking to the previous block of the block chain. The improved bit coin block internal index structure obtained in this embodiment is shown in fig. 4.
Thirdly, tracing and inquiring; the query targeted by the invention is a history traceability-oriented query, firstly querying the cache table, then querying the temporary table, and then querying the MB + tree in the modified block chain to obtain a target query result, as shown in FIG. 5, the specific method is as follows:
step S1: for a certain tracing object, which has a unique tracing object ID, firstly, traversing and querying a cache table of local cache data, that is, transaction data which is not added to a block, because the transaction data of the local cache is not much, the query is only needed to be traversed here, if the transaction data is found in the cache table, the query result is stored in a query result set, then, step S2 is executed, otherwise, step S2 is directly executed;
step S2: inquiring the temporary table, if the tracing object is not found in the temporary table, returning an inquiry result set, and if the tracing object is found and verified correctly, searching block data in a corresponding block number in the result searched by the temporary table;
step S2.1: judging whether the current node is a leaf node, if so, comparing whether the ID of the traceability object to be searched is the same as the keyword of the current node, and if so, executing the step S3; if the keywords are different, quitting the query and returning to a query result set;
step S2.2: if not, comparing the ID of the tracing object to be inquired with the key word size of the node; if the traceable object ID is smaller than the minimum keyword of the node, the step 3.2.1 is repeatedly executed, and the searching is continued to the leftmost sub-tree of the current node; if the tracing object ID is larger than the maximum keyword of the node, the step 3.2.1 is repeatedly executed, and the searching is continued to the rightmost sub-tree of the current node; otherwise, step 3.2.1 is executed repeatedly, and the searching is continued to the middle subtree of the current node;
step S3: inquiring and verifying the MB + tree of the block corresponding to the retrieved block number;
step S3.1: judging whether the current node is a leaf node, if so, judging whether a block number preBlockNum field is empty, if so, storing transaction data packaged by the leaf node into a result set, meanwhile, comparing whether the block number preBlockNum field is the same as the corresponding block number preBlockNum field in the temporary table, if so, directly returning to an inquiry result set, and finishing the inquiry; if not, after updating the temporary table, returning to the query result set, and quitting the query; if the block number preBlockNum field is not empty, comparing whether the block number preBlockNum field is the same as the corresponding block number preBlockNum field in the temporary table or not, if not, updating the temporary table, and then inquiring a previous block according to the block number preBlockNum field; otherwise, directly inquiring the previous block according to the block number prebockNum field;
s3.2, if the trace source object ID is not a leaf node, comparing the transaction ID corresponding to the trace source object ID to be searched with the key word size of the node; if the transaction ID corresponding to the traceable object ID is smaller than the minimum keyword of the node, the step S3.1 is repeatedly executed, and the searching is continued to the leftmost sub-tree of the current node; if the transaction ID corresponding to the traceable object ID is larger than the maximum keyword of the node, the step S3.1 is repeatedly executed, and the searching is continued to the rightmost subtree of the current node; otherwise, step S3.1 is executed repeatedly, and the searching is continued to the middle subtree of the current node;
step S4: query the MB + tree: when a Merkle tree in a block is searched, the searched leaf node stores a preBlockNum field, if the field is empty, the transaction data packaged by the leaf node is stored into a result set, then the query is finished, and if the preBlockNum is not empty, the block data in the corresponding block number is continuously searched;
step S4.1: judging whether the current node is a leaf node, if so, judging whether a block number preBlockNum field is empty, if so, storing transaction data packaged by the leaf node into an inquiry result set, returning the inquiry result set, and finishing the inquiry, otherwise, retrieving the MB + tree of the block corresponding to the block number preBlockNum field;
s4.2, if the trace source object ID is not a leaf node, comparing the transaction ID corresponding to the trace source object ID to be searched with the key word size of the current node; if the transaction ID corresponding to the tracing object ID is smaller than the minimum keyword of the current node, the step S4.1 is repeatedly executed, and the searching is continued to the leftmost sub-tree of the current node; if the transaction ID corresponding to the tracing object ID is larger than the maximum keyword of the current node, the step S4.1 is repeatedly executed, and the searching is continued to the rightmost subtree of the current node; otherwise, step S4.1 is executed repeatedly, and the searching is continued to the middle subtree of the current node;
in this embodiment, the target query result is obtained by inputting the sheep serial number and querying in the cache table and the temporary table of the local cache data and the MB + tree in the modified block chain.
Fourthly, index updating: updating and creating the internal index of the block are the same, and updating of the external index of the block occurs when the internal data of the blockchain is different from the temporary table data or when the traceable object ID does not exist; when the tracing object ID does not exist, updating the external index of the block is the same as the method for creating the temporary table; when the data in the blockchain is different from the data in the temporary table, the data is tampered, and the blockchain has the characteristic of being not tampered, so that only the temporary table is tampered, and the temporary table needs to be updated at this time, wherein the specific updating method comprises the following steps:
three fields for the data in the temporary table: updating a temporary table according to three tampering conditions of a transaction ID, a tracing object ID and a previous block number, which specifically comprise:
if the transaction ID is changed, changing the transaction ID field of the temporary table node;
if the previous block number field is changed, changing the previous block number field of the temporary table node;
if the traceable object ID changes, the situation is complicated, because the traceable object ID is a key of the temporary table, and therefore, if the traceable object ID changes, the B + tree storing the temporary table needs to be adjusted, the leaf node storing the wrong traceable object ID is deleted first, and then the temporary table insertion algorithm is executed to update the temporary table.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; such modifications and substitutions do not depart from the spirit of the corresponding technical solutions and scope of the present invention as defined in the appended claims.

Claims (7)

1. A data tracing query method based on a block index structure stores transaction data in an MB + tree of a block chain, and creates an index aiming at the block chain tracing, and is characterized in that: the method comprises the following steps of defining a block index structure, creating an index, tracing and inquiring and updating the index, and specifically comprises the following steps:
firstly, defining a block index structure as a double-layer index structure: the first layer is a block external index; the second layer is block internal index;
the block external index is realized by creating a temporary table, and a tracing object ID, a transaction ID of the last transaction data with the tracing object ID and a block number preBlockNum of the transaction data are stored in the temporary table; storing the temporary table on a storage by using a B + tree, wherein the key word is a traceable object ID;
the intra-block indexing is implemented by creating an index structure named MB + tree to replace Merkle tree in the block; in the MB + tree, leaf nodes are responsible for storing all data, including transaction ID, tracing object ID, transaction time, last block number, transaction data, Hash values of the transaction ID, tracing object ID, transaction time, last block number and transaction data, and intermediate nodes and root nodes are responsible for storing keyword information, pointers, keyword information, pointers and Hash values of all sub-nodes;
secondly, creating an index aiming at the block chain source tracing, namely creating a new block;
step 1: when the quantity of the transaction data does not reach a set threshold value, firstly storing the data into a cache table; when the transaction data quantity reaches a set threshold value, repeatedly executing the step 2-4;
step 2: when first transaction data is inserted, firstly, a temporary table of a block index structure is inquired according to a traceability object ID in the transaction data to obtain a block number preBlockNum field, the block number of a current block is stored in the block number preBlockNum field, and the temporary table is updated; then, the transaction data and the block number preBlockNum field are packaged into a leaf node, and the leaf node is also a root node at the moment;
and step 3: inserting transaction data other than the first transaction data; for each transaction datum, inquiring a temporary table of a block index structure according to a traceability object ID in the transaction datum to obtain a block number preBlockNum field, storing the block number of the current block into the block number preBlockNum field, and updating the temporary table; then, the transaction data is packaged into leaf nodes, then the insertion positions are found according to the value of the transaction ID, and the leaf nodes are inserted into the MB + tree; after insertion, if the number of the keywords of the current node is less than or equal to M-1, and M is the order of the MB + tree, the insertion is finished; otherwise, splitting the leaf node into a left leaf node and a right leaf node, wherein the left leaf node comprises data stored in the first M/2 leaf nodes, the right leaf node comprises the rest data, carrying the keywords of the M/2+1 th record into the father node, the left pointer of the keywords carried into the father node points to the left leaf node, and the right pointer points to the right leaf node; then executing the step 4;
and 4, step 4: for nodes of the intermediate node type: if the number of the current node keywords is less than or equal to M-1, ending the insertion; otherwise, splitting the current intermediate node into two intermediate nodes, wherein the left intermediate node comprises front (M-1)/2 keywords, the right intermediate node comprises M- (M-1)/2 keywords, carrying the M/2-th keyword into the father node, the left pointer of the keyword carried into the father node points to the left intermediate node, and the right pointer of the keyword carried into the father node points to the right intermediate node; pointing the pointer of the current node to the father node, then executing the step 3 again, and executing the insertion of the next transaction data until all the transaction data are inserted into the MB + tree;
and 5: when all transaction data are built into the MB + tree, a new block is generated and is linked to the previous block of the block chain;
thirdly, tracing and inquiring; firstly, inquiring a cache table, then inquiring a temporary table, and then inquiring an MB + tree in an improved block chain to obtain a target inquiry result, wherein the specific method comprises the following steps:
step S1: for a certain tracing object, firstly traversing and querying a cache table of local cache data, namely transaction data which is not added to a block, if the transaction data is found in the cache table, storing a query result into a query result set, and then executing a step S2, otherwise, directly executing a step S2;
step S2: inquiring the temporary table, if the tracing object is not found in the temporary table, returning an inquiry result set, and if the tracing object is found and verified correctly, searching block data in a corresponding block number in the result searched by the temporary table;
step S3: inquiring and verifying the MB + tree of the block corresponding to the retrieved block number;
step S4: query the MB + tree: when a Merkle tree in a block is searched, the searched leaf node stores a preBlockNum field, if the field is empty, the transaction data packaged by the leaf node is stored into a result set, then the query is finished, and if the preBlockNum is not empty, the block data in the corresponding block number is continuously searched;
fourthly, index updating: updating and creating the internal index of the block are the same, and updating of the external index of the block occurs when the internal data of the blockchain is different from the temporary table data or when the traceable object ID does not exist; when the tracing object ID does not exist, updating the external index of the block is the same as the method for creating the temporary table; when the data in the blockchain is different from the data in the temporary table, the temporary table is tampered, so that the temporary table is updated.
2. The method according to claim 1, wherein the data source-tracing query method based on the block index structure comprises: creating an index aiming at the block chain traceability, and when the index is packaged into a leaf node, simultaneously calculating the Hash value LeafNodeHash of the leaf node by taking 5 parts of a traceability object ID, a transaction ID, transaction time, a previous block number and transaction data as parameters, wherein the formula is as follows:
LeafNodeHash=Hash(ProductId,TransationId,Time,PreBlockNum,Data)
the ProductId, TransactionId, Time, PreBlockNum, and Data respectively represent a tracing object ID, a transaction Time, a previous block number, and transaction Data.
3. The method according to claim 2, wherein the data source-tracing query method based on the block index structure comprises: and (3) creating indexes aiming at the block chain source tracing, and calculating Hash values stored in the intermediate nodes and the root nodes by the following formulas:
MidNodeHash=Hash(Pointers,ChildNodeHashs,ProductIds)
wherein, Pointers, child node hashs and product ids respectively represent the Hash value and the keyword information of the pointer, the sub-node.
4. The method according to claim 3, wherein the data source-tracing query method based on the block index structure comprises: the specific method of step S2 is as follows:
step S2.1: judging whether the current node is a leaf node, if so, comparing whether the ID of the traceability object to be searched is the same as the keyword of the current node, and if so, executing the step S3; if the keywords are different, quitting the query and returning to a query result set;
step S2.2: if not, comparing the ID of the tracing object to be inquired with the key word size of the node; if the traceable object ID is smaller than the minimum keyword of the node, the step S2.1 is repeatedly executed, and the searching is continued to the leftmost sub-tree of the current node; if the tracing object ID is larger than the maximum keyword of the node, the step S2.1 is repeatedly executed, and the searching is continued to the rightmost sub-tree of the current node; otherwise, step S2.1 is executed repeatedly, and the search continues to the middle subtree of the current node.
5. The method according to claim 4, wherein the data source-tracing query method based on the block index structure comprises: the specific method of step S3 is as follows:
step S3.1: judging whether the current node is a leaf node, if so, judging whether a block number preBlockNum field is empty, if so, storing transaction data packaged by the leaf node into a result set, meanwhile, comparing whether the block number preBlockNum field is the same as the corresponding block number preBlockNum field in the temporary table, if so, directly returning to an inquiry result set, and finishing the inquiry; if not, after updating the temporary table, returning to the query result set, and quitting the query; if the block number preBlockNum field is not empty, comparing whether the block number preBlockNum field is the same as the corresponding block number preBlockNum field in the temporary table or not, if not, updating the temporary table, and then inquiring a previous block according to the block number preBlockNum field; otherwise, directly inquiring the previous block according to the block number prebockNum field;
s3.2, if the trace source object ID is not a leaf node, comparing the transaction ID corresponding to the trace source object ID to be searched with the key word size of the node; if the transaction ID corresponding to the traceable object ID is smaller than the minimum keyword of the node, the step S3.1 is repeatedly executed, and the searching is continued to the leftmost sub-tree of the current node; if the transaction ID corresponding to the traceable object ID is larger than the maximum keyword of the node, the step S3.1 is repeatedly executed, and the searching is continued to the rightmost subtree of the current node; otherwise, step S3.1 is executed repeatedly, and the search continues to the middle subtree of the current node.
6. The method of claim 5, wherein the data source-tracing query method based on the block index structure comprises: the specific method of step S4 is as follows:
step S4.1: judging whether the current node is a leaf node, if so, judging whether a block number preBlockNum field is empty, if so, storing transaction data packaged by the leaf node into an inquiry result set, returning the inquiry result set, and finishing the inquiry, otherwise, retrieving the MB + tree of the block corresponding to the block number preBlockNum field;
s4.2, if the trace source object ID is not a leaf node, comparing the transaction ID corresponding to the trace source object ID to be searched with the key word size of the current node; if the transaction ID corresponding to the tracing object ID is smaller than the minimum keyword of the current node, the step S4.1 is repeatedly executed, and the searching is continued to the leftmost sub-tree of the current node; if the transaction ID corresponding to the tracing object ID is larger than the maximum keyword of the current node, the step S4.1 is repeatedly executed, and the searching is continued to the rightmost subtree of the current node; otherwise, step S4.1 is executed repeatedly, and the searching is continued to the middle subtree of the current node.
7. The method of claim 6, wherein the data source-tracing query method based on the block index structure comprises: the specific method for updating the temporary table is as follows:
three fields for the data in the temporary table: updating a temporary table according to three tampering conditions of a transaction ID, a tracing object ID and a previous block number, which specifically comprise:
if the transaction ID is changed, changing the transaction ID field of the temporary table node;
if the previous block number field is changed, changing the previous block number field of the temporary table node;
if the tracing object ID is changed, adjusting the B + tree storing the temporary table, firstly deleting the leaf node storing the wrong tracing object ID, and then executing a temporary table insertion algorithm to update the temporary table.
CN202110109990.2A 2021-01-27 2021-01-27 Data tracing query method based on block index structure Expired - Fee Related CN112765181B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110109990.2A CN112765181B (en) 2021-01-27 2021-01-27 Data tracing query method based on block index structure

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110109990.2A CN112765181B (en) 2021-01-27 2021-01-27 Data tracing query method based on block index structure

Publications (2)

Publication Number Publication Date
CN112765181A true CN112765181A (en) 2021-05-07
CN112765181B CN112765181B (en) 2021-12-03

Family

ID=75706072

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110109990.2A Expired - Fee Related CN112765181B (en) 2021-01-27 2021-01-27 Data tracing query method based on block index structure

Country Status (1)

Country Link
CN (1) CN112765181B (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113535732A (en) * 2021-07-23 2021-10-22 东北大学 Credibility-behavior association double-block chain oriented verifiable query optimization method
CN113626433A (en) * 2021-08-03 2021-11-09 浪潮云信息技术股份公司 Data storage method based on two-layer ART tree
CN113704248A (en) * 2021-07-12 2021-11-26 北京邮电大学 Block chain query optimization method based on external index

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20200234383A1 (en) * 2019-04-29 2020-07-23 Alibaba Group Holding Limited Blockchain-based service source tracing method, apparatus, and electronic device
CN112035469A (en) * 2020-08-27 2020-12-04 贵州大学 Food data tracing method based on block chain

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20200234383A1 (en) * 2019-04-29 2020-07-23 Alibaba Group Holding Limited Blockchain-based service source tracing method, apparatus, and electronic device
CN112035469A (en) * 2020-08-27 2020-12-04 贵州大学 Food data tracing method based on block chain

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
QINGXING GUO等: "Blockchain PG: Enabling Authenticated Query and Trace Query in Database", 《SPRINGER NATURE SWITZERLAND AG 2020》 *
焦通等: "区块链数据库:一种可查询且防篡改的数据库", 《软件学报》 *

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113704248A (en) * 2021-07-12 2021-11-26 北京邮电大学 Block chain query optimization method based on external index
CN113704248B (en) * 2021-07-12 2024-01-09 北京邮电大学 Block chain query optimization method based on external index
CN113535732A (en) * 2021-07-23 2021-10-22 东北大学 Credibility-behavior association double-block chain oriented verifiable query optimization method
CN113535732B (en) * 2021-07-23 2023-07-25 东北大学 Verifiable query optimization method for reputation-behavior correlation-oriented double-block chain
CN113626433A (en) * 2021-08-03 2021-11-09 浪潮云信息技术股份公司 Data storage method based on two-layer ART tree
CN113626433B (en) * 2021-08-03 2024-01-19 上海沄熹科技有限公司 Data storage method based on two-layer ART tree

Also Published As

Publication number Publication date
CN112765181B (en) 2021-12-03

Similar Documents

Publication Publication Date Title
CN112765181B (en) Data tracing query method based on block index structure
US8996502B2 (en) Using join dependencies for refresh
US7562073B2 (en) Business object search using multi-join indexes and extended join indexes
CN109471905B (en) Block chain indexing method supporting time range and attribute range compound query
CN105975587B (en) A kind of high performance memory database index organization and access method
WO2005106717A1 (en) Partial query caching
CN105574054B (en) A kind of distributed caching range query method, apparatus and system
CN110928882B (en) Memory database indexing method and system based on improved red black tree
US8543614B2 (en) Packing nodes into records to store XML XQuery data model and other hierarchically structured data
CN105373541A (en) Processing method and system for data operation request of database
US9418154B2 (en) Push-model based index updating
CN101833568A (en) Web data management system
CN101256579A (en) Method for inquesting data organization in database
CN110928939A (en) Method for converting Sql result set into Json data based on tree structure
US9594784B2 (en) Push-model based index deletion
Esmailoghli et al. MATE: multi-attribute table extraction
CN113704248B (en) Block chain query optimization method based on external index
CN112256821B (en) Chinese address completion method, device, equipment and storage medium
CN115840751B (en) Novel tree-shaped data coding method
CN111984649A (en) Data index searching method and device and related equipment
CN115237914A (en) Tamper-resistant index structure and construction, storage and query methods thereof
CN114218277A (en) Efficient query method and device for relational database
CN115794873A (en) Authority control method based on full-text retrieval technology
CN111159175B (en) Incomplete database Skyline query method based on index
CN114579617A (en) Data query method and device, computer equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20211203

CF01 Termination of patent right due to non-payment of annual fee