Abstract
To address the data security and user privacy issues in the task offloading process and resource allocation of the fog computing network, a blockchainenabled fog computing network task offloading model is proposed in this paper. Furthermore, to reduce the network utility which is defined as the total energy consumption of the fog computing network and the total delay of the blockchain network, a blockchainenabled fog computing network task offloading and resource allocation algorithm (TRBFCN) is proposed to jointly optimize the task offloading decision and resource allocation. Finally, the original nonconvex optimization problem is converted into two suboptimization problems, namely, task offloading decisions and computational resource allocations. Moreover, a twostage Stackelberg game model is designed to obtain the optimal amount of purchased resource and the optimal resource pricing. Simulation results show that the proposed TRBFCN algorithm can effectively reduce the network utility compared with other algorithms.
1. Introduction
With the rapid growth of smart devices and the development of the Internet of Things (IoT), the traditional network architecture is facing a huge flow load problem [1]. As a supplement to cloud computing, fog computing could randomly deploy a large number of fog nodes (FNs) at the edge of the network to deal with the realtime application requirements generated by devices and improve network performance [2]. In the distributed fog network, IoT devices (IDs) interact with FNs in real time. Due to the mobility of IDs, service migration across FNs will occur during the interaction [3]. Meanwhile, because FNs are distributed in an unsupervised environment, the security of the user’s data during the task processing is an important challenge for fog computing networks (FCNs) [4]. Currently, to ensure the user privacy and data security in fog computing networks, the following two methods are taken into account: (i)Method 1: develop a reliable, effective mechanism to evaluate the reputation of IDs and FNs. Reputation of IDs and FNs is used to indicate their credibility [5]. If the user privacy is leaked or data tampering occurs, the reputation of the associated nodes will be decreased. Reference [6] proposed a contextaware trust evaluation algorithm to calculate the trustworthiness of users in FCNs. Reference [7] proposed a trust forwarding mechanism in FCNs, which divided the network into edge communication communities, and set the reputation of nodes in the community based on actual factors such as the communication probability and service degree. Reference [8] considered the reputation of vehicles in distributed Internet of Vehicles. The authors mainly considered familiarity, similarity, and timeliness to calculate the local reputation of vehicles. Finally, the local reputation and the historical reputation were combined to calculate the globe reputation of vehicles. Reference [9] proposed a resource allocation scheme for communitybased fog computing based on reputation mechanism. A user first submits his/her task request to the communitybased fog network, and then, the fog server makes a reliable resource allocation process based on multiplelayer communities and reputation calculation. Reference [10] proposed innovative approach that estimates the initial reputation values of newcomer services in web service recommendation systems through the use of the fog node’s (service provider) reputation and ANN model. The quality of services and reputation of previously published services are used to estimate the reputation values of newcomer services(ii)Method 2: combine blockchain technology to achieve reliable data transmission [11]. Blockchain has unique features such as fault tolerance, security, and immutability, as well as the potential to provide decentralized databases and network operations [12]. Blockchain technology is used to realize the verification and traceability by building a decentralized ledger to record transactions between users [13]. Different from traditional digital ledgers, blockchain does not rely on a central authority [14]. In addition, the consistency of the ledgers between nodes is ensured by the consensus mechanism. Reference [15] proposed a user privacy protection scheme based on blockchain and federated learning (BlockchainEnabled Federated Learning (FLBlock)), which proposed an autonomous learning process without any central trust agency to maintain the global model, and complete data processing and transmission through the blockchain ProofofWork mechanism and consensus mechanism [16]. In addition, the authors jointly considered the communication delay, consensus delay, and computation cost to optimize the block generation rate. Reference [17] studied the data security and user privacy issues in the vehicle fog networks. A lightweight anonymous authentication mechanism assisted by blockchain was proposed to realize the flexibility and anonymity of crosscenter authentication, reduce the communication delay of data authentication, and build a lightweight network authentication mechanism. Reference [18] proposed a data sharing model based on blockchain. The data owner processes the original data generation according to the algorithm provided by the data requester. The data report is returned to the demander, and the data sharing platform supervises all the behaviors of the sharing parties and writes the entire sharing process into the blockchain, which not only satisfies the demander’s use of data but also avoids the risk of data leakage by the data holder
However, due to the limited computing capability of FNs, when FNs process task offloading and blockchain verification at the same time, there could be a shortage of resources, resulting in the task offloading time increasing or the block generation and verification delay increasing, which affects the transaction’s recording time in the blockchain [19]. In order to optimize the allocation of computing capability and ensure the security of the network, we propose a task offloading and resource allocation algorithm in blockchainenabled fog computing network (TRBFCN) in this paper. The TRBFCN algorithm is aimed at minimizing network utility, i.e., the total energy consumption of the FCN and the total delay of the blockchain network, by jointly optimizing the task offloading decision and resource allocation between two networks.
2. Network Modeling and Analysis
2.1. Network Model
A blockchainbased fog computing network (FCN) is shown in Figure 1, which includes the device layer and the fog layer. The fog layer consists of geodistributed fog nodes (FNs) to provide computing, storage, and communication resources to nearby IoT devices (IDs). Besides, blockchain is deployed in the fog layer to verify and record transactions. The task offloading process is composed of three parts: master node election, resource pricing and offloading decisionmaking, and blockchain consensus process. The Authorized Service Center (ASC) is a trusted edge server, which is responsible for monitoring the FNs in the coverage area and the authentication process of network entities. The ASC will generate a unique publicprivate key pair and identification code for each entity, as well as the entity’s cancellation and other functions.
Firstly, IDs should finish the registration and authentication through the ASC, then they could offload tasks to associated FNs for processing. FNs with higher reputation value will be elected as blockchain nodes, which will not only provide offloading services but also block consensus services.
Secondly, IDs purchase computing resources from FNs to transfer the offloading tasks. Then, the task offloading decisions and resource allocation will be performed to minimize the network utility.
Finally, the task offloading process in the FCN is regarded as a transaction record. The elected blockchain nodes will package transactions to generate blocks and perform a block consensus verification process. The verified blocks will be added to the blockchain network, to guarantee the network security and transactions traceability. The blockchain technology is used to preserve transactions among distributed nodes, which requires additional storage capacity on devices. Moreover, the consensus algorithms used to ensure the data security of devices also require additional computing and communication resources.
2.2. Communication Model
Let denotes the task offloading request sent by ID , where (bit) is the size of the task and (cycle/bit) is the task calculation frequency, i.e., the task processing intensity. The total system bandwidth is divided into resource blocks (RB) with equal bandwidth, namely, . To avoid interference between IDs during task offloading, each RB could be only assigned to one ID and one FN. The uplink transmission rate of ID offloading task to FN on RB is given as where denotes the transmission power from ID to FN through RB ; represents the channel gain value, including largescale fading and smallscale fading , where represents the average channel gain at 1 km; is the logarithmic shadow fading variable with mean 0 and standard deviation ; denotes the distance from ID to FN ; and is the path loss index. is the independent and identically distributed complex Gaussian random variables with zero mean unit variance. represents additive white Gaussian noise.
Therefore, the offloading delay from ID to FN by RB is given as where is the allocation index between ID and FN . And indicates that ID will offload tasks to FN , while represents that ID will not offload tasks to FN ; is the allocation index between RB and FN . indicates that ID will offload tasks to FN on RB , and represents that ID will not offload tasks to FN on RB . Moreover, ID could offload tasks to multiple FNs, and indicates the task offloading proportional coefficient from ID to FN .
Thus, the total transmission energy consumption of the fog computing network can be expressed as
2.3. Calculation Model
For the computation phase, we mainly consider the task computation delay and the computation energy consumption of FN .
The task computation delay of FN is given by where denotes the number of CPU cycles required to process the unit data size and (cycle/s) represents the computation resources provided by FN for the task offloaded from ID .
Thus, the computation energy consumption of FN is given as where is the energy consumption coefficient of FN .
Therefore, the computation energy consumption of the FCN could be calculated by
In summary, the total energy consumption of the FCN includes the transmission energy consumption and the computation energy consumption, which can be expressed as
2.4. Blockchain Network Consensus Model
Based on blockchain technology, the FCN could effectively prevent malicious FNs from tampering or copying user data and improve the reliability of data transmission. In the blockchain network, transaction records will be processed in the following two steps: (1)Block generation, where the transaction records are packaged to generate blocks through the master node(2)Block consensus, where the master node will broadcast the new block to verification nodes to form a unified ledger information; then, all verification nodes compare the hash value and return the verification results to the master node through their private key signatures
If the verification is passed, the master node will add the new block to the blockchain.
Assume there are L blockchain nodes, the master node could process transaction records, and the block generation delay is given as where , , and denote the computation frequency, the task processing intensity, and the processing data size of the master node , respectively. Assume that all verification nodes are honest and reliable; the consensus process is divided into two steps: block propagation and block verification. In the block propagation phase, the propagation rate from the master node to the verification node is
Correspondingly, the block transmission delay , where represents the block size.
In the block verification phase, the verification node will confirm the content of the block broadcasted by the master node, with the verification delay where is the number of CPU cycles required for block verification and represents the computation frequency to verify the block.
Therefore, the total delay of the blockchain network is expressed as where represents the master node indication parameter. If , FN will be elected as the master node.
3. Optimization Problem Modeling
To minimize the network utility, namely, the sum of the total energy consumption of the FCN and the total delay of the blockchain network, the optimization problem could be represented as where α is the proportion of the total energy consumption of the FCN in the optimization goal; indicates that an ID can select multiple FNs to offload tasks; indicates that an RB can only be allocated to one FN, but each FN can be allocated multiple RBs; indicates that the computation resources allocated by the FCN cannot exceed the purchased computation resources; indicates the computation resources constraint; indicates that the total delay of the FCN cannot exceed the maximum tolerable delay of the task; is the task size constraint; and is the blockchain master node constraint, which ensures that there is only one master node in each processing cycle.
4. Task Offloading and Resource Allocation Scheme in BlockchainEnabled Fog Computing Network
To optimize the computation resource allocation of the FCN and the blockchain network, in this paper, we propose the task offloading and resource allocation algorithm in blockchainenabled fog computing network (TRBFCN), which includes the Differentiated Resource Pricing Algorithm (DRPA), task offloading decision algorithm, and computation resource allocation algorithm.
4.1. Computing Resource Allocation Algorithm Based on Differentiated Pricing
Firstly, a twostage Stackelberg game is considered to optimize the amount of resources to purchase and the associated price. In the Stackelberg game, the cost of ID to purchase computation resource from FN is expressed as where denotes the price for ID to purchase the computation resources from FN , and represents the amount of computation resources purchased by ID from FN .
The revenue function of ID to offload tasks to FN is defined as where is the benefit factor of ID and denotes the number of CPU cycles required to process the unit data size. The offloading revenue of IDs is related to the amount of offloading tasks . To maximize the benefits of ID , the optimization problem is modeled as where and denote the minimum and the maximum amount of computation resources that could be purchased by ID from FN , respectively.
The computation energy cost of offloading tasks from ID to FN is defined as where is the energy consumption coefficient of FN.
Therefore, the utility function of FN is defined as where is the price of computation resources provided by FN for ID .
To maximize the utility of FN , the price to purchase computation resources should be optimized. The dynamic price optimization problem is modeled as where indicates that the price is not lower than the cost of FN . To ensure that the revenue of FN is nonnegative, let , and we have .
Sinceis a convex function of, the constraint is a linear function. The optimization problem is convex, which can be solved by the Lagrange multiplier method. The Lagrange function is defined as where and are the Lagrange multipliers.
The KKT (KarushKuhnTucker) condition is used to find the partial derivative of the Lagrange function with respect to the variable . The optimal solution can be obtained by where . The Lagrange multipliers and are updated by the following equations: where is the number of iterations and and are the step sizes.
Substituting into (18) to find the second derivative, we can obtain where ; i.e., the revenue function of FN is a convex function with respect to the variable , and its constraints are all linear functions. Therefore, the dynamic price optimization problem can be solved by the Lagrange multiplier method, and the Lagrange function is where is the Lagrange multiplier.
Similarly, the KKT condition could be used to find the partial derivative of its Lagrange function with respect to the variable ; the optimal solution is given by
The Lagrange multiplier is updated by where is the number of iterations and is the step size.
To prove that the optimal solution (, ) is the Nash equilibrium solution, the following definitions and lemmas are proposed.
Definition 1. When the price of FN is fixed, the following condition is satisfied:
Meanwhile, when the computing resources purchased by ID from FN are fixed, the following condition is satisfied:
Then, (, ) is the Nash equilibrium solution, which will be proven by the following three lemmas.
Lemma 2. When the quotation of FN is fixed, the revenue function of ID is maximized at .
Proof. Since the secondorder partial derivative of is less than 0, is a convex function of variable . Therefore, achieves the maximum at . According to Definition 1, is the Nash equilibrium solution.☐
Lemma 3. The optimal computing resource purchased by ID from FN decreases as the price increases.
Proof. Based on the firstorder partial derivative of the optimal solution , we could obtain From (29), we know that is a monotonically decreasing function of variable . When the quotation of FN is too high, less IDs will purchase resources, resulting in decreasing of the revenue of FN . Therefore, the optimal price of FNs could be obtained by setting the first partial derivative of to 0 [20].☐
Lemma 4. When the optimal computing resource purchased by ID from FNs is fixed, the revenue function of FN achieves the maximum at .
Proof. Since the secondorder partial derivative of with respect to variable is less than or equal to 0, is a convex function with respect to variable . Therefore, achieves the maximum at . According to Definition 1, is the Nash equilibrium solution.☐
Therefore, the optimal solution (, ) is the Nash equilibrium solution of the Stackelberg game. The dynamic resource pricing algorithm (DRPA) is shown in Algorithm 1.

