A Cost-Efficient-Based Cooperative Allocation of Mining Devices and Renewable Resources Enhancing Blockchain Architecture

: The impressive furtherance of communication technologies has exhorted industrial companies to link-up these developments with their own abilities with the target of efﬁciency enhancement through smart supervision and control. With this in mind, the blockchain platform is a prospective solution for merging communication technologies and industrial infrastructures, but there are several challenges. Such obstacles should be addressed to effectively adopt this technology. One of the most recent challenges relative to adopting blockchain technology is the energy consumption of miners. Thus, providing an accurate approach that addresses the underlying cause of the problem will carry weight in the future. This work addresses managing the energy consumption of miners by using the advantage of distributed generation resources (DGRs). Along the same vein, it appears that achieving the optimal solution requires executing the modiﬁed reconﬁrmation of DGRs and miners (indeed, mining pool systems) in the smart grid. In order to perform this task, this article utilizes the Intelligent Priority Selection (IPS) method since this method is up to snuff for corporative allocation. In order to ﬁnd practical solutions for this problem, the uncertainty is also modeled as a credible index highly correlated with the load and generation. All in all, it can be said that the outcome of this research study can help researchers in the ﬁeld of enhancement of social welfare by using the proposed technology.


Introduction
Peer-to-peer (P2P) energy management has become a practical and technical solution since distributed grids are introduced. Research suggests that the procedure of electrification is evolving around the clock owing to the merging of microgrids and distributed generation resources (DGRs) [1]. Block chain technology is also an emerging technology in both science and the industry. Therefore, all the network's agents will have access to information in distributed energy management [2]. Recently, researchers have become much yearned in researching the distributed energy management based on blockchain. Basically, researchers always have a thirst for investigating new topics. However, the deployment of blockchain technologies does not entrust a straightforward choice because there are challenging obstacles in its way. Thus, the present study focuses on the issue

Energy Consumption of Miners
Different algorithms are used within blockchain technology to provide the consensus among the active nodes, validate and generate the data blocks including proof-of-work (PoW), proof-of-stack (PoS), Byzantine fault tolerance algorithm (BFTA), etc., among which the PoW is the most authenticated [14]. Using the PoW method, validation of the data blocks and consensus among the nodes is carried out by some of the validator nodes' so called "Miners". Based on the PoW method, the consensus is accomplished by miners by using some complicated mathematical calculations that are complex, energy demanding, and time-consuming and are known to be significant challenges relative to PoW algorithms. To overcome the high energy demand issue of the PoW method, some major works are proposed in the literature. Some literatures investigated hybrid methods wherein a combination of different methods is used to handle the consensus among the nodes in the blockchain framework. United Bitcoin is proposed on the UTBC website [15] in which the data blocks are mined by both the PoS and PoW algorithms in order to provide consensus attainment. The same view point is followed in PPCoin website [16], wherein the PoW and PoS methods are employed in a multi-stage manner. The PoW is used firstly to provide a fair environment among the nodes, and then the PoS is employed in order to assure network security. A proof-of-activity (PoA) approach is represented by Bentov et al. in [17], which benefits from both the PoS and PoW methods. In their work the nodes need to carry out some extended works to accomplish the consensus in the network. Tosh et al. [18] have represented a Cloud PoS method to provide the security of recording data in the cloud architecture. Moreover, Xue et al. [19] proposed a proof-of-contribution (PoC) to reduce the energy consumption of the miners in PoW consensus protocol. In their approach, the miners receive a reward for every successful mining instance and encourages the miners to be honest in the process instead of utilizing more machines for rewards. However, none Sustainability 2021, 13, 10382 3 of 24 of these and similar references have concentrated on how the energy consumption of the minors in the power network is managed, which is the main focus of this paper.

