# Reputation-Driven Dynamic Node Consensus and Reliability Sharding Model in IoT Blockchain
## 3 System Model
### Node Cross Reconfiguration Sharding Scheme (NCRS)
#### 3.2.2 Details of NCRS  
Sharding is an effective solution to improve the throughput of blockchain. The core requirement of sharding is randomness during sharding and reliability after sharding. To prevent excessive malicious nodes appearing in the same shard leading to the malicious node taking over, this paper shows the design of a shard distribution scheme based on the reputation calculation method introduced in Section 3.1: the minimum value of the sum of the absolute values of the difference between the mean reputation of each shard and the mean reputation of all nodes is obtained. In other words, the sharding scheme satisfying Equation (8) is obtained. Equation (8) is defined as the fitness function, \(k\) is the number of shards, \(N\) is the total number of blockchain nodes, \(N_{i}\) is the number of nodes in the \(i\)th shard, and \(r\) is the node's reputation. \[Fit=min\sum_{i=1}^{k}\left|\frac{\sum_{j=1}^{N_{i}}r_{j}}{N_{i}}-\frac{\sum_{j =1}^{N}r_{j}}{N}\right| \tag{8}\]  
However, there are two problems in solving the fitness function: (1) The fitness function is an NP-hard problem, and the result cannot be calculated in polynomial time. (2) Even if the optimal solution of the fitness function can be solved, there is still a problem: the optimal solution is unique or predictable, which cannot meet the randomness requirement of sharding. To solve the above problems, in this paper, we designed the Node cross Reconfiguration Sharding (NCRS) scheme of blockchain nodes based on reputation. The total number of shard schemes can be calculated according to the combination number formula shown in Equation (9), where \(N\) is the total number of nodes and \(M\) is the number of nodes in a single shard. In the actual calculation process of the fitness function, in addition to the optimal solution, other sharding schemes can also achieve reliable shards. Therefore, the NCRS scheme uses the iterative method to calculate the fitness function. In the iterative process, the node cross reconstruction sharding method is used to obtain a reliable sharding scheme, it does not need to calculate the fitness function solution of the final, it just needs to obtain a certain number of iterations that can be regarded as the result of the reliable shard met sharding scheme. The problem of time consumption and loss of randomness in calculating the optimal solution is solved. Using the total result calculated by the combination number formula as the benchmark, it is found through several experiments that the success rate of sharding with 100% reliability can be achieved when the number of iterations reaches 70% \(c(n,m)\). \[c(n,m)=\frac{n!}{(n-m)!m!} \tag{9}\]  
The implementation process of NCRS is shown in Algorithm 1. The external main body is iteration, and the internal is node cross reconstruction sharding. The number of alternative sharding schemes is quite large. To obtain a successful sharding scheme in a limited number of iterations, targeted sharding reconstruction is required, The new sharding scheme is reconstructed by the method of cross nodes--randomly select a node higher than the average reputation of all nodes in the sharding with the highest average reputation and randomly select a node lower than the average reputation of all nodes in the sharding with the lowest average value for exchange. After the exchange, the average values of the new reputation of the highest and lowest pieces of pre-reputation are close to the average value of the overall reputation, which reduces the value of the fitness function to a certain extent. There are two slices in Figure 4. The reputation of four nodes in slice S1 is [1; 2; 3; 4], and the reputation of four nodes in slice S2 is [5; 6; 7; 8]. The fitness function value before crossover is calculated to be 4. After crossing, you can see that the node with the reputation of 8 in S2 is exchanged with the node with the reputation of 3 in S1.