Method and device for querying high-frequency data of energy block chain
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING UNIV OF POSTS & TELECOMM
- Filing Date
- 2024-05-07
- Publication Date
- 2026-08-07
AI Technical Summary
而区块链作为分布式存储系统,与传统的关系数据库相比,存在查询效率低、查询键值有限等问题
[0027]Fifthly, embodiments of the present invention also provide a computer program product, including a computer program that, when executed by a processor, implements the steps of the energy blockchain high-frequency data query method as described in the first aspect.
Smart Images

Figure CN118568117B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of energy technology, and in particular to a method and apparatus for querying high-frequency data in energy blockchain. Background Technology
[0002] Since its inception, blockchain technology has revolutionized numerous fields, one of which is distributed energy trading. With the rapid growth of renewable energy and the increasing demand for clean energy, distributed energy trading has become a key area in the energy market. This emerging market model allows energy producers and consumers to trade energy in a decentralized manner, thereby reducing the complexity of energy trading, minimizing energy transmission losses, and promoting the adoption of sustainable energy.
[0003] While the prospects for distributed energy trading are bright, current blockchain systems face several significant challenges in this field. One of these is the high-frequency nature of the data, meaning a large amount of transaction data needs to be stored and retrieved. However, as a distributed storage system, blockchain suffers from low query efficiency and a limited number of query keys compared to traditional relational databases. Therefore, how to achieve high-frequency data retrieval in energy blockchains is a technical problem that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0004] To address the problems in the prior art, embodiments of the present invention provide a method and apparatus for querying high-frequency data in the energy blockchain.
[0005] Specifically, the embodiments of the present invention provide the following technical solutions:
[0006] In a first aspect, embodiments of the present invention provide a method for querying high-frequency data in an energy blockchain, comprising:
[0007] When the energy data query information is a continuous value, the Z-order code of the query information is matched with the key value in the MBZ tree corresponding to the target block to determine the query result of the energy data corresponding to the query information; the MBZ tree is constructed based on the Z-order code of the energy data already stored in the energy blockchain and the Merkle prefix tree (MPT); the Z-order code of the energy data serves as the key value in the Merkle prefix tree (MPT); and / or,
[0008] When the energy data query information is a discrete value, the nibble sequence corresponding to the query information is matched with the key value in the MBZ tree corresponding to the target block to determine the query result of the energy data corresponding to the query information; the MBZ tree is constructed based on the half-byte nibble sequence corresponding to the energy data already stored in the energy blockchain and the Merkle prefix tree MPT; the nibble sequence corresponding to the energy data is used as the key value in the Merkle prefix tree MPT.
[0009] Furthermore, if the query information is a discrete value, and the nibble sequence corresponding to the query information matches the shared path of the extended node in the MBZ tree, then the query will directly jump to the end of the shared path or the next branch point to determine the query result of the energy data corresponding to the query information.
[0010] Furthermore, before determining the query result of the energy data corresponding to the query information, the process also includes:
[0011] If the query information is a discrete value, perform a hash calculation on the query information to obtain a hash result;
[0012] Based on the Bloom filter associated with the target node and the hash result, the target block corresponding to the query information is determined; the target node is the node on the hash ring corresponding to the energy data that corresponds to the hash result.
[0013] Furthermore, before determining the query result of the energy data corresponding to the query information, the process also includes:
[0014] When the query information is a continuous value, a hash calculation is performed on the boundary of the continuous value to obtain the upper boundary hash result and the lower boundary hash result of the query range;
[0015] The target block corresponding to the query information is determined based on the minimum bounding rectangle (MBR) corresponding to the key value range of the energy data stored in each block, the upper boundary hash result of the query range, and the lower boundary hash result of the query range.
[0016] Furthermore, based on the jump function and the total number of nodes in the blockchain system, the target node number corresponding to the energy data to be stored is determined;
[0017] The energy data is stored according to the target node number.
[0018] Furthermore, when a new node is added to the blockchain system, the second node number corresponding to each energy data is re-determined based on the jump function and the total number of nodes in the blockchain system.
[0019] If the second node number is different from the original node number corresponding to the energy data, then the energy data is migrated from the original node to the node indicated by the second node number.
[0020] Furthermore, based on the random forest model, the slice node information corresponding to the energy data that needs to be uploaded to the blockchain system is determined; the node information is used to indicate the slice size of the energy data, the number of energy data slices, and the number of redundant storage nodes for each energy data slice;
[0021] The energy data is uploaded to the blockchain system based on the slice node information corresponding to the energy data.
[0022] Secondly, embodiments of the present invention also provide a device for querying high-frequency data in an energy blockchain, comprising:
[0023] The query module is used to match the Z-order code of the query information with the key value in the MBZ tree corresponding to the target block when the query information of the energy data is a continuous value, to determine the query result of the energy data corresponding to the query information; the MBZ tree is constructed based on the Z-order code of the energy data stored in the energy blockchain and the Merkle prefix tree MPT; the Z-order code of the energy data is used as the key value in the Merkle prefix tree MPT; and / or,
[0024] When the energy data query information is a discrete value, the nibble sequence corresponding to the query information is matched with the key value in the MBZ tree corresponding to the target block to determine the query result of the energy data corresponding to the query information; the MBZ tree is constructed based on the half-byte nibble sequence corresponding to the energy data already stored in the energy blockchain and the Merkle prefix tree MPT; the nibble sequence corresponding to the energy data is used as the key value in the Merkle prefix tree MPT.
[0025] Thirdly, embodiments of the present invention also provide an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of the energy blockchain high-frequency data query method as described in the first aspect.
[0026] Fourthly, embodiments of the present invention also provide a non-transitory computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the energy blockchain high-frequency data query method as described in the first aspect.
[0027] Fifthly, embodiments of the present invention also provide a computer program product, including a computer program that, when executed by a processor, implements the steps of the energy blockchain high-frequency data query method as described in the first aspect.
[0028] The energy blockchain high-frequency data query method and apparatus provided in this invention have two aspects. First, for queries of multidimensional continuous values, this embodiment matches the Z-order encoding of the query information with the key values in the MBZ tree corresponding to the energy data in the target block to determine the query result of the energy data corresponding to the query information. This is achieved by combining the spatial hashing technique Z-order curve and the MBZ tree obtained from the MPT tree corresponding to the energy data to handle complex spatial query requirements. By mapping multidimensional data to a one-dimensional encoding space, the multidimensional query performance for both continuous and discrete value attributes is effectively enhanced, making data storage, transmission, and processing more efficient, thereby effectively improving the query efficiency of high-frequency energy blockchain data. Second, for queries of discrete values, the query result of the energy data corresponding to the query information is determined by matching the nibble sequence corresponding to the query information with the key values in the MBZ tree corresponding to the target block, achieving detailed and accurate query processing. Attached Figure Description
[0029] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0030] Figure 1 This is a flowchart illustrating the energy blockchain high-frequency data query method provided in an embodiment of the present invention;
[0031] Figure 2 This is another flowchart illustrating the energy blockchain high-frequency data query method provided in this embodiment of the invention;
[0032] Figure 3 This is a flowchart illustrating the method for storing high-frequency data in an energy blockchain according to an embodiment of the present invention.
[0033] Figure 4 This is a schematic diagram of the structure of the energy blockchain high-frequency data query device provided in an embodiment of the present invention;
[0034] Figure 5 This is a schematic diagram of the structure of the electronic device provided in an embodiment of the present invention. Detailed Implementation
[0035] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0036] The method of this invention can be applied to energy data query and storage scenarios, effectively improving the query efficiency of high-frequency data in energy blockchain.
[0037] While the prospects for distributed energy trading are bright, current blockchain systems face several significant challenges in this field. One of these is the high-frequency nature of the data, meaning a large amount of transaction data needs to be stored and retrieved. However, as a distributed storage system, blockchain suffers from low query efficiency and a limited number of query keys compared to traditional relational databases. Therefore, how to achieve high-frequency data retrieval in energy blockchains is a technical problem that urgently needs to be solved by those skilled in the art.
[0038] The energy blockchain high-frequency data query method of this invention has two aspects. First, for queries of multidimensional continuous values, this embodiment matches the Z-order encoding of the query information with the key value in the MBZ tree corresponding to the energy data in the target block to determine the query result of the energy data corresponding to the query information. That is, it uses the MBZ tree obtained by combining the spatial hashing technology Z-order curve and the MPT tree corresponding to the energy data to handle complex spatial query requirements. By mapping multidimensional data to a one-dimensional encoding space, it effectively enhances the multidimensional query performance for continuous and discrete value attributes, making data storage, transmission and processing more efficient, thereby effectively improving the query efficiency of high-frequency energy blockchain data. Second, for queries of discrete values, the query result of the energy data corresponding to the query information is determined by matching the nibble sequence corresponding to the query information with the key value in the MBZ tree corresponding to the target block, achieving detailed and accurate query processing.
[0039] The following is combined with Figures 1-5 The technical solution of the present invention will be described in detail with reference to specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments.
[0040] Figure 1 This is a flowchart illustrating an embodiment of the energy blockchain high-frequency data query method provided by this invention. Figure 1 As shown, the method provided in this embodiment includes:
[0041] Step 101: When the energy data query information is a continuous value, match the Z-order code of the query information with the key value in the MBZ tree corresponding to the target block to determine the query result of the energy data corresponding to the query information; the MBZ tree is constructed based on the Z-order code of the energy data already stored in the energy blockchain and the Merkle prefix tree (MPT) corresponding to the energy data; the Z-order code of the energy data serves as the key value in the Merkle prefix tree (MPT); and / or,
[0042] When the energy data query information is a discrete value, the nibble sequence corresponding to the query information is matched with the key value in the MBZ tree corresponding to the target block to determine the query result of the energy data corresponding to the query information. The MBZ tree is constructed based on the half-byte nibble sequence corresponding to the energy data already stored in the energy blockchain and the Merkle prefix tree MPT corresponding to the energy data. The nibble sequence corresponding to the energy data is used as the key value in the Merkle prefix tree MPT.
[0043] Specifically, as a decentralized system, blockchain is maintained by all nodes in the network. All nodes are equal, and everyone can access complete information, ensuring the trustworthiness of the ledger. However, because blockchain data is publicly transparent, any user can view all user data, compromising user privacy and significantly limiting the application expansion of blockchain. This poses a significant risk to industries with high privacy requirements. In response, some have proposed encrypting data to ensure confidentiality. However, simple encryption reduces data usability; for example, encryption eliminates features supporting plaintext retrieval, requiring users to download and decrypt the entire encrypted data, increasing computational overhead and time costs. Solving this problem is crucial because participants in the energy market need rapid access to historical transaction data for decision-making, analysis, and compliance checks. Currently, mainstream blockchain systems use key-value databases, where the key is the hash value of a block or transaction. This limits the system's ability to quickly query values for a limited number of data points, preventing queries based on specific conditions, such as the value of a particular attribute within a certain range. To query the value of a specific attribute within a transaction, the system must iteratively query each transaction. This query method has low query efficiency, which hinders the application of blockchain and also causes problems such as low query efficiency and limited query key values for high-frequency data in energy blockchain.
[0044] To address the aforementioned issues, this application introduces a data structure called MBZ-Tree during the intra-block query process. MBZ-Tree not only inherits the powerful capabilities of MPT in data integrity verification but also effectively enhances the multi-dimensional query performance for continuous and discrete value attributes.
[0045] Optionally, when querying within a block, if the energy data query information is a continuous value, this embodiment matches the Z-order code of the query information with the key value in the MBZ tree corresponding to the block to determine the query result of the energy data corresponding to the query information. The MBZ tree is constructed based on the Z-order code of the energy data already stored in the energy blockchain and the Merkle prefix tree (MPT) corresponding to the energy data. The Z-order code of the energy data serves as the key value in the MPT. In other words, by combining the Z-order code of the energy data with the existing MPT structure corresponding to the energy data, the MBZ-Tree can be obtained. Optionally, Z-order encoding is a method for encoding multidimensional data. It maps multidimensional data to a one-dimensional encoding space, making data storage, transmission, and processing more efficient, thereby effectively improving the query efficiency of high-frequency data in the energy blockchain.
[0046] Optionally, in the design of MBZ-Tree, each node carries three important functions. First, each node contains a hash value, which is carefully calculated to ensure the data integrity of the entire tree, guaranteeing data security and immutability. Second, each node integrates a Bloom filter, which enables the rapid determination of whether a specific discrete value query is likely to find a match in the node's subtree, greatly improving query efficiency. Finally, by employing Z-order curve technology, MBZ-Tree can effectively map multidimensional data to one-dimensional space while preserving the spatial proximity between data points. This is crucial for performing complex multidimensional continuous value queries, thereby effectively improving the query efficiency of high-frequency data in the energy blockchain.
[0047] For example, for queries of multidimensional continuous values, this application embodiment adopts a comprehensive strategy, which uses an MBZ tree obtained by combining the spatial hashing technique Z-order curve and the MPT tree corresponding to energy data to handle complex spatial query requirements.
[0048] For each block in the blockchain, consider the set of multidimensional data points contained within it. Each data point can be a transaction record, containing multidimensional information such as timestamp, amount, initiator and receiver addresses, etc. First, preprocess this multidimensional data:
[0049] For each dimension i, the value p at data point P i Standardized to the range [0,1]:
[0050]
[0051] For the standardized multidimensional data points P ′ =(p1) ′ ,p ′ 2,…,p ′ d Z-order curve encoding is applied to generate unique one-dimensional hash values. This process converts the value of each dimension into a binary representation and interleaves these binary bits:
[0052]
[0053] Here b ij It is the j-th bit of the value at dimension i in the n-bit binary representation. The Z-order code of each data point is used as the key in the MPT. In this way, data points within each block can be efficiently located and verified in the MPT through their multidimensional features. Then, for a given multidimensional query, the Z-order code of the query range in each dimension is first calculated to determine the one-dimensional encoding range of the query [Z]. min Z max Then, by searching all key values within the encoded range in the MPT, the corresponding data points are retrieved, thus efficiently realizing the querying of high-frequency data in the energy blockchain.
[0054] Optionally, when querying within a block, if the query information for energy data is a discrete value, this embodiment matches the nibble sequence corresponding to the query information with the key value in the MBZ tree corresponding to the target block to determine the query result for the energy data corresponding to the query information. The MBZ tree is constructed based on the half-byte nibble sequence corresponding to the energy data already stored in the energy blockchain and the Merkle prefix tree (MPT) corresponding to the energy data. The nibble sequence corresponding to the energy data serves as the key value in the MPT, meaning that by combining the nibble sequence corresponding to the energy data with the existing MPT structure, an MBZ-Tree can be obtained. Optionally, in the MBZ-Tree, the MPT stores information related to the status of each account, using the account address (or other unique identifier) as the key. These keys are precisely encoded into nibs through a series of transformation processes for detailed and accurate query processing.
[0055] For example, for querying discrete value attributes, this application embodiment adopts a comprehensive strategy, which uses the MBZ tree obtained by the half-byte nibble sequence corresponding to the energy data and the MPT tree to perform detailed and accurate query processing.
[0056] Assuming there is an account address or identifier as the key, this embodiment first converts the account address into a nibble. Given a hexadecimal account address A = H1H2...H... n H i It is the i-th hexadecimal number. Convert A to its binary representation B by processing each H. i Apply the transformation function f and concatenate the results. The formula can be expressed as:
[0057]
[0058] Where f(H) i ) indicates that the hexadecimal number H i The function that converts it to its corresponding 4-bit binary representation. This indicates a concatenation operation. Furthermore, by matching the nibble sequence corresponding to the query information with the key values in the MBZ tree corresponding to the target block, the query result for the energy data corresponding to the query information can be determined, achieving detailed and precise query processing.
[0059] For example, when the query information for energy data is a continuous value, the query method for high-frequency data in the energy blockchain is as follows:
[0060] S1. Assume that at a specific time t, the energy trading data states of the three nodes are as follows:
[0061] Node 1: This indicates that the energy price reported by this node is 1.5 yuan / unit, the trading volume is 120 units, and the market volatility is 0.35.
[0062] Node 2: This indicates that the energy price is 2.0 yuan / unit, the trading volume is 200 units, and the market volatility is 0.5.
[0063] Node 3: This indicates that the energy price is 1.75 yuan per unit, the trading volume is 150 units, and the market volatility is 0.45.
[0064] The data at each node is first encoded using a Z-order curve. Assume that after Z-order curve encoding, the node data is transformed into the following form:
[0065] Node 1 code: 011010101001
[0066] Node 2 code: 100110110110
[0067] Node 3 code: 011110111010
[0068] Using the above encoding as the key of the MPT, an MBZ-Tree is constructed. For example, the data encoding 011010101001 for node 1 will directly affect its position in the tree. Bloom filters are used to quickly determine whether a particular query is likely to find a match in the subtree of that node.
[0069] Suppose we need to find all transaction records with transaction volumes in the range of 100 to 180. Using MBZ-Tree, we first use a Bloom filter to pre-screen potentially matching nodes, then perform a precise search using Z-order encoding and MPT, ultimately finding nodes 1 and 3 that meet the criteria.
[0070] The method described in the above embodiments, on the one hand, for queries of multidimensional continuous values, matches the Z-order encoding of the query information with the key values in the MBZ tree corresponding to the energy data in the target block to determine the query result of the energy data corresponding to the query information. That is, it handles complex spatial query requirements by combining the spatial hashing technique Z-order curve and the MBZ tree obtained from the MPT tree corresponding to the energy data. By mapping multidimensional data to a one-dimensional encoding space, it effectively enhances the multidimensional query performance for both continuous and discrete value attributes, making data storage, transmission, and processing more efficient, thereby effectively improving the query efficiency of high-frequency data in the energy blockchain. On the other hand, for queries of discrete values, it matches the nibble sequence corresponding to the query information with the key values in the MBZ tree corresponding to the target block to determine the query result of the energy data corresponding to the query information, achieving detailed and accurate query processing.
[0071] In one embodiment, when the query information is a discrete value, if the nibble sequence corresponding to the query information matches the shared path of the extended node in the MBZ tree, then the query is directly performed at the end of the shared path or the next branch point to determine the query result of the energy data corresponding to the query information.
[0072] Specifically, when querying discrete values, this embodiment starts from the root node of the MBZ-Tree corresponding to the energy data and traverses the tree downwards level by level according to the nibble sequence of the keys until a leaf node is reached. If the query key matches a shared path of an extended node, the query can directly jump to the end of that path or the next branch point, without needing to traverse every node on the path, thus effectively improving query efficiency; if all keys on the path are successfully matched, then the leaf node containing the query result will eventually be reached. Let K be the complete query key, consisting of a series of nibble K = k1k2...k n Composition, where each k i It is a nibble, representing a part of the key. Let T represent a node in the MPT, where T can be a leaf node, an extension node, or a branch node.
[0073] If T is the expanding node, let be the shared nibble path stored in the expanding node, and be the next node pointed to by the expanding node. Assume the expanding node stores a shared path P. E =p1p2...p m , where each p i It is a nibble on the path, and |PE| is the length of the path. If the key of the current query contains P E If a matching nibble sequence is found, the query can skip the entire path and continue from the next node pointed to by the extended node. In other words, when querying discrete values, the discrete value A to be queried is encoded, then its address is converted into a nibble; the query is then performed based on the existing query method. However, when reaching an extended node, if the query key matches a shared path of that extended node, the query can directly jump to the end of that path or the next fork, without needing to traverse every node on the path. This is achieved through path compression, effectively improving the query efficiency of high-frequency data in the energy blockchain.
[0074] For example, when querying discrete values, if T is an extended node, the query method is as follows:
[0075]
[0076] If T is a branch node, let T j It is the child node of the branch node corresponding to the nibble value j.
[0077]
[0078] That is, the query will be based on the current nibblek iThe value determines which child node in the branch node to continue the query. If there is no match, the query fails.
[0079] If T is a leaf node, let P L It is the key stored in the leaf node.
[0080]
[0081] In other words, if the key of a leaf node matches the complete query key K exactly, the query succeeds and the value of the leaf node is returned. If there is no match, the query fails.
[0082] Simultaneously, a Bloom filter is added to each node of the MBZ-Tree. A Bloom filter is a long binary vector and a series of random mapping functions used to check whether an element is not in a set. In the MBZ-Tree, this structure is used to assist in pre-filtering operations to optimize the query process for discrete-valued attributes. In other words, the Bloom filter of a non-leaf node is the sum of the Bloom filters of all its child nodes, which we express using the following formula:
[0083] BF parent =BF child1 +BF child2 +…+BF childn #(1-7)
[0084] Starting from the root node of the MPT, each discrete value query first undergoes a hash map check by the node's Bloom filter. If the Bloom filter indicates that the query value cannot exist in the subtree, the traversal of that subtree is skipped.
[0085] In the method described in the above embodiments, when querying discrete values, if the nibble sequence corresponding to the query information matches the shared path of the extended node in the MBZ tree corresponding to the energy data, the query is directly performed at the end of the shared path or the next fork point. That is, when querying discrete values, the discrete value A to be queried is encoded, then its address is converted into a nibble; the query is then performed based on the existing query method, but when reaching the extended node, the query is performed using path compression, thereby effectively improving the query efficiency of high-frequency data in the energy blockchain.
[0086] In one embodiment, before determining the query result of the energy data corresponding to the query information, the method further includes:
[0087] When the query information is a discrete value, a hash calculation is performed on the query information to obtain the hash result;
[0088] Based on the Bloom filter and hash result associated with the target node, the target block corresponding to the query information is determined; the target node is the node on the hash ring corresponding to the energy data that corresponds to the hash result.
[0089] Specifically, when querying energy data, if it is unclear which block the data being queried is in, a cross-block query can be performed first, which can effectively narrow down the scope of the query and improve the query efficiency of high-frequency data in the energy blockchain.
[0090] Optionally, when the query information is a discrete value, this embodiment first performs a hash calculation on the query information to obtain a hash result; then, based on the Bloom filter associated with the target node and the hash result, the target block corresponding to the query information is determined. That is, one hash value may correspond to multiple nodes, so by further querying through a Bloom filter, blocks that cannot possibly contain the query data are filtered out, thereby selecting the target blocks that contain the query data, and then the required result can be accurately found in the selected target blocks.
[0091] For example, for inter-block queries with discrete value attributes, the hash value is first calculated using the hash function defined in the consistent hash ring. This hash value determines the starting position of the query on the hash ring. For example, for a specific account address or transaction ID, its hash value is calculated directly. After locating the node corresponding to the query hash value on the hash ring, the Bloom filter associated with that node is used to determine whether the query key is likely to exist in the block represented by that node. If the Bloom filter indicates that the query key is impossible, the block can be directly excluded, avoiding further query operations. If the Bloom filter indicates that the query key may exist, a more in-depth examination of the block is required, which can effectively narrow down the scope of the query and improve the query efficiency of high-frequency data in the energy blockchain.
[0092] The method described in the above embodiments, when the query information is a discrete value, performs a hash calculation on the query information to obtain a hash result; based on the Bloom filter associated with the target node and the hash result, it determines the target block corresponding to the query information, thereby filtering out the target blocks containing the query data, and then accurately querying the required result in the filtered target blocks. In other words, this application proposes an efficient inter-block query method that associates a Bloom filter with each block position on the hash ring corresponding to the energy data to represent the relevant information of transactions within that block, thereby effectively narrowing the query scope and improving the query efficiency of high-frequency data in the energy blockchain.
[0093] In one embodiment, before determining the query result of the energy data corresponding to the query information, the method further includes:
[0094] When the query information is a continuous value, a hash calculation is performed on the boundary of the continuous value to obtain the hash result of the upper boundary of the query range and the hash result of the lower boundary of the query range;
[0095] Based on the minimum bounding rectangle (MBR) corresponding to the key value range of energy data stored in each block, the upper boundary hash result of the query range, and the lower boundary hash result of the query range, the target block corresponding to the query information is determined.
[0096] Specifically, when querying energy data, if it is unclear which block the data being queried is in, a cross-block query can be performed first, which can effectively narrow down the scope of the query and improve the query efficiency of high-frequency data in the energy blockchain.
[0097] Optionally, when the query information is a continuous value, this embodiment first performs a hash calculation on the boundaries of the continuous values to obtain the upper boundary hash result and the lower boundary hash result of the query range. Then, based on the minimum bounding rectangle (MBR) corresponding to the key-value range of the energy data stored in each block, and the upper and lower boundary hash results of the query range, the target block corresponding to the query information is determined. That is, by further querying using the minimum bounding rectangle (MBR) corresponding to the key-value range of the energy data stored in each block, blocks where the query data is impossible are filtered out, thus identifying the target block containing the query data. Therefore, the required result can be accurately found within the selected target block.
[0098] For example, inter-block queries with continuous value attributes are similar to those with discrete value attributes. For queries based on a certain range (e.g., queries for transactions within a certain value range), it may be necessary to hash the representation of the query range. For a continuous value query defining a range R = [a, b], where a and b represent the lower and upper bounds of the query range, respectively, we do not directly hash the range. Instead, we identify key checkpoints on the hash ring by determining the hash values of specific points or boundaries within the range. This can be expressed as:
[0099]
[0100] Where H is the hash function, H start and H endThese represent the start and end positions of the query range on the hash ring, respectively. Then, the MBR (Mean Backtesting) of the block header associated with the query conditions is used to determine if the query range intersects with the data range in the block. If the MBR indicates no intersection between the query range and the block's data range, the block can be excluded. If there is an intersection, the block requires further detailed querying. If the query successfully finds matching data, the relevant results are returned. If no matching data is found in any of the relevant nodes on the hash ring, the query result is empty.
[0101] The method described in the above embodiment, when the query information is a continuous value, performs hash calculations on the boundaries of the continuous values to obtain the upper boundary hash result and the lower boundary hash result of the query range. Based on the minimum bounding rectangle (MBR) corresponding to the key-value range of the energy data stored in each block, and the upper and lower boundary hash results of the query range, the target block corresponding to the query information is determined. This filters out the target blocks containing the query data, allowing for accurate retrieval of the desired results within the filtered target blocks. In essence, this proposes an efficient inter-block query method that associates each block position on the hash ring corresponding to the energy data with a minimum bounding rectangle (MBR) corresponding to the key-value range of the energy data, representing the relevant transaction information within that block. This effectively narrows the query range and improves the query efficiency of high-frequency data in the energy blockchain.
[0102] In one embodiment, the target node number corresponding to the energy data to be stored is determined based on the jump function and the total number of nodes in the blockchain system.
[0103] Energy data is stored based on the target node number.
[0104] Specifically, this application provides a method for storing energy data, which involves determining the target node number corresponding to the energy data to be stored based on a jump function and the total number of nodes in the blockchain system; and storing the energy data according to the target node number. The jump function is a jump-consistent hash algorithm, which maintains the stability of data distribution during dynamic system changes (such as node additions or removals) by only needing to relocate the smallest affected dataset, reducing the need for data migration and rebalancing. Assuming data needs to be stored in an off-chain distributed storage system, the system first calculates the hash value of the key to store the data. Using the jump-consistent hash algorithm, for a given data key, its corresponding node number can be calculated as follows:
[0105] node=Jump(hash(key),N)#(2-1)
[0106] Where N is the total number of nodes in the current system, the Jump function calculates which node the key should be stored on based on the value of hash(key) and N.
[0107] If the node server corresponding to the calculated node number exists, the data is directly stored on that node server. If the node number does not exist, a backup strategy is required, such as temporarily storing the data on the nearest available node and recalculating the hash value or migrating it after the nodes are rebalanced.
[0108] The method described in the above embodiment determines the target node number corresponding to the energy data to be stored based on the jump function and the total number of nodes in the blockchain system; and stores the energy data according to the target node number. It can maintain the stability of data distribution when the system changes dynamically (such as the addition or removal of nodes), and only needs to relocate the smallest affected dataset, reducing the need for data migration and rebalancing, and effectively improving the storage efficiency of energy data.
[0109] In one embodiment, when a new node is added to the blockchain system, the second node number corresponding to each energy data is re-determined based on the jump function and the total number of nodes in the blockchain system.
[0110] If the second node number is different from the original node number corresponding to the energy data, the energy data will be migrated from the original node to the node indicated by the second node number.
[0111] Specifically, when a new node joins the energy blockchain system, this embodiment does not require remapping all existing data, thereby effectively improving the management efficiency of energy data in the blockchain.
[0112] Optionally, the new node is first initialized, and then all nodes in the system update their key-to-node mappings. After the new node is added, the total number of nodes in the system changes from N to N+1. For each key, its node number needs to be recalculated:
[0113] node new =Jump(hash(key),N+1)#(2-2)
[0114] If node new If the key has the same node number as the original node, then the key does not need to be moved. If the node... new If the key is different from the original node number, it means that the key needs to be migrated from the original node to the node indicated by the new node number.
[0115] This approach only affects a small subset of the data in the energy blockchain because the mapping nodes for most data items do not change with the addition of a new node. The data to be migrated is then copied to the new node, and other nodes in the system update their stored total node count information and the key-to-node mappings that may be affected. This means that not all existing data needs to be remapped, effectively improving the management efficiency of energy data in the blockchain.
[0116] For example, based on the state data of node 2 Suppose we shard this data and determine its storage location. We use a skip-consistent hashing algorithm to calculate the storage location. Assuming the system currently has 5 storage nodes, the target storage node for the data on node 2 is calculated as follows:
[0117] Hash value calculation: hash([2.0,200,0.5])=45789 (example value)
[0118] Storage node calculation: node = Jump(45789, 5) = 3, meaning that data should be stored on node number 3 in the system. When the system dynamically changes (e.g., the addition of new nodes or the removal of existing nodes), the total number of nodes changes, and the storage location of each data slice is recalculated to ensure uniform data distribution, thereby optimizing data access speed. In other words, this application innovatively proposes a distributed storage system architecture that can guarantee the normal operation of the system and the integrity of data even in the presence of a certain proportion of malicious nodes.
[0119] In the method described above, when a new node is added to the blockchain system, the second node number corresponding to each energy data is re-determined based on the jump function and the total number of nodes in the blockchain system. If the second node number is different from the original node number corresponding to the energy data, the energy data is migrated from the original node to the node indicated by the second node number. In other words, it is not necessary to remap all existing data, thereby effectively improving the management efficiency of energy data in the blockchain.
[0120] In one embodiment, the slice node information corresponding to the energy data that needs to be uploaded to the blockchain system is determined according to the random forest model; the node information is used to indicate the slice size of the energy data, the number of energy data slices, and the number of redundant storage nodes for each energy data slice.
[0121] Based on the slice node information corresponding to the energy data, the energy data is uploaded to the blockchain system.
[0122] Specifically, in the energy data upload process, this embodiment uses a random forest model to perform initial processing and sharding of the energy data, thereby achieving efficient synchronization of the energy data to the blockchain system. The specific process is as follows:
[0123] When preparing to upload data, the random forest model is first used to analyze the data. For each data item to be uploaded, its feature vector is defined as X = [x1, x2, x3, ..., x...]. n ], where x1, x2, x3, ..., x n These represent data characteristics, such as type, size, expected access patterns, and change frequency. A random forest model consists of multiple decision trees, each making a decision based on a random subset of the data's feature vectors. For each decision tree D in the random forest... i Its decision output for the data feature vector X can be expressed as:
[0124] d i (X)=[s i ,n i ,k i #(2-3)
[0125] Where, d i (X) is the decision made by the i-th decision tree based on the feature vector X, s i Indicates the suggested partition size, n i k represents the suggested number of data slices. i This represents the recommended number of redundant storage nodes for each data slice.
[0126] The final decision of the random forest model is determined based on the average or majority vote of the outputs of all decision trees. Therefore, for the output of the entire model, we have:
[0127] S = avg(s) i ),#(2-4)
[0128] N = round(avg(n i )),#(2-5)
[0129] K = round(avg(k) i ))#(2-6)
[0130] Here, S, N, and K represent the final determined shard size, the number of data shards, and the number of redundant storage nodes for each data shard, respectively. Based on these analysis results, the data is divided into K shards, each approximately S in size, and K redundant storage nodes are allocated to each node. This node information v n = <v1,v2,…,v n >, where v i v represents the redundant storage node information of the i-th data slice. i = <node1,node2,…,node kAll of these will be collected and prepared to be uploaded to the blockchain system along with the data.
[0131] Then, the data's metadata, including the node information of the data slices, is... n The data's tags and the data owner's information are packaged into a data structure called slice= <v i The hash table `<i,n,τ,inf>` represents the hash value of the data or a slice thereof, used for subsequent data integrity verification. `inf` contains information about the data owner and possibly other metadata, such as timestamps. This packaged information is then uploaded to the blockchain system. Simultaneously, the blockchain's Proof-of-Stake (PoS) consensus module plays a crucial role, electing nodes with higher token holdings as ledger nodes, significantly improving the system's security and tamper resistance, ensuring data integrity and system availability.
[0132] The method described in the above embodiments uses a random forest model to perform initial processing and sharding of energy data, thereby enabling efficient synchronization of energy data to the blockchain system.
[0133] For example, such as Figure 2 and Figure 3 As shown, this application also provides a method for querying and storing high-frequency data in an energy blockchain, as detailed below:
[0134] With the rise of distributed energy resources and the rapid development of the clean energy market, the demand for efficient and secure energy trading platforms has become increasingly urgent. Existing blockchain technology faces the dual challenges of insufficient processing efficiency and inadequate data privacy protection when handling distributed energy trading data. These problems not only hinder the real-time performance and security of energy trading but also limit the wider application of blockchain within the energy industry. Faced with the challenges of low query efficiency and data security in high-frequency data processing, existing solutions, without optimizing query mechanisms and data storage strategies, struggle to simultaneously meet the demands of efficiency and security. Furthermore, these methods often lack the necessary flexibility when the blockchain network environment changes, leading to reconfiguration and additional time costs. This application provides a method that integrates on-chain and off-chain storage technologies. Through an innovative data structure, MBZ-Tree, and a skip consensus hashing algorithm, along with an introduced dynamic data sharding strategy and Proof-of-Stake (PoS) consensus mechanism, it aims to solve the aforementioned problems, improving not only query efficiency and data security but also increasing the system's scalability and adaptability.
[0135] like Figure 2As shown, by combining Merkle Patricia Tree (MPT), Bloom filter, and Z-order curve to construct the MBZ-Tree, this invention significantly improves the efficiency of multidimensional data query. The MBZ-Tree optimizes the storage and retrieval mechanism of on-chain data, effectively reduces unnecessary node traversal, and enhances support for both discrete and continuous value queries.
[0136] like Figure 3 As shown, this invention employs a skip-consistent hashing algorithm and a dynamic data sharding strategy to optimize the design of an off-chain distributed storage system. This design allows the system to maintain efficient and secure data storage when facing dynamic node additions or removals, while providing high versatility and scalability.
[0137] In other words, this application significantly improves the query efficiency and accuracy of distributed energy trading data by combining MBZ-Tree with a jump-consistent hashing algorithm. Simultaneously, it strengthens data security and tamper-proof capabilities through a dynamic data sharding strategy and a Proof-of-Stake (PoS) consensus mechanism. This approach not only greatly reduces data processing latency and resource consumption during energy trading but also promotes a more efficient and secure energy trading process, accelerating the application and development of clean energy in a wider range of fields. Furthermore, through an optimized on-chain and off-chain storage structure and adaptive design, this invention enhances the system's flexibility and stability in the face of network environment changes, ensuring the reliability of the energy trading platform and providing participants with more efficient and secure services. This not only improves the application efficiency of blockchain technology in the field of distributed energy trading but also promotes the energy market towards a greener and more sustainable direction, demonstrating the enormous potential of using advanced technologies to advance clean energy utilization and environmental sustainability.
[0138] The following describes the energy blockchain high-frequency data query device provided by the present invention. The energy blockchain high-frequency data query device described below and the energy blockchain high-frequency data query method described above can be referred to in correspondence.
[0139] Figure 4 This is a schematic diagram of the energy blockchain high-frequency data query device provided by the present invention. The energy blockchain high-frequency data query device provided in this embodiment includes:
[0140] Query module 410 is used to match the Z-order code of the query information with the key value in the MBZ tree corresponding to the target block when the query information of the energy data is a continuous value, to determine the query result of the energy data corresponding to the query information; the MBZ tree is constructed based on the Z-order code of the energy data stored in the energy blockchain and the Merkle prefix tree MPT; the Z-order code of the energy data serves as the key value in the Merkle prefix tree MPT; and / or,
[0141] When the energy data query information is a discrete value, the nibble sequence corresponding to the query information is matched with the key value in the MBZ tree corresponding to the target block to determine the query result of the energy data corresponding to the query information. The MBZ tree is constructed based on the half-byte nibble sequence corresponding to the energy data already stored in the energy blockchain and the Merkle prefix tree MPT. The nibble sequence corresponding to the energy data is used as the key value in the Merkle prefix tree MPT.
[0142] Optionally, the query module 410 is further configured to: when the query information is a discrete value, if the nibble sequence corresponding to the query information matches the shared path of the extended node in the MBZ tree, then directly jump to the end of the shared path or the next branch point to perform the query and determine the query result of the energy data corresponding to the query information.
[0143] Optionally, the query module 410 is further configured to: perform a hash calculation on the query information to obtain a hash result when the query information is a discrete value;
[0144] Based on the Bloom filter and hash result associated with the target node, the target block corresponding to the query information is determined; the target node is the node on the hash ring corresponding to the energy data that corresponds to the hash result.
[0145] Optionally, the query module 410 is further configured to: when the query information is a continuous value, perform a hash calculation on the boundary of the continuous value to obtain the upper boundary hash result and the lower boundary hash result of the query range;
[0146] Based on the minimum bounding rectangle (MBR) corresponding to the key value range of energy data stored in each block, the upper boundary hash result of the query range, and the lower boundary hash result of the query range, the target block corresponding to the query information is determined.
[0147] Optionally, the query module 410 is further configured to: determine the target node number corresponding to the energy data to be stored based on the jump function and the total number of nodes in the blockchain system;
[0148] Energy data is stored based on the target node number.
[0149] Optionally, the query module 410 is further configured to: when a new node is added to the blockchain system, re-determine the second node number corresponding to each energy data according to the jump function and the total number of nodes in the blockchain system;
[0150] If the second node number is different from the original node number corresponding to the energy data, the energy data will be migrated from the original node to the node indicated by the second node number.
[0151] Optionally, the query module 410 is further configured to: determine the slice node information corresponding to the energy data to be uploaded to the blockchain system based on the random forest model; the node information is used to indicate the slice size of the energy data, the number of energy data slices, and the number of redundant storage nodes for each energy data slice;
[0152] Based on the slice node information corresponding to the energy data, the energy data is uploaded to the blockchain system.
[0153] The apparatus of this invention is used to execute the method in any of the foregoing method embodiments, and its implementation principle and technical effect are similar, so they will not be described again here.
[0154] Figure 5 The example illustrates the physical structure of an electronic device, which may include: a processor 510, a communications interface 520, a memory 530, and a communication bus 540, wherein the processor 510, the communications interface 520, and the memory 530 communicate with each other through the communication bus 540. The processor 510 can invoke logical instructions in the memory 530 to execute a query method for high-frequency data in the energy blockchain. This method includes: when the query information for energy data is a continuous value, matching the Z-order code of the query information with the key value in the MBZ tree corresponding to the target block to determine the query result for the energy data corresponding to the query information; the MBZ tree is constructed based on the Z-order code of the energy data already stored in the energy blockchain and the Merkle prefix tree (MPT); the Z-order code of the energy data serves as the key value in the Merkle prefix tree (MPT); and / or, when the query information for energy data is a discrete value, matching the nibble sequence corresponding to the query information with the key value in the MBZ tree corresponding to the target block to determine the query result for the energy data corresponding to the query information; the MBZ tree is constructed based on the half-byte nibble sequence corresponding to the energy data already stored in the energy blockchain and the Merkle prefix tree (MPT); the nibble sequence corresponding to the energy data serves as the key value in the Merkle prefix tree (MPT).
[0155] Furthermore, the logical instructions in the aforementioned memory 530 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, essentially, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0156] On the other hand, the present invention also provides a computer program product, the computer program product comprising a computer program stored on a non-transitory computer-readable storage medium, the computer program comprising program instructions, wherein when the program instructions are executed by a computer, the computer is able to execute the energy blockchain high-frequency data query method provided by the above methods, the method comprising: when the energy data query information is a continuous value, matching the Z-order code of the query information with the key value in the MBZ tree corresponding to the target block to determine the query result of the energy data corresponding to the query information; the MBZ tree is constructed based on the Z-order code of the energy data already stored in the energy blockchain and the Merkle prefix tree MPT; the Z-order code of the energy data is used as the key value in the Merkle prefix tree MPT; and / or, when the energy data query information is a discrete value, matching the nibble sequence corresponding to the query information with the key value in the MBZ tree corresponding to the target block to determine the query result of the energy data corresponding to the query information; the MBZ tree is constructed based on the half-byte nibble sequence corresponding to the energy data already stored in the energy blockchain and the Merkle prefix tree MPT; the nibble sequence corresponding to the energy data is used as the key value in the Merkle prefix tree MPT.
[0157] In another aspect, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon. When executed by a processor, the computer program implements the above-described methods for querying high-frequency energy blockchain data. The method includes: when the query information of the energy data is a continuous value, matching the Z-order code of the query information with the key value in the MBZ tree corresponding to the target block to determine the query result of the energy data corresponding to the query information; the MBZ tree is constructed based on the Z-order code of the energy data already stored in the energy blockchain and the Merkle prefix tree (MPT); the Z-order code of the energy data serves as the key value in the Merkle prefix tree (MPT); and / or, when the energy data query information is a discrete value, matching the nibble sequence corresponding to the query information with the key value in the MBZ tree corresponding to the target block to determine the query result of the energy data corresponding to the query information; the MBZ tree is constructed based on the half-byte nibble sequence corresponding to the energy data already stored in the energy blockchain and the Merkle prefix tree (MPT); the nibble sequence corresponding to the energy data serves as the key value in the Merkle prefix tree (MPT).
[0158] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. 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 network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0159] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0160] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for querying high-frequency data in an energy blockchain, characterized in that, include: When the energy data query information is a continuous value, the Z-order code of the query information is matched with the key value in the MBZ tree corresponding to the target block to determine the query result of the energy data corresponding to the query information; the MBZ tree is constructed based on the Z-order code of the energy data already stored in the energy blockchain and the Merkle prefix tree (MPT) corresponding to the energy data; the Z-order code of the energy data serves as the key value in the Merkle prefix tree (MPT); and / or, When the energy data query information is a discrete value, the nibble sequence corresponding to the query information is matched with the key value in the MBZ tree corresponding to the target block to determine the query result of the energy data corresponding to the query information; the MBZ tree is constructed based on the half-byte nibble sequence corresponding to the energy data already stored in the energy blockchain and the Merkle prefix tree MPT corresponding to the energy data; the nibble sequence corresponding to the energy data is used as the key value in the Merkle prefix tree MPT; Before determining the query result of the energy data corresponding to the query information, the method further includes: If the query information is a discrete value, perform a hash calculation on the query information to obtain a hash result; The target block corresponding to the query information is determined based on the Bloom filter associated with the target node and the hash result; the target node is the node on the hash ring corresponding to the energy data that corresponds to the hash result. Before determining the query result of the energy data corresponding to the query information, the method further includes: When the query information is a continuous value, a hash calculation is performed on the boundary of the continuous value to obtain the upper boundary hash result and the lower boundary hash result of the query range; Based on the minimum bounding rectangle (MBR) corresponding to the key value range of the energy data stored in each block, the upper boundary hash result of the query range, and the lower boundary hash result of the query range, the target block corresponding to the query information is determined. The method further includes: When a new node is added to the blockchain system, the second node number corresponding to each energy data is re-determined based on the jump function and the total number of nodes in the blockchain system. If the second node number is different from the original node number corresponding to the energy data, then the energy data is migrated from the original node to the node indicated by the second node number; The method further includes: Based on the random forest model, the slice node information corresponding to the energy data that needs to be uploaded to the blockchain system is determined; the node information is used to indicate the slice size of the energy data, the number of energy data slices, and the number of redundant storage nodes for each energy data slice. The energy data is uploaded to the blockchain system based on the slice node information corresponding to the energy data.
2. The method for querying high-frequency data in energy blockchain according to claim 1, characterized in that, The method further includes: If the query information is a discrete value, and the nibble sequence corresponding to the query information matches the shared path of the extended node in the MBZ tree, then jump directly to the end of the shared path or the next branch point to perform the query and determine the query result of the energy data corresponding to the query information.
3. The method for querying high-frequency data in an energy blockchain according to claim 1 or 2, characterized in that, The method further includes: Based on the jump function and the total number of nodes in the blockchain system, determine the target node number corresponding to the energy data to be stored; The energy data is stored according to the target node number.
4. A query device for high-frequency data in an energy blockchain, used to implement the method as described in any one of claims 1-3, characterized in that, include: The query module is used to match the Z-order code of the query information with the key value in the MBZ tree corresponding to the target block when the query information of the energy data is a continuous value, to determine the query result of the energy data corresponding to the query information; the MBZ tree is constructed based on the Z-order code of the energy data stored in the energy blockchain and the Merkle prefix tree MPT; the Z-order code of the energy data is used as the key value in the Merkle prefix tree MPT; and / or, When the energy data query information is a discrete value, the nibble sequence corresponding to the query information is matched with the key value in the MBZ tree corresponding to the target block to determine the query result of the energy data corresponding to the query information; The MBZ tree is constructed based on the half-byte nibble sequence corresponding to the energy data stored in the energy blockchain and the Merkle prefix tree MPT; the nibble sequence corresponding to the energy data serves as the key value in the Merkle prefix tree MPT.
5. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the energy blockchain high-frequency data query method as described in any one of claims 1 to 3.
6. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the energy blockchain high-frequency data query method as described in any one of claims 1 to 3.
Citation Information
Patent Citations
Message processing method and device and electronic equipment
CN114253979A
Packet processing method and apparatus, and electronic device
WO2023115978A1