Data query method and device based on block chain network, and electronic equipment
By dividing the blockchain network into N block fragments and positioning the target block fragments and accounting nodes, the problem of low efficiency of traditional blockchain query is solved, and efficient data query and writing is achieved.
Patent Information
- Application Number
- CN202510675731.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-23
- Publication Date
- 2025-08-26
AI Technical Summary
In traditional blockchain technology, the query efficiency of a single chain has become a bottleneck, especially when data retrieval is needed based on a specific block number, it needs to traverse the entire chain, which consumes time and wastes network resources, and lacks effective positioning strategies, resulting in low query efficiency.
The blockchain network is pre-divided into N block fragments connected in sequence. Each fragment contains multiple shard blocks and accounting nodes. The first accounting node of the source block fragment receives query requests, locates the target block fragment and the corresponding shard block cluster, obtains the address of the second accounting node and directly forwards the client query requests to avoid inter-cluster polling.
It realizes the rapid positioning of block fragments and accounting nodes, significantly improving the efficiency of data query and writing in the blockchain network, reducing unnecessary network communication, and reducing system delay and resource consumption.
Smart Images

Figure CN120541124A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of blockchain technology, distributed query technology or other related fields, and specifically to a data query method and device, and electronic equipment based on a blockchain network. Background Art
[0002] In traditional blockchain technology, all transaction data is recorded sequentially in a single, ever-growing chain. This structure presents limitations in data query and processing. As blockchain networks expand and transaction volume grows, the efficiency of single-chain queries becomes a bottleneck. Retrieving data based on a specific block number often requires traversing the entire chain, which is not only time-consuming but can also waste network resources.
[0003] To improve the performance and security of blockchain systems, the industry has begun exploring blockchain sharding. This involves splitting a blockchain into multiple independently operating sub-chains (or shards), with each shard responsible for processing a portion of transaction data. While this approach can alleviate centralization pressure and improve processing speed to a certain extent, cross-shard data queries still rely on a polling mechanism and lack an effective positioning strategy, resulting in insignificant improvements in query efficiency and increased ineffective communication between clusters.
[0004] To address the above-mentioned problems, no effective solutions have been proposed so far. Summary of the Invention
[0005] The embodiments of the present invention provide a data query method and device, and an electronic device based on a blockchain network, to at least solve the technical problems in related technologies of requiring traversal of all clusters when querying specific block data in a blockchain, lacking an effective positioning strategy, and resulting in low query efficiency.
[0006] According to one aspect of an embodiment of the present invention, a data query method based on a blockchain network is provided. The blockchain network is pre-divided into N sequentially connected block segments, and the segment interval of each block segment contains multiple shard blocks and accounting nodes. The data query method based on the blockchain network includes: receiving a block query request from a client through a first accounting node in a source block segment, wherein the block query request includes: a target shard block number and accounting data information to be queried; in response to the block query request, querying local block history records through the first accounting node to determine the target block segment and the corresponding shard block cluster to which the shard block indicated by the target block number belongs; obtaining a node address of a second accounting node corresponding to the target block segment, and returning the node address of the second accounting node to the client; receiving a new block query request initiated by the client through the second accounting node, wherein the new block query request includes: the node address of the second accounting node, the target shard block number, and the accounting data information to be queried; and in response to the new block query request, returning the ledger data corresponding to the target shard block number to the client through the second accounting node.
[0007] Optionally, before receiving the block query request of the client through the first accounting node in the source block fragment, it also includes: after the accounting node corresponding to any of the block fragments in the blockchain network is started, the accounting node scans the shard block information of the current terminal to obtain the start bit and end bit of the block fragment; based on the start bit and end bit of the block fragment, establishes a shard block cluster corresponding to the block fragment; records the block index information and node information of the shard block cluster in the world state database through the accounting node; broadcasts the block index information and the node information to each accounting node in other block fragments through the accounting node, wherein each accounting node in other block fragments records the block index information and the node information in the local world state database.
[0008] Optionally, in response to the block query request, querying the local block history record through the first accounting node to determine the target block fragment and the corresponding shard block cluster to which the shard block indicated by the target block number belongs, includes: responding to the block query request, querying the block index information in the local world state database, and determining whether the target shard block number is located in the fragment interval of the source block fragment; if the target shard block number is not located in the fragment interval of the source block fragment, indexing the block index information and node information broadcasted in the historical process of each accounting node in other block fragments, and obtaining the target block fragment and the corresponding shard block cluster to which the shard block indicated by the target block number belongs.
[0009] Optionally, before receiving the block query request from the client through the first accounting node in the source block fragment, the method further includes: receiving the block write request from the client through the first accounting node in the source block fragment, wherein the block write request includes at least: the node address of the first accounting node and the block information of the block to be sharded; in response to the block write request, querying the local historical block record through the first accounting node to obtain the fragment interval status of the source block fragment; if the fragment interval status indicates that the source block fragment is a read-only interval, querying the local historical block record through the first accounting node; The point query is for a block segment whose fragment interval status is a write interval, the shard block cluster corresponding to the block segment and the node address of the third accounting node are located, and the node address of the third accounting node is returned to the client; a new block write request initiated by the client is received through the third accounting node, wherein the new block write request includes: the node address of the third accounting node and the block information of the block to be sharded; in response to the new block write request, block accounting processing is performed through the third accounting node, a block number receipt is generated, and the block number receipt is returned to the client.
[0010] Optionally, the process of pre-dividing the blockchain network into N sequentially connected block fragments includes: determining the starting shard block number and the ending shard block number of each block fragment according to the total number of blocks in the blockchain network and a predetermined fragment interval range, wherein the block numbers between the block fragments do not overlap.
[0011] Optionally, the first N-1 block segments of the N block segments are closed intervals, and the Nth block segment is an open interval.
[0012] Optionally, the cluster state of the shard block cluster corresponding to the first N-1 block fragments among the N block fragments is in a read-only state, and block writes are not accepted; the cluster state of the shard block cluster corresponding to the Nth block fragment is in a writable state, and block writes are accepted.
[0013] According to another aspect of an embodiment of the present invention, a data query device based on a blockchain network is further provided. The blockchain network is pre-divided into N sequentially connected block fragments, and the fragment interval of each block fragment contains multiple shard blocks and accounting nodes. The data query device based on the blockchain network includes: a first block query request receiving unit, which is used to receive a block query request from a client through a first accounting node in a source block fragment, wherein the block query request includes: a target shard block number and accounting data information to be queried; a block fragment query unit, which is used to respond to the block query request, query the local block history record through the first accounting node, and determine the shard block number indicated by the target block number. The target block fragment to which the shard block belongs and the corresponding shard block cluster; an accounting node address acquisition unit, used to obtain the node address of the second accounting node corresponding to the target block fragment, and return the node address of the second accounting node to the client; a second block query request receiving unit, used to receive a new block query request initiated by the client through the second accounting node, wherein the new block query request includes: the node address of the second accounting node, the target shard block number and the accounting data information to be queried; an account data returning unit, used to respond to the new block query request, and return the account data corresponding to the target shard block number to the client through the second accounting node.
[0014] Optionally, the data query device based on the blockchain network also includes: a node scanning unit, which is used to scan the shard block information of the current terminal through the accounting node after detecting that the accounting node corresponding to any block fragment in the blockchain network is started before receiving the block query request of the client through the first accounting node in the source block fragment, and obtain the start bit and end bit of the block fragment; a block cluster establishment unit, which establishes a shard block cluster corresponding to the block fragment based on the start bit and end bit of the block fragment; a block index information recording unit, which is used to record the block index information and node information of the shard block cluster in the world state database through the accounting node; an index information broadcasting unit, which is used to broadcast the block index information and the node information to each accounting node in other block fragments through the accounting node, wherein each accounting node in other block fragments records the block index information and the node information in the local world state database.
[0015] Optionally, the block fragment query unit includes: a block index query module, which is used to respond to the block query request, query the block index information in the local world state database, and determine whether the target shard block number is located in the fragment interval of the source block fragment; a block fragment determination module, which is used to index the block index information and node information broadcasted in the history of each accounting node in other block fragments when the target shard block number is not located in the fragment interval of the source block fragment, and obtain the target block fragment and the corresponding shard block cluster to which the shard block indicated by the target block number belongs.
[0016] Optionally, the data query device based on the blockchain network further includes: a first block write request unit, configured to receive a block write request from the client through the first accounting node in the source block fragment before receiving the block query request from the client through the first accounting node in the source block fragment, wherein the block write request includes at least: the node address of the first accounting node and the block information of the block to be sharded; a first write request response unit, configured to respond to the block write request, query the local historical block record through the first accounting node, and obtain the fragment interval status of the source block fragment; a node address positioning unit, configured to respond to the block write request, query the local historical block record through the first accounting node, and obtain the fragment interval status of the source block fragment; and a node address positioning unit, configured to respond to the block write request, query the local historical block record through the first accounting node, and obtain the fragment interval status of the source block fragment when the fragment interval status indicates that the source block fragment is a read-only interval. In this case, the first accounting node is used to query the block fragment whose fragment interval status is the write interval, locate the shard block cluster corresponding to the block fragment and the node address of the third accounting node, and return the node address of the third accounting node to the client; the second block write request unit is used to receive the new block write request initiated by the client through the third accounting node, wherein the new block write request includes: the node address of the third accounting node and the block information of the block to be sharded; the second write request response unit is used to respond to the new block write request, perform block accounting processing through the third accounting node, generate a block number receipt, and return the block number receipt to the client.
[0017] Optionally, in the process of pre-dividing the blockchain network into N sequentially connected block fragments, the data query device based on the blockchain network includes: a block fragment division unit, used to determine the starting shard block number and the ending shard block number of each block fragment according to the total number of blocks in the blockchain network and a predetermined fragment interval range, wherein the block numbers between the block fragments do not overlap.
[0018] Optionally, the first N-1 block segments of the N block segments are closed intervals, and the Nth block segment is an open interval.
[0019] Optionally, the cluster state of the shard block cluster corresponding to the first N-1 block fragments among the N block fragments is in a read-only state, and block writes are not accepted; the cluster state of the shard block cluster corresponding to the Nth block fragment is in a writable state, and block writes are accepted.
[0020] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is further provided, wherein the computer-readable storage medium includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute any one of the above-mentioned blockchain network-based data query methods.
[0021] According to another aspect of an embodiment of the present invention, an electronic device is also provided, comprising one or more processors and a memory, wherein the memory is used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement any one of the above-mentioned data query methods based on a blockchain network.
[0022] According to another aspect of an embodiment of the present invention, a computer program product is also provided, including a computer program, which, when executed by a processor, implements the steps of any one of the above-mentioned blockchain network-based data query methods.
[0023] In the present disclosure, a block query request from a client is received through a first accounting node in a source block fragment, wherein the block query request includes: a target shard block number and accounting data information to be queried; in response to the block query request, the local block history record is queried through the first accounting node to determine the target block fragment and the corresponding shard block cluster to which the shard block indicated by the target block number belongs; the node address of the second accounting node corresponding to the target block fragment is obtained, and returned to the client based on the node address of the second accounting node; a new block query request initiated by the client is received through the second accounting node, wherein the new block query request includes: the node address of the second accounting node, the target shard block number and accounting data information to be queried; in response to the new block query request, the ledger data corresponding to the target shard block number is returned to the client through the second accounting node.
[0024] According to the above-mentioned public content, when a user wants to query the ledger data of a target block, it can quickly locate the corresponding block fragment according to the block number. If the target block is not within the range of the current block fragment, the accounting node will use the previously collected global block interval information to quickly query the target block fragment range and the node address of the corresponding accounting node. The client can directly initiate a query to the accounting node, avoiding polling access between clusters. This can significantly improve the query and write efficiency of data in the segmented blockchain network, reduce unnecessary network communication, and reduce system latency and resource consumption, thereby solving the technical problems in related technologies that when querying specific block data in the blockchain, all clusters need to be traversed, there is a lack of effective positioning strategy, and the query efficiency is low. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0026] Figure 1 Schematic diagram of sharding a blockchain network according to the first embodiment of the present invention;
[0027] Figure 2 2. It is a schematic diagram of interval information broadcasting between each block fragment in the application blockchain network according to the first embodiment of the present invention;
[0028] Figure 3 is a schematic diagram of an optional method for extracting block ledger data according to an embodiment of the present invention;
[0029] Figure 4 This is a flowchart of an optional data query method based on a blockchain network according to Embodiment 1 of the present invention;
[0030] Figure 5 2 is a schematic diagram of an optional data query device based on a blockchain network according to an embodiment of the present invention;
[0031] Figure 6 This is a hardware structure block diagram of an electronic device (or mobile device) according to a data query method based on a blockchain network according to an embodiment of the present invention. DETAILED DESCRIPTION
[0032] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.
[0033] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0034] To facilitate those skilled in the art to understand the present invention, some of the terms or nouns involved in the embodiments of the present invention are explained below:
[0035] The client is the front end through which users or applications interact with the blockchain network, initiating block queries or write requests.
[0036] A request is an instruction or query message sent by a client when communicating with a blockchain network. Specifically, it can be a block query request or a block write request.
[0037] Response, when the node of the blockchain network receives the request from the client, it processes it according to the request content and returns the result information.
[0038] A blockchain cluster is a collection of multiple blockchain nodes running on a specific block interval. Each cluster is responsible for managing the block data within its interval.
[0039] org1, organization, is an organizational unit in the blockchain network, which may represent different enterprises, institutions or entities. Each organization can have its own accounting node.
[0040] ClosedInterval, in the blockchain context, refers to a blockchain interval with a fixed start and end block number, such as [1,9999]. Once the interval is determined, no new transactions or blocks will be accepted.
[0041] Open Interval, in the blockchain scenario, refers to a blockchain interval with only a starting block number but no ending block number. It has a starting block number but no ending block number, such as: [10000,+∞). It can continuously receive new transactions and block writes.
[0042] A read-only cluster refers to a blockchain cluster running in a closed interval. Since this interval no longer accepts write operations, the cluster is in a read-only state.
[0043] It should be noted that the data query method and device based on the blockchain network in the present disclosure can be used in the field of blockchain technology when the query of block ledger data is realized based on the segmented blockchain, and can also be used in any field other than the field of blockchain technology when the query of block ledger data is realized based on the segmented blockchain. The application field of the data query method and device based on the blockchain network in the present disclosure is not limited.
[0044] It should be noted that the information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) collected by this disclosure are information and data authorized by the user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of relevant data comply with the relevant laws, regulations and standards of the relevant regions, take necessary confidentiality measures, do not violate public order and good morals, and provide corresponding operation portals for users to choose to authorize or refuse. For example, an interface is set up between this system and relevant users or institutions. Before obtaining relevant information, it is necessary to send an acquisition request to the aforementioned user or institution through the interface, and obtain relevant information after receiving the consent information fed back by the aforementioned user or institution.
[0045] It should be noted that in this disclosure, when collecting and analyzing customer information, the corresponding operation entrance is provided for users to choose to agree or reject the automated decision-making results; if the user chooses to reject, the expert decision-making process will be entered.
[0046] The following embodiments of the present invention can be applied to various systems / applications / devices for data query based on blockchain networks. The present invention can be applied to various scenarios / systems running blockchain networks / distributed transportation, such as financial settlement, supply chain management, data storage, Internet of Things (IoT) data processing and other fields, especially in application scenarios involving large-scale data storage and high-speed query requirements. For example, in financial transaction systems, for real-time recording and rapid query of high-frequency transaction data, the embodiments of the present application can significantly improve transaction confirmation speed and data accessibility, reduce delays and costs. In supply chain management scenarios, for complex supply chains, each step of the transaction or flow of goods needs to be accurately recorded and traced. The embodiments of the present application accelerate information flow and improve supply chain transparency through efficient data positioning and retrieval.
[0047] By establishing a block interval index and cluster positioning mechanism, this invention avoids polling queries on blockchain clusters, significantly improving query speed and reducing query latency. Furthermore, this invention can reduce ineffective communication between clusters, conserve network bandwidth, reduce communication energy consumption, and optimize overall system performance.
[0048] Furthermore, this invention makes interactions within the blockchain network transparent to users, eliminating the need to expose all cluster node configurations. This enhances the security of the entire blockchain network and prevents external attacks and malicious access. Users only need to know a single ledger node peer to complete all block request interactions, simplifying system maintenance and management and reducing operational complexity.
[0049] The present invention will be described in detail below with reference to various embodiments.
[0050] Example 1
[0051] According to an embodiment of the present invention, an embodiment of a data query method based on a blockchain network is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in an order different from that shown here.
[0052] According to one aspect of an embodiment of the present invention, a data query method based on a blockchain network is provided. The blockchain network is pre-divided into N block fragments connected in sequence, and the fragment interval of each block fragment contains multiple shard blocks and accounting nodes.
[0053] Figure 1 Schematic diagram of sharding a blockchain network according to the first embodiment of the present invention. Figure 1As shown in the figure, the current blockchain is divided into three blockchain clusters, corresponding to cluster 1, cluster 2, and cluster 3 from left to right. Cluster 1 has a block space of [0, i-1]; cluster 2 has a block space of [i, n-1]; and cluster 3 has a block space of [n, +∞).
[0054] Since cluster1 and cluster2 are running on closed intervals, the block fragment / shard block cluster is in read-only state and no longer accepts block writes. Cluster3 is running on the block fragment of the open interval and can accept block writes.
[0055] Each block fragment corresponds to a ledger node (Blockchain Ledger), which records the ledger data of each block in the block fragment.
[0056] Figure 2 Schematic diagram of interval information broadcasting between each block fragment in the application blockchain network according to the first embodiment of the present invention, such as Figure 2 As shown in the figure, the block storage interval information is exchanged between each block fragment / shard block cluster through broadcasting. The relevant information is stored in the world state database of each node.
[0057] When a new block segment is generated, the newly generated closed interval cluster and open interval cluster will broadcast the interval information they manage, and each cluster will update and replace related records.
[0058] Exchange of block interval information during broadcast, such as:
[0059] [0,i-1]: cluster1;
[0060] [i,n-1]: cluster2;
[0061] [n,+∞): cluster3;
[0062] Exchange of cluster information in broadcasts, such as:
[0063] cluster1:[peer0.org1.com:ip1];
[0064] cluster2:[peer0.org2.com:ip2];
[0065] cluster3:[peer0.org3.com:ip3].
[0066] Figure 3is a schematic diagram of an optional method for extracting block ledger data according to an embodiment of the present invention, such as Figure 3 As shown in the figure, when the user / client holds the block number and needs to query the ledger data of the block, it will initiate a block query request to the task blockchain cluster through the corresponding blockchain node ( Figure 3 The current node finds the block fragment / target shard block cluster by querying the cluster information of the block number in the world state database, and then finds the corresponding accounting node address of the new block fragment / target shard block cluster. It forwards the query request to the corresponding accounting node of the block fragment / target shard block cluster and obtains the receipt result.
[0067] The following combination Figures 1 to 3 The schematic blockchain network is used to illustrate the embodiments of the present invention in detail.
[0068] Figure 4 This is a flowchart of an optional data query method based on a blockchain network according to the first embodiment of the present invention. Figure 4 As shown, the method includes the following steps:
[0069] In this embodiment, the blockchain network is pre-divided into N sequentially connected block segments. This partitioning strategy is intended to optimize data storage and query efficiency while accommodating dynamic data growth. Optionally, the process of pre-dividing the blockchain network into N sequentially connected block segments includes determining a starting shard block number and an ending shard block number for each block segment based on the total number of blocks in the blockchain network and a predetermined segment interval range, wherein the block numbers of the block segments do not overlap.
[0070] In the process of dividing the N block segments, this embodiment considers the total number of blocks and the predetermined segment range, and uses this as a basis to determine the starting and ending shard block numbers of each block segment. This division ensures that the shard block numbers within each block segment are continuous and that the block numbers between block segments do not overlap. In other words, any block number belongs to only one block segment, avoiding confusion in data management.
[0071] Optionally, the first N-1 block segments among the N block segments are closed intervals, and the Nth block segment is an open interval.
[0072] In this example, the first N-1 block segments that have been divided and used are considered closed intervals, while the Nth block segment is considered open intervals. This division method reflects the phased nature of data storage: data within closed intervals is complete and no new data is accepted. Open intervals, on the other hand, are used to accept new transactions and write operations. As network transactions proceed, open intervals will continue to expand and may eventually become closed intervals.
[0073] Optionally, the cluster state of the shard block cluster corresponding to the first N-1 block fragments in the N block fragments is read-only and does not accept block writes; the cluster state of the shard block cluster corresponding to the Nth block fragment is writable and accepts block writes.
[0074] In this embodiment, when dividing the N block segments, the sharded block clusters corresponding to the first N-1 block segments are in a read-only state, meaning that these clusters will no longer accept any new block write operations. This read-only state, based on the closed interval property of the block segments, helps maintain data integrity and historical record accuracy. Conversely, the sharded block cluster corresponding to the Nth block segment is in a writable state, processing new transaction records and block writes. Clusters in a writable state are active in the network, responsible for real-time data updates and storage, and are the primary carrier of data growth in the blockchain network.
[0075] It should be noted that as the amount of data in the blockchain network continues to grow, this embodiment allows for the dynamic addition of new open interval block fragments to accommodate higher data storage requirements. If the current open interval can no longer meet the write requirements, a new open interval block fragment can be created, and the original open interval is converted into a closed interval.
[0076] Because closed interval block segments do not accept new writes, their data structure is relatively stable, allowing for more efficient data indexing and querying techniques, such as building index trees, to further improve data query speed. Furthermore, read-only clusters can utilize caching technology to store frequently accessed data in memory, reducing disk access times.
[0077] The open interval block segment is responsible for receiving new write operations. To ensure data security and consistency, this embodiment can adopt a consensus mechanism such as PBFT (Practical Byzantine Fault Tolerance) or DPoS (Delegated Proof of Stake) to ensure that all nodes reach consensus before writing a new block. In addition, because write operations are concentrated in the writable cluster, this makes it possible to implement data writes efficiently. For example, distributed file systems or database technologies can be used to achieve parallel writes and fast confirmation.
[0078] In this embodiment, each cluster node is required to regularly broadcast information about the block intervals it manages and its node status to ensure that other nodes in the network can promptly update their local world state databases. This not only facilitates accurate data location but also enhances network transparency and trust. Furthermore, the cluster's read-only and writable states simplify cluster management and maintenance, reducing the complexity of system operations.
[0079] Step S401: Receive a block query request from a client through the first accounting node in the source block fragment, wherein the block query request includes: the target shard block number and the accounting data information to be queried.
[0080] In this embodiment, the client, as the initiator of a data query, primarily submits a query request to the blockchain network. This query request contains two key pieces of information: the target shard block number and the accounting data to be queried. The target shard block number is the block number specified by the client, used to locate the block fragment within which the queried data resides, while the accounting data is the specific data content or data identifier that the client wishes to retrieve.
[0081] In this embodiment, the first accounting node is the node in the blockchain network that the client first contacts. It is typically located in a source block fragment known to the client. The source block fragment can be any block fragment, but the client generally tends to use the most recent or most frequently used node as the starting point for the query. After receiving the client's query request, the first accounting node acts as an intermediary or proxy for the query, including but not limited to receiving the query request, initially retrieving local data, locating the target block fragment, and returning instructions to the client for the next query.
[0082] It should be noted that the target shard block number mentioned in this embodiment is the number of the specific block that the client wants to query, which is used to accurately locate the block position of the data. Under the segmented blockchain architecture, each block fragment is responsible for managing block numbers within a certain range. Therefore, the target shard block number is the key to determining the data storage location.
[0083] The accounting data information to be queried mentioned in this embodiment refers to more specific information that the client needs to provide, such as transaction hash, account address, timestamp, etc., so that the first accounting node can more accurately locate and obtain data.
[0084] Step S402: In response to the block query request, query the local block history record through the first accounting node to determine the target block segment to which the shard block indicated by the target block number belongs and the corresponding shard block cluster.
[0085] Optionally, step S402 includes: responding to a block query request, querying block index information in a local world state database, and determining whether the target shard block number is located in the fragment interval of the source block fragment; if the target shard block number is not located in the fragment interval of the source block fragment, indexing the block index information and node information broadcasted in the history of each accounting node in other block fragments, and obtaining the target block fragment to which the shard block indicated by the target block number belongs and the corresponding shard block cluster.
[0086] In this embodiment, in response to a block query request, the first accounting node immediately queries its locally stored block history records. This is the first step in determining the target block fragment. The local history records contain block information directly managed by the node, including block number ranges and status (read-only or writable). The purpose of the query is to identify whether the target block number is within the fragment range managed by the current node, that is, to determine whether the target shard block belongs to the source block fragment.
[0087] In this embodiment, the first accounting node further queries the local world state database for more detailed block index information. The world state database stores the distribution of all block fragments across the entire blockchain network, including the starting and ending block numbers of each fragment and the accounting node responsible for managing that fragment. The determination process involves comparing the target block number with the block index information stored in the database to verify whether it falls within the range managed by the current node. If the target block number falls within the current node's management range, the query process will be directly performed in the local cluster; otherwise, further positioning is required.
[0088] If the target shard block number does not fall within the fragment interval of the source block fragment, this embodiment requires the first accounting node to index and utilize the block index information historically broadcast by accounting nodes of other block fragments. This information reflects the distribution of blocks across the network, including the cluster information corresponding to each interval. By indexing this historical data, the first accounting node can determine the correct block fragment and its corresponding cluster to which the target block number belongs. This operation relies on the mutual synchronization and broadcast mechanism between blocks, ensuring that all nodes have a common understanding of the network status, thereby avoiding blind polling and ineffective communication between clusters.
[0089] Through the above steps, the first accounting node in this embodiment can quickly locate the block fragment where the target block is located and obtain the cluster information of the fragment, including the address of the accounting node in the cluster. Once the location of the target block is determined, the first accounting node returns the address of the second accounting node corresponding to the target block fragment to the client. The client then directly initiates a query to the node, reducing intermediate links and improving query efficiency.
[0090] It should be noted that the world state database of this embodiment is updated regularly to ensure the latest status of information between nodes, which is crucial for fast responses to block queries and write requests.
[0091] Step S403: Obtain the node address of the second accounting node corresponding to the target block segment, and return it to the client based on the node address of the second accounting node.
[0092] In this embodiment, when the first accounting node receives a block query request from the client, it will immediately perform a local query operation to determine which block fragment the target shard block number specified in the request belongs to. Once the target block fragment is determined, the first accounting node will consult the block index information in its world state database and extract the node address information of the second accounting node that matches the target block fragment. The node address information may include but is not limited to the IP address and port number.
[0093] After finding the target node address, the first accounting node does not directly perform the query action, but adopts an indirect communication strategy, that is, it feeds back the node address information of the second accounting node to the client, instructing the client to directly establish a connection with the second accounting node and initiate subsequent block query requests.
[0094] Step S404: Receive a new block query request initiated by the client through the second accounting node, where the new block query request includes: the node address of the second accounting node, the target shard block number, and the accounting data information to be queried.
[0095] The client obtains the network address of the second accounting node and can directly send a new block query request to the second accounting node. Upon receiving the new block query request, the second accounting node immediately searches its local blockchain ledger for block data that matches the target shard block number. Because the second accounting node in this embodiment is located within the target block fragment, it has the most direct and complete data access rights, allowing it to quickly locate and extract the required information. After the query is complete, the second accounting node organizes and packages the retrieved accounting data and directly returns it to the client, avoiding repeated queries across multiple nodes, thereby significantly improving overall query speed and system responsiveness.
[0096] Furthermore, the query operation of the second accounting node in this embodiment adheres to the principle of minimal transmission, that is, only transmitting necessary data information, avoiding data redundancy and bandwidth waste. This is particularly important for handling large-scale data storage and high-concurrency user queries. Furthermore, by ensuring direct interaction between the client and the target accounting node, the security of the blockchain network is enhanced, reducing the possibility of intermediate nodes being attacked or tampered with, thereby ensuring data integrity and transaction security.
[0097] Step S405: In response to the new block query request, the ledger data corresponding to the target shard block number is returned to the client through the second accounting node.
[0098] When a client initiates a new block query request for a target shard block number, the second accounting node in this embodiment, acting as the accounting node within the target block segment, is designed to directly process and respond to such query requests, providing accurate ledger data. Upon receiving the new block query request, the second accounting node immediately performs a data retrieval operation. Using the block information stored on the node, the second accounting node locates the specific location of the target shard block number and extracts the required ledger data. This data is then packaged into a response message and transmitted directly over the network to the initiator of the query request, the client.
[0099] Before returning the ledger data, the second accounting node performs data integrity verification to ensure that the data has not been tampered with, in accordance with the core principles of blockchain technology. This may include calculating the hash value of the data and comparing it with the hash value stored in the block header to verify the validity and consistency of the data. To protect the security of ledger data during transmission, the data exchange in this embodiment uses encrypted communication technology. When the second accounting node returns the ledger data to the client, it encrypts the data, ensuring that only legitimate clients can decrypt and use the data, preventing data leakage or illegal interception during transmission.
[0100] Through the above steps, the block query request of the client can be received through the first accounting node in the source block fragment, wherein the block query request includes: the target shard block number and the accounting data information to be queried; in response to the block query request, the local block history record is queried through the first accounting node to determine the target block fragment and the corresponding shard block cluster to which the shard block indicated by the target block number belongs; the node address of the second accounting node corresponding to the target block fragment is obtained, and returned to the client based on the node address of the second accounting node; the new block query request initiated by the client is received through the second accounting node, wherein the new block query request includes: the node address of the second accounting node, the target shard block number and the accounting data information to be queried; in response to the new block query request, the ledger data corresponding to the target shard block number is returned to the client through the second accounting node. In this embodiment, when the user terminal wants to query the ledger data of a target block, it can quickly locate the corresponding block fragment according to the block number. If the target block is not within the range of the current block fragment, the accounting node will use the previously collected global block interval information to quickly query the target block fragment range and the node address of the corresponding accounting node. The client can directly initiate a query to the accounting node, avoiding polling access between clusters, which can significantly improve the query and write efficiency of data in the segmented blockchain network, reduce unnecessary network communication, and reduce system latency and resource consumption, thereby solving the technical problems in related technologies that when querying specific block data in the blockchain, all clusters need to be traversed, there is a lack of effective positioning strategy, and the query efficiency is low.
[0101] This embodiment provides a startup and initialization process before the client queries, ensuring that each block fragment in the blockchain network has an accurate location and all nodes have a common understanding of the network status.
[0102] Optionally, before receiving the block query request of the client through the first accounting node in the source block fragment, it also includes: after the accounting node corresponding to any block fragment in the blockchain network is started, scanning the shard block information of the current terminal through the accounting node to obtain the start bit and end bit of the block fragment; based on the start bit and end bit of the block fragment, establishing a shard block cluster corresponding to the block fragment; recording the block index information and node information of the shard block cluster in the world state database through the accounting node; broadcasting the block index information and node information to each accounting node in other block fragments through the accounting node, wherein each accounting node in other block fragments records the block index information and node information in the local world state database.
[0103] When the accounting node corresponding to any block fragment in the blockchain network is activated, it automatically performs a scan operation, checking the shard block information currently stored on the terminal, thereby determining the start and end bits of the block fragment, ensuring that the node has a clear understanding of the data range within its management interval. Based on the start and end bits of the block fragment, the accounting node can then build a shard block cluster corresponding to the block fragment. The establishment of the cluster involves communication between nodes, data synchronization, and the operation of the consensus algorithm, ensuring that all nodes in the cluster can share and maintain data for the same block fragment while maintaining data consistency and integrity.
[0104] The accounting node records the block index information and node information of the sharded block cluster in the world state database. This information includes the block number range that the cluster is responsible for, the network address (IP address and port number) of each node in the cluster, etc., providing important guidance for subsequent query and write operations.
[0105] Furthermore, the accounting node can broadcast the block index information and node information to the accounting nodes in other block fragments through the network. This embodiment ensures that the nodes in the entire blockchain network can update the world state database in a timely manner through the broadcast mechanism and obtain the latest network status, including the distribution of all block fragments and the corresponding accounting node information. This process promotes collaborative work between nodes and ensures the efficiency and accuracy of data query.
[0106] It's important to note that when accounting nodes broadcast information to other nodes, they employ distributed consensus mechanisms, such as the Byzantine Fault Tolerance (PBFT) algorithm, to ensure consistency across all nodes, preventing data inconsistencies caused by network delays or node failures. The inter-node information broadcast and local database updates provide direct location information for queries. Clients can send requests directly to nodes within the target block segment without traversing the entire network, significantly improving query efficiency and reducing ineffective network communication.
[0107] Optionally, before receiving the block query request from the client through the first accounting node in the source block fragment, the method further includes: receiving a block write request from the client through the first accounting node in the source block fragment, wherein the block write request includes at least: the node address of the first accounting node and the block information of the block to be sharded; in response to the block write request, querying the local historical block record through the first accounting node to obtain the fragment interval status of the source block fragment; when the fragment interval status indicates that the source block fragment is a read-only interval, querying the block fragment whose fragment interval status is a write interval through the first accounting node, locating the shard block cluster corresponding to the block fragment and the node address of the third accounting node, and returning the node address of the third accounting node to the client; receiving a new block write request initiated by the client through the third accounting node, wherein the new block write request includes: the node address of the third accounting node and the block information of the block to be sharded; in response to the new block write request, performing block accounting processing through the third accounting node, generating a block number receipt, and returning the block number receipt to the client.
[0108] Before responding to a new block query request, this embodiment receives a client's block write request through the first accounting node in the source block fragment. The block write request carries the node address of the first accounting node (as the starting point of communication) and the block information of the block to be sharded, including transaction data, account information, etc. After receiving the write request, this embodiment first queries the local historical block record to determine the fragment interval status of the current source block fragment. The fragment interval status reflects whether the fragment is a read-only interval, that is, whether it accepts new block write operations.
[0109] If the query result shows that the source block segment is a read-only interval, indicating that the write operation cannot be performed on the current node, the first accounting node designed in this embodiment will not directly reject the request. Instead, it will adopt an intelligent positioning strategy to find the block segment in the write interval. The first accounting node will consult its world state database, index the segment interval status information recorded therein, and locate the block segment whose segment interval status is the write interval, ensuring that the write operation can be efficiently performed on the correct block segment.
[0110] Once the block fragment of the write interval is found, the first accounting node will further determine the shard block cluster corresponding to the fragment and the node address of the third accounting node that can perform the write operation, and return it to the client, guiding the client to initiate a new block write request to the correct accounting node.
[0111] After receiving the address of the third-party accounting node from the first accounting node, the client initiates a new block write request to the third-party accounting node. The request also includes the node address of the third-party accounting node and the block information of the block to be sharded. After receiving the new block write request, the third-party accounting node performs block accounting processing, namely transaction verification, data writing, and block creation. This process may involve the operation of a consensus mechanism such as PoW (Proof of Work), PoS (Proof of Stake), or PBFT (Practical Byzantine Fault Tolerance) to ensure data accuracy and network consistency.
[0112] After successful accounting, the third accounting node returns the generated block number to the client in the form of a receipt as confirmation that the write operation is complete. This block number is the unique identifier of the newly created block and can be used for subsequent queries and transaction confirmations.
[0113] Through this embodiment, it can be seen that the separation of node status (read-only or write) and function (query or write processing) in the blockchain network is reasonable and necessary. This separation not only optimizes the data processing flow and reduces invalid write requests, but also improves the overall efficiency and security of the network.
[0114] In addition, the block write request processing flow of this embodiment can also realize the dynamic adjustment capability of the blockchain network. As the network scale expands and the block data increases, the write operation can be intelligently directed to the write interval with lower load, avoiding the bottleneck of data writing and ensuring the scalability and high performance of the system.
[0115] The following describes in detail another optional specific implementation.
[0116] like Figures 1 to 3 As shown, the current blockchain is divided into three intervals, corresponding to cluser1, cluser2, and cluser3 respectively.
[0117] Among them, the block space of cluster1 is [0,9999].
[0118] Among them, the block space of cluster2 is [10000,19999].
[0119] Among them, the block space of cluster3 is [20000,+∞).
[0120] Cluster1 contains org1, which contains the accounting node peer0.org1.com, with the IP address 192.168.1.1.
[0121] Cluster2 contains org2, which contains the accounting node peer0.org1.com, with the IP address 192.168.2.1.
[0122] Cluster3 contains org3, which contains the accounting node peer0.org1.com, with the IP address 192.168.3.1.
[0123] First, the block interval index creation mode is described, which includes the following steps:
[0124] Step 1. After the accounting node peer0 in cluster1 is started, it scans the local block information and finds that the start and end positions of the block are [0, 9999].
[0125] Step 2. peer0 creates the block index information [0, 9999] of the cluster: cluster1, and the node information cluster1: [peer0.org1.com:192.168.1.1] in its own world state database.
[0126] Step 3. peer0 broadcasts the index information and node information to the nodes of cluster2 and cluster3.
[0127] Step 4. The accounting node of cluster 2 receives this information and records it in the local world state database.
[0128] Step 5. The accounting node of cluster 3 receives this information and records it in the local world state database.
[0129] Step 6. After peer0 in cluster2 starts, it scans the local block information and finds that the start and end positions of the block are [10000, 19999].
[0130] Step 7. peer0 creates the index information of the cluster [10000, 19999]: cluster2 and the node information cluster1: [peer0.org1.com:192.168.2.1] in its own world state database.
[0131] Step 8. peer0 broadcasts the index information and node information to cluster1 and cluster3.
[0132] Step 9. The accounting node of cluster 1 receives this information and records it in the local world state database.
[0133] Step 10. The accounting node of cluster 3 receives this information and records it in the local world state database.
[0134] Step 11. After peer0 in cluster3 starts, it scans the local block information and finds that the start and end positions of the block are [20000, +∞].
[0135] Step 12. peer0 creates the index information of the cluster [20000, +∞]: cluster3 and the node information cluster1: [peer0.org1.com:192.168.3.1] in its own world state database.
[0136] Step 13. peer0 broadcasts the index information and node information to cluster1 and cluster2.
[0137] Step 14. The accounting node of cluster 1 receives this information and records it in the local world state database.
[0138] Step 15. The accounting node of cluster 2 receives this information and records it in the local world state database.
[0139] Next, the writing mode of each block is described, which includes the following steps:
[0140] Step 1. The user initiates a block write operation to the peer0 node of cluster1 through the client.
[0141] Step 2. peer0 queries the local block record as closed block [0.9999], which is a read-only interval.
[0142] Step 3. The peer finds the open interval [20000, +∞), which corresponds to cluster 3.
[0143] Step 4. peer0 queries the accounting node IP in cluster3 and finds it is 192.168.3.1.
[0144] Step 5. peer0 writes the new request address back to the client.
[0145] Step 6. The client initiates a write request to peer0:192.168.3.1 of cluster3.
[0146] Step 7. peer0 queries the local block record and finds that the interval is [20000, +∞), which is a writable interval.
[0147] Step 8. The peer node of cluster3 records the receipt of block number 20001.
[0148] Step 9. The client receives the write receipt for block number 20001.
[0149] Next, let's explain the query mode for each block, which includes the following steps:
[0150] Step 1. The user initiates a query operation for block 20001 to peer0 of cluster1 through the client.
[0151] Step 2. peer0 queries the local block record [0,9999], which is not within this range.
[0152] Step 3. peer0 queries the local block record [10000,19999], which is not within this range.
[0153] Step 4. peer0 queries its local block record [20000, +∞)], which includes 20001 and corresponds to cluser3.
[0154] Step 5. peer0 finds that the accounting node IP in cluster3 is 192.168.3.1.
[0155] Step 6. peer0 writes the new request address back to the client.
[0156] Step 7. The client sends a query for block 20001 to peer0:192.168.3.1 of cluster3.
[0157] Step 8. Peer 0 of cluster 3 queries the local block record, which is an open interval [20000, +∞). This block contains 20001.
[0158] Step 9. The peer node of cluser3 returns the ledger data corresponding to 20001.
[0159] Step 10. The client receives the query result.
[0160] Through the above-described implementation, the present invention establishes a mapping between block interval index information and cluster nodes, creating a method for quickly locating blocks in blockchain clusters. This improves block query efficiency and avoids the significant amount of inefficient communication caused by cluster polling. Users only need to know a single peer to complete all block request interactions, simplifying maintenance.
[0161] The following describes it in detail with reference to another embodiment.
[0162] Example 2
[0163] A data query device based on a blockchain network provided in this embodiment includes multiple implementation units, each implementation unit corresponding to each implementation step in the above-mentioned embodiment one.
[0164] According to another aspect of an embodiment of the present invention, a data query device based on a blockchain network is also provided. The blockchain network is pre-divided into N block fragments connected in sequence, and the fragment interval of each block fragment contains multiple shard blocks and accounting nodes.
[0165] Figure 5 is a schematic diagram of an optional data query device based on a blockchain network according to an embodiment of the present invention. Figure 5 As shown, the data query device based on the blockchain network may include: a first block query request receiving unit 51, a block fragment query unit 52, an accounting node address acquisition unit 53, a second block query request receiving unit 54, and an account data returning unit 55.
[0166] Among them, the first block query request receiving unit 51 is used to receive the block query request of the client through the first accounting node in the source block fragment, wherein the block query request includes: the target shard block number and the accounting data information to be queried.
[0167] The block fragment query unit 52 is used to respond to the block query request, query the local block history record through the first accounting node, and determine the target block fragment and the corresponding shard block cluster to which the shard block indicated by the target block number belongs.
[0168] The accounting node address obtaining unit 53 is used to obtain the node address of the second accounting node corresponding to the target block segment, and return it to the client based on the node address of the second accounting node.
[0169] The second block query request receiving unit 54 is used to receive a new block query request initiated by the client through the second accounting node, wherein the new block query request includes: the node address of the second accounting node, the target shard block number and the accounting data information to be queried.
[0170] The ledger data returning unit 55 is used to respond to the new block query request and return the ledger data corresponding to the target shard block number to the client through the second accounting node.
[0171] The above-mentioned data query device based on the blockchain network can receive a block query request from a client through the first accounting node in the source block fragment through the first block query request receiving unit 51, wherein the block query request includes: the target shard block number and the accounting data information to be queried. The block query request is responded to by the block fragment query unit 52, and the local block history is queried through the first accounting node to determine the target block fragment and the corresponding shard block cluster to which the shard block indicated by the target block number belongs. The node address of the second accounting node corresponding to the target block fragment is obtained through the accounting node address acquisition unit 53, and is returned to the client based on the node address of the second accounting node. The new block query request initiated by the client is received through the second accounting node through the second block query request receiving unit 54, wherein the new block query request includes: the node address of the second accounting node, the target shard block number and the accounting data information to be queried. The new block query request is responded to by the ledger data returning unit 55, and the ledger data corresponding to the target shard block number is returned to the client through the second accounting node. In this embodiment, when the user terminal wants to query the ledger data of a target block, it can quickly locate the corresponding block fragment according to the block number. If the target block is not within the range of the current block fragment, the accounting node will use the previously collected global block interval information to quickly query the target block fragment range and the node address of the corresponding accounting node. The client can directly initiate a query to the accounting node, avoiding polling access between clusters, which can significantly improve the query and write efficiency of data in the segmented blockchain network, reduce unnecessary network communication, and reduce system latency and resource consumption, thereby solving the technical problems in related technologies that when querying specific block data in the blockchain, all clusters need to be traversed, there is a lack of effective positioning strategy, and the query efficiency is low.
[0172] Optionally, the data query device based on the blockchain network also includes: a node scanning unit, which is used to scan the shard block information of the current terminal through the accounting node after detecting that the accounting node corresponding to any block fragment in the blockchain network is started before receiving the block query request of the client through the first accounting node in the source block fragment, and obtain the start bit and end bit of the block fragment; a block cluster establishment unit, which establishes a shard block cluster corresponding to the block fragment based on the start bit and end bit of the block fragment; a block index information recording unit, which is used to record the block index information and node information of the shard block cluster in the world state database through the accounting node; an index information broadcasting unit, which is used to broadcast the block index information and node information to each accounting node in other block fragments through the accounting node, wherein each accounting node in other block fragments records the block index information and node information in the local world state database.
[0173] Optionally, the block fragment query unit includes: a block index query module, which is used to respond to a block query request, query the block index information in the local world state database, and determine whether the target shard block number is located in the fragment interval of the source block fragment; a block fragment determination module, which is used to, when the target shard block number is not located in the fragment interval of the source block fragment, index the block index information and node information broadcasted in the historical process of each accounting node in other block fragments, and obtain the target block fragment to which the shard block indicated by the target block number belongs and the corresponding shard block cluster.
[0174] Optionally, the data query device based on the blockchain network further includes: a first block write request unit, configured to receive a block write request from the client through the first accounting node in the source block fragment before receiving the block query request from the client through the first accounting node in the source block fragment, wherein the block write request includes at least: the node address of the first accounting node and the block information of the block to be sharded; a first write request response unit, configured to respond to the block write request, query the local historical block record through the first accounting node, and obtain the fragment interval status of the source block fragment; a node address positioning unit, configured to indicate that the source block fragment is read-only when the fragment interval status indicates that the source block fragment is read-only. In the case of a shard interval, the first accounting node is used to query the block fragment whose fragment interval status is the write interval, locate the shard block cluster corresponding to the block fragment and the node address of the third accounting node, and return the node address of the third accounting node to the client; the second block write request unit is used to receive a new block write request initiated by the client through the third accounting node, wherein the new block write request includes: the node address of the third accounting node and the block information of the block to be sharded; the second write request response unit is used to respond to the new block write request, perform block accounting processing through the third accounting node, generate a block number receipt, and return the block number receipt to the client.
[0175] Optionally, in the process of pre-dividing the blockchain network into N sequentially connected block fragments, the data query device based on the blockchain network includes: a block fragment division unit, used to determine the starting shard block number and the ending shard block number of each block fragment according to the total number of blocks in the blockchain network and a predetermined fragment interval range, wherein the block numbers between the block fragments do not overlap.
[0176] Optionally, the first N-1 block segments among the N block segments are closed intervals, and the Nth block segment is an open interval.
[0177] Optionally, the cluster state of the shard block cluster corresponding to the first N-1 block fragments in the N block fragments is read-only and does not accept block writes; the cluster state of the shard block cluster corresponding to the Nth block fragment is writable and accepts block writes.
[0178] The above-mentioned data query device based on the blockchain network may also include a processor and a memory. The above-mentioned first block query request receiving unit 51, block fragment query unit 52, accounting node address acquisition unit 53, second block query request receiving unit 54, ledger data return unit 55, etc. are all stored in the memory as program units, and the processor executes the above-mentioned program units stored in the memory to realize corresponding functions.
[0179] The processor includes a kernel, which retrieves the corresponding program unit from the memory. One or more kernels can be set, and data query operations based on the segmented blockchain network can be implemented by adjusting kernel parameters.
[0180] The above-mentioned memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0181] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is further provided, wherein the computer-readable storage medium includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute any one of the blockchain network-based data query methods in the above-mentioned embodiment 1.
[0182] According to another aspect of an embodiment of the present invention, an electronic device is also provided, comprising one or more processors and a memory, wherein the memory is used to store one or more programs, wherein when the one or more programs are executed by one or more processors, the one or more processors implement the data query method based on the blockchain network of any one of the above-mentioned embodiments.
[0183] The present application also provides a computer program product, including a computer program, which, when executed by a processor, implements the steps of the blockchain network-based data query method described in each embodiment of the present application.
[0184] The present application also provides a computer program product, including a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the data query method based on the blockchain network described in each embodiment of the present application are implemented.
[0185] Figure 6 This is a hardware structure diagram of an electronic device (or mobile device) according to a data query method based on a blockchain network according to an embodiment of the present invention. Figure 6 As shown, the electronic device may include one or more ( Figure 6(As shown in the figure, 602a, 602b, ..., 602n are used) processor 602 (processor 602 may include but is not limited to a microprocessor MCU or a programmable logic device FPGA, etc.), memory 604 for storing data. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the I / O interface), a network interface, a keyboard, a power supply and / or a camera. It will be understood by those skilled in the art that Figure 6 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 6 More or fewer components than shown, or with Figure 6 Different configurations shown.
[0186] The serial numbers of the above embodiments of the present invention are for description only and do not represent the advantages or disadvantages of the embodiments.
[0187] In the above embodiments of the present invention, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0188] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only exemplary. For example, the division of the units can be a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0189] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0190] In addition, the functional units in the various embodiments of the present invention may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0191] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk, etc. Various media that can store program codes.
[0192] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as within the scope of protection of the present invention.
Claims
1. A data query method based on a blockchain network, characterized in that: The blockchain network is pre-divided into N sequentially connected block segments, each of which contains multiple shard blocks and accounting nodes. The data query method based on the blockchain network includes: Receiving, through the first accounting node in the source block segment, a block query request from a client, wherein the block query request includes: a target shard block number and accounting data information to be queried; In response to the block query request, query the local block history through the first accounting node to determine the target block segment and the corresponding shard block cluster to which the shard block indicated by the target block number belongs; Obtaining a node address of a second accounting node corresponding to the target block segment, and returning the node address of the second accounting node to the client; Receiving, through the second accounting node, a new block query request initiated by the client, wherein the new block query request includes: a node address of the second accounting node, a target shard block number, and accounting data information to be queried; In response to the new block query request, the account data corresponding to the target shard block number is returned to the client through the second accounting node.
2. The data query method according to claim 1, characterized in that: Before receiving the client's block query request through the first accounting node in the source block segment, the process further includes: After the accounting node corresponding to any of the block fragments in the blockchain network is started, the accounting node scans the shard block information of the current terminal to obtain the start bit and end bit of the block fragment; Based on the start bit and the end bit of the block fragment, establish a shard block cluster corresponding to the block fragment; Record the block index information and node information of the sharded block cluster in the world state database through the accounting node; The block index information and the node information are broadcasted to each accounting node in other block fragments through the accounting node, wherein each accounting node in other block fragments records the block index information and the node information in a local world state database.
3. The data query method according to claim 2, characterized in that: The step of responding to the block query request, querying the local block history through the first accounting node, and determining the target block segment to which the shard block indicated by the target block number belongs and the corresponding shard block cluster includes: In response to the block query request, query the block index information in the local world state database to determine whether the target shard block number is located in the fragment interval of the source block fragment; In the case that the target shard block number is not located in the fragment interval of the source block fragment, the block index information and node information broadcasted in the history of each accounting node in other block fragments are indexed to obtain the target block fragment to which the shard block indicated by the target block number belongs and the corresponding shard block cluster.
4. The data query method according to claim 1, characterized in that: Before receiving the client's block query request through the first accounting node in the source block segment, the process further includes: Receiving, through a first accounting node in a source block segment, a block write request from a client, wherein the block write request includes at least: a node address of the first accounting node and block information of the block to be sharded; In response to the block write request, query the local historical block record through the first accounting node to obtain the fragment interval status of the source block fragment; If the fragment interval status indicates that the source block fragment is a read-only interval, query the block fragment whose fragment interval status is a write interval through the first accounting node, locate the shard block cluster corresponding to the block fragment and the node address of the third accounting node, and return the node address of the third accounting node to the client; Receiving, through the third accounting node, a new block write request initiated by the client, wherein the new block write request includes: a node address of the third accounting node and block information of the block to be sharded; In response to the new block write request, block accounting processing is performed through the third accounting node, a block number receipt is generated, and the block number receipt is returned to the client.
5. The data query method according to claim 1, characterized in that: The process of pre-dividing the blockchain network into N sequentially connected block segments includes: According to the total number of blocks in the blockchain network and the predetermined fragment interval range, the starting shard block number and the ending shard block number of each block fragment are determined, wherein the block numbers between the block fragments do not overlap.
6. The data query method according to claim 1, characterized in that: The first N-1 block segments of the N block segments are closed intervals, and the Nth block segment is an open interval.
7. The data query method according to claim 6, characterized in that: The cluster state of the shard block cluster corresponding to the first N-1 block fragments among the N block fragments is read-only and does not accept block writes; the cluster state of the shard block cluster corresponding to the Nth block fragment is writable and accepts block writes.
8. A data query device based on a blockchain network, characterized in that: The blockchain network is pre-divided into N sequentially connected block segments, each of which contains multiple shard blocks and accounting nodes within its segment interval. The data query device based on the blockchain network includes: A first block query request receiving unit, configured to receive a block query request from a client through a first accounting node in a source block segment, wherein the block query request includes: a target shard block number and accounting data information to be queried; a block fragment query unit, configured to respond to the block query request, query the local block history records through the first accounting node, and determine the target block fragment and the corresponding shard block cluster to which the shard block indicated by the target block number belongs; a bookkeeping node address obtaining unit, configured to obtain a node address of a second bookkeeping node corresponding to the target block segment, and return the node address of the second bookkeeping node to the client; a second block query request receiving unit, configured to receive, through the second accounting node, a new block query request initiated by the client, wherein the new block query request includes: a node address of the second accounting node, a target shard block number, and accounting data information to be queried; The ledger data returning unit is configured to respond to the new block query request and return the ledger data corresponding to the target shard block number to the client through the second accounting node.
9. An electronic device, characterized in that: The system comprises one or more processors and a memory, wherein the memory is used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the data query method based on the blockchain network as described in any one of claims 1 to 7.
10. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the data query method based on the blockchain network described in any one of claims 1 to 7 are implemented.