A method and system for storing electric power data based on blockchain

By analyzing the time and access log of power data, dividing it into on-chain and off-chain storage, and using hash optimization, the security and capacity problems of traditional power data storage methods are solved, and the safety and efficiency of power data are achieved Storage and stability.

CN118708597BActive Publication Date: 2024-11-19ELECTRIC POWER RESEARCH INSTITUTE OF STATE GRID SHANDONG ELECTRIC POWER COMPANY +2
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411203401.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-30
Publication Date
2024-11-19
Estimated Expiration
2044-08-30

AI Technical Summary

Technical Problem

Traditional power data storage methods have the risk of low data security and being easily tampered with and lost, and the storage capacity of the blockchain cannot meet the storage needs of a large amount of power data, affecting the security of data storage and the stability of the blockchain.

Method used

By acquiring the time data and access log of the power data, the stored value on the chain is obtained, and the data is divided into on-chain and off-chain storage. The SHA-256 algorithm and Merkle tree merge hash value are used for optimization, and the storage method is adjusted to meet the area Blockchain's storage capacity limits enable secure and efficient storage of data.

Benefits of technology

It ensures the storage security of power data, reduces the storage pressure of blockchain, improves the stability of power data storage, and realizes effective storage of data through hash value merging when the blockchain cannot meet storage needs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118708597B_ABST
    Figure CN118708597B_ABST
Patent Text Reader

Abstract

The present invention belongs to the technical field of data storage. The present invention provides an electric power data storage method and system based on blockchain and off-chain, including: the present invention reduces the storage pressure of blockchain while ensuring the security of important data storage by dividing the electric power data to be stored; when the storage capacity of blockchain cannot meet the storage of electric power data, data storage is optimized through data hash value analysis to further reduce the storage pressure of blockchain; when the hash values ​​of all data are stored on-chain and all data are stored off-chain, if the blockchain still cannot meet the storage requirements, hash value merging is achieved through Merkle tree to obtain a root hash value; when the blockchain cannot meet the storage requirements of electric power data and the storage requirements of hash values ​​of all electric power data, the present invention performs hash value merging processing to achieve storage of electric power data by blockchain within a limited storage space.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of data storage, and specifically relates to a method and system for storing electric power data based on and off the blockchain. Background Art

[0002] Traditional power data storage methods have low data security, easy to be tampered and lost risks, and low data access efficiency. With the continuous development of blockchain technology, its application in the field of data storage is becoming more and more extensive. Blockchain, with its decentralized, tamper-proof and traceable characteristics, provides a new idea for the storage of power data.

[0003] A Chinese patent application with publication number CN116450572A discloses a blockchain-based power supply chain data storage optimization method, including: S1: creating a consortium chain with power supply chain participating organizations as members, and specifying the internal nodes of the consortium chain; S2: building a blockchain network based on the consortium chain; S3: controlling the access and storage of power supply chain data by consortium chain members through smart contracts; S4: creating a consortium chain data storage layer, the data storage layer includes a dual-chain structure and IPFS; wherein the dual-chain structure is responsible for on-chain storage, and the InterPlanetary File System IPFS is responsible for off-chain storage.

[0004] In the above-mentioned prior art, on-chain storage of power data is realized, but in practice, the amount of power data collected is large, and the storage capacity of the blockchain may not be able to meet the storage of a large amount of power data. If there is a lack of whether the blockchain can meet the storage and analysis of a large amount of power data, the storage security of the data and the operational stability of the blockchain cannot be guaranteed. In addition, there is also a lack of a method to achieve distributed storage through hash values ​​(storing hash values ​​on the chain and storing power data off the chain) to solve the problem that the blockchain cannot meet the storage of a large amount of power data when the blockchain cannot meet the storage of a large amount of power data.

[0005] To this end, the present invention provides a method and system for storing electric power data based on and off the blockchain. Summary of the invention

[0006] In order to make up for the deficiencies of the prior art, at least one technical problem raised in the background technology is solved.

[0007] The technical solution adopted by the present invention to solve the technical problem is: a method for storing power data on and off the blockchain, including:

[0008] Based on the query interface of the data collection platform of all the power data to be stored, the time data of all the power data to be stored is obtained, wherein the time data includes the capture time difference. At the same time, according to the operation access log of the power system storing the power data, the accessed data of the same type as all the power data to be stored in the historical storage cycle is obtained, wherein the accessed data includes the average number of accesses. The time data and the accessed data are processed and analyzed to obtain the on-chain storage value of the power data to be stored;

[0009] Based on the on-chain storage value, all the power data to be stored are divided into on-chain storage data and off-chain storage data;

[0010] Obtain the total storage capacity required for on-chain data storage and the standard limited capacity of the blockchain, and compare them. According to the comparison results, determine whether the blockchain can meet the storage requirements for on-chain data storage. If not, generate an optimization analysis signal.

