1 Introduction

Customers may safeguard their personal information with blockchain technology, and agencies can generate and exchange economic value at smaller operational scales. AI systems aim to concentrate power in the hands of a select few businesses who have the capacity to gather and analyze enormous amounts of data. Blockchain technology aids in the long-term, unchangeable preservation of precise data, while machine learning can utilize this data to spot trends and provide precise estimations. While blockchain's distributed ledger offers data security, data science concentrates on harnessing data for efficient administration. There is a lot of untapped potential in these technologies to increase efficiency and output.

Since Satoshi Nakamoto published the Bitcoin white paper in 2008 [1], the Bitcoin system, as a model of distributed systems, has developed rapidly and stably around the world, and its underlying technology has attracted more attention from the industry. The birth of blockchain technology is to deal with the resource monopoly and other problems caused by the existing centralized system [2]. It is a combination of P2P network, consensus mechanism, encryption algorithm, smart contract, and other technologies, and has the characteristics of decentralization, non-tampering and traceability. In short, its essence is a distributed ledger based on a chain structure [3]. Although the blockchain is not impenetrable, scalability is one of its notable shortcomings. Blockchain might be very challenging and inefficient at the same time. The uniqueness of data has always been one of the blockchain's biggest disadvantages. It is evident that it benefits a number of systems, including the financial and supply chain systems. Although the blockchain is not infallible, one of its notable shortcomings is scalability. The blockchain can be broken. Blockchain still has issues with scalability. Nothing on a blockchain is set in stone or immutable.

According to different usage scenarios of blockchain technology, it can be divided into public chain, alliance chain and private chain [1]. The public chain system is a completely open and decentralized system. Any node can access data and participate in the maintenance of the system, but its efficiency is low. Both the alliance chain and the private chain require relevant authorization to enter the network. Comparison of the number of nodes between the two the public chain is more fixed and the review is more stringent [4]. The difference is that the alliance chain is generally used between enterprises or organizations, while the private chain is only used within enterprises or organizations. There are many enterprises in the SC and information exchange is frequent. Choosing a consortium chain system is more in line with the business scenario of the SC. In view of the problems of the original centralized SC platform such as scattered upstream and downstream information, low sharing, poor authenticity and poor reliability [5], Liao[6] proposed a blockchain-based A technology-based product trustworthy traceability solution is established to establish a product traceability platform, collect and store data from each link of the commodity SC in the blockchain, so that the information can be queried and cannot be tampered with, ensuring the authenticity and credibility of the data.

Food makers are also interested in learning about food circulation and related topics. By tracking food information via the food traceability system, we are able to verify food safety and dependability by gaining a comprehensive understanding of food from the point of production to the point of consumption. Food manufacturers are also want to know about food transportation and associated information. The important requirements and interests of the individuals who will utilize the food traceability goods should be considered in addition to their high economic value. Food is the most important thing to people, and customers have always agreed. When problems with food safety and quality are discovered, traceability may be used to rapidly pinpoint the source of the problem, the responsible party, and to initiate the recall of tainted food.

The oversight of the appropriate regulatory agencies is being strengthened and made more effective by incorporating modern technologies and methods of supervision. Food data must be tracked throughout the process in order for it to be utilized for food traceability. The necessary consumer complaint mechanism and the food safety recall procedure put in place by the regulatory bodies are absent from the system. Therefore, once a problematic product causes a health danger, it won't be able to prevent it from accessing the market at the right time. Because of the knowledge asymmetry between the primary supply chain participants, it is hard to ascertain whether the data has been purposefully changed along the circulation process.

Li et al. [7] proposed the automotive SC product traceability system based on blockchain adopts the blockchain + automotive SC model to conduct distributed storage of automotive-related data, ensuring the security of SC data, increasing mutual trust among participants, and making automotive Product traceability is more efficient and convenient. Yu et al. [8] proposed a blockchain-based pharmaceutical traceability system, based on the alliance chain platform, to record and track data on each link in the pharmaceutical SC to ensure drug safety.

In this study, a blockchain-based food traceability system is suggested, whereby farms, slaughterhouses, shipping businesses, and sales units are added as nodes to the blockchain network, and is used as the traceability object. The blockchain is developed using Ethereum. Ethereum smart contracts are used to construct the significant supply chain enterprise. To ensure that the data cannot be changed, the critical supply chain production and distribution data is stored on the blockchain. Blockchain-based traceability makes it easier to track and trace the origin of goods and supply chain operations while also identifying fraudulent or deceptive activity. Examined the whole supply chain and created useful modules to satisfy the needs of each link's nodes. Using the appropriate development tools, the system is deployed and tested after the software architecture has been chosen. Customers can use this system to ask questions about traceability by using the traceability code found on food packaging.

