Abstract

For traditional agricultural product traceability system, there are some problems, such as information asymmetry and serious centralized storage. To solve the problems, a set of an agricultural product traceability information analysis system based on blockchain is designed. The overall framework of the agricultural product information traceability system is built, and the traceability model and process are designed in detail from the data layer, consensus layer, and contract layer. Collaborative verification function modules are added in the data layer to ensure the authenticity of data on the blockchain. The integral penalty mechanism is introduced to improve the practical Byzantine fault tolerance algorithm (PBFT), which ensures the security of the block network and the validity of data. Smart contracts are adopted to ensure that changes in agricultural information are actually recorded on blockchain. The results show that the designed blockchain-based agricultural product information traceability system solves the problem of difficult sharing and traceability of agricultural product information, which realizes the traceability of agricultural product production information, processing information, transportation information, and transaction query information, and has certain theoretical and practical value for the information traceability of agricultural products and other products.

1. Introduction

As a food source, the quality and safety of agricultural products are closely related to human health. In recent years, with the development of agricultural technology, the production and processing of agricultural products have gradually been intelligent, but its quality and safety problems have become more and more serious. The quality and safety accidents of agricultural products, such as fruit and vegetables, occur frequently, which becomes the focus of people’s attention. To this end, relevant researchers have developed a traceability system for agricultural products, which makes the production process of agricultural products transparent, and to a certain extent, the traceability of agricultural product information is realized. Yang et al. proposed a decision algorithm using q-Rof sets to select a blockchain-based agricultural product traceability system (BAPTS) design with the help of Q-Rung orthogonal pair fuzzy (q-Rof) sets dynamically delineating the space of uncertain information. Muirhead mean operator and power operator are combined to develop q-Rof power Muirhead mean (q-RofpMM) operator and q-Rof weighted power Muirhead mean (q-RofWPmm) operator; thus, a multicriterion decision-making framework based on q-RofWPMM is constructed to effectively solve the problem of BAPTS evaluation and selection, eliminate the negative impact of abnormal expert evaluation on decision results, and improve the effectiveness of the agricultural product traceability system [1]. Park et al. analyzed agricultural product traceability by using the structural equation model (SEM) and tested its hypothesis with users’ online purchase intention. The results show that the convenience of agricultural product traceability has a positive impact on the traceability attitude, and the trust of agricultural product traceability has a positive impact on online purchase intention, which verifies the importance of agricultural product traceability [2]. Zhao et al. put forward a detection of pesticide residues and agricultural product traceability system based on the acetylcholinesterase (AChE) biosensor and the Internet of Things (IoT), and it is designed to use the advantages of pesticide residue detection data remote control, data processing and sharing, and agricultural product traceability to detect the location of the equipment (lower computer). Through the upper computer, the detection data obtained from the detection equipment are further summarized, processed, and analyzed to extract useful information (detection time, origin, detection samples, pesticide residue value, and detection inspector), so as to effectively protect the quality and safety of agricultural products. Finally, the useful information is coded in the form of a QR code to achieve efficient and safe traceability of agricultural product information [3]. Qian et al. adopted Web technology, bar code technology, and data acquisition middleware technology to build a database server platform and SOA-oriented software information system, designed and implemented agricultural product traceability system, standardized enterprise production management, and enabled consumers to obtain the right to know [4]. Bao et al. established the agricultural product traceability mode and proposed the method to realize the agricultural product traceability mode through analyzing the influence of the participants, the agricultural product circulation mode of the supply chain, the traceability guarantee system, and the traceability process. This method is based on the construction of the agricultural product traceability chain and the redesign of the traceability code and uses RFID technology to collect related information of agricultural products, which realizes the agricultural product traceability and has certain feasibility [5]. Wu et al. designed the information traceability database of agricultural product production, wholesale, and sales by using WebGIS technology and developed the agricultural product traceability information system, which realizes the agricultural product traceability [6]. Li et al. designed and implemented an encryption algorithm for an agricultural product traceability code based on the improved AES algorithm to ensure the reliability and security of agricultural product traceability [7]. Chen et al. analyzed consumer preferences and willingness to pay for ecological agricultural product traceability technology and adopted a selective experiment method to verify the consumer preferences, which are blockchain technology application attributes, traditional traceability technology application attributes, high credit supervision attributes, and international certification attributes [8]. It can be seen that the agricultural product traceability method based on blockchain technology has certain advantages. Therefore, based on blockchain technology, this paper designed a set of the agricultural product information traceability analysis system.

