Block chain data search method, device and equipment
By applying the congruence theorem formula in blockchain to divide data areas, the problems of low efficiency and complex management of blockchain data search are solved, and efficient parallel search and reduced maintenance costs are achieved.
Patent Information
- Application Number
- CN202311618900.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-29
- Publication Date
- 2025-05-30
AI Technical Summary
Existing blockchain data search methods are inefficient, especially when blockchain continues to grow, serial search speed is slow, parallel search algorithms are complex, and distributed search has data latency and inconsistency problems, which increases management difficulty and maintenance costs.
Drawing on the congruent theorem formula in number theory, integrating the target business index into mathematical formulas, and regionally dividing the blockchain data through the congruent theorem to realize parallel search, avoiding nodes tracking blocks in each subset, and reducing computing power and storage overhead.
It realizes efficient parallel search of blockchain data, reduces the additional overhead of search paths and data maintenance, and improves system performance and management efficiency.
Smart Images

Figure CN120067404A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of blockchain technology, and in particular, to a blockchain data search method, device and equipment. Background Art
[0002] In order to reduce the space complexity, the blockchain restricts the direct storage of transaction and status data on the chain. Ethereum recommends using the MPT data structure to store data and saving the root hash on the blockchain to ensure the immutability of the data. In the prior art, the data of the blockchain system can be searched for data blocks and transactions of the blockchain in a serial search, parallel search or distributed search manner.
[0003] The serial search sequentially searches for data blocks and transactions of the blockchain in order, traversing data blocks and transactions one by one. The search efficiency is low. When the blockchain continues to grow and becomes larger and larger, the search speed will slow down, and the load on the nodes will increase, affecting the system performance.
[0004] In parallel search, by decomposing the search task into multiple subtasks and assigning them to multiple processors for parallel execution, each processor is responsible for its own search task, and finally the results are merged. However, due to the relatively complex algorithm design, problems such as data partitioning, task assignment, and result merging need to be considered, increasing the complexity of the algorithm. At the same time, in order to implement parallel search operations, the node needs to track the blocks existing in each subset, thus generating additional overhead for maintaining disjoint subsets.
[0005] In distributed search, the blockchain data is divided into multiple parts, and each part is assigned to different nodes for search, and finally the search results are merged. However, due to possible delays and inconsistencies in the data of different nodes, the search results may not be completely consistent; and distributed search requires the management and maintenance of multiple computing nodes, including node connection, data synchronization, etc., increasing the management difficulty and maintenance cost. Summary of the Invention
[0006] The embodiments of the present application provide a blockchain data search method, device and equipment. On the basis of the existing blockchain parallel search, referring to the congruence theorem formula in number theory, the target service index is incorporated into the mathematical formula to solve the problem of regional division of the blockchain. Nodes do not need to track the blocks existing in each subset, saving the computing power and storage overhead generated for maintaining the search paths of disjoint subsets.
[0007] In a first aspect, the present application provides a blockchain data search method, which is applied to a blockchain node and includes:
[0008] In response to a data search instruction, at least one target business record index is determined according to the search instruction, and the target business record index is a parameter related to at least one of the business initiator and the recipient in the business record;
[0009] Determine k search regions into which each block is divided. Among them, by performing a modulo operation on the business record index of each business record in each block using the congruence theorem formula and the modulus k, and determining each business record with the same remainder as a search region to obtain the k search regions;
[0010] Perform a modulo operation on each target business record index using the congruence theorem formula and the modulus k, and determine the search region corresponding to the target remainder as the target search region;
[0011] For each target search region corresponding to each target remainder, perform data search using a parallel search method.
[0012] In some possible embodiments, the determining at least one target business record index according to the search instruction includes:
[0013] When it is determined that the search instruction carries a target keyword field and does not carry a target business record index, determine the mapping relationship between each different keyword field established in advance and the key of the business record containing the keyword field;
[0014] Based on the mapping relationship, determine all keys corresponding to the target keyword field;
[0015] Traverse the target business records corresponding to all keys, and determine the business record index in the target business records as at least one target business record index.
[0016] In some possible embodiments, determining at least one target business record index according to the search instruction includes:
[0017] Obtain at least one target business record index carried in the search instruction from the search instruction.
[0018] In some possible embodiments, determining k search regions into which each block is divided includes:
[0019] According to a preset modulus k value or a default modulus k, divide each block into k search regions by using a static division method; or
[0020] Obtain the k value from the search instruction, and divide each block into k search regions by using a dynamic method.
[0021] In some possible embodiments, the search instruction carries a search range, and the search range includes a start block and an end block. Determining k search regions into which each block is divided includes:
[0022] Determine the k search regions into which each block in the search range is divided.
[0023] In some possible embodiments, the search instruction carries a search quantity. For each target remainder corresponding to a target search region, data search is performed using a parallel search method, including:
[0024] For each target remainder corresponding to a target search region, data search is performed using a parallel search method. When it is determined that the number of service records searched reaches the search quantity, stop the parallel search.
[0025] In some possible embodiments, the performing data search on each target remainder corresponding to a target search region using a parallel search method includes:
[0026] When there is one target remainder, perform data search on the target search region corresponding to this target remainder, or any other blockchain node performs data search on the target search region corresponding to this target remainder;
[0027] When there are multiple target remainders, perform parallel search on the target search regions corresponding to the multiple target remainders, or any other blockchain node performs parallel search on the target search regions corresponding to the multiple target remainders, or cooperate with at least one other blockchain node to perform parallel search on the target search regions corresponding to the multiple target remainders.
[0028] In a second aspect, the present application provides a blockchain data search device, and the device includes:
[0029] A first determination module, in response to a data search instruction, determines at least one target service record index according to the search instruction, and the target service record index is a parameter related to at least one of the service initiator and the recipient in the service record;
[0030] A second determination module determines the k search regions into which each block is divided. Among them, by performing a remainder operation on the service record index of each service record in each block through the congruence theorem formula and the modulus value k, and determining each service record with the same remainder as a search region to obtain the k search regions;
[0031] A third determination module performs a remainder operation on each target service record index through the congruence theorem formula and the modulus value k, and determines the search region corresponding to the target remainder as the target search region;
[0032] A search module performs data search on each target remainder corresponding to a target search region using a parallel search method.
[0033] In a third aspect, the present application provides an electronic device, and the electronic device includes:
[0034] At least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the blockchain data search method as described in any one of the first aspect.
[0035] In a fourth aspect, the present application provides a computer storage medium storing a computer program for causing a computer to execute the blockchain data search method as described in any one of the first aspect.
[0036] According to a blockchain data search method, apparatus and device provided by the present application, on the basis of existing blockchain parallel search, by referring to the congruence theorem formula in number theory, integrating the target service index into a mathematical formula, solving the problem of blockchain region division, nodes can achieve parallel search of blockchain data without tracking the blocks existing in each subset, thus eliminating the need to maintain additional search paths and the additional overhead generated by data. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] The accompanying drawings herein are incorporated into the specification and constitute a part of the specification, showing embodiments consistent with the present application, and are used together with the specification to explain the principles of the present application, and do not constitute an improper limitation to the present application.
[0038] Figure 1 Schematic diagram of an existing blockchain system provided by an embodiment of the present application;
[0039] Figure 2 Schematic diagram of key-value pair storage of blockchain data provided by an embodiment of the present application;
[0040] Figure 3 Flowchart of a blockchain data search method provided by an embodiment of the present application;
[0041] Figure 3 (a) Schematic diagram of blockchain data storage provided by an embodiment of the present application;
[0042] Figure 4 Schematic diagram of a block on a blockchain provided by an embodiment of the present application;
[0043] Figure 5 Schematic diagram of block region division provided by an embodiment of the present application;
[0044] Figure 6 Schematic diagram of a target search region provided by an embodiment of the present application;
[0045] Figure 7 Schematic diagram of an MPT search process provided by an embodiment of the present application;
[0046] Figure 8 Flowchart of a blockchain data search method provided by an embodiment of the present application;
[0047] Figure 9 Diagram of the storage method of keyword fields on the chain provided by an embodiment of the present application;
[0048] Figure 10 Diagram of an example of a keyword field provided by an embodiment of the present application;
[0049] Figure 11 Diagram of an example of a keyword field provided by an embodiment of the present application;
[0050] Figure 12 Flowchart of a blockchain data search method provided by an embodiment of the present application;
[0051] Figure 13 Schematic diagram of the block search range provided by an embodiment of the present application;
[0052] Figure 14 Flowchart of a blockchain data search method provided by an embodiment of the present application;
[0053] Figure 15 Overall flowchart of a blockchain search provided by an embodiment of the present application;
[0054] Figure 16 Schematic diagram of the process of parallel blockchain search provided by an embodiment of the present application;
[0055] Figure 17 Diagram of a blockchain data search device provided by an embodiment of the present application;
[0056] Figure 18 Diagram of a blockchain data search device according to an embodiment;
[0057] Figure 19 Diagram of a storage medium for blockchain data search provided by an embodiment of the present application. Detailed implementation manners
[0058] The technical solutions in the embodiments of the present application will be clearly and fully described below with reference to the accompanying drawings. Apparently, the described embodiments are only a part of the embodiments of the present application, rather than all of them. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present application without creative efforts shall fall within the protection scope of the present application.
[0059] To further illustrate the technical solutions provided by the embodiments of the present application, the following will provide a detailed description in combination with the accompanying drawings and specific implementation manners. Although the embodiments of the present application provide method operation steps as shown in the following embodiments or drawings, based on routine or non-creative labor, more or fewer operation steps may be included in the method. In steps where there is no necessary causal relationship logically, the execution order of these steps is not limited to the execution order provided by the embodiments of the present application. When the method is actually processed or executed by a control device, it can be executed in the method order shown in the embodiments or drawings or executed in parallel.
[0060] First, the relevant concepts in the embodiments of the present application will be described:
[0061] In the existing blockchain structure, such as Figure 1 shown, the business records of each node in the blockchain are the same. To reduce the space complexity, the blockchain restricts directly storing transaction and state data on the chain. Ethereum recommends using the MPT (Merkle Patricia Trie) data structure to store data and saves the root hash on the blockchain to ensure the immutability of the data.
[0062] There are the following three ways to search for existing blockchain data:
[0063] ① Serial search: Sequentially search the data blocks and transactions of the blockchain in order. Disadvantage: The search efficiency is low. Serial search needs to traverse each data block and transaction one by one. When the blockchain continues to grow and becomes larger and larger, it will lead to a slow search speed and increase the load on the nodes, affecting the system performance.
[0064] ② Parallel search: Design a reasonable parallel algorithm to achieve simultaneous search for multiple data blocks and transactions. By decomposing the search task into multiple subtasks and allocating them to multiple processors for parallel execution, each processor is responsible for its own search task, and finally the results are merged. Disadvantage: The algorithm design is relatively complex, but the algorithm complexity is high; in order to implement parallel search, the operation nodes need to track the blocks existing in each subset, thus generating additional overhead for maintaining non-overlapping subsets.
[0065] ③ Distributed search: Divide the blockchain data into multiple parts and allocate each part to different nodes for search. Each node searches the data part it is responsible for, and finally merges the search results. Disadvantage: It cannot guarantee the data consistency. The data of different nodes may have delays and inconsistencies, so the search results in distributed search may not be completely consistent; the management is complex, and multiple computing nodes need to be managed and maintained, including node connection, data synchronization, etc., increasing the management difficulty and maintenance cost.
[0066] In view of the above problems, the present application invents a blockchain data search method, which first introduces a new MPT data structure into the blockchain architecture. The core idea of the MPT structure is to decompose data into key-value pairs, as Figure 2 shown, and use a hash function to perform a hash operation on the key. Its features are as follows: ① It can store key-value pair data of any length, which is suitable for storing and retrieving a large number of key-value pairs; ② It provides a mechanism for quickly calculating the hash identifier of the maintained data set, and uses path compression technology so that the same prefix or subtree can be shared by multiple keys. Therefore, the MPT structure can verify the integrity of data by comparing hash values, and can also quickly locate specific data through hash values, providing efficient data verification and retrieval capabilities.
[0067] In the blockchain data search method based on MPT, the present application divides the blockchain data into non-overlapping transaction subsets to achieve parallel search. When dividing the search area, referring to the congruence theorem formula in number theory, the address of the transaction initiator is incorporated into the mathematical formula to solve the complex problem of blockchain area division and achieve parallel search of blockchain data.
[0068] Therefore, the basis of the present invention is a mechanism for introducing the MPT data structure for search, which uses a single parameter to query transactions in the blockchain. Therefore, any transaction field can be used for search requests. For example, in the blockchain, the parameters of a transaction may include but are not limited to the following: 1. Sender Address: The wallet address or identity identifier that initiates the transaction. 2. Recipient Address: The wallet address or identity identifier that receives the transaction. 3. Transaction Amount: Indicates the quantity of currency or other assets involved in this transaction. 4. Transaction Fee, to ensure that the transaction is packaged and confirmed. 5. Timestamp: The time when the transaction occurs. 6. Digital Signature: An encrypted signature used to verify the legality of the transaction, ensuring the authenticity and integrity of the transaction. 7. Transaction Data: An optional parameter that may contain some additional transaction information, such as remarks, text messages, etc. 8. Transaction Hash: The unique identifier of the transaction, generated through a hash algorithm. The present invention regards the sender address (initiator address) as the parameter for querying transactions in the blockchain.
[0069] A blockchain data search method provided by an embodiment of the present application is applied to a blockchain node, as Figure 3 shown, and includes:
[0070] Step S301: In response to a data search instruction, determine at least one target business record index according to the search instruction. The target business record index is a parameter related to at least one of the business initiator and the recipient in the business record.
[0071] The blockchain system includes blockchain nodes, and the data contained in each blockchain node is the same. The blockchain nodes are divided into multiple blocks. When data is stored, that is, when each business record is generated, it will be stored in each corresponding block on each blockchain node, as shown in Figure 3 (a); The business record index can index each business record and is some key parameters in the business record. For example, it can be parameters related to transactions or data, parameters related to at least one of the initiator or the recipient, parameters related to transaction fees or transaction amounts, etc. Since each business record generation involves the interaction of data or information of the business initiator or the recipient, the addresses of the business initiator and the recipient are included in each business record. Therefore, the address of the business initiator, the address of the business recipient, or the addresses of both the business initiator and the recipient can be used as the business record index. As a preferred way, in the embodiments of the present application, the address of the business initiator is used as the business record index, and the business record index determined according to the search instruction is the target business record index.
[0072] The user inputs multiple search parameters for searching. The search instruction includes the search parameters input by the user. There are two ways to determine the search parameters. Way 1: The search parameter itself is the target business record index. Way 2: The target business record index is determined according to the mapping relationship between the search parameter and the target business record index.
[0073] Step S302: Determine k search regions into which each block is divided. Among them, by performing a modulo operation on the business record index of each business record in each block through the congruence theorem formula and the modulus k, and determining each business record with the same remainder as a search region to obtain the k search regions.
[0074] When dividing the search regions, since a modulo operation is performed on the business record index, that is, the address of the initiator or the recipient, to obtain k different regions, for each block, each block is also divided into k search regions, and each business record with the same remainder in each block is merged and determined as a search region.
[0075] The congruence theorem is briefly described below: If two integers a and b have the same remainder when divided by a positive integer m, then these two integers are congruent with respect to this positive integer, and it is said that a and b are congruent modulo m, denoted as a ≡ b (mod m). For example, 17 ≡ 11 (mod 3), indicating that 17 and 11 are congruent modulo 3.
[0076] The formula used in this application for search area division is R(U i )≡Adr(U i )(mod k), where Adr(U i ) is the address of the transaction initiator or recipient, and it is also the unique identifier of the transaction initiator or recipient in the blockchain network. k is the number of divided areas, and R(U i ) is the storage area. For example, the address of the transaction initiator or recipient can be Adr(U 1 ) = 0x9580f8897a4ed6db, which is essentially a 16-bit number, so a mathematical modulo operation can be performed.
[0077] Specifically, as Figure 4 shown, Block1 and Block2 are two blocks on the blockchain, and each block contains business records. When the value of k is 3, that is, when the data on the blockchain is divided into 3 search areas, the business records in each block, as Figure 5 shown, all belong to 3 different areas R0, R1, and R2. Those belonging to the R0 search area are transactions T1, T5, T7, T2. Those belonging to the R1 search area are transactions T3, T4, T9. Those belonging to the R2 search area are T6 and T8.
[0078] Step S303: Perform a modulo operation on each target business record index through the congruence theorem formula and the modulus value k to determine the search area corresponding to the target remainder as the target search area;
[0079] When performing data search, perform a modulo operation on the business records included in the search parameters determined in step S301, that is, the address of the initiator or recipient, to quickly locate the search area. As Figure 6 shown, if the initiator address is known to be U1, then without traversing all search areas, the search area can be quickly located as R0.
[0080] Step S304: For each target remainder corresponding to the target search area, perform data search using a parallel search method.
[0081] When performing parallel search on data, there are three search methods:
[0082] Search method one: Perform parallel search for different search areas on a single blockchain node;
[0083] Search method two: Multiple blockchain nodes cooperate to perform parallel search, and each blockchain node is responsible for at least one search area search task.
[0084] Search method three: Multiple blockchain nodes cooperate to perform parallel search, and each blockchain node is only responsible for one search area search task.
[0085] This application draws on the congruence theorem formula in number theory, incorporates the address of the initiator as a service index into a mathematical formula, and solves the problem of non - overlapping subsets in the regional division of the blockchain. This way of dividing the search area enables nodes to perform parallel search of blockchain data without having to track the blocks existing in each subset, thus eliminating the need to maintain additional search paths and the extra overhead generated by data.
[0086] In some possible embodiments, for each target remainder corresponding to a target search area, a parallel search method is used to search for data, as Figure 7 shown, including:
[0087] Step S701, when there is one target remainder, search for data in the target search area corresponding to this target remainder, or any other blockchain node searches for data in the target search area corresponding to this target remainder;
[0088] Step S702, when there are multiple target remainders, perform a parallel search in the target search areas corresponding to the multiple target remainders, or any other blockchain node performs a parallel search in the target search areas corresponding to the multiple target remainders, or cooperate with at least one other blockchain node to perform a parallel search in the target search areas corresponding to the multiple target remainders.
[0089] Specifically, when performing a search according to a search instruction, there are two possible ways:
[0090] Way 1: When there is one target remainder corresponding to the target service index, find the blockchain node responsible for searching in the target search area where this target remainder is located, that is, find the blockchain node responsible for this search area to search for data.
[0091] Way 2: When there are multiple target remainders corresponding to the target service index, it is necessary to search in multiple target search areas. According to the three search schemes mentioned above in the description, the blockchain nodes performing the search task may be multiple nodes or one node.
[0092] When determining the target service record index according to the search instruction, there are two possible situations:
[0093] Situation 1: When the parameter in the search instruction does not carry the target service record index.
[0094] In some possible embodiments, determining at least one target service record index according to the search instruction, as Figure 8 shown, includes:
[0095] Step S801, when it is determined that the search instruction carries the target keyword field and does not carry the target business record index, determine the mapping relationship established in advance between each different keyword field and the key of the business record containing the keyword field;
[0096] When storing data, as Figure 9 shown, the keyword fields are stored on the blockchain in the form of key-value pairs. The key is the hash value describing the keyword field, and the hash value is the unique identifier of each keyword field. The value is the content contained in the keyword field. Specifically, where is the key of each business record related to the keyword field.
[0097] Step S802, based on the mapping relationship, determine all keys corresponding to the target keyword field;
[0098] As Figure 10 shown, if the keyword field is keyword field 1, the corresponding keys are key1, key2, key6...; as Figure 11 shown, if the keyword field is keyword field 2, the corresponding keys are, key1, key8, key13...
[0099] Step S803, traverse the target business records corresponding to all keys, and determine the business record index in the target business records as at least one target business record index.
[0100] Since in each business record, the key is the unique identifier, and at the same time, each business record has the address of the business initiator or recipient (the address of the initiator or recipient is the target business record index), the addresses of the initiator or recipient in different business records may be the same. Therefore, by traversing all keys, at least one target business record index can be determined.
[0101] Case 2: When the parameter in the search instruction carries the target business record index.
[0102] In some possible embodiments, determining at least one target business record index according to the search instruction includes:
[0103] Obtain at least one target business record index carried by the search instruction from the search instruction.
[0104] If the search instruction carries one or more target business record indexes, then directly determine the target search area and the node responsible for executing the tasks in the target search area according to the target business record index.
[0105] After determining the target search area and the blockchain node that performs the search task on the target search area, data is searched in the target search area using the MPT data structure. For example, when searching for 3 transaction data using the MPT structure in the same target search area: ① 0x801…6: value 1; ② 0xd6503…7: value 2; ③ 0xd65h2…8: value 3. It should be noted that ①②③ are key-value pairs of 3 transaction data. The key is a hash string, and the value contains the specific information of the transaction. When the key of the transaction data is known, the specific information of the transaction must be obtained through searching using the MPT structure. Figure 12 shows the prefixes of 3 transaction keys starting with 8 and d in the MPT structure search. Therefore, the MPT has two branches at the root node. There is only one transaction starting with 8, and the value of transaction ① is directly stored on the leaf node; the other subtree uses 65 as the common prefix of the two transaction keys, so transactions ② and ③ are stored on an extended node, and next is used to continue searching downward. Finally, for the two different prefixes 0 and h, the corresponding transactions are stored on the leaf nodes of different branches. The specific transactions stored on the nodes during the entire search process are the final search targets.
[0106] In some possible embodiments, k search areas divided for each block are determined, as Figure 13 shown, including:
[0107] Step S1301, according to the preset modulus value k or the default modulus value k, each block is divided into k search areas by using a static division method; or
[0108] Step S1302, obtain the value of k from the search instruction, and divide each block into k search areas by using a dynamic method.
[0109] When dividing the search area, there are the following two division methods:
[0110] Method 1: Static division method.
[0111] Modify or set the default modulus value k in advance. If it is not set or modified in advance, it is set to the default value. The search area is divided in advance before executing the search instruction, and the search tasks of different search areas are assigned to the same or different blockchain nodes. Each time a search is performed, parallel search of data is performed based on the divided search area.
[0112] Method 2: Dynamic division method.
[0113] The area is not divided before receiving the search instruction. After receiving the search execution, the area is dynamically divided according to the number k of area divisions in the search instruction. Dynamic division means that it is divided according to the k carried in each search instruction. Therefore, the number k of search areas divided during each search may be the same or different, and it is set according to the search requirements.
[0114] In some possible embodiments, the search instruction carries a search range, and the search range includes a starting block and an ending block. Determining the k search areas into which each block is divided includes:
[0115] Determining the k search areas into which each block within the search range is divided.
[0116] When searching for data on the blockchain, it is not to search all the data on the blockchain, but it is possible to select a certain range of blocks for searching. For example, Figure 14 as shown, search for the target business record by searching the data within the range of the starting block 2 and the ending block n.
[0117] In some possible embodiments, the search instruction carries a search quantity. For each target remainder corresponding to a target search area, data search is performed using a parallel search method, including:
[0118] For each target remainder corresponding to a target search area, data search is performed using a parallel search method. When it is determined that the number of business records searched reaches the search quantity, stop the parallel search. For example, when the search range of the block is from the 2nd to the 5th block, each block contains 20,000 business data, and there are a total of 80,000 data in the 2nd to 5th blocks. If the search quantity is set to 70,000 at this time, according to the storage order of the data and the structure of the block, select the first 70,000 business records as the basis for search area division. If the search quantity is not set in advance, by default, all the business records in the 2nd to 5th blocks are used as the basis for search area division.
[0119] Each block contains a certain number of business records. To improve the search efficiency during search, a certain amount of data within the range of the starting block and the ending block can be set. When the search quantity is completed, stop the search.
[0120] Based on the existing parallel search of the blockchain, this invention draws on the congruence theorem formula in number theory, integrates the target business index into a mathematical formula, and divides the regions simply and clearly. It not only covers all regions but also does not generate intersections, solving the problem of regional division of the blockchain, avoiding the complexity of parallel algorithms. Nodes do not need to track the blocks existing in each subset, and can achieve parallel search of blockchain data. Thus, there is no need to maintain additional search paths and the additional overhead generated by data. Using the parameters in the formula, the address and search path of the transaction initiator can be quickly located, greatly reducing the resource costs of management and maintenance.
[0121] Specifically, as Figure 15 shown, the overall process of blockchain search is described in detail as follows:
[0122] Step S1501, input parameters: [P[], k, sBlk, eBlk, num]
[0123] Among them, P[] = p 1 , p 2 , ··· are search parameters. The search parameters themselves can be parameters related to the initiator or the recipient, and the search parameters can also include any other parameters, such as the transfer amount, etc. Among them, there is at least one search parameter in P[]; k is the number of divided search regions; sBlk is the starting block of the search; eBlk is the ending block of the search; num is the number of business records to be searched.
[0124] Step S1502, determine whether there is a parameter p j that is the address of the initiator. If so, execute Step S1503; if not, then execute Step S1504;
[0125] Step S1503, if any parameter p j is the address of the initiator, then perform regional clouding on the initiator address according to the number k of divided regions, and calculate: R ≡ p j (mod k), search the R th th search region, and execute SearchRegion(R, P[], sBlk, eBlk, num) for all parameters
[0126] Step S1504, if the parameter p j is not the address of the initiator, then create search threads for each search region R i (0 ≤ i ≤ k - 1) respectively to execute SearchRegion(R i , P[], sBlk, eBlk, num) for parallel search. The three schemes of parallel search have been described in detail above and will not be elaborated here.
[0127] Step S1505: Merge all search results into a complete result set.
[0128] Specifically, as Figure 16 shown, the process of parallel search on the blockchain is described in detail:
[0129] When the search parameter p is other parameters (for example, a transaction amount of 5000 yuan), the parameter p is defined in the form of key-value pairs: p:p→(key,value), where key is the unique identifier of the parameter p, and value contains business records with the same search content (a transaction amount of 5000 yuan). This parameter (i.e., the keyword field in the above description) is defined during storage, and business records with the same content are defined under the same key when saving content to the chain.
[0130] For example: The key-value pair of the search parameter for a transaction amount of 5000 yuan is: p(5000 yuan transaction amount): p→(0x123……,[T1,T4,T7,T9……]) indicating that the business records containing the content of 5000 transaction amount are T1, T4, T7, T9…… respectively. Transaction T1:U2→U6 represents the business record initiated by U2 to U6. U2 is the business initiator address. Substitute U2:0x456…… into the formula R x =U 2 (modk) to obtain the search area Rx, and finally use the MPT structure to complete the parallel search in the Rx search area.
[0131] Based on the same inventive concept, the present application also provides a blockchain data search device, as Figure 17 shown. The device includes:
[0132] A first determination module 1701, in response to a data search instruction, determines at least one target business record index according to the search instruction. The target business record index is a parameter related to at least one of the business initiator and the recipient in the business record;
[0133] A second determination module 1702 determines k search areas divided for each block. Among them, by performing a modulo operation on the business record indexes of each business record in each block through the congruence theorem formula and the modulus k, and determining each business record with the same remainder as a search area to obtain the k search areas;
[0134] A third determination module 1703 performs a modulo operation on each target business record index through the congruence theorem formula and the modulus k, and determines the search area corresponding to the target remainder as the target search area;
[0135] A search module 1704 performs data search on each target search area corresponding to the target remainder by using a parallel search method.
[0136] In some possible embodiments, determining at least one target service record index according to the search instruction includes:
[0137] When it is determined that the search instruction carries a target keyword field and does not carry a target service record index, determining the mapping relationship between each different keyword field established in advance and the key of the service record including this keyword field;
[0138] Based on the mapping relationship, determining all keys corresponding to the target keyword field;
[0139] Traversing the target service records corresponding to all keys, and determining the service record index in the target service records as at least one target service record index.
[0140] In some possible embodiments, the first determination module 1701 determines at least one target service record index according to the search instruction, including:
[0141] Obtaining at least one target service record index carried by the search instruction from the search instruction.
[0142] In some possible embodiments, the second determination module 1702 determines k search regions into which each block is divided, including:
[0143] Dividing each block into k search regions in a static division manner according to a preset modulus value k or a default modulus value k; or
[0144] Obtaining the value of k from the search instruction, and dividing each block into k search regions in a dynamic manner.
[0145] In some possible embodiments, the search instruction carries a search range, and the search range includes a start block and an end block. Determining k search regions into which each block is divided includes:
[0146] Determining k search regions into which each block within the search range is divided.
[0147] In some possible embodiments, the search instruction carries a search quantity, and the search module 1704 performs data search on the target search regions corresponding to each target remainder by using a parallel search method, including:
[0148] Performing data search on the target search regions corresponding to each target remainder by using a parallel search method, and stopping the parallel search when it is determined that the quantity of the service records searched reaches the search quantity.
[0149] In some possible embodiments, for the target search regions corresponding to each target remainder, the search module 1704 performs data search by using a parallel search method, including:
[0150] When there is one target remainder, data search is performed on the target search area corresponding to the target remainder, or any other blockchain node performs data search on the target search area corresponding to the target remainder;
[0151] When there are multiple target remainders, parallel search is performed on the target search areas corresponding to the multiple target remainders, or any other blockchain node performs parallel search on the target search areas corresponding to the multiple target remainders, or collaborates with at least one other blockchain node to perform parallel search on the target search areas corresponding to the multiple target remainders.
[0152] Based on the same inventive concept, the present application also provides an electronic device, as Figure 18 shown, including at least one processor; and a memory communicatively connected to the at least one processor; wherein, the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute a blockchain data search method in the above embodiments.
[0153] As Figure 18 shown, the device includes a processor 1801, a memory 1802, a communication interface 1803, and a bus 1804. Among them, the processor 1801, the memory 1802, and the communication interface 1803 are interconnected through the bus 1804.
[0154] The processor 1801 is configured to read and execute instructions in the memory 1802 to enable the at least one processor to execute the blockchain data search method provided in the above embodiments.
[0155] The memory 1802 is configured to store various instructions and programs of the blockchain data search method provided in the above embodiments.
[0156] The bus 1804 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of representation, Figure 18 only a thick line is used to represent it in the figure, but it does not mean that there is only one bus or one type of bus.
[0157] The processor 1801 may be a central processing unit (CPU), a network processor (NP), a graphic processing unit (GPU), or any combination of a CPU, an NP, and a GPU. It may also be a hardware chip. The above-mentioned hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The above-mentioned PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.
[0158] Based on the same inventive concept, the present application also provides a readable storage medium, as Figure 19 shown, the computer storage medium stores a computer program, and the computer program is used to cause the computer to execute any one of the methods in the above-mentioned embodiments.
[0159] The memory may include a readable medium in the form of volatile memory, such as a random access memory (RAM) 191 and / or a cache memory 1922, and may further include a read-only memory (ROM) 1923.
[0160] The memory may also include a program / utilities 1925 having a set (at least one) of program modules 1924. Such program modules 1924 include, but are not limited to: an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include the implementation of a network environment.
[0161] Those skilled in the art should understand that the embodiments of the present application may be provided as a method, a system, or a computer program product. Therefore, the present application may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk memories, CD-ROMs, optical memories, etc.) containing computer-usable program code.
[0162] This application is described with reference to the flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to the application. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, and the combination of flows and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, such that the instructions executed by the processor of the computer or other programmable data processing device produce means for implementing the functions specified in a process Figure 1 one process or multiple processes and / or blocks Figure 1 or means for implementing the functions specified in multiple blocks.
[0163] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, such that the instructions stored in the computer-readable memory produce a manufactured article including instruction means that implement the functions specified in a process Figure 1 one process or multiple processes and / or blocks Figure 1 or means for implementing the functions specified in multiple blocks.
[0164] These computer program instructions can also be loaded onto a computer or other programmable data processing device, such that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in a process Figure 1 one process or multiple processes and / or blocks Figure 1 or means for implementing the functions specified in multiple blocks.
[0165] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Thus, if these modifications and variations of this application fall within the scope of the claims of this application and their equivalent technologies, this application is also intended to include these modifications and variations.
Claims
1. A blockchain data search method, applied to a blockchain node, Characterized in that, Comprising: In response to a data search instruction, determining at least one target business record index according to the search instruction, where the target business record index is a parameter related to at least one of the business initiator and the recipient in the business record; Determining k search regions into which each block is divided, where, by using the congruence theorem formula and the modulus value k, performing a remainder operation on the business record indexes of each business record in each block, and determining each business record with the same remainder as a search region to obtain the k search regions; Performing a remainder operation on each target business record index by using the congruence theorem formula and the modulus value k, and determining the search region corresponding to the target remainder as the target search region; For each target remainder corresponding to the target search region, performing data search by using a parallel search method.
2. The method according to claim 1, Characterized in that, The determining at least one target business record index according to the search instruction includes: When it is determined that the search instruction carries a target keyword field and does not carry a target business record index, determining the mapping relationship between each different keyword field established in advance and the key of the business record containing the keyword field; Based on the mapping relationship, determining all keys corresponding to the target keyword field; Traversing the target business records corresponding to all keys, and determining the business record indexes in the target business records as at least one target business record index.
3. The method according to claim 1, Characterized in that, The determining at least one target business record index according to the search instruction includes: Obtaining at least one target business record index carried in the search instruction from the search instruction.
4. The method according to claim 1, Characterized in that, Determining k search regions into which each block is divided includes: According to the preset modulus value k or the default modulus value k, dividing each block into k search regions by using a static division method; or Obtaining the value of k from the search instruction, and dividing each block into k search regions by using a dynamic method.
5. The method according to claim 1, Characterized in that, The search instruction carries a search range, and the search range includes a start block and an end block. Determining k search regions into which each block is divided includes: Determining k search regions into which each block within the search range is divided.
6. The method according to claim 1, Characterized in that, The search instruction carries a search quantity. For each target remainder corresponding to the target search region, performing data search by using a parallel search method includes: For each target remainder corresponding to the target search region, performing data search by using a parallel search method, and stopping the parallel search when it is determined that the number of searched business records reaches the search quantity.
7. The method according to claim 1, Characterized in that, The performing data search by using a parallel search method for each target remainder corresponding to the target search region includes: When the target remainder is one, performing data search on the target search region corresponding to the target remainder, or performing data search on the target search region corresponding to the target remainder by any other blockchain node; When there are multiple target remainders, parallel search is performed on the target search areas corresponding to the multiple target remainders, or any other blockchain node performs parallel search on the target search areas corresponding to the multiple target remainders, or collaborates with at least one other blockchain node to perform parallel search on the target search areas corresponding to the multiple target remainders.
8. A blockchain data search device, the device comprising: A first determination module, in response to a data search instruction, determines at least one target business record index according to the search instruction, and the target business record index is a parameter related to at least one of the business initiator and the recipient in the business record; A second determination module determines k search areas into which each block is divided. Among them, the remainder operation is performed on the business record indexes of each business record in each block through the congruence theorem formula and the modulus value k, and the business records with the same remainder are determined as one search area to obtain the k search areas; A third determination module performs a remainder operation on each target business record index through the congruence theorem formula and the modulus value k, and determines the search area corresponding to the target remainder as the target search area; A search module performs data search on the target search areas corresponding to each target remainder by using a parallel search method.
9. An electronic device, characterized in that the electronic device includes: At least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the blockchain data search method according to any one of claims 1-7.