The blockchain-based supply chain contains a large volume of data collected at each connecting node. This is because many nodes in the chain are actively participating. If they are all uploaded to the blockchain network at the same time. The real data is not stored in the blockchain system; only the information summary of the material in its entirety is. For later usage, the information is kept in the database. In order to achieve the purpose of traceability, a blockchain-based traceability system must be developed together with a traceability code for pig products.

Wang et al. [9] proposed a flexible and trusted traceability scheme for agricultural products, which combined with the excellent characteristics of blockchain technology, is suitable for relevant business needs in agricultural product traceability.

The above literature combines blockchain technology with SC scenarios to varying degrees and improves the existing traceability system, but relatively ignores the impact on the distributed system as a whole by use of the consensus procedure. The consensus algorithm is the key component of blockchain technology [10], whose role is to ensure that all nodes in the system can reach a consistent state. The main consensus algorithms in the current blockchain include PoW, PoS [11], Raft [12] and PBFT [13] algorithms, etc. These algorithms will directly Affects the reliability and availability of the entire system. The PBFT consensus algorithm is improved from the BFT algorithm [14]. It has recently become one of the most popular and commonly utilised consensus algorithms in the alliance chain. With its help, the Byzantine problem may be mostly resolved. The issue with general [15] is that it has drawbacks including a high communication overhead and poor efficiency [16]. We propose an improved PBFT algorithm that reduces the original algorithm's communication overhead, improves node consensus efficiency, and better meets industry needs. This is considering the problems with the current algorithm and the relatively trustworthy characteristics of nodes in the collaborative food supply chain.

The integration of blockchain technology with IoT will provide full food commodities accessibility across the supply chain. The primary advantages of blockchain and IoT in the food supply chain include real-time surveillance and the recognition of authentic food items at the source, which helps identify major bottlenecks. Smart agriculture uses Internet of Things (IoT) technologies for management and monitoring. In order to maximize agriculture, IoT implementation in the field has increased farmers' productivity and efficiency.

Food makers are also interested in learning about food circulation and related topics. By following food information from the point of production to the point of consumption using the food traceability system, we are able to verify the food's safety and dependability. Food manufacturers are also wanted to know about food transportation and associated information. The important requirements and interests of the individuals who will utilize the food traceability goods should be considered in addition to their high economic value. Food is the most important thing to people, and customers have always agreed. When problems with food safety and quality are discovered, traceability may be used to rapidly pinpoint the source of the problem, the responsible party, and to initiate the recall of tainted food.

The objective of this study is to improve upon the PBFT algorithm by suggesting a new version called Improved PBFT and then to use empirical analysis to establish that it works. Furthermore, it uses T-PBFT to improve dependability and expands the use of PBFT for food traceability. Experimentally confirmed algorithmic innovations that solve PBFT's shortcomings are part of the contribution. The integration into the food traceability architecture guarantees a strong foundation, with an emphasis on practical use and enhanced performance. To advance both consensus algorithms and their practical applications in important sectors, this study provides insights into the practical consequences of the improved algorithm through rigorous analysis. Specifically, it aims to help secure and transparently trace food goods along the SC.

The oversight of the appropriate regulatory agencies is being strengthened and made more effective by incorporating modern technologies and methods of supervision. Food data must be tracked throughout the process in order for it to be utilized for food traceability. The necessary consumer complaint mechanism and the food safety recall procedure put in place by the regulatory bodies are absent from the system. Therefore, once a problematic product causes a health danger, it won't be able to prevent it from accessing the market at the right time. Because of the knowledge asymmetry between the primary supply chain participants, it is hard to ascertain whether the data has been purposefully changed along the circulation process.

Section 2, explores PBFT's principles, design, operation, and use cases. In Sect. 3, details enhancements and optimizations to address limitations and enhance performance and in Sect. 4, presents empirical findings, including performance evaluations and comparative analyses. Section 5, introduces a T-PBFT-based architecture for food traceability, prioritizing transparency, and reliability. In Sect. 6, summarizes findings, implications, and future research directions.

2 PBFT algorithm

