CN111984732A - Method, node and block chain network for realizing decentralized retrieval on block chain - Google Patents
Method, node and block chain network for realizing decentralized retrieval on block chain Download PDFInfo
- Publication number
- CN111984732A CN111984732A CN202010904403.4A CN202010904403A CN111984732A CN 111984732 A CN111984732 A CN 111984732A CN 202010904403 A CN202010904403 A CN 202010904403A CN 111984732 A CN111984732 A CN 111984732A
- Authority
- CN
- China
- Prior art keywords
- block
- hash
- key
- block hash
- current
- 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
Links
- 238000000034 method Methods 0.000 title claims abstract description 48
- 238000013507 mapping Methods 0.000 claims abstract description 44
- 238000004590 computer program Methods 0.000 claims description 7
- 230000008569 process Effects 0.000 description 16
- 230000006870 function Effects 0.000 description 7
- 238000010586 diagram Methods 0.000 description 6
- 238000012545 processing Methods 0.000 description 4
- 230000009286 beneficial effect Effects 0.000 description 3
- 238000010276 construction Methods 0.000 description 3
- 230000006399 behavior Effects 0.000 description 2
- 238000004891 communication Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 238000004364 calculation method Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/27—Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/22—Indexing; Data structures therefor; Storage structures
- G06F16/2228—Indexing structures
- G06F16/2246—Trees, e.g. B+trees
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/22—Indexing; Data structures therefor; Storage structures
- G06F16/2228—Indexing structures
- G06F16/2255—Hash tables
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/22—Indexing; Data structures therefor; Storage structures
- G06F16/2282—Tablespace storage structures; Management thereof
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/242—Query formulation
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/27—Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
- G06F16/278—Data partitioning, e.g. horizontal or vertical partitioning
Abstract
The invention provides a method for realizing decentralized retrieval on a block chain, a node and a block chain network, wherein the method comprises the following steps: s1, acquiring a main key or a keyword of the transaction data to be retrieved, and inquiring whether a record with the main key or the keyword exists according to a first mapping table; s2, when the record exists, acquiring the first block hash of the current block at the tail of the linked list corresponding to the record; s3, acquiring the transaction data of the current block from a block chain through the first block hash; s4, acquiring a second block hash of a previous block of the current block based on a preset second mapping table and the first block hash; s5, judging whether the hash of the second block is zero; if not, executing S6, if yes, executing S7; s6, updating the first block hash to a second block hash, and returning to the step S3; and S7, outputting all the inquired transaction data. The invention realizes decentralized and distributed rapid retrieval in the block chain.
Description
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method, a node, and a blockchain network for implementing decentralized search on a blockchain.
Background
In block chain application implementation, one transaction generates one block, transaction data is stored in the block in a plaintext or ciphertext mode, and the block data is linked according to the transaction time sequence. And calculating a hash value for each block data, wherein the transaction data and the hash value of the previous block are involved in the calculation when the hash value is calculated. Therefore, if a certain block in the block chain is maliciously tampered, the hash value calculated by using the modified block data is inconsistent with the original hash value, and the data of the block can be found to be tampered by calculating the hash value of the subsequent block. This is the basic principle behind the tamper resistance of blockchains.
In the implementation of blockchain applications, each blockchain node stores the blockchain data in an embedded database local to the node. Usually, the node will store all the block data locally, and there will be a little difference due to the node network synchronization delay, but eventually the data of each node will be kept in consistent synchronization. Thus, distributed storage of block data is guaranteed, and even if a certain node fails, data cannot be lost or unavailable. Due to the decentralized nature of blockchain networks, Byzantine Fault Tolerant (BFT) algorithms are commonly used in blockchain implementations, allowing a blockchain network to still be properly available when a few nodes fail.
In some cases, transaction data on the blockchain needs to be retrieved, but the transaction data stored on the blockchain is inconvenient to be retrieved effectively due to the special data structure mode of the transaction data, and in the worst case, the block data of the whole blockchain needs to be traversed.
Disclosure of Invention
In view of the above, the present invention provides a method, a node and a blockchain network for implementing decentralized search on a blockchain, which can implement decentralized and distributed fast search on the blockchain.
The embodiment of the invention provides a method for realizing decentralized retrieval on a block chain, which comprises the following steps:
s1, acquiring a main key or a keyword of the transaction data to be retrieved, and inquiring whether a record with the main key or the keyword exists according to a first mapping table;
s2, when the record exists, acquiring the first block hash of the current block at the tail of the linked list corresponding to the record;
s3, acquiring the transaction data of the current block from a block chain through the first block hash;
s4, acquiring a second block hash of a previous block of the current block based on a preset second mapping table and the first block hash;
s5, judging whether the hash of the second block is zero; if not, executing S6, if yes, executing S7;
s6, updating the first block hash to a second block hash, and returning to the step S3;
and S7, outputting all the inquired transaction data.
Preferably, the first mapping table includes a plurality of key value pairs, the key of the key value pair is a primary key or a key word, the value of the key value pair is a block hash of a block, and the block hash corresponds to a block at the tail of a linked list.
Preferably, the second mapping table includes a plurality of key value pairs, the key of the key value pair is a block hash of the current block, and the value of the key value pair is a block hash of a last block of the current block on the same linked list.
Preferably, the method further comprises the following steps:
when a new transaction block is generated, recording the block generated by the new transaction as a current block, and adding the current block to a block chain; acquiring transaction data of a current block; wherein the transaction data comprises a primary key or a keyword;
acquiring a primary key or a keyword corresponding to each current linked list from a first mapping table to determine the linked list to which the current block belongs; wherein, the blocks with the same primary key or key word are stored in the same linked list; when the main key or the key word of the current block does not exist in the first mapping table, newly adding a record in the first mapping table, wherein the key of the record is the main key or the key word of the current block, and the value of the record is the block hash of the current block;
and acquiring the link information of the tail part of the linked list, linking the current block to the linked list, and updating the second mapping table.
The embodiment of the invention also provides a method for realizing decentralized retrieval on the block chain, which comprises the following steps:
s201, acquiring a primary key or a key word of transaction data to be searched and a current block hash of a binary tree root;
s202, searching in a third mapping table according to the current block hash to obtain a search result, wherein the search result comprises a main key or a keyword, a block hash of a left sub-tree and a block hash of a right sub-tree;
s203, judging whether the main key or the keyword to be searched is consistent with the main key or the keyword in the search result;
s204, when the judgment is consistent, acquiring transaction data of the block in the block chain according to the current block hash, and updating the block hash of the left sub-tree into the current block hash; when the judgment result shows that the two sub-trees are inconsistent, updating the block hash of the right sub-tree into the current block hash;
s205, judging whether the hash of the current block is zero, if so, continuing to execute S206; if not, executing S202;
and S206, outputting all inquired transaction data.
Preferably, the data table of the binary tree root includes a record for recording the block hash of the binary tree root, and the initial value is zero.
Preferably, the third mapping table includes a plurality of key value pairs, the keys of the key value pairs are block hashes, and the values of the key value pairs include a primary key or a key word, a block hash of the left sub-tree, and a block hash of the right sub-tree.
Preferably, the method further comprises the following steps:
when a new transaction block is generated:
s301, acquiring a block generated by a new transaction, and adding the block to a block chain; wherein the block generated by the new transaction has a first block hash;
s302, acquiring a second block hash of the binary tree root according to the data table of the binary tree root, wherein the binary tree root is a parent node of the current binary tree;
s303, when the second block hash is zero, newly adding a record in a third mapping table, where a primary key of the record is the first block hash, and a value of the record is: the key or keyword of the newly generated transaction data of the block, the block hash of the left sub-tree and the block hash of the right sub-tree are both zero;
judging whether the parent node of the current binary tree is a binary tree root or not;
if so, setting the data table of the binary tree root as a first block hash;
if not, judging whether the main key or the key word of the father node is the same as the main key or the key word of the transaction data of the newly generated block; if yes, setting the left sub-tree of the father node as a first block hash, and executing S306; if not, setting the right subtree of the father node as a first block hash, and executing S306;
s304, when the second block hash is not zero, searching in a third mapping table by using the second block hash to obtain a search result, wherein the search result is a current binary tree father node;
s305, judging whether the main key or the key word of the search result is the same as the main key or the key word of the transaction data of the newly generated block;
if so, updating the block hash of the left sub-tree of the search result to be the second block hash, and executing S303;
if not, updating the block hash of the right subtree of the search result to be a second block hash, and executing S303;
s306, the newly generated block is added into the binary tree.
The embodiment of the invention also provides a node for realizing decentralized retrieval on the block chain, which comprises a memory and a processor, wherein a computer program is stored in the memory, and the computer program can be executed by the processor so as to realize the model-enhanced face recognition method.
The embodiment of the invention also provides a block chain network which comprises a plurality of nodes, wherein each node is in communication connection through a point-to-point network.
The above embodiment has the following beneficial effects:
1. by constructing a linked list or a binary tree and taking transaction data as a storage unit in the linked list or the binary tree, the data in the blocks are not modified, but the blocks are connected by constructing linked data of the linked list or the binary tree;
2. an embedded database carried by a node is used as a storage medium of linked list or binary tree linked data, so that the linked data also has the characteristic of distributed storage;
3. the process of constructing a linked list or a binary tree is added in the transaction processing process of the blockchain, and because the blockchain network has the functions of propagation and copy among nodes, link data are also constructed at each node in the transaction copying process, so that the link data also has the characteristic of decentralized storage;
4. when searching transaction data, since the linked list or binary tree is decentralized and distributed storage, the searching operation can be performed on any one block link point; in the retrieval process, the head or the root node of the linked list is found through the linked list or the binary tree data, and according to the set key value in construction, all transaction data in the linked list or the binary tree search block, decentralized distributed rapid retrieval is realized.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings that are required to be used in the embodiments will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present invention and therefore should not be considered as limiting the scope, and for those skilled in the art, other related drawings can be obtained according to the drawings without inventive efforts.
Fig. 1 is a schematic flowchart of a method for implementing decentralized search on a blockchain according to a first embodiment of the present invention.
FIG. 2 is a diagram of a linked list provided by a first embodiment of the present invention.
Fig. 3 is a flowchart illustrating a method for implementing decentralized search on a blockchain according to a second embodiment of the present invention.
Fig. 4 is a schematic diagram of a binary tree provided by a second embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be described clearly and completely with reference to the accompanying drawings of the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all embodiments of the present invention. All other embodiments, which can be obtained by a person skilled in the art without any inventive step based on the embodiments of the present invention, are within the scope of the present invention. Thus, the following detailed description of the embodiments of the present invention, presented in the figures, is not intended to limit the scope of the invention, as claimed, but is merely representative of selected embodiments of the invention. All other embodiments, which can be obtained by a person skilled in the art without any inventive step based on the embodiments of the present invention, are within the scope of the present invention.
Referring to fig. 1, a first embodiment of the present invention provides a method for implementing decentralized search on blockchains, which is performed by a node (hereinafter referred to as a node) for implementing decentralized search on blockchains, and in particular, is performed by one or more processors in the node, so as to implement the following steps:
s1, obtaining the main key or key word of the transaction data to be retrieved, and inquiring whether the record with the main key or key word exists according to the first mapping table.
In this embodiment, the nodes are located in a blockchain network, and the blockchain network generally includes a plurality of nodes that are communicatively connected by a peer-to-peer network, and the nodes are all peer-to-peer nodes, so as to achieve decentralization.
In this embodiment, in the block storage, for a currently generated block, the node first acquires transaction data in the currently generated block, where the transaction data includes a primary key or a keyword. Taking the operation on a file as an example, the transaction data generally includes the following information: a file hash (i.e. a primary key or a key word in this embodiment), a file name, and a file operation (e.g. file creation or file browsing, and an operation occurrence time). The file hash is used to uniquely represent a file, and is generally calculated by performing a hash on the content of the file. It should be noted that, in this embodiment, the transaction data is not necessarily a transaction behavior, but may be a substitute of various behaviors, such as a real transaction or some operations (for example, the file operation data in this embodiment may also be referred to as a transaction data), which are all within the protection scope of the present invention and are not described herein.
For the convenience of understanding of the present invention, the following description will be given by taking the operation on the document as an example, but it should be understood that the scope of application of the present invention is not limited thereto.
In this embodiment, after acquiring the transaction data of the block, the node acquires a file hash corresponding to each current linked list to determine the linked list to which the current block belongs.
In this embodiment, the node may construct a first mapping table, where the first mapping table includes a plurality of key value pairs, a key of each key value pair is a file hash, a value of each key value pair is a block hash of one block, and the block hash corresponds to a block at the tail of one linked list, that is, in this embodiment, blocks with the same file hash may be placed in the same linked list.
In the embodiment, when the linked list is constructed, the file hash corresponding to each current linked list is obtained from the first mapping table to determine the linked list to which the current block belongs; and storing blocks with the same file hash on the same linked list. In addition, if the file hash of the current block does not exist in the first mapping table, the node adds a record in the first mapping table, where the key of the record is the file hash of the current block, and the value of the record is the block hash of the current block.
In this embodiment, after obtaining the linked list corresponding to the current block, the node obtains the link information at the tail of the linked list, links the current block to the linked list, and updates the second mapping table.
In this embodiment, the second mapping table includes a plurality of key value pairs, where a key of a key value pair is a block hash of a current block, and a value of the key value pair is a block hash of a previous block of the current block on the same linked list, so that the node can continuously search for the transaction data of the previous block on the same linked list upward through the second mapping table.
In this embodiment, after the current block is connected to the linked list, a mapping relationship, that is, a mapping relationship between the block hash of the current block and the block hash of the previous block, needs to be added to the second mapping table.
And S2, when the record exists, acquiring the first block hash of the current block at the tail of the linked list corresponding to the record.
In this embodiment, if there is a record, it indicates that the transaction data to be retrieved already exists, so the first block hash of the block at the tail of the linked list of the corresponding linked list can be obtained according to the file hash of the record.
In the present embodiment, if there is no record, the retrieval is ended.
S3, obtaining the transaction data of the current block from the block chain through the first block hash.
S4, acquiring a second block hash of a previous block of the current block based on a preset second mapping table and the first block hash;
s5, judging whether the hash of the second block is zero; if not, executing S6, if yes, executing S7;
s6, updating the first block hash to a second block hash, and returning to the step S3;
and S7, outputting all the inquired transaction data.
As shown in fig. 2, in this embodiment, after finding the record, the node obtains the transaction data in the block from the block chain through the first block hash. And then, acquiring a second block hash of the previous block according to a second mapping table, and continuously querying the head of the linked list to acquire transaction data until the head of the linked list is reached (namely the block hash of the previous block is zero or does not exist). And finally, outputting all the searched transaction data to obtain all the transaction data corresponding to the current file hash.
In summary, the present embodiment has the following beneficial effects:
1. by constructing a linked list and taking transaction data as a storage unit in the linked list, the data in the blocks are not modified, but the blocks are connected by constructing link data of the linked list;
2. an embedded database of a node is used as a storage medium of linked data of a linked list, so that the linked data also has the characteristic of distributed storage;
3. the process of constructing the linked list is added in the transaction processing process of the block chain, and because the block chain network has the functions of propagation and copy among nodes, the link data is also constructed at each node in the transaction copying process, so the link data also has the characteristic of decentralized storage;
4. when searching transaction data, the searching operation can be carried out on any block link point because the linked list is decentralized and distributed storage; in the retrieval process, the head of the linked list is found through the linked list, and all transaction data in the linked list search block are searched according to the set key value during construction, so that decentralized distributed rapid retrieval is realized.
Referring to fig. 3 and fig. 4, a second embodiment of the present invention further provides a method for implementing decentralized search on a block chain, including:
s201, acquiring a primary key or a key word of transaction data to be searched and a current block hash of a binary tree root.
In this embodiment, the file operation record is still used as an embodiment for description. When a new transaction block is generated, firstly, the block generated by the new transaction is obtained, and the block is added to a block chain; wherein the block generated by the new transaction has a first block hash.
The block hash is an attribute of each block.
And then, acquiring a second block hash of the binary tree root according to the data table of the binary tree root, wherein the binary tree root is a parent node of the binary tree at the moment.
In this embodiment, the data table of the binary tree root includes only one record, and is used to record the block hash of the binary tree root, and the initial value is zero.
When the second block hash is zero, there is no record yet, so that a record is newly added in the third mapping table, the primary key of the record is the first block hash, and the values of the record are: the primary key or key is the file hash of the newly generated block, the block hash of the left sub-tree, and the block hash of the right sub-tree (which are all initially zero).
Then, judging whether the father node of the current binary tree is a binary tree root or not; if yes, setting the data table of the binary tree root as a first block hash, and indicating that the new block is a first leaf node of the binary tree; if not, judging whether the file hash of the father node is the same as the file hash of the new block; if the two blocks are the same, setting the left sub-tree of the father node as a first block hash; and if not, setting the right subtree of the father node as the first block hash. At this point, the new block has been added to the linking data of the binary tree. Thus, in the binary tree designed based on this way, all blocks with different file hashes will appear in the right subtree, and all blocks with the same file hash will appear in the left subtree.
And when the second block hash is not zero, searching in a third mapping table by using the second block hash to obtain a search result, wherein the search result is a parent node of the current binary tree.
In this embodiment, if the second block hash is not zero, it indicates that there is a related record currently. So that the second block hash can be directly used to search in the third mapping table to obtain the search result. The search result comprises a file hash, a block hash of a left sub-tree and a block hash of a right sub-tree;
judging whether the file hash of the search result is the same as the file hash of the newly generated block or not;
if so, updating the block hash of the left sub-tree of the search result into a second block hash;
if not, updating the block hash of the right subtree of the search result to be a second block hash;
in this embodiment, the above-mentioned determination and processing on whether the second block hash is zero are continuously repeated until the second block hash is zero and the addition of new block link data is completed.
Thus, the addition of the block generated by the new transaction to the binary tree is completed, and the binary tree is updated.
S202, searching in a third mapping table according to the current block hash to obtain a search result, wherein the search result comprises the file hash, the block hash of the left sub-tree and the block hash of the right sub-tree.
S203, judging whether the hash of the file to be searched is the same as the hash of the file in the search result.
S204, when the judgment is consistent, acquiring transaction data of the block in the block chain according to the current block hash, and updating the block hash of the left sub-tree into the current block hash; and when the judgment result is inconsistent, updating the block hash of the right subtree to the current block hash.
S205, judging whether the hash of the current block is zero, if so, continuing to execute S206; if not, executing S202;
and S206, outputting all inquired transaction data.
In this embodiment, since all blocks with different file hashes will appear in the right sub-tree and all blocks with the same file hash will appear in the left sub-tree, during searching, if they are consistent, the left sub-number is searched, and if they are inconsistent, the right sub-number is searched. And continuously updating the current block hash in the searching process, and continuously performing traversal retrieval on child nodes below the binary tree by taking the updated current block hash as a new searching condition until the current block hash is zero or does not exist, so that all transaction data of the current block hash can be obtained.
In summary, the present embodiment has the following beneficial effects:
1. by constructing a binary tree and taking transaction data as a storage unit in the binary tree, data in the blocks are not modified, but the blocks are connected by constructing link data of the binary tree;
2. an embedded database carried by the node is used as a storage medium of binary tree link data, so that the link data also has the characteristic of distributed storage;
3. the process of constructing the binary tree is added in the transaction processing process of the block chain, and because the block chain network has the functions of propagation and copying among nodes, link data are constructed in each node in the transaction copying process, so that the link data also have the characteristic of decentralized storage;
4. in retrieving transaction data, since the binary tree is decentralized and distributed storage, the retrieval operation can be performed at any one of the block link points; in the retrieval process, the root node is found through the binary tree data, and decentralized distributed retrieval is realized according to the transaction data of the set key value in the binary tree search block during construction.
The embodiment of the present invention further provides a node for implementing decentralized search on a blockchain, including a memory and a processor, where the memory stores a computer program, and the computer program can be executed by the processor to implement the method for implementing decentralized search on a blockchain as described above.
The embodiment of the invention also provides a block chain network which comprises a plurality of nodes, wherein each node is in communication connection through a point-to-point network.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus and method can be implemented in other ways. The apparatus and method embodiments described above are illustrative only, as the flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
In addition, the functional modules in the embodiments of the present invention may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
The functions, if implemented in the form of software functional modules and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, an electronic device, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes. It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims (10)
1. A method for decentralized search over a blockchain, comprising:
s1, acquiring a main key or a keyword of the transaction data to be retrieved, and inquiring whether a record with the main key or the keyword exists according to a first mapping table;
s2, when the record exists, acquiring the first block hash of the current block at the tail of the linked list corresponding to the record;
s3, acquiring the transaction data of the current block from a block chain through the first block hash;
s4, acquiring a second block hash of a previous block of the current block based on a preset second mapping table and the first block hash;
s5, judging whether the hash of the second block is zero; if not, executing S6, if yes, executing S7;
s6, updating the first block hash to a second block hash, and returning to the step S3;
and S7, outputting all the inquired transaction data.
2. The method of claim 1, wherein the first mapping table comprises a plurality of key value pairs, wherein a key of the key value pair is a primary key or a key word of the transaction data, a value of the key value pair is a block hash of a block, and the block hash corresponds to a block at a tail of a linked list.
3. The method of claim 2, wherein the second mapping table comprises a plurality of key-value pairs, the key of each key-value pair is a block hash of the current block, and the value of each key-value pair is a block hash of a previous block of the current block on the same linked list.
4. The method of claim 3, further comprising:
when a new transaction block is generated, recording the block generated by the new transaction as a current block, and adding the current block to a block chain;
acquiring transaction data of a current block; wherein the transaction data comprises a primary key or a keyword;
acquiring a primary key or a keyword corresponding to each current linked list from a first mapping table to determine the linked list to which the current block belongs; wherein, the blocks with the same primary key or key word are stored in the same linked list; when the main key or the key word of the current block does not exist in the first mapping table, newly adding a record in the first mapping table, wherein the key of the record is the main key or the key word of the current block, and the value of the record is the block hash of the current block;
and acquiring the link information of the tail part of the linked list, linking the current block to the linked list, and updating the second mapping table.
5. A method for decentralized search over a blockchain, comprising:
s201, acquiring a primary key or a key word of transaction data to be searched and a current block hash of a binary tree root;
s202, searching in a third mapping table according to the current block hash to obtain a search result, wherein the search result comprises a main key or a keyword, a block hash of a left sub-tree and a block hash of a right sub-tree;
s203, judging whether the main key or the keyword to be searched is consistent with the main key or the keyword in the search result;
s204, when the judgment is consistent, acquiring transaction data of the block in the block chain according to the current block hash, and updating the block hash of the left sub-tree into the current block hash; when the judgment result shows that the two sub-trees are inconsistent, updating the block hash of the right sub-tree into the current block hash;
s205, judging whether the hash of the current block is zero, if so, continuing to execute S206; if not, executing S202;
and S206, outputting all inquired transaction data.
6. The method of claim 5, wherein the data table of the binary tree root includes a record for recording a block hash of the binary tree root, and the initial value is zero.
7. The method of claim 6, wherein the third mapping table comprises a plurality of key-value pairs, wherein the keys of the key-value pairs are block hashes, and the values of the key-value pairs comprise a primary key or a key word, a block hash of a left sub-tree, and a block hash of a right sub-tree.
8. The method of claim 7, further comprising:
when a new transaction block is generated:
s301, acquiring a block generated by a new transaction, and adding the block to a block chain; wherein the block generated by the new transaction has a first block hash;
s302, acquiring a second block hash of the binary tree root according to the data table of the binary tree root, wherein the binary tree root is a parent node of the current binary tree;
s303, when the second block hash is zero, newly adding a record in a third mapping table, where a primary key of the record is the first block hash, and a value of the record is: the key or keyword of the newly generated transaction data of the block, the block hash of the left sub-tree and the block hash of the right sub-tree are both zero;
judging whether the parent node of the current binary tree is a binary tree root or not;
if so, setting the data table of the binary tree root as a first block hash;
if not, judging whether the main key or the key word of the father node is the same as the main key or the key word of the transaction data of the newly generated block;
if yes, setting the left sub-tree of the father node as a first block hash, and executing S306;
if not, setting the right subtree of the father node as a first block hash, and executing S306;
s304, when the second block hash is not zero, searching in a third mapping table by using the second block hash to obtain a search result, wherein the search result is a current binary tree father node;
s305, judging whether the main key or the key word of the search result is the same as the main key or the key word of the transaction data of the newly generated block;
if so, updating the block hash of the left sub-tree of the search result to be the second block hash, and executing S303;
if not, updating the block hash of the right subtree of the search result to be a second block hash, and executing S303;
s306, adding the newly generated block into the binary tree.
9. A node for implementing decentralized search over a blockchain, comprising a memory and a processor, the memory storing a computer program, the computer program being executable by the processor to implement the method for implementing decentralized search over a blockchain according to any one of claims 1 to 8.
10. A blockchain network comprising a plurality of nodes according to claim 9, wherein each node is communicatively connected via a point-to-point network.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010904403.4A CN111984732B (en) | 2020-09-01 | 2020-09-01 | Method, node and blockchain network for implementing decentralization search on blockchain |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010904403.4A CN111984732B (en) | 2020-09-01 | 2020-09-01 | Method, node and blockchain network for implementing decentralization search on blockchain |
Publications (2)
Publication Number | Publication Date |
---|---|
CN111984732A true CN111984732A (en) | 2020-11-24 |
CN111984732B CN111984732B (en) | 2023-12-26 |
Family
ID=73447200
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010904403.4A Active CN111984732B (en) | 2020-09-01 | 2020-09-01 | Method, node and blockchain network for implementing decentralization search on blockchain |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111984732B (en) |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113505155A (en) * | 2021-07-06 | 2021-10-15 | 中国联合网络通信集团有限公司 | Transaction information retrieval method and retrieval device based on block chain network |
CN114723564A (en) * | 2022-06-01 | 2022-07-08 | 杭州天谷信息科技有限公司 | Block chain generation method and block chain structure |
CN114756603A (en) * | 2022-05-23 | 2022-07-15 | 天津大学 | High-efficiency verifiable query method for lightweight block chain |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN109189782A (en) * | 2018-08-02 | 2019-01-11 | 哈尔滨工程大学 | A kind of indexing means in block chain commodity transaction inquiry |
US20190042620A1 (en) * | 2017-08-01 | 2019-02-07 | International Business Machines Corporation | Optimizing queries and other retrieve operations in a blockchain |
-
2020
- 2020-09-01 CN CN202010904403.4A patent/CN111984732B/en active Active
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20190042620A1 (en) * | 2017-08-01 | 2019-02-07 | International Business Machines Corporation | Optimizing queries and other retrieve operations in a blockchain |
CN109189782A (en) * | 2018-08-02 | 2019-01-11 | 哈尔滨工程大学 | A kind of indexing means in block chain commodity transaction inquiry |
Non-Patent Citations (1)
Title |
---|
珞沫: "详解二叉排序树(二叉搜索树、二叉查找树)以及Python实现相关操作", pages 332 - 6, Retrieved from the Internet <URL:https://blog.csdn.net/weixin_45666566/article/details/107984974> * |
Cited By (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113505155A (en) * | 2021-07-06 | 2021-10-15 | 中国联合网络通信集团有限公司 | Transaction information retrieval method and retrieval device based on block chain network |
CN113505155B (en) * | 2021-07-06 | 2023-05-12 | 中国联合网络通信集团有限公司 | Transaction information retrieval method and retrieval device based on blockchain network |
CN114756603A (en) * | 2022-05-23 | 2022-07-15 | 天津大学 | High-efficiency verifiable query method for lightweight block chain |
CN114756603B (en) * | 2022-05-23 | 2023-04-07 | 天津大学 | High-efficiency verifiable query method for lightweight block chain |
CN114723564A (en) * | 2022-06-01 | 2022-07-08 | 杭州天谷信息科技有限公司 | Block chain generation method and block chain structure |
CN114723564B (en) * | 2022-06-01 | 2022-10-28 | 杭州天谷信息科技有限公司 | Block chain generation method and block chain structure |
Also Published As
Publication number | Publication date |
---|---|
CN111984732B (en) | 2023-12-26 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN111984732B (en) | Method, node and blockchain network for implementing decentralization search on blockchain | |
JP4263477B2 (en) | System for identifying common digital sequences | |
US7478113B1 (en) | Boundaries | |
CN108446376B (en) | Data storage method and device | |
US7769719B2 (en) | File system dump/restore by node numbering | |
CN109586896B (en) | Data integrity verification method based on Hash prefix tree | |
EP3371717A1 (en) | Virtual edge of a graph database | |
CN110888837B (en) | Object storage small file merging method and device | |
US11544150B2 (en) | Method of detecting source change for file level incremental backup | |
CN107391557B (en) | Block chain serial query method and system for setting out-of-chain fault table | |
CN111045860A (en) | Improving conflict resolution within synchronized composite part-based digital assets | |
CN107463596B (en) | Block chain parallel query method and system for setting out-of-chain fault table | |
CN107451177B (en) | Query method and system for single error-surveying block chain of increased blocks | |
US20070101127A1 (en) | Method of digitally signing data and a data repository storing digitally signed data | |
CN109359481B (en) | Anti-collision search reduction method based on BK tree | |
US10061654B1 (en) | Depth first search of summary change log records for backup | |
CN113986942B (en) | Message queue management method and device based on man-machine conversation | |
CN114840487A (en) | Metadata management method and device for distributed file system | |
CN111444194B (en) | Method, device and equipment for clearing indexes in block chain type account book | |
Kniesburges et al. | Hashed Patricia Trie: Efficient longest prefix matching in peer-to-peer systems | |
CN108984780B (en) | Method and device for managing disk data based on data structure supporting repeated key value tree | |
CN111698330A (en) | Data recovery method and device of storage cluster and server | |
WO2019176011A1 (en) | Retrieval sentence utilization device and retrieval sentence utilization method | |
US11847137B2 (en) | Database synchronization using resizable invertible bloom filters with database snapshots | |
CN117131023B (en) | Data table processing method, device, computer equipment and readable 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 | ||
CB02 | Change of applicant information | ||
CB02 | Change of applicant information |
Address after: 361000 one of 504, No. 18, guanri Road, phase II, software park, Xiamen, Fujian Applicant after: XIAMEN YILIANZHONG YIHUI TECHNOLOGY CO.,LTD. Address before: Room 504, No.18, guanri Road, phase II, software park, Xiamen City, Fujian Province, 361000 Applicant before: XIAMEN YILIANZHONG YIHUI TECHNOLOGY CO.,LTD. |
|
GR01 | Patent grant | ||
GR01 | Patent grant |