4.2. Task Offloading and Transmission Resource Allocation Algorithm
To further minimize the utility of the FCN, the task offloading decisions and transmission resource allocation algorithm is proposed. Since the optimization problem is nonconvex, we decompose it into two subproblems and solve them individually to minimize the total energy consumption of the FCN.
Firstly, the original optimization problem could be transformed to
Based on the optimal task offloading algorithm proposed in [21], the task offloading decisions and transmission resource allocation results in this scenario can be obtained.
4.3. Computing Resource Allocation Algorithm
The task offloading decisions and transmission resource allocation could be obtained through the above algorithm. In addition, the alternate direction method is used to optimize the computation resource allocation in the FCN and blockchain network.
First of all, with the fixed computation resource of the blockchain network, we could solve the computation resource allocation problem in the FCN. Due to the coupling relationship between variables in the optimization problem, we assume that when ID offloads tasks to multiple FNs simultaneously, the offloading proportional from ID to FN is dependent on the amount of computation resources purchased from FN , which is expressed as
Based on the Lagrange multiplier method, the optimal solution can be obtained. The constraint is rewritten as
Then, the Lagrange function is given by where , , and are the Lagrange multipliers. Thus, the optimal solution of the optimization problem can be obtained:
The Lagrange multiplier update are updated by where is the step size.
Secondly, with the obtained computation resource of the FCN, the blockchain node selection and computation resource allocation problem could be expressed as
Based on the reputation model proposed in [22], an odd number of nodes with high reputation will be selected as blockchain nodes to participate in the blockchain consensus process. Therefore, the computing resource allocation problem in the blockchain network is transformed into
The optimization problem is a linearly decreasing function; when takes the maximum value, the objective function obtains the minimum value, and we have
Finally, based on the alternating direction method, and could reach the convergence, and the associated network utility could be obtained. The computation resource allocation algorithm is summarized in Algorithm 2.
The computational complexity for one round of pricing for FNs of DRPA is . Thus, the total computational complexity of DRPA is , where denotes the number of IDs. Considering that the loop number of DRPA is , thus, the total computational complexity of DRPA is .
5. Simulation Results and Analysis
To verify the effectiveness of task offloading and resource allocation algorithm in the blockchainenabled fog network (TRBFCN), the following two algorithms are used for comparison.
Random resource allocation algorithm (RAA). This algorithm uses different resource pricing to ensure the network revenue of IDs and FNs and uses random offloading decisions and transmission resource allocation.
Unified price algorithm (UPA) [23]. This algorithm adopts a unified resource pricing, i.e., each ID purchases the same computing resource from different FNs, and adopts the optimal offloading decision and transmission resource allocation.
Figures 2 and 3 show the computation resources purchased by different IDs and the associated prices with , , and . For ID 1, the task processing intensity is 200 cycles/bit; for ID 2, it is 300 cycles/bit; and for ID 3, it is 400 cycles/bit. As shown in the figure, with the number of tasks increasing, the computation resources purchased by IDs increase, and the amount of computation resources purchased by different IDs from different FNs is also different. ID 1 has a lower task processing intensity and purchases fewer computation resources with a higher price, whereas ID 3 has a higher task processing intensity and purchases more computation resources with a lower price.
Figures 4 and 5, respectively, show the convergence of the purchased computation resources and the associated prices. The DRPA algorithm converges when the number of iterations reaches 10. It can be seen that FN 1 has the smallest energy consumption factor and the lowest cost, and FN 5 has the largest energy consumption factor and the highest cost. As increases, the computing resources that can be purchased decrease, and resource quotations continue to increase correspondingly.
Figure 6 shows the network utility versus the number of FNs. It can be seen that the network utility is a decrease function of the number of FNs, which converges when the number of iterations is greater than 12. With the increase of the number of FNs, IDs could purchase computation resources from more available FNs; thus, the total network delay and the network utility could be reduced. Moreover, as the number of FNs increases, more FNs can be selected as blockchain nodes, and the network utility will be further minimized.
Figure 7 shows the network utility versus the number of IDs. The task transmission delay and computation delay increase when the number of offloading tasks increases, resulting in the increase of the network utility. Compared with other algorithms, the proposed TRBFCN algorithm has the lowest network utility. For algorithm RAA, ID may offload tasks to FNs with poor channel conditions, resulting in high transmission delay and high network utility. The simulation results show that the proposed DRPA algorithm could make each FN provide different computation resources for each ID according to the task processing intensity, which can effectively reduce the network utility.
Figure 8 shows the relationship between the network utility and the task processing intensity with three algorithms. The increase in task processing intensity leads to the increase in network calculation delay; thus, the total energy consumption of the network also increases. The ID in the algorithm RAA may offload tasks to the FN with poor channel conditions, which could increase the transmission delay. In the UPA algorithm, each ID purchases the same amount of computing resources from each FN. For FNs with rich computing resources or higher processing costs, the ID has not obtained the optimal amount of computing resources to maximize its own revenue, resulting in higher network utility.
Figure 9 shows the relationship between network utility and the number of FNs with different algorithms. With the number of FNs increasing, the available computing resources also increase. Therefore, the available FNs for each ID to offload tasks are increasing, and IDs could select the FN with better processing capability for task offloading, resulting in the decrease of the total network delay and the total energy consumption, as well as the network utility.
6. Conclusions
In this paper, we proposed a task offloading and resource allocation scheme in the blockchainenabled FCN to minimize the network utility by optimizing the resource pricing, task offloading decisions, and resource allocation. The FCN was responsible for the task offloading and the blockchain network was responsible for the security in the data communication process. Firstly, we proposed a task offloading model in the blockchainenabled FCN; secondly, based on the twostage Stackelberg model, a dynamic resource pricing algorithm was proposed to ensure the fairness of transactions. Finally, we verified the feasibility and effectiveness of the proposed algorithm by simulation results.
Data Availability
In this paper, we did not use a specific dataset.
Conflicts of Interest
The authors declare that they have no conflicts of interest.