In 1999, the authors put out the PBFT Algorithm [17]. Its goal is to resolve the distributed system issue known as the Byzantine Generals Problem. For Byzantine issues, it is now a canonical algorithm. It is proven that there are f Byzantine nodes using the Byzantine Generals Problem. In cases where the necessary number of nodes for the network iss \(N\ge 3f+1\) Keeping the system up and running regularly requires determining how many Byzantine nodes are tolerable \((N-1)/3\).

All the state machine copies in PBFT keep track of the service status, so the user's legitimate request is fulfilled. This distributed method is PBFT's foundation. During the process of each node has real time dependency to reaching consensus, PBFT will run 3 protocols, namely the consistency protocol [18], checkpoint protocol and view switching protocol.

2.1 Consistency protocol

In this algorithm, there are two roles: master node and slave node. Requests to the master node are initiated by the client, and the consistency protocol is conducted in response [19]. The complete protocol execution process is divided into client request, pre-preparation, preparation, submission, and reply. There are 5 stages, and the execution process is shown in Fig. 1.

  1. (1)

    Client inquiry stage The client submits a service request to the master node, the parameters  \(<REQUEST,o,t,c>\) include the client identifier (c), the timestamp (t), and the specified operation (o).

  2. (2)

    Pre-preparation stage When a client makes a request, the master node is responsible for sending out proposal number and send a message to pre-prepare everything \(<<<PRE-PREPARE, v, n, d>, m>\) v, n, d, and m are the view number, message number, summary, and client request message, respectively, to each replica node.

  3. (3)

    Preparation stage The node not only gets the pre-preparation message but also simultaneously transmits the preparation message \(<PREPARE,v,n,d,i>\) to other nodes while simultaneously getting preparation information from those nodes. The node that gets the preparation message will check it against what it has already prepared. The pre-written message is added to the message log whenever the verification fails. When at least \(2f+1\) pre-prepared messages are received, the confirmation phase is entered.

  4. (4)

    Submission stage:At this stage, the node communicates with other nodes, including the master node, by sending the message \(<COMMIT,v,n,d,i>\). The request is considered committed and moves on to the next step when the node gets \(2f+1\) COMMIT signals, including itself.

  5. (5)

    Reply phase Upon completion of the confirmation process, the client is notified by each node's real-time dependence through the message \(<REPLY,v,t,c,i,r>\), where r is the execution outcome of the original request.

Fig. 1
figure 1

PBFT algorithm consistency protocol execution process

2.2 View switching protocol

During the PBFT consensus process, the status of all nodes must be consistent, that is, in the same view. When the slave node \(i\) times out in the view \({v}_{old}\) and does not receive the request sent by executing the protocol for view replacement on behalf of the master node, view number \(v+1\), and start to elect a new master node. Suppose the set of all nodes is N, the node number is \(\left\{ {0,1,2,\;\,\left| N \right|\, - 1} \right\},v_{new} = v_{old} + 1\), the new master node number The calculation formula is:

$$p = v_{{{\text{new}}}} \bmod \left| N \right|$$
(1)

Among them, \(p\) is the main node number, \({v}_{new}\) is the updated view, and \(|N|\) is the total number of nodes.

2.3 Checkpoint protocol

The consensus information generated by the nodes in the system during consensus is stored in the log of the slave node, which will occupy the storage space of the node. Long-term operation of the system will generate a large amount of log information. The checkpoint protocol works periodically, which can help nodes clear out useless information [20]. Log, release node memory resources, and help some nodes that have faults or are not synchronized with the system due to network problems. When the node executes the view switching protocol, the checkpoint protocol can ensure that the node executes the relevant requests before the view switching, ensuring it’sthe order of requests is the same as before.

3 Improved PBFT algorithm

The PBFT algorithm is widely used in alliance chains. Because of its fault tolerance, the network can withstand Byzantine nodes with less damage, and the system may be trusted. But before reaching an agreement, the master node must be chosen. The number of nodes is used to elect the master node [21]. There is a significant likelihood of malicious nodes, which might impact the dependability of the system; secondly, when there is a client request, nodes need to communicate in multiple stages, and the number of communications is high. Especially when the number of nodes in the network increases, the consensus efficiency will be further reduced; Finally, frequent switching of views in the network will lead to increased communication overhead and slower service response.

3.1 Algorithm overview

