# Design of Multi-Chain Traceability Model for Pepper Products Based on Traceability Code
## 4 Construction of Multi-Chain Traceability Model for Pepper Products
### Storage Schema Design for Multi-Chain Traceability Model
Traceability information is stored on the planting sidechain block:  
After collecting the information, the manufacturer submits the traceability information regarding planting, processing, storage, and transportation to the respective side chain through the uplink function in the smart contract. After receiving the request, the planting side chain will generate a transaction and store the transaction content in the current block and generate the transaction address. Sidechain update status data:  
The side chain updates the status data according to the incoming transaction content, and the status data of the planting side chain will add a piece of traceability information regarding the planting link of the pepper product, so that the status data can be quickly queried through the transaction address without traversing all the data. Coded exchange smart contract:  
The uplink function of the side chain will return the transaction address, the traceability code of each link, and the peppercorn product traceability code to the public node of the link and then store them in the main chain. Thus, the whole peppercorn product traceability process is controlled through the main chain. Main chain query to see if a record already exists:  
Only the traceability code and the transaction address of each link are stored in the main chain, because a traceability code will correspond to the transaction address of four side chains, so after the transaction information is passed from the side chains, the main chain is first queried to see if the information record of the traceability code already exists. New/updated records:  
If the record already exists in the main chain, then the record is updated according to the update record; the update record only updates the corresponding transaction address of the link, and the link does not have the authority to update the transaction address of other links. If the mapping relationship does not exist in the main chain, a new mapping relationship is created between the traceability code and the transaction address of the traceability information of the side chain, taking the traceability code as the primary key and setting up the transaction address of the link. This completes the traceability information uplinking phase. Creating mapping relationships;  
A mapping relationship is established between the traceability code in the form of an object in the main chain and the transaction address in the side chain, and the main chain and the side chain correspond to each other in a one-to-many relationship, with one main chain corresponding to multiple side chains. Fast Query Process for Multi-Chain Traceability Model  
When querying on the blockchain, the query time increases linearly with the quantity of data. In this paper, we propose a multi-chain query process that can not only guarantee data security, but also improve the query efficiency of traceability, as the main chain only stores the traceability code and mapping relationship data while the main pepper industry chain traceability information is stored in the side chain, and the query efficiency is improved by establishing the mapping relationship with the side-chain transactions and utilizing index querying, and this query mode will shorten the query time of the traceability data when the data volume is large. The traceability data query process of the multi-chain model is shown in Figure 3. When the system receives the query request for traceability information, it first traverses the main chain to query the mapping relationship, conducts a quick query on the information of each stage through the mapping relationship, and then splices these together to form the traceability information of the whole supply chain and transmits it to the main chain,which transmits the query result to the client through the smart contract, and the front-end page reads the data to the consumer. The front-end page reads the data and displays the traceability information to consumers.