2. Agricultural Product Information Traceability Scheme Based on Blockchain

2.1. System Framework

Blockchain is a data structure that records transactions, and it is mainly composed of the data layer, consensus layer, contract layer, application layer, and other network layers [9]. This paper applies blockchain technology to trace agricultural product information, and its overall framework is designed as shown in Figure 1. As the core of the whole system, the data layer is responsible for generating the agricultural product traceability information and management information block in the way of dynamic storage, and it usually uses the Merkle structure to store data. The consensus layer is responsible for reaching a consensus on the effectiveness of scattered agricultural product information according to the consensus algorithm to ensure the safe operation of the blockchain network. The commonly used consensus algorithm is mainly the PBFT algorithm. The contract layer is related to the smart contract, which realizes the connection between nodes by formulating codes and automatically activates the blockchain. In the framework of Fabric, the Golang programming language writes chain code to realize the smart contract between nodes, and Docker runs the chain code and connects to the client and Fabric. In addition, the blockchain system is activated and automatically run under specific conditions [10]. The application layer is responsible for the release of agricultural product information and provides users with traceability and query operations of agricultural product information through CSS and other tools, which can be regarded as the application scenario of blockchain.

2.2. Construction of Traceability Model

According to the characteristics of production, transportation, and sales of agricultural products, combined with blockchain technology, the agricultural product information traceability system model based on blockchain is designed, which is shown in Figure 2. In this model, production data are collected through various sensors in the process of agricultural production and planting. Pick, process, and exchange machine to collect agricultural product processing information through product identification. In the logistics and transportation process, the environment and other related data during agricultural product transportation are collected by positioning devices. The sales terminal records sales data by means of the QR code and bar code. Data collection in each link is completed independently and stored in blockchain through verification. Then, encryption technology is used to encrypt the data on the blockchain to prevent the data from being maliciously tampered with. Here, the SHA-256 algorithm with good crash-resistance and efficiency is used to encrypt the data asymmetrically [11]. Finally, agricultural product information traceability is achieved through the timestamp technology in blockchain [12].

2.3. Traceability Process Design

Based on the above system model, the agricultural product information traceability process is designed from planting and picking, packaging and processing, logistics transportation, and sales inquiry, which is shown in Figure 3. In the process of planting and picking of agricultural products, relevant data are collected by installing light, soil water content, and other sensor equipment, and the wireless network is used to transmit and store, which serves as the source of blockchain data. In the process of packaging processing, the processing unit is used to upload the data to the blockchain, and the generated traceability code is marked on the product packaging. In the process of logistics transport, management uploads the information such as product delivery and receipt to value blockchain. In the sales inquiry link, users can scan the two-dimensional code or bar code on the product package to obtain the relevant information of agricultural products from planting to sales.

3. Design of Agricultural Product Information Traceability System Based on Blockchain

3.1. Data Layer

Data layer in blockchain usually uses the Merkle tree structure to store data. The displacement hash value is obtained by performing the hash operation for each transaction, and the hash operation continues upward; thus, a unique Merkle tree is finally obtained, which can prevent the transaction data from being tampered with and reduces the amount of data transmission and the difficulty of calculation [13, 14]. In agricultural product information traceability, each entity has a pair of keys: public key and private key, which represents a unique identity. When a node applies to publish data or modify published data, the approved application performs a hash operation through the consensus algorithm to generate Merkle trees, and it is packaged into data blocks, which is shown in Figure 4 [15].

The node is received, and data is verified. If the verified data is consistent with the data on the blockchain, the data is received and stored; otherwise, the data is not accepted. Collaborative verification function modules are designed in the data layer to realize data feed.

In the collaborative verification module of agricultural product information, the operation is carried out by employees of the enterprise, and each employee has a unique work number. During the inspection of agricultural products, the employee enters the work number for identification. The digital signature process is as follows:

Write the initial agricultural product information as , and generate the summary hash value of through the hash algorithm SHA256:

Use the elliptic curve algorithm ECDSA for digital signature [16]; then,