In the food technology traceability scenario, each enterprise in the system is subject to review or supervision by relevant departments, and active evil nodes will be punished accordingly, so that active evil nodes can be primarily eliminated. However, it is undeniable that when a node has its own fault or Network delay also causes client service request failure. In view of the actual situation in these two aspects, the traceability practical Byzantine algorithm t-PBFT is proposed.

  1. (1)

    Considering that node failures and network delays always exist, a node rating mechanism is set up to evaluate whether a node is in a faulty state. Improve the election method of the master node to avoid electing a faulty master node to minimize view switching. This reduces the impact of a faulty master node on system response.

  2. (2)

    In the original PBFT algorithm, the first two stages have completed the message broadcast and interaction between nodes, and the third stage, together with the view switching protocol, ensures the execution security of requests under different views. Normal changes in views will not cause security problems, only in the main Security issues will only occur when the node crashes. If the master node crashes and executes the view switching protocol, a slave node will broadcast a view switching message to each node. The message contains the last request sequence number obtained by the slave node. When the master node is elected It will be clear that the serial number has been used. In the collaborative food supply chain scenario, each member node undergoes identity authentication and is subject to supervision. The credibility of the node is relatively high, and there is no active evil. The elected master node will not be used for the next consensus. Use the request sequence number again to ensure the correct execution of requests under different views. Therefore, you can consider merging the third communication stage of the original PBFT algorithm to reduce the communication overhead in the consistency protocol process to improve system throughput and reduce purpose of delay.

3.2 Node evaluation mechanism

For possible fault problems in collaborative food supply chain nodes, an evaluation mechanism is introduced to describe the status of the node [22], assign points to the node for its corresponding behaviour, reward or punish the node's behaviour, and master node election based on points [23], thereby enhancing the enthusiasm of node behaviour and reducing the probability of electing a faulty master node.

3.2.1 Initial points settings

The t-PBFT algorithm is mostly employed in alliance chains environment of manufacturers at all levels in the collaborative food supply chain [24], and there are certain differences in the comprehensive strength and social reputation of different food technology manufacturers. The stronger the comprehensive strength of a certain manufacturer's node, the better its performance and stability, the stronger. In view of this actual situation, the comprehensive strength and social reputation the cooperative food supply chain includes used as evaluation indicators for the initial points [25].

\({S}_{i}\) represents the points value of node numbered i, \(n\) represents the number of nodes in the network. When initializing the network score, all enterprises are sorted according to their comprehensive strength, the top \(\frac{1}{3}n\) nodes are taken as outstanding nodes [26], and the initial points are randomly set to be greater than 80 and less than 100, the integration accuracy is accurate to 0.1, the initial integration of the remaining nodes is set to less than or equal to 80 and greater than 0 in order, and the integral decreasing step is 0.1. If \(80<{S}_{i}\le 100\), it means that the node status is excellent and can be given priority is elected as the master node; if \(0\le {S}_{i}\le 80\), the node participates in the consensus as an ordinary node; if \({S}_{i}=0\), it means that the node has experienced multiple failures during the consensus process, and the node will be marked as an invalid node at this time. To participate in the consensus process again, if you need to re-enter the network, the nodes in the SC need to re-authenticate their votes.

The node behaviour state transition is shown in Fig. 2. The process by which a node in a network modifies its state in response to certain circumstances or occurrences is known as node behavior state transition. This idea is frequently brought up in relation to distributed systems, such computer networks, where nodes cooperate to accomplish a common objective. This is a broad summary of the mechanism at play:

  • Initial State Every network node begins in a certain state. This state might stand for a number of different circumstances, including being active, idle, or in a particular operating mode.

  • Event or Trigger In most cases, a state shift is brought about by specific events or triggers. These events can happen internally, such as when a timer expires or the node's internal settings change, or externally, such as when a message is received from another node in the network.

  • Transition Rules Nodes are configured to behave in accordance with preset rules or conditions when specific events occur. These principles are often found in state transition functions or algorithms.

  • Evaluation The node evaluates its current state as well as the conditions around the event in order to determine the next state after it. This assessment may include confirming several factors, such as the node's current workload, available resources, network conditions, etc.

  • State Transition Based on the evaluation, the node transitions to a new state in compliance with preset rules. This transition may include initiating specific activities, modifying internal variables, or notifying other nodes of the state change via messages.

  • Propagation In a distributed system, state transitions may propagate to neighboring nodes and could lead to more state changes throughout the network. This propagation ensures that all nodes remain synchronized and cooperate to accomplish the objectives of the system.

  • Feedback and Adaptation After a state transition, the node may monitor its environment and alter its behavior as needed. This feedback loop enables nodes to adapt to changing conditions and progressively increase their performance.