Allocation-Based Energy Management
Since lack of control and supervision can deter the optimal operation of the system, the energy management system is a proper approach to redress. The energy management system is established to regulate the power flow in the grid, wherein all components such as sources, loads, and storage converge to the optimal point [20,21].
Suitable placement of DGRs and the use of proper energy management policy in the grid have been well surveyed in the literature [22][23][24][25]. In this regard, Gözel et al. [26] has proposed a theoretical approach for the proper allocation of DGRs in radial grids to minimize the total power loss of the grid without mining admittance matrices. The method is robust and promising for a small grid, yet its efficiency and accuracy are dubious for a big network. Similarly, Prabha et al. [27] have investigated a sensitivity factor with the meta-heuristic method for optimal sizing and placement of DGRs sequentially. This method uses a multi-object fitness function for the environment of the search algorithm, but it is naturally slow and computationally takes a long period of time for a big network. Nevertheless, Khalesi et al. [28] have proposed an efficient algorithm for large power grid.
In this research, the optimal placement carries out simultaneously for the miners and DGRs in which the energy consumption of miners will be controlled. The Intelligent Priority Selection algorithm (IPS) has been proposed for solving the issue. Supplementary information about this approach is given in the next sections. The proposed algorithm is completely proper for a large grid because it decreases state space.
The renewable energy sources (RESs) have brought many promising benefits to the power systems in terms of loss reduction, reliability improvement, and air pollutants diminishment [29,30] and roles markedly in the modern power grids. Apart from the RESs' advantages, they are of high uncertainty factor since their output power fluctuates, and this is a result from the climate changes [31]. The same issue goes for the loads of the system that could vary regularly and that are not precisely predictable. Hence, the uncertainty has been the core of attention of the body of literature during the last few years, and researchers have proposed effective approaches for handling this issue in the power systems' problems, where some of these methods are exploited in [32]. Generally speaking, some of the main approaches for capturing the uncertainty in models can be mentioned as (I) the Monte Carlo method, (II) analytical methods, and (III) approximate methods. Some major differences are worth mentioning. The Monte Carlo provides the utmost accuracy while it retards calculation time. The analytical methods employ some simplifications in the modeling to compensate for the solution time of the first method, but it loses its preciseness by doing so. The third category brings both accuracy and speed, which is the most preferable method. The unscented transform (UT) method, which belongs to the category III, is utilized in this paper to model the uncertainty associated with the model, which will be further explained.
All in all, the main contributions in this paper can be summarized as follows: • Modelling and precisely formulating the blockchain structure based on the energy consumption of the miners during the process of data transactions; • Suggesting the modified reconfiguration of mining devices using an IPS based effective corporative allocation algorithm to improve the energy management of the blockchain technology; • Developing a stochastic effect based on unscented transform method to precisely model the energy management of smart grid in the presence of blockchain tech.
The rest of the paper is organized as follows: Section 2 represents the proposed blockchain tech-based security management structure. Section 3 expresses the utility function related to the energy consumption of miners. Moreover, in Section 4, the energy management framework of the smart active grid based on DGRs is discussed. In addition, the proposed IPS based corporative allocation algorithm is described in this section. Uncer-Sustainability 2021, 13, 10382 4 of 24 tainty modeling is explained to cover the uncertainty effects in Section 5. The results on the test system are discussed in Section 6. Finally, Section 6 expresses the outcomes and advantages of the proposed approach.

Security Achievement under Blockchain Technology
After introducing the basics of blockchain in 2008 by Nakamoto et al. [33], the deployment of this technology has recently begun to flourish in different sciences such as economics, technical sciences, etc. Recently, blockchain technology has been employed increasingly in the concept of Internet of Things (IoT) to perform tasks including identity recognition, voting, and data authenticity identification [34]. The blockchain technology is a secure platform based on a distributed manner with no central part governing the nodes, which is tolerable against concealed subversive penetrations. Thus, the blockchain substructure needs to make sure that it exploits the verified honest nodes to counteract the destructive behavior of the attackers. In the following subsections, the basic principles of the blockchain framework and the modeled attack are explained in separate parts.

Blockchain Structure
As outlined above, blockchain generally has been designed to provide security in decentralized or P2P environments. Thus, there is no longer a centralized agent in such structures, and the agents are able to exchange with each other in the blockchain network to verify the transactions, which will avoid activity on the unhealthy nodes that can sabotage the system's operation. In addition to providing security and creating a P2P environment, there is one other important reason for employing a blockchain framework based on a decentralized network. This advantage is the faster attainment of a consensus because of the elimination of the central supervisory. In the blockchain framework, each data in a chain will be protected by assigned hash addresses (HAs) in order to avoid being tampered by a saboteur. Figure 1 depicts the mining process of blocks in the blockchain tech. From the above expressions, it is evident that the blockchain platform has several key components: 1-decentralized networks as a main substructure; 2-the consensus algorithm for verifying the performed transactions; and 3-cryptography process. Each of the items is explained briefly in the following subsections.

Decentralized Network
The consensus in the decentralized networks will take place if all nodes cooperate to achieve a common goal. In such structures, a transaction will be legally registered provided that all agents validate a new transaction. Therefore, what hinders consensus is the sabotage and manipulation of data. The agents attempt to overtake one another in generating new data blocks in a tough competitive space and broadcast them to the network within a specified timespan in a P2P manner. There are two main strategies of blockchain called private and public blockchains, which are different in terms of security and accessibility of data [35]. Indeed, blockchain exclusively relies on the basic principle of P2P theory (decentralized grid) in such a manner that connecting/disconnecting to the network does not interfere with the duty of other nodes.