where is the public key and is the private key. A random number is generated, and is calculated:

can be calculated according to , , and :

After signing, the signature results and related information will be written into the QR code of agricultural products. Besides the identification function, the digital signature is equivalent to encrypting data internally and also plays a protective role in agricultural product information [17].

3.2. Consensus Layer

Analyzing the application scenario of blockchain of agricultural product information traceability system, Hyperledger Fabric which can meet all characteristics of the alliance chain is selected to deal with agricultural product traceability information, and the PBFT consensus algorithm is used as a consensus mechanism.

3.2.1. PBFT Consensus Algorithm

PBFT algorithm is an algorithm that can well maintain the consistency between Byzantine failure nodes and distributed systems. And compared with the traditional consensus algorithm, the PBFT algorithm has the characteristics of low energy consumption and high efficiency [18]. Its transmission diagram is shown in Figure 5. is the request node, and 0~3 are the server. indicates failure. The algorithm execution is as follows: sends request information to 0, and 0 transmits the request information from 1 to 3. After receiving the information, 1 transmits the request information to 0, 2, and 3. After receiving the information, 2 transmits the request information to 0, 1, and 3. Because serve 3 is a failure node, it cannot pass information. If 0 to 3 receive too many same requests, the application is submitted and the information is fed back to .

The PBFT algorithm can provide a certain fault tolerance number to make the blockchain network have good activity. However, there are also problems in that the performance of the traceability network is low when facing many blockchain network nodes, and it is incapable of determining whether or not the failure node is a malicious node, which may place the whole blockchain network into crisis [19]. Therefore, to solve the above problems, the integral punishment mechanism is introduced to improve the PBFT algorithm.

3.2.2. Improvement of PBFT Consensus Algorithm

Select some trusted nodes to form a verification node list , and the verification node set can be expressed as

The initial integral of the node is and is expressed in Formula (6). Taking the consensus best block in each round as the packaging verification node, the integral of the worst block packaging verification node is reduced by the coefficient . The integral of the worst block is shown in Formula (7) [20]:

When the node integral in is lower than the set value , the node is cleared. When the node integral in is less than 2/3, the list is dissolved and a new verification node list is generated [21].

The mathematical description of the consensus process is as follows:

Let the verification node set be , which is shown in Formula (8), and the candidate set to be verified of is ; then, the candidate set to be verified is

The terminal submission package block is , and the set of other verification groups and revenue is . Terminal verification set is composed of block , which is packaged by a terminal , in which the verification setwhereinverifies blocksubmitted bysatisfies Formulas (11) to (13) [22, 23]:

The steps to reach consensus are as follows: (1)Generate verification node list . For the earliest , and , block is selected as the best block; thus, Step (4) is performed; otherwise, Step (2) is performed(2) and making , block is selected as the best block, and Step 4 is performed; otherwise, Step (3) is performed(3), and if , select the earliest block from and as the best block(4); if , select block as the worst block and execute . Set the integral specified value to ; if , then node fails, and it is cleared from

Based on the above operation, integral penalty is introduced to dynamically allocate verification right, and failure node is punished, which avoids all nodes involved in the algorithm, and the problem that the PBFT algorithm requires high network bandwidth is solved. Thus, the consensus network dynamics of the PBFT algorithm is improved, block generation efficiency is increased, and the security of the blockchain network is improved.

3.3. Contract Layer

The contract layer realizes the activation and operation of blockchain through the smart contract. According to the requirements of agricultural product information traceability business, there are four chain codes to fully trace the four different types of data structures of agricultural product production information, processing information, transportation information, and sales information. Among them, agricultural product production information includes agricultural product name, planting address, and picking date. Processing information includes processing type, processing unit, and relevant management. Transportation information includes delivery time, delivery address, and delivery unit. Sales information includes dealers, sales locations, and sales time. All are shown in Table 1. The installation of smart contracts must be carried out by authorized members, which is instantiated on a peer node server and deployed and run through the interaction between Fabric-SDK and peer nodes [24, 25].

Smart contracts can ensure that every change of agricultural information is actually recorded on the blockchain. The production unit of the agricultural product delivers the agricultural products to the processing unit to generate a contract; the processing unit will process the agricultural products and then deliver them to the transportation unit to generate a contract, which will be carried out in this way until the completion of agricultural product sales. In addition, all the contracts generated during the period will be stored on the blockchain in the form of code, namely, smart contracts. And all participating nodes enjoy the right to read and write information. In this way, the traceability of agricultural product information is realized.

