Blockchain-based data indexing construction and querying methods, media, and electronic devices

By building a topology-based data index in the blockchain, the problem of low data query efficiency in blockchain is solved, efficient data query is achieved, single node overload is avoided, and the efficiency of query business is improved.

CN119322794BActive Publication Date: 2025-10-31WEBANK (CHINA)
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411408727.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-10
Publication Date
2025-10-31
Estimated Expiration
2044-10-10

AI Technical Summary

Technical Problem

Existing technologies suffer from low efficiency when querying data in the blockchain, especially during high-concurrency queries, which can easily overload a single node and affect the efficiency of query operations.

Method used

By acquiring the query nodes and topology in the blockchain, the target path is determined, and a data index is built based on the planning frame format. The target indicator range is allocated, and a query index is built to be distributed across multiple nodes to avoid centralized queries and improve query efficiency.

Benefits of technology

It enables efficient data querying in the blockchain, avoids single-node overload, and improves the efficiency of query operations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119322794B_ABST
    Figure CN119322794B_ABST
Patent Text Reader

Abstract

This application discloses a method, medium, and electronic device for constructing and querying a blockchain-based data index. The method for constructing a blockchain-based data index includes: obtaining query nodes in the blockchain and the blockchain topology; determining the target path of the data index based on the query nodes and the blockchain topology; determining the planning frame of any node on the target path based on a specified planning frame format; assigning 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; and constructing a query index for the target transaction data according to the target indicator range and the corresponding relationship, thereby distributing the data index across multiple nodes. When executing a query task, the node where the data index is located is queried first, and then the corresponding transaction data is queried from that node. This eliminates the need to traverse all transaction data, avoids concentrating on querying data on a single or partial node, and improves the efficiency of data query operations.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the technical field of data query, and more specifically, relates to a method, medium, and electronic device for constructing and querying data indexes based on blockchain. Background Technology

[0002] In scenarios involving large amounts of data, paginated queries are commonly used to retrieve data. Paginated queries are a method used by the front-end system (browser or app) to query data from the back-end system (blockchain, database, or search engine). Because blockchain data evolves over time and requires regular updates to keep it up-to-date, the efficiency of data retrieval inevitably impacts the maintenance costs of the blockchain.

[0003] Related technologies have proposed using sharding-based distributed indexing in blockchains. However, sharding rules need to be maintained on a single node, which can easily lead to single-node problems. Moreover, this method stores the data of each shard on a single node, which can easily cause the single node to be overloaded during high-concurrency queries, affecting the efficiency of query operations.

[0004] It should be noted that the information disclosed in the background section above is only used to enhance the understanding of the background of this application, and therefore may include information that does not constitute prior art known to those skilled in the art. Summary of the Invention

[0005] The purpose of this invention is to provide a method, medium, and electronic device for constructing and querying blockchain-based data indexes, in order to solve the problem of low efficiency when searching blockchain data.

[0006] According to one aspect of the embodiments of this application, a method for constructing a blockchain-based data index is provided, the method comprising:

[0007] Obtain the query node in the blockchain, as well as the blockchain topology; the query node is a blockchain node used to query data.

[0008] Based on the topology of query nodes and 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 duplicated.

[0009] Based on the specified planning frame format, determine the planning frame for any node of the target path; the planning frame includes the indicators of the transaction data and the total range of indicators. The total range of indicators is a data set composed of all indicator values. There is a correspondence between indicator values ​​and transaction flags. The transaction flags are used to represent the target transaction data.

[0010] Based on the total range of indicators and the number of nodes on the target path, assign a corresponding target indicator range to any node on the target path;

[0011] Based on the target indicator range and corresponding relationships, construct a query index for the target transaction data.

[0012] In some embodiments, the planning frame also includes the contract address of the transaction data. Based on the target indicator range and the correspondence, a query index for the target transaction data is constructed, including: retrieving the target transaction data with the target address as the contract address from the block data according to the contract address of the planning frame; 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 correspondence; 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 range of indicators and the number of nodes in the target path, a corresponding target indicator range is assigned to any node on the target path, including: dividing the total range of indicators into multiple target indicator ranges on an average basis based on the total range of indicators and the number of nodes in the target path; and assigning the target indicator ranges to the corresponding nodes according to the order of the nodes in the target path.

