Multi-node hash chain consistency verification method and system for traceability data
Patent Information
- Application Number
- CN202611086210.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-21
- Publication Date
- 2026-10-30
AI Technical Summary
[0003]本申请提供了用于追溯数据的多节点哈希链式一致性校验方法及系统,其关键在于,解决了现有追溯数据存储依赖中心化或单点数据库,历史数据易被静默篡改、删除,导致追溯数据完整性和可信度不足的技术问题,达到了通过哈希链和多副节点独立重算比对实现追溯数据篡改可检测、节点间一致性可验证,提升追溯数据不可篡改性和可靠性的技术效果
首先从数据库中获取经过链式结构组织的最新追溯数据。随后,对该数据中的关键字段进行哈希运算,将生成的数据哈希值写入主节点,并在数据块头部保存前序哈希值和空间邻居哈希值,以建立时间链路和空间关联。之后,将同一数据及其哈希结果同步写入至少两个副节点,由各副节点独立重新计算哈希值,并与主节点提供的哈希结果进行一致性比对。如果比对一致,则说明主副节点数据一致并返回确认成功,如果比对不一致,则说明可能存在写入异常或数据被篡改,立即返回异常告警,从而实现追溯数据的链式防篡改存储、多节点一致性校验及异常数据快速检测,提高追溯数据的完整性、可靠性及可信度。
Smart Images