[0011] Based on the optimization analysis signal, the hash value of the on-chain storage data is generated according to the SHA-256 algorithm, and the number of storage bytes of the on-chain storage data is compared and analyzed with the number of storage bytes of the hash value corresponding to the on-chain storage data. According to the comparison result, the on-chain storage data is marked as adjustable storage data and non-adjustable storage data;

[0012] Based on the number of storage bytes of the adjustable storage data and the number of storage bytes of the hash value corresponding to the adjustable storage data, an adjustment priority coefficient is obtained by processing and analyzing, an adjustment sequence table is generated according to the adjustment priority coefficient, and the first storage mode is optimized for the adjustable storage data according to the adjustment sequence table. If the data storage is satisfied after the first storage mode optimization, the optimization ends; if the data storage is still not satisfied, a storage mode re-optimization signal is generated;

[0013] Based on the storage method re-optimization signal, the second storage method is optimized by merging the hash value through the Merkle tree.

[0014] As a further technical solution of the present invention, the specific process of dividing all the power data to be stored is as follows:

[0015] The capture deviation ratio BH and the access number ratio CS are processed by the formula:

[0016] Get the chain storage value CX, where s1 and s2 are both preset proportional coefficients;

[0017] If the on-chain storage value is less than the on-chain storage threshold, the power data to be stored is marked as off-chain storage data;

[0018] If the on-chain storage value is greater than or equal to the on-chain storage threshold, the power data to be stored is marked as on-chain storage data.

[0019] As a further technical solution of the present invention, the capture deviation ratio BH is obtained in the following manner:

[0020] Obtain the capture time differences of all the power data to be stored, and sum them to obtain the total capture time difference, perform ratio processing on the capture time difference of the power data to be stored and the total capture time difference to obtain the capture deviation ratio of the data to be stored, and mark it as BH;

[0021] The access count ratio CS is obtained as follows:

[0022] Obtain the average number of times the power data of the same type as all the power data to be stored is accessed during the historical storage period, and sum them up to obtain the total number of accesses. Ratio the average number of times the power data of the same type as the power data to be stored is accessed during the historical storage period to the total number of accesses to obtain the access number ratio, and mark it as CS.

[0023] As a further technical solution of the present invention, the optimization analysis signal is generated in the following manner:

[0024] If the total storage capacity required for storing data on the chain is greater than or equal to the standard limit capacity of the blockchain, it means that the blockchain cannot meet the storage of the data stored on the chain, and an optimization analysis signal is generated.

[0025] As a further technical solution of the present invention, the process of marking the data stored on the chain is specifically as follows:

[0026] If the number of storage bytes of the on-chain storage data is greater than the number of storage bytes of the hash value corresponding to the on-chain storage data, the on-chain storage data is marked as adjustable storage data;

[0027] If the number of storage bytes of the on-chain stored data is less than or equal to the number of storage bytes of the hash value corresponding to the on-chain stored data, the on-chain stored data will be marked as non-adjustable storage data.

[0028] As a further technical solution of the present invention, the method for obtaining the adjustment priority coefficient is:

[0029] The optimized performance value YH and the on-chain storage value CX are processed by the formula: The adjustment priority coefficient TZ is obtained, wherein a1 and a2 are both preset proportional coefficients.

[0030] As a further technical solution of the present invention, the optimization performance value YH is obtained in the following manner:

[0031] The number of storage bytes of the adjustable storage data and the number of storage bytes of the hash value corresponding to the adjustable storage data are obtained, and the difference is processed to obtain the byte deviation of the adjustable storage data, and the ratio is processed with the number of storage bytes of the hash value corresponding to the adjustable storage data to obtain the optimized performance value of the adjustable storage data, and it is marked as YH.

[0032] As a further technical solution of the present invention, the specific process of optimizing the first storage method is as follows:

[0033] According to the adjustment priority coefficient TZ, the adjustable storage data is sorted in descending order to generate an adjustment sequence table;

[0034] The total storage capacity required to store data on the chain is processed by difference with the standard limit capacity of the blockchain to obtain the storage capacity to be adjusted;

[0035] According to the adjustment sequence table, the adjustable storage data is selected in sequence in the adjustment sequence table, and the byte deviations of the adjustable storage data of the adjustable storage data are summed to obtain the adjustment capacity;

[0036] When the adjustment capacity is less than or equal to the storage capacity to be adjusted, the selection is stopped, and the hash value of the selected adjustable storage data is stored on the blockchain; and the unselected adjustable storage data is directly stored on the blockchain;

[0037] If the adjustment capacity is still greater than the storage capacity to be adjusted after all adjustable storage data in the adjustment sequence table are selected, a storage mode re-optimization signal is generated.

[0038] As a further technical solution of the present invention, the specific process of optimizing the second storage method is as follows:

[0039] S1, initialize leaf nodes;

[0040] Get the hash value of the adjustable storage data and use the obtained hash value as the leaf node of the Merkle tree;

[0041] S2, the level of tree construction;

[0042] The first level: directly composed of leaf nodes;

[0043] Second level: If there are an odd number of leaf nodes, the last leaf node will be combined with itself (directly copy the hash value);