[0014] In some embodiments, the method further 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 on a certain node; determining the hit probability of a node based on the number of hits and the number of historical queries; and adjusting the range of the target indicator 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 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. The target indicator range is adjusted according to the hit probability of each node, including: when the first hit probability is greater than the second hit probability, adjusting the exchange indicator range located at the end of the first indicator range to the beginning of the second indicator range; when the first hit probability is less than the second hit probability, adjusting the exchange indicator range located at the beginning of the second indicator range to the end of the first indicator range.

[0016] In some embodiments, determining the target path for the data index based on the topology of the query node and the blockchain includes: determining the longest non-repeating path starting from the initial query node based on the topology of the blockchain; and determining the longest non-repeating path as the target path.

[0017] According to one aspect of the embodiments of this application, a blockchain-based data query method is provided, the method comprising:

[0018] Obtain the query information for this data query and the target indicator range for each query node; the query information includes the query indicators;

[0019] Determine the target node where the query indicator is located based on the target indicator range to which the query indicator belongs;

[0020] Search for 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, and the indicator value and the transaction flag have a corresponding relationship. The transaction flag is used to represent the target transaction data. The process of finding the transaction data corresponding to the query indicator from the target node includes: when the query indicator is an indicator value, finding the target transaction data corresponding to the indicator value from the target node; when the query indicator is an indicator range, finding 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 the transaction flag, finding the target transaction data range corresponding to the indicator range from the target node, and finding the target transaction data corresponding to the transaction flag from the target transaction data range.

[0022] According to one aspect of the embodiments of this application, a computer medium is provided, on which a computer program is stored, which, when executed by a processor, implements the blockchain-based data index construction method or the blockchain-based data query method provided in any embodiment of this application.

[0023] According to one aspect of the embodiments of this 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 the blockchain-based data index construction method or the blockchain-based data query method provided in any embodiment of this application.

[0024] In the technical solution of this application, based on the query node and the topology of the blockchain, a target path for the data index 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 unique. Then, based on a specified planning frame format, a planning frame for any node in the target path is determined. This planning frame records the information needed to build the data index, facilitating the acquisition of target indicator values ​​and corresponding transaction flags during subsequent data index construction, as well as determining whether the transaction data is within the total range of indicators, thereby determining whether to record the data index corresponding to the transaction data on a node in the target path. Next, based on the total range of indicators and the number of nodes in the target path, a corresponding target indicator range is assigned to any node in the target path. Finally, based on the target indicator range and the corresponding relationship, a query index for the target transaction data is constructed, thus distributing the data index of the target transaction data across multiple nodes. Since each node in the blockchain can obtain the corresponding transaction data, when executing a query task, the node containing the data index is queried first, and then the transaction data corresponding to the data index is queried from that node. This eliminates the need to traverse all transaction data and avoids concentrating on querying data on a single or partial node, improving the efficiency of the data query business.

[0025] It should be understood in this application that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this application. Attached Figure Description

[0026] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application. It is obvious that the drawings described below are merely some embodiments of this application, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort.

[0027] Figure 1 The illustration shows a flowchart of a blockchain-based data index construction method provided in one embodiment of this application.

[0028] Figure 2 The diagram illustrates a schematic representation of the blockchain topology provided in one embodiment of this application.

[0029] Figure 3 The schematic diagram illustrates the structure of a planning frame provided in an embodiment of this application.

[0030] Figure 4 The diagram illustrates the structure of an initial query node planning frame provided in one embodiment of this application.

[0031] Figure 5 The schematic diagram illustrates the structure of a query node planning frame provided in an embodiment of this application.

[0032] Figure 6 The schematic diagram illustrates the structure of a query node planning frame provided in an embodiment of this application.

[0033] Figure 7 The illustration shows a flowchart of a blockchain-based data query method provided in an embodiment of this application.

[0034] Figure 8 The diagram illustrates the structure of an electronic device according to an embodiment of this application.

[0035] Figure 9 A schematic diagram illustrating a computer system architecture for implementing an electronic device according to embodiments of this application is shown. Detailed Implementation

[0036] Exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, these exemplary embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided to make this application more comprehensive and complete, and to fully convey the concept of the exemplary embodiments to those skilled in the art.

[0037] Furthermore, the features, structures, or characteristics described in this application can be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to give a thorough understanding of embodiments of this application. However, those skilled in the art will recognize that the technical solutions of this application can be practiced without one or more of the specific details, or other methods, components, apparatuses, steps, etc., can be employed. In other instances, well-known methods, apparatuses, implementations, or operations are not shown or described in detail to avoid obscuring various aspects of this 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 can be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.