4. Simulation Experiment

4.1. Algorithm Verification
4.1.1. Evaluation Indicators

The evaluation indicators are throughput (TPS) and latency (Latency). The larger the throughput is, the better the performance of the consensus algorithm is. Delay represents the response time of the system transaction, which mainly measures the response time of the system to a request. The higher the delay, the worse the performance of the consensus algorithm. In order to avoid the influence of a random error on the results, the average value of the 10 results is taken as the final result.

4.1.2. Results and Analysis

The different number of nodes are set, and the throughput and latency of the PBFT consensus algorithm are compared with those of the traditional PBFT consensus algorithm. The results are shown in Figures 6 and 7, respectively. It can be seen from Figure 6 that when the number of nodes is small , the throughput of the two algorithms is close and both of them increase with the increase of the number of nodes. When the number of nodes is more than 10, the throughput of the two algorithms decreases with the increase of nodes, but the decrease rate of the SBFT algorithm is lower than that of the PBFT algorithm. Therefore, in the complex communication environment, the proposed SBFT algorithm performs better than the PBFT algorithm in the throughput performance index.

As can be seen from Figure 7, with the increase of the number of nodes, the delay of both the SBFT algorithm and the PBFT algorithm increases, but the delay growth rate of the SBFT algorithm is significantly slower than that of the PBFT algorithm, indicating that the proposed SBFT algorithm has better delay performance than the improved PBFT algorithm.

According to Figures 6 and 7, compared with PBFT, the proposed SBFT algorithm performs better in terms of throughput and delay.

4.2. System Verification
4.2.1. System Environment

The operating system of the experiment is 64-bit Windows 10, and VMware is used to install the virtual Ubuntu system. Adopting MySQL as the database, the agricultural product information traceability system framework is constructed by Hyperledger Fabric1.2, and GoLand is utilized to deploy the blockchain background environment.

4.2.2. Main Function Interface of the System

(1) Generation Interface of Traceability QR Code. The QR code is generated when the information of agricultural products is published, and it is stuck on the outer packing of agricultural products. Each node of the blockchain can be collaboratively verified by scanning the QR code or entering the bar code. The generation interface of the QR code of agricultural product information traceability is shown in Figure 8.

(2) Publish Interface of Agricultural Product Information. Agricultural product information includes agricultural product production, processing, transportation, and sales, which can be automatically collected and uploaded by sensors and manually inputted and published. Taking the agricultural product production information publish interface for example, this interface includes detailed information such as product name, termination address, and picking date. The interface is shown in Figure 9.

(3) Agricultural Product Information Inquiry. As can be seen, after purchasing the products, consumers can trace the relevant information of agricultural products by scanning the QR code or entering the bar code. Figure 10 shows the query interface of the agricultural product traceability code. By inputting the bar code and inquiring, the main information of agricultural products such as production, processing, and transportation can be obtained.

5. Conclusion

The agricultural product information traceability system based on blockchain designs in detail the data layer, consensus layer, and contract layer of the system by combining blockchain technology and the characteristics of agricultural product information. Blockchain trade proposals are collaboratively verified with the QR code label information of agricultural products, which ensures the authenticity of the agricultural information data. Moreover, a penalty mechanism is adopted to improve the PBFT consensus algorithm, which solves the problem of difficult sharing and traceability of agricultural product information; ensures the network security of the block data and blockchain; realizes the traceability of agricultural product production information, processing information, transportation information, and transaction query information; and has certain theoretical and practical value for the information traceability of agricultural products and other products. But because of the condition limitations, there are still some imperfect places for the designed agricultural product information traceability system to be improved. For example, in the cooperative verification of agricultural product information, the designed scheme relies on manual cooperation verification, which leads to low system implementation efficiency. Therefore, the next research can try to integrate the Internet of Things devices with the blockchain-based agricultural product information traceability system to reduce manual participation and improve system implementation efficiency.

Data Availability

The experimental data used to support the findings of this study are available from the corresponding author upon request.

Conflicts of Interest

The author declared that they have no conflicts of interest regarding this work.