## 5 Algorithm
### Intra-Cluster Block Allocation
At the RSU level, the demand of RSU \(r_{i}\) for block \(b_{k}\) can be expressed as follows:  
\[\Omega_{ik}=\sum_{r_{in}\in V^{i}}P_{mk}\cdot PR(t_{m}^{d}) \tag{22}\]  
Within an RSU cluster, the transmission latency between nearby RSUs are relatively low, meaning that the block allocation strategy for one RSU will impact the storage demand of RSUs within a certain range. Specifically, suppose block \(b_{k}\) is allocated to RSU \(r_{i}\) for storage, i.e., \(x_{ik}=1\). Let \(C_{i}^{neighbbr}\) represent the set of RSUs within the neighboring region of \(r_{i}\). After the allocation, both \(r_{i}\) and the neighboring RSUs in \(C_{i}^{neighbor}\) will have a reduced demand for the next allocation of block \(b_{k}\) because they can retrieve it from \(r_{i}\) with low latency. The extent of this demand reduction is determined by the physical distance between RSUs. Based on this scenario, we define the block demand function of RSU \(r_{i}\) for \(b_{k}\) as follows:  
\[Q(r_{i},b_{k})=\left\{ \begin{array}{cc}\Omega_{ik}+\sum\limits_{r_{j}\in C _{i}^{neighbor}}\lambda_{ij}\cdot(1-x_{jk})\cdot\Omega_{jk},&x_{ik}=0\\ 0,&x_{ik}=1\end{array} \right. \tag{23}\]  
If \(x_{ik}=1\), then RSU \(r_{i}\) has already stored block \(b_{k}\), meaning that no additional storage resources are required for redundant storage of \(b_{k}\). In this case, the block demand function value of \(r_{i}\) for block \(b_{k}\) reduces to 0. If \(x_{ik}=0\) and \(x_{jk}=0\), it indicates that neither \(r_{i}\) nor its neighboring RSUs have stored block \(b_{k}\). In this case, the block demand function value of \(r_{i}\) for block \(b_{k}\) will increase as the number of neighboring RSUs that require \(b_{k}\) also increases. The parameter \(\lambda_{ij}\) is a physical weight factor, determined by the distance between RSUs within the cluster:  
\[\lambda_{ij}=\frac{D_{l}^{\max}-D_{ij}}{D_{l}^{\max}} \tag{24}\]  
where \(D_{l}^{\max}\) represents the Euclidean distance between the two most distant RSUs within the cluster. Based on the above definitions, this paper proposes VSPGBAA. The algorithm first calculates the vehicle service priority in each RSU based on vehicle dwell time and defines the block demand for each RSU. Then, it considers the dynamic changes in RSU block demand during the allocation process. Finally, the algorithm further optimizes the overall access cost by utilizing the remaining available storage space within the cluster. The complete process of the proposed algorithm is presented in Algorithm 2. The overall process of Algorithm 2 consists of three main steps: Initialization--Greedy Allocation--Cost Optimization. First, in the initialization step, we process the vehicle-related information for each RSU, computing the vehicle service priority and block access probability to determine the block demand of each RSU. Since each RSU cluster must store a complete copy of all blockchain blocks, we ensure this requirement in the greedy allocation step by assigning each block at least once. This guarantees that all RSUs in the cluster can provide complete block data query services for vehicles. During the allocation, blocks are assigned in descending order of demand, prioritizing those with higher demand to achieve a near-optimal allocation that minimizes access cost. After each allocation, we update the impact of the current allocation on neighboring RSUs. Once all blocks have been allocated, the cluster constraint is satisfied, and the remaining storage space can be used for further access cost optimization. In the cost optimization step, we iteratively select the most critical RSU-block pair based on the demand function to perform redundant block allocation. This process is repeated whenever storage space is available, maximizing the utilization of storage resources within the cluster.