[0039] The flowcharts shown in the accompanying drawings are merely illustrative and do not necessarily include all content and operations / steps, nor do they necessarily have to be performed in the described order. For example, some operations / steps can be broken down, while others can be combined or partially combined; therefore, the actual execution order may change depending on the specific circumstances.

[0040] First, let's introduce the relevant technologies for data querying. As mentioned in the background technology, pagination query is a way to query data. Pagination query is usually used to query data in the form of a list. The characteristics of the data list include: (1) the data elements of each column of data in the list are the same; (2) the data scale of the list is large; (3) the list can be sorted in ascending or descending order according to a certain element. For example, in the employee information management system, the employee information list is this type of data. Each employee data in the system has the same elements, such as name, position, age and number (ID). If there are many employees, it is generally not possible to query and display all employee data at once. The list can be sorted in ascending or descending order according to the lexicographical order of the employee name or the lexicographical order of the ID. Pagination query is a query method in which the list is sorted according to the set rules and then queried page by page. Pagination query includes the following core parameters: (1) sorting field: which field the list data is sorted by; (2) sorting rule: generally in ascending or descending order according to the numerical size; (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 query process for sorting employee information in ascending order by lexicographical order of employee ID, with a page size of 10 and page number 2, is as follows: Sort all employee information in the employee information management system in ascending order by 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, to obtain a list of employee information sorted in ascending order by lexicographical order of employee ID, and then retrieve the data from the 11th to the 20th data in this list.

[0041] Blockchain data is generally stored in key-value (kV) type databases, where k is usually the block hash. Knowing the block hash allows for quick retrieval of the corresponding block data. However, this storage structure makes pagination queries difficult. Each query requires traversing all block data, parsing the block data, and comparing sorting fields to obtain an ordered sequence and return the paginated query result, resulting in low data query efficiency. Related technologies utilize indexing techniques for data querying, such as global indexes or distributed indexes. Global indexes are a common indexing method in centralized relational databases, characterized by: (1) storing all data on a single server (including master-slave clusters); (2) storing the index on a single server (including master-slave clusters) to accelerate queries; and (3) indexing all data on a single server (including master-slave clusters). The advantage of this global index is its simple implementation process and the absence of common network and consistency issues in distributed systems. However, its disadvantages include the susceptibility to single-node failures, performance bottlenecks with large data volumes and high concurrency queries, and poor scalability. Sharded indexes are a common indexing method in distributed relational databases. Their characteristics include: (1) dividing the full data into several shards, each shard being distributed and stored on a single node; (2) storing and maintaining sharding rules on a single node (usually called the Master node). When querying data, it is necessary to first locate the shard and its node, and then equivalently divide a query on the full data into several subqueries, which are executed on the corresponding shard nodes; (3) each node only indexes the sharded data of its own node. The Master node needs to summarize the results returned by the subqueries of each shard node to obtain the query results for the full data. This shard-based distributed indexing method requires sharding rules to be maintained on a single node, inherently presenting a single-node problem. Furthermore, the sharding scheme lacks flexibility and cannot effectively handle changes in concurrent load. Although some schemes use dynamic sharding to distribute shards with high concurrent loads to other nodes, the problem of excessive network data circulation costs due to data movement between shards still exists. Furthermore, during paginated queries, if a page of data is distributed across two nodes for query aggregation, it will increase system overhead. To address the issues of single-node overload or incompatibility with paginated queries in related technologies, such as... Figure 1 As shown, this application provides a data index construction method based on blockchain, which includes the following steps S110 to S150.

[0042] S110. Obtain the query node in the blockchain and the topology of the blockchain; the query node is a blockchain node used to query data.

[0043] Specifically, the blockchain topology in this application refers to the network shape formed by the communication connections between query nodes. For example, query nodes N0 to N7 communicate with each other, forming a network like this: Figure 2 The diagram illustrates a blockchain topology. It's important to understand that blockchain is distributed, meaning there's no single point of control storing the entire dataset. Instead, data is distributed across multiple nodes in the network, each independently maintaining its local data. Therefore, query nodes N0-N7 are several blockchain nodes specifically built by the blockchain user to perform query operations. They can synchronize data on the blockchain and perform data query operations on these specific blockchain nodes without affecting the data processing work of other blockchain nodes.