[0044] Combine the hash values ​​of adjacent leaf nodes, perform hash operations on the combined data, and generate the hash value of the node at the previous level;

[0045] Subsequent levels:

[0046] For each layer, the adjacent node hash values ​​are combined and hashed until only one hash value remains;

[0047] S3, generate a root hash value.

[0048] An electric power data storage system based on blockchain and off-chain, comprising:

[0049] Data storage module: Based on the query interface of the data collection platform of all power data to be stored, the time data of all power data to be stored is obtained, wherein the time data includes the capture time difference. At the same time, according to the operation access log of the power system storing the power data, the accessed data of the same type as all the power data to be stored in the historical storage cycle is obtained, wherein the accessed data includes the average number of accesses. The time data and the accessed data are processed and analyzed to obtain the on-chain storage value of the power data to be stored;

[0050] On-chain data partitioning module: divides all power data to be stored into on-chain storage data and off-chain storage data based on the on-chain storage value;

[0051] Storage optimization judgment module: obtains the total storage capacity required for on-chain storage data and the standard limit capacity of the blockchain, and compares them. Based on the comparison results, it is determined whether the blockchain can meet the storage requirements for on-chain storage data. If not, an optimization analysis signal is generated;

[0052] Optimized data marking module: Based on the optimization analysis signal, the hash value of the on-chain storage data is generated according to the SHA-256 algorithm, and the number of storage bytes of the on-chain storage data is compared and analyzed with the number of storage bytes of the hash value corresponding to the on-chain storage data. According to the comparison result, the on-chain storage data is marked as adjustable storage data and non-adjustable storage data;

[0053] The first storage optimization processing module: based on the number of storage bytes of the adjustable storage data and the number of storage bytes of the hash value corresponding to the adjustable storage data, the adjustment priority coefficient is obtained by processing and analyzing, an adjustment sequence table is generated according to the adjustment priority coefficient, and the first storage mode optimization is performed on the adjustable storage data according to the adjustment sequence table. If the data storage is satisfied after the first storage mode optimization, the optimization ends; if the data storage is still not satisfied, a storage mode re-optimization signal is generated;

[0054] The second storage optimization processing module: based on the storage method re-optimization signal, the second storage method is optimized by merging the hash value through the Merkle tree.

[0055] The beneficial effects of the present invention are as follows:

[0056] 1. Based on the time data of all power data to be stored and the accessed data of the same type as all power data to be stored in the historical storage period, the on-chain storage value of the power data to be stored is analyzed, and the power data to be stored is marked and divided according to the on-chain storage value, and is divided into on-chain data and off-chain data, and the on-chain data is stored on the blockchain, and the off-chain data is stored off-chain. The present invention ensures the security of important data storage by dividing the power data to be stored, while reducing the storage pressure of the blockchain and improving the stability of power data storage.

[0057] 2. Obtain the required total storage capacity of the on-chain storage data and the standard limited capacity of the blockchain, and compare them to determine whether the blockchain can meet the storage of the on-chain storage data. If it cannot be met, generate a hash value of the on-chain storage data according to the SHA-256 algorithm, and compare and analyze the number of storage bytes of the on-chain storage data with the number of storage bytes of the hash value corresponding to the on-chain storage data, mark the on-chain storage data to obtain adjustable storage data, and obtain an adjustment priority coefficient based on the analysis and processing of the adjustable storage data. Generate an adjustment sequence table according to the adjustment priority coefficient, optimize the adjustable storage data in a first storage mode according to the adjustment sequence table, store its hash value on the chain, and store the data corresponding to the hash value stored on the chain off the chain. If the data storage is met after the first storage mode optimization, the optimization ends. If the data storage still cannot be met, a storage mode re-optimization signal is generated. When the blockchain storage capacity cannot meet the storage of power data, the present invention realizes data storage optimization through data hash value analysis, thereby further alleviating the storage pressure of the blockchain.

[0058] 3. Based on storing the hash values ​​of all data on the chain, when all data are stored off the chain, if the blockchain still cannot meet the storage requirements, the hash values ​​are merged through the Merkle tree to obtain the root hash value, and the data is stored through the root hash value. When the blockchain cannot meet the storage requirements of power data and the storage requirements of the hash values ​​of all power data, the present invention merges the hash values ​​to realize the storage of power data in the blockchain within a limited storage space. BRIEF DESCRIPTION OF THE DRAWINGS

[0059] The present invention will be further described below in conjunction with the accompanying drawings.

[0060] Figure 1 This is a flowchart of the steps of a method for storing power data on and off the blockchain according to an embodiment of the present invention;

[0061] Figure 2 It is a flowchart of an electric power data storage system based on blockchain and off-chain as described in an embodiment of the present invention. DETAILED DESCRIPTION

[0062] In order to make the technical means, creative features, objectives and effects achieved by the present invention easy to understand, the present invention is further explained below in conjunction with specific implementation methods.

[0063] Embodiment 1, as Figure 1 As shown, a method for storing power data based on blockchain and off-chain according to an embodiment of the present invention includes:

[0064] Step 1: Based on the query interface of the data collection platform of all the power data to be stored, the time data of all the power data to be stored is obtained, wherein the time data includes the capture time difference. At the same time, according to the operation access log of the power system storing the power data, the accessed data of the same type as all the power data to be stored in the historical storage cycle is obtained, wherein the accessed data includes the average number of accesses. The time data and the accessed data are processed and analyzed to obtain the on-chain storage value of the power data to be stored;

[0065] It should be noted that the historical storage period represents the duration from the time point when the power data starts to be stored to the current time point. It should also be noted that the capture time difference represented by the time data means: the time difference between the generation time point of the power data to be stored and the time point when the power data to be stored is collected and captured by the data collection platform;

[0066] Among them, the average number of visits = the number of visits in the historical storage period / the length of the historical storage period;

[0067] In some embodiments, the capture time differences of all the power data to be stored are obtained and summed to obtain a total capture time difference, and the capture time difference of the power data to be stored is ratioed to the total capture time difference to obtain a capture deviation ratio of the data to be stored, which is marked as BH;

[0068] Obtain the average number of times that the power data of the same type as all the power data to be stored are accessed in the historical storage period, and sum them up to obtain the total number of accesses, perform ratio processing on the average number of times that the power data of the same type as the power data to be stored are accessed in the historical storage period and the total number of accesses to obtain the access number ratio, and mark it as CS;

[0069] The obtained capture deviation ratio BH and access number ratio CS are processed by data, and the formula is:

[0070] Get the chain storage value CX, where s1 and s2 are both preset proportional coefficients;

[0071] It should be noted that the meaning of the on-chain storage value Cs is: the on-chain storage value CX is calculated by the capture deviation ratio BH and the access number ratio CS, wherein the smaller the capture deviation ratio is, the shorter the time from the generation to the capture and collection of the power data to be stored is, which means that the real-time performance of the power data to be stored is higher. Similarly, the larger the access number ratio is, the more frequently the power data of the same type as the power data to be stored has been accessed in the past. The capture deviation ratio BH and the access number ratio CS reflect the criticality of the power data to be stored as a whole, that is, the larger the on-chain storage value Cs is, the more critical the power data to be stored is, and it should be stored on the blockchain. On the contrary, the smaller the on-chain storage value Cs is, the weaker the criticality of the power data to be stored is, and it can be stored under the blockchain.

[0072] Step 2: Based on the on-chain storage value, all the power data to be stored are divided into on-chain storage data and off-chain storage data;

[0073] In some embodiments, the on-chain storage value is compared with the on-chain storage threshold, and the specific comparison process is:

[0074] If the on-chain storage value is less than the on-chain storage threshold, the power data to be stored is marked as off-chain storage data and stored off-chain;

[0075] The methods of storing off-chain data include but are not limited to:

[0076] Combine its off-chain storage data storage with traditional data centers, cloud storage services or decentralized storage networks;

[0077] If the on-chain storage value is greater than or equal to the on-chain storage threshold, the power data to be stored is marked as on-chain storage data and stored on the chain;

[0078] The technical solution of an embodiment of the present invention is: based on the time data of all power data to be stored and the accessed data of the same type as all power data to be stored in the historical storage period, the on-chain storage value of the power data to be stored is analyzed, and the power data to be stored is marked and divided according to the on-chain storage value, and divided into on-chain data and off-chain data, and the on-chain data is stored on the blockchain, and the off-chain data is stored off-chain. The present invention ensures the security of important data storage by dividing the power data to be stored, while reducing the storage pressure of the blockchain and improving the stability of power data storage.

[0079] Embodiment 2, based on Embodiment 1, the present invention stores its on-chain data on-chain, but usually on-chain storage needs to consider whether the blockchain can meet the storage ratio of power data, to prevent the blockchain from failing to meet the storage of its power data or the blockchain from storing power data under extreme conditions, resulting in excessive storage pressure, which will reduce the storage quality of power data and cause the quality of use and processing of stored data to decline. Therefore, the embodiment of the present invention optimizes and analyzes the storage of its blockchain and power data, such as Figure 1 As shown, the method for storing power data based on blockchain and off-chain according to an embodiment of the present invention includes:

[0080] Step 3: Obtain the total storage capacity required for on-chain data storage and the standard limited capacity of the blockchain, and compare them. According to the comparison results, determine whether the blockchain can meet the storage of on-chain data storage. If it cannot meet the requirements, generate an optimization analysis signal.

[0081] In some embodiments, the required storage capacity for storing data on-chain is compared to a standard limited capacity of the blockchain;

[0082] If the total storage capacity required for storing data on the chain is greater than or equal to the standard limit capacity of the blockchain, it means that the blockchain cannot meet the storage requirements for storing data on the chain, and an optimization analysis signal is generated;

[0083] If the total storage capacity required for storing data on the chain is less than the standard limit capacity of the blockchain, it means that the cross-chain can meet the storage needs of the data stored on the chain, and the data stored on the chain will be stored on its cross-chain;

