Abstract
The quality and safety of agricultural products cannot be separated from rural revitalization. This is also related to the interests and development of participating in the agricultural supply chain. The traditional unitary agricultural product quality supervision system meets the growing market demand and requirements. This paper constructs the traceability and blockchain of agricultural products supply chain, as well as the trusted computing model of Internet of things nodes based on blockchain. The results show that the trusted computing model of IOT nodes based on blockchain can effectively identify and remove malicious nodes, ensure the effectiveness, tamperability, security, and reliability of agricultural product process data, greatly reduce the transaction delay, and provide a guarantee.
1. Introduction
Food is a very important part of people’s life. A qualified food inspection report is an important voucher for solving quality disputes. False inspection and testing reports not only disrupt the normal business order, but also may cause product quality problems and pose potential risks to consumers’ life, health, and property safety. The exposure of the “cadmium rice” incident, the smuggling of frozen meat incident, and the crayfish incident has led to the continuous improvement of consumers’ awareness of food safety. There are many kinds and large quantities of agricultural products. The traditional supervision model not only needs high cost but also relatively low efficiency. At the same time, it does not build a complete and effective information disclosure mechanism food quality and safety information, resulting in serious asymmetry of information and failure of supervision [1]. Agricultural departments at all levels should make every effort to promote the achievement in positive progress and results and to ensure the quality and safety of agricultural products and maintain an overall stable and gradually improving trend.
Compared with the other products, agricultural products need to go through multiple links from planting and production to genuine consumers, and agricultural products themselves are organic organisms, which have the problems of preservation, storage, and transportation and easy decay [2]. Therefore, there are safety risks in any link of agricultural products. To explore the establishment of the environmental safety monitoring and evaluation system for the producing areas of agricultural products, we need to concentrate our efforts on exploring the products, the suburbs of the surrounding areas of industrial and mining enterprises, and other key areas. Most scholars believe that this is due to the simplification of the quality and safety supervision system of agricultural products, which is prone to problems such as blind spots and low efficiency [3, 4]. It is difficult for consumers to identify the responsibility subject of agricultural products, and the division of responsibility is not clear [5, 6]. Other scholars pointed out that the detection system of food additives, harmful substances, and other substances in the quality inspection process of each link in the whole agricultural product supply chain is not perfect, the strength and quantity of detection cannot meet the product regulatory market, and there is a lack of corresponding professional quality inspection talents and effective quality inspection methods [7, 8]. In addition, some scholars pointed out that some agricultural products are vulnerable to pollution in the process of storage and transportation, while there is a lack of reasonable and scientific supervision system for storage and transportation in the safety and quality inspection of agricultural products, and the information transparency of agricultural product supply chain is low [9, 10].
Ensuring the major task in the new stage of agricultural development, but also a major responsibility for the agricultural department to perform its duties according to law. Some scholars proposed to build the management system of agricultural key control points, so as to quickly perceive and timely feed back the harmful substances existing from planting to processing and sales, so as to ensure the quality and safety of agricultural products [11]. Other scholars have applied bar code and vegetables and agricultural products, which improves the efficiency of agricultural product information traceability. It can effectively monitor the quality and safety and enable consumers to carry out effective information traceability [12, 13]. The production team, time, and process of products can be traced through bar code. It is through tracing management to investigate the quality of the person accident, so as to increase the awareness of the producers and operators [14]. In addition, some scholars have effectively combined blockchain technology with RFID, QR code, and other technologies to build a real-time data tracking system for all links put on the chain [15, 16]. At the same time, some scholars pointed out that the application of product traceability system still has security and distribution problems, which should be optimized and improved in combination with other technologies, and the query function of blockchain system has been expanded in an easy to implement way [17, 18].
The development of agricultural product traceability system can recall the existing agricultural products, reduce the damage to the interests of consumers, and clarify the responsibilities of relevant enterprises. Consumers and enterprises can reduce the cost of obtaining relevant information, improve the credibility of agricultural products, and promote the development of transaction rate and brand of agricultural products [19]. Enterprises can better improve management efficiency, optimize product quality, and improve the overall market core competitiveness by using relevant information.
2. Agricultural Product Tracking System
The quality and safety traceability system and traceability system of agricultural products have also been gradually built, and great changes have taken place in its production field. At present, there are many traceability systems for agricultural products in China. These traceability systems can trace the source of agricultural products to a certain extent. However, compared with foreign traceability systems, there is a lack of unified standards and cannot be shared among provinces, which seriously affects the implementation and promotion of traceability systems. China is rich in agricultural products. The establishment of a quality traceability system can greatly promote the standardization, and systematization of the planting of characteristic agricultural products. It can play a positive role in improving the quality of agricultural products, strengthening the market competitiveness of products, and protecting characteristic resources.
The supply chain of agricultural products needs to go through many links from production to sales. There may be safety and quality problems in each link, and the subject of responsibility in each link is different. At the same time, agricultural products have a wide variety, short shelf life, difficult storage, and different needs for transportation environmental conditions. Therefore, the traceability link of agricultural products supply chain is complex and the main body is changeable. The normal system is not only inefficient, but also difficult to ensure the reliability of agricultural product safety information, and cannot meet the pursuit and demand of consumers [20]. The key to the traceability is to build a complete and continuous information system combining supply chain and logistics to ensure the information transparency of agricultural products in the whole supply chain, so as to realize the forward and reverse traceability and accountability of farm product supply chain in a short time. Internet of things technology can build a traceable chain system and solve the quality and safety problems through intelligent management and control. However, the system has the problems of low information reliability and data can be tampered with, and it is difficult to share traceability information among different enterprises [21]. The blockchain is not only traceable in the whole process, but also has the characteristics of unforgeability, openness, transparency, and decentralization. The combination of the two can learn from each other, locate and detect malicious nodes of the Internet of things, optimize data storage, improve identity authentication, make the traceability information of agricultural products supply chain completely open and transparent, realize the efficient transmission of credit risk-free and leverage free between things, and ensure the reliability and integrity of agricultural products supply chain information.
2.1. Construction of Traceability System
Agricultural product traceability system refers to the system that tracks the entry of agricultural products (including food and means of production) into the market at all stages (the whole process from production to circulation). It involves many links such as the origin, processing, transportation, wholesale, and sales of agricultural products, which is conducive to quality control and recall of products when necessary. The traceability system of agricultural products can realize the traceability from the source of products to the processing and circulation process, ensure that end users can buy assured products, and prevent fake and shoddy agricultural products from entering the market.
As shown in Figure 1, it is a product safety traceability system. The system introduces blockchain technology and superimposes the operation rules of the agricultural product supply chain product safety traceability system. The system mainly includes four layers. The physical layer uses an equipment to realize the automatic data collection, transmission, and management of agricultural products in different links. The data layer, that is, the node with accounting right. The blockchain generates timestamp data signatures that can correspond to agricultural products one by one, and uses distributed data storage to ensure the integrity of the data. The data layer can realize the sharing of agricultural product data information, promote, and avoid the problem of information island. The core layer, i.e., blockchain, embeds the laws, and tests whether the uploaded data complies with the relevant contract provisions, which promotes the development of standardized and intelligent supervision of agricultural products and greatly improves the supervision efficiency. The application layer is that all enterprises and consumers in the agricultural product supply chain can query and trace the relevant agricultural product quality and safety information data through computers or mobile intelligent terminals.