[0044] S120. Based on the topology of the query nodes and the blockchain, determine the target path for 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 duplicated.

[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 indexes have different names in different scenarios; for example, an index can also be called a key or a pointer. The target path refers to the path formed by the blockchain nodes that record the data index, and the blockchain nodes in this path are ordered. For example, such as... Figure 2 As shown, query nodes N0 to N7 form the 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 in sequence, and the ending point is query node N7.

[0046] Based on the query nodes and the blockchain topology, paths formed by connecting multiple nodes can be obtained. Figure 2 Taking the blockchain shown as an example, let's define query node N0 as the current processing node. We determine the path starting from query node N0, such as path A{N0, N1, N3, N6}, path B{N0, N2, N3, N6}, path C{N0, N1, N3, N2, N4, N7}, or other paths. The length of the target path depends on the efficiency requirements of the query business. If the efficiency requirements are high, the target path should be as long as possible to distribute the data index across more nodes, preventing the query from being concentrated on a single node and causing node overload. Furthermore, ensuring that the nodes in the target path are not duplicated allows the data index to be distributed across different nodes, avoiding duplicate allocation and excessive load on some nodes.

[0047] In some embodiments, determining the target path for the data index based on the topology of the query node and the blockchain includes: determining the longest non-repeating path starting from the initial query node based on the topology of the blockchain; and determining the longest non-repeating path as the target path.

[0048] Specifically, based on S110, we know the set of query nodes is M = {N0, N1, N2, N3, N4, N5, N6, N7}. Let query node N0 be the initial node. First, return N0 to the known node list K0, i.e., K0 = {N0}. The length of the longest non-repeating path starting from query node N0 is: L0(M) = 1 + L 1,2 (M-K0), which is the length of the longest non-repeating path starting from query node N0, is equal to the longest path formed by all query nodes except query node N0 plus 1. Since this longest non-repeating path length needs to be connected to query node N0, it is the length of the longest non-repeating path starting from query node N1 or query node N2 that does not pass through query node N0: L 1,2 (M-K0) = Max{L1(M-K0), L2(M-K0)}. Similarly, the process of calculating the length of the longest non-repeating path starting from query node N2 without passing through query node N0 is similar to the process starting from query node N0. Query node N2 is placed into the known node list K2 = {N0, N2}, and the longest path L2(M-K0) = 1 + L 3,4 (M-K2). Continue in this manner until only one node remains that does not pass through the known node list, meaning the remaining path length is 1. Backtracking will then yield L0(M). At this point, the node in the known node list plus the node with a remaining path length of 1 represents the longest non-repeating path starting from N_0. The final longest non-repeating path is: {N0, N1, N3, N2, N4, N5, N7}.

[0049] S130. Based on the specified planning frame format, determine the planning frame for any node of the target path; the planning frame includes the indicators of the transaction data and the total range of indicators. The total range of indicators is a data set composed of all indicator values. The indicator values ​​and transaction flags have a corresponding relationship. The transaction flags are used to represent the target transaction data.

[0050] Specifically, the specified planning frame format is a predefined indexed planning frame format, and the specific format of the planning frame is as follows: Figure 3As shown, the field number represents the order of the field within the planning frame, the field name represents the corresponding field within the planning frame, and the data type represents the data type of the corresponding field within the planning frame. The contract address is the position of the currently queried transaction data within the block. The indicator is the field in the transaction data that needs to be queried. For example, for a blockchain user, suppose they need to perform a paginated query for a digital collectible based on its order price. In this case, the contract address in the planning frame is the address of the digital collectible's transaction contract. The indicator is the order price of this digital collectible. It should be understood that the indicator can be any field other than the order price, and this field is not limited to those mentioned above. Figure 3 The fields shown are as follows: The total range of indicators is the data set formed by the maximum and minimum allowed order prices. The path length is the target path length of the blockchain running this digital collectible transaction, starting from the initial node N0. The current node position is the position of the current node within the entire target path. The previous node address is the communication address of the node preceding the current node on the target path, and the next node address is the communication address of the node following 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-4 can be determined at the beginning of the transmission. The current node position is initialized to 0 and increments by 1 with each subsequent transmission. During each transmission, adjacent nodes exchange addresses; the preceding node fills the address of the following node into the address of the next node, and the following node fills the address of the preceding node into the address of the previous node. Taking the target path {N0, N1, N3, N2, N4, N5, N7} as an example, when performing a paginated query on a digital collectible based on the order price, assuming the contract address of this digital collectible 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 Among them, the certificate of rights refers to the electronic authentication or certificate of ownership of digital collectibles.

[0051] Query node N0 will Figure 4 When the planning frame shown is transmitted along the target path, it will be passed to the query node N1, and the addresses will be exchanged during the transmission. Then, the planning frame of the query node N0 will be as follows: Figure 5 As shown. In the planning frame passed to query node N1, the current node position needs to be incremented by 1. Therefore, the planning frame passed to query node N1 is as follows: Figure 6 As shown.

[0052] If the planning frame is transmitted in the target path in the manner described above, then each node in the target path can obtain the corresponding planning frame.

[0053] The transaction identifier can be the transaction hash (TxHash) of the transaction data or other numerical 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, which serves as the index of that node. The key of each key-value pair is the indicator value, and the value is the transaction identifier corresponding to the indicator value, thus obtaining a corresponding indicator value and transaction identifier. The values ​​of these key-value pairs can be sorted in ascending order or descending order according to the key (i.e., indicator value).

[0054] S140. Based on the total range of indicators and the number of nodes on the target path, assign a corresponding target indicator range to any node on the target path.

[0055] Specifically, based on the total range of indicators and the number of nodes on the target path, we can determine how many smaller ranges the total range of indicators needs to be divided into. Each smaller range represents the target indicator range assigned to any node on the target path. By dividing the total range of indicators into multiple ranges corresponding to the number of nodes according to a predetermined method, we can obtain the target indicator range. It should be understood that the predetermined method of division includes various approaches, such as equal distribution, a preset difference between the target indicator ranges of adjacent nodes, or other feasible methods.

[0056] In some embodiments, based on the total range of indicators and the number of nodes in the target path, a corresponding target indicator range is assigned to any node on the target path, including: dividing the total range of indicators into multiple target indicator ranges on an average basis based on the total range of indicators and the number of nodes in the target path; and assigning the target indicator ranges to the corresponding nodes according to the order of the nodes in the target path.

[0057] Specifically, this embodiment is one way to divide the target indicator range. It can be applied when initially dividing the target indicator range to initially allocate the total indicator range. That is, for a 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, the target indicator range allocated to the i-th node Ni is: For example, if the target path length is 7, the upper limit of the indicator value Vmax is 100, and the lower limit of the indicator value Vmin is 0, then the target indicator range for the first node (i.e., query node N0) is:

[0058] In some embodiments, the method further includes: obtaining the hit count and historical query count of each node of the target path in the historical query task; determining the hit probability of a node based on the hit count and historical query count; and adjusting the target indicator range based on the hit probability of each node.

[0059] Specifically, the hit count is the number of times a metric value queried by a historical query task is distributed across a particular node. For example, by recording the hit count and historical query count for each node on the target path during each query task, at a certain point in time, the historical query count is 500. Among them, query node N0 has a hit count of 50, query node N1 has a hit count of 155, query node N3 has a hit count of 120, query node N2 has a hit count of 68, query node N4 has a hit count of 97, query node N5 has a hit count of 7, and query node N7 has a hit count of 3. The ratio of the hit count to the historical query count is the hit probability. The hit probability of each query node in the above example can be calculated. It can be seen that the hit probabilities of different query nodes are not similar, meaning that some query nodes bear a heavy load, such as query nodes N1 and N2. Based on the hit probability of each query node, the corresponding target indicator range is adjusted. For example, if the target indicator range of query node N3, which has a higher hit probability, is reduced, then the indicator range originally belonging to query node N3 can be adjusted to the adjacent query node N2. In another embodiment, assuming the target indicator range of query node N4 changes, the target transaction flag and target indicator value originally recorded on query node N4 can be transferred back to query node N5. This will not affect the pagination query of the query index, and transferring only 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 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. The target indicator range is adjusted according to the hit probability of each node, including: when the first hit probability is greater than the second hit probability, adjusting the exchange indicator range located at the end of the first indicator range to the beginning of the second indicator range; when the first hit probability is less than the second hit probability, adjusting the exchange indicator range located at the beginning of the second indicator range to the end of the first indicator range.

[0061] Specifically, the first and second nodes do not restrict the order of query nodes; they 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 can be query node N0, and the second node can be query node N1; if the first node is query node N1, the second node can be either query node N0 or query node N3. In other words, the first and second nodes are not fixed; in some cases, they can even be interchanged. Taking the target path above as an example, if the first node is query node N1 and the second node is query node N3, then the probability of a first hit is P.N1 The probability of the second hit is P. N3 When P N1 >P N3 This indicates that the load on query node N1 is high, and the exchange index range located at the tail of the first index range can be moved to the head of the second index range; when P N1 <P N3 This indicates that query node N3 has a high load, and the exchange index range located at the head of the second index range can be moved to the tail of the first index range. This embodiment reduces the query pressure on the query node with a higher hit probability (i.e., the query node with a higher load) by redistributing its target index range to adjacent nodes, thus avoiding the concentration of query index tasks on a few nodes.

[0062] S150. Based on the target indicator range and corresponding relationships, construct a query index for the target transaction data.

[0063] Specifically, based on the target indicator range and the corresponding relationship, the target indicator range corresponding to each indicator value in the corresponding relationship can be determined. This allows us to determine the record location of the query index for the target transaction data. Finally, the query index is recorded within the corresponding target indicator range, thus completing the query index construction process. It should be understood that this application constructs the query index to achieve paginated querying of blockchain data without traversing all block data. Furthermore, the index is divided into multiple target indicator ranges according to the size of the indicator values, avoiding centralized querying on a single node.

[0064] In the technical solution of this application, based on the query node and the topology of the blockchain, a target path for the data index 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 unique. Then, based on a specified planning frame format, a planning frame for any node in the target path is determined. This planning frame records the information needed to build the data index, facilitating the acquisition of target indicator values ​​and corresponding transaction flags during subsequent data index construction, as well as determining whether the transaction data is within the total range of indicators, thereby determining whether to record the data index corresponding to the transaction data on a node in the target path. Next, based on the total range of indicators and the number of nodes in the target path, a corresponding target indicator range is assigned to any node in the target path. Finally, based on the target indicator range and the corresponding relationship, a query index for the target transaction data is constructed, thus distributing the data index of the target transaction data across multiple nodes. Since each node in the blockchain can obtain the corresponding transaction data, when executing a query task, the node containing the data index is queried first, and then the transaction data corresponding to the data index is queried from that node. This eliminates the need to traverse all transaction data and avoids concentrating on querying data on a single or partial node, improving the efficiency of the data query business.

[0065] In some embodiments, the planning frame also includes the contract address of the transaction data. Based on the target indicator range and the correspondence, a query index for the target transaction data is constructed, including: retrieving the target transaction data with the target address as the contract address from the block data according to the contract address of the planning frame; 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 correspondence; and recording the target transaction flag and the target indicator value in the node corresponding to the target indicator range.

[0066] Specifically, a block of data can record a large amount of transaction data. The contract addresses of these transactions are not unique. A blockchain user can set up multiple query nodes to build a query index for the block's data for transaction data at a specific contract address, facilitating subsequent queries of transactions within that block. For example, if the contract address in the planning frame is 0x1234, a query index is built for the transaction data at the target address 0x1234 in the block data. Therefore, the target transaction data with the same target address and contract address is first extracted from the block data. From this target transaction data, the corresponding target indicator value, such as the order price, can be parsed. Based on the pre-maintained correspondence between indicator values ​​and transaction flags, the target transaction flag can be determined based on the determined target indicator value. If the target transaction indicator value is within the target indicator range, it means that the target transaction data is the data that the blockchain user wants to index on the query nodes along the target path. The target transaction flag and target indicator value are then recorded in the node corresponding to the target indicator range, thus associating the target transaction flag, target indicator value, and the target indicator range of the query node.

[0067] In another embodiment, the query indexes of transaction data from different contract addresses can be assigned to the same target path. When determining the planning frame for each query node, the fields such as contract address, indicator, and total indicator range in the planning frame can be modified accordingly, thereby distinguishing the planning frames of transaction data from different contract addresses.

[0068] The following describes the blockchain-based data query method provided in this application. This method queries transaction data based on the query index constructed by the aforementioned blockchain-based data index construction method, such as... Figure 7 As shown, the method includes the following steps S710 to S730.

[0069] S710. Obtain the query information for this data query and the target indicator range for each query node; the query information includes the query indicators.

[0070] Specifically, when executing a query task, the query information for this data query can be obtained, namely the expected range or specific value of the indicator to be queried, i.e., the query indicator. For example, if a query requires retrieving transaction data with an order price of 100, then the indicator is the order price, and the indicator value is 100. Additionally, the target indicator range for each query node needs to be obtained to determine the target node where the query indicator resides.

[0071] S720. Determine the target node where the query indicator is located based on the target indicator range to which the query indicator belongs.

[0072] Specifically, since the target indicator range for each query node is specific, the indicator range in which the query indicator falls is also determined, and therefore the target node corresponding to the query indicator can also be determined. It should be noted that a query indicator can be an indicator value or an indicator range. For example, if you need to query transaction data with an indicator value in the range [50, 60], this indicator range may lie across multiple query nodes, meaning that you will need to search for transaction data from multiple query nodes.

[0073] S730: Search for the transaction data corresponding to the query indicator from the target node.

[0074] Specifically, as mentioned earlier, transaction markers can represent transaction data, and blockchain data can be accessed by every node on the chain. Furthermore, different query metrics may be recorded on different query nodes. Therefore, by first determining the target node where the query metric resides, and then searching for the corresponding transaction data from that target node, we can avoid concentrating data queries on a few nodes and causing single-node problems.

[0075] In some embodiments, the query indicator is an indicator value or an indicator range, and the indicator value and the transaction flag have a corresponding relationship. The transaction flag is used to represent the target transaction data. The process of finding the transaction data corresponding to the query indicator from the target node includes: when the query indicator is an indicator value, finding the target transaction data corresponding to the indicator value from the target node; when the query indicator is an indicator range, finding 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 the transaction flag, finding the target transaction data range corresponding to the indicator range from the target node, and finding the target transaction data corresponding to the transaction flag from the target transaction data range.

[0076] Specifically, the above embodiments describe the transaction data query process corresponding to different query information scenarios. 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 that indicator value can be found from the target node. It should be understood that an indicator value is a single value, which does not equate to the target transaction data also having only one instance; rather, multiple transactions may have the same indicator value. 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 at query node N0 and query node N1, where the query indicator range... The data index between them is located at query node N0, and the query metric range is... The data index between them is located at query node N1, therefore the metric value queried from query node N0 is located at The target transaction data set A, from query node N1, queries the indicator value located at... The target transaction data set B is then aggregated from sets A and B to obtain the final target transaction data. When the current query indicator is a range and the query information also includes transaction flags, the target transaction data range corresponding to the indicator range can be found first from the target node, and then the target transaction data corresponding to the transaction flag can be found from the target transaction data range. It should be understood that transaction flags may be randomly coded numerical values ​​and cannot be used as allocation indicators for data indexes. If transaction data is found solely based on transaction flags, it is still necessary to traverse all blocks, which does not enable paginated queries. However, by first establishing a data index according to the index construction method provided in this application, paginated queries can be performed based on the query information to find the corresponding transaction data, and the query task can be avoided by concentrating on a few nodes.

[0077] The following describes the electronic device of this application, such as... Figure 8 As shown, this 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 in any embodiment of this application.

[0078] Specifically, the blockchain-based data index construction method or blockchain-based data query method provided in this application is stored in the memory 820 of the electronic device. The processor 810 executes the blockchain-based data index construction method or blockchain-based data query method provided in any embodiment, so that when the electronic device performs a query task, it can perform paginated queries on the data index, distribute the query task to multiple nodes, and improve query efficiency.

[0079] It should be understood that the specific implementation details of the electronic device in this application have been explained in detail in the corresponding method embodiments, and will not be repeated here.

[0080] Figure 9 A schematic block diagram of a computer system architecture for implementing an electronic device according to embodiments of the present application is shown.

[0081] It should be noted that, Figure 9 The computer system 900 of the electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.

[0082] like Figure 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 based on programs stored in read-only memory (ROM) 902 or programs loaded from storage section 908 into random access memory (RAM). The random access memory 903 also stores various programs and data required for system operation. The processor 901, ROM 902, and RAM 903 are interconnected via a bus 904. An input / output interface 905 (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, mouse, etc.; an output section 907 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 908 including a hard disk, etc.; and a communication section 909 including a network interface card such as a local area network card, 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 disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on the drive 910 as needed so that computer programs read from it can be installed into the storage section 908 as needed.

[0084] Specifically, according to embodiments of this application, the processes described in the various method flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 909, and / or installed from removable medium 911. When the computer program is executed by processor 901, it performs various functions defined in the system of this application.

[0085] It should be noted that the computer-readable medium shown in the embodiments of this application can be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), flash memory, optical fiber, portable compact disc read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this application, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such transmitted data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. The computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to wireless, wired, etc., or any suitable combination thereof.

[0086] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0087] It should be noted that although several modules or units for the device used to perform actions have been mentioned in the detailed description above, this division is not mandatory. In fact, according to the embodiments of this application, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.

