Traceability of animal products based on a blockchain consensus mechanism

Block chain technology has the characteristics of decentralization, distributed storage, open and transparent, consensus mechanism, security, information encryption, anonymity and so on. It provides an important way to realize the value added of modern animal supply chain. This paper studies the blockchain related technology, an optimization scheme of sBFT consensus algorithm is proposed, and then the optimization scheme is applied to traceability of animal product quality and safety, which solves the problem of decentralization of traceability system and improves the efficiency of consensus in the case of large data input of traceability system. Then, based on Fabric framework, this paper proposes the design and implementation scheme of traceability system for aquaculture industry chain, which can ensure that the participants of traceability system can not tamper with and modify the aquaculture records, and realize the security, reliability and unforgeability of traceability information. Finally, this paper builds a 12-Node block-chain network test environment based on four cloud servers. Under the same test conditions, the sBFT algorithm, PBFT algorithm and dBFT algorithm are tested and compared, and the function and performance of the traceability platform are tested, which shows that the system is feasibility and efficiency of the schemes designed in this paper.


Introduction
Animal husbandry is one of the components of agriculture. The industrialization of animal products has developed rapidly, and the scale and scope of animal husbandry and breeding have grown. Studies have done to analyze a variety of production factors [1][2][3][4], and tried to optimize and improve the quality from all aspects. In terms of animal breeding, control could be carried out from many aspects, such as optimizing feed and additives [5][6][7][8][9][10], disease prevention and pathogenic microorganism detection [11,12], etc. In terms of product processing, improvements could be made in meat product processing and taste improvement [13][14][15][16][17], cold chain transportation and preservation [18][19][20][21][22]. However, as each link from production to processing to circulation is becoming more and more complex, it is becoming more and more difficult to control the quality of animal products.
Traditional information technology can provide some solutions to the above problems, but it can not solve all the problems. Therefore, we must introduce new thinking, adopt new technology and establish new solutions to solve the product development problems.
The logic diagram of animal product supply chain as shown in Fig. 1. The emergence of block chain technology provides technical support for the construction of modern animal products supply In this paper, the current situation of animal supply chain is analyzed in detail, and the concept, technical characteristics and technical framework of block chain technology are analyzed in depth. On this basis, facing the demand of animal supply chain, the logical framework of animal supply chain based on block chain technology is proposed in order to provide support for the construction of animal supply chain platform by using block chain technology.

PBFT algorithm of fabric
The Fabric framework selected by this paper provides the PBFT consensus algorithm by default, which is efficient in the blockchain network where the nodes are not trusted. However, in the node trusted network provided by the Fabric framework, its complicated verification process reduces the efficiency of transaction consensus [24]. Therefore, for this situation and the performance problems mentioned above, this paper proposes an sBFT consensus algorithm that uses state lists for 2019 The 3rd International Conference on Agricultural and Food Science IOP Conf. Series: Earth and Environmental Science 559 (2020) 012032 IOP Publishing doi: 10.1088/1755-1315/559/1/012032 3 optimization. This paper proposes eight situations that may interfere with the consensus efficiency of this algorithm and the solution for each case.

SBFT algorithm
In this paper, the following optimization algorithm of PBFT, sBFT algorithm, is proposed.Electronic cash as a chain of digital signatures, as shown in Fig. 2   Figure 2. Electronic cash as a chain of digital signatures.

Nodes in block chain network.
Peer and Orderer nodes of Fabric Framework remain unchanged, while Chaincode is still deployed on Peer nodes to read and write books. A Peer node continues to play multiple roles, such as Endorser, the endorser, and Committer, the submitter. Orderer node still ranks transactions by consensus, and packages them together to generate blocks according to block generation strategy and sends them to Peer node [25].

Primary node.
Primary node is the only node that submits a large number of transactions in a certain period of time.

Node status.
Each Peer node has a status identifier indicating that it is in one of three states: no request state (state 1), sent request state/waiting to generate block state (state 2) or large data input request state (state 3).

SL (Status List) status list.
Each Peer node maintains a status list, which records the necessary information to access other nodes and node status.
The state of each node in the list is request less (except node A). The consensus process of RPCA algorithm is divided into two steps [26]. First, the transaction consensus is formed, and then the consensus is packaged into blocks. Because the maintained status list has no requests except Node A, that is to say, only Node A is trading, so we can omit the step of transaction consensus and directly conduct block consensus.

