# Design of Multi-Chain Traceability Model for Pepper Products Based on Traceability Code
## 4 Construction of Multi-Chain Traceability Model for Pepper Products  
### Pepper Multi-Chain Traceability Model  
Aimed at the low query efficiency of the single chain model, a multi-chain traceability model of pepper products is constructed to improve blockchain data query efficiency, as shown in Figure 1. First, a main chain is constructed, which stores the product traceability code and the transaction address of each link, and then a side chain is constructed for each link of pepper products, and the side chain stores the traceability information of each link. This model stores the traceability data of different links in the corresponding link side chain and builds a main chain to store the traceability code of pepper products and the transaction address of traceability information, which not only guarantees the tamper-proofness, credibility, and security of traceability data but also ensures the efficiency of traceability querying.  
The blockchain is used to record the traceability information of each link, and the blockchain timestamp is used to record the chronological order so as to realize the uploading of all the records of peppercorn products from planting to consumers' hands, and the consumers can query all of the whole peppercorn supply chain information through its traceability code. In the process of peppercorn data uploading, the plaintext data are encrypted by encryption algorithms and then the ciphertext data are uploaded to protect data privacy, and the blockchain is stored in a multi-chain structure to optimize the efficiency of data query.  
After information is collected, the traceability information is divided into public traceability data and private traceability data through the on-chain contract. The private traceability data are encrypted by RSA algorithm, and then the ciphertext data are uplinked to the corresponding side chain, while the public traceability data are directly uplinked after the quality and safety standard monitoring smart contract. Through the side chain uplinking contract, the hash address of the transaction and the link traceability code of the link are returned to the link node, and the node establishes the mapping relationship between the traceability code and each transaction by calling up the mapping contract and then saves the mapping relationship on the main chain.  
In the process of data traceability, consumers query the traceability information through the traceability code in the peppercorn traceability system; the client node verifies the traceability code, transmits it to the blockchain network, and calls up the mapping contract to query the main chain to obtain the mapping relationship. Then the mapping relationship is used to obtain the transaction hash address on each side chain while the nodes use the transaction address to index the query on each side chain and obtain the traceability data of each side chain through the transaction address, and finally, the traceability information is integrated into each side chain to create the complete traceability information of the whole industry chain, which is presented in front of the consumers.  
This model uses one main chain and multiple side chains, the main chain and side chains form a one-to-many mapping relationship, and the mapping relationship between the traceability code and the transaction address of the side chain traceability information is stored in the main chain. The mapping relationship is queried by traversing the main chain, and then the side chain traceability information is queried by direct indexing to realize fast traceability, which improves the efficiency of traceability querying.