A power trading mode based on blockchain for prosumers

. With the increase of the penetration rate of distributed generation on the distribution network side, the access of a large number of prosumers makes the trading information massive, and the demand of prosumers for more flexible power trading mechanism is also strengthened. Therefore, a weak-centralized power trading mode based on blockchain is proposed in this paper. Trading information is automatically stored in the blockchain in the form of smart contracts. The centralized organization only manages congestion and does not participate in the process of trading matching and settlement. In the distributed security verification, the successive over relaxation (SOR) iterative method is improved in this paper, which improves the iterative efficiency and convergence stability of the distributed algorithm. Finally, a case consisting of six nodes is presented to verify the feasibility of the method.


Introduction
In recent years, with the development of distributed generation technology, users gradually change from oneway consumers to prosumers. The emergence of a large number of prosumers will produce new business opportunities [1] . The increase of the number of market participants makes the trading information massive. However, the traditional centralized power trading mode has some problems, such as high operating cost, difficult to guarantee the fairness and transparency of the transaction. It is urgent to seek a safe, efficient and fair power trading mode.
Therefore, this paper proposes to use blockchain technology to manage the power trading between prosumers. As a distributed accounting system with asymmetric encryption, blockchain has the characteristics of decentralization, unforgeability and anonymity, which can well adapt to the decentralized system structure of distribution network side, and is in line with the demands of power trading between prosumers [2] . The introduction of blockchain technology into the electricity trading of prosumers can achieve the transaction in a decentralized way, and ensure the efficient and reliable power trading between prosumers.
However, for the present stage, it is difficult to realize the fully decentralized multilateral electricity trading, because the power trading is different from the ordinary commodity trading, and the network constraints should also be considered. In the fully decentralized environment, it is still difficult for each node to reduce and adjust the trading volume spontaneously and eliminate the line congestion. Therefore, this paper proposes a weaklycentralized electricity trading mode for prosumers. In this mode, the centralized organization still exists, but only manages congestion, and does not directly participate in the matching and settlement process of electricity retail trading between prosumers, which limits the power of the central organization, and also satisfies the safe and reliable operation of the distribution network.

Distributed trading and blockchain technology
Blockchain is a chained data structure that connects the blocks of stored data in chronological order. It is a decentralized database and can be regarded as a distributed ledger [3][4] . The simplified structure of block chaining is shown in . It links the blocks with certain associations in the time sequence generated by blocks. Each block is composed of a block header and a block body. The block header contains the version number, the hash value of the previous block, Merkle root and time stamp. The block body is equivalent to a database, which records the specific trading information. It takes Merkle function as the root and stores each trading information in the form of an inverted tree. The features of blockchain, such as high security and decentralization, are just in line with the demands of distributed power trading. The specific analysis are as follows: (1) The decentralized characteristics of blockchain makes trading between prosumers without the assistance of a third-party central organization, and the trading cost between prosumers decreases with the reduction of trust cost.
(2) The tamper resistant characteristics of blockchain ensures the information security of distributed trading, and maintains the fairness of distributed trading.
(3) Due to the data traceability characteristics of blockchain, users can know the types of electric energy purchased by each transaction, such as traditional energy, wind energy, photovoltaic power generation, etc., which enriches the selection of energy purchase types for users.

Overall structure
The specific process of weakly-centralized distributed trading based on blockchain is shown in (1) When the deviation occurs in the real-time phase, the user reports the trading price and the deviation quantity, and requests to eliminate the deviation.
(2) The blockchain platform collects trading requests reported by all users and matches trading orders to form temporary trading orders.
(3) Each user conducts distributed security verification according to temporary trading orders. If there is no power flow overrun, the temporary order will be regarded as the final trading result, and the trading data will be recorded in the blockchain. Otherwise, the central organization will manage the congestion and record the adjusted trading result in the blockchain.
(4) In the whole trading process, the energy data of each prosumer will be recorded by smart meters. In the trading settlement stage, the smart contract will confirm the actual output or power consumption of users, so as to evaluate the transaction reputation value of each user, and impose a certain liquidated damage on the default user.
The details of bidding strategy, trade matching mechanism, distributed security verification, congestion management, evaluation of transaction reputation value, etc. are described in detail below.

Bidding strategy and matching mechanism of prosumers
First of all, the following market parameters are set: is the unit price of electricity sold to the grid by prosumers, that is, the grid connected price; buy.w p is the price for market participants to purchase electricity directly from the grid; The smooth operation of the distributed power trading market should meet the basic premise that the income obtained by the users participating in the distributed power trading should not be less than the income obtained by trading directly with the power grid. Therefore, the quote range of prosumers should be expressed as