[0084] Step 4: Based on the optimization analysis signal, generate the hash value of the on-chain storage data according to the SHA-256 algorithm, and compare the number of storage bytes of the on-chain storage data with the number of storage bytes of the hash value corresponding to the on-chain storage data. Mark the on-chain storage data according to the comparison result, and mark it as adjustable storage data and non-adjustable storage data;

[0085] In some embodiments, the number of storage bytes of the on-chain stored data is compared with the number of storage bytes of the hash value corresponding to the on-chain stored data, specifically:

[0086] If the number of storage bytes of the on-chain storage data is greater than the number of storage bytes of the hash value corresponding to the on-chain storage data, the on-chain storage data is marked as adjustable storage data;

[0087] If the number of storage bytes of the on-chain stored data is less than or equal to the number of storage bytes of the hash value corresponding to the on-chain stored data, the on-chain stored data is marked as non-adjustable storage data;

[0088] It should be noted that adjustable storage data means that its storage bytes are greater than the corresponding hash value storage bytes. The storage of its data can be optimized by storing its hash value on the chain and storing its data off the chain, thereby reducing the storage pressure of the blockchain. Conversely, non-adjustable storage data means that its storage bytes are less than or equal to the corresponding hash value storage bytes. If its hash value is stored on the chain and its data is stored off the chain, it will not reduce the storage pressure of the blockchain. It should be noted that the occurrence of non-adjustable storage data is extremely rare, and usually the storage bytes of the data itself will be much larger than the storage bytes of the corresponding hash value.

[0089] Step 5: Based on the number of storage bytes of the adjustable storage data and the number of storage bytes of the hash value corresponding to the adjustable storage data, an adjustment priority coefficient is obtained by processing and analyzing, an adjustment sequence table is generated according to the adjustment priority coefficient, and the first storage mode is optimized for the adjustable storage data according to the adjustment sequence table. If the data storage is satisfied after the first storage mode optimization, the optimization ends; if the data storage is still not satisfied, a storage mode re-optimization signal is generated;

[0090] In some embodiments, the number of storage bytes of the adjustable storage data and the number of storage bytes of the hash value corresponding to the adjustable storage data are obtained, and a difference process is performed on them to obtain a byte deviation of the adjustable storage data, and a ratio process is performed on it and the number of storage bytes of the hash value corresponding to the adjustable storage data to obtain an optimized performance value of the adjustable storage data, and the optimized performance value is marked as YH;

[0091] It should be noted that the meaning of the optimization performance value YH is: the optimization performance value reflects the degree of deviation between the number of storage bytes of adjustable storage data and the number of storage bytes of the hash value corresponding to the adjustable storage data. The larger the optimization performance value YH, the greater the deviation between the memory occupied by the hash value stored on the blockchain and the memory occupied by the adjustable storage data on the blockchain. The storage pressure of the blockchain can be reduced by storing the hash value corresponding to the adjustable storage data on the blockchain;

[0092] The obtained optimized performance value YH and the on-chain storage value CX are processed by the formula: The adjustment priority coefficient TZ is obtained, wherein a1 and a2 are both preset proportional coefficients;

[0093] It should be noted that the adjustment priority coefficient TZ is calculated by combining the optimized performance value YH and the on-chain storage value CX, which reflects the storage adjustment priority level of the adjustable storage data. The optimized performance value YH reflects the deviation between the number of storage bytes of the adjustable storage data and the number of storage bytes of the corresponding hash value of the adjustable storage data. The larger the optimized performance value YH, the more it can reduce the storage pressure of the blockchain. The on-chain storage value CX reflects the criticality of the data. If the data is less critical and the deviation between the number of storage bytes of the data and the number of storage bytes of the corresponding hash value is greater, the adjustment priority level of the data is higher.

[0094] In some embodiments, the adjustable storage data is sorted in descending order according to the adjustment priority coefficient TZ to generate an adjustment sequence table;

[0095] The total storage capacity required to store data on the chain is processed by difference with the standard limit capacity of the blockchain to obtain the storage capacity to be adjusted;

[0096] According to the adjustment sequence table, the adjustable storage data is selected in sequence in the adjustment sequence table, and the byte deviations of the adjustable storage data are summed to obtain the adjustment capacity;

[0097] When the adjustment capacity is less than or equal to the storage capacity to be adjusted, the selection is stopped, and the hash value of the selected adjustable storage data is stored on the blockchain; the adjustable storage data corresponding to the stored hash value is stored off-chain, and the unselected adjustable storage data is directly stored on the blockchain;

[0098] If after selecting all adjustable storage data in the adjustment sequence table, the adjustment capacity is still greater than the storage capacity to be adjusted, a storage mode re-optimization signal is generated;