PBFT algorithm
In SBFT, one designated block generator collects and validates proposed transactions, periodically batching them together into a new-block proposal. Consensus is provided by a Generator that applies rules (validates) agreed to by the nodes (chain cores) to the block and designated block signors. Other (multiple) designated block signers ratify the proposed block with their signatures [27]. All network members know the identities of the block signers (permissioned blockchain) and accept blocks only if signed by a sufficient number of signers. A Block Signer validates all transactions in each block and IOP Conf. Series: Earth and Environmental Science 559 (2020) 012032 IOP Publishing doi:10.1088/1755-1315/559/1/012032 4 adds a signature. Only blocks with sufficient signatures are accepted into the chain [28]. This attempts to prevent the double spending problem by attempting to ensure competing transactions gets resolved. The PBFT algorithm of fabric as shown in Fig. 3. Figure 3. The PBFT algorithm of fabric By using 1 generator (master replicator) in a trusted, private environment this effectively allows for kind of scale and speed needed for transactions and for the signors to validate transactions. These signors are configurable meaning they can be added/removed from the system at any time. The same goes for the nodes (chain cores) in the network. They can be added/deleted since it is a private network and this adds an extra layer of security particularly when dealing with what could be a malicious actor [29] .The processing requires of PBFT algorithm as shown in Fig. 4. As a result of using 1 generator instead of multiple, synchronization does not occur. Synchronization is a process that establishes consistency of data between 2 or more entities. This feature allows for scalability and speed to not be affected for the enterprise grade solution. Since the blockchain is private and the entities are known multiple generators could be seen as a redundancy. Not all nodes need to be online for this platform to function at a minimum 1 generator and 1 signor are needed [30]. However, typically it allows 100 participants to interact, only needs 5 signors, 1 generator and 1 issuer (some regulatory body). The Fault Tolerance in this setup allows for 3 out of 4 or 4 out of 5 signors. The Privacy section will go into the details of how the Chain Open Standard tackles the problem of Confidentiality of information for the platform participants. Open, permissionless blockchains like Bitcoin are transparency machines in that all participants can view information on the network. Chain has built a solution for those who need privacy as a main feature [31]. Without the need for complete transparency and all nodes (chain cores) receiving transactional information, scalability does not get sacrificed, but transparency does. All systems have trade-offs. In this system, the nodes (chain cores) would only get block proofs by node platform [32].
The node (core) itself, could store all the blockchain data or only a snapshot (balance sheet) and a limited history of activity from the Account Manager (described below).

Animal product supply based on block chain
After introducing the sBFT algorithm, this paper conducts detailed functional module analysis and design of the animal products industry chain traceability system according to actual needs, including detailed design of the logical relationship between the traceability system modules; then the system is integrated with the fabric framework to design the chain code, the hierarchical structure of the system, and the way the data is stored. The traceability system combined with the blockchain framework has decentralized and tamper-proofed on the data storage to ensure data security [33]. Finally, based on four cloud servers, this paper builds a 12-node blockchain network test environment. Under the same test conditions, the sBFT algorithm, PBFT algorithm and dBFT algorithm are respectively tested and compared, and finally, it is concluded that the performance of the sBFT algorithm is better than the other two algorithms [34]. The function and performance of the traceability platform istested to prove the feasibility of the various schemes designed in this paper.

Demand analysis
Open sharing of data is an inevitable trend. The marginal benefits of information use are increasing. The larger the scope of information flow and sharing, the higher the value created. Online and offline digitalization and data openness are the two prerequisites for large-scale flow of information.. According to the analysis above, it is a feasible technical scheme for animal supply chain to maintain a reliable, open and transparent distributed database collectively by means of block chain decentralization and trust-free, and to encrypt and store data in order to ensure information security by using block chain cryptographic algorithm [35].
The design of agro-product supply chain based on block chain should pay attention to the following principles: open data sharing and circulation channels, legal and rigorous data transaction process, open and transparent transaction data, secure and reliable data encryption and storage, traceable transaction records, queriable, appealable, and private data belonging to all members. Due to the variety of animal products, animal production has typical regional and cyclical characteristics. According to the actual application needs of animal supply chain, system construction can be carried out according to the region, animal products types, market positioning and so on [36].
Based on the analysis of the technical structure and type characteristics of block chain, the alliance chain in block chain technology is more suitable for animal supply chain. The main reasons are as follows: 3.1.1. Accurate positioning. Participants in the alliance chain require "specific groups, signing agreements". Participants are engaged in the same production around the same goal. They can better meet the actual situation of all parties in the animal supply chain from the aspects of management, process, service and so on [35].