As shown in Figure 1, it is a product safety traceability system based on the Internet of things and blockchain. The system introduces and superimposes the operation rules of the agricultural product supply chain product safety traceability system. The system mainly includes four layers. The physical layer uses equipment to realize the automatic data collection, transmission, and management of agricultural products in different links. The data layer, that is, the node with accounting right, writes the relevant data into the block and encapsulates it. At the same time, the blockchain generates timestamp data signatures that can correspond to agricultural products one by one, and uses distributed data storage to ensure the integrity of the data. The data layer can realize the sharing of agricultural product data information, promote the efficiency of information transmission, and avoid the problem of information island. The core layer, i.e., blockchain in the form of smart contract, and tests whether the uploaded data complies with the relevant contract provisions, which promotes the development of standardized and intelligent supervision of agricultural products and greatly improves the supervision efficiency. The application layer is that all enterprises and consumers can query and trace the relevant agricultural product quality and safety information data through computers or mobile intelligent terminals.
2.2. Construction of Trusted Computing Model of Internet of Things Nodes Based on Blockchain
The wireless sensor network of the Internet of things includes multiple microsensor nodes, which can cover a wide area, deploy quickly, and monitor remotely. It has high accuracy; WSNs nodes are vulnerable to the threat of malicious nodes due to their large number of nodes and relatively weak perception. Distributed algorithms in the Internet of things depend on single agent computing. However, it is vulnerable to data injection attacks from internal malicious nodes. Most of the existing detection methods run locally, and there are problems such as data closure, single point of failure, and opaque detection process. We can consider using blockchain technology and smart contract to detect malicious nodes in the network. Based on the decentralization and multilocation backup characteristics of blockchain technology, the proposed method realizes data sharing and avoids the problem of single point of failure.
One of the most valuable attributes of most blockchain applications is “Trustlessness,” that is, the application can keep running in the expected way without relying on specific participants to act in a specific form, even if their relevant interests may change in the future and make them make unexpected actions. Blockchain applications are never completely trust free, but some applications are more trust free than others.
Therefore, this paper combines the blockchain trust model to detect malicious nodes in the Internet of things framework, so as to curb the interference of malicious nodes and improve the security, authenticity, and reliability of traceability information in the agricultural supply chain. Figure 2 shows the blockchain trust model.

