# HPoC: A Lightweight Blockchain Consensus Design for the IoT
## 5 Election Algorithm Based on Proof-of-Capability
### Consensus Flow Chart
Because LEADER and VICE-LEADER are unrelated nodes located far apart, the chances of both being offline at the same time are extremely remote; hence, this study does not investigate the possibility of LEADER and VICE-LEADER going offline at the same time. * Digital cache table: each node in the network maintains a digital cache table in RAM according to its storage capacity, and the numbers used to calculate the campaign hash are randomly generated from the specified maximum cache. This means that the node that stores a larger cache table is more likely to find the random number corresponding to the campaign hash in each election round, while the node that maintains a cache table of the same size has more computational power to find the number corresponding to the ELECTION HASH faster. As a result, nodes with largerstorage and computing resources are more likely to become leader nodes, which is compatible with the capability proof concept presented in this study. The digital cache table displayed in the figures is intentionally kept modest for demonstration purposes (only 10 numbers are generally stored), although the table is a massive data table in reality. * Offline: this refers to the case where the LEADER node or the VICE-LEADER node loses the ability to provide services. * Blocks: blockchains generated by LEADER nodes; in this case, blocks specifically means minute blocks and ten-minute enhanced blocks. In Figure 2(a), the whole-network nodes receive the ELECTION HASH and start to look for the corresponding random number. Assuming that the random number is 7, only node A and node B can find the random number, so they become CANDIDATE nodes. As node A has stronger computing power, it finds the number 7 first and sends the election proof to other nodes. Other nodes will return the vote information to node A after receiving the election proof and passing the verification. Once node A receives the vote information with more than half of the number of nodes in the whole network, it considers itself a LEADER node. In Figure 2(b), at the beginning of TERM 1, node A becomes the LEADER node, generates the genesis block, and starts the election of the VICE-LEADER node. This time, assume the random number is 6. Both node B and node E have the conditions to become a CANDIDATE node. Because node B has stronger computing power, it is the first to find the random number 6 and starts sending the election proof to the whole network and collecting the corresponding vote information. When node B collects enough vote information, it will send it to the LEADER node (node A). After receiving it, node A will verify it. After passing the verification, node B will be designated as a VICE-LEADER node. Figure 3(a) shows the consensus period when the double-leaders are online and the whole network operates normally. That is, all nodes submit block TX data to node A, which collects the data and produces blocks before broadcasting to the entire network. In addition, nodes A and B will check each other's heartbeats to see if the other is still connected. When the VICE-LEADER drops the line, the LEADER node (node A) starts the next TERM and elects a new VICE-LEADER, as shown in Figure 3(b). Nodes C, D, and E have become candidate nodes in this round of voting, and node E is the first to find the random number and broadcast to the entire network. Figure 4(a) shows that node E has become the VICE-LEADER node in TERM 2 and has executed the heartbeat monitoring with node A, and the whole network has entered the normal working stage again. Figure 4(b) shows that node B is back online. However, in TERM 2, it has become a FOLLOWER node and is only responsible for generating TX data. Figure 5(a) illustrates that when node A (LEADER node) is offline, node E will automatically become a new LEADER node and start the next TERM, and publish the ELECTION HASH of the new VICE-LEADER in the block with a new TERM. Because node B has stronger storage and computing power, it is the first to find the random number corresponding to this round of elections.