High technical feasibility.
Alliance chain is a typical "multi-center" architecture. Regardless of the size of participants and the degree of internal system construction, it only needs to be an access center to upload the standard transaction data needed by the block chain to the block chain, without affecting the internal business processing of the system, and to realize data sharing with other nodes. IOP Conf. Series: Earth and Environmental Science 559 (2020) 012032 IOP Publishing doi:10.1088/1755-1315/559/1/012032 6

Proper carrying capacity.
The goal of animal supply chain is to realize value-added through information sharing. Information sharing does not require too strong real-time. The carrying capacity of 1 000-10 000 pens/s can fully meet the needs of animal supply chain.

Proper data storage.
Public chains with multi-category and multi-user participation include huge business volume, too much space occupied by blocks, and too high demand for data storage; private chains focus on internal business, although the amount of data is small, it is not conducive to different users to share information; alliance chains focus on a specific group, and data properly meet the needs of all users. The storage capacity is suitable [37].
3.1.5. The mode can be replicated. When the system is applied to different areas or scenarios, the reuse of the system can be realized by changing the format of the shared data.

Logical Architecture
According to the above analysis, the logical framework of animal product supply chain based on block chain is constructed. The information stored in the block is: production information, including raw materials, production process, origin and other information; logistics information, including address, logistics enterprise, time and other information; order information, including order, product, quantity, amount and other information. Inventory information, including product, warehouse, stock, surplus space and other information that members of the alliance think they need [38]. The alliance chain structure based on supply chain of livestock and poultry products, as shown in Fig. 5.

Information Flow in Architecture
Through the block and distributed data storage in the block chain technology, the information flow in the supply chain is opened and the data sharing is completed, which mainly includes the following business processes:

Registration.
A pair of public and private key addresses based on ECDSA elliptic curve algorithm are generated for each user when the user registers to join. Because the private key address can not be computed by public key, as long as the private key address of the robot is not disclosed, it is impossible to forge nodes to attack, which endangers the security and integrity of the system [39].

Sharing data.
All participants upload the data to the block chain shared storage according to the shared data format agreed by the alliance members, while other private data are still stored in the corresponding business system database. Participants encapsulate the data to be uploaded, sign the data using their private key address, and then generate block information [40].

Authentication and storage of data to block chains.
Before storing the data, the data is decremented according to the public key of the uploaded user to verify the validity of the data. If the validation passes, the transaction timestamp is generated and the data is permanently stored in the block chain.

Data acquisition.
When it is necessary to obtain the information of upstream and downstream members of the supply chain, the block chain data can be queried according to the agreed protocol, and no additional third party communication is needed. The technology is simple and the network structure is clear.

Maintaining data.
In this scheme, using the data security mechanism of block chain itself, the whole network must reach a consensus and modify it in the way of "minority is subordinate to majority" to solve the problem of "centralized" mandatory change and illegal tampering with data.

Traceability of animal products based on PBFT algorithm
Through the application layer, the users can interact with each other and build a common chain and network. The paper also introduces the proposed consensus mechanism and chooses the node pairs in the connected block Yang Ge to deal with the consensus. The main modules are dealing between Shangbao and businessmen, businessmen and users [41].