[0099] The technical solution of the embodiment of the present invention is: obtaining the required total storage capacity of the on-chain storage data and the standard limit capacity of the blockchain, and comparing them to determine whether the blockchain can meet the storage of the on-chain storage data. If it cannot be met, a hash value of the on-chain storage data is generated according to the SHA-256 algorithm, and the number of storage bytes of the on-chain storage data is compared and analyzed with the number of storage bytes of the hash value corresponding to the on-chain storage data, and the on-chain storage data is marked to obtain adjustable storage data. Based on the analysis and processing of the adjustable storage data, an adjustment priority coefficient is obtained, and an adjustment sequence table is generated according to the adjustment priority coefficient. According to the adjustment sequence table, the first storage method is optimized for the adjustable storage data, and its hash value is stored on the chain, and the data corresponding to the hash value stored on the chain is stored off the chain. If the data storage is satisfied after the first storage method is optimized, the optimization ends. If the data storage still cannot be satisfied, a storage method re-optimization signal is generated. When the blockchain storage capacity cannot meet the storage of power data, the present invention realizes data storage optimization through data hash value analysis, thereby further reducing the storage pressure of the blockchain.

[0100] Embodiment 3, based on Embodiment 1 and Embodiment 2, a method for storing power data based on blockchain and off-chain according to an embodiment of the present invention includes:

[0101] Step 6: Optimize the signal based on the storage method, and optimize the second storage method by combining the hash value through the Merkle tree;

[0102] Specifically, the optimization process includes:

[0103] S1, initialize leaf nodes;

[0104] Get the hash value of the adjustable storage data and use the obtained hash value as the leaf node of the Merkle tree;

[0105] S2, the level at which the tree is constructed;

[0106] First level:

[0107] Directly composed of leaf nodes;

[0108] Second level:

[0109] If there are an odd number of leaf nodes, the last leaf node is combined with itself (directly copying the hash value);

[0110] Combine the hash values ​​of adjacent leaf nodes, perform hash operations on the combined data, and generate the hash value of the node at the previous level;

[0111] Subsequent levels:

[0112] For each layer, the adjacent node hash values ​​are combined and hashed until only one hash value remains;

[0113] S3, generate the root hash value;

[0114] When all leaf nodes have been processed and all levels have been constructed, the unique hash value at the top of the tree is the root hash value of the Merkle tree;

[0115] An exemplary description is given below:

[0116] Assume there are four leaf nodes, and the hash values ​​are H1, H2, H3, and H4 respectively;

[0117] Second level:

[0118] Combine H1 and H2 and calculate the hash to get H12 (i.e. hash(H1+H2), where + represents the concatenation operation and hash represents the hash function);

[0119] Similarly, combine H3 and H4 (if H3 and H4 are the only two nodes, directly calculate H34=hash(H3+H4); if the number of nodes is an odd number, the last node will be combined with itself) to get H34;

[0120] The third level (root level):

[0121] Combine H12 and H34, calculate the hash and get the root hash value HR=hash(H12+H34);

[0122] HR is the root hash value of the Merkle tree, which is stored on the blockchain.

[0123] It should be noted that when access to power data is required, the hash value verification is required to access or verify the power data;

[0124] The technical solution of an embodiment of the present invention is: based on storing the hash values ​​of all data on the chain, when all data are stored off the chain, if the blockchain still cannot meet the storage requirements, the hash values ​​are merged through the Merkle tree to obtain the root hash value, and the data is stored through the root hash value. When the blockchain cannot meet the storage requirements of power data and the storage requirements of the hash values ​​of all power data, the present invention performs hash value merging processing to realize the storage of power data in the blockchain within a limited storage space.

[0125] Embodiment 4, as Figure 2 As shown, an electric power data storage system based on blockchain and off-chain according to an embodiment of the present invention includes:

[0126] Data storage module: Based on the query interface of the data collection platform of all power data to be stored, the time data of all power data to be stored is obtained, wherein the time data includes the capture time difference. At the same time, according to the operation access log of the power system storing the power data, the accessed data of the same type as all the power data to be stored in the historical storage cycle is obtained, wherein the accessed data includes the average number of accesses. The time data and the accessed data are processed and analyzed to obtain the on-chain storage value of the power data to be stored;

[0127] On-chain data partitioning module: divides all power data to be stored into on-chain storage data and off-chain storage data based on the on-chain storage value;

[0128] Storage optimization judgment module: obtains the total storage capacity required for on-chain storage data and the standard limit capacity of the blockchain, and compares them. Based on the comparison results, it is determined whether the blockchain can meet the storage requirements for on-chain storage data. If not, an optimization analysis signal is generated;

[0129] Optimized data marking module: Based on the optimization analysis signal, the hash value of the on-chain storage data is generated according to the SHA-256 algorithm, and the number of storage bytes of the on-chain storage data is compared and analyzed with the number of storage bytes of the hash value corresponding to the on-chain storage data. According to the comparison result, the on-chain storage data is marked as adjustable storage data and non-adjustable storage data;

[0130] The first storage optimization processing module: based on the number of storage bytes of the adjustable storage data and the number of storage bytes of the hash value corresponding to the adjustable storage data, the adjustment priority coefficient is obtained by processing and analyzing, an adjustment sequence table is generated according to the adjustment priority coefficient, and the first storage mode optimization is performed on the adjustable storage data according to the adjustment sequence table. If the data storage is satisfied after the first storage mode optimization, the optimization ends; if the data storage is still not satisfied, a storage mode re-optimization signal is generated;

