Fixed value checking method and device based on block chain, equipment and storage medium
By using blockchain and Merkle tree technology, the verification of relay protection settings in the power system is made efficient, accurate, and real-time, solving the problems of low efficiency and error-proneness in traditional methods and ensuring power grid safety.
Patent Information
- Application Number
- CN202510829647.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-20
- Publication Date
- 2025-11-14
AI Technical Summary
Traditional methods for verifying relay protection settings in power systems are inefficient, lack timeliness, and are prone to errors, which affect power grid safety.
A blockchain-based value verification method is adopted. By comparing the hash values of local and on-chain value files, a Merkle tree is constructed and the root of the Merkle tree is compared to identify the difference nodes and accurately locate the difference value items. This method utilizes the immutability of blockchain and the efficient verification mechanism of Merkle tree.
It improves the efficiency of setting value verification, meets real-time requirements, avoids chain reactions caused by setting value errors, and ensures power grid safety.
Smart Images

Figure CN120951980A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of power system relay protection technology, and in particular to a blockchain-based method, apparatus, device, and storage medium for setting value verification. Background Technology
[0002] In the field of power system relay protection, the accuracy and timeliness of setting verification directly affect the operational reliability of protection devices. Traditional setting verification methods mainly rely on offline manual comparison. Operators need to export the setting file from the protection device and compare it item by item with the benchmark file. This verification method has low efficiency, insufficient timeliness, and is prone to errors that threaten power grid safety.
[0003] Currently, blockchain technology, due to its characteristics of data immutability and traceability, has been attempted to be applied in the field of power data management. In existing technologies, blockchain is mostly used for the storage and version tracking of fixed value files. In the case of fixed value verification, customized files on the blockchain can be used as reference files. However, it does not fully utilize the structured characteristics of fixed value files (e.g., the nested hierarchy of fixed value files) and does not solve the problems existing in the traditional fixed value verification methods. Summary of the Invention
[0004] The embodiments of this application provide a blockchain-based method, apparatus, device, and storage medium for setting value verification, which can improve verification efficiency, meet the real-time requirements of setting value adjustment, effectively avoid chain reactions caused by setting value errors, and ensure power grid safety.
[0005] In a first aspect, embodiments of this application provide a blockchain-based method for verifying fixed values, including:
[0006] Obtain the local setting file currently running on the protection device, and determine the global hash value of the local setting file;
[0007] Determine the hash value of the on-chain fixed-value file and use it as the base hash value;
[0008] If the global hash value and the base hash value are inconsistent, a local Merkle tree is constructed based on the local value file, and the root of the local Merkle tree is determined.
[0009] Determine the Merkle root of the on-chain value file and use it as the reference root;
[0010] If the local Merkle tree root and the benchmark tree root are inconsistent, obtain the on-chain Merkle tree and compare the node hash values in the local Merkle tree and the on-chain Merkle tree using a recursive hierarchical algorithm, and determine the nodes with different hash values based on the comparison results;
[0011] Based on the difference nodes, the difference values between the local value file and the on-chain value file are determined, as well as the path of the difference values in the local value file; wherein, the on-chain value file is a value file on the blockchain; the on-chain Merkle tree is a Merkle tree on the blockchain; and the on-chain value file is the base file of the local value file.
[0012] Secondly, embodiments of this application provide a blockchain-based value verification device, comprising:
[0013] The first determining module is used to obtain the local setting file of the protection device currently in operation and determine the global hash value of the local setting file;
[0014] The second determining module is used to determine the hash value of the on-chain value file and use it as the base hash value;
[0015] The third determining module is used to construct a local Merkle tree based on the local value file and determine the root of the local Merkle tree if the global hash value and the base hash value are inconsistent.
[0016] The baseline root determination module is used to determine the Merkle root of the on-chain value file and use it as the baseline root.
[0017] The difference node determination module is used to obtain the on-chain Merkle tree and compare the node hash values in the local Merkle tree and the on-chain Merkle tree through a recursive hierarchical algorithm if the local Merkle tree root and the benchmark tree root are inconsistent, and determine the difference nodes in the hash values based on the comparison results.
[0018] The difference value item determination module is used to determine the difference value items between the local value file and the on-chain value file, as well as the path of the difference value items in the local value file, based on the difference node; wherein, the on-chain value file is a value file on the blockchain; the on-chain Merkle tree is a Merkle tree on the blockchain; and the on-chain value file is the base file of the local value file.
[0019] Thirdly, embodiments of this application provide an electronic device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, it implements the method provided in embodiments of this application.
[0020] Fourthly, embodiments of this application provide a computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to perform the method provided in embodiments of this application.
[0021] The technical solution provided in this application compares the global hash value of the local value file with the hash value of the on-chain value file. If an inconsistency exists, a local Merkle tree is constructed based on the local value file, and the root of the local Merkle tree is determined. The root of the local Merkle tree is then compared with the root of the Merkle tree in the on-chain value file. If an inconsistency exists, the hash values of the nodes in the local Merkle tree and the on-chain Merkle tree are compared to determine the nodes with hash value differences. Based on these nodes, the difference value items between the local value file and the on-chain value file, as well as the path of these difference value items in the local value file, are determined. Therefore, the technical solution provided in this application eliminates the need for manual verification of values, improves verification efficiency, meets the real-time requirements of value adjustment, effectively avoids chain reactions caused by value errors, and ensures power grid safety. Attached Figure Description
[0022] Figure 1 This is a flowchart of a blockchain-based value verification method provided in an embodiment of this application;
[0023] Figure 2 This is a flowchart of the blockchain matching process;
[0024] Figure 3 This is a diagram illustrating the range of node vector encoding.
[0025] Figure 4 It is a schematic diagram of the node vector encoding result;
[0026] Figure 5 This is a flowchart of the difference node location process;
[0027] Figure 6 This is a schematic diagram of differential node positioning;
[0028] Figure 7 This is a flowchart illustrating the determination of the difference value item and its path, provided in an embodiment of this application.
[0029] Figure 8 This is a diagram illustrating the traversal results of the block header;
[0030] Figure 9 This is a diagram showing the comparison between the local Merkle tree and the on-chain Merkle tree;
[0031] Figure 10 This is a structural block diagram of a blockchain-based value verification device provided in an embodiment of this application;
[0032] Figure 11 This is a schematic diagram of an electronic device structure provided in an embodiment of this application. Detailed Implementation
[0033] The present application will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0034] Figure 1 This is a flowchart of a blockchain-based value verification method provided in an embodiment of this application. The method can be executed by a blockchain-based value verification device, which can be implemented by software and / or hardware and can be configured in electronic devices such as computers.
[0035] like Figure 1 As shown, the method provided in this application embodiment may include the following steps:
[0036] S110: Obtain the local setting file currently running on the protection device, and determine the global hash value of the local setting file.
[0037] In this embodiment, the local value file currently running in the protection device is the value file to be verified. The global hash value of the local value file can be calculated from its contents. The local value file can be an XML file, which has structured characteristics. The global hash value of the local value file can be denoted as XML_Hash_L.
[0038] S120: Determine the hash value of the on-chain value file and use it as the base hash value.
[0039] In this embodiment, the on-chain value file can be a value file on the blockchain, which can serve as the base file for the local value file. The block header on the blockchain may include the on-chain value file ID, the Merkle root of the on-chain value file, and the on-chain protection device number matrix Sp. The block header may also include the hash value of the previous block, the block sequence number, the timestamp, the substation number matrix SG, the node reliability matrix R, the address of the substation node that generated this block, the number matrix N of the three types of nodes, a random number, and a unified network difficulty value.
[0040] In one implementation, optionally, determining the hash value of the on-chain value file includes: traversing the block headers of the blockchain in reverse order; determining the latest associated block in the blockchain corresponding to the local value file based on the on-chain protection device number matrix in the block header; and obtaining the hash value of the on-chain value file from a relational database based on the ID of the on-chain value file in the block header of the latest associated block. The traversal and matching process can be referenced from... Figure 2 Specifically, the blockchain block headers are traversed in reverse order. If the on-chain protection device number matrix in the block header is the same as the local protection device encoding matrix, the block corresponding to that block header is taken as the latest associated block. The on-chain fixed value file ID is obtained from the latest associated block. Based on the on-chain fixed value file ID, the hash value of the on-chain fixed value file is extracted from the relational database, which can be recorded as the XML_Hash field.
[0041] S130: If the global hash value and the base hash value are inconsistent, construct a local Merkle tree based on the local value file and determine the root of the local Merkle tree.
[0042] In this embodiment, if the global hash value of the local value file is the same as the hash value of the on-chain value file, it indicates that the local value file and the on-chain value file are identical, and the value verification in the local value file is complete. If the global hash value of the local value file and the hash value of the on-chain value file are different, it indicates that there is a difference between the local value file and the on-chain value file, and further verification of the local value file is required.
[0043] In this embodiment, when the global hash value of the local value file is inconsistent with the hash value of the on-chain value file, the cryptographic properties of Merkle trees can be used to map the content of the value file to a single hash value (Merkle tree root), constructing a Merkle tree. The differences in value are then confirmed by comparing the Merkle tree root, facilitating the subsequent location of the differing nodes. Therefore, when the global hash value of the local value file is inconsistent with the hash value of the on-chain value file, it is necessary to construct a local Merkle tree based on the local value file and determine the local Merkle tree root.
[0044] In this embodiment, optionally, constructing a local Merkle tree based on the local value file includes:
[0045] The local value file is mapped to a hash check table containing node names, node vector codes, and node hash values. The node hash values in the hash check table are arranged in a top-down order, and two node hash values are grouped together to calculate the parent node hash value. The parent node hash value is used as the node hash value, and the steps of merging the parent node hash value in a top-down order and grouping two node hash values together are returned until a local Merkle tree root is generated, forming a local Merkle tree. In the case where the number of nodes is odd, the hash value of the last remaining node is merged with the hash value of the upper-level node separately.
[0046] Specifically, mapping the local value file into a hash verification table containing node names, node vector codes, and node hash values includes: removing redundant spaces and newlines from the local value file; calculating hash values using a hash function based on the start and end markers of non-leaf nodes in the local value file, and the content between the start and end markers, as the node hash values in the hash verification table; grouping the node hash values, the corresponding node names, and the corresponding node vector codes into a set, and arranging them in ascending order according to the start vector in the node vector codes to obtain the hash verification table. Table 1 shows the hash verification table of the local value file for line protection. As shown in Table 1, redundant spaces and newlines are removed from the XML format file, and the start and end markers of non-leaf nodes in the local value file, and the content between the start and end markers, are calculated using the SHA256 hash function to obtain hash values, which are then used as the node hash values in the hash verification table. In the hash verification table, the node hash value, the corresponding node vector code, and the corresponding node name are grouped together and sorted in ascending order according to the starting vector in the node vector code. This facilitates the subsequent construction of the local Merkle tree and prevents differences in the node order during the construction process. In Table 1, Node_Name is the node name, StartVec is the starting vector, EndVec is the ending vector, and Hash is the node hash value.
[0047] Table 1
[0048]
[0049] In this embodiment, optionally, the local value file can be vector-encoded according to the following rules to obtain the node vector encoding:
[0050] The node vector encoding of each node in the local value file includes a start vector and an end vector, wherein the tangent of the end vector is greater than the tangent of the start vector, thereby ensuring that the node can contain a certain spatial range.
[0051] For a node in the local value file, if the first node is a child node of the second node, the tangent of the starting vector of the first node is greater than the tangent of the starting vector of the second node, and the tangent of the ending vector of the first node is less than the tangent of the ending vector of the second node.
[0052] For a node in the local value file, if the target node has sibling nodes, the tangent of the target node's starting vector is greater than the tangent of the ending vector of the nearest preceding sibling node; the tangent of the target node's ending vector is less than the tangent of the ending vector of the nearest following sibling node.
[0053] The root node of the local value file starts at (n, 0); other nodes in the local value file are encoded by adding 1 to their ordinates; where n is an integer greater than 0. For convenience, n can be set to 1.
[0054] Therefore, by performing vector encoding according to the above rules, node vector encoding can be obtained. The node vector encoding includes a range that can be illustrated as follows: Figure 3 As shown, the node vector encoding result can be as follows: Figure 4 As shown.
[0055] The calculations for constructing the local Merkle tree and its root follow the same rules as the on-chain Merkle tree. The Hash field in the hash verification table (e.g., Table 1) is used to construct the local Merkle tree layer by layer, in pairs, from top to bottom. During construction, if the number of nodes is odd, the hash value of the last remaining node can be used as the hash value of the corresponding upper-level node. In the calculation of the upper-level node's hash value, hash values are then calculated by merging pairs until the local Merkle tree root is reached. The root node of the local Merkle tree can be the local Merkle tree root itself. During the construction of the local Merkle tree, the Hash field in the hash verification table can be input into the algorithm program, which outputs the local Merkle tree and its root. The local Merkle tree root can be denoted as Root_local.
[0056] S140: Determine the Merkle root of the on-chain value file and use it as the reference root.
[0057] In this embodiment, the calculation process of the Merkle tree of the on-chain value file is the same as that of the local value file, and the Merkle tree root of the on-chain value file is stored in the block header of the blockchain.
[0058] In this embodiment, optionally, determining the Merkle root of the on-chain value file includes: extracting the Merkle root of the on-chain value file from the block header of the latest associated block. The Merkle tree of the on-chain value file can be denoted as the Root_Chain field.
[0059] S150: If the local Merkle tree root and the reference tree root are inconsistent, obtain the on-chain Merkle tree and compare the node hash values in the local Merkle tree and the on-chain Merkle tree using a recursive hierarchical algorithm, and determine the nodes with different hash values based on the comparison results.
[0060] In this embodiment, the local Merkle tree is compared with the reference tree root. By comparing the two, the values in the local value file are verified and the differences in value items are identified. Specifically, the Root_Chain field in the most relevant block is compared with the local Merkle tree root. If the local Merkle tree root is inconsistent with the reference tree root, it is confirmed that the values in the local value file currently running by the protection device differ from the reference values. The process of locating the difference in value items then begins, and the difference in value items is accurately located in subsequent processes by comparing the node hash values in the Merkle tree.
[0061] In this embodiment, when the local Merkle tree root is inconsistent with the baseline tree root (Root_local ≠ Root_chain), hierarchical hash value comparison and metadata association are required to specifically locate the differing attribute items and verify their consistency. By locating the nodes in the differing Merkle tree, the inconsistent node hash values are confirmed to match the nodes in the local attribute file, ultimately determining the inconsistent attribute items.
[0062] In this embodiment, a recursive hierarchical algorithm can be used to compare the node hash values in the local Merkle tree and the on-chain Merkle tree. The on-chain Merkle tree acquisition process can be as follows: after determining the most relevant block using the on-chain protection device number matrix, the on-chain Merkle tree can be obtained from the block body of the most relevant block. The construction process of the on-chain Merkle tree is the same as that of the local Merkle tree. Optionally, comparing the node hash values in the local Merkle tree and the on-chain Merkle tree using a recursive hierarchical algorithm, and determining the differing nodes based on the comparison results, includes: starting from the root node, comparing the node hash values in the local Merkle tree and the on-chain Merkle tree layer by layer; if the hash value of the current layer node in the local Merkle tree is inconsistent with the corresponding node hash value in the on-chain Merkle tree, recursively checking the child nodes of the current layer node until the bottom-level leaf differing node is located, which is taken as the differing node. The comparison results include inconsistent and consistent results between the local Merkle tree and the on-chain Merkle tree. Therefore, the leaf difference node at the lowest level of the local Merkle tree was found by comparing the hash values of nodes in the Merkle tree. The process for locating the difference node can be found by referring to... Figure 5 A schematic diagram of the differential node location can be found here. Figure 6 ,like Figure 6 As shown, during the comparison of node hash values between the local Merkle tree and the on-chain Merkle tree, the hash value of the leaf node with the difference is Hash3'.
[0063] S160: Based on the difference node, determine the difference value items between the local value file and the on-chain value file, and the path of the difference value items in the local value file; wherein, the on-chain value file is a value file on the blockchain; the on-chain Merkle tree is a Merkle tree on the blockchain; and the on-chain value file is the base file of the local value file.
[0064] In one implementation, local value files and on-chain value files can be mapped to corresponding vector encoding tables. Differential value items can be determined by associating a hash verification table and the local vector encoding table. Specifically, the corresponding node vector code is found through the hash verification table, the corresponding node in the local value file is found by associating it with the local vector encoding table, the child nodes of that node are found, and the row data in the local vector encoding table corresponding to that child node is compared with the corresponding row data in the on-chain vector encoding table to find the differential value item, thereby determining the path of the differential value item in the local value file. The differential value item includes the value name and the corresponding actual value.
[0065] Optionally, before determining the difference value items between the local value file and the on-chain value file based on the difference nodes, and the path of the difference value items in the local value file, the process may further include: mapping the local value file into a local vector encoding table containing node names, node vector codes, the hierarchy depth of the node, and the element values or attribute values corresponding to the node; the element values include the value name and the corresponding actual value, and the attribute values include information about the actual value. Attribute values may include, for example, units, data ranges, etc. The node vector code includes a start vector and an end vector; the process of mapping the local value file into a vector encoding table can be understood as mapping it into a relational data table, which includes node names, node vector codes, the hierarchy depth of the node, the element values or attribute values corresponding to the node, and may also include the ID of the local value file, i.e., a file ID in local XML format.
[0066] In one embodiment of this example, optionally, determining the difference value item between the local value file and the on-chain value file based on the difference node, and the path of the difference value item in the local value file, includes: determining the corresponding node name based on the node hash value of the difference node using the hash verification table; comparing the node content corresponding to the node name in the local value file with the node content corresponding to the node name in the on-chain value file to obtain the difference value item; and determining the path of the difference value item in the local value file based on its position in the local value file. Wherein, the local value file and the on-chain value file do not need to be mapped to corresponding vector encoding tables; they can be associated with hash verification tables. The corresponding node name is determined by the node hash value of the difference node; the node content corresponding to the node name in the local value file is compared with the node content corresponding to the node name in the on-chain value file to determine the difference value item with inconsistent node content; and the path of the difference value item in the local value file is obtained according to its hierarchical relationship within the local value file.
[0067] Therefore, the embodiments of this application ensure the authenticity of the benchmark data through the immutability of blockchain, and at the same time shorten the verification time of the set value by using the efficient verification mechanism of Merkle tree. The positioning accuracy of the difference node can reach the element level of XML format file, which significantly improves the intelligent operation and maintenance level of power system relay protection equipment.
[0068] In related technologies, traditional setting verification methods have the following technical problems: (1) Insufficient timeliness: manual item-by-item verification takes a long time and is difficult to meet the real-time requirements of high-frequency setting adjustments; (2) Low efficiency: manual comparison is easily affected by operational errors, especially in complex setting files (such as those containing thousands of attributes), the risk of missed detection or false detection increases significantly; (3) Chain risk: a single device setting error may trigger a chain reaction of protection malfunction or failure to operate, threatening the safety of the power grid.
[0069] The technical solution provided in this application compares the global hash value of the local value file with the hash value of the on-chain value file. If an inconsistency exists, a local Merkle tree is constructed based on the local value file, and the root of the local Merkle tree is determined. The root of the local Merkle tree is then compared with the root of the Merkle tree in the on-chain value file. If an inconsistency exists, the hash values of the nodes in the local Merkle tree and the on-chain Merkle tree are compared to determine the nodes with hash value differences. Based on these nodes, the difference value items between the local value file and the on-chain value file, as well as the path of these difference value items in the local value file, are determined. Thus, by utilizing the structured characteristics of the value file, the technical solution provided in this application can accurately locate difference value items, eliminate the need for manual verification of values, improve verification efficiency, meet the real-time requirements of value adjustment, effectively avoid chain reactions caused by value errors, and ensure power grid safety.
[0070] Figure 7 This is a flowchart illustrating the determination of difference values and their paths provided in embodiments of this application, such as... Figure 7 As shown, the method may include:
[0071] S710: Determine the corresponding node vector code based on the hash check table using the node hash value of the difference node.
[0072] In this embodiment, the node vector code corresponding to the node hash value of the different node can be found by querying the hash verification table, and the node name (Node_Name) can also be found. The node vector code includes the start vector (StartVec) and the end vector (EndVec).
[0073] S720: Determine the target node corresponding to the node vector encoding in the local vector encoding table.
[0074] In this embodiment, the node vector code corresponding to the node hash value of the different node can be found by querying the hash verification table, and the node name corresponding to the node vector code can be found by querying the local vector code table. The node corresponding to the node name is then used as the target node.
[0075] S730: Determine the child nodes of the target node based on the local vector encoding table.
[0076] In this embodiment, the hash check table is generated based on the non-leaf nodes and their contents in the local fixed-value file. It can also be understood that when the local fixed-value file is an XML file, the hash check table converts the non-leaf nodes in the XML file into a row of data. The local vector encoding table is generated based on each node and its contents in the local fixed-value file. It can also be understood that the local vector encoding table converts each node and its corresponding contents into a row of data. Therefore, the target node in the XML file has child nodes, and the local vector encoding table mapped from the XML file also contains the child nodes of the target node.
[0077] In this embodiment, optionally, determining the child nodes of the target node based on the vector encoding table includes: determining the child nodes of the target node based on the following formula:
[0078]
[0079] Where P is the target node, i.e., the parent node, and C is the child node; Deep is the layer depth of the node, StartVec is the starting vector, and EndVec is the ending vector. Thus, the starting vectors, ending vectors, and layer depths of the target node and other nodes can be determined through local vector encoding, and the child nodes of the target node can be determined using the above formula.
[0080] S740: Compare the row data corresponding to the child node in the local vector encoding table with the row data corresponding to the on-chain vector encoding table, and determine the inconsistent value item data as the difference value item, and determine the path of the difference value item in the local value file based on the vector encoding rules; wherein, the difference value item includes the value name and the corresponding actual value.
[0081] In this embodiment, since the local vector encoding table converts each node and its corresponding content into a row of data, the row data corresponding to the child node in the local vector encoding table can be compared with the corresponding row data in the on-chain vector encoding table to determine the inconsistent value items as difference value items. Based on the node vector encoding corresponding to the difference value items, the specific path of the difference value items in the XML format file is determined by the vector encoding rules.
[0082] Therefore, by associating the hash verification table and the local vector encoding table to obtain the difference value items and their paths, the workload of comparison can be reduced and the efficiency of value verification can be improved.
[0083] The verification process for the technical solutions provided in this application can be based on the following steps:
[0084] (1) First, performance testing of the fast verification method can be conducted in scenarios where there are no differences in the fixed values. Following a certain consensus mechanism, 10 rounds of consensus are performed, and 10 fixed value files containing "Line Protection_1.xml" are stored on the blockchain as on-chain fixed value files. After calculating the Hash field of the local fixed value file at the local protection device, it is compared with the corresponding XML_Hash field stored in the on-chain relational database to achieve fast verification of the fixed values. The results of the fixed value file consistency verification can be found in Table 2.
[0085] Table 2
[0086]
[0087] As shown in Table 2, the test results demonstrate that, assuming the local and on-chain value files are identical, the verification of protection values is extremely rapid. This is because it only requires hash value calculation and comparison of the files. The average verification time for a single local value file is 42.67 ms, the average hash calculation time is 1.56 ms per file, and the average time for block retrieval and database query is 41.11 ms per query. Compared to the timescales of hours or even days required for manual verification methods, this approach offers significant advantages.
[0088] (2) To verify the performance of the method provided in this application embodiment for quickly locating the difference value, the "protection setting: change amount starting current setting" in the second group of "line protection_1.xml" (file size is 23.6KB, total number of elements is 427, number of attributes is 1117, maximum depth is 5) is modified from "0.470" to "0.500" to simulate the scenario where the running setting is inconsistent with the benchmark setting, thereby triggering the difference value location and verification process, and testing the ability of the setting verification method to locate the difference value.
[0089] Then follow Figure 2 The method described above searches in reverse order for the corresponding block in the local value file, and selects it as the latest associated block. The block header is as follows: Figure 8 As shown.
[0090] After locating the latest associated block, the block body is a Merkle tree constructed from the on-chain value file. The XML_ID field provides the hash verification table mapped to the value file stored by the verification storage node. After obtaining the hash value of the on-chain node, it can be used as the base data for subsequent verification and checking of the value.
[0091] For a comparison between the local Merkle tree and the on-chain Merkle tree corresponding to the on-chain block, please refer to... Figure 9 . Figure 9The document displays the detailed information of the first four layers of two Merkle trees from top to bottom. It can be seen that some hash values are different. By tracing the path, the bottom layer can be determined, which is the difference node stored in the hash verification table.
[0092] After identifying the differing hash fields in the hash verification table, the parent-child node relationship is determined using vector encoding rules, and the difference values and corresponding paths are ultimately provided for rapid location. The final verification results are shown in Tables 3 and 4.
[0093] Table 3. Results of Fixed Value Data Verification
[0094]
[0095] Table 4. Results of Fixed Value Data Verification
[0096]
[0097] As shown in the table above, the blockchain-based setting verification method provided in this application embodiment can achieve rapid verification between the running setting value and the on-chain benchmark setting value. By comparing the Merkle tree structure and the path formation of the difference node, inconsistent difference setting value items can be accurately located. The verification and value location time consumed by a single difference node is less, which improves the efficiency of relay protection setting value management.
[0098] Based on the above embodiments, the method provided in this application may further include: modifying the difference value items in the local setting file. Therefore, by modifying the difference value items, an accurate local setting file can be obtained, ensuring that the operation of the protection device meets the requirements. The method provided in this application may also include displaying the difference value items before and after modification, and may further include storing the data in the block header for subsequent querying.
[0099] It should be noted that in the method provided in this application embodiment, when traversing the blockchain in reverse order, it can be implemented based on the light node protocol. The verification and validation can be completed by downloading the data in the block header, which can reduce the network bandwidth usage.
[0100] Based on the above embodiments, the method provided in this application may further include: displaying the difference nodes in the local Merkle tree and the paths of the difference value items in the local value file, and marking and displaying the difference value items in the local value file. Thus, by displaying the difference nodes in the local Merkle tree, the location of the difference can be quickly and easily understood; by displaying the paths of the difference value items in the local value file and marking and displaying the difference value items, the specific details of the difference value items can be easily understood by the user.
[0101] Figure 10This is a structural block diagram of a blockchain-based value verification device provided in an embodiment of this application, such as... Figure 10 As shown, the device includes:
[0102] The first determining module 101 is used to obtain the local setting file of the protection device currently in operation and determine the global hash value of the local setting file;
[0103] The second determining module 102 is used to determine the hash value of the on-chain value file and use it as the base hash value;
[0104] The third determining module 103 is used to construct a local Merkle tree based on the local value file and determine the root of the local Merkle tree if the global hash value and the base hash value are inconsistent.
[0105] The reference tree root determination module 104 is used to determine the Merkle tree root of the on-chain value file and use it as the reference tree root;
[0106] The difference node determination module 105 is used to obtain the on-chain Merkle tree and compare the node hash values in the local Merkle tree and the on-chain Merkle tree through a recursive hierarchical algorithm if the local Merkle tree root and the reference tree root are inconsistent, and determine the difference nodes in the hash values based on the comparison results.
[0107] The difference value item determination module 106 is used to determine the difference value items between the local value file and the on-chain value file and the path of the difference value items in the local value file based on the difference node; wherein, the on-chain value file is a value file on the blockchain; the on-chain Merkle tree is a Merkle tree on the blockchain; and the on-chain value file is the base file of the local value file.
[0108] In one optional embodiment, the hash values of nodes in the local Merkle tree and the on-chain Merkle tree are compared using a recursive hierarchical algorithm, and the nodes with differing hash values are determined based on the comparison results, including:
[0109] Starting from the root node, compare the node hash values in the local Merkle tree and the chain Merkle tree layer by layer;
[0110] If the hash value of the current layer node in the local Merkle tree is inconsistent with the hash value of the corresponding node in the chain Merkle tree, the child nodes of the current layer node are recursively checked until the leaf difference node at the bottom layer is located, which is taken as the difference node.
[0111] In an optional embodiment, constructing a local Merkle tree based on the local value file includes:
[0112] The local value file is mapped to a hash check table containing node names, node vector codes, and node hash values;
[0113] The hash values of the nodes in the hash verification table are arranged in a top-to-bottom order, and two node hash values are grouped together to calculate the hash value of the parent node.
[0114] Using the parent node hash value as the node hash value, the steps of calculating the parent node hash value are returned in a top-down order, with two node hash values grouped together, until a local Merkle tree root is generated, forming a local Merkle tree; wherein, when the number of nodes is odd, the hash value of the last remaining node is calculated separately by merging it with the hash value of the upper-level node.
[0115] In an optional embodiment, mapping the local value file to a hash check table containing node names, node vector codes, and node hash values includes:
[0116] The local value file is processed to remove redundant spaces and newline characters;
[0117] Based on the start and end markers of the non-leaf nodes in the local value file, and the content between the start and end markers, a hash value is calculated using a hash function and used as the node hash value in the hash verification table.
[0118] The node hash value, the node name corresponding to the node hash value, and the corresponding node vector code are grouped together and sorted in ascending order according to the starting vector in the node vector code to obtain a hash verification table; wherein, the local value file is an XML format file with structured characteristics.
[0119] In an optional embodiment, the apparatus further includes a vector encoding module, configured to perform vector encoding on the local value file according to the following rules to obtain node vector encoding:
[0120] The node vector encoding of each node in the local value file includes a start vector and an end vector, wherein the tangent value of the end vector is greater than the tangent value of the start vector;
[0121] For a node in the local value file, if the first node is a child node of the second node, the tangent of the starting vector of the first node is greater than the tangent of the starting vector of the second node, and the tangent of the ending vector of the first node is less than the tangent of the ending vector of the second node.
[0122] For a node in the local value file, if the target node has sibling nodes, the tangent of the target node's starting vector is greater than the tangent of the ending vector of the nearest preceding sibling node; the tangent of the target node's ending vector is less than the tangent of the ending vector of the nearest following sibling node.
[0123] The root node of the local value file has an initial vector of (n, 0); other nodes in the local value file are encoded by adding 1 to their ordinates; where n is an integer greater than 0.
[0124] In one optional embodiment, the block header of the blockchain includes an on-chain value file ID, a Merkle root of the on-chain value file, and an on-chain protection device number matrix.
[0125] In an optional embodiment, determining the hash value of the on-chain value file includes:
[0126] Traverse the block headers of the blockchain in reverse order, and determine the latest associated block in the blockchain corresponding to the local value file based on the on-chain protection device number matrix in the block header;
[0127] Based on the ID of the on-chain value file in the block header of the latest associated block, the hash value of the on-chain value file is obtained from the relational database;
[0128] Determining the Merkle root of the on-chain value file includes:
[0129] Extract the Merkle root of the on-chain value file from the block header of the latest associated block.
[0130] In an optional embodiment, determining the difference value items between the local value file and the on-chain value file based on the difference node, and the path of the difference value items in the local value file, includes:
[0131] The corresponding node name is determined by the hash verification table based on the node hash value of the difference node.
[0132] The node content corresponding to the node name in the local value file is compared with the node content corresponding to the node name in the on-chain value file to obtain the difference value item;
[0133] The path of the difference value item in the local value file is determined based on its position in the local value file.
[0134] In an optional embodiment, the apparatus further includes: a local vector encoding table generation module, configured to:
[0135] The local value file is mapped to a local vector encoding table containing node name, node vector code, node level depth, and element value or attribute value corresponding to the node; the element value includes the value name and the corresponding actual value, and the attribute value includes information about the actual value.
[0136] In an optional embodiment, determining the difference value items between the local value file and the on-chain value file based on the difference node, and the path of the difference value items in the local value file, includes:
[0137] The corresponding node vector code is determined by the node hash value of the difference node according to the hash verification table;
[0138] Determine the target node corresponding to the node vector code in the local vector encoding table;
[0139] The child nodes of the target node are determined based on the local vector encoding table;
[0140] The row data corresponding to the child node in the local vector encoding table is compared with the row data corresponding to the on-chain vector encoding table, and inconsistent value items are identified as the difference value items. The path of the difference value items in the local value file is determined based on the vector encoding rules. The difference value items include the value name and the corresponding actual value.
[0141] In an optional embodiment, determining the child nodes of the target node based on the vector encoding table includes:
[0142] The child nodes of the target node are determined based on the following formula:
[0143]
[0144] Wherein, P is the target node, i.e., the parent node, and C is the child node; Deep is the layer depth of the node, StartVec is the starting vector, and EndVec is the ending vector.
[0145] In an optional embodiment, the apparatus further includes a modification module for modifying the difference values in the local value file.
[0146] In an optional embodiment, the apparatus further includes a display module for displaying the difference nodes in the local Merkle tree and the paths of the difference values in the local value file, and for marking and displaying the difference values in the local value file.
[0147] like Figure 11As shown in the figure, this application provides an electronic device, including a processor 111, a communication interface 112, a memory 113, and a communication bus 114, wherein the processor 111, the communication interface 112, and the memory 113 communicate with each other through the communication bus 114.
[0148] Memory 113 is used to store computer programs;
[0149] In one embodiment of this application, when the processor 111 executes a program stored in the memory 113, it implements the method provided in any of the foregoing method embodiments, including:
[0150] Obtain the local setting file currently running on the protection device, and determine the global hash value of the local setting file;
[0151] Determine the hash value of the on-chain fixed-value file and use it as the base hash value;
[0152] If the global hash value and the base hash value are inconsistent, a local Merkle tree is constructed based on the local value file, and the root of the local Merkle tree is determined.
[0153] Determine the Merkle root of the on-chain value file and use it as the reference root;
[0154] If the local Merkle tree root and the benchmark tree root are inconsistent, obtain the on-chain Merkle tree and compare the node hash values in the local Merkle tree and the on-chain Merkle tree using a recursive hierarchical algorithm, and determine the nodes with different hash values based on the comparison results;
[0155] Based on the difference nodes, the difference values between the local value file and the on-chain value file are determined, as well as the path of the difference values in the local value file; wherein, the on-chain value file is a value file on the blockchain; the on-chain Merkle tree is a Merkle tree on the blockchain; and the on-chain value file is the base file of the local value file.
[0156] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the method provided in any of the foregoing method embodiments.
[0157] 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.
[0158] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented using software plus a general-purpose hardware platform, or of course, using hardware. Based on this understanding, the above technical solutions, in essence or the parts that contribute to the related technology, 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.
[0159] The above embodiments are merely illustrative examples and are not intended to limit the implementation. Those skilled in the art will recognize that other variations or modifications can be made based on the above description. It is neither necessary nor possible to exhaustively list all possible implementations. However, obvious variations or modifications derived therefrom are still within the scope of protection of this application.
Claims
1. A blockchain-based method for verifying fixed values, characterized in that, include: Obtain the local setting file currently running on the protection device, and determine the global hash value of the local setting file; Determine the hash value of the on-chain fixed-value file and use it as the base hash value; If the global hash value and the base hash value are inconsistent, a local Merkle tree is constructed based on the local value file, and the root of the local Merkle tree is determined. Determine the Merkle root of the on-chain value file and use it as the reference root; If the local Merkle tree root and the benchmark tree root are inconsistent, obtain the on-chain Merkle tree and compare the node hash values in the local Merkle tree and the on-chain Merkle tree using a recursive hierarchical algorithm, and determine the nodes with different hash values based on the comparison results; Based on the difference nodes, the difference values between the local value file and the on-chain value file are determined, as well as the path of the difference values in the local value file; wherein, the on-chain value file is a value file on the blockchain; the on-chain Merkle tree is a Merkle tree on the blockchain; and the on-chain value file is the base file of the local value file.
2. The method according to claim 1, characterized in that, The hash values of nodes in the local Merkle tree and the on-chain Merkle tree are compared using a recursive hierarchical algorithm. Based on the comparison results, nodes with differing hash values are identified, including: Starting from the root node, compare the node hash values in the local Merkle tree and the chain Merkle tree layer by layer; If the hash value of the current layer node in the local Merkle tree is inconsistent with the hash value of the corresponding node in the chain Merkle tree, the child nodes of the current layer node are recursively checked until the leaf difference node at the bottom layer is located, which is taken as the difference node.
3. The method according to claim 1, characterized in that, The construction of the local Merkle tree based on the local value file includes: The local value file is mapped to a hash check table containing node names, node vector codes, and node hash values; The hash values of the nodes in the hash verification table are arranged in a top-to-bottom order, and two node hash values are grouped together to calculate the hash value of the parent node. Using the parent node hash value as the node hash value, the steps of calculating the parent node hash value are returned in a top-down order, with two node hash values grouped together, until a local Merkle tree root is generated, forming a local Merkle tree; wherein, when the number of nodes is odd, the hash value of the last remaining node is calculated separately by merging it with the hash value of the upper-level node.
4. The method according to claim 3, characterized in that, The step of mapping the local value file into a hash verification table containing node names, node vector codes, and node hash values includes: The local value file is processed to remove redundant spaces and newline characters; Based on the start and end markers of the non-leaf nodes in the local value file, and the content between the start and end markers, a hash value is calculated using a hash function and used as the node hash value in the hash verification table. The node hash value, the node name corresponding to the node hash value, and the corresponding node vector code are grouped together and sorted in ascending order according to the starting vector in the node vector code to obtain a hash verification table; wherein, the local value file is an XML format file with structured characteristics.
5. The method according to claim 4, characterized in that, Also includes: The local value file is vector-encoded according to the following rules to obtain the node vector encoding: The node vector encoding of each node in the local value file includes a start vector and an end vector, wherein the tangent value of the end vector is greater than the tangent value of the start vector; For a node in the local value file, if the first node is a child node of the second node, the tangent of the starting vector of the first node is greater than the tangent of the starting vector of the second node, and the tangent of the ending vector of the first node is less than the tangent of the ending vector of the second node. For a node in the local value file, if the target node has sibling nodes, the tangent of the target node's starting vector is greater than the tangent of the ending vector of the nearest preceding sibling node; the tangent of the target node's ending vector is less than the tangent of the ending vector of the nearest following sibling node. The root node of the local value file has an initial vector of (n, 0); other nodes in the local value file are encoded by adding 1 to their ordinates; where n is an integer greater than 0.
6. The method according to claim 1, characterized in that, The block header of the blockchain includes the on-chain value file ID, the Merkle root of the on-chain value file, and the on-chain protection device number matrix.
7. The method according to claim 6, characterized in that, The determination of the hash value of the on-chain fixed-value file includes: Traverse the block headers of the blockchain in reverse order, and determine the latest associated block in the blockchain corresponding to the local value file based on the on-chain protection device number matrix in the block header; Based on the ID of the on-chain value file in the block header of the latest associated block, the hash value of the on-chain value file is obtained from the relational database; Determining the Merkle root of the on-chain value file includes: Extract the Merkle root of the on-chain value file from the block header of the latest associated block.
8. The method according to claim 3, characterized in that, The step of determining the difference value items between the local value file and the on-chain value file based on the difference node, and the path of the difference value items in the local value file, includes: The corresponding node name is determined by the hash verification table based on the node hash value of the difference node. The node content corresponding to the node name in the local value file is compared with the node content corresponding to the node name in the on-chain value file to obtain the difference value item; The path of the difference value item in the local value file is determined based on its position in the local value file.
9. The method according to claim 5, characterized in that, Also includes: The local value file is mapped to a local vector encoding table containing node name, node vector code, node level depth, and element value or attribute value corresponding to the node; the element value includes the value name and the corresponding actual value, and the attribute value includes information about the actual value.
10. The method according to claim 9, characterized in that, The step of determining the difference value items between the local value file and the on-chain value file based on the difference node, and the path of the difference value items in the local value file, includes: The corresponding node vector code is determined by the node hash value of the difference node according to the hash verification table; Determine the target node corresponding to the node vector code in the local vector encoding table; The child nodes of the target node are determined based on the local vector encoding table; The row data corresponding to the child node in the local vector encoding table is compared with the row data corresponding to the on-chain vector encoding table, and inconsistent value items are identified as the difference value items. The path of the difference value items in the local value file is determined based on the vector encoding rules. The difference value items include the value name and the corresponding actual value.
11. The method according to claim 9, characterized in that, The step of determining the child nodes of the target node based on the vector encoding table includes: The child nodes of the target node are determined based on the following formula: Wherein, P is the target node, i.e., the parent node, and C is the child node; Deep is the layer depth of the node, StartVec is the starting vector, and EndVec is the ending vector.
12. The method according to claim 1, characterized in that, Also includes: Modify the difference settings in the local setting file.
13. The method according to claim 1, characterized in that, Also includes: Display the difference nodes in the local Merkle tree and the paths of the difference values in the local value file, and mark and display the difference values in the local value file.
14. A blockchain-based value verification device, characterized in that, include: The first determining module is used to obtain the local setting file of the protection device currently in operation and determine the global hash value of the local setting file; The second determining module is used to determine the hash value of the on-chain value file and use it as the base hash value; The third determining module is used to construct a local Merkle tree based on the local value file and determine the root of the local Merkle tree if the global hash value and the base hash value are inconsistent. The baseline root determination module is used to determine the Merkle root of the on-chain value file and use it as the baseline root. The difference node determination module is used to obtain the on-chain Merkle tree and compare the node hash values in the local Merkle tree and the on-chain Merkle tree through a recursive hierarchical algorithm if the local Merkle tree root and the benchmark tree root are inconsistent, and determine the difference nodes in the hash values based on the comparison results. The difference value item determination module is used to determine the difference value items between the local value file and the on-chain value file, as well as the path of the difference value items in the local value file, based on the difference node; wherein, the on-chain value file is a value file on the blockchain; the on-chain Merkle tree is a Merkle tree on the blockchain; and the on-chain value file is the base file of the local value file.
15. An electronic device, characterized in that, It includes a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the method as described in any one of claims 1-13.
16. A computer-readable storage medium, characterized in that, It stores a computer program that, when executed in a computer, causes the computer to perform the method described in any one of claims 1-13.