Figure CN123011868A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data security technology, specifically to a multi-node hash chain consistency verification method and system for tracing data. Background Technology
[0002] Currently, product traceability systems generally use centralized relational databases to record every status change. For example, corresponding change records are generated at each stage of a product's lifecycle, from production and outbound shipments to transportation and warehousing. These systems face numerous technical vulnerabilities during operation: because all records are concentrated on a single database node, administrators or internal personnel with write permissions can perform modifications or deletions without leaving obvious traces. Furthermore, the database's own logs may be synchronously deleted, making tampering difficult to detect in a timely manner. In addition, existing traceability solutions lack multi-node redundancy backup and consistency verification mechanisms. If the master node experiences storage failure or suffers a malicious attack, traceability data may be permanently lost, and anomalies cannot be identified through comparison between different nodes. More importantly, existing systems have not established proactive verification processes for the integrity of historical records. Problems are usually only exposed when users or auditors accidentally discover data inconsistencies. This passive response model severely weakens the evidentiary value of regulatory audits, leading to delayed anomaly detection and insufficient evidence chain integrity. Summary of the Invention
[0003] This application provides a multi-node hash chain consistency verification method and system for traceability data. Its key feature is that it solves the technical problem that existing traceability data storage relies on centralized or single-point databases, and historical data is easily tampered with or deleted silently, resulting in insufficient integrity and reliability of traceability data. It achieves the technical effect of making traceability data tampering detectable and inter-node consistency verifiable through hash chain and independent recalculation comparison of multiple sub-nodes, thereby improving the immutability and reliability of traceability data.
[0004] A first aspect of this application provides a multi-node hash chain consistency verification method for tracing data, the method comprising: The system reads the latest data sequence from the database, where the latest data sequence is preprocessed using a chained data structure. It then performs hash calculations on the data fields of the latest data sequence, obtains the hash calculation results, and writes them to the master node within the corresponding data block. The data block header stores the previous hash value and spatial neighbor hash values, and the master node stores the data hash value. The system then writes the latest data sequence and hash calculation results to the slave nodes within the corresponding data block. Each slave node receives a consistency confirmation request from the master node, independently performs data hash value calculation, and compares it with the hash calculation results to determine the comparison result. The system requires at least two slave nodes. If the comparison result is consistent, a confirmation success is returned; otherwise, an exception alarm is returned.
[0005] A second aspect of this application provides a multi-node hash chain consistency verification system for tracing data, the system comprising: Data Reading Module: Reads the latest data sequence from the database, wherein the latest data sequence is preprocessed using a chained data structure; Hash Calculation Module: Performs hash calculation on the data fields of the latest data sequence, obtains the hash calculation result, and writes it to the master node in the corresponding data block, wherein the data block header stores the previous hash value and the spatial neighbor hash value, and the master node stores the data hash value; Hash Comparison Module: Writes the latest data sequence and hash calculation result to the slave nodes in the corresponding data block, each slave node receives a consistency confirmation request from the master node, independently performs data hash value calculation, and compares it with the hash calculation result to determine the comparison result, wherein the number of slave nodes is at least two; Comparison Result Return Module: If the comparison result is consistent, it returns a confirmation success; if the comparison result is inconsistent, it returns an exception alarm.
[0006] One or more technical solutions provided in this application have at least the following technical effects or advantages: First, the latest traceability data, organized in a chain structure, is retrieved from the database. Then, key fields in this data are hashed, and the resulting hash value is written to the master node. The preceding hash value and spatial neighbor hash values are stored in the data block header to establish temporal and spatial associations. Next, the same data and its hash result are synchronously written to at least two slave nodes. Each slave node independently recalculates its hash value and compares it with the hash result provided by the master node. If the comparison matches, it indicates that the data on the master and slave nodes are consistent, and a confirmation of success is returned. If the comparison does not match, it indicates a possible write anomaly or data tampering, and an anomaly alarm is immediately returned. This achieves chain-based tamper-proof storage of traceability data, multi-node consistency verification, and rapid detection of abnormal data, improving the integrity, reliability, and trustworthiness of traceability data. Attached Figure Description
[0007] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0008] Figure 1 This is a schematic diagram of a multi-node hash chain consistency verification method for tracing data provided in an embodiment of this application.
[0009] Figure 2 This is a schematic diagram illustrating the convergence of topological hierarchical localization steps provided in an embodiment of this application.
[0010] Figure 3 This is a schematic diagram of the hash consistency matrix of the primary and secondary nodes provided in an embodiment of this application.
[0011] Figure 4 This is a schematic diagram of a multi-node hash chain consistency verification system for tracing data, provided in an embodiment of this application.
[0012] Figure labeling: Data reading module 11, hash calculation module 12, hash comparison module 13, comparison result return module 14. Detailed Implementation
[0013] To further illustrate the technical means and effects of the present invention in achieving its intended purpose, the following detailed description of the specific implementation methods, structures, features, and effects of the present invention, in conjunction with the accompanying drawings and preferred embodiments, is provided below.
[0014] Example 1, as Figure 1 As shown, this application provides a multi-node hash chain consistency verification method for tracing data, wherein the method includes: The latest data sequence is read from the database, wherein the latest data sequence is preprocessed using a chained data structure.
[0015] In this embodiment, upon receiving a request to write traceability data for a product, the system first accesses the traceability database using the product's unique identifier as the retrieval basis, and reads all valid traceability records already generated for that product within the database transaction. After reading, the traceability records are arranged according to their order of creation, and the arranged set of records is determined as the latest data sequence. For this latest data sequence, each record is no longer stored as independent data, but rather organized according to a chained data structure. Specifically, the first record is set as the starting data block of the chained structure, and its preceding hash information is written to a preset initial value. Starting from the second record, the hash value of the previous data block is read sequentially, and this hash value is written into the current data block as the preceding association information, so that each data block can point to its preceding data block. In this way, any traceability record not only contains its own business data content, but also contains the hash association relationship with the previous traceability record. After preprocessing, a latest data sequence is obtained, which is connected sequentially in chronological order. Each data block in this sequence has a definite order and a definite preorder reference relationship, which provides the basis for subsequent hash calculation of the current data block, writing to the master node, and performing consistency verification between the master and slave nodes. If any historical data is modified, its corresponding hash value and the preorder association relationship of subsequent data blocks will change, which makes it easier for the system to detect anomalies in the subsequent verification process and avoid inconsistent hash verification results due to disordered record order.
[0016] The data fields of the latest data sequence are hashed to obtain the hash calculation result and written to the master node in the corresponding data block. The data block header stores the previous hash value and the spatial neighbor hash value, and the master node stores the data hash value.
[0017] In one embodiment, after obtaining the latest data sequence after chained preprocessing, hash write operations are performed block by block according to the order of data blocks in the data sequence. For the current data block to be written, the business data content describing the traceability facts in the data block is read, and the content of each field is converted into uniform UTF-8 byte data according to the preset field order. A fixed-length identifier is added before each field content to indicate the length of the corresponding byte data. Then, the byte data corresponding to all fields are concatenated in sequence to form the byte sequence to be hashed for the current data block. Subsequently, a preset hash algorithm, such as SHA-256, is called to calculate the hash byte sequence to be hashed, resulting in a data hash value of 64 hexadecimal characters, which is determined as the hash calculation result. Then, the header information of the current data block is generated. If the current data block is the first data block in the latest data sequence, the preceding hash value is set to 64 zero characters; if the current data block is not the first data block, the data hash value generated by the previous data block is read and written into the header of the current data block as the preceding hash value. For spatial neighbor hash values, a fixed-dimensional semantic feature vector is generated based on the product batch number, process node number, etc., of the current data block. The vector distance between the current data block and the previously written historical data blocks is calculated, and the three historical data blocks with the smallest distance are selected as spatial neighbor data blocks. The data hash values of these three spatial neighbor data blocks are then read in ascending order of distance, concatenated, and hashed again to obtain the spatial neighbor hash value. When there are fewer than three historical data blocks, missing positions are padded with 64 zero characters before being included in the calculation. After the above processing, the preceding hash value and spatial neighbor hash value are written to the header area of the current data block, and the current data block's data hash value is written to the hash storage area of the corresponding master node. Before the master node database transaction is committed, it is verified that both the header hash information and the data hash value are not empty. After successful verification, the master node commits the write transaction, ensuring that the current data block simultaneously possesses a time-precedence reference relationship, a spatial neighbor reference relationship, and its own data hash identifier. This provides a directly comparable hash basis for subsequent slave node consistency confirmation and full-chain integrity verification.
[0018] Furthermore, the master node written within the corresponding data block includes: For the latest data sequence, determine the data content and multidimensional semantic feature vector; based on the data content, obtain the data hash value through hash calculation; write the data hash value to the master node; when the master node successfully writes, the master node pushes the data content and hash calculation result to the slave node and generates a consistency confirmation request.
[0019] Preferably, for the latest data sequence after chain preprocessing, the current data block is processed sequentially according to the generation order of the data blocks. First, the actual business data content used for traceability is extracted from the current data block, including the product batch number, process node number, data generation timestamp, data type, operation node type, and state transition type corresponding to the traceability record. Among them, the product batch number is used to indicate the product batch to which the data belongs; the process node number is used to indicate the specific node in the preset production or circulation process in which the data is generated; the data generation timestamp is used to indicate the generation time of the data; the data type is used to indicate that the data belongs to a fixed type among production record, warehousing record, transportation record, or acceptance record; the operation node type is used to indicate the business role of the data generation node; and the state transition type is used to indicate the state change of the traceability object in this record. The system uses the above fields as the data content of the current data block, and generates a multi-dimensional semantic feature vector according to preset semantic embedding rules. Specifically, it performs hashing and normalization on the product batch number to obtain the batch feature value; it converts the process node number into a node sequence number according to a preset process sequence table and normalizes it to obtain the process node feature value; it converts the data generation timestamp into a time interval relative to the time of the first record of the batch and normalizes it to obtain the time feature value; it converts the data type, operation node type, and state transition type into fixed-length semantic encoding vectors through a preset encoding table, and then concatenates the batch feature value, process node feature value, time feature value, and each semantic encoding vector in a fixed order to obtain the multi-dimensional semantic feature vector of the current data block.
[0020] Subsequently, the data content of the current data block is serialized according to the preset field order. That is, each field is converted into byte data with a unified character encoding, and the length identifier of each field is written before the byte data of each field. Then, the byte data of each field is concatenated to form the data to be hashed. Next, the preset hash algorithm is called to calculate the data to be hashed. Taking SHA-256 as an example, the data to be hashed is grouped into 512-bit groups. Data with less than 512 bits at the end is padded and the original data length is appended. Then, eight 32-bit hash state values are initialized. Each 512-bit data group is expanded to generate 64 32-bit message words. Combined with preset constants, 64 rounds of compression operations are performed. In each round of operation, the intermediate hash state is updated through circular right shift, logical selection, logical majority, and modulo addition operations. After all data groups are processed, the final eight 32-bit hash state values are concatenated to obtain a 64-bit hexadecimal string data hash value, which is determined as the hash calculation result of the current data block. After hash calculation, the current data block's data content, multidimensional semantic feature vector, preceding hash value, spatial neighbor hash value, and data hash value are written to the master node in the master node database transaction. The data content is used to restore and trace records; the multidimensional semantic feature vector is used to subsequently determine spatial neighbor relationships and topological affiliation; and the data hash value represents the integrity of the current data block's content. Upon successful writing by the master node, a consistency confirmation request uniquely corresponding to the current data block is generated. This request includes at least the current data block identifier, data content, data hash value, master node write time, and request sequence number. The master node then synchronously pushes the data content and hash calculation result to each slave node, enabling each slave node to independently recalculate the hash value based on the received data content and perform consistency confirmation with the data hash value pushed by the master node. This improves the anti-tampering capability of the data writing process and the reliability of inter-node consistency verification.
[0021] Furthermore, after determining the multidimensional semantic feature vector, the following steps are included: Determine the topological coordinates of the data block in the multidimensional feature space based on the multidimensional semantic feature vector; establish a link between the data block and the previous block according to the temporal sequence, and determine the preceding hash value; based on the topological coordinates of the data block, establish spatial neighbor links with multiple historical data blocks in the adjacent space based on the multidimensional semantic feature vector, and establish spatial neighbor hash values based on cross-hash references; write the preceding hash value and the spatial neighbor hash value into the data block.
[0022] Optionally, after the data content extraction and multidimensional semantic feature vector generation of the current data block are completed, the feature values of each dimension in the multidimensional semantic feature vector are normalized to between 0 and 1, and then arranged into a vector sequence according to a preset dimensional order. Subsequently, the vector sequence is coordinate-processed with a preset grid precision; that is, the normalized feature value of each dimension is multiplied by a preset factor and rounded down, such as by 10000, to obtain the integer coordinate value of that dimension. Then, the integer coordinate values of all dimensions are concatenated in sequence to form the data block topological coordinates of the current data block in the multidimensional feature space. After the topological coordinates are determined, a temporal link is established based on the arrangement order of the current data block in the latest data sequence. Specifically, the data hash value of the previous data block corresponding to the same traceable object is read first, and this data hash value is determined as the preceding hash value of the current data block. When the current data block is the first data block of the traceable object, the preceding hash value is set to 64 zero characters to identify the starting position of the chain structure. Subsequently, based on the topological coordinates of the current data block, historical data blocks within the adjacent grid range of the current topological coordinates are retrieved from the historical data blocks already written to the master node. The Euclidean distance between the multidimensional semantic feature vector of the current data block and the multidimensional semantic feature vectors of each historical data block is calculated. Three historical data blocks are then selected as spatial neighbor data blocks in ascending order of Euclidean distance; if the distances are the same, the order in which the historical data blocks were generated determines their priority. For each selected spatial neighbor data block, its data block identifier and data hash value are read. The current data block identifier, spatial neighbor data block identifier, and spatial neighbor data block data hash value are then concatenated in a preset order to form a spatial cross-reference record. Next, the three spatial cross-reference records are concatenated sequentially according to their proximity, and a preset hash algorithm is used to perform hash calculation on the concatenation result to obtain the spatial neighbor hash value. If there are fewer than three historical data blocks, the missing spatial cross-reference records participate in the concatenation with a preset empty reference value, ensuring that the spatial neighbor hash value is always generated according to a fixed rule. Finally, the determined preceding hash value and spatial neighbor hash value are written into the header area of the current data block. The preceding hash value is used to prove the temporal chain relationship between the current data block and the previous data block; the spatial neighbor hash value is used to prove the cross-reference relationship between the current data block and adjacent historical data blocks in the semantic space. Thus, the current data block is constrained by both the temporal preceding hash and the neighbor hash in the multidimensional semantic space. If the data content, temporal relationship, or spatial neighbor relationship of any subsequent historical data block changes, it will lead to inconsistencies in the corresponding hash value verification, which will be detected by the system.
[0023] Furthermore, a topological layered trusted anchor point is set for the data block. The topological layer is defined by multi-dimensional semantic features. Each layer uses the hash value of the representative data block corresponding to the semantic clustering center of the layer as the layer root hash. Each data block belongs to both the root anchor point of the current layer and the neighbor anchor point across layers. The verification system uses the dual constraints as the index key to perform fast spatial positioning and topological affiliation verification of the data block.
[0024] Optionally, after generating the multidimensional semantic feature vectors of the data blocks, semantic layering processing is performed on all written data blocks according to a preset topological layering rule. Specifically, the multidimensional semantic feature vector of each data block is normalized and mapped to a multidimensional feature space. A preset number of semantic clustering centers are used to divide this multidimensional feature space, with each semantic clustering center corresponding to a topological layer. The current data block is assigned to the layer containing the semantic clustering center closest to its multidimensional semantic feature vector. For each topological layer, the data block with the smallest distance to the layer's semantic clustering center is selected as a representative data block. The data hash value of this representative data block is read and determined as the root hash of this topological layer, serving as a trusted anchor point for the data blocks in this layer. Subsequently, a dual hash reference constraint is established for the current data block. The first constraint is the root anchor point constraint of the current layer, which means that the root hash of the topological layer to which the current data block belongs is written into the anchor point field of the current data block, so that the current data block can be quickly located to the corresponding semantic subset through the root hash of the current layer. The second constraint is the cross-layer neighbor anchor point constraint, which means that the distance between the semantic cluster center of the current topological layer and the semantic cluster centers of other topological layers is calculated, the nearest adjacent topological layer is selected as the cross-layer neighbor layer, and the root hash of the cross-layer neighbor layer is written into the cross-layer anchor point field of the current data block, so that the current data block, in addition to belonging to the trusted anchor point of the current layer, can also form a horizontal hash reference relationship with the adjacent semantic layers. After the dual constraints are established, the current data block identifier, the root hash of the current layer, and the cross-layer neighbor anchor point hash are concatenated in a preset order and hash calculation is performed to obtain the topological anchor point index key of the current data block. This topological anchor point index key and the topological coordinates of the current data block are written into the index table. Thus, the original chain-like links that relied solely on sequential order are expanded into a network-like link structure that simultaneously includes temporal links, anchor links within the same layer, and cross-layer neighbor anchor links. When verifying a target data block, it's not necessary to traverse the entire chain starting from the first data block. Instead, the root anchor of the layer to which the target data block belongs is located first based on its topological anchor index key. Then, the process backtracks from the target data block to the nearest trusted anchor within the same layer, verifying the continuity of the hash reference relationship between the target data block and the root anchor. If the path from the root anchor cannot reach the target data block, the hash of the cross-layer neighbor anchor stored in the target data block is read, and the process switches to the adjacent semantic level to continue backtracking verification. This allows the tracing path to be recovered even in the event of a local topological break. Through this process, the topological layered trusted anchors provide a fast starting point for data block verification. Verification only requires locating and backtracking around the semantic layer to which the target data block belongs and adjacent semantic layers, without traversing the entire data chain. This improves the efficiency of data block spatial location and topological attribution verification, and also enhances the recovery capability of the network-like hash structure in path break scenarios.
[0025] like Figure 2As shown, the impact of the number of topological layers on the efficiency of fast data block location is illustrated. As the number of topological layers increases from approximately 2 to 12, the average number of location steps decreases significantly, indicating that layered trusted anchors effectively narrow the verification and retrieval scope, allowing the system to directly locate the semantic level of the target data block without traversing the entire chain from the head. When the number of layers continues to increase to 16 and 20, the decrease in the average number of location steps tends to level off, indicating that after the number of topological layers reaches a certain scale, the location efficiency gradually converges, and further increasing the number of layers has limited performance improvement.
[0026] The latest data sequence and hash calculation result are written into the corresponding secondary nodes in the data block. Each secondary node receives a consistency confirmation request from the master node, independently performs data hash value calculation and compares it with the hash calculation result to determine the comparison result. The number of secondary nodes is at least two.
[0027] In one embodiment, after the master node completes writing the data hash value of the current data block, it immediately initiates the synchronous writing process of the slave nodes, using two slave nodes as fixed replica verification nodes. The master node first encapsulates the latest data sequence, data block identifier, data content, preceding hash value, spatial neighbor hash value, data hash value, master node write time, and consistency confirmation request number corresponding to the current data block into a synchronous write data packet, and sends it to the first and second slave nodes respectively. Upon receiving the synchronous write data packet, the first and second slave nodes first verify whether the data block identifier and consistency confirmation request number are complete. If the verification passes, they write the latest data sequence and its corresponding hash calculation result into the data block storage area of their respective slave nodes, which has the same number as the master node. After writing, each slave node does not directly use the hash value sent by the master node as the confirmation basis. Instead, it rereads the data content from the data block already written by its own slave node, generates data to be hashed according to the exact same field order, character encoding method, and length identifier concatenation rules as the master node, and then independently calculates the local verification hash value using a preset hash algorithm. Subsequently, each secondary node compares its local verification hash value with the data hash value carried in the data packet synchronously written by the primary node, character by character. If the local verification hash values of both the first and second secondary nodes are completely consistent with the data hash value sent by the primary node, each secondary node returns a matching result to the primary node. If the local verification hash value calculated by any secondary node is inconsistent with the data hash value sent by the primary node, or if the secondary node fails to complete the writing and comparison within a preset time, the secondary node returns a mismatch result to the primary node. Based on this, the primary node marks the current data block as having an inconsistency and triggers an anomaly alarm. Through this process, the secondary nodes independently recalculate and independently compare the same data content, avoiding reliance solely on the primary node's write result for confirmation. This allows the system to promptly detect data writing errors, transmission anomalies, or data tampering issues between the primary and secondary nodes.
[0028] Furthermore, the data hash value is calculated independently and compared with the hash calculation result to determine the comparison result, including: When a secondary node successfully writes data, in response to the consistency confirmation request, each secondary node independently performs a hash calculation on the data content to obtain a verification data hash value; the data hash value is compared with the verification data hash value to obtain a comparison result, wherein the comparison result includes either a match or at least one inconsistency.
[0029] Preferably, after the first and second slave nodes complete the synchronous writing of the current data block, each slave node initiates a local verification process based on the received consistency confirmation request. First, it reads the written data content from its own data block storage area, along with the corresponding data block identifier, preceding hash value, spatial neighbor hash value, and the data hash value sent by the master node. Then, each slave node re-serializes the data content according to the same hash calculation rules as the master node. Specifically, it extracts each field from the data content in a preset order, converts each field into byte data with a unified character encoding, adds a fixed-length field length identifier before each field byte data, and then concatenates all the field byte data sequentially into a byte sequence to be verified. After generating the byte sequence to be verified, each slave node independently calculates the verification data hash value corresponding to its own byte sequence using a preset hash algorithm. This calculation process is executed independently on the slave node's local machine and does not directly use the data hash value sent by the master node as the calculation result. Subsequently, each secondary node compares the locally generated verification data hash value with the data hash value written and sent by the primary node character by character. If the 64-bit hexadecimal strings of the two are exactly the same, the secondary node determines that the data content of the current data block in its secondary node is consistent with the corresponding data content in the primary node, and generates a consistent comparison result. If any character is different, or if the secondary node cannot recalculate a valid verification data hash value based on the written data, the secondary node determines that there is an inconsistent comparison result. After receiving the comparison results returned by each secondary node, the primary node summarizes the returned results of all secondary nodes. When at least two secondary nodes return consistent comparison results, the consistency check result of the current data block is determined to be consistent. When any secondary node returns inconsistent comparison results, calculation failure, or timeout, the consistency check result of the current data block is determined to have at least one inconsistent comparison result, and the corresponding secondary node number, data block identifier, primary node data hash value, verification data hash value, and comparison time are written to the exception record for subsequent alarm, review, and data repair. Through the above process, it can be ensured that the secondary node does not passively save the results of the primary node, but recalculates the hash value based on the data it writes, thereby discovering inconsistencies between the primary and secondary nodes caused by write errors, transmission corruption, or data tampering, and improving the reliability of consistency verification and anomaly detection capabilities during the data synchronization writing process.
[0030] like Figure 3As shown, the hash consistency verification results of the master node, slave node A, and slave node B on multiple data blocks are displayed. Most data blocks in the matrix are consistent across the three nodes, indicating that the data written by the master node and the data independently stored by the slave nodes can maintain synchronization and consistency. However, some data blocks corresponding to individual slave nodes are shown as abnormal, indicating that the hash value of the corresponding data block in the slave node is inconsistent with that of the master node. This can serve as the basis for triggering consistency alarms, locating abnormal replicas, and performing data review or repair processes.
[0031] Furthermore, a timeout threshold is set for the synchronous write interval between the primary and secondary nodes; wherein, when the primary node writes successfully, if the time interval between the synchronous writes of the secondary node is greater than the timeout threshold, it is determined that the secondary node synchronization has failed and an alarm is triggered.
[0032] Preferably, before the master-slave node synchronous write process starts, a timeout threshold for the master-slave node synchronous write interval is pre-set in the consistency check configuration table. This timeout threshold can be set to 5 seconds. After the current data block is successfully written to the master node, the master node immediately records the master node's write completion time and uses this time as the start time for the slave node's synchronization timing. Subsequently, the master node sends synchronous write data packets to the first and second slave nodes. After receiving the synchronous write data packets, each slave node writes the data content and data hash value to the corresponding data block storage area of its own node, and generates a slave node write completion time when the write is complete. This write completion time is then returned to the master node along with the confirmation result. After receiving the return result from the slave node, the master node calculates the time difference between the slave node's write completion time and the master node's write completion time, and uses this time difference as the master-slave node synchronous write interval. When the synchronization write intervals of both the first and second slave nodes are less than or equal to the timeout threshold, and the hash comparison results returned by the slave nodes are consistent, the master node determines that the slave node's synchronization write is successful. When the synchronization write interval of any slave node exceeds the timeout threshold, or the master node does not receive a write completion confirmation from the slave node within the timeout threshold, the master node determines that the slave node's synchronization has failed and immediately marks the current data block as being in a synchronization abnormal state. Simultaneously, an abnormal alarm record is generated, including the data block identifier, slave node number, master node write completion time, timeout threshold, actual return time, and abnormal type. Finally, the abnormal alarm is sent to the client of the user with preset permissions, and the consistency confirmation completion status of the data block is suspended until the slave node resynchronizes successfully or the abnormality is handled after manual review. This approach avoids the problem of data inconsistency between the master and slave nodes caused by successful master node writes but prolonged slave node non-synchronization, synchronization delays, or synchronization loss, improving the reliability and real-time consistency of multi-node traceable data storage.
[0033] If the comparison result is a match, a confirmation of success will be returned; if the comparison result is a mismatch, an exception alarm will be returned.
[0034] In one embodiment, after receiving the hash comparison results returned by each slave node, the master node summarizes and judges the consistency confirmation status of the current data block. Specifically, the master node first searches for all slave node return records corresponding to the current data block based on the consistency confirmation request number, and verifies whether the data block identifier, slave node number, verification data hash value, comparison conclusion, and return time in the returned records are complete. When both the first and second slave nodes return consistent comparisons within the timeout threshold, and the verification data hash values returned by the two slave nodes are exactly the same as the data hash value stored in the master node, the master node updates the consistency status of the current data block to successful confirmation and generates a successful confirmation record. This successful confirmation record includes the data block identifier, the master node data hash value, and the verification numbers of each slave node. Based on the hash value, confirmation completion time, and confirmation request number, the data block is allowed to enter subsequent chained storage, query, or full-chain verification processes. When any slave node returns an inconsistency, an empty verification data hash value, a different verification data hash value from the master node's data hash value, or any slave node fails to return a confirmation result within the timeout threshold, the master node updates the consistency status of the current data block to abnormal and immediately generates an abnormal alarm record. This abnormal alarm record includes the abnormal data block identifier, the abnormal slave node number, the master node's data hash value, the slave node's verification data hash value, the abnormal occurrence time, the abnormal type, and the consistency confirmation request number. Finally, the abnormal alarm record is written to the audit log, and an alarm notification is sent to users with preset permissions. At the same time, the confirmation completion status of the current data block is suspended, and it is prohibited from being used as a confirmed data block in subsequent trusted links until the slave node resynchronizes, recalculates, and passes consistency confirmation, or the abnormality is handled after manual review. Through the above process, a successful confirmation can be returned when the data on the primary and secondary nodes are completely consistent. If a write error, transmission corruption, data modification, or response timeout occurs on any node, an abnormal alarm will be returned immediately, thereby ensuring the integrity and consistency of traceability data in a multi-node storage environment.
[0035] Furthermore, the method also includes: According to a preset cycle, perform a full-chain integrity check. If there is an abnormal record, mark the abnormal record and subsequent records as pending verification. Based on the pending verification status, send an alarm notification to the user terminal with preset permissions and perform data tampering judgment.
[0036] Preferably, the full-chain integrity verification task is started according to the preset verification cycle. After the verification task is triggered by the background timer, all data blocks corresponding to the product are read first using the product's unique identifier as the retrieval condition. Then, the data blocks are verified one by one starting from the first data block according to the data block generation order. For the data block being verified, the data to be hashed is regenerated according to the same field order, character encoding method and field length identification rules as when it was written. The preset hash algorithm is then called to recalculate the current verification hash value. The current verification hash value is then compared with the data hash value already stored in the data block. At the same time, the preceding hash value in the header of the current data block is read and compared with the data hash value of the previous data block. When the current data block is the first data block, its preceding hash value is checked against the preset starting hash value. If the hash value of the current data block matches, and the preceding hash value matches the hash value of the previous data block, the next data block is checked. If any data block has inconsistent hash values, inconsistent preceding hash values, or its spatial neighbor hash value cannot be mapped to a registered neighbor data block, the data block is identified as an abnormal record. This abnormal record and all data blocks following it in the same product chain are immediately marked as pending verification, and subsequent additions, writes, and confirmations of traceable data for that product are suspended. After marking the abnormality, an alarm notification is generated and sent to the client of the user with preset permissions. This alarm notification includes the abnormal data block identifier, the product's unique identifier, the time of abnormality discovery, the abnormality type, the primary node's data hash value, and the recalculated verification hash value. Then, the data tampering judgment process begins. This involves reading the data content and hash value corresponding to the abnormal data block from the secondary node, comparing the hash values, and determining whether to proceed with the data repair process based on the comparison results. Through the above process, abnormal records can be proactively detected during periodic full-chain verification, and these abnormal records and their subsequent records can be isolated into a state pending verification. Authorized users can be notified in a timely manner to determine data tampering and to carry out subsequent processing, thereby improving the initiative and audit credibility of data integrity verification.
[0037] Furthermore, determining data tampering includes: For each abnormal record corresponding to a data block, the data hash value is read from at least one secondary node and the hash value is compared. If the data hash value of the secondary node is consistent with that of the primary node, it is determined that the data has not been tampered with, and the data repair process is executed. If the data hash value of the secondary node is inconsistent with that of the primary node, it is determined that the data has been tampered with. The original data sequence and all hash values are packaged, digitally signed, and uploaded to the regulatory audit interface.
[0038] Optionally, when an abnormal record is detected during the full-chain integrity verification, the data block identifier corresponding to the abnormal record is used as the retrieval basis. The original data content, data hash value, preceding hash value, and spatial neighbor hash value stored in the data block are first read from the master node, and the master node's read time is recorded. Since the master node is used as the sole data write entry point, all new data blocks are generated by the master node and distributed to the slave nodes. The slave nodes do not participate in new data writing; they are only responsible for receiving data distributed by the master node and performing independent storage and verification. Therefore, when an anomaly occurs, the master node is prioritized as a potential source of anomaly for investigation. Subsequently, the system reads the data hash value stored under the same data block identifier from at least one secondary node, and compares the data hash value returned by the secondary node with the data hash value in the primary node character by character. If the data hash values read by each secondary node are completely consistent with the data hash value of the primary node, it indicates that the data digests stored by the primary and secondary nodes are consistent. The current anomaly is not caused by the data content being tampered with, but may be due to an anomaly in the link association field, index field, storage medium, or the execution process of the verification task. Based on this, the system determines that the data has not been tampered with and enters the data repair process, such as regenerating the link index, repairing the preceding reference relationship, rewriting the anomaly status identifier, or restoring the verification task status. If the data hash value read by any secondary node is inconsistent with the data hash value of the primary node, it indicates that different data digests have been formed for the same data block between the primary and secondary nodes. Since secondary nodes only store copies of the data distributed by the primary node and do not handle business write operations, the hash values in secondary nodes can serve as independent verification criteria. Based on this, the system determines there is a risk of data tampering, especially the risk of primary node data modification. In this case, normal verification of the abnormal data block and its subsequent blocks is stopped, and the block is kept in a pending verification state. The system reads the original data sequence, data hash value, preceding hash value, spatial neighbor hash value, write time, and node identifier corresponding to the data block from both the primary node and each secondary node, and packages them into an evidence collection data package according to a fixed format. After the evidence collection data package is generated, it is digitally signed using a preset private key to form a non-repudiable evidence report. This report is then uploaded to the regulatory audit interface, and the upload time, signature value, abnormal data block identifier, and hash difference results for each node are recorded in the local audit log for subsequent traceability and verification by regulators or authorized auditors.
[0039] Furthermore, the method also includes: The hash comparison results, anomaly record details, and processing conclusions of the master node and each slave node for full-chain integrity verification are determined and written into the audit log. The audit log is stored using the same hash chain structure as the data chain. By anchoring the hash value of the audit log to the previous data block of the abnormal data block, a dual-chain association lock between the data chain and the audit chain is formed. When it is verified that the anchoring relationship between the audit chain and the data chain is broken, an audit log forgery alarm is triggered.
[0040] Preferably, after the full-chain integrity verification is completed, the hash comparison results of the master node, the hash comparison results of the first sub-node, the hash comparison results of the second sub-node, the abnormal data block identifier, the abnormal discovery time, the abnormal type, the data hash value stored in the abnormal data block, the recalculated verification hash value, the data hash value read by the sub-node, and the final processing conclusion generated during this verification process are compiled into an audit log record. When generating an audit log record, the log hash value of the previous audit log is first read and used as the preceding log hash value of the current audit log. If the current audit log is the first log, the preceding log hash value is set to a preset initial value. Subsequently, the verification result, abnormal record details, processing conclusion, preceding log hash value, and log generation time in the current audit log are serialized in a fixed order, and a preset hash calculation is performed to obtain the current audit log hash value, thereby forming a continuous hash chain structure for the audit log itself. In cases where abnormal records exist, the preceding data block of the abnormal data block is read, and its data hash value is obtained. Then, the data hash value of the preceding data block, the abnormal data block identifier, and the current audit log hash value are concatenated in a preset order, and a hash calculation is performed again to generate an anchor hash value between the data chain and the audit chain. This anchor hash value is then written to the anchor field of the current audit log. In this way, the current audit log is constrained not only by the hash value of the previous audit log entry but also by the data hash value of the preceding data block of the abnormal data block, creating a double-chain association and locking between the audit log chain and the traceability data chain. When verifying the authenticity of the audit log, the audit log hash value, the preceding log hash relationship, and the anchor hash value are recalculated sequentially. The recalculated anchor hash value is compared with the anchor hash value stored in the audit log. If the audit log content has been modified, the current audit log hash value changes, causing the audit chain to break; if the preceding data block of the abnormal data block has been modified, its data hash value changes, causing the anchor hash value to fail to match. If an audit log hash chain is found to be discontinuous, the audit log hash value is inconsistent with the stored value, or the audit log anchoring field cannot be recalculated and matched with the data hash value of the previous data block of the abnormal data block, the anchoring relationship between the audit chain and the data chain is determined to be broken, and an audit log forgery alarm is immediately triggered. At the same time, the break location, the abnormal audit log identifier, the abnormal data block identifier, and the verification time are recorded for subsequent regulatory audits and manual review, thereby improving the credibility of the anomaly tracing results and the completeness of regulatory audit evidence.
[0041] In summary, the embodiments of this application have at least the following technical effects: First, the latest data sequence is read from the database, where it is preprocessed using a chained data structure. Then, a hash calculation is performed on the data fields of the latest data sequence, and the hash result is written to the master node within the corresponding data block. The data block header stores the previous hash value and spatial neighbor hash values, while the master node stores the data hash value. Next, the latest data sequence and hash calculation result are written to the slave nodes within the corresponding data block. Each slave node receives a consistency confirmation request from the master node, independently performs data hash value calculation, and compares it with the hash calculation result to determine the comparison result. There must be at least two slave nodes. Finally, if the comparison result is consistent, a confirmation success is returned; if the comparison result is inconsistent, an exception alarm is returned. This solves the technical problem that existing traceability data storage relies on centralized or single-point databases, making historical data susceptible to silent tampering and deletion, resulting in insufficient traceability data integrity and reliability. It achieves the technical effect of making traceability data tampering detectable and inter-node consistency verifiable through hash chains and independent recalculation and comparison by multiple slave nodes, thereby improving the immutability and reliability of traceability data.
[0042] Example 2 is based on the same inventive concept as the multi-node hash chain consistency verification method for tracing data in the foregoing examples, such as... Figure 4 As shown, this application provides a multi-node hash chain consistency verification system for tracing data, wherein the system includes: Data reading module 11: Reads the latest data sequence from the database, wherein the latest data sequence is preprocessed using a chained data structure; Hash calculation module 12: Performs hash calculation on the data fields of the latest data sequence, obtains the hash calculation result, and writes it to the master node in the corresponding data block, wherein the header of the data block stores the previous hash value and the spatial neighbor hash value, and the master node stores the data hash value; Hash comparison module 13: Writes the latest data sequence and the hash calculation result to the slave node in the corresponding data block, each slave node receives a consistency confirmation request from the master node, independently performs data hash value calculation, and compares it with the hash calculation result to determine the comparison result, wherein the number of slave nodes is at least two; Comparison result return module 14: If the comparison result is consistent, it returns a confirmation success; if the comparison result is inconsistent, it returns an exception alarm.
[0043] Furthermore, the hash calculation module 12 is used to perform the following method: For the latest data sequence, determine the data content and multidimensional semantic feature vector; based on the data content, obtain the data hash value through hash calculation; write the data hash value to the master node; when the master node successfully writes, the master node pushes the data content and hash calculation result to the slave node and generates a consistency confirmation request.
[0044] Furthermore, the hash calculation module 12 is used to perform the following method: Determine the topological coordinates of the data block in the multidimensional feature space based on the multidimensional semantic feature vector; establish a link between the data block and the previous block according to the temporal sequence, and determine the preceding hash value; based on the topological coordinates of the data block, establish spatial neighbor links with multiple historical data blocks in the adjacent space based on the multidimensional semantic feature vector, and establish spatial neighbor hash values based on cross-hash references; write the preceding hash value and the spatial neighbor hash value into the data block.
[0045] Furthermore, the hash calculation module 12 is used to perform the following method: The topological layering of data blocks is set up with trusted anchor points. The topological layering is defined by multi-dimensional semantic features. Each layer uses the hash value of the representative data block corresponding to the semantic clustering center of the layer as the layer root hash. Each data block belongs to both the root anchor of the current layer and the neighbor anchor of the cross layer. The verification system uses the dual constraints as the index key to perform fast spatial positioning and topological affiliation verification of the data blocks.
[0046] Furthermore, the hash comparison module 13 is used to perform the following method: When a secondary node successfully writes data, in response to the consistency confirmation request, each secondary node independently performs a hash calculation on the data content to obtain a verification data hash value; the data hash value is compared with the verification data hash value to obtain a comparison result, wherein the comparison result includes either a match or at least one inconsistency.
[0047] Furthermore, the hash comparison module 13 is used to perform the following method: Set a timeout threshold for the synchronous write interval between the primary and secondary nodes; wherein, if the time interval between the synchronous write of the primary node and the synchronous write of the secondary node is greater than the timeout threshold, it is determined that the synchronization of the secondary node has failed and an alarm is triggered.
[0048] Furthermore, the comparison result return module 14 is used to perform the following method: According to a preset cycle, perform a full-chain integrity check. If there is an abnormal record, mark the abnormal record and subsequent records as pending verification. Based on the pending verification status, send an alarm notification to the user terminal with preset permissions and perform data tampering judgment.
[0049] Furthermore, the comparison result return module 14 is used to perform the following method: For each abnormal record corresponding to a data block, the data hash value is read from at least one secondary node and the hash value is compared. If the data hash value of the secondary node is consistent with that of the primary node, it is determined that the data has not been tampered with, and the data repair process is executed. If the data hash value of the secondary node is inconsistent with that of the primary node, it is determined that the data has been tampered with. The original data sequence and all hash values are packaged, digitally signed, and uploaded to the regulatory audit interface.
[0050] Furthermore, the comparison result return module 14 is used to perform the following method: The hash comparison results, anomaly record details, and processing conclusions of the master node and each slave node for full-chain integrity verification are determined and written into the audit log. The audit log is stored using the same hash chain structure as the data chain. By anchoring the hash value of the audit log to the previous data block of the abnormal data block, a dual-chain association lock between the data chain and the audit chain is formed. When it is verified that the anchoring relationship between the audit chain and the data chain is broken, an audit log forgery alarm is triggered.
[0051] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention in any way. Although the present invention has been disclosed above with reference to preferred embodiments, it is not intended to limit the present invention. Any person skilled in the art can make some modifications or alterations to the above-disclosed technical content to create equivalent embodiments without departing from the scope of the present invention. Any modifications, equivalent changes, and alterations made to the above embodiments based on the technical essence of the present invention without departing from the scope of the present invention shall still fall within the scope of the present invention.
Claims
1. A multi-node hash chain consistency verification method for tracing data, characterized in that, The method includes: Read the latest data sequence from the database, wherein the latest data sequence is preprocessed using a chained data structure; The data fields of the latest data sequence are hashed to obtain the hash calculation result and written to the master node in the corresponding data block. The data block header stores the previous hash value and the spatial neighbor hash value, and the master node stores the data hash value. The latest data sequence and hash calculation result are written into the secondary nodes in the corresponding data block. Each secondary node receives a consistency confirmation request from the master node, independently performs data hash value calculation and compares it with the hash calculation result to determine the comparison result. The number of secondary nodes is at least two. If the comparison result is a match, a confirmation of success will be returned; if the comparison result is a mismatch, an exception alarm will be returned.
2. The multi-node hash chain consistency verification method for tracing data as described in claim 1, characterized in that, Write the master node within the corresponding data block, including: For the latest data sequence, determine the data content and multidimensional semantic feature vector; Based on the data content, the data hash value is obtained through hash calculation; The data hash value is written to the master node. When the master node successfully writes the data, it pushes the data content and hash calculation result to the slave node and generates a consistency confirmation request.
3. The multi-node hash chain consistency verification method for tracing data as described in claim 2, characterized in that, After determining the multidimensional semantic feature vector, the following is included: Determine the data block topological coordinates of the multidimensional semantic feature vector in the multidimensional feature space; Establish links between data blocks and previous blocks based on their temporal order, and determine the preceding hash value; Based on the topological coordinates of the data block, establish spatial neighbor links with multiple historical data blocks in the adjacent space based on multidimensional semantic feature vectors, and establish spatial neighbor hash values based on cross-hash references. Write the preceding hash value and the spatial neighbor hash value into the data block.
4. The multi-node hash chain consistency verification method for tracing data as described in claim 3, characterized in that, The topological layering of data blocks is set up with trusted anchor points. The topological layering is defined by multi-dimensional semantic features. Each layer uses the hash value of the representative data block corresponding to the semantic clustering center of the layer as the layer root hash. Each data block belongs to both the root anchor of the current layer and the neighbor anchor of the cross layer. The verification system uses the dual constraints as the index key to perform fast spatial positioning and topological affiliation verification of the data blocks.
5. The multi-node hash chain consistency verification method for tracing data as described in claim 1, characterized in that, Independently perform data hash value calculation and compare it with the hash calculation result to determine the comparison result, including: When a secondary node successfully writes data, in response to the consistency confirmation request, each secondary node independently performs a hash calculation of the data content to obtain a verification data hash value. The data hash value is compared with the verification data hash value to obtain a comparison result, wherein the comparison result includes either a match or at least one inconsistency.
6. The multi-node hash chain consistency verification method for tracing data as described in claim 1, characterized in that, Set the timeout threshold for the synchronous write interval between the primary and secondary nodes; Specifically, if the time interval between the primary node's successful write and the secondary node's synchronized write exceeds the timeout threshold, the secondary node's synchronization is deemed to have failed and an alarm is triggered.
7. The multi-node hash chain consistency verification method for tracing data as described in claim 1, characterized in that, The method further includes: According to the preset cycle, perform full-chain integrity verification. When there are abnormal records, mark the abnormal records and subsequent records as pending verification. Based on the pending verification status, an alarm notification is sent to the user terminal with preset permissions, and a data tampering determination is performed.
8. The multi-node hash chain consistency verification method for tracing data as described in claim 7, characterized in that, Data tampering detection includes: For each data block corresponding to an anomaly record, read the data hash value from at least one secondary node and perform hash value comparison. If the data hash value of the secondary node is consistent with that of the primary node, it is determined that the data has not been tampered with, and the data repair process is executed. If the hash value of the data on the secondary node is inconsistent with that of the primary node, it is determined that data tampering has occurred. The original data sequence and all hash values are packaged, digitally signed, and then uploaded to the regulatory audit interface.
9. The multi-node hash chain consistency verification method for tracing data as described in claim 1, characterized in that, The method further includes: Determine the hash comparison results between the master node and each slave node for full-chain integrity verification, details of anomaly records, and processing conclusions, and write them into the audit log; The audit log is stored using the same hash chain structure as the data chain. By anchoring the hash value of the audit log to the previous data block of the abnormal data block, a dual-chain association lock is formed between the data chain and the audit chain. When verification shows a break in the anchoring relationship between the audit chain and the data chain, an audit log forgery alert is triggered.
10. A multi-node hash chain consistency verification system for tracing data, characterized in that, The system is used to implement the multi-node hash chain consistency verification method for tracing data as described in any one of claims 1-9, the system comprising: Data reading module: Reads the latest data sequence from the database, wherein the latest data sequence is preprocessed using a chained data structure; Hash calculation module: performs hash calculation on the data fields of the latest data sequence, obtains the hash calculation result and writes it into the master node in the corresponding data block. The data block header stores the previous hash value and the spatial neighbor hash value, and the master node stores the data hash value. Hash comparison module: Writes the latest data sequence and hash calculation result into the secondary nodes in the corresponding data block. Each secondary node receives a consistency confirmation request from the master node, independently performs data hash value calculation and compares it with the hash calculation result to determine the comparison result. The number of secondary nodes is at least two. The comparison result return module returns a confirmation of success if the comparison result is consistent, and an exception alarm if the comparison result is inconsistent.