Consensus Protocol and Algorithm
The decision on whether a transaction is valid or not is the responsibility of the consensus algorithm. In this regard, any nodes will attempt to collect the data blocks and then will validate the identity of each broadcasted transaction. Thus, the broadcasted data are registered when a specific number of validators confirm their identity. Therefore, if a specific number of validators confirm the data block's identity, the broadcasted data are registered by each node and then added to the ledgers. There are several consensus protocol methods, but the "fault-tolerant consensus" seems more practical than the rest. After updating ledgers, the confirmed transaction must be added to the chain by one of the nodes. If any node successfully solves a complex equation, it can add the verified Sustainability 2021, 13, 10382 5 of 24 data to the chain and receive a reward. Three pivotal components are very effective in the consensus algorithm operation. The first factor is the broadcasting of data synchronously, in which the rate of coordination of the nodes is very significant. A network is called a synchronization in which all nodes simultaneously broadcast their data in iteration r and receive responses in iteration r + 1. The consensus protocol basically defines specific rules that govern the details of transactions among the nodes and guarantees an ultimate agreement in the network. As a third principle, the consensus algorithm must be robust against the improper performance of some nodes. In addition to the above three pivotal elements, the consensus algorithm must generally come off four targets. Agreement, integrity, validity, and termination are the final goals of the consensus process. Agreement is when all optative nodes admit one unique solution obtained by the algorithm. If all active nodes attempt to attain the common goal, integrity will be obtained. Validity creates stability and safety in the network through the guarantee of transactions. Finally, any algorithm must converge to the specific response that it is the termination of the process.

