An Efficient Algorithm for Peer-to-Peer Energy Trading Using Blockchain in Microgrid Energy Markets

—Electricity generation from distributed renewable energy sources is strongly increasing worldwide. Due to their intermittency in nature, the large scale integration of these renewable energy sources creates acute challenges to the existing energy system network. Thus, it is highly demanding to secure a reliable balance between energy generation and consumption. To overcome such challenges, peer-to-peer energy trading using blockchains on microgrid networks can play a significant role. In this paper, we present the concept of an efficient algorithm that can be useful for energy trading using blockchain from both the prosumers and consumers end. We also show the detailed outline of the methodology for energy transactions in a comprehensive way. The outcome of this study prove that if implemented properly this methodology can efficiently balance supply and demand locally and provide socio-economic benefits to the participants.


I. INTRODUCTION
Historically, electrical power has mainly been produced by large centralized power plants operated by conventional energy sources coming primarily from fossil fuels.This has adverse consequences both on the environment and energy system network.Contrarily, renewable energy such as wind and solar power offers far fewer negative impacts at reasonable prices [1].Recently, the global renewable generation capacity is increasing rapidly.The study carried out by International Renewable Energy Agency (IRENA) shows that, the total installed renewable generation capacity accounted to approximately 2,179 GW with wind and solar energy capacities of 514 GW and 397 GW respectively at the end of 2017 [2].This large scale integration of renewable energy sources (RES) into the existing energy system networks present a solution to the issues related to climate change and global warming.However, unpredictability and instability in renewable generation also required to be taken into account [3].
Prevailing wholesale energy markets deficit the ability to behave in real time to the irregular generation from RES.Additionally, the price of electricity in the market are usually set on a national level which does not indicate local energy shortage or surplus of supply.Because of such issues new market approaches are required that will assist the integration of distributed RES into the low-voltage energy network locally [4].
Microgrids basically represent a geographically limited group of energy producers mainly through renewable energy resources with local demands.It increases the reliability of energy supply as it can be useful for providing energy in case of power outages in the national grid system [5].Microgrid energy markets offer small-scale participants, e.g. consumers as well as prosumers (consumers producing excess energy) to readily exchange energy within their locality in real time [6].Accordingly, these type of local markets accelerate a sustainable, reliable, and local balance of renewable energy mainly solar power generation and consumption in an efficient and economical way.Likewise, this permits small-scale energy consumers and prosumers, motivation for investing in local renewable generation and to establish self-sustainable microgrid communities [6][7].
Blockchain, as a rising information technology, proposes new opportunities for microgrid-based decentralized market designs.It ensures transparent and convenient applications that permits energy consumers to take part in the selection process of their energy producer and also by which technology it is to be generated [8].The implementation of blockchain-based microgrid energy markets have recently earned the consideration of the researchers worldwide [9].Reference [10] presented a proof-of-concept operation of a small blockchainbased machine-to-machine electricity market with two producers and one consumer working in the chemical industry.Their trial validates that blockchain technology can set up very small-scale electricity markets.Reference [11] evaluated the growth of local communities into self-sufficient, local generation utilities namely citizen utilities.This paper explored the opportunity of blockchain-based microgrid energy markets to the advancement of decentralized solar power systems and the associated risks and challenges for the conventional energy grid in Australia.They clearly mentioned that the use of blockchain technology for electricity transactions causes microgrids more resilient by building trust between the participating agents, notably with respect to financial payments and electricity delivery.
Following to an extensive literature review of peer-to-peer energy trading, microgrid energy markets, blockchain technology, and their amalgamation i.e. blockchain-based microgrid energy markets in section II, we suggest an efficient algorithm for the participating agents in these markets e.g.prosumers and consumers in section III.Then, in section IV, we discuss about the future works that are specifically related to blockchain technology.Finally, section V presents the conclusion of our work.

A. Peer-to-Peer Energy Trading
Peer-to-Peer (P2P) trading is the process in which energy prosumers (e.g. consumers with photovoltaic (PV) systems) trade energy in exchange for a certain deposit with the consumer [12].In this process a four-layer architectural business model was proposed that consisted of three dimensions for secured energy exchange.The dimensions included bidding between prosumers and consumers for a certain unit of energy through smart contracts, exchanging the energy and settling payments through block chain technology [13].In this system of transaction, a ledger is posted to the block chain, which is verified by the network and added to the smart contracts block.Whenever the energy demands can be met by any prosumer, energy exchange in lieu of digital money takes placed through a secured medium for renewable energy systems.The peer to peer energy trading system balance the demands and generation rate successfully [13].Piclo, Vandebron, Peer Energy Clouds, Smart Watts, Yaloha and Mosaic, Sonnen Community are some of the successful existing projects that acts on peer to peer trading mechanisms [14].

