# A Scalable and Trust-Value-Based Consensus Algorithm for Internet of Vehicles
## 4 C-PBFT Consensus Algorithm
### Double-Layer Consensus Structure
#### 4.4.1 Regional Local Consensus  
Node \(RSU_{k}\) receives the request message \(m\) sent by the requesting vehicle in the target area in the format of \(<REQUEST^{2}\), \(o\), \(t\), \(c>\sigma_{c}\), and node \(RSU_{k}\) puts the request message \(e\) into the transaction pool in the target area, where \(O\) indicates that node \(RSU_{k}\) receives the request message \(e\) sent by the requesting vehicle in the target area in the format of \(<REQUEST^{2},o,t,c>\sigma_{c}\), and node \(RSU_{k}\) puts the request message \(e\) into the transaction pool in the target area, where \(O\) indicates the specific operation to be performed, \(t\) indicates the timestamp, which is the time when the requesting vehicle sends the request message to the \(RSU_{k}\), \(c\) indicates the requested vehicle number, and \(\sigma_{c}\) indicates the request for vehicle signature, \(REQUEST^{2}\)'s superscript 2 indicates the request at the second layer. Pre-prepare Phase  
The regional master node p of the target regional committee assigns the serial number to the request message in the transaction pool and broadcasts the preparatory message \(\langle(PRE-PREPARE^{2},v,h,d)_{\sigma_{p}},e>\) to all nodes of the regional committee. \(\langle PRE-PREPARE^{2},v,h,d\rangle_{\sigma_{p}}\) is the signature of the master node \(p\) of the target regional committee using its own private key, \(v\) indicates the view number, \(h\) indicates the sequence number assigned to the request message \(e\), and \(d\) represents a summary of the request message \(e\). Prepare Phase  
After receiving the \(PRE-PREPARE^{2}\) message from the primary node \(p\), node \(RSU_{k}\) uses the corresponding public key for verification. After the verification is successful, node \(RSU_{k}\) sends a \(<PREPARE^{2},v,h,d,k>_{\sigma_{k}}\) message, indicating the signature message of node \(RSU_{k}\), to other nodes in the owning area committee, including the primary node. Commit Phase  
If \(RSU_{k}\) receives \(2f+1\)\(PREPARE^{2}\) messages that pass the authentication, \(RSU_{k}\) enters the confirmation phase. The \(\langle COMMIT^{2},v,h,d,k\rangle_{\sigma_{k}}\) multicast message is sent to the node that receives \(2f+1\)\(PREPARE^{2}\) messages that pass the authentication. Reply Phase  
If node \(RSU_{k}\) receives \(2f+1 COMMIT^{2}\) messages that pass the authentication, it indicates that most nodes in the current regional committee have reached a consensus. Node \(RSU_{k}\) sends a reply message \(<REPLY^{2},v,t,c,k,r>_{\sigma_{k}}\) to the area master node \(p\) of  
Figure 3: The whole process of C-PBFT’s consensus. the region, where \(r\) represents the execution result of the requested operation. Master node \(p\) of the area confirms that the area has reached \(a\) consensus by checking that more than \(f+1\) members in the current area, including itself, reply to the \(REPLY^{2}\) message with the same serial number. The regional master node sends a request to the first-layer master node \(p\) to send the consensus data \(m\) to the first-layer master node, opening a new round of consensus requests. The algorithm pseudocode is described in Algorithm 2. ```
Input:\(<REQUEST^{2},o,t,c>_{rc}\) Output:\(<REPLY^{2},v,t,c,k,r>_{rk}\)
1.while valid \(<REQUIST^{2},o,t,c>_{rc}\) received = True do
2. broadcast \(<<PRE-PREPARE^{2},v,h,d>_{cp},e_{2}>\) to \(r^{2}\) in same consensus group. 3.endwhile
4.while valid \(<<PRE-PREPARE^{2},v,h,d>_{cp},e_{2}>\) received = True do
5. broadcast \(<PREPARE^{2},v,h,d,k>_{rk}\) to \(r^{2}\) in same consensus group. 6.endwhile
7.while valid \(<PREPARE^{2},v,h,d,k>_{rk}\) received = True do
8.if number of valid \(<PREPARE^{2},v,h,d,k>_{rk}>2f+1\)then
9. broadcast \(<COMMIT^{2},v,h,d,k>_{rk}\) to \(r^{2}\) in same consensus group. 10.endif
11.endwhile
12.while valid \(<COMMIT^{2},v,h,d,k>_{rk}\) received = True do
13.if number of valid \(<COMMIT^{2},v,h,d,k>_{rk}>2f+1\)then
14. broadcast \(<REPLY^{2},v,t,c,k,r>_{rk}\) to \(r^{2}\) group leader. 15.endif
16.endwhile
```  
**Algorithm 2** Regional Local Consensus Pseudocode