[0088] Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solutions according to the embodiments of this application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, external hard drive, etc.) or on a network, including several instructions to cause a computing device (such as a personal computer, server, touch terminal, or network device, etc.) to execute the embodiments according to this application.

[0089] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein.

[0090] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.

Claims

1. A method for constructing a data index based on blockchain, characterized in that, include: Obtain the query node in the blockchain, as well as the topology of the blockchain; The query node is a blockchain node in the blockchain used for querying data; Based on the query node and the topology of the blockchain, the target path for the data index 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. Based on the specified planning frame format, the planning frame of any node in the target path is determined; the planning frame includes indicators of the transaction data, the total range of indicators, and the contract address of the transaction data. The total range of indicators is a data set composed of all indicator values. The indicator values ​​and transaction flags have a corresponding relationship. The transaction flags are used to represent the target transaction data. Based on the total range of the indicators and the number of nodes on the target path, assign a corresponding target indicator range to any node on the target path; Based on the contract address of the planning frame, retrieve the target transaction data with the target address being the contract address from the block data; The target indicator value is obtained by parsing the target transaction data; When the target indicator value is within the target indicator range, the target transaction flag corresponding to the target indicator value is determined according to the correspondence. The target transaction flag and the target indicator value are recorded in the nodes corresponding to the target indicator range to construct a query index.