B. Microgrids and Microgrid Energy Markets
The introduction of distributed generation resources to low voltage networks such as solar photovoltaics, wind turbines, microturbines, tidal turbines, and other power devices is expanding and this type of generation is continually modifying the customary guidelines of the networks [15].A new type of grid capable of operating in both islanded and grid connected mode, with the proper optimization of renewable energy resources that promises emission free green energy is microgrid.Distributed Energy Resources (DERs) based on renewable sources such as solar energy is operated at capacities to influx all available power into the grid, maximizing grid output regardless of its state [15].Enthralling advancements in both solar and wind power grids through continuous research has now paved a path to synchronize these generations with the local utility grids at optimum frequency levels [16].A salient feature of microgrids is that they can also provide backup power in critical scenarios when local grids fail to provide power, i.e. in isolated mode [17].
Due to the microgrid energy markets, small-scale prosumers and consumers now have a market platform to trade energy generated locally within their community.As a result, loss of energy is less because the consumption of energy is in close proximity to generation [9].This helps to promote sustainable and efficient utilization of local resources.It is to be noted that the market participants in a microgrid energy market do not compulsorily need to be connected physically.Multiple energy producers, prosumers, and consumers can be added to form a virtual community and the control can be maintained through virtual microgrids [9].

C. Blockchain Technology
Blockchains are databases containing the same sets of data, that are stored in the memory blocks of each person in the network [18].It does not consist of fixed memory bases, rather contains blocks whose data can be modified or extended with inputs from each agent in the blockchain.Smart contracts, which are computer programs allow currency exchange on the blockchain network without third party intervention.Each block stores smart contract individually [19].Whenever a smart contract is updated, every agent in the network is notified about the event.The data intake in the blockchain is verified by a verification process, such that the data in the network is accurate and not subject to any data spamming [20].Blocks include the hash sum of previous blocks, so breaking any block requires decrypting cryptogenic codes, which makes it impossible to break a good amount of block codes [21].Even if nodes connecting blockchain are disconnected each node on the network maintains its own set of the ledger, which prevents from data losses.Such algorithms can be the substitute of official administration.Blockchain is a very secure system for transactions which also provides distributed applications to convey understanding of each block and data on the system [20].

D. Blockchain-based Microgrid Energy Markets
A good number of research papers are available on the microgrid energy markets and blockchain technology individually but their aggregation is yet lacking greatly.Reference [22] particularly pointed out the use of blockchain technology in energy markets.They introduced a new virtual currency.They proposed that the generation and consumption of renewable energy can be directly transferred into virtual coins.The market value of the said currency is to be determined by the distribution system operators (DSOs) centrally.Reference [10] concluded that blockchains can strongly support electricity markets.Reference [11] outlined how the utilities can innovate their business models and boost-up microgrid markets with professional expertise by administering ancillary services and establishing a balanced energy system.

III. PROPOSED ALGORITHMS
In the following section we proposed two algorithms for the participating agents in these markets e.g.prosumers algorithm in Fig. 1 and consumers algorithm in Fig. 2.

A. Description of Prosumers Algorithm
Prosumers are those who can sell their excess power after energy is being produced.They can sell their power only when their demands are less than their own production.When this criterion is fulfilled blockchain gets the status and starts working.It will store the offered amount of power which prosumers wants to sell and will calculate the generated power by where   is the generated voltage level and   is the generated current rating.The total loss will be calculated by adding line losses and miscellaneous losses by where   is the resistance of total line and   is the value of the current of the line, and   *   is the miscellaneous power losses.Then the offered power can be calculated by subtracting (2) from (1).To calculate the total price, the total offered power is multiplied by the per unit price of energy.The per unit price is determined by negotiating among the prosumers and consumers of that area.After doing all these the offer status goes online where consumers can see the advertisement of selling and blockchain will sell the power to the consumers using first come first serve service.This system will run like a loop until there is stored power to sell and consumers are demanding power.When the power selling operation is completed both the customers will get notification.Here, virtual currency will be used as a medium for payment.

B. Description of Consumers Algorithm
Consumers are those who want to buy power for self-usage.Generally, they cannot produce power but sometimes prosumers can buy power also when their demand is greater than their production.When consumers demand is greater than the supplied energy then consumers want to buy energy from the local prosumers.When consumers give a status of their demand ledger blockchain make a demand list according to the time of their status then it compares both the demand list and the generation list which are offered in the system.Then by calculating losses and subtracting it from the actual power a message will be sent to both the prosumers and consumers notifying them about the transaction amount.When both the consumers and prosumers agree with it then transaction will be completed and power will be transferred from the local grid to the consumers.Consumers cannot buy power if there is no power left in the grid or there is no prosumer who want to sell power in that case transaction cannot be done and consumers have to wait till someone offer to sell power to the grid and then the process will start as per the algorithm.

IV. FUTURE WORKS
The next stage of this work is to improve the mechanisms of smart contracts and its security measures.We are also working on the issues related to efficient large-scale integration of renewable resources to the local grid and high voltage DC to DC transformation for microgrid integration to the grid.

V. CONCLUSION
An efficient and robust algorithm is introduced in this paper for peer-to-peer energy trading using blockchain mechanism.To run this system, specifically designed smart contracts are required for prosumers and consumers so that they can automatically perform transaction, negotiation and payment.Transaction can only be done when both prosumers and consumers are agreed to sell and buy energy at a certain price.Subsidy for the losses will be carried out by both prosumers and consumers.The whole process may be monitored by a regulatory authority for transparency and the price for the energy trading will be settled by the community and must be approved by the regulatory body.For performing this type of smart energy trading in microgrid systems smart meter is also needed which will perform its operation along with blockchain.Virtual currency could be the way for transaction of this smart meters.Overall, if this system is developed as per our assumptions then both prosumers and consumers will be benefitted for using renewable energy resources.