Security verification
In the distributed security verification method, reference [5] calculates the phase angle of each node iteratively, so as to find out the power flow of all lines. In reference [6], a distributed power flow calculation method based on successive over relaxation iteration (SOR) is proposed. Compared with the traditional distributed iteration method, the algorithm has faster convergence speed and stronger convergence stability. In this paper, based on the SOR iterative method, an improved SOR iterative algorithm is proposed, which makes the convergence speed faster and the convergence stability further enhanced. The specific calculation steps of the improved SOR iterative algorithm are as follows: Firstly, let's select a reference node in the network, set its phase angle 0 =0  , and set the initial phase angle of other nodes as 0. Secondly, calculate the injection power t inj  P of each node to the network. When t inj. >0 i P  , it means that node i sells electric energy to the other nodes, otherwise it means that node i purchases electric energy from the other nodes. In the iteration process, each node broadcasts the results of each phase angle iteration to the network for the other nodes connected with itself. The iterative formula is shown in formula (3): is the phase angle value of node i in the k-th iteration; i  is the set of all nodes connected , which is the reciprocal of impedance between node i and j ; The convergence condition is shown in formula (4): Where  is a positive number as small as possible.
The power flow distribution of each branch can be calculated from the final phase angle of each node. The power flow calculation formula of branch from node i to node j is shown in formula (5):

Congestion management
In the aspect of congestion management, the trading weight factor is introduced in this paper, so that the trading volume can be reduced while the user's willingness to trade can be fully considered, so as to make targeted reduction. The calculation of the trading weight factor is shown in formula (6) where ij x is the reactance from node i to node j , and A is the reduced order node incidence matrix of the corresponding row with the slack nodes removed; temp T is the temporary trading matrix formed by temporary trading orders, the element ij t in the matrix represents the electric energy provided by the prosumer i to j : The constraint condition is shown in formula (10)

Evaluation of transaction reputation value and settlement
In the distributed power trading, users may not generate and use electricity according to the contract. Therefore, it is necessary to punish the defaulting users, deduct the transaction reputation value and charge the liquidated damages.

Calculation of reputation value
When the actual power generation or consumption deviation is within a certain range, the transaction reputation value of the user will not be deducted; otherwise, the transaction reputation value will be deducted. The reputation value is shown in formula (11):

