Abstract:The quality and safety of grain and oil is directly related to people’s life and health and national security and stability. The grain and oil supply chain is characterized by complex subjects, multiple risks, cross domain supply network, and difficulty in getting through the information chain. New generation information technologies, such as blockchain, providing new solutions and application models for food quality safety assurance and traceability, but also introducing new systematic risks, and there are security challenges. Based on the analysis of the risks and information characteristics of the grain and oil quality and safety blockchain, the general-purpose blockchain structure in the existing completely untrusted execution scenario was improved and optimized. At the network layer, a special blockchain network structure suitable for grain and oil quality and safety in non-completely trusted execution scenarios was proposed, and a Kafka consensus optimization algorithm P-Kafka based on PBFT improved Byzantine fault tolerance and in line with the characteristics of grain and oil quality and safety blockchain was proposed at the consensus layer. The performance of P-Kafka was compared with the traditional consensus algorithm from the perspectives of correctness and decentralization, security, scalability, consensus efficiency and consistency. Through analysis and comparison, the network node partition and sub chain partition proposed saved the operation cost of blockchain system and improved the privacy security of nodes to a certain extent. The improved P-Kafka consensus algorithm had Byzantine fault tolerance and inherited the high throughput characteristics of Kafka partition optimization, making it more suitable for grain and oil quality and security application scenarios.