[0131] The second storage optimization processing module: based on the storage mode re-optimization signal, the second storage mode is optimized by merging the hash value through the Merkle tree;

[0132] Blockchain: Stores power data or hash values ​​of power data.

[0133] The above shows and describes the basic principles, main features and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments, and the above embodiments and descriptions are only for explaining the principles of the present invention. Without departing from the spirit and scope of the present invention, the present invention may have various changes and improvements, and these changes and improvements all fall within the scope of the present invention to be protected.

Claims

1. A method for storing power data on and off the blockchain. Features: include: Based on the query interface of the data collection platform of all the power data to be stored, the time data of all the power data to be stored is obtained, wherein the time data includes the capture time difference. At the same time, according to the operation access log of the power system storing the power data, the accessed data of the same type as all the power data to be stored in the historical storage cycle is obtained, wherein the accessed data includes the average number of accesses. The time data and the accessed data are processed and analyzed to obtain the on-chain storage value of the power data to be stored; Based on the on-chain storage value, all the power data to be stored are divided into on-chain storage data and off-chain storage data; The specific process of dividing all the power data to be stored is as follows: The capture deviation ratio BH and the access number ratio CS are processed by the formula: Get the chain storage value CX, where s1 and s2 are both preset proportional coefficients; If the on-chain storage value is less than the on-chain storage threshold, the power data to be stored is marked as off-chain storage data; If the on-chain storage value is greater than or equal to the on-chain storage threshold, the power data to be stored is marked as on-chain storage data; The capture deviation ratio BH is obtained as follows: Obtain the capture time differences of all the power data to be stored, and sum them to obtain the total capture time difference, perform ratio processing on the capture time difference of the power data to be stored and the total capture time difference to obtain the capture deviation ratio of the data to be stored, and mark it as BH; The access count ratio CS is obtained as follows: Obtain the average number of times that the power data of the same type as all the power data to be stored are accessed in the historical storage period, and sum them up to obtain the total number of accesses, perform ratio processing on the average number of times that the power data of the same type as the power data to be stored are accessed in the historical storage period and the total number of accesses to obtain the access number ratio, and mark it as CS; Obtain the total storage capacity required for on-chain data storage and the standard limited capacity of the blockchain, and compare them. According to the comparison results, determine whether the blockchain can meet the storage requirements for on-chain data storage. If not, generate an optimization analysis signal. Based on the optimization analysis signal, the hash value of the on-chain storage data is generated according to the SHA-256 algorithm, and the number of storage bytes of the on-chain storage data is compared and analyzed with the number of storage bytes of the hash value corresponding to the on-chain storage data. According to the comparison result, the on-chain storage data is marked as adjustable storage data and non-adjustable storage data; Based on the number of storage bytes of the adjustable storage data and the number of storage bytes of the hash value corresponding to the adjustable storage data, an adjustment priority coefficient is obtained by processing and analyzing, an adjustment sequence table is generated according to the adjustment priority coefficient, and the first storage mode is optimized for the adjustable storage data according to the adjustment sequence table. If the data storage is satisfied after the first storage mode optimization, the optimization ends; if the data storage is still not satisfied, a storage mode re-optimization signal is generated; The adjustment priority coefficient is obtained in the following manner: The optimized performance value YH and the on-chain storage value CX are processed by the formula: The adjustment priority coefficient TZ is obtained, wherein a1 and a2 are both preset proportional coefficients; The optimization performance value YH is obtained as follows: Obtain the number of storage bytes of the adjustable storage data and the number of storage bytes of the hash value corresponding to the adjustable storage data, perform difference processing on them, obtain the byte deviation of the adjustable storage data, perform ratio processing on it and the number of storage bytes of the hash value corresponding to the adjustable storage data, obtain the optimization performance value of the adjustable storage data, and mark it as YH; Based on the storage method re-optimization signal, the second storage method is optimized by merging the hash value through the Merkle tree.

2. According to claim 1, a method for storing power data based on blockchain and off-chain, Features: The optimization analysis signal is generated in the following manner: If the total storage capacity required for storing data on the chain is greater than or equal to the standard limit capacity of the blockchain, it means that the blockchain cannot meet the storage of the data stored on the chain, and an optimization analysis signal is generated.

3. According to claim 1, a method for storing power data based on blockchain and off-chain, Features: The process of marking the data stored on the chain is specifically as follows: If the number of storage bytes of the on-chain storage data is greater than the number of storage bytes of the hash value corresponding to the on-chain storage data, the on-chain storage data is marked as adjustable storage data; If the number of storage bytes of the on-chain stored data is less than or equal to the number of storage bytes of the hash value corresponding to the on-chain stored data, the on-chain stored data will be marked as non-adjustable storage data.