Let the model be abbreviated as , which is an octet, as shown in (1):where, the contract publishing point is and its finite set is , the CA node and verification node are and its finite set is , the ordinary node is and its finite set is , the blockchain for malicious node detection of WSNs is , its smart contract is , the mapping function of ordinary nodes and in the blockchain is , and the location list of ordinary nodes is .
Smart contracts are also octets, as shown in (2):
In the formula, publisher is , authorized stock sink node is , candidate malicious node is , malicious sensor evaluation index is , reputation is , data structure is , and WSNs positioning method represents as .
The evaluation of malicious nodes has certain subjectivity and uncertainty. Therefore, this paper selects four evaluation indexes. Let the processing delay be expressed as , and its evaluation value range is shown in formula (3):where, the time taken by the sensor to complete data reception and transmission in time interval is expressed as .
The evaluation range of forwarding rate is shown in formula (4):
The range of response time evaluation value is shown in formula (5):where, the response time is expressed as , the propagation speed is expressed as , and a certain time interval is expressed as .
The final single communication quality of the sensor node is shown in formula (6):where the single communication quality is expressed as , the weight of processing delay is expressed as , the weight of forwarding rate is expressed as , the weight of response time is expressed as , and . Set the threshold and when , the number of successful communication of the node increases once, otherwise the number of failed communication increases once. Calculate the node credit according to the number of successful and failed communications, as shown in formula (7):where, the node credit is expressed as .
Because it is difficult to obtain the location information of all nodes in the initial stage of the sensor network system, this paper divides the terminal nodes into two types: the anchor node set with known location and the unknown node set without knowing its location. The nodes with unknown location can be obtained by four-sided measurement method. Let the distance between the expressed as respectively, then the calculation formula of node position data is shown in formula (8):
In this paper, the frequent exchange of noncritical data is carried out through the DCPN model. Due to the time attribute of frequent exchange of noncritical data, this paper constructs a delay control Petri net, which is ten tuples, as shown in (9):where and represent all finite sets of conventional discrete library and all finite sets of fuzzy library are ; and , is a finite set with finite delay; represents the finite set of arcs; represents a finite set of suppression arcs; denotes a finite set of control arcs; represents the time delay function of , means that the transition needs time units to complete; is the time delay control function on ; is the confidence function of ; is the output function of ; indicates initial identification. In the running rule, if the condition is satisfied in , the transition of has the right to occur, which is expressed as ; When , if , , the change of the identification has the right to occur, that is, it is expressed as ; Under the condition of , the change will generate a new identification , which is expressed as , and its expression is shown in (10):
Under the condition of , , and , the time delay control function is shown in formula (11):where the constant is expressed as .
Under condition, , and , the expression of confidence function is shown in (12):where the constant is , and the state component product of all ’s pre libraries is expressed as .
Under the condition of , , , and , the output function expression is shown in (13):
In this paper, the credit rating is used to evaluate the dynamic credit status of the initiator, as shown in formulas (14)–(16):
Among them, the element summation function in the set is expressed as , the counting function is expressed as , and the corresponding bad data exchange penalty coefficient is expressed as .
3. Experimental Results and Analysis of Traceability System
3.1. Experimental Results and Analysis of Network Node Trusted Computing Model
The data management center sends various data of agricultural products to the monitoring personnel, which improves the production and processing level of agricultural products. When there are safety risks in agricultural products, the network monitoring system will carry out automatic early warning and classify the risk level. To ensure the quality of agricultural products, it is imperative to apply the network information monitoring platform for data management. In order to test the trusted computing model of IOT nodes, the feasibility of the malicious node detection model of wireless sensor networks based on blockchain trust model is verified. In the experiment, the sensors to be tested are positioned accordingly, and in order, all nodes will be clustered, as shown in Figure 3, which is the contract address of each node and the number of nodes covered in the smart contract.