Traceability Network Design
When a new node requests to join the network, first. Connect with the designated DNS seed point and send a request to get the! P address of other nodes in the network. Connect with the seed node after acquisition. 2. Get the address list of the node connection. 3. Connect with the node in the list (node A wants to connect with node B, notify the other party of its own! P and port number, and B receives the reverse after receiving it. Return to your P address and port number, and establish a connection in this way when a node successfully joins the network, only an initial block exists locally. At this time, it is necessary to connect with other participating nodes in the network and download the data on the block chain in the network to realize initialization. The node that stores the whole block chain information in the network becomes the complete node to send the synchronous block request according to the node address in the node network connection To monitor whether the response of the connection node is timed out, if the timeout continues to send synchronous requests to other nodes to obtain the latest block chain from the node and compare the height of its own block chain [42]. If the height is higher than the height of its own block chain, then apply for the other party to send the block chain information, after receiving the block chain information, continue to other nodes. list, requesting the other party to send the block information. Flow chart of inter-node transactions as shown in Fig. 6.  Figure 6. Flow chart of inter-node transactions Send the application block synchronization request 5. Verify the correctness of the received block chain after receiving, find the optimal node, get the block chain information of the node, synchronize to their local block chain, the new node will randomly request the complete information of the random block from the complete node in the network.

Transactors and Transaction Information
According to the design of block chain and the analysis of transaction flow of block chain, the transaction roles and transaction information on the transaction model can be defined. In this model, these transaction roles exist as different nodes in the block chain network, each server acts as a node, and these nodes belong to different users. When a new transaction occurs, each node will add the transaction information to the block after verifying the transaction, and all the participating nodes in the whole network can maintain the transaction information to objectively reflect the transaction history information. Participating nodes in the chain can also trace the origin of the transaction history and search to determine the origin of the commodity. In this model, the transaction information between the producer and the distributor is a class 1. The transaction information between the producer and the distributor includes the initial transaction number, the manufacturer's information, the period, the batch, the date of manufacture, the quantity of the goods 2. The transaction information between the distributor and the retailer 2. Interest includes the last transaction number, current transaction number, distributor information, qualification, batch and quantity of goods. 3. The transaction information between retailers and users includes the last transaction number, current transaction number, retailer information, qualification, batch, quantity of goods, time of goods on shelf [43].
The system will assign a pair of public and private keys to the node after the application for consensus is successful. The public key is used to denote the encryption of its own transaction information. The private key uses mimic signature and acknowledgement to prove its ownership of the transaction. Only the account with the corresponding private key can control the transaction of the commodity. Here we use elliptic curve. Encryption algorithm generates public and private keys.

Traceability transaction
Define the transaction information class. The transaction information class includes the following private key signatures of the pen transaction compiler, the shipper and the logistics organization.

Transaction subject transacts in transaction system.
All trading roles register accounts in the block chain network, and then store transactions in the trading pool. When the trading pool of the miners node is full, they begin to calculate and find the miners node in the block network layer to try to find a job to prove the authenticity of the trading information. When any miners node in the network finds a workload certificate, it broadcasts like the whole network. All authentication nodes agree that the new block is valid and up-to-date, accept the block, validity of identification, otherwise they will not receive the block; their trading blocks are linked to the last block, extending the block chain. A block is easy to continue, trading roles continue to trade in the network Trading continues, and retailers and customers trade through the trading platform connected to the network.

4.3.2.
The flow of transaction realization in the system. Transaction shall be carried out according to the normal process, and the transaction information filled out by the shipper shall be confirmed by the consignee upon receipt of the goods for verification. After confirmation of receipt, this transaction and other pending transactions are propagated to the block chain network. Every once in a while, the miner node in the block chain network collect multiple transactions and then combine them to form a "trading group".

4.3.3.
After the transaction information is successfully stored in the block, this paper defines the specific data structure of the existence form of the transaction information in the block.

The correctness of the transaction information is that the transaction information lacks one party's digital signature;
if the transaction information lacks one party's digital signature, indicating that the transaction information is not shared by both parties, then the transaction information has no happy transaction quantity. The number of goods sent by the shipper is larger than the description of goods received by the consignment pen. Some of the goods are not in one batch. Secondly, the quantity of goods input in the transaction information is equal to the total amount of goods output in the transaction information.

4.3.5.
After mining the blocks, the miners will publish the blocks to the network. First, they will look at their node address list and check whether they are still connected to these nodes. If they are disconnected, they will reconnect and send block information.

Block verification.
The block conditions of the lattice are as follows: SHA256D (Blockherder) < F (n Bits, where: SHA256D (Blockherder) is the result of mining, F (n Bits) is the target value corresponding to the difficulty, and the difficulty value of the whole network is the same, both of them When a miner node in the network finds a new block, other miner nodes need to download the new block and store the block after the block has been secured successfully.are 256 bits, which are regarded as reasonable, and the size is directly compared to determine whether it meets the difficulty requirements.

Traceability and novelty search
Blocks consist of transaction information, hash hash formed by the previous block, and random numbers. Transaction information is the number of tasks carried by blocks, including the private keys of both parties, the number of transactions, the information of both parties, etc. Hash hash formed by the former block is used to connect blocks and realize the sequential arrangement of past transactions. The traceability transaction flow chart as shown in Fig. 7.   11 First, the transaction before traceability needs to be filled in by the shipper and stored successfully in the block. Then the transaction information can be traceable according to the structure of the block chain and the last transaction number in the transaction information sheet. Users who traceable can input the transaction number through the client to display. Indicates the block in which the exchange is located. The block contains many transactions. At this time, the user locates the current transaction position by the transaction number. The block chain structure is used to query the previous transaction of the current transaction in turn. The second step of the vehicle reply. Tracing back to the original transaction to the source In order to solve the problems of low efficiency, small amount of information storage and high cost. Traceability information can be stored in both public and private chains. Due to the overhead of storing traceability information directly in public chains (it costs about one yuan to call intelligent contracts to store an integer in Ethernet workshop), it is difficult to serialize traceability information in different formats, such as pictures and text, into block chains by using block chains directly to store traceability information. Traceability system can use private block chain to store traceability verification data (i.e. hash value of traceability data), and store all traceability data, and store hash value of block information of private block chain in public block chain.

System functional testing
Then, building the test environment of the system, deploy the system to the environment, test the function and performance of the system with the pre-prepared data set, make an analysis and comparison according to the test results, and finally draw a conclusion.

Testing environment
From the previous analysis, we can see that the traceability platform is a B/S system which is directly hosted by the enterprise and allocated accounts to the enterprise by the platform. Therefore, the traceability system only needs to be deployed to a server. As for the database used by the system, the distributed scheme of the least three server nodes or a simple single database can be chosen first.
For Fabric framework, because the total number of nodes in block chain network is 3f + 1 and f is the number of fault nodes, the minimum number of nodes in the whole network is 4. In this paper, in order to present the real scene of data transmission between nodes through the network, we abandon the scheme of using virtual machine and rent four cloud servers to deploy nodes.
The result of building block chain network is shown in Fig. 8. During the testing process, the running environment of the code is: Docker version is 18.09.1, 2 core CPU, 8GB memory, 1000GB hard disk, and the operating system is CentOS 7.564 bits.  The Fabric project generates Docker images such as fabric-peer, fabric-orderer by successful construction. With the virtualization technology of Docker, we can deploy multiple Peer nodes on the same server. As can be seen from Fig. 8, three Peer nodes are deployed on each server in this paper.

Testing sBFT algorithm
Based on the blockchain network, we can test the performance of the sBFT consensus algorithm implemented. Because the sBFT consensus algorithm is not only the optimization of PBFT algorithm, but also the dBFT algorithm is used in the implementation process, it is necessary to test and compare the consensus performance of the three algorithms. The test data line chart of sBFT optimization algorithm as shown in Fig. 9.   13 From the experimental results, it shows that after excluding some external factors such as network fluctuation and trading randomness, the performance of the three algorithms is in turn sBFT, dBFT and PBFT.

Testing of traceability system
Most of the modules in the traceability system have similar functions. We only select representative modules to show the function test. The test data line chart of optimization algorithm, as shown in Fig.  10.

Figure 10. Test data line chart of optimization algorithm
Fabric framework has a block chain under each channel, and the chain code is deployed here. Therefore, enterprise users need to deploy corresponding chain codes after building nodes on their own servers.
Animal husbandry is one of the components of agriculture. The industrialization of animal products shows a rapid development trend, the scale of animal husbandry and breeding industry is getting higher and higher, and the range of breeding is getting larger and larger.
In terms of aquaculture, people control from multiple links such as improving the feed ratio, improving the breeding environment, preventing diseases and pathogenic microorganisms, and improving immunity and health; In terms of product processing, improvements are made in meat product processing and taste improvement, cold chain transportation and preservation. IOP Conf. Series: Earth and Environmental Science 559 (2020) 012032 IOP Publishing doi:10.1088/1755-1315/559/1/012032 14

Conclusions
Block chain technology has the characteristics of decentralization, distributed storage, open and transparent, consensus mechanism, security, information encryption, anonymity and so on. It provides an important way to realize the value added of modern animal supply chain. By analyzing the concepts and connotations of animal products, logistics, animal products logistics, supply chain and animal products supply chain, this paper further clarifies the supply chain of animal products and its business logic, points out the problems existing in the current circulation of animal products, and by analyzing the concept, technical characteristics and structure of block chain technology, faces the needs of animal products supply chain. In this paper, the logical framework of animal product supply chain based on block chain is proposed, and the information flow and capital flow in the framework are discussed, which can provide useful enlightenment and reference for the related research of animal product supply chain based on block chain.