The structure of the grain-and-oil-food-supply chain has the characteristics of complexity, cross-regionality, a long cycle, and numerous participants, making it difficult to maintain the safety of supply. In recent years, some phenomena have emerged in the field of grain procurement and sale, such as topping the new with the old, rotating grains, the pressure of grades and prices, and counterfeit oil food, which have seriously threatened grain-and-oil-food security. Blockchain technology has the advantage of decentralization and non-tampering Therefore, this study analyzes the characteristics of traceability data in the grain-and-oil-food-supply chain, and presents a blockchain-based traceability model for the grain-and-oil-food-supply chain. Firstly, a new method combining blockchain and machine learning is proposed to enhance the authenticity and reliability of blockchain source data by constructing anomalous data-processing models. In addition, a lightweight blockchain-storage method and a data-recovery mechanism are proposed to reduce the pressure on supply-chain-data storage and improve fault tolerance. The results indicate that the average query delay of public data is 0.42 s, the average query delay of private data is 0.88 s, and the average data-recovery delay is 1.2 s. Finally, a blockchain-based grain-and-oil-food-supply-chain traceability system is designed and built using Hyperledger Fabric. Compared with the existing grain-and-oil-food-supply chain, the model constructed achieves multi-source heterogeneous data uploading, lightweight storage, data recovery, and traceability in the supply chain, which are of great significance for ensuring the safety of grain-and-oil food in China.