# Improved PBFT Algorithm Based on Comprehensive Evaluation Model
## 3 TB-PBFT Algorithm
### Consensus Process of the TB-PBFT Algorithm  
The TB-PBFT algorithm is improved on the basis of the original PBFT algorithm. Our algorithm adopts the grouping structure, the client distributes the transaction to the primary node of each group, and the PBFT algorithm is implemented to reach local consensus in the group. Each primary node participates in global consensus on behalf of the group. Assuming that there are \(n\) nodes in the system, consensus nodes are divided into several groups, the number of groups is no less than three, and each group has \(m\) nodes. Our algorithm executes the PBFT algorithm in the group, so each group needs at least three nodes. When \(n<9\), our algorithm adopts the PBFT algorithm to complete consensus. The consensus process of the TB-PBFT algorithm is shown in Figure 5, and the detailed consensus process is as follows:  
Figure 4: Primary node selection.  
Figure 5: The consensus process of TB-PBFT algorithm.  
Request: The client sends the _request_ message \(M=\)_<request_, \(o\), \(t\), \(c>\) to the primary node of all the groups, where \(o\) is the specific operation of the request message \(M\), \(t\) is the timestamp of the request message \(M\), and \(c\) is the client.  
Pre-prepare: After the primary node \(p\) receives the message \(M\) from the client, it multicasts the _<<pre-prepare_, \(v\), \(n\), \(d(M)\), _p\(>\)_, \(M>\) message to other nodes in the group, where \(v\) is the view number, \(n\) is the sequence number, \(d(M)\) is the digest of \(M\), and \(p\) is the primary node number.  
Prepare: When node \(i\) receives the _pre-prepare_ message from the primary node \(p\) in the group, it verifies the message and multicasts the _<prepare_, \(v\), \(n\), \(d(M)\), _i\(>\)_ message to other nodes if the message is valid, where \(i\) is the node number.  
Commit: When node \(i\) receives more than \(2f_{m}+1\) the valid _prepare_ message from other nodes in the group, it means that the node enters the commit phase. At this time, node \(i\) multicasts _<commit_, \(v\), \(n\), \(d(M)\), _i\(>\)_ messages to other nodes. Here, \(f_{m}\) is the maximum number of Byzantine nodes that can be tolerated in the group.  
Verify: When node \(i\) receives more than \(2f_{m}+1\) valid _commit_ messages from other nodes in the group, it indicates that the group has reached a local consensus and waits for the response message from the primary node in the group, and primary node \(p\) will participate in the global consensus with other primary nodes on behalf of the group. Therefore, the committed primary node enters the verify phase by multicasting _<verify_, \(v\), \(n\), \(d(M)\), _p\(>\)_ messages to other primary nodes.  
Respond: When the primary node \(p\) receives more than \(2f_{p}+1\) valid _verify_ messages, it indicates that the global consensus has been reached among the primary nodes. The primary node \(p\) will multicast _<respond_, \(v\), \(n\), \(d(M)\), _p\(>\)_ messages to other nodes in the group. Here, \(f_{p}\) represents the maximum number of Byzantine nodes in the global consensus.  
Reply: When node \(i\) receives the _respond_ message from the primary node \(p\), it multicasts a _<reply_, \(v\), \(t\), \(r\), _i\(>\)_ message to the client if the message is valid. When the client receives more than \(2f+1\)_reply_ messages from all consensus nodes, the complete consensus is reached and the transaction is added to the blockchain. Here, \(f\) represents the maximum number of Byzantine nodes in the system that can be tolerated.