In order to further detect malicious sensors, all credits are calculated, and the results are shown in Figure 4. In Figure 4, the abscissa is the sensor ID and the ordinate is the credit rating.

From the experiment based on the blockchain trust model, it can be seen that the model has a distributed data structure, which makes it closely related to the previous block and the next block. You need to change the records of more than 51% of its local data. The amount of data and change complexity realize the purpose that the process data cannot be tampered with. Therefore, it improves the stability and reliability of the whole model system. In addition, the data block based on time sequence can be permanently stored in all sensors, which provides a guarantee for tracing the original data and updating the tracking process in real time. Therefore, once the malicious node in WSNs is determined, the identity of the attacking node will be handled by corresponding measures to reduce its possible further adverse effects.
There is a small transaction between an agricultural product retailer and five other initiators. The retailer and nine other retailers work together as the transaction verification node to verify the transaction. As shown in Figures 5 and 6, the transaction distance, the composition time of the next block, and the credit degree of each initiator are shown, respectively.


In the conventional transaction mode of blockchain, the transaction can be confirmed only after the composition of new blocks. Therefore, the time in Figure 5 can be regarded as the time to wait for determination. During transaction confirmation, the model will complete the transaction with high credit degree in advance according to the credit degree of the initiator in Figure 6, reducing most unnecessary waiting time.
As shown in Figure 7, the total delay comparison results of multiple rounds of transactions of DCPN model and other methods are shown. In the figure that the delay time of multiple rounds of small transactions through DCPN model is less than that of the other two methods, which shows that the model improves the efficiency of transaction verification and greatly reduces the transaction delay based on the credit degree of the initiator.