Decentralized Network
The consensus in the decentralized networks will take place if all nodes coopera achieve a common goal. In such structures, a transaction will be legally registered prov that all agents validate a new transaction. Therefore, what hinders consensus is the sabo and manipulation of data. The agents attempt to overtake one another in generating data blocks in a tough competitive space and broadcast them to the network within a s fied timespan in a P2P manner. There are two main strategies of blockchain called pr and public blockchains, which are different in terms of security and accessibility of data Indeed, blockchain exclusively relies on the basic principle of P2P theory (decentralized in such a manner that connecting/disconnecting to the network does not interfere with duty of other nodes.

Cryptographic Process
New transactions in the system are sealed and broadcasted through the data blocks across the network. New data blocks are added to the blockchain network, followed by their validation by the nodes. If the authenticity of the block is approved, a copy of the validated data block is stored in the distributed ledgers. It is obvious that the data block consists of different parts including transactions, nonce, height, Merkle root, etc. In blockchain technology, the essential data are transmitted through data blocks, sealed, and encrypted by using cryptography HA generation mechanism, and all the nodes (agents of the system or market participants) need to confirm the data block authenticity. Moreover, each data block carries the HA of the previous block, which makes each block relevant to the previous one and forms a chain that is tolerable against intentional manipulations. After broadcasting the data blocks and receiving them by the nodes of the network, they are able to access the data blocks by a public key. The data blocks are sealed by the Has, which can be 32-bit compounded words using the hash function SHA-256, or other methods such as SHA-512, SHA-384, SHA-224, etc. The HA function generates random HAs for each data transaction process. Hence, unauthorized access or data manipulation will be immediately recognized as soon as the receiver starts processing the received data block. In order to conduct proper time analysis, the following equation can be used: where T sig defines a time duration of signature verification, q indicates the average number of transactions received by a node, T back-off is known as the back-off time which is defined by the utilized protocol by Sheikh et al. [36], T trm is the time takes for the data to be broadcasted from the sender to receiver, t prod is block generation time and t Mining implies the time needed to mine a data block, and T tot-chain indicates the total consumption time for the entire blockchain framework.

Utility Function Formulation of Mining Devices
One of the main steps of the blockchain framework is data mining. The central processing unit (CPU) carries out the data mining process. Thus, this section of blockchains is considered a huge energy consumer. This section surveys the energy consumption of the miners during the trend of data mining. Therefore, speaking about the energy consumption of miners is the energy consumption of CPU and its clock cycle indeed. The clock cycle is the number of tasks that the CPU will be able to process per second; therefore, it is in direct proportion to the energy consumption of miners. Thus, the consumption of energy by the CPU can be stated as Equation (2).
Each of the parameters in the above equation is defined as follows, respectively: P m is the energy consumption of miners; S is a constant value associate with the CPU's power; V is the voltage; f is the CPU's frequency. The operating frequency in Equation (2) characterizes the computational power of the CPU. On the other hand, data mining in the blockchain is in direct proportion to the hash ratio that the CPU can process per second. If the relationship between frequency and computational power of CPU is assumed to be linear, then Equation (2) can be stated in the following form.
After substituting Equation (2) into Equation (3) and reordering the terms, the following formulation for the energy consumption of the CPU can be defined.
Moreover, the relative energy demand of minor i can be formulated as follows.
Furthermore, it must be considered that the action of data mining could be successful or not because of data frequency. Hence, the Poisson distribution is adopted to compute the probability of successfulness of data mining. Equation (6) obtains the probability of successfulness of each miner. Pr where ψ is a constant value and is defined by a delay factor. Moreover, t i implies the total number of transactions embedded in a new data block. As previously mentioned, the agents try to obtain more benefits by adding the block to the chain in a competitive space. This benefit can be provided through tax as a public service. In other words, each miner can earn more benefits if it plays more actively than others. Equation (7) indicates the benefit of the miner.
In Equation (7), please note that the role of y i P i is the cost of power demand supply for the minor, which may be considered as a benefit for the smart grid. Moreover, it should be noted that the benefits of the minors come around two main parts: (1) the power demand, which should the minor buy from either the smart grid or the smart city, and (2) the higher tax, which the minor owner would pay to the smart grid/smart city for higher security, which is needed to be provided by these agents. Therefore, the more minors exist, the more benefits the smart grid and smart city would earn. Sustainability 2021, 13, x FOR PEER REVIEW 9 of 28

The Basic Formulation of the Smart Grid
A comprehensive and axiomatic apperception of energy management can be entirely accomplished if the objective function pursued by the smart grid is well-known. On this basis, this part explicates the varied segments of the underlining objection function and the examinants of the conflicting factors relative to minimizing the relevant goals in the smart grid. Generally, Equations (8)- (20) are aimed at describing the objective function and the limitations of smart grid operation. It is true to say that the proposed function in Equation (8) can overshadow the grid operation goals, including the operation cost, start-up cost, and shot-down cost in line with the generation units. One of the essential issues relative to the effective operation of system is being aware of the active/reactive power generation limitations modeled by the Equations (12) and (13). The active power stability of electrical grid needs to be regularly checked by taking account into the load demands as defined by Equation (9). Similar to active power, Equation (10) demonstrates the balancing relationship between the reactive generation/demands. What is worth mentioning is the voltage stability of the smart grid discovered by Equation (11). The use of reserve power pertaining to the generation units can successfully assist to improve the energy management in the cases of contingency. Hence, regarding the reserve power constraints, Equations (14) and (15) are a must for the generation units. Physically, the loads and resources are coupled by the modified linear AC power flow described in detail by Sheikh et al. [37]. In this regard, the active/reactive power injection from bth bus to eth line can be calculated by Equations (16) and (17). In addition to that, the power flow through lines is restricted up to a permitted level, in

The Basic Formulation of the Smart Grid
A comprehensive and axiomatic apperception of energy management can be entirely accomplished if the objective function pursued by the smart grid is well-known. On this basis, this part explicates the varied segments of the underlining objection function and the examinants of the conflicting factors relative to minimizing the relevant goals in the smart grid. Generally, Equations (8)- (20) are aimed at describing the objective function and the limitations of smart grid operation. It is true to say that the proposed function in Equation (8) can overshadow the grid operation goals, including the operation cost, start-up cost, and shot-down cost in line with the generation units. One of the essential issues relative to the effective operation of system is being aware of the active/reactive power generation limitations modeled by the Equations (12) and (13). The active power stability of electrical grid needs to be regularly checked by taking account into the load demands as defined by Equation (9). Similar to active power, Equation (10) demonstrates the balancing relationship between the reactive generation/demands. What is worth mentioning is the voltage stability of the smart grid discovered by Equation (11). The use of reserve power pertaining to the generation units can successfully assist to improve the energy management in the cases of contingency. Hence, regarding the reserve power constraints, Equations (14) and (15) are a must for the generation units. Physically, the loads and resources are coupled by the modified linear AC power flow described in detail by Sheikh et al. [37]. In this regard, the active/reactive power injection from b th bus to e th line can be calculated by Equations (16) and (17). In addition to that, the power flow through lines is restricted up to a permitted level, in compliance with the constraints of Equations (19) and (20) in which bus angles within their acceptable range are controlled by Equation (18).
The wide utilization of DGRs, especially the allocation term, within the smart grid is growing at a tremendous pace. It is a proven fact that each DGR takes into account its unique features and gives the smart grid the chance of optimally improving the energy management in the peak-load state. Hence, it seems that DGRs are able to boost the problems' definition (high-energy consumption of miners) and are defined in the following manner. We decide to effectively use the operative units such as the storage unit, wind turbines (WTs), photovoltaic (PV), and tidal units located on the buses of the smart grid [38]. Firstly, each unit aims to pursue its cost-efficient-based objective function in accordance with Equation (21). The generation limitations related to each DGR are formulated based on the technical potential by Equations (22)- (24). Moreover, binary variables w b , i b and v b determine whether it is necessary to place the relevant DGR in bus b or not. One the main challenge facing DGR is the generated power fluctuation owing to the uncertainty concept. For this reason, all the defined DGRs are equipped by the storage unit in order to dynamically inject power to the grid in critical cases. The relevant restrictions are molded based on Equations (25)- (28). Limitation (25) provides the hourly energy level of the storage unit by taking account into the charging/discharging power of the previous hour.

The Intelligent Priority Selection Algorithm Framework
As it was previously elucidated, DGRs can be introduced in order to yield two of the most pivotal goals: (1) providing environmentally-friendly energy generation resources and (2) reliable energy-demand supply of mining devices. These aims would be comfortably realized if an adaptive location of DGRs is coincidently assigned and the mining devices use a cost-efficient-based appropriate algorithm. In the literature, the varied approaches are commonly investigated in order to obtain simultaneous allocation subordinated to basic mathematical modeling or artificial intelligence. It is a proven fact that such methods do not take the first place for simultaneous allocation owing to its long passing time and inadequate accuracy. In light of this evidence, this section of the paper recommends a costefficient-based algorithm to concomitantly seek the location of DGRs and miners by taking into account accuracy and runtime improvement. In the first place, being inspired from statistics concept, extracting the number of n from N matrix is computed as stated below.
Apart from having high accuracy, the structure of such a model induces a long period of solving time due to the massive search space. Along the same vein, the proposed method revolutionizes such a model and decreases the overall runtime by smartly limiting the search space. To be clear, the following process mainly demonstrates the performance of the proposed algorithm.
Step1: First, assume that an arbitrary set P of the possible selections includes all candidate places of the problem. The number of DGRs and miners as the control variables is determined by the size of the K matrix in which the candidate places are randomly inserted in the first step. Then, the other places of set P (P-K) are saved by the set W. Merging the points of K and W matrices result in most possible states of the allocation problem. Hence, all points of the W matrix are substituted for the member of k matrix and saved in the KT matrix. The outage of sorting members of the KT matrix is modeled by the set H, the best member i th of which is selected by computing the optimal objective function, as indicated by F best W 1 ,K n . It is important to note that K n in Equation (33)   The objective function value of each best member of H W i is regularly saved in Equations (34) and (35). Components of K and W matrices result in F best and are indicated and stored by W j , K j matrices in Equations (36) and (37), respectively. Finally, the first level of F best m is opted as the most optimal answer.
Step2: In this stage, we aim to obtain the new matrix KT new r by updating the member of W j by Equation (39), with the aim of calculating the final best objective function. After checking the old matrixes k j and w j , these matrices need to be removed, and the remaining points by matrix K1 new j are updated. Merging the new points related to w j and KT new r results in matrix ψ r in Equation (41), where r is obtained based on m − j, which include the matrix length of W and the number of the needed iteration, respectively. Then, the best objective function (F1 Best ) among the members of ψ r is opted for, and the relevant component is saved in matrix ψ Best , as demonstrated by Equations (42) and (43). Finally, Equation (44) shows that matrix K needs to be updated, becoming compatible with ψ Best for each iteration j.
Step3: With respect to the descending trend of sorting matrix F best_sort , the first component is selected as the optimal answer in each iteration.
The flowchart of the proposed allocation algorithm is shown in Figure 3. Sustainability 2021, 13, x FOR PEER REVIEW 14 of 28

Stochastic Quantization Model
The presence of DFRs in the smart grid can convince taking accurate looks at the stochastic effects on the energy management of miners in blockchain structure. Inspired from the uncertainty concept, this section intends to model the exiting uncertainty parameters by using the correlating framework-based UT approach. This method is basically organized to precisely turn the probability density function of a random point into a few discreet distribution points [39]. Focusing on a nonlinear function T =f (Q), the stochastic outage of vector Q results based on the main objective function f. It is important to say that Q is considered as a vector, including p number of stochastic parameters, mean value of z, and covariance matrix of A. The UT method solves the proper 2p + 1 times in order to capture the uncertainty related to the model. The following steps mainly explain the UT method process.
In the above, matrix A aa shows the covariance values and R = z.
Step2: The weight of each point is calculated by Equations (47) and (48) is obtained by Equation (49).
The summation of the weights is equal to 1.
Step3: By inserting these points into the nonlinear function T k =f Q k , the output values are computed by the following.

Simulation Results
Developing the basic structure of blockchain technology is a vital requirement to fully cover challenges of the miner energy consumption and cyber-security which are in conflict with each other. Therefore, it is very important to find a method to reconcile two conflicting views. With the advent of these issues, we believe that picking out a proper cooperative location of the miners and renewable resources can be the best available solution to deal with challenges facing blockchain architecture. To prove the truth of the matter, in this section we try to capture more attention to the acceptance of the above solution' effectiveness by taking account into different cases. To obtain the best knowledge, firstly, some further elucidations related to the conflicting relationship between the energy cost of miners and pretention of cyber-attacks arising from the wild fluctuations in miner hash rates must be mentioned. In addition to that, we will represent the miners that can earn more revenue through such a modified framework of the blockchain architecture within the smart grid. Moreover, by being inspired from uncertainty concept, the effects of uncertain parameters arising from DGRs on the benefits and costs of miners are completely examined.
It is worth mentioning that the smart grid is made up of some fossil fuel-based generation units, lines/buses, and electrical loads that are compatible with the IEEE 24-bus test system. In addition, renewable resources include a photovoltaic unit, wind turbine, tidal turbine system, and storage unit aiming to improve the energy management of smart grid [40][41][42][43][44]. Considering the steady state analysis of the study, the constant P-Q model is considered for the renewable energy sources. Based on the argument cited above, we consider the relative results in different studied cases:

•
Mode I: assessing the blockchain technology under various hash rates; • Mode II: analyzing the IPS based simultaneous allocation of mining devises and DGRs; • Mode III: checking the effect of uncertainty on the energy cost of miners; • Each mode is expressed and discussed in detail in the subsequent parts.

Assessing the Blockchain Technology under Various Hash Rates
The discussion in foregoing sections demonstrated that one underling challenge overshadowing blockchain structure within the smart grid is the required energy consumption of miners aiming to perform data mining. After examining this issue, it is evident that the energy consumption of miners can be seriously eclipsed by a number of main factors including the miner hash rate, the new block size at each time, and so forth. On the flip side, decreasing the hashing process speed of mining devices unlocks a smooth method for the high penetration of Cyber-attacks in blockchain platform. In another words, the environment of data exchanging is safely guaranteed if the hash rate is adequately raised relative to the miners embedded in the blockchain structure. Meanwhile, this work intensifies the energy consumption of miners relative to the energy management intricacy of smart grid. To make this issue clear, assume two cases, (1) low-speed hashing rate and (2) high-speed hashing rate, considered for mining devices throughout blockchain platform. In this study, the low-speed rate is 512 kilo hash per second and the low-speed rate is 256-kilo hash per rate. Furthermore, let us assume the number of 24 miners for the security framework and a decision for their location in the smart grid is required. In the light of the evidence, we focused on carrying out blockchain technology on the smart electrical grid and indicate the relevant consequences in Figures 4-6. It can be deducted from Figure 4 that the needed energy of miners in order to elicit information from the new blocks' tracks an ascending order for cases 1 and 2, respectively. In contrast, the successful probability of an FDI-based attack launched on the network for case 1 shows an upward trend, overtaking case 2 as indicated in Figure 5. These opposing trends mean that the cyber-security concept and the energy consumption of mining devices function in differently in the blockchain platform.
As it was previously mentioned, the operation cost of smart grid in the modified structure of blockchain is made up of three parts, i.e., the energy cost of non-renewable units, the cost of DGRs, and, finally, the consumed energy cost of the mining devices in virtue of cyber-security of the network. As a matter of fact, the blockchain-based secure framework may literally muddle the energy scheduling of smart grid, which in turn can force the addition outlay to the total operation cost. Such a discussion may be observed by looking at the convincing consequence shown in Figure 6. In the light of this result, the operation cost of smart grid takes an ascending trend from case 1 to 2 owing to the high energy consumption of mining devices. With finer examination results, it is very significant to find an effective method to conciliate these opposing views, the cost of miners, and cyber-security. According to Figure 6, as the hash rate of the miners increases from case 1 to case 2, higher operating costs would be experienced by the smart grid. In other words, it is true that a higher hash rate of the miners would provide higher security for the smart grid by actively using the blockchain, but on the other side the energy management cost would be increased. Therefore, one may conclude that the smart grid operator can provide an appropriate balance between requiring security and the operation costs according to his/her preferences and the system's status. Sustainability 2021, 13, x FOR PEER REVIEW 17 of 28      method to conciliate these opposing views, the cost of miners, and cyber-security. According to Figure 6, as the hash rate of the miners increases from case 1 to case 2, higher operating costs would be experienced by the smart grid. In other words, it is true that a higher hash rate of the miners would provide higher security for the smart grid by actively using the blockchain, but on the other side the energy management cost would be increased. Therefore, one may conclude that the smart grid operator can provide an appropriate balance between requiring security and the operation costs according to his/her preferences and the system's status. Figure 6. The operation cost of smart grid.

Analyzing the IPS Based Simultaneous Allocation of Mining Devices and DGRs
In the previous subsection, we tried to prove that finding a feasible balanced solution to overthrow the underlying drawbacks between the blockchain system and the smart grid is a must. Thus, this section is organized to confirm that the safe environment of data exchanging in the smart grid can be entirely assured if the optimal adaptive area of mining devices is purposefully assigned within the blockchain tech. To this end, firstly, we carry out the allocation algorithm based on the IPS theory and demonstrate the assessment results of the

Analyzing the IPS Based Simultaneous Allocation of Mining Devices and DGRs
In the previous subsection, we tried to prove that finding a feasible balanced solution to overthrow the underlying drawbacks between the blockchain system and the smart grid is a must. Thus, this section is organized to confirm that the safe environment of data exchanging in the smart grid can be entirely assured if the optimal adaptive area of mining devices is purposefully assigned within the blockchain tech. To this end, firstly, we carry out the allocation algorithm based on the IPS theory and demonstrate the assessment results of the proposed algorithm compared to the other well-known methods, i.e., Firefly algorithm (FA) [45], Genetic Algorithm (GA) [46], and Bacterial Foraging (BF) [47]. In the literature, the passing time and the accuracy have gained attention as two critical matters for evaluating the optimal qualified strategy [48][49][50]. Hence, Figures 7 and 8 provide sheer information about the simulation outcome of varied methods for the same studied case. Figure 7 shows that the IPS method takes a potential tendency toward a descending method for optimal computing of a total cost of 4.69850 × 10 9 (¢). Looking over Figure 8, the other algorithms failed in rivalry with the IPS and obtained high values of total cost, which means the proposed algorithm is the optimum one. As elucidated before, the appraised algorithm aims seek corporative locations of mining devices and DGRs in order to eliminate the mentioned concerns. Hence, the relevant consequences are depicted in Figures 9 and 10. It can be inferred from results that the smart grid for handling the consumed energy arising from the security support system needs to be optimally assigned the 18 DGRs, made up of three PV units, nine WT units and six tidal turbine units located on buses in compatible with Figure 9. On the one hand, the blockchain tech is obligated to make an appropriate reconfiguration of miners based on the grid buses as indicated in Figure 10. This work results in energy management improvement of mining devices in the blockchain system. relevant consequences are depicted in Figures 9 and 10. It can be inferred from results t the smart grid for handling the consumed energy arising from the security support syst needs to be optimally assigned the 18 DGRs, made up of three PV units, nine WT units a six tidal turbine units located on buses in compatible with Figure 9. On the one hand, blockchain tech is obligated to make an appropriate reconfiguration of miners based on grid buses as indicated in Figure 10. This work results in energy management improvem of mining devices in the blockchain system.       Another matter that requires more attention is how the different energy supply resources in the modified framework contribute to satisfying the load demands within the smart grid. Figure 11 indicates the participation percentage of energy resources aimed at supplying the type of demands. The previous sections precisely expressed that the smart grid equipped by the blockchain technology commits to supplying both non-miner (local loads) and miner demands optimally, based on the new reconfiguration of miners. On the one hand, the smart grid is made up of a hybrid energy source for guaranteeing continuous and Another matter that requires more attention is how the different energy supply resources in the modified framework contribute to satisfying the load demands within the smart grid. Figure 11 indicates the participation percentage of energy resources aimed at supplying the type of demands. The previous sections precisely expressed that the smart grid equipped by the blockchain technology commits to supplying both non-miner (local loads) and miner demands optimally, based on the new reconfiguration of miners. On the one hand, the smart grid is made up of a hybrid energy source for guaranteeing continuous and stable power for handling miming for blockchain. Hence, the renewable resources are mixed with non-renewable resources in order to provide energy to the system. Having looked at Figure 11, the miner demands makes up 32.55% of the total demand of grid, which needs to be supported. In the light of the evidence, the new reconfiguration gives DGRs the chance of participating in 78.71% of the miner energy supply. On the other hand, the miner demands (32.55%) merely involve the 21.29% generation capacity of the fossil fuel units, which evidently means the optimal reduction in energy cost. Results Figure 11. The participation percentage of energy supply resources. Figure 11. The participation percentage of energy supply resources.
Apart from these outcomes, providing the comparative results assist in ensuring the usefulness of the proposed reconfiguration of miners. To this end, we implement two strategies with the same hash rate: strategy (1), the modified framework; and strategy (2), the basic structure. The relative results are shown in Figure 12 and Table 1. In light of this evidence, assigning the optimal location of mining devices causes the operation cost the smart grid to remarkably decline from 6.92 × 10 9 (¢) to 4.69850 × 10 9 (¢). These results are realized for to the sake of decreasing the consumed energy cost of blockchain system. On the other hand, the data security of grid is safeguarded, the miner could earn a revenue of almost 40,000 ¢ in the modified framework. Such an energy framework results in total cost reduction in comparison with the strategy 2, which reflects the new framework' effectiveness for miners in blockchain technology.  Figure 11. The participation percentage of energy supply resources.

Checking the Effect of Uncertainty on the Energy Cost of Miners
This section intends to highlight whether the presence of uncertainty can alter the cost-effective based energy operation of mining devices or not. To prove the truth of the matter, we fulfill correlation modeling among the uncertain parameters by using the unscented transform concept on the proposed studied case and underline the consequences related to the miners and DGRs. Figures 13 and 14 are the comparative results of the benefit/cost associated with the miner and DGRs under uncertainty/normal states. As explicated before, the high accuracy of uncertainty-based energy management in blockchain technology guarantees the chance of having optimal energy cost scheduling for the mining devices within the smart grid. Inspecting the results in Figure 13, it is deducted that remarkable fluctuations relative to the benefit of miners can be mostly observed under a stochastic state with values 5.47% in comparison with the normal one. This discussion is also correct for the energy cost of renewable resources in the smart grid, as shown in Figure 14. To conclude, using uncertainty modeling can assist blockchain technology relative to energy management in gaining cost-effective based energy scheduling.

Checking the Effect of Uncertainty on the Energy Cost of Miners
This section intends to highlight whether the presence of uncertainty can alter the cost-effective based energy operation of mining devices or not. To prove the truth of the matter, we fulfill correlation modeling among the uncertain parameters by using the unscented transform concept on the proposed studied case and underline the consequences related to the miners and DGRs. Figures 13 and 14 are the comparative results of the benefit/cost associated with the miner and DGRs under uncertainty/normal states. As explicated before, the high accuracy of uncertainty-based energy management in blockchain technology guarantees the chance of having optimal energy cost scheduling for the mining devices within the smart grid. Inspecting the results in Figure 13, it is deducted that remarkable fluctuations relative to the benefit of miners can be mostly observed under a stochastic state with values 5.47% in comparison with the normal one. This discussion is also correct for the energy cost of renewable resources in the smart grid, as shown in Figure 14. To conclude, using uncertainty modeling can assist blockchain technology relative to energy management in gaining cost-effective based energy scheduling.

Conclusions
This article tried to remove one of the obstacles relative to the optimal operation of blockchain technology in smart grids. Such a challenge has roots in the energy consumption of miners that must be considered in energy management programs. To solve this problem, a novel stochastic framework incorporating the IPS algorithm and UT was proposed in which the placement process simultaneously included both DGRs and miners. The simulation results show that the optimal placement of miner and DGRs would require using a correct method of optimal energy management in the presence of miners. Considering the very large state of the problem, the implementation of the proposed method is not very simple because if the state space does not reduce, then solving the problem will be time consuming and impossible. In order to evaluate the quality of the proposed method, three case studies were designed: 1-assessing the blockchain technology under various hash rates; 2-analyzing the IPS based simultaneous allocation of mining devises and DGRs; and 3-checking the effect of uncertainty on the energy cost of miners. It is observed that if the place of the miner is determined according to the grid configuration, the energy management of miners rapidly converges at the optimal point. Moreover, it is observed that the proper placement provides higher security for the grid at a lower cost. Nevertheless, it is observed that higher security would require higher hash rates, which would result in higher energy management costs. Therefore, the operator needs a suitable tradeoff between the two security levels and operating costs according to preferences and smart grid situation. Finally, the present study can be completed by proposing a suitable method to calculate the required number of miners in the smart city. From the uncertainty point of view, incorporating the uncertainty effects increased the total renewable costs. This is the cost that we pay to have a more realistic and reliable study.

Conclusions
This article tried to remove one of the obstacles relative to the optimal operation of blockchain technology in smart grids. Such a challenge has roots in the energy consumption of miners that must be considered in energy management programs. To solve this problem, a novel stochastic framework incorporating the IPS algorithm and UT was proposed in which the placement process simultaneously included both DGRs and miners. The simulation results show that the optimal placement of miner and DGRs would require using a correct method of optimal energy management in the presence of miners. Considering the very large state of the problem, the implementation of the proposed method is not very simple because if the state space does not reduce, then solving the problem will be time consuming and impossible. In order to evaluate the quality of the proposed method, three case studies were designed: 1-assessing the blockchain technology under various hash rates; 2-analyzing the IPS based simultaneous allocation of mining devises and DGRs; and 3-checking the effect of uncertainty on the energy cost of miners. It is observed that if the place of the miner is determined according to the grid configuration, the energy management of miners rapidly converges at the optimal point. Moreover, it is observed that the proper placement provides higher security for the grid at a lower cost. Nevertheless, it is observed that higher security would require higher hash rates, which would result in higher energy management costs. Therefore, the operator needs a suitable tradeoff between the two security levels and operating costs according to preferences and smart grid situation. Finally, the present study can be completed by proposing a suitable method to calculate the required number of miners in the smart city. From the uncertainty point of view, incorporating the uncertainty effects increased the total renewable costs. This is the cost that we pay to have a more realistic and reliable study.   Power output of the storage, WT, tidal and PV, respectively Q t,u , Ql e,t The generation reactive power of the generators and the line reactive power flow F best_sort Sorted matrix of the best values of the objective function F1 r Objective function of the elements of matrix ψ r F1 Best Best solution of the matrix F1 r H w i Matrix of k n I ch t ,I dch t Binary variables of charging and discharging modes of EH energy storage K Matrix of control variables P t,u , Pl e,t The generation active power of the generators and the line active power flow P ch t , P dis t Ch/Dis powers of storage z t,u Binary variables of the generator V b , η b Voltage and angle of the bus V B t Energy of the storage system min G grid Costs of the smart grid