2. The data index construction method based on blockchain as described in claim 1, characterized in that, The process of assigning a corresponding target indicator range to any node on the target path based on the total range of the indicators and the number of nodes on the target path includes: Based on the total range of the indicators and the number of nodes in the target path, the total range of the indicators is divided into multiple target indicator ranges on an average basis. The target index range is assigned to the corresponding nodes according to the node order in the target path.

3. The data index construction method based on blockchain as described in claim 2, characterized in that, The method further includes: Obtain the hit count and historical query count for 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 on a certain node; The hit probability of the node is determined based on the number of hits and the number of historical queries. The target index range is adjusted based on the hit probability of each node.

4. The data index construction method based on blockchain as described in claim 3, 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, and 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 based on the hit probabilities of each node includes: When the first hit probability is greater than the second hit probability, the exchange index range located at the tail of the first index range is adjusted 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.

5. The data index construction method based on blockchain as described in claim 1, characterized in that, Determining the target path for the data index based on the topology of the query node and the blockchain includes: Based on the topology of the blockchain, determine the longest non-repeating path starting from the initial query node; The longest non-repeating path is determined as the target path.

6. A data query method based on blockchain, characterized in that, include: Obtain the query information for this data query and the target indicator range for each query node; The query information includes query metrics; The target node where the query indicator is located is determined based on the query index and the target indicator range to which the query indicator belongs; wherein the query index is obtained according to any one of claims 1-5 based on the blockchain-based data index construction method; The transaction data corresponding to the query indicator is retrieved from the target node based on the query index.

7. The data query method based on blockchain as described in claim 6, characterized in that, 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 represents the target transaction data. The step of searching for the transaction data corresponding to the query indicator from the target node includes: When the query indicator is the indicator value, the target transaction data corresponding to the indicator value is retrieved from the target node; When the query indicator is an indicator range, the target transaction data corresponding to the indicator range is retrieved from the target node; When the query indicator is an indicator range and the query information also includes a transaction flag, the target transaction data range corresponding to the indicator range is searched from the target node, and the target transaction data corresponding to the transaction flag is searched from the target transaction data range.

8. A computer-readable medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the blockchain-based data index construction method according to any one of claims 1 to 5, or the blockchain-based data query method according to any one of claims 6 to 7.

9. An electronic device, characterized in that, include: processor; Memory for storing the 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 5, or the blockchain-based data query method as described in any one of claims 6 to 7.

Citation Information

Patent Citations

  • Block chain-based query method, apparatus and device, and storage medium

    CN112506987A

  • Integrated index blocks and searching in blockchain systems

    US20200104428A1