Blockchain-based method and system for agricultural food source traceability
By establishing batch traceability indexes and anomaly detection, the problem of batch identification breaks in the agricultural food circulation process has been solved, and dynamic identity correction throughout the entire life cycle has been achieved, ensuring the accuracy of traceability information and the reliability of the system.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- GUANGDONG NEOFARMER TECH
- Filing Date
- 2026-03-13
- Publication Date
- 2026-06-23
AI Technical Summary
In existing technologies, when agricultural food products undergo batch splitting and repackaging during distribution, the blockchain traceability system fails to fully inherit the original batch identifiers, leading to data merging errors, causing confusion in traceability paths, and affecting the accuracy and reliability of information.
By establishing a batch traceability index, collecting original batch numbers, splitting records, and handover times, generating a batch traceability index, detecting abnormal splitting or merging situations, generating an identity anomaly list, and through the collaborative operation of reverse supplementation and forward freezing, the dynamic correction of the identity of agricultural food products and the maintenance of consistency of on-chain records throughout their entire life cycle can be achieved.
This ensures that the identity information of agricultural food products remains intact throughout the entire process, achieving full traceability at the batch level, improving the accuracy of traceability results and the reliability of data records, and enhancing the stability and practicality of the traceability system.
Smart Images

Figure CN122264804A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of trusted supply chain management technology, specifically to a blockchain-based method and system for tracing the origin of agricultural and food products. Background Technology
[0002] Blockchain-based agricultural and food traceability refers to the collaborative recording of key events and big data processing results at each stage of the agricultural product's journey from planting, processing, storage, transportation to final sale. This data is continuously, encrypted, and immutably written into a blockchain ledger and bound to a unique product code, forming a traceability record covering the entire lifecycle. In this process, each batch generation, quality inspection results, temperature and humidity changes in the storage environment, cold chain transportation node status, smart vending machine operating parameters, and consumer scanning behavior are all aggregated, cleaned, and time-aligned through big data processing, becoming independent time nodes and solidified on the blockchain in chronological order. Historical information cannot be arbitrarily modified or deleted. By combining the processing results of multi-source data with the blockchain ledger, the origin, production process, and distribution trajectory of agricultural products can be accurately verified. Consumers can obtain authentic and reliable source and process information when scanning codes, businesses can conduct quality checks and traceability, and regulatory authorities can conduct reviews based on on-chain records. This approach leverages the synergy of blockchain and big data processing to achieve reliable solidification of information across multiple stages and types, making food sources more transparent, information chains more complete, and risk points more traceable, thereby building a stable and reliable agricultural food traceability system.
[0003] The existing technology has the following shortcomings: In existing technologies, when agricultural products undergo batch splitting, repackaging, and secondary on-chain recording during distribution, the system typically only generates new on-chain records based on the new packaging information, without fully inheriting or mapping the original batch identifier. This can easily lead to data merging errors or duplicate hash fingerprint generation. In such cases, the same batch may be split into multiple independent identities on the blockchain, and different batches may be incorrectly merged into the same traceability chain, causing confusion in traceability paths. When consumers scan the code to query, they may obtain origin, testing, or distribution data that does not belong to the product, resulting in incorrect display of source information. This problem not only weakens the credibility of blockchain traceability but also leads to misjudgment of responsible parties by regulators during recall or traceability processes, ultimately undermining the integrity and reliability of the agricultural food source traceability system.
[0004] The information disclosed in the background section is only intended to enhance the understanding of the background of this disclosure, and therefore may include information that does not constitute prior art known to those skilled in the art. Summary of the Invention
[0005] The purpose of this invention is to provide a blockchain-based method and system for tracing the source of agricultural food products, in order to solve the problems mentioned in the background art.
[0006] To achieve the above objectives, the present invention provides the following technical solution: a blockchain-based method for tracing the source of agricultural food, comprising the following steps: In the process of tracing the source of agricultural and food products, the original batch number, splitting record, packaging number and handover time are collected. The collected data are stored in a distributed storage system to generate a batch traceability index, which is used to record the identity continuity information of agricultural and food products throughout the entire process of production, processing, storage, transportation and sales. Based on the batch traceability index, the time sequence, packaging sequence and handover party information are compared item by item. The logical relationship between the data in the batch traceability index is analyzed to detect whether there are abnormal splits or abnormal mergings, and an identity anomaly list is generated as a reference for subsequent traceability analysis. By using the identity anomaly list to perform backtracking analysis on the on-chain data of the original production node, distribution node and terminal node, the corresponding collection records are extracted from the batch traceability index to determine the time interval of the anomaly and generate an anomaly time distribution map to locate the distribution of the anomaly data in the time dimension. Based on the abnormal time distribution map, an inheritance instruction is issued to extend the original batch number to the corresponding split packaging unit, establish a one-to-many mapping relationship between the original batch and each split packaging unit, and generate a batch inheritance list to achieve identity continuation between different packaging units. Based on the batch inheritance list, a collaborative operation of reverse supplementation and forward freezing is performed to backfill historical records to the correct source node. The identity change is temporarily frozen at the node where the batch split is about to occur, and then gradually unlocked in a time-step manner to achieve dynamic correction of the identity of agricultural food throughout its entire life cycle and maintenance of consistency of on-chain records.
[0007] Preferably, the batch traceability index generation steps are as follows: The original batch number generated when agricultural food enters the production process is associated with key data in the production process and collected. The original batch number is recorded synchronously with raw material information, harvesting environment parameters and first storage time to form an initial data set. After the original batch number is generated, the splitting records and packaging numbers of agricultural products during the circulation process are collected. The splitting records are bound to the original batch number to form an expanded identity association dataset, enabling continuous tracking from batch to packaging unit. After completing the collection of splitting records and packaging numbers, the flow information of agricultural products between different nodes is recorded by the handover time, and the handover time is uniformly associated with the packaging number, splitting record and original batch number to form time-series traceability information; The original batch number, splitting record, packaging number, and handover time are uniformly stored in a distributed storage structure and sorted according to the collection order to generate a batch traceability index, so as to record the identity continuity information of agricultural food throughout the entire process of production, processing, storage, transportation, and sales.
[0008] Preferably, in the process of generating the batch traceability index, the original batch number is used as the root node, the split record and packaging number are used as branch nodes, and the handover time is used as the time series backbone. Various types of data are classified and organized according to time order and hierarchical relationship to form a multi-dimensional data chain, so that agricultural food forms a continuous identity continuation structure in the whole process, and realizes the unified association and retrieval of batch information in the distributed storage structure.
[0009] Preferably, the steps for generating the identity anomaly list are as follows: Based on the batch traceability index, the time sequence information of the records is organized, and the production time, processing time, warehousing time, outbound time, transportation time and sales time of each batch are arranged in chronological order, so that the time nodes form a continuous time chain. After the time sequence is sorted out, the packaging sequence in the batch traceability index is merged. Taking the time sequence as the main line, each packaging number is inserted under the corresponding time node, so that a continuous mapping relationship is formed between the batch number, packaging number and time node. After the packaging sequence is sorted out, the time chain and packaging chain are comprehensively analyzed based on the handover party information in the batch traceability index. The handover time is matched with the packaging number and batch number, and abnormal splitting and abnormal merging are identified by comparing each item. After the analysis, the anomaly splitting and merging results are summarized and organized. Conflicting data fragments are extracted from the time chain, packaging chain, and handover chain to generate an identity anomaly list, which records the batch number, packaging number, handover party information, and time range of the anomaly.
[0010] Preferably, when generating the identity anomaly list, the batch numbers and packaging numbers of the anomaly splitting and anomaly merging are grouped in chronological order, and the time range of the anomalies is divided into segments in combination with the flow path information of the handover party, so that each anomaly record corresponds to a unique time interval and handover node, thereby ensuring that the batch information recorded in the identity anomaly list is consistent with the time chain.
[0011] Preferably, the steps for generating the anomaly time distribution map are as follows: Based on the abnormal records in the identity abnormality list, the original production node, distribution node and terminal node information corresponding to each abnormality are determined, and the abnormal batch number is matched with the node information in the batch traceability index item by item to form a complete circulation process chain. After the node information is determined, the on-chain data corresponding to each node is backtracked. Taking the time range in the identity anomaly list as a clue, the on-chain data is retrieved sequentially starting from the original production node to establish the time correspondence between the anomaly record and the node data. After completing the node data backtracking, the collected data corresponding to the abnormal records is extracted from the batch traceability index, and cross-analysis is performed based on the time parameters and the abnormal time period to determine the specific time interval in which the abnormality occurred. An anomaly time distribution map is generated based on the defined time interval information. With time as the main axis and node category as the reference axis, the start time, end time and involved nodes of the anomaly event are visualized to reflect the distribution characteristics of the anomaly data in the time dimension.
[0012] Preferably, in the process of generating the abnormal time distribution map, the time node information in the batch traceability index is superimposed with the abnormal type information in the identity abnormal list, so that different types of abnormal events are displayed in segments on the time axis, and the time continuity of abnormal events in different stages is shown through the vertical correspondence of node categories, thereby reflecting the distribution status of abnormal data synchronously in the time dimension and node dimension.
[0013] Preferably, the batch inheritance list generation steps are as follows: Based on the abnormal time interval information presented in the abnormal time distribution map, the time correlation between the original batch number and the involved split packaging unit is determined. By matching the abnormal start time and end time, the records of batch splitting, repackaging or circulation operations that occurred within the abnormal time period are filtered. After the time correlation is determined, an inheritance instruction is issued based on the distribution pattern of the abnormal time distribution map, extending the identity of the original batch number to all split packaging units derived within the abnormal time period, and recording the time span, circulation path and participating entity information. After the inheritance instruction is issued, based on the batch correspondence established in the inheritance instruction, a one-to-many mapping relationship between the original batch number and the split packaging unit is established, and a continuous identity chain is formed according to the time sequence and circulation sequence. After the mapping relationship is established, all inheritance relationships are integrated and organized to generate a batch inheritance list, which records the original batch number, derived packaging number, inheritance time interval and circulation path information to reflect the identity continuation process of agricultural food.
[0014] Preferably, based on the batch inheritance list, a collaborative operation of reverse data entry and forward freezing is performed to backfill historical records to the correct source node. Identity is frozen at the node where batch splitting is about to occur, and the process is gradually unlocked according to a time-step approach, as follows: Based on the one-to-many mapping relationship between the original batch number and the split packaging unit established in the batch inheritance list, the historical chain records are traced and identified, and each downstream packaging unit is mapped to the correct source node, thus establishing the correspondence between the batch number and the source node. After the source node is determined, based on the inheritance time interval recorded in the batch inheritance list, the historical chain record is reversed and supplemented. The batch number, packaging number, handover time, handover party and circulation information are supplemented in chronological order to restore the continuity of the broken identity chain. After the reverse data entry is completed, a forward freeze operation is performed on the nodes that are about to be split into batches, temporarily locking the batch number, packaging number and time information of the nodes to ensure that the data is not updated during the freeze period. After the forward freeze period ends, the frozen nodes are gradually unlocked in a time-step manner to restore the identity change capability of each node, thereby realizing the dynamic correction of agricultural and food identity and the maintenance of consistency of on-chain records.
[0015] The blockchain-based agricultural food traceability system includes a batch index construction module, an anomaly detection module, an anomaly backtracking module, a batch inheritance module, and a dynamic correction module. The batch index building module collects the original batch number, split record, packaging number and handover time in the agricultural food source traceability process. The collected data is uniformly stored in the distributed storage system to generate a batch traceability index, which is used to record the identity continuity information of agricultural food throughout the entire process of production, processing, storage, transportation and sales. The anomaly detection module compares the time sequence, packaging sequence, and handover information item by item based on the batch traceability index, analyzes the logical relationship between the data in the batch traceability index, detects whether there are abnormal splits or abnormal mergings, and generates an identity anomaly list as a reference for subsequent traceability analysis. The anomaly backtracking module uses the identity anomaly list to backtrack and analyze the on-chain data of the original production node, distribution node and terminal node, extracts the corresponding collection records from the batch traceability index, determines the time interval of the anomaly, and generates an anomaly time distribution map to locate the distribution of anomaly data in the time dimension. The batch inheritance module issues inheritance instructions based on the abnormal time distribution map, extends the original batch number to the corresponding split packaging unit, establishes a one-to-many mapping relationship between the original batch and each split packaging unit, and generates a batch inheritance list to achieve identity continuation between different packaging units. The dynamic correction module performs a collaborative operation of reverse supplementation and forward freezing based on the batch inheritance list, backfilling historical records to the correct source node, and temporarily freezing identity changes at nodes where batch splitting is about to occur. Subsequently, it gradually unlocks the identity in a time-step manner, realizing dynamic identity correction and on-chain record consistency maintenance for agricultural and food products throughout their entire life cycle.
[0016] The technical effects and advantages provided by the present invention in the above technical solution are as follows: This invention establishes a batch traceability index throughout the entire agricultural and food process, enabling unified collection and storage of original batch numbers, splitting records, packaging numbers, and handover times. This ensures that data generated at each stage remains continuously linked on the chain. By constructing a dual index structure along both the time and packaging dimensions, it guarantees that the identity information of agricultural and food products remains unbroken during distribution, allowing for continuous tracking back to the source and achieving full batch-level traceability. This method effectively avoids identity confusion caused by batch splitting or merging, ensuring consistency in the recording and display of food origin information, thereby improving the accuracy of traceability results and the reliability of data records.
[0017] This invention constructs a batch inheritance list and combines it with a collaborative mechanism of reverse data entry and forward freezing to ensure logical consistency of on-chain data during dynamic changes. By backfilling historical records and freezing future nodes, it achieves adaptive correction of agricultural and food identity information throughout its entire lifecycle, enabling continuous updating of blockchain data over time. This approach guarantees the integrity of traceability information across multiple nodes and batches, allowing regulatory bodies, producers, and consumers to obtain accurate source chains and authentic process data when using traceability information, thereby improving the stability and practicality of the traceability system. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this invention. For those skilled in the art, other drawings can be obtained based on these drawings.
[0019] Figure 1 This is a flowchart of the blockchain-based agricultural food source traceability method of the present invention.
[0020] Figure 2 This is a schematic diagram of the modules of the blockchain-based agricultural food source traceability system of the present invention. Detailed Implementation
[0021] Exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, these exemplary embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein; rather, they are provided so that the description of this disclosure will be more complete and fully convey the concept of the exemplary embodiments to those skilled in the art.
[0022] This invention provides, for example Figure 1 The blockchain-based agri-food traceability method shown includes the following steps: In the process of tracing the source of agricultural and food products, the original batch number, splitting record, packaging number and handover time are collected. The collected data are stored in a distributed storage system to generate a batch traceability index, which is used to record the identity continuity information of agricultural and food products throughout the entire process of production, processing, storage, transportation and sales. In the process of tracing the source of agricultural and food products, in order to achieve complete recording of the identity information of agricultural products throughout the entire process of production, processing, storage, transportation and sales, the following steps are taken: This process involves associating the original batch number generated when agricultural products first enter the production stage with key data from the production process. The original batch number is generated based on basic information such as the agricultural product's origin, harvest time, geographical location, and the production entity. Each batch number serves as a unique identifier for subsequent distribution, processing, and packaging. The collection process includes synchronously recording the original batch number along with corresponding raw material information, harvesting environment parameters, and the initial warehousing time. This information is then aggregated in a structured format to the information collection terminal via a pre-defined data interface. During aggregation, the information collection terminal integrates different types of data in a unified format, forming an initial data set with the original batch number and its corresponding time, location, and entity dimensions. This process ensures that each original batch number is consistent with its source information, allowing the agricultural product to use this number as a fundamental identifier for continued identification during subsequent distribution.
[0023] After the initial batch number is generated, the corresponding agricultural product undergoes multiple physical state changes during its distribution, including batch splitting, merging, repackaging, and transshipment. To record these changes, splitting records and packaging numbers need to be collected each time the agricultural product enters a new distribution stage. The splitting record contains information such as the number of new units separated from the original batch, the allocation order, the operation time, and the executing entity. Each splitting operation generates a new packaging number, which maintains a one-to-one or one-to-many correspondence with its original batch number. Through this association, continuous tracking of agricultural products from the original batch to each split and packaged unit can be maintained at the data level. All splitting records and packaging number information are bound to the original batch number after collection, forming an expanded identity association dataset, thereby providing continuous logical clues for subsequent traceability processes.
[0024] After completing the collection of splitting records and packaging numbers, the flow information of agricultural food products across different stages is tracked through handover times. The collection of handover times includes recording the specific time and duration of agricultural products moving from one distribution node to the next, ensuring a clear chronological sequence for each handover during the distribution process. Handover times encompass not only the time of physical transfer but also the confirmation time of the handover operation, the recipient's identity information, and the geographical location of the handover. In this way, a complete time chain of agricultural products across different distribution nodes can be formed at the data level. The handover time, along with the corresponding packaging number, splitting record, and original batch number, forms time-series traceability information. This time-series information maintains a consistent format during collection, allowing subsequent data processing and indexing to directly utilize this time chain to construct the continuity of identity relationships.
[0025] The collected original batch numbers, splitting records, packaging numbers, and handover times are uniformly stored in a distributed storage structure, forming a batch traceability index for the entire agricultural and food process. The storage process includes classifying and organizing all collected data by batch number and sorting it according to the collection order, ensuring data continuity between production, distribution, and packaging information for each batch. The distributed storage structure allows data related to each batch to be stored simultaneously on multiple data nodes, enabling distributed storage and retrieval of information across multiple nodes. During generation, the batch traceability index uses the original batch number as the root node, splitting records and packaging numbers as branch nodes, and the handover time as the time series backbone, forming a multi-dimensional data chain through hierarchical association. After generation, this batch traceability index comprehensively reflects the continuous identity information of agricultural and food products from production to final sale, ensuring consistency in the correspondence between each packaging unit, distribution node, and production node within the data structure. Through this multi-layered information integration, a unified data traceability thread is formed for agricultural and food products throughout their entire lifecycle, providing a structured data foundation for subsequent anomaly identification, batch inheritance, and dynamic correction.
[0026] Based on the batch traceability index, the time sequence, packaging sequence and handover party information are compared item by item. The logical relationship between the data in the batch traceability index is analyzed to detect whether there are abnormal splits or abnormal mergings, and an identity anomaly list is generated as a reference for subsequent traceability analysis. To ensure that the time sequence, packaging sequence, and handover information contained in the batch traceability index remain logically continuous and consistent, the specific implementation steps are as follows: Based on the established batch traceability index, the recorded time sequence information is comprehensively organized and structured. The batch traceability index contains multiple time nodes representing the entire process of agricultural products from production, processing, storage to transportation and sales. Each time node corresponds to a specific production batch, packaging number, and handover record. During the organization process, time is the main thread, arranging the production start time, processing completion time, warehousing time, outbound time, transportation start time, and sales completion time of each batch in chronological order to ensure the continuity between time nodes is preserved. Time data for the same batch appearing at different stages is categorized using time tags, forming a continuous time chain in the batch traceability index. This time chain reflects the actual flow of agricultural products throughout their entire lifecycle, providing a temporal basis for subsequent data logic analysis. At this point, the time sequence information is synchronously associated with the batch number, packaging number, and handover party information, forming the main time logic thread in the batch traceability index.
[0027] After the chronological order is established, the packaging sequences in the batch traceability index are further merged item by item. The packaging sequence includes the physical packaging forms of agricultural products at different stages and their numbering relationships, which is the core content for achieving batch identity continuity. Each packaging number corresponds to one or more upstream original batch numbers. When splitting, combining, or repackaging occurs, changes in the packaging number directly affect the continuity of the traceability chain. To ensure the accurate correspondence between packaging numbers and chronological order, the merging process uses chronological order as the main thread, inserting each packaging number according to its generation time position under the corresponding time node, thus establishing a causal connection between each packaging number and its predecessor. For example, when a batch of products is divided into several small packaging units during processing, these small packaging numbers will be linked to the corresponding processing completion time node, thereby maintaining the synchronous extension of the time chain and the packaging chain. Through this merging method, a continuous mapping relationship between batch number, packaging number, and time node can be established in the data structure, forming a dual logical chain of time and packaging dimensions.
[0028] After organizing the packaging sequence, a comprehensive analysis of the logical relationship between the time chain and the packaging chain is conducted based on the handover information in the batch traceability index. Handover information refers to the handover records between different entities during the circulation of agricultural products, including the initiator, recipient, handover time, and handover stage. The logical consistency between the handover information, the time sequence, and the packaging sequence is a key basis for determining whether abnormal splitting or merging of agricultural products has occurred during circulation. During the analysis, the handover time is used as a key node, and each handover operation is matched with its corresponding packaging number and batch number, compared item by item from front to back in chronological order. If abrupt changes in packaging numbers or discontinuities in quantity relationships occur between adjacent handover nodes, it indicates a possible abnormal splitting or merging. To further ensure the logical consistency between the handover information and the packaging sequence, the handover records for each packaging number are summarized during the analysis, forming a continuous record chain of the flow path of the same packaging number between different handover nodes. In this way, it can be clearly reflected whether the handover process of agricultural products from one entity to another maintains a normal batch transfer relationship. When the handover information, time sequence information, and packaging sequence information are logically completely matched, the identity continuity relationship within the batch traceability index is in a complete state.
[0029] After completing the logical comparison of time sequence, packaging sequence, and handover party information, the anomalies discovered during the analysis are summarized and organized to generate an identity anomaly list. The identity anomaly list is a centralized record of logically conflicting parts in the entire batch traceability index. Its content includes the batch number where the anomaly occurred, the corresponding packaging number, the involved handover parties, and the time range of the anomaly. The process of generating the identity anomaly list involves extracting discontinuous or conflicting data segments from the time chain, packaging chain, and handover chain, and summarizing them in a structured form. Each anomaly record corresponds to a unique anomaly type. For example, anomaly splitting indicates that the same batch was broken down into multiple logically unrelated packaging numbers at the same time point in the time chain, while anomaly merging indicates that multiple batches from different sources were grouped into the same packaging number in the time chain. After the identity anomaly list is generated, it can intuitively reflect the identity misalignment and inconsistent association phenomena in the traceability chain. This list not only contains basic information about the anomaly nodes but also records the time points before and after the anomaly occurred, the packaging change trajectory, and the flow path of the handover parties, thus serving as a core basis in subsequent traceability analysis.
[0030] By using the identity anomaly list to perform backtracking analysis on the on-chain data of the original production node, distribution node and terminal node, the corresponding collection records are extracted from the batch traceability index to determine the time interval of the anomaly and generate an anomaly time distribution map to locate the distribution of the anomaly data in the time dimension. After generating an identity anomaly list through the previous stage of comparison and analysis, to further determine the causes of the anomaly data and its distribution characteristics over time, a backtracking analysis of the batch traceability index can be performed based on the identity anomaly list. This, combined with the on-chain data from the original production nodes, distribution nodes, and terminal nodes, will complete the extraction of anomaly time intervals and the generation of anomaly time distribution maps. The specific implementation steps are as follows: Based on the anomaly records in the anomaly identification list, the original production node, distribution node, and terminal node information corresponding to each anomaly are determined. The anomaly identification list records the anomaly batch number, packaging number, handover party information, and a preliminary description of the anomaly time range, providing a data entry point for subsequent backtracking analysis. In this step, using the anomaly batch number as the core index, the corresponding node information is extracted item by item from the batch traceability index. Each node information includes the node name, node category, node participation time, and the node's on-chain record address. The original production node typically corresponds to the planting or initial processing stage of agricultural products, the distribution node corresponds to the intermediate warehousing, transportation, or wholesale stage, and the terminal node corresponds to the retail or consumption stage. By mapping the batch numbers in the anomaly identification list to the node information in the batch traceability index, the complete circulation process chain involved in the anomaly data can be determined, establishing a structured data association relationship for subsequent time-dimensional analysis.
[0031] After the node information is determined, the on-chain data corresponding to each node is traced back layer by layer. The tracing process uses the time range in the identity anomaly list as a guide, starting from the original production node and sequentially retrieving the on-chain data of each node along the actual circulation process of agricultural products. Each on-chain operation includes the data content uploaded by the node, timestamp, identity of the data submitter, and on-chain sequence number. By comparing this on-chain information, the data transmission status between nodes before and after the abnormal time period can be clearly identified. In the on-chain data of the original production node, the initial production data related to the original batch number is extracted, including the production start time, harvest time, and initial warehousing time; in the on-chain data of the distribution node, the corresponding storage time, inbound / outbound time, and transportation handover time are extracted; in the on-chain data of the terminal node, the sales on-chain time and consumer scanning behavior records are extracted. Through this hierarchical tracing process, the abnormal records in the identity anomaly list can be correlated with the on-chain data of each node, so that the context data of the anomaly can be completely restored. The process logically maintains the continuity of the timeline, enabling the on-chain data of each node to form a unified time reference framework with the identity anomaly list.
[0032] After completing the node data backtracking, the collected data corresponding to the abnormal records is extracted from the batch traceability index to further determine the specific time interval of the abnormality. The batch traceability index contains multi-dimensional information from the original collection stage, including multiple time parameters such as production time, packaging time, transportation time, and sales time. By cross-analyzing these time parameters with the abnormal time periods in the identity anomaly list, the concentrated distribution range of abnormal data in the time dimension can be located. To ensure the accuracy of the time interval, the time order of the data is kept consistent during the extraction process, so that the interval relationship between each time point and its preceding and following nodes is preserved. In this way, it can be determined whether the anomaly occurred in the production, distribution, or terminal stage, and its starting and ending points can be clearly identified. For example, when multiple packaging numbers are found to be repeatedly uploaded to the chain in the same time period in the distribution node, and the original production node has not generated a corresponding batch branch, it can be determined that the time interval of the anomaly is located in the mid-operation stage of the distribution node. Through this method of extracting time intervals, the clustering characteristics of anomalies in the time dimension are presented, providing an accurate time basis for subsequent anomaly visualization.
[0033] Based on defined time intervals, an anomaly time distribution map is generated to visually reflect the distribution characteristics of anomalous data over time. The map uses time as the horizontal axis and node category as the vertical axis, visually representing the start and end times of each anomalous event and the nodes involved as segments. During generation, time node information extracted from the batch tracing index is overlaid with anomaly type information from the identity anomaly list, resulting in different time period markers for each anomaly type. For example, anomaly splitting events are marked with different colored segments on the corresponding time axis, while anomaly merging events are marked with segments within the transition time interval between nodes. This method presents the concentrated distribution areas of anomalous data and their node relationships over time. The anomaly time distribution map not only includes temporal continuity but also upstream and downstream logical relationships between nodes, ensuring a complete mapping of each anomalous event in both time and spatial dimensions. This distribution map allows for the intuitive identification of the formation process, occurrence stages, and duration of anomalous events, providing a structured analytical basis for subsequent batch inheritance and dynamic correction.
[0034] Based on the abnormal time distribution map, an inheritance instruction is issued to extend the original batch number to the corresponding split packaging unit, establish a one-to-many mapping relationship between the original batch and each split packaging unit, and generate a batch inheritance list to achieve identity continuation between different packaging units. To ensure the continuity of the original batch number throughout the multi-level splitting and repackaging process and to achieve logical mapping between different packaging units, inheritance instructions can be issued based on the anomaly time distribution map to extend each batch, establishing a one-to-many correspondence between the original batch and the splitting and repackaging units, thereby generating a batch inheritance list. The specific steps are as follows: Based on the abnormal time intervals presented in the abnormal time distribution map, the temporal relationship between the corresponding original batch number and the involved splitting and packaging units is determined. The abnormal time distribution map reflects the time span and node distribution of abnormal events between different nodes, with each abnormal segment corresponding to a specific production, distribution, or terminal link. In this stage, by reading the abnormal start and end times in the abnormal time distribution map, these time intervals are matched with the time nodes in the batch traceability index to filter out batch records that underwent batch splitting, repackaging, or distribution operations within the abnormal time period. The original batch number serves as the upstream identifier, and the splitting and packaging unit serves as the downstream identifier, maintaining a time-to-late sequential relationship. This time matching method allows for the determination at the data level of which splitting and packaging units have a temporal continuity with the original batch number, providing a logical basis for subsequent inheritance instructions. Throughout this process, time information, batch numbers, and packaging numbers maintain a unified format, ensuring structural continuity in the timeline between the original batch and derived batches.
[0035] After determining the time correlation, inheritance instructions are issued based on the distribution patterns of the abnormal time distribution map, targeting the relationship between batch numbers and packaging numbers within the abnormal time period. The purpose of these inheritance instructions is to extend the identity of the original batch number to all split packaging units derived from it within the abnormal time period, ensuring that each downstream packaging unit can be traced back to its corresponding original batch number. Inheritance instructions are generated based on the original batch number, matching its identity information, production node information, and on-chain time with the packaging number and formation time of the split packaging unit. Each inheritance instruction clearly defines the correspondence between the original batch number and the target packaging unit number, including the time span, circulation path, and participating entity information within the inheritance relationship. This approach logically extends the original batch number to all packaging units whose time intervals overlap with itss and whose origins are consistent, thus forming a continuous identity mapping chain in the data structure. The issuance of inheritance instructions maintains a dependence on the time distribution, ensuring that each inheritance relationship can be traced back to the corresponding time period in the abnormal time distribution map, thereby guaranteeing the consistency of batch identity continuation across the time dimension.
[0036] After the inheritance instruction is issued, a one-to-many mapping relationship is established between the original batch number and each split packaging unit, based on the batch correspondence established in the inheritance instruction. This mapping relationship uses the original batch number as the parent node and all split packaging unit numbers as child nodes, arranged sequentially according to the time and distribution order determined in the inheritance instruction. The construction process of the mapping relationship includes batch number extension processing, packaging number classification, and time segment hierarchical organization. Each original batch number can correspond to several packaging units formed at different times, and each packaging unit can continue to form new split units in subsequent stages. Through this one-to-many mapping relationship, the branching evolution path of the batch can be accurately reflected in the data structure, giving each packaging unit a clear source indication. This mapping relationship not only records the correspondence between batch numbers and packaging numbers but also includes their respective time nodes and handover stages, thus maintaining the integrity of the identity inheritance logical chain in both time and space dimensions. In this way, agricultural food products can maintain their identity connection with the original batch number even after undergoing multiple repackaging, transshipment, and sales processes.
[0037] After establishing a one-to-many mapping relationship between the original batch number and the split packaging unit, all inheritance relationships are integrated and organized to generate a batch inheritance list. The batch inheritance list records the original batch number, derived packaging number, inheritance time interval, and distribution path information in a structured manner. Each record in the list clearly specifies the number of downstream packaging units corresponding to the original batch number, the start and end points of the inheritance time, the handover node, and the participating entities. This structured batch inheritance list comprehensively presents the identity continuation process of agricultural food products throughout the entire production, distribution, and sales process. The process of generating the batch inheritance list not only integrates the mapping information in the inheritance instructions but also sorts the inheritance chain according to the time distribution relationship, ensuring that the inheritance logic between different batches is arranged in chronological order in the list, guaranteeing accurate recall during subsequent dynamic correction. After the batch inheritance list is generated, each packaging unit is explicitly associated with its original batch number at the data level, thereby realizing the hierarchical transfer of identity. This list visually demonstrates the identity continuation chain from the original batch to the final sales packaging, providing a complete batch inheritance basis for tracing the origin of agricultural food products.
[0038] Based on the batch inheritance list, the collaborative operation of reverse supplementation and forward freezing is performed to fill the historical records back to the correct source node, and the identity change is temporarily frozen at the node where the batch split is about to occur. Then, it is gradually unlocked in a time step manner to realize the dynamic correction of the identity of agricultural food and the maintenance of consistency of on-chain records throughout the entire life cycle. To achieve dynamic identity correction and on-chain record consistency maintenance throughout the entire lifecycle after the batch inheritance relationship is established, historical data can be retroactively recorded based on the batch inheritance list. A forward freeze operation can be performed on nodes that are about to undergo batch splitting. After the freeze is lifted, the identity changes of the nodes are gradually restored in a time-step manner, thereby achieving dynamic balance and continuous updating of agricultural and food identity data at each stage. The specific implementation steps are as follows: Based on the one-to-many mapping relationship between the original batch number and each split packaging unit established in the batch inheritance list, historical on-chain records are traced and identified to clarify the correct source node for each downstream packaging unit. The batch inheritance list contains the original batch number, derived packaging number, inheritance time interval, and handover node information; each entry corresponds to an actual batch continuation path. In this stage, the source node information for each packaging unit within its lifecycle is determined by comparing the data in the batch inheritance list with the historical on-chain records in the batch traceability index. Source nodes include production nodes, distribution nodes, and terminal nodes, each corresponding to a specific on-chain time and data record. When a discrepancy is found between the batch number or packaging number in the historical on-chain data and the source node recorded in the inheritance list, the correct source node is redirected based on the inheritance relationship established in the list. In this way, a precise correspondence between batch numbers and source nodes can be established, providing a structured reference for subsequent reverse data entry. This step integrates batch inheritance relationships with historical records, enabling each packaging unit to be logically traced back to its original batch source.
[0039] After the source node is determined, a reverse recording operation is performed on the historical on-chain records based on the inheritance time interval recorded in the batch inheritance list. The core objective of reverse recording is to fill in the gaps in the identity chain caused by batch breaks, packaging regeneration, or node information loss. Specifically, starting with each original batch number, records are recorded item by item along the inheritance time interval from earliest to latest, corresponding to the missing records within that time period. The recorded content includes the batch number, packaging number, handover time, handover party, and corresponding circulation information. Through this recording method, the broken identity chain can be reconnected, restoring the continuity of records on the chain in time sequence. During the reverse recording process, all newly recorded records maintain the same format and structure as the original on-chain data to ensure the logical coherence of historical records. Once the recording is completed, the batch transfer relationship between agricultural food products and different nodes is reconnected, the identity continuation chain is restored to completeness, and the foundation is laid for subsequent forward freezing and dynamic unlocking operations.
[0040] After reverse data entry is completed, to prevent batch information breaks or crossover errors from occurring again during subsequent circulation, a forward freeze operation is performed on nodes that are about to undergo batch splitting. The purpose of the forward freeze operation is to temporarily lock the identity change permissions of nodes that are about to be split, repackaged, or handed over after the batch identity relationship is re-established, preventing the node from generating new packaging numbers or modifying existing batch information during the freeze period. When executing the freeze, the node marked as "about to be split" in the batch inheritance list is targeted, and the corresponding batch number, packaging number, and time information of the node are temporarily frozen to ensure that they are not updated during the freeze period. The duration of the freeze operation is set according to the time step interval, consistent with the time interval in the batch inheritance list. When the freeze state takes effect, all data associated with the node is temporarily marked as read-only in the distributed storage structure, thereby avoiding new data discrepancies during identity correction. Through the forward freeze operation, the batch inheritance chain can be prevented from being interrupted during the correction process, ensuring that the identity continuation logic remains stable during the transition phase.
[0041] After the forward freeze period ends, frozen nodes are gradually unlocked in a time-step manner to achieve dynamic correction of agricultural food identities and maintain consistency of on-chain records. The time-step approach refers to restoring the identity change capability of each node step-by-step according to the time intervals in the batch inheritance list. Each unlocking operation is based on the data correction results of the previous time period, ensuring the integrity of the data continuity chain during the recovery process. During unlocking, the earliest frozen node is unfrozen first, enabling it to re-execute normal on-chain operations; subsequently, subsequent nodes are unfrozen in sequence, resulting in a sequential recovery process of identity changes over time. This time-step unlocking mechanism ensures that data correction and on-chain operations for agricultural food are synchronized across different nodes, preventing sudden changes or conflicts in batch identities within a short period. As all nodes are gradually unfrozen, the identity data of agricultural food throughout the entire process of production, distribution, and sales is comprehensively updated, ensuring that on-chain records logically align with the actual circulation process, thus achieving a closed loop of data consistency maintenance and dynamic correction.
[0042] This invention establishes a batch traceability index throughout the entire agricultural and food process, enabling unified collection and storage of original batch numbers, splitting records, packaging numbers, and handover times. This ensures that data generated at each stage remains continuously linked on the chain. By constructing a dual index structure along both the time and packaging dimensions, it guarantees that the identity information of agricultural and food products remains unbroken during distribution, allowing for continuous tracking back to the source and achieving full batch-level traceability. This method effectively avoids identity confusion caused by batch splitting or merging, ensuring consistency in the recording and display of food origin information, thereby improving the accuracy of traceability results and the reliability of data records.
[0043] This invention constructs a batch inheritance list and combines it with a collaborative mechanism of reverse data entry and forward freezing to ensure logical consistency of on-chain data during dynamic changes. By backfilling historical records and freezing future nodes, it achieves adaptive correction of agricultural and food identity information throughout its entire lifecycle, enabling continuous updating of blockchain data over time. This approach guarantees the integrity of traceability information across multiple nodes and batches, allowing regulatory bodies, producers, and consumers to obtain accurate source chains and authentic process data when using traceability information, thereby improving the stability and practicality of the traceability system.
[0044] This invention provides, for example Figure 2 The blockchain-based agricultural food traceability system shown includes a batch index construction module, an anomaly detection module, an anomaly backtracking module, a batch inheritance module, and a dynamic correction module. The batch index building module collects the original batch number, split record, packaging number and handover time in the agricultural food source traceability process. The collected data is uniformly stored in the distributed storage system to generate a batch traceability index, which is used to record the identity continuity information of agricultural food throughout the entire process of production, processing, storage, transportation and sales. The anomaly detection module compares the time sequence, packaging sequence, and handover information item by item based on the batch traceability index, analyzes the logical relationship between the data in the batch traceability index, detects whether there are abnormal splits or abnormal mergings, and generates an identity anomaly list as a reference for subsequent traceability analysis. The anomaly backtracking module uses the identity anomaly list to backtrack and analyze the on-chain data of the original production node, distribution node and terminal node, extracts the corresponding collection records from the batch traceability index, determines the time interval of the anomaly, and generates an anomaly time distribution map to locate the distribution of anomaly data in the time dimension. The batch inheritance module issues inheritance instructions based on the abnormal time distribution map, extends the original batch number to the corresponding split packaging unit, establishes a one-to-many mapping relationship between the original batch and each split packaging unit, and generates a batch inheritance list to achieve identity continuation between different packaging units. The dynamic correction module performs a collaborative operation of reverse supplementation and forward freezing based on the batch inheritance list, backfilling historical records to the correct source node, and temporarily freezing identity changes at nodes where batch splitting is about to occur. Subsequently, it gradually unlocks the identity in a time-step manner, realizing dynamic identity correction and on-chain record consistency maintenance for agricultural and food products throughout their entire life cycle.
[0045] The blockchain-based agricultural food source traceability method provided in this embodiment of the invention is implemented through the aforementioned blockchain-based agricultural food source traceability system. For details of the specific methods and processes of the blockchain-based agricultural food source traceability system, please refer to the embodiments of the aforementioned blockchain-based agricultural food source traceability method, which will not be repeated here.
[0046] The foregoing has only described certain exemplary embodiments of the present invention by way of illustration. Undoubtedly, those skilled in the art can modify the described embodiments in various ways without departing from the spirit and scope of the present invention. Therefore, the foregoing drawings and descriptions are illustrative in nature and should not be construed as limiting the scope of protection of the claims of the present invention.
Claims
1. A blockchain-based method for tracing the origin of agricultural and food products, characterized in that: Includes the following steps: In the agricultural and food source traceability process, the original batch number, splitting record, packaging number and handover time are collected, and the collected data are uniformly stored in a distributed storage system to generate a batch traceability index. Based on the batch traceability index, the time sequence, packaging sequence and handover party information are compared item by item. The logical relationship between the data in the batch traceability index is analyzed to detect whether there are abnormal splits or abnormal mergings, and an identity anomaly list is generated. By using the identity anomaly list to perform backtracking analysis on the on-chain data of the original production node, distribution node and terminal node, the corresponding collection records are extracted from the batch traceability index to determine the time interval of the anomaly and generate an anomaly time distribution map. Based on the abnormal time distribution map, an inheritance instruction is issued to extend the original batch number to the corresponding split packaging unit, establish a one-to-many mapping relationship between the original batch and each split packaging unit, and generate a batch inheritance list; Based on the batch inheritance list, a collaborative operation of reverse data entry and forward freezing is performed to backfill historical records to the correct source node, and identity changes are temporarily frozen at the node where a batch split is about to occur, and then gradually unlocked in a time-step manner.
2. The blockchain-based agricultural food source traceability method according to claim 1, characterized in that, The steps for generating a batch traceability index are as follows: The original batch number generated when agricultural food enters the production process is associated with key data in the production process and collected. The original batch number is recorded synchronously with raw material information, harvesting environment parameters and first storage time to form an initial data set. After the original batch number is generated, the splitting records and packaging numbers of agricultural products during the circulation process are collected. The splitting records are bound to the original batch number to form an expanded identity association dataset, enabling continuous tracking from batch to packaging unit. After completing the collection of splitting records and packaging numbers, the flow information of agricultural products between different nodes is recorded by the handover time, and the handover time is uniformly associated with the packaging number, splitting record and original batch number to form time-series traceability information; The original batch number, splitting record, packaging number, and handover time are stored in a distributed storage structure and sorted according to the collection order to generate a batch traceability index.
3. The blockchain-based agricultural food source traceability method according to claim 2, characterized in that, In the process of generating the batch traceability index, the original batch number is used as the root node, the split record and packaging number are used as branch nodes, and the handover time is used as the time series backbone. Various types of data are classified and organized according to time order and hierarchical relationship to form a multi-dimensional data chain, so that agricultural food forms a continuous identity continuity structure throughout the whole process.
4. The blockchain-based agricultural food source traceability method according to claim 2, characterized in that, The steps for generating an identity anomaly list are as follows: Based on the batch traceability index, the time sequence information of the records is organized, and the production time, processing time, warehousing time, outbound time, transportation time and sales time of each batch are arranged in chronological order. After the time sequence is sorted out, the packaging sequence in the batch traceability index is merged. Taking the time sequence as the main line, each packaging number is inserted under the corresponding time node, so that a continuous mapping relationship is formed between the batch number, packaging number and time node. After the packaging sequence is sorted out, the time chain and packaging chain are comprehensively analyzed based on the handover party information in the batch traceability index. The handover time is matched with the packaging number and batch number, and abnormal splitting and abnormal merging are identified by comparing each item. After the analysis, the anomaly splitting and merging cases are summarized and organized, and conflicting data fragments are extracted from the time chain, packaging chain and handover chain to generate an identity anomaly list.
5. The blockchain-based agricultural food source traceability method according to claim 4, characterized in that, When generating the identity anomaly list, the batch numbers and packaging numbers of the anomaly splitting and merging are grouped in chronological order, and the time range of the anomalies is divided into segments in combination with the flow path information of the handover party, so that each anomaly record corresponds to a unique time interval and handover node.
6. The blockchain-based agricultural food source traceability method according to claim 4, characterized in that, The steps for generating an anomaly time distribution map are as follows: Based on the abnormal records in the identity abnormality list, the original production node, distribution node and terminal node information corresponding to each abnormality are determined, and the abnormal batch number is matched with the node information in the batch traceability index item by item to form a complete circulation process chain. After the node information is determined, the on-chain data corresponding to each node is backtracked. Taking the time range in the identity anomaly list as a clue, the on-chain data is retrieved sequentially starting from the original production node to establish the time correspondence between the anomaly record and the node data. After completing the node data backtracking, the collected data corresponding to the abnormal records is extracted from the batch traceability index, and cross-analysis is performed based on the time parameters and the abnormal time period to determine the specific time interval in which the abnormality occurred. An abnormal time distribution map is generated based on the determined time interval information. With time as the main axis and node category as the reference axis, the start time, end time and involved nodes of the abnormal event are visualized.
7. The blockchain-based agricultural food source traceability method according to claim 6, characterized in that, In the process of generating the abnormal time distribution map, the time node information in the batch traceability index is superimposed with the abnormal type information in the identity abnormality list, so that different types of abnormal events are displayed in segments on the time axis. The vertical correspondence of node categories is used to show the time continuity of abnormal events in different stages, thereby reflecting the distribution status of abnormal data synchronously in the time dimension and node dimension.
8. The blockchain-based agricultural food source traceability method according to claim 6, characterized in that, The steps for generating a batch inheritance list are as follows: Based on the abnormal time interval information presented in the abnormal time distribution map, the time correlation between the original batch number and the involved split packaging unit is determined. By matching the abnormal start time and end time, the records of batch splitting, repackaging or circulation operations that occurred within the abnormal time period are filtered. After the time correlation is determined, an inheritance instruction is issued based on the distribution pattern of the abnormal time distribution map, extending the identity of the original batch number to all split packaging units derived within the abnormal time period, and recording the time span, circulation path and participating entity information. After the inheritance instruction is issued, based on the batch correspondence established in the inheritance instruction, a one-to-many mapping relationship between the original batch number and the split packaging unit is established, and a continuous identity chain is formed according to the time sequence and circulation sequence. After the mapping relationship is established, all inheritance relationships are integrated and organized to generate a batch inheritance list, recording the original batch number, derived packaging number, inheritance time interval, and circulation path information.
9. The blockchain-based agricultural food source traceability method according to claim 8, characterized in that, Based on the batch inheritance list, a combined reverse data entry and forward freeze operation is performed to backfill historical records to the correct source node. Identity is frozen at the node where the batch split is about to occur, and the nodes are gradually unlocked according to a time-step approach, as follows: Based on the one-to-many mapping relationship between the original batch number and the split packaging unit established in the batch inheritance list, the historical chain records are traced and identified, and each downstream packaging unit is mapped to the correct source node, thus establishing the correspondence between the batch number and the source node. After the source node is determined, based on the inheritance time interval recorded in the batch inheritance list, the historical chain record is reversed and supplemented. The batch number, packaging number, handover time, handover party and circulation information are supplemented in chronological order to restore the continuity of the broken identity chain. After the reverse data entry is completed, a forward freeze operation is performed on the nodes that are about to be split into batches, temporarily locking the batch number, packaging number and time information of the nodes to ensure that the data is not updated during the freeze period. After the forward freeze period ends, the frozen nodes are gradually unlocked in a time-step manner, restoring the ability of each node to change its identity.
10. A blockchain-based agricultural food source traceability system, used to implement the blockchain-based agricultural food source traceability method according to any one of claims 1-9, characterized in that, It includes a batch index building module, an anomaly detection module, an anomaly backtracking module, a batch inheritance module, and a dynamic correction module: The batch index building module collects the original batch number, split record, packaging number and handover time in the agricultural and food source traceability process, and stores the collected data into a distributed storage system to generate a batch traceability index. The anomaly detection module compares the time sequence, packaging sequence, and handover party information item by item based on the batch traceability index, analyzes the logical relationship between the data in the batch traceability index, detects whether there are abnormal splits or abnormal mergings, and generates an identity anomaly list. The anomaly backtracking module uses the identity anomaly list to backtrack and analyze the on-chain data of the original production node, distribution node and terminal node, extracts the corresponding collection records from the batch traceability index, determines the time interval of the anomaly, and generates an anomaly time distribution map. The batch inheritance module issues inheritance instructions based on the abnormal time distribution map, extends the original batch number to the corresponding split packaging unit, establishes a one-to-many mapping relationship between the original batch and each split packaging unit, and generates a batch inheritance list. The dynamic correction module performs a collaborative operation of reverse data entry and forward freezing based on the batch inheritance list, backfilling historical records to the correct source node, and temporarily freezing identity changes at nodes where batch splitting is about to occur, and then gradually unlocking them in a time-step manner.