Liquidated damages
If the reputation value of the user is deducted, a certain liquidated damage will be added on the basis of the trading price.
For the buyer, the liquidated damage is: For the seller, the liquidated damage is: pc Δt The final settlement price of user i is the sum of trading price and the liquidated damage, that is: According to the final settlement price formula, only when the reputation value is not deducted in the current trading cycle, the final settlement price of the user ( Δt is equal to the trading price ( t ij G  ). Otherwise, the users whose reputation value is deducted will bear some losses, and the matching priority in the next trading cycle will be reduced [7] . Therefore, the introduction of reputation value can supervise the user to complete the trading contract in strict accordance with the contract content, which can play a certain role in restraining the user's illegal behavior.

Example setting
In order to verify the economic benefits of distributed trading between prosumers, the 6-node system shown in Fig4 is used to simulate the trading.

Fig4. Six node distribution network diagram
In the network, A-G are the prosumers with distributed generation equipment, and W is the distribution network operator, which can balance the fluctuating power of the distribution network. Because it is connected to the power grid, it can be equivalent to a generator with infinite capacity. The grid-connected price of distributed generation equipment is 0.4 yuan/kWh ( sell.w =0.4 p yuan/kWh), and the unit price of electricity purchased directly from the seller is 1.2 yuan/kWh ( buy.w =1.2 p yuan/kWh). Assume that the distributed power trading is a seller's market, that is, the total amount of electricity sold by the prosumers is less than the amount of electricity purchased. If the price interval parameter =21 n , the trading information reported by each prosumer according to the bidding strategy in section 4 at time t is shown in Table 1

Trade matching
According to the trading reporting information of prosumers, 6 temporary trading orders are successfully matched according to the priority of "trading price, reputation value and reporting time [8] ". Electricity quantity that failed to match was deemed to have been purchased from or sold to the distribution network operator W. The trade matching results are shown in Table  2, where temp.ij t represents the amount of electricity temporarily traded between user i and j ; Δt ij G represents the trading price of temporary order formed by user i and j .

Comparison of security verification algorithms
The improved SOR iterative algorithm described in section 5 is used to calculate the distributed power flow of the temporary trading orders, and the power of each branch is shown in Table 3. From the security verification results, the actual power of branch 2-5 exceeds the transmission capacity margin, and congestion management is needed to eliminate power flow overrun.
The performance comparison of the three distributed algorithms is shown in Table 4, where TDA represents traditional distributed algorithm. The phase angle convergence process of node 5 in the three iterative algorithms is shown in Fig 5   Fig5. Phase angle convergence process of node 5 From the above performance comparison, the improved SOR iterative algorithm proposed in this paper has higher convergence speed than the distributed iterative algorithm in reference [5] and reference [6], and has stronger convergence stability.

Congestion management
The trading contract formed by the central organization after congestion management in combination with formula (9) and formula (10) is shown in Fig 6. In Fig 6, the second column of each transaction is the optimization result without considering the user's trading willingness (i.e., the weight factor =1 ij  for all trade), and the third column is the optimization result after considering the trading weight factor of formula (6).

Fig6. Congestion management optimization results
The trading reduction of each prosumer after congestion management is shown in

Fig7. Trading reduction of prosumers
Comparing two kinds of congestion management results, we can see that when the trading weight factor is not considered, the congestion management is to reduce the trading according to the minimum square sum of the adjustment volume, and treat all temporary transaction orders equally. When considering the trading weight factor, because A, G, F and some other users choose the bidding strategy with higher trading willingness degree, the trading volume is reduced relatively less in the congestion management. On the contrary, because the buyer E chooses the bidding strategy with lower trading willingness degree, it is located at the end of the matching queue, and its trading reduction is relatively increased during congestion management. Therefore, the introduction of trading weight factor can reflect the trading intention of users to a certain extent, enhance the enthusiasm of prosumers to participate in distributed trading, and make users with stronger trading intention can purchase or sell more electric energy.

Recording and settlement of transactions
When the final trading contract is reached, all prosumers and the distribution network operator who participate in the transaction will use the private key to authenticate the trading contract, and then broadcast the contract to other nodes in the network for consensus authentication. The trading information is packed into a set in the form of Merkle tree as shown in Fig 8. The hash value of each trading data is calculated in turn, and recursion is continued until the root node data value is obtained. The blockchain only needs to save the data of the root node, so that the recorded trading information has good tamper resistance. If a malicious node attempts to tamper with the trading information, such as tampering the trading contract between user W and user E into the trading between user A and user E (as shown in Fig 8), the data value of the root node of the Merkle tree will also change, indicating that the trading information has been tampered with. At the same time, we can find the location of the tampered trading information by comparing the root node value of each subtree step by step from the root node. When the trading settlement phase is reached, the smart contract will automatically read the energy data collected by smart meters, and clear the actual power delivery of each prosumer. According to formula (11-13), the smart contract will change the reputation value of the defaulting users and punish them with liquidated damages, and conduct trading settlement for all users according to formula (14). In this example, it is assumed that the actual power generation capacity of seller B is 12.06kWh due to the fault of its own distributed generation equipment. The reputation value change and trading settlement of each prosumer are shown in Table 5

Benefits analysis of prosumers
Compared with the direct grid connection, the relative return rate of each prosumer participating in the distributed trading is shown in Fig 9. (1) Users B and D choose the same electricity selling price, while the relative return rate of user B is lower than that of user D. The main reasons are as follows: firstly, the trading reporting time of user D is shorter, so it is in front of user B in the trading matching queue, and can match with the buyer user with higher quotation; secondly, user B has certain liquidated damages due to equipment failure, so its return rate is relatively lower.
(2) User A chooses the lowest electricity selling price among all the seller users, but its relative return rate is very high. The main reasons are as follows: although user A chooses the lowest electricity selling price, according to the matching principle of "trading price priority", it will be at the top of the matching queue, so as to match with the user with the highest electricity purchase price, and obtain a trading price not too low. At the same time, a lower electricity selling willingness price has a higher trading willingness degree. When the central organization carries out congestion management by reducing the trading volume, the trading order of user A has a higher trading weight, which makes the reduction less, thus indirectly improving the electricity sales income of user A.
From the above analysis, we can see that under the distributed trading mechanism of two-way competition, the low willingness price does not mean the low final settlement price and the relative return rate of users, but also is related to the willingness price of the trading matching object, the reputation value of the prosumer and the trading weight factor. This requires that prosumers should enhance their enthusiasm to participate in distributed trading, and at the same time, they should maintain good electricity generation and consumption behavior, avoid the occurrence of liquidated damages, and strive for maximum revenue.

Conclusion
In this paper, a weakly-centralized electricity trading mode is proposed. In this mode, the central organization only manages the trading orders that fail to pass the security verification, and does not directly participate in the matching and settlement of electricity trading orders, which improves the transparency and fairness of the trading. In the part of security verification, the traditional SOR iterative method is improved to make the convergence rate of distributed algorithm faster. Finally, an example is given to analyze the return rate of multilateral electricity trading compared with direct grid connection, and the feasibility and economy of this power trading mode are verified. This paper focuses on the power trading mode of prosumers based on blockchain, including the bidding strategy, security verification, congestion management model and so on. However, some specific details of the trading mode have not been studied, such as the preparation of smart contract, the construction of power trading platform based on blockchain, the data maintenance mechanism of energy blockchain, etc., which should be further studied in the future.