Block chain-based data index construction and query method, medium and electronic equipment
By determining the target path and assigning target indicator ranges in the blockchain, and building a distributed index of blockchain data, the problems of single node overload and low query efficiency are solved, and more efficient data queries are achieved.
Patent Information
- Application Number
- CN202411408727.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-10
- Publication Date
- 2025-01-17
- Estimated Expiration
- 2044-10-10
AI Technical Summary
When the prior art uses shard-based distributed indexing method in blockchain, it is easy to cause single node overload and low query efficiency.
By obtaining the query nodes and topology structure in the blockchain, the target path of the data index is determined, and the planning frame of each node is determined based on the planning frame format. Then, based on the total range of the indicator and the number of nodes on the target path, each node is assigned a target indicator range to build a query index for the target transaction data.
Allocate the data index of the target transaction data to multiple nodes to avoid concentrating the data query on a single or partial node and improve the efficiency of the data query business.
Smart Images

Figure CN119322794A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of data query, and more specifically, particularly relates to a data index construction and query method, medium and electronic device based on blockchain. Background Art
[0002] When processing large amounts of data, paging queries are usually used to retrieve data. Paging queries are a way for the front-end system (browser or app) to query data from the back-end system (blockchain, database or search engine). Since blockchain data evolves over time and needs to be updated regularly to keep up to date, the efficiency of data queries will inevitably affect the maintenance cost of the blockchain.
[0003] Related technologies have proposed the use of sharding-based distributed indexing in blockchains, but the sharding rules need to be maintained on a single node, which can easily cause single-node problems. In addition, this method stores the data of each shard on a single node, which can easily cause a single node to be overloaded during high-concurrency queries, affecting the efficiency of query services.
[0004] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present application, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention
[0005] The purpose of the present invention is to provide a data index construction and query method, medium and electronic device based on blockchain, which are used to solve the problem of low efficiency when searching blockchain data.
[0006] According to one aspect of an embodiment of the present application, a method for constructing a data index based on blockchain is provided, the method comprising:
[0007] Obtain the query node in the blockchain and the topological structure of the blockchain; the query node is the blockchain node used to query data in the blockchain;
[0008] Based on the query node and the topological structure of the blockchain, the target path for data indexing is determined; the length of the target path is related to the efficiency of the query business, and the nodes in the target path are not repeated;
[0009] Based on the specified planning frame format, determine the planning frame of any node of the target path; the planning frame includes the index of the transaction data and the total index range, the total index range is a data set composed of all index values, the index value and the transaction flag have a corresponding relationship, and the transaction flag is used to represent the target transaction data;
[0010] Based on the total indicator range and the number of nodes on the target path, a corresponding target indicator range is assigned to any node on the target path;
[0011] Build a query index for target transaction data based on the target indicator range and corresponding relationship.
[0012] In some embodiments, the planning frame also includes the contract address of the transaction data, and a query index for the target transaction data is constructed according to the target indicator range and the corresponding relationship, including: according to the contract address of the planning frame, extracting the target transaction data whose target address is the contract address from the block data; parsing the target indicator value from the target transaction data; when the target indicator value is within the target indicator range, determining the target transaction flag corresponding to the target indicator value according to the corresponding relationship; and recording the target transaction flag and the target indicator value in the node corresponding to the target indicator range.
[0013] In some embodiments, based on the total indicator range and the number of nodes in the target path, a corresponding target indicator range is allocated to any node on the target path, including: based on the total indicator range and the number of nodes in the target path, the total indicator range is evenly divided to obtain multiple target indicator ranges; according to the order of nodes in the target path, the target indicator range is allocated to the corresponding nodes.
[0014] In some embodiments, the method also includes: obtaining the number of hits and the number of historical queries for each node of the target path in the historical query task; the number of hits is the number of times the indicator value queried by the historical query task is distributed at a certain node; determining the hit probability of the node based on the number of hits and the number of historical queries; and adjusting the target indicator range based on the hit probability of each node.
[0015] In some embodiments, the first node and the second node are adjacent nodes on the target path, the hit probability of the first node is the first hit probability, the target indicator range of the first node is the first indicator range, the hit probability of the second node is the second hit probability, and the target indicator range of the second node is the second indicator range; according to the hit probability of each node, the target indicator range is adjusted, including: when the first hit probability is greater than the second hit probability, the exchange indicator range at the tail of the first indicator range is adjusted to the head of the second indicator range; when the first hit probability is less than the second hit probability, the exchange indicator range at the head of the second indicator range is adjusted to the tail of the first indicator range.
[0016] In some embodiments, based on the query node and the topological structure of the blockchain, determining the target path of the data index includes: based on the topological structure of the blockchain, determining the longest non-repetitive path starting from the initial query node; and determining the longest non-repetitive path as the target path.
[0017] According to one aspect of an embodiment of the present application, a data query method based on blockchain is provided, the method comprising:
[0018] Obtain the query information of this data query and the target index range of each query node; the query information includes the query index;
[0019] Determine the target node where the query indicator is located according to the target indicator range to which the query indicator belongs;
[0020] Find the transaction data corresponding to the query indicator from the target node.
[0021] In some embodiments, the query indicator is an indicator value or an indicator range, the indicator value and the transaction flag have a corresponding relationship, the transaction flag is used to represent the target transaction data, and the transaction data corresponding to the query indicator is searched from the target node, including: when the query indicator is an indicator value, searching the target transaction data corresponding to the indicator value from the target node; when the query indicator is an indicator range, searching the target transaction data corresponding to the indicator range from the target node; when the query indicator is an indicator range and the query information also includes a transaction flag, searching the target transaction data range corresponding to the indicator range from the target node, and searching the target transaction data corresponding to the transaction flag from the target transaction data range.
[0022] According to one aspect of an embodiment of the present application, a computer medium is provided, on which a computer program is stored. When the computer program is executed by a processor, a blockchain-based data index construction method or a blockchain-based data query method provided in any embodiment of the present application is implemented.
[0023] According to one aspect of an embodiment of the present application, an electronic device is provided, including: a processor; a memory for storing executable instructions of the processor; the processor executes the executable instructions to enable the electronic device to implement a blockchain-based data index construction method or a blockchain-based data query method provided in any embodiment of the present application.
[0024] In the technical solution of the present application, based on the query node and the topological structure of the blockchain, the target path of the data index is determined, wherein the length of the target path is related to the efficiency of the query service, and the nodes in the target path are not repeated; then based on the specified planning frame format, the planning frame of any node of the target path is determined, so that the information required for constructing the data index is recorded through the planning frame, so as to facilitate the subsequent acquisition of the target indicator value and the corresponding transaction flag when constructing the data index, and determine whether the transaction data is within the total indicator range, thereby determining whether to record the data index corresponding to the transaction data in the node on the target path; then based on the total indicator range and the number of nodes of the target path, the corresponding target indicator range is assigned to any node on the target path, and finally, according to the target indicator range and the corresponding relationship, the query index of the target transaction data is constructed, so that the data index of the target transaction data is assigned to multiple nodes, and the corresponding transaction data can be obtained based on each node in the blockchain. Then, when executing the query task, the node where the data index is located is queried first, and then the transaction data corresponding to the data index is queried from the node, without traversing all the transaction data, and it can also avoid concentrating on querying data on a single or part of the nodes, thereby improving the work efficiency of the data query service.
[0025] It should be understood that the above general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] The drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present application, and together with the specification are used to explain the principles of the present application. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0027] Figure 1 The figure schematically shows a flow chart of a method for constructing a data index based on blockchain provided in one embodiment of the present application.
[0028] Figure 2 A schematic diagram schematically shows the topological structure of a blockchain provided in an embodiment of the present application.
[0029] Figure 3 The structural diagram of the planning frame provided in an embodiment of the present application is schematically shown.
[0030] Figure 4 The structural diagram of the initial query node planning frame provided by an embodiment of the present application is schematically shown.
[0031] Figure 5 The structure diagram of a query node planning frame provided by an embodiment of the present application is schematically shown.
[0032] Figure 6 The structure diagram of a query node planning frame provided by an embodiment of the present application is schematically shown.
[0033] Figure 7 The figure schematically shows a flow chart of a blockchain-based data query method provided in one embodiment of the present application.
[0034] Figure 8 The structural block diagram of an electronic device provided by an embodiment of the present application is schematically shown.
[0035] Fig. 9 The computer system structure block diagram schematically shows the electronic device used to implement the embodiment of the present application. DETAILED DESCRIPTION
[0036] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this application will be more comprehensive and complete and fully convey the concept of the example embodiments to those skilled in the art.
[0037] In addition, the features, structures or characteristics described in the present application may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present application. However, those skilled in the art will appreciate that the technical scheme of the present application can be put into practice without one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known methods, devices, realizations or operations are not shown or described in detail to avoid blurring the various aspects of the present application.
[0038] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0039] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0040] First, the relevant technologies of data query are introduced. As described in the background technology, paging query is a way to query data. Usually, paging query is to query data in list form. The characteristics of the data list include: (1) the data elements of each column of the list are the same; (2) the list data is large in size; (3) the list can be sorted in ascending or descending order according to a certain element. For example, in an employee information management system, the employee information list is this form of data, in which each employee data in the system has the same elements, such as name, position, age and number (ID); if there are many employees, generally not all employee data will be queried and displayed at one time; the list can be sorted in ascending or descending order according to the dictionary order of employee names or the dictionary order of IDs. Paging query is a query method in which the list is sorted according to the set rules and then queried page by page. Paging query includes the following core parameters: (1) sorting field: which field the list data is sorted by; (2) sorting rule: generally ascending or descending order according to the value; (3) page size: how many data are contained in each page; (4) page number: which page of data is the current page under the specific sorting rule of the list. Taking the employee information management system as an example, the data is sorted in ascending order according to the lexicographical order of employee ID. The page size is 10 and the page number is 2. The data query process is: sort all employee information in the employee information management system in ascending order according to the lexicographical order of employee ID, that is, the data with the smallest lexicographical order is the first data in the list, the second smallest is the second data, and so on. Get the employee information list sorted in ascending order according to the lexicographical order of employee ID, and then take out the data from the 11th to the 20th in this list.
[0041] Blockchain data is generally stored in a kv type database, where k is generally a block hash. When the block hash is known, the corresponding block data can be quickly found. However, this storage structure is difficult to perform paging queries. Each query requires traversing all block data, parsing the block data and comparing the sorting fields to obtain an ordered sequence and return the paging query results, resulting in low data query efficiency. Related technologies use indexing technology to perform data queries, such as global indexing or distributed indexing. Global indexing is a common indexing method in centralized relational databases. Its characteristics are: (1) storing all data on a single server (including active and standby clusters); (2) storing indexes on a single server (including active and standby clusters) to accelerate queries; (3) indexing all data on a single server (including active and standby clusters). The advantage of this global index is that the implementation process is simple and there are no network and consistency problems common in distributed systems; however, the disadvantage is that it is prone to single node failures, and is prone to performance bottlenecks when querying large amounts of data and large concurrency, and has poor scalability. Sharded indexing is a common indexing method in distributed relational databases. Its characteristics are as follows: (1) the full data is divided into several shards, and each shard is distributed and stored in a single node; (2) the sharding rules are stored and maintained in a single node (generally this node is called the Master node). When querying data, it is first necessary to locate the shard and its node, and to divide a query on the full data into several sub-queries equivalently and execute them on the corresponding shard nodes; (3) each node only indexes the shard data of the node, and the Master node needs to summarize the results returned by the sub-queries of each shard node before the query results of the full data can be obtained. This shard-based distributed indexing method, whose sharding rules need to be maintained on a single node, has a single-node problem. In addition, the sharding scheme has poor flexibility and cannot cope well with changes in concurrent load. Although some schemes use dynamic sharding to distribute shards with large concurrent loads to other nodes, there is still the problem of shard data moving between shards, resulting in excessive network data circulation costs. Moreover, when querying by page, once a page of data is distributed on two nodes for query and aggregation, it will increase the system overhead. In order to solve the problem of single node overload or incompatibility with paging query in related technologies, Figure 1 As shown, the present application provides a data index construction method based on blockchain, which includes the following S110 to S150.
[0042] S110, obtaining a query node in the blockchain and a topological structure of the blockchain; the query node is a blockchain node in the blockchain used to query data.
[0043] Specifically, the topology of the blockchain in this application refers to the network shape formed by the query nodes communicating with each other. For example, query nodes N0 to N7 communicate with each other to form Figure 2 The blockchain topology shown in Figure 1. It should be noted that the blockchain is distributed, meaning that there is no single control point to store the entire data set. Instead, the data is distributed across multiple nodes in the network, and each node independently maintains local data. Therefore, query nodes N0 to N7 are several blockchain nodes specially built by the blockchain user who performs query services, which can synchronize data on the blockchain and perform data query services on these specific blockchain nodes without affecting the data processing work of other blockchain nodes.
[0044] S120. Based on the query node and the topological structure of the blockchain, determine the target path of the data index; the length of the target path is related to the efficiency of the query business, and the nodes in the target path are not repeated.
[0045] Specifically, an index refers to a structure that sorts the values of one or more columns in a database table. In this embodiment, the data index refers to the basis for querying transaction data. It should be understood that in different scenarios, indexes have different names, such as indexes can also be called keys or pointers. The target path refers to the path formed by the blockchain nodes that record the data index, and the blockchain nodes in the path are in order. For example, Figure 2 As shown, query nodes N0 to N7 form a target path {N0, N1, N3, N2, N4, N5, N7}, that is, the starting point of the target path is query node N0, the intermediate nodes are query nodes N1, N3, N2, N4 and N5 respectively, and the end point is query node N7.
[0046] Based on the query node and the topological structure of the blockchain, multiple paths connected by nodes can be obtained. Figure 2 Taking the blockchain shown as an example, the query node N0 is set as the current processing node, and the path starting from the query node N0 is determined. For example, path A{N0, N1, N3, N6}, or path B{N0, N2, N3, N6}, or path C{N0, N1, N3, N2, N4, N7}, or other paths can be obtained. Among them, the length of the target path depends on the efficiency requirements of the query business. If the efficiency requirements of the query business are high, the length of the target path should be extended as much as possible to distribute the data index to as many nodes as possible, so that the query data index does not need to be concentrated on a single node, causing the problem of node overload. Moreover, the nodes in the target path are not repeated, so that the data index can be distributed to different nodes, avoiding repeated allocation of some nodes, causing some nodes to bear too much load.
[0047] In some embodiments, based on the query node and the topological structure of the blockchain, determining the target path of the data index includes: based on the topological structure of the blockchain, determining the longest non-repetitive path starting from the initial query node; and determining the longest non-repetitive path as the target path.
[0048] Specifically, based on S110, we know that the query node set is M = {N0, N1, N2, N3, N4, N5, N6, N7}. Set query node N0 as the initial node, and return N0 to the known node list K0, that is, K0 = {N0}. The longest non-repeating path length starting from query node N0 is: L0(M) = 1 + L 1,2 (M-K0), that is, the longest non-repetitive path length starting from query node N0, is equal to the longest path formed by other query nodes except query node N0 plus 1. Since the longest non-repetitive path length needs to be connected to query node N0, that is, the longest non-repetitive path length starting from query node N1 or query node N2 without passing through query node N0 is: L 1,2 (M-K0) = Max{L1(M-K0), L2(M-K0)}. Similarly, the process of calculating the longest non-repeating path length starting from query node N2 without passing through query node N0 is similar to the process starting from query node N0. Put query node N2 into the known node list K2 = {N0, N2}, and the longest path L2(M-K0) = 1 + L 3,4 (M-K2). And so on, until there is only one node left that does not pass through the known node list, that is, the remaining path length is 1, and L0(M) can be found by backtracking. At this time, the node list plus the node with a remaining path length of 1 is the longest non-repeating path starting from N_0. The longest non-repeating path obtained is: {N0, N1, N3, N2, N4, N5, N7}.
[0049] S130. Based on the specified planning frame format, determine the planning frame of any node of the target path; the planning frame includes the index of the transaction data and the total index range, the total index range is a data set composed of all index values, the index value and the transaction flag have a corresponding relationship, and the transaction flag is used to represent the target transaction data.
[0050] Specifically, the specified planning frame format is a predefined index planning frame format. The specific format of the planning frame is as follows: Figure 3As shown, the field sequence number is the order of the fields in the planning frame, the field is the name of the corresponding field in the planning frame, and the data type is the data type of the corresponding field in the planning frame. The contract address is the location of the currently queried transaction data in the block. The indicator is the field that needs to be queried in the transaction data. For example, for a blockchain user, suppose that a paginated query is required for a certain digital collection according to the pending order price. At this time, in the planning frame, the contract address is the address of the digital collection transaction contract. The indicator is the pending order price of the digital collection. It should be understood that the indicator can be other fields besides the pending order price, and the field is not limited to the above Figure 3 The fields shown. The total range of the indicator is the data set formed by the maximum and minimum values allowed for the pending order price. The path length is the target path length of the blockchain running the digital collection transaction starting from the initial node N0. The current node position is the position of the current node in the target path in the entire target path. The previous node address is the communication address of the previous node of the current node on the target path, and the next node address is the communication address of the next node of the current node on the target path. The above planning frame is transmitted along the target path starting from the initial node N0, where fields 1 to 4 can be determined at the beginning of the transmission. The current node position is initialized to 0 and incremented by 1 each time it is transmitted downward. During each transmission, two adjacent nodes exchange addresses with each other, the previous node fills the address of the next node with the address of the next node, and the next node fills the address of the previous node with the address of the previous node. Taking the target path {N0, N1, N3, N2, N4, N5, N7} as an example, when a digital collection is queried by paging according to the order price, assuming that the contract address of this digital collection is 0x1234 and the order price is between 0 and 100 equity certificates, the planning frame on the query node N0 is as follows: Figure 4 , where the equity certificate refers to the electronic certification or certificate of ownership of the digital collection.
[0051] Query node N0 will Figure 4 When the planning frame is transmitted along the target path, the planning frame is transmitted to the query node N1, and the addresses are exchanged during the transmission. Then, the planning frame of the query node N0 is as follows: Figure 5 As shown. In the planning frame transmitted to the query node N1, the current node position needs to be incremented by 1, so the planning frame transmitted to the query node N1 is as follows Figure 6 shown.
[0052] The planning frame is transmitted in the target path in the above manner, so that each node in the target path can obtain the corresponding planning frame.
[0053] The transaction flag can be the transaction hash (TxHash) of the transaction data or other values that can represent the transaction data. After determining the query nodes included in the target path, a key-value pair array is maintained on each query node, and the key-value pair array is the index of the node. The key of each key-value pair is the indicator value, and the value is the transaction flag corresponding to the indicator value, thereby obtaining the indicator value and transaction flag with a corresponding relationship. The key-value pair value can be sorted from small to large or from large to small according to the key (i.e., the indicator value).
[0054] S140: Allocate a corresponding target indicator range to any node on the target path based on the total indicator range and the number of nodes on the target path.
[0055] Specifically, based on the total indicator range and the number of nodes on the target path, it can be determined how many small ranges the total indicator range needs to be divided into, and this small range is the target indicator range assigned to any node on the target path. According to a predetermined division method, the total indicator range is divided into multiple indicator ranges corresponding to the number of nodes, and the target indicator range can be obtained. It should be understood that the predetermined division method includes multiple methods, such as equal division, or the target indicator ranges of adjacent nodes have a preset difference, or other feasible methods.
[0056] In some embodiments, based on the total indicator range and the number of nodes in the target path, a corresponding target indicator range is allocated to any node on the target path, including: based on the total indicator range and the number of nodes in the target path, the total indicator range is evenly divided to obtain multiple target indicator ranges; according to the order of nodes in the target path, the target indicator range is allocated to the corresponding nodes.
[0057] Specifically, this embodiment is one of the ways to divide the target indicator range, which can be applied when the target indicator range is divided for the first time, so as to initially allocate the total indicator range, that is, for the node Ni (0≤i≤n) on the target path, where n is the target path length, Vmax represents the upper limit of the indicator value, and Vmin represents the lower limit of the indicator value, then the target indicator range allocated to the i-th node Ni is: For example, if the target path length is 7, the upper limit Vmax of the index value is 100, and the lower limit Vmin of the index value is 0, then the target index range for the first node (i.e., query node N0) is:
[0058] In some embodiments, the method further includes: obtaining the number of hits and the number of historical queries of each node in the target path in the historical query task; determining the hit probability of the node based on the number of hits and the number of historical queries; and adjusting the target indicator range based on the hit probability of each node.
[0059] Specifically, the hit count is the number of times the index value queried by the historical query task is distributed at a certain node. For example, by recording the hit count and historical query count of each node of the target path for each query task, at a certain time point, the historical query count is 500 times, of which the hit count of query node N0 is 50 times, the hit count of query node N1 is 155 times, the hit count of query node N3 is 120 times, the hit count of query node N2 is 68 times, the hit count of query node N4 is 97 times, the hit count of query node N5 is 7 times, and the hit count of query node N7 is 3 times. The ratio of the hit count to the historical query count is the hit probability, which can be used to obtain the hit probability of each query node in the above example. It can be seen that the hit probabilities between the query nodes are not similar, which means that some query nodes bear a large load, such as query nodes N1 and N2. Based on the hit probability of each query node, the corresponding target index range is adjusted. For example, the target index range of query node N3 with a higher hit probability is reduced, so the index range originally belonging to query node N3 can be adjusted to the adjacent query node N2. In another embodiment, assuming that the target index range of query node N4 changes, the target transaction flag and target index value originally recorded in query node N4 can be transferred to query node N5 accordingly, which will not affect the paging query of the query index, and only transferring the query index will not generate excessive communication overhead.
[0060] In some embodiments, the first node and the second node are adjacent nodes on the target path, the hit probability of the first node is the first hit probability, the target indicator range of the first node is the first indicator range, the hit probability of the second node is the second hit probability, and the target indicator range of the second node is the second indicator range; according to the hit probability of each node, the target indicator range is adjusted, including: when the first hit probability is greater than the second hit probability, the exchange indicator range at the tail of the first indicator range is adjusted to the head of the second indicator range; when the first hit probability is less than the second hit probability, the exchange indicator range at the head of the second indicator range is adjusted to the tail of the first indicator range.
[0061] Specifically, the first node and the second node do not limit the order of the query nodes, but are only used to distinguish between two adjacent query nodes. For example, when the target path is {N0, N1, N3, N2, N4, N5, N7}, the first node may be query node N0, and the second node may be query node N1; if the first node is query node N1, the second node may be query node N0 or query node N3. In other words, the first node and the second node are not two fixed query nodes, and in some cases, the first node and the second node may be interchangeable. Taking the above target path as an example, the first node is query node N1, and the second node is query node N3, then the first hit probability is PN1 , the second hit probability is P N3 , when P N1 >P N3 , indicating that the query node N1 has a large load, and the exchange index range at the tail of the first index range can be adjusted to the head of the second index range; when P N1 <P N3 , indicating that the query node N3 has a large load, and the exchange index range at the head of the second index range can be adjusted to the tail of the first index range. This embodiment can reduce the query pressure of the query node with a higher hit probability (i.e., the query node with a larger load) by reallocating the target index range of the query node with a higher hit probability (i.e., the query node with a larger load) to the adjacent nodes, thereby avoiding the query index task from being concentrated on a few nodes.
[0062] S150: Construct a query index for target transaction data according to the target indicator range and the corresponding relationship.
[0063] Specifically, according to the target indicator range and the corresponding relationship, the target indicator range corresponding to each indicator value in the corresponding relationship can be determined, so that the record position of the query index of the target transaction data can be determined, and finally the query index is recorded in the corresponding target indicator range, that is, the query index construction process is completed. It should be understood that the purpose of constructing the query index in this application is to realize the index paging query of blockchain data without traversing all block data, and the index is divided into multiple target indicator ranges according to the size of the indicator value, and the query will not be concentrated on a single node.
[0064] In the technical solution of the present application, based on the query node and the topological structure of the blockchain, the target path of the data index is determined, wherein the length of the target path is related to the efficiency of the query service, and the nodes in the target path are not repeated; then based on the specified planning frame format, the planning frame of any node of the target path is determined, so that the information required for constructing the data index is recorded through the planning frame, so as to facilitate the subsequent acquisition of the target indicator value and the corresponding transaction flag when constructing the data index, and determine whether the transaction data is within the total indicator range, thereby determining whether to record the data index corresponding to the transaction data in the node on the target path; then based on the total indicator range and the number of nodes of the target path, the corresponding target indicator range is assigned to any node on the target path, and finally, according to the target indicator range and the corresponding relationship, the query index of the target transaction data is constructed, so that the data index of the target transaction data is assigned to multiple nodes, and the corresponding transaction data can be obtained based on each node in the blockchain. Then, when executing the query task, the node where the data index is located is queried first, and then the transaction data corresponding to the data index is queried from the node, without traversing all the transaction data, and it can also avoid concentrating on querying data on a single or part of the nodes, thereby improving the work efficiency of the data query service.
[0065] In some embodiments, the planning frame also includes the contract address of the transaction data, and a query index for the target transaction data is constructed according to the target indicator range and the corresponding relationship, including: according to the contract address of the planning frame, extracting the target transaction data whose target address is the contract address from the block data; parsing the target indicator value from the target transaction data; when the target indicator value is within the target indicator range, determining the target transaction flag corresponding to the target indicator value according to the corresponding relationship; and recording the target transaction flag and the target indicator value in the node corresponding to the target indicator range.
[0066] Specifically, a block data can record a large amount of transaction data, and the contract addresses of these transaction data are not unique. A blockchain user can set up multiple query nodes to build a query index for the block data for the transaction data of a certain contract address, so as to facilitate subsequent queries on the transaction data in the block data. For example, the contract address in the planning frame is 0x1234, that is, a query index is built for the transaction data with a target address of 0x1234 in the block data. Therefore, the target transaction data with the same target address and contract address is first taken out from the block data, and the target indicator value of the corresponding transaction, such as the pending order price, can be parsed from the target transaction data. According to the correspondence between the indicator value and the transaction flag maintained in advance, the target transaction flag can be determined based on the determined target indicator value. If the target transaction index value is within the target indicator range, it means that the target transaction data is the data that the blockchain user expects to index at the query node on the target path, then the target transaction flag and the target indicator value are recorded in the node corresponding to the target indicator range, and the target transaction flag, the target indicator value and the target indicator range of the query node can be associated.
[0067] In another embodiment, the query index of transaction data of different contract addresses can be assigned to the same target path. When determining the planning frame of each query node, the fields such as the contract address, indicator, and total range of indicators in the planning frame can be modified accordingly, so as to distinguish the planning frames of transaction data of different contract addresses.
[0068] The following introduces the blockchain-based data query method provided by the present application. The method queries the transaction data based on the query index constructed by the above-mentioned blockchain-based data index construction method, such as Figure 7 As shown, the method includes the following S710 to S730.
[0069] S710, obtaining query information of this data query and target index range of each query node; the query information includes query index.
[0070] Specifically, when executing a query task, you can obtain the query information of this data query, that is, the index range or specific index value expected to be queried this time, that is, the query index. For example, when you need to query the transaction data with a pending order price of 100, the index is the pending order price and the index value is 100. In addition, you also need to obtain the target index range of each query node in order to determine the target node where the query index is located.
[0071] S720: Determine the target node where the query indicator is located according to the target indicator range to which the query indicator belongs.
[0072] Specifically, the target index range of each query node is specific, so the index range of the query index is also determined, and therefore the target node corresponding to the query index can also be determined. It should be known that the query index can be an index value or an index range. For example, if you need to query transaction data with an index value in [50,60], this index range may be in multiple query nodes, which means that you need to search for transaction data from multiple query nodes later.
[0073] S730. Search the target node for transaction data corresponding to the query index.
[0074] Specifically, as mentioned above, the transaction flag can represent the transaction data, and the blockchain data can be obtained at each node on the chain, and different query indicators may be recorded in different query nodes. Then, by first determining the target node where the query indicator is located, and then searching for the transaction data corresponding to the query indicator from the target node, it is possible to avoid concentrating data query on a few nodes and causing single node problems.
[0075] In some embodiments, the query indicator is an indicator value or an indicator range, the indicator value and the transaction flag have a corresponding relationship, the transaction flag is used to represent the target transaction data, and the transaction data corresponding to the query indicator is searched from the target node, including: when the query indicator is an indicator value, searching the target transaction data corresponding to the indicator value from the target node; when the query indicator is an indicator range, searching the target transaction data corresponding to the indicator range from the target node; when the query indicator is an indicator range and the query information also includes a transaction flag, searching the target transaction data range corresponding to the indicator range from the target node, and searching the target transaction data corresponding to the transaction flag from the target transaction data range.
[0076] Specifically, the above embodiments are transaction data query processes corresponding to query information in different situations. For example, when the query indicator is an indicator value, the query node corresponding to the indicator value is unique, so the target transaction data corresponding to the indicator value can be found from the target node. It should be understood that the indicator value is a value, which is not equivalent to the target transaction data also having only one, but having the same indicator value for multiple transactions. When the query indicator is an indicator range, the query indicator range may span multiple query nodes. For example, the data index between the query indicator range [10,30] is located between query node N0 and query node N1, where the query indicator range The data index between is located at query node N0, and the query index range is The data index between is located at query node N1, so the index value queried from query node N0 is located at The target transaction data set A, querying the index value from query node N1 is located at The target transaction data set B is obtained by aggregating set A and set B to obtain the final target transaction data. When the current query index is the index range and the query information also includes the transaction flag, the target transaction data range corresponding to the index range can be first searched from the target node, and then the target transaction data corresponding to the transaction flag can be searched from the target transaction data range, so that the target transaction data corresponding to the transaction flag can be found. It should be understood that the transaction flag may be a coded value with no size regularity and cannot be used as an allocation index for the data index. If the transaction data is searched only based on the transaction flag, all blocks still need to be traversed, and paging query cannot be implemented. However, the data index is first established according to the index construction method provided in this application, and the paging query can be performed according to the query information to find the corresponding transaction data, and the query task can be avoided from being concentrated on a few nodes.
[0077] The electronic equipment of this application is introduced below, such as Figure 8 As shown, the present application provides an electronic device 800, which includes: a processor 810 and a memory 820, the memory 820 is used to store executable instructions of the processor; the processor 810 executes the executable instructions to enable the electronic device to implement the blockchain-based data index construction method or the blockchain-based data query method provided by any embodiment of the present application.
[0078] Specifically, the blockchain-based data index construction method or the blockchain-based data query method provided in the present application is stored in the memory 820 of the electronic device, and the blockchain-based data index construction method or the blockchain-based data query method provided by any embodiment is executed by the processor 810, so that when the electronic device executes the query task, it can perform paging query on the data index and distribute the query task to multiple nodes to improve the query efficiency.
[0079] It should be known that the specific implementation content of the electronic device in the present application has been explained in detail in the corresponding method embodiment and will not be repeated here.
[0080] Fig. 9 The structure block diagram of a computer system for implementing an electronic device according to an embodiment of the present application is schematically shown.
[0081] It should be noted that Fig. 9 The computer system 900 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0082] like Fig. 9 As shown, the computer system 900 includes a processor 901, which can be a CPU (Central Processing Unit) or an MCU (Microcontroller Unit). The processor 901 can perform various appropriate actions and processes according to the program stored in the read-only memory 902 (Read-Only Memory, ROM) or the program loaded from the storage part 908 to the random access memory 903 (Random Access Memory, RAM). In the random access memory 903, various programs and data required for system operation are also stored. The processor 901, the read-only memory 902 and the random access memory 903 are connected to each other through a bus 904. The input / output interface 905 (Input / Output interface, i.e., I / O interface) is also connected to the bus 904.
[0083] The following components are connected to the input / output interface 905: an input section 906 including a keyboard, a mouse, etc.; an output section 907 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker; a storage section 908 including a hard disk, etc.; and a communication section 909 including a network interface card such as a LAN card, a modem, etc. The communication section 909 performs communication processing via a network such as the Internet. A drive 910 is also connected to the input / output interface 905 as needed. A removable medium 911, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 910 as needed so that a computer program read therefrom is installed into the storage section 908 as needed.
[0084] In particular, according to an embodiment of the present application, the process described in each method flow chart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer readable medium, and the computer program contains a program code for executing the method shown in the flow chart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication part 909, and / or installed from a removable medium 911. When the computer program is executed by the processor 901, various functions defined in the system of the present application are executed.
[0085] It should be noted that the computer-readable medium shown in the embodiment of the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by an instruction execution system, device or device or used in combination with it. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a computer-readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer readable signal media may also be any computer readable medium other than computer readable storage media, which may send, propagate, or transmit programs for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0086] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the above-mentioned module, program segment or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0087] It should be noted that, although several modules or units of the equipment for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into being embodied by multiple modules or units.
[0088] Through the description of the above implementation methods, it is easy for those skilled in the art to understand that the example implementation methods described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation method of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a touch terminal, or a network device, etc.) to execute the implementation method according to the present application.
[0089] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary technical means in the art that are not disclosed in the present application.
[0090] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A method for constructing a data index based on blockchain, characterized in that: include: Obtaining a query node in a blockchain and a topological structure of the blockchain; The query node is a blockchain node in the blockchain used to query data; Based on the query node and the topological structure of the blockchain, a target path for data indexing is determined; the length of the target path is related to the efficiency of the query service, and the nodes in the target path are not repeated; Based on the specified planning frame format, determining a planning frame of any node of the target path; the planning frame includes an indicator of transaction data and a total indicator range, the total indicator range is a data set composed of all indicator values, the indicator value and the transaction flag have a corresponding relationship, and the transaction flag is used to represent the target transaction data; Based on the total indicator range and the number of nodes on the target path, assign a corresponding target indicator range to any node on the target path; A query index for the target transaction data is constructed according to the target indicator range and the corresponding relationship.
2. The method for constructing a data index based on blockchain according to claim 1, characterized in that: The planning frame also includes the contract address of the transaction data. The query index of the target transaction data is constructed according to the target indicator range and the corresponding relationship, including: According to the contract address of the planning frame, the target transaction data whose target address is the contract address is retrieved from the block data; Parsing the target transaction data to obtain a target indicator value; When the target indicator value is within the target indicator range, determining the target transaction flag corresponding to the target indicator value according to the corresponding relationship; The target transaction flag and the target indicator value are recorded in the node corresponding to the target indicator range.
3. The method for constructing a data index based on blockchain according to claim 1, characterized in that: The allocating a corresponding target indicator range to any node on the target path based on the total indicator range and the number of nodes on the target path includes: Based on the total indicator range and the number of nodes in the target path, the total indicator range is evenly divided to obtain a plurality of target indicator ranges; According to the order of nodes in the target path, the target indicator range is allocated to corresponding nodes.
4. The method for constructing a data index based on blockchain according to claim 3, characterized in that: The method further comprises: Obtain the hit count and historical query count of each node of the target path in the historical query task; the hit count is the number of times the indicator value queried by the historical query task is distributed at a certain node; Determining the hit probability of the node according to the hit number and the historical query number; The target indicator range is adjusted according to the hit probability of each node.
5. The method for constructing a data index based on blockchain according to claim 4, characterized in that: The first node and the second node are adjacent nodes on the target path, the hit probability of the first node is a first hit probability, the target indicator range of the first node is a first indicator range, the hit probability of the second node is a second hit probability, and the target indicator range of the second node is a second indicator range; adjusting the target indicator range according to the hit probability of each node includes: When the first hit probability is greater than the second hit probability, adjusting the exchange index range at the tail of the first index range to the head of the second index range; When the first hit probability is less than the second hit probability, the exchange index range located at the head of the second index range is adjusted to the tail of the first index range.
6. The method for constructing a data index based on blockchain according to claim 1, characterized in that: The determining a target path of the data index based on the query node and the topological structure of the blockchain includes: Based on the topology of the blockchain, determining the longest non-repetitive path starting from the initial query node; The longest non-repetitive path is determined as the target path.
7. A data query method based on blockchain, characterized in that: include: Obtain the query information of this data query and the target indicator range of each query node; The query information includes query indicators; Determining a target node where the query indicator is located according to the target indicator range to which the query indicator belongs; Search the target node for transaction data corresponding to the query indicator.
8. The data query method based on blockchain as claimed in claim 7, characterized in that: The query index is an index value or an index range, the index value and the transaction flag have a corresponding relationship, the transaction flag is used to represent target transaction data, and searching the transaction data corresponding to the query index from the target node includes: When the query indicator is the indicator value, searching the target transaction data corresponding to the indicator value from the target node; When the query index is an index range, searching the target transaction data corresponding to the index range from the target node; When the query index is an index range and the query information also includes a transaction flag, a target transaction data range corresponding to the index range is searched from the target node, and target transaction data corresponding to the transaction flag is searched from the target transaction data range.
9. A computer readable medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, it implements the blockchain-based data index construction method described in any one of claims 1 to 6, or the blockchain-based data query method described in any one of claims 7 to 8.
10. An electronic device, characterized in that: include: processor; A memory, configured to store executable instructions of the processor; The processor executes the executable instructions to enable the electronic device to implement the blockchain-based data index construction method as described in any one of claims 1 to 6, or the blockchain-based data query method as described in any one of claims 7 to 8.
Citation Information
Patent Citations
Block chain certificate storage method and device and computer equipment
CN109947845A
Block chain-based query method, apparatus and device, and storage medium
CN112506987A
Blockchain query method based on distributed search engine, and storage medium
CN113722420A
Index structure for block chain ledger
CN115004625A
Integrated index blocks and searching in blockchain systems
US20200104428A1