4. According to claim 1, a method for storing power data based on blockchain and off-chain, Features: The specific process of optimizing the first storage method is as follows: According to the adjustment priority coefficient TZ, the adjustable storage data is sorted in descending order to generate an adjustment sequence table; The total storage capacity required to store data on the chain is processed by difference with the standard limit capacity of the blockchain to obtain the storage capacity to be adjusted; According to the adjustment sequence table, the adjustable storage data is selected in sequence in the adjustment sequence table, and the byte deviations of the adjustable storage data are summed to obtain the adjustment capacity; When the adjustment capacity is less than or equal to the storage capacity to be adjusted, the selection is stopped, and the hash value of the selected adjustable storage data is stored on the blockchain; And the unselected adjustable storage data is directly stored on the blockchain; If the adjustment capacity is still greater than the storage capacity to be adjusted after all adjustable storage data in the adjustment sequence table are selected, a storage mode re-optimization signal is generated.

5. According to claim 3, a method for storing power data based on blockchain and off-chain, Features: The specific process of optimizing the second storage method is as follows: S1, initialize leaf nodes; Get the hash value of the adjustable storage data and use the obtained hash value as the leaf node of the Merkle tree; S2, the level at which the tree is constructed; The first level: directly composed of leaf nodes; Second level: If there are an odd number of leaf nodes, the last leaf node will be combined with itself; Combine the hash values ​​of adjacent leaf nodes, perform hash operations on the combined data, and generate the hash value of the node at the previous level; Subsequent levels: For each layer, the adjacent node hash values ​​are combined and hashed until only one hash value remains; S3, generate a root hash value.

6. A power data storage system based on blockchain and off-chain, the system is used to implement the power data storage method according to any one of claims 1 to 5, Features: include: Data storage module: Based on the query interface of the data collection platform of all power data to be stored, the time data of all power data to be stored is obtained, wherein the time data includes the capture time difference. At the same time, according to the operation access log of the power system storing the power data, the accessed data of the same type as all the power data to be stored in the historical storage cycle is obtained, wherein the accessed data includes the average number of accesses. The time data and the accessed data are processed and analyzed to obtain the on-chain storage value of the power data to be stored; On-chain data partitioning module: divides all power data to be stored into on-chain storage data and off-chain storage data based on the on-chain storage value; The specific process of dividing all the power data to be stored is as follows: The capture deviation ratio BH and the access number ratio CS are processed by the formula: Get the chain storage value CX, where s1 and s2 are both preset proportional coefficients; If the on-chain storage value is less than the on-chain storage threshold, the power data to be stored is marked as off-chain storage data; If the on-chain storage value is greater than or equal to the on-chain storage threshold, the power data to be stored is marked as on-chain storage data; The capture deviation ratio BH is obtained as follows: Obtain the capture time differences of all the power data to be stored, and sum them to obtain the total capture time difference, perform ratio processing on the capture time difference of the power data to be stored and the total capture time difference to obtain the capture deviation ratio of the data to be stored, and mark it as BH; The access count ratio CS is obtained as follows: Obtain the average number of times that the power data of the same type as all the power data to be stored are accessed in the historical storage period, and sum them up to obtain the total number of accesses, perform ratio processing on the average number of times that the power data of the same type as the power data to be stored are accessed in the historical storage period and the total number of accesses to obtain the access number ratio, and mark it as CS; Storage optimization judgment module: obtains the total storage capacity required for on-chain storage data and the standard limit capacity of the blockchain, and compares them. Based on the comparison results, it is determined whether the blockchain can meet the storage requirements for on-chain storage data. If not, an optimization analysis signal is generated; Optimized data marking module: Based on the optimization analysis signal, the hash value of the on-chain storage data is generated according to the SHA-256 algorithm, and the number of storage bytes of the on-chain storage data is compared and analyzed with the number of storage bytes of the hash value corresponding to the on-chain storage data. According to the comparison result, the on-chain storage data is marked as adjustable storage data and non-adjustable storage data; The first storage optimization processing module: based on the number of storage bytes of the adjustable storage data and the number of storage bytes of the hash value corresponding to the adjustable storage data, the adjustment priority coefficient is obtained by processing and analyzing, an adjustment sequence table is generated according to the adjustment priority coefficient, and the first storage mode optimization is performed on the adjustable storage data according to the adjustment sequence table. If the data storage is satisfied after the first storage mode optimization, the optimization ends; if the data storage is still not satisfied, a storage mode re-optimization signal is generated; The adjustment priority coefficient is obtained in the following manner: The optimized performance value YH and the on-chain storage value CX are processed by the formula: The adjustment priority coefficient TZ is obtained, wherein a1 and a2 are both preset proportional coefficients; The optimization performance value YH is obtained as follows: Obtain the number of storage bytes of the adjustable storage data and the number of storage bytes of the hash value corresponding to the adjustable storage data, perform difference processing on them, obtain the byte deviation of the adjustable storage data, perform ratio processing on it and the number of storage bytes of the hash value corresponding to the adjustable storage data, obtain the optimization performance value of the adjustable storage data, and mark it as YH; The second storage optimization processing module: based on the storage method re-optimization signal, the second storage method is optimized by merging the hash value through the Merkle tree.