To sum up, the trusted computing model of IOT nodes based on blockchain can detect and identify malicious nodes in WSNs, effectively trace the location to exclude the network, and reduce the adverse impact of its attacks. At the same time, the complexity of the data structure of the model makes the recorded process data cannot be tampered with, which ensures the reliability of tracing the original data. In addition, based on the credit degree of the transaction initiator, the model can effectively reduce the transaction delay, reduce unnecessary waiting time, and provide query time guarantee for the agricultural product supply chain traceability system.
3.2. Experimental Results and Analysis of Traceability Products
This paper tests and compares the traceability systems of different agricultural products supply chain, that is, to complete the same query task under the same situation. The system is constructed and developed by using two-dimensional code technology, database technology, and network information technology to realize the traceability of agricultural products. Track and trace the whole process from planting, harvesting, and processing to sales in the whole supply chain. The supervision of the quality and safety of agricultural products has been effectively strengthened to ensure the consumers’ final right to know. This paper uses the actual test results of the system in some areas of Jiangsu to verify the feasibility and effectiveness of the scheme.
Considering that in practice, the query time of the system within a certain range due to the influence of other factors, in order to make a more objective comparative analysis, each group of data calculated for many times will be taken as the final comparison ratio. The number of system traceability records selected in the experiment is 10 K, 50 K, and 90 K, respectively. The correlation coefficient is , the significance is expressed as , and the significance level is . As shown in Figure 8, the query time comparison results of different systems in different trace record quantities reflect the number of batch trace records in the case of a specific total number of trace records. From the results in the figure that the query time of system 1 and the query system in this paper, and the correlation coefficient between them is higher than 0.8, and . The correlation coefficient between the query time of system 2 and the batch traceability record is lower than 0.5, showing weak correlation.

As shown in Figure 9, the query efficiency improvement rate of the system in this paper is compared with that of system 1 and system 2, respectively. According to the data in Figure 9(a), when the two systems query a single trace record, a large proportion of the time is the fluctuation interval. In terms of the improvement rate of query efficiency, the stability of the system in this paper is relatively low. It shows correlation with the two systems. At this time, the query improvement rate of the system is higher than that of system 1, and the state is more stable. As can be seen from Figure 9(b), the relationship between the two systems and the quantity of batch traceability records is different. This paper decreases with the increase of their quantity, and there is a weak correlation between system 2 and them. The number of batch records of agricultural products in the experiment kept within the range of 200 to 400. The overall number of traceability records in this system is positively correlated with nodes and time. When the number of query efficiency reaches 400, the system will continue to improve with the increase of the total number. When the total number reaches 10000, the efficiency of this system is negative, and the query efficiency is lower than system 2. However, when the total number exceeds 30000, the efficiency of this system is higher than system 2, and the advantages will continue to expand with the increase of the overall number.

(a)

(b)
To sum up, there is a positive correlation between the query time number of batch traceability records. When the number exceeds 200, the query improvement rate of the system in this paper is more stable. When the number reaches 400, the query efficiency of this system continues to improve. When the number exceeds 30 K, the query efficiency of this system continues to expand due to system 2 and its advantages.
4. Conclusion
The traditional unitary agricultural product supervision system and requirements of the market, and retrospective investigation and analysis are carried out for product safety. Combined with Internet of things and blockchain, the reliability calculation model of product nodes based on blockchain is constructed. The trusted computing model of IOT nodes based on blockchain can effectively detect and identify malicious nodes in the network and remove them. The blockchain data structure makes the process data of agricultural products cannot be tampered, which ensures the security and reliability of the system. In addition, the trusted computing model of Internet of things nodes based on blockchain can effectively reduce the transaction delay and ensure the query efficiency of agricultural products supply chain traceability system. There is a positive correlation between the query time and records of the agricultural products and blockchain, and the query improvement rate of the system is more stable when the batch traceability records exceed 200. The total number of traceable records, the accuracy of the system is increasing, and the advantages are expanding. This paper has some limitations. Blockchain technology is not yet mature. This paper does not discuss the prominent contradiction between privacy protection and data sharing, the limitations of performance efficiency, and the lack of coordination inside and outside the chain. This needs further analysis in future research and analysis.
Data Availability
The data used to support the findings of this study are available from the corresponding author upon request.
Conflicts of Interest
The author declare that they have no known competing financial interests or personal relationships that could have appeared to influence the work reported in this paper.