Fig. 2
figure 2

Node behaviour state transition

Nodes are able to successfully coordinate and collaborate across a dispersed network through the dynamic interaction of events, rules, evaluations, and actions that make up the process of node behavior state transition.

3.2.2 Points update rules

After each consensus is completed, the node points are updated through the checkpoint protocol. If the node performs consensus behaviour, the node will be rewarded with additional points [27], otherwise the node will be deducted. The node communication during the consensus process can be calculated by checking the node log information. Whether the number of times is the same as the expected number of communications, to determine its Behavioral status. To prevent nodes from maliciously broadcasting point values, an ordered list of points values will be generated and stored in each node [28]. Point values need to be included when broadcasting messages.

  1. (1)

    Points increase [29]: By judging the actual communication times of the node, the node's performance during the consensus procedure is evaluated. In accordance with Eq. (2), the t-PBFT algorithm raises the node points.

    $$S^{\prime}_{i} = \left\{ {\begin{array}{*{20}c} {S_{i} + \frac{An}{{Hn}} \times X_{1} ,} & {S_{i} < 80} \\ {S_{i} + \frac{An}{{Hn}} \times X_{2} ,} & {80 \le S_{i} < 100} \\ \end{array} } \right.$$
    (2)

Among them, \(S^{\prime}_{i}\) is the updated integral value of node \(i\), \({S}_{i}\) is the integral value before update, where \(An\) represents the real number of messages exchanged throughout the node consensus process and \(Hn\) represents the predicted number of messages exchanged over the same procedure. If the node conducts a complete consensus process, the ratio between the two is 1, and \(X\) is a fixed constant, which is used to adjust the growth rate of the node integral. Usually, it is decided through consultation among the members in the SC. By setting \({X}_{1}>{X}_{2}\), ordinary people are encouraged to nodes that carry out correct consensus can get more points than excellent nodes.

  • (2) Points reduction [30]: When the actual number of communications of a node \(An=0\), it means that the node has a fault in the consensus process, and the node points are deducted according to Eq. (3).

    $$S^{\prime}_{i} = \left\{ {\begin{array}{*{20}c} {S_{i} - Y_{1} ,} & {S_{i} < 80} \\ {S_{i} - Y_{2} ,} & {80 \le S_{i} < 100} \\ \end{array} } \right.$$
    (3)

Among them, \(Y\) is a fixed constant, and \({Y}_{1}<{Y}_{2}\) is set at the same time to punish outstanding nodes more. If the master node times out or fails during the consensus process, 40 points will be deducted from the master node and it will become an ordinary node.

3.3 Master node election

During the operation of the system, it is necessary to reduce the number of master node replacements as much as possible. When the network is initialized or if the master node fails, the view replacement protocol is begun to replace it. The t-PBFT method depends on an ordered list of values generated and maintained by each node's real-time dependence [31], which is then used to pick the master node. When the point value is high, it means that the node has been quite steady during the consensus process recently. Electing such a node can greatly reduce the probability of view switching, thus ensuring the stability of the system. Improve system efficiency.

  1. (1)

    Network initialization: After completing the initialization of the points of each node, choose the node that has the most points to serve as the master node, while the other nodes act as replica nodes, contributing to the consensus.

  2. (2)

    (2) Master node failure: In this case, the failure of the master node is learned by the replica node [32], and broadcasts to the entire network to elect the node with the highest score in the ordered list it maintains. The subsequent process is consistent with the PBFT algorithm view switching protocol, so it will not be described again. If after a long period of running iterations in the system, multiple nodes with the highest and equal integral values appear, the master node will be randomly selected from this part. Because the penalty score after an error is large, when the view replacement protocol is executed, an error can be guaranteed the master node cannot run for the master node for a long time [33].

3.4 Consensus protocol optimization

The PBFT algorithm is a relatively complex consensus protocol designed to deal with active evil nodes. The submission phase is to allow each node real time dependency in the system to master the status of other nodes. In the food technology [34] traceability network, each member is supervised, has high credibility and a relatively safe operating environment. stable. Along the same lines, following the implementation of the node assessment method, the probability of electing a faulty master node is reduced. Therefore, the submission phase in the classic PBFT algorithm is omitted in the t-PBFT algorithm, which can greatly reduce the system communication overhead [35]. Optimized consensus protocol execution the process is shown in Fig. 3.

Fig. 3
figure 3

Optimize the consensus protocol execution process

The detailed execution process of the agreement includes the following 4 stages.

  1. (1)

    Request phase (t-request): The client sends a request \(<t-REQUEST,o,t,c>\) to the master node.

  2. (2)

    Preparation phase (t-prepare): All the nodes in the network will get the preparation message after the master node has received and verified the request. The structure of the preparation message is \(<<t-PREPARE,v,n,H\left(m\right),s>,m>\),\(H\left(m\right)\) is the client message summary and s is the node score. Execution begins once the node sends the request message and stores it in the local log.

  3. (3)

    Execution phase (t-execute): In this phase, the slave node sends execution messages to all nodes including once it has received the preparation message, the master node continues. The text format is \(<t-EXECUTE,v,n,d,i,s>\),\(i\) Number the node. At the same time, the node will also receive execution messages broadcast by other nodes. Each node needs to verify the message using real time dependency. When 2f + 1 messages pass verification and reach the node, it is considered that a consensus has been reached and the node enters the response stage.

  4. (4)

    Response phase (tGreply): The client receives have real time dependency for response results from each node real time dependency \(<t-REPLY,v,t,c,i,r>\),r is the node response result.

3.5 Algorithm Process

The t-PBFT algorithm is based on the traceability scenario. While introducing the node evaluation mechanism, it also optimizes the original PBFT algorithm consensus protocol. By improving these two aspects, the election probability of the failed master node is reduced, and the corresponding communication overhead is reduced, thereby improving the system. The purpose of performance. The t-PBFT algorithm flow is display in Fig. 4.

Fig. 4
figure 4

t-PBFT algorithm flow

The specific execution process of the algorithm is as follows:

  1. (1)

    Initialize the network, set the initial points of the nodes to 80, number the M nodes in the network with \(\{0, 1, 2, \cdots , M-1\}\), and select the main node according to the points.

  2. (2)

    After Client requests from master node, it will determine whether the master node has timed out: If there is a timeout, the slave node initiates a view conversion protocol message to re-elect the master node. The message contains a deduction of 20 points from the master node. Request, after the election is successful, Real-time dependence deductions by the master node are 20 points per view \(v+1\), and executes the checkpoint protocol to restore the behavior of each node before the view conversion, and the request continues. If the master node does not time out, the request proceeds normally.

  3. (3)

    Request the normal execution of the consensus protocol. After the consensus protocol is successfully executed, each node reaches a consensus, logs the results, and returns the results to the client.

  4. (4)

    After completing the response of real time dependency, calculate the number of communications of each node in this request. If the actual number of communications \(An\) is 0, points will be deducted from the node. If \(0 <An\le Hn\), points will be added to the node. This process Complete the update of node points.

  5. (5)

    After the node updates its points, it packages and generates blocks and executes the periodic checkpoint protocol using real time dependency. Its function is to perform garbage collection, clear some outdated messages of each node under this request, release the node space, and complete the request in one time.

4 Experimental results and analysis

The experimental equipment configuration information is Intel Core i5G8400, 8 GB RAM, Windows 10, 256 GB SSD hard drive. The programming language is used to simulate and implement the t-PBFT algorithm, and different IP addresses are set up through the Docker container to simulate the blockchain environment to ensure that the t-PBFT algorithm and the PBFT algorithm are the experimental environment is the same. This article will conduct experiments on the PBFT algorithm and the t-PBFT algorithm from three aspects: communication overhead, request delay, and throughput, and analyze the performance of the two algorithms through theoretical and experimental results.

4.1 Communication overhead analysis

The number of messages sent and received by all nodes participating in a consensus process is called communication overhead. It is assumed that the system has a view switching probability of p and a total of m nodes in the network. The original PBFT algorithm’s consistency mechanism was introduced in Sect. 1.1,, we can know that The communication overhead in the request phase is 1, There is a total of m communication overhead in the pre-prepare phase, is \(m(m-1)\) in the prepare phase, is \(m(m-1)\) in the commit phase, is \(m(m-1)\) in the reply phase, and is \(m(m-1)\) when view switching happens, making the total communication overhead of the PBFT algorithm:

$$C_{p} = \left( {p + 2} \right)m^{2} - pm$$
(4)

The t-PBFT algorithm simplifies the consistency protocol and introduces a node evaluation mechanism. Analysis shows that it can reduce the probability of view switching. Assume its view switching probability is q, the communication overhead in the t-request stage is 1, and the communication in the t-prepare phase is \(m-1\), the communication overhead in the t-execute stage is \(m(m-1)\), the communication overhead in the t-reply stage is m, the communication overhead in switching views is \(m(m-1)\), the total communication overhead is:

$$C_{tp} = \left( {q + 1} \right)m^{2} - \left( {1 - q} \right)m$$
(5)

The communication overhead ratio Q of the two algorithms is shown in Eq. (6):

$$Q = \frac{{C_{tp} }}{{C_{P} }} = \frac{{\left( {q + 1} \right)m + 1 - q}}{{\left( {p + 2} \right)m - p}},0 < q \le p < 1$$
(6)

Among them, p and q are the view switching probability values ​​of the two algorithms respectively, and the value range is \(0\sim 1\). Replace q with p, and perform the transformation operation on Eq. (6) to obtain Eq. (7):

$$Q = 1 - \frac{m + 1}{{\left( {p + 2} \right)m - p}}$$
(7)

The three-dimensional diagram of visual analysis of Eq. (7) is shown in Fig. 5.

Fig. 5
figure 5

Three-dimensional graph of communication volume ratio between T-PBFT And PBFT

Figure 5 shows that there is a finite value for the number of nodes m. A three-dimensional graph requires three axes: the dependent variable in this case, the communication volume ratio between T-PBFT and PBFT, and two independent variables. Assuming that the number of nodes and rounds are the independent variables, we might create a graph to illustrate how the communication volume ratio changes with these variations.

The potential strategy to create communication volume ration between T-PBFT and PBFT is:

Choose the Parameters: Decide on a range for the number of rounds and nodes that will be included in your study.

Calculate Communication Volume Ratio For each combination of nodes and rounds, calculate the communication volume ratio between T-PBFT and PBFT.

Plot the Graph Use a 3D charting program to create a 3D graph. The graph's x, y, and z axes should represent the quantity of nodes, number of rounds, and ratio of communication volume, in that order.

Assuming a constant view switching probability p, the ratio Q grows with increasing node counts; however, Q is never greater than 1, meaning that the t-PBFT algorithm will always use fewer communications than the PBFT algorithm in a collaborative food supply chain involving multiple nodes. Solving the limit of Eq. (7), we can get \(\underset{\begin{array}{c}m\to \infty \\ p\to 1\end{array}}{\text{lim}}2/3\), that is, \({Q}_{max}=2/3\), which theoretically proves that the communication overhead of the t-PBFT algorithm is reduced by 33% compared with the original algorithm, thereby achieving the purpose of improving system performance.

4.2 Request delay

The request latency is a critical metric for assessing the performance of consensus algorithms. It measures how long it takes for a client to send a request to the master node and for the system to finish the consensus and provide the result. The experimental variable in this study was the number of nodes, which was utilized to measure the algorithm's request under varied node counts Delay. To reduce the experimental error, the average value of 50 requests was taken as the experimental value of request delay. The experimental results are shown in Fig. 6.

Fig. 6
figure 6

Observation latency comparison

From the analysis of the experimental results, the request latency grows steadily worse with increasing node count. There is little to no difference between the two algorithms' request delays and relatively mild changes to the experimental index when the number of nodes is low. However, as the number of nodes grows, the t-PBFT algorithm's request delay changes at a slower rate than the PBFT algorithm's, which makes it more stable and more suitable for multi-node environments.

4.3 Throughput

Throughput generally refers to the number of completed requests that the system can process per unit time, represented by TPS (Transaction Per Second). In the design of the algorithm, the master node introduces the concept of views so that the system can process client requests concurrently, that is, throughput The quantity can better describe this characteristic of the system. The experiment was set up under different numbers of nodes, and the client sent 500 requests. The experiment recorded the time required to complete the processing of these requests multiple times and calculated the average throughput. The experimental results are shown in Fig. 7 shown.

Fig. 7
figure 7

Throughput comparison

Both methods exhibit a little decline in throughput as the number of nodes rises in a small-node environment, according to the experimental results. However, in a multi-node environment, the throughput reduction rate of PBFT is more than that of the t-PBFT algorithm. Between 237 and 363 TPS, the average throughput rose. Overall, the t-PBFT algorithm is more suitable for the field of food technology traceability than the original algorithm.

5 Food traceability architecture based on T-PBFT

After optimizing the original PBFT algorithm, to facilitate the tracking of food products, this article suggests a blockchain-based system design that utilizes thet-PBFT algorithm for the field of food technology traceability.

The upstream and downstream of the food supply chain involve multiple enterprises, which can be briefly divided into raw material suppliers, manufacturers, distributors, retailers, regulatory agencies, and consumers. Using blockchain technology to build a food traceability system, regulatory agencies can realize the monitoring of the collaborative food supply chain Traceability is carried out in every link, effectively breaking the problem of information islands. If a food technology safety accident occurs, regulatory agencies can quickly locate the responsible enterprise and identify the cause of the accident, thereby reducing the impact of the incident. This article combines the model of blockchain technology and selects as the system infrastructure, the alliance chain divides the blockchain food traceability system architecture into six parts for design, namely data collection layer, data layer, network layer, contract layer, application layer and user layer. The specific system architecture is as shown in the Fig. 8 is shown.

Fig. 8
figure 8

Food traceability system architecture

In this architecture, the data collection layer refers to the collection of food technology raw material information, production information, logistics information and sales information in the collaborative food supply chain. At this stage, the related Internet of Things technology can be used for information collection. The data layer refers to the collection of information from the lower layers. Food technology information in each link is stored in the data layer. Depending on the storage capacity of the data layer, it is judged whether to use a traditional database to store detailed information. Only key information or hash summaries of food technology can be stored on the blockchain system. The network layer is based on the P2P network, including consensus algorithm, verification mechanism and propagation mechanism, etc. Inserting the t-PBFT algorithm into this layer can reduce the node consensus communication overhead to achieve the purpose of improving the performance of the traceability system. The contract layer refers to the contract encapsulation of relevant business requirements on the food supply chain. Smart contracts are functional codes that can implement traceability systems. They can automatically execute corresponding commands when certain constraints are met without the need for a third party, and can interact with the underlying structure. The application layer provides interaction with the blockchain system. The interface allows users to access food technology data on the blockchain. The user level is oriented to various roles in the collaborative food supply chain. Each enterprise can upload the collected information to the system, and consumers and regulatory agencies can use the system to Perform query verification.

In the architecture shown in Fig. 8, the data layer and network layer are provided by the alliance chain as the infrastructure in the system. For example, the current mainstream alliance chain platform Hy-perledger Fabric has pluggable components, including consensus algorithms. Users can customize and improve each component according to relevant business needs.

This article proposes this architecture in combination with other food technology traceability solutions, and embeds the t-PBFT algorithm in the network layer. Compared with previous blockchain food technology traceability systems, the improved the advantage of the consensus algorithm is that it can improve the problems of low performance and high system consumption caused by high communication overhead in the food technology traceability SC, thereby improving the connection. Thanks to a digital food system, network participants can now measure food loss and savings more precisely. Food waste may be reduced by using blockchain technology, which promotes trust and openness while keeping digital data in an immutable, decentralized fashion. Together, preservation, enhanced openness, visibility, and data integrity provide a range of benefits that increase public confidence in extended food supply chains (FSCs). Blockchain technology has the potential to enhance traceability, boost the efficacy of recalls, and reduce the likelihood of counterfeit goods and illicit trafficking.

6 Conclusion

Conclusion Based on the PBFT algorithm and combined with the relatively trustworthy characteristics of nodes in the supervised food supply chain, this article proposes an optimized PBFT algorithm suitable for food traceability scenarios—t-PBFT algorithm. The t-PBFT algorithm combines the nodes in the SC with Nodes are divided into three levels, and their reliability is evaluated based on the actual communication volume of these nodes during the consensus process. In addition, the t-PBFT algorithm simplifies the execution process of the consensus protocol, reduces communication overhead, and improves the consensus efficiency of the nodes. Finally, based on the t-PBFT algorithm and combined with blockchain technology, a system architecture model is proposed to meet the needs of food traceability business. In the follow-up work, this system model will be further studied to reduce the relevant differences between the algorithm and the actual application of food traceability, and enhance the applicability of the algorithm. Enhancing safety, quality, efficiency, sustainability, transparency, and regulatory compliance along the whole food supply chain are some of the practical utilities of a traceable scheme for smart and sustainable food supply chain that can be further analysed in future.