# A Classification-Based Blockchain Architecture for Smart Home with Hierarchical PoW Mechanism
## 4 Hierarchical PoW Mechanism  
As far as we know, PoW is the most widely used consensus algorithm in the blockchain which can effectively defend against various malicious attacks [17; 22]. However, it is overloaded for power-constrained IoT devices. We cannot eliminate PoW since it may cause system vulnerabilities and threats. To address the above problem, we propose a moderate-cost hierarchical PoW mechanism for such power-constrained IoT devices to make the trade-off between efficiency and security. In our architecture, we use small-scale private blockchain and each sub-blockchain only records the same category of data. According to the security requirements, we define that a data category has a security grade (SG), i.e., the SG of each data category must be positively related to its security requirement and cannot be much higher to make the IoT device overload. On the other hand, each CN also has the same security grade as a data category. The difficulty of PoW is self-adaptive according to the SG of each CN. The higher the SG, the longer it takes to run the PoW mechanism. Thus, this mechanism allows the CNs that store the data category with low-security requirements to consume fewer resources. However, letting the miners know the SG of the transaction data and run a PoW of corresponding difficulty when a transaction is released is a key problem. We built a blockchain between miners to record the mapping of all the categories of data in the blockchain system to SGs that have been initialized. When a transaction occurs, the source CN constructs a record that includes information such as timestamp, the index of the category of transaction data, transaction content. The miners read the index from the constructed records and obtain the security grade through the mapping. Then, they run the PoW with corresponding difficulty for verification. If the transaction is verified to be legal, the record is added to the current block of the sub-blockchain with the same index of transaction data category. When the current block in a sub-blockchain of a CN is full, according to the working principle of blockchain, the data in the current full block, the hash value of previous block and other information will be published to the whole sub-blockchain network. Miners receive this data and competitively calculate the cryptographic hash value. Once a miner settles down the puzzle, it will publish to the sub-blockchain for verification. If the verified result is acceptable, the block will be encrypted and stored, otherwise, it will be discarded and the above process will be repeated. In addition to setting the security grade, the number of CNs in each VS must be sufficient to reach the security requirements. To avoid the construction of a VS with only a few CNs (e.g., some CNs are deleted from the blockchain), we designed a series of algorithms to manage the process of node joining (i.e., connect to network) and deletion (disconnection). When a new node is connected to the network, each of its CNs is added to the VS that contains its other associated CNs and stores the same data category. If there is no VS associated with the new node in the network, its CNs will be randomly added to a VS in which the stored data category is the same as the corresponding CNs. On the other hand, if the number of CNs in a VS is greater than \(maxn\), then the VS is split into two sets, one of which has a number of \(minn\) CNs and the other is \((maxn\text{-}minn)\). Specifically, there is no association for CNs in these two VSs. Here we can assume that the number of interconnected devices is less than \(minn\) since there are not many associated devices in the context of the smart home. The process for node addition is shown in Algorithm 1. In contrast, when a node is deleted from the network, i.e., disconnected from the network, it may cause the number of CNs in a VS to be less than \(minn\). At this time, we merge this VS and the other VS whose number of child nodes does not exceed \((maxn\text{-}minn)\).