Proposed framework for blockchain technology in a decentralised energy network

The integration of distributed renewable energy sources into the conventional power grid has become a hot research topic, all part of attempts to reduce greenhouse gas emission. There are many distributed renewable energy sources available and the network participants in energy delivery have also increased. This makes the management of the new power grid with integrated distributed renewable energy sources extremely complex. Applying the technical advantages of blockchain technology to this complex system to manage peer-to-peer energy sharing, transmission, data storage and build smart contracts between network participants can develop an optimal consensus mechanism within the new power grid. This paper proposes a new framework for the application of blockchain in a decentralised energy network. The microgrid is assumed to be private and managed by local prosumers. An overview description of the proposed model and a case study are presented in the paper.


Introduction
There has been increased interest recently in the application of blockchain technology to energy networks with distributed renewable energy sources. Blockchain technology with its decentralised and trustworthy nature can provide a wide range of advantages in energy delivery such as peer-to-peer (PTP) energy sharing and data management among different decentralised energy networks [1][2][3][4][5][6]. Blockchain can also provide a secure digital platform where energy prosumers are able to directly participate in the energy market without the need of a third party [4]. Therefore, the adoption of blockchain technology can enhance the integration of renewable energy sources and facilitate energy delivery between different energy mixes and thus revolutionize the energy sector.
The integration of distributed renewable energy sources into the conventional power grid is of significant interest in both developed and developing countries [7,8]. This is partly because of pressure from environmentalists and other activists calling for the reduction of greenhouse gas emissions. In addition, there are increasingly serious environmental problems due to the use of fossil fuel for power generation. Furthermore, there are many distributed renewable energy sources available and the number of network participants in energy delivery have also increased [9,10]. This has made the management of new grids with integrated and distributed renewable energy sources extremely complex, as most of the renewable energy sources are distributed all over the geographical space. Many countries such as South Africa have embarked on a process to reduce the amount of power generated from fossil fuels by replacing them with sustainable renewable energy sources [11,12]. These sources are implemented at both high-and low-level scales. Megawatt renewable energy power is incorporated by some power utilities and big companies. On the other hand, low-level scale energy systems may be built by electricity consumers at their premises where they are able to generate their own electricity. However, at some point, the electricity consumers might produce Page 2 of 11 Dzobo et al. Prot Control Mod Power Syst (2021) 6:31 more than their load requirement and would want to feed the surplus back into the grid. Electricity consumers then become prosumers who are able to produce and consume electricity at the same time. This makes the control and management of a distributed energy network extremely complex.
The new power grid now consists of a broader number of participants, a variety of energy forms and a different mode of information exchange. Therefore, there is a need to develop innovative energy delivery systems with complementary multi-energy systems that are highly integrated and distributed, and can provide a secure way to exchange energy management information. Applying the technical advantages of blockchain technology to this extremely complex network will ensure an optimal and secure mechanism for management of data transmission and storage, and implementation of smart contracts between the power system network participants.
The traditional approach of managing a power grid is that the balancing responsibility of the network lies entirely with the aggregator and/or regulator [7]. Figure 1 shows the power flow in a traditional power system management approach. Power generation is done by a sole entity and any other energy player who needs to generate electricity will have to consult the entity. The sole power generation entity is also responsible for balancing the power dispatch in the entire power grid. It owns the transmission and distribution processes and trades directly with all the electricity consumers. As a result, PTP energy transfer between different entities or network participants is not possible in a traditional power system network configuration. Therefore, only smaller volumes of power will be traded on the energy market by other independent power producers as there is more consumption from the sole power generation entity.
The South African energy market is set up in such a way that Eskom is the sole supplier of electricity in South Africa and is thus the aggregator. Besides generation of power, with prior approval by the National Energy Regulatory Authority of South Africa (NERSA), Eskom also determines the pricing of electricity at any given time. Eskom supplies more than 99% of the electricity in South Africa [12]. In developed countries such as Belgium, the energy market has already seen a sharp increase in the number of energy competitors or providers in the energy market [10]. By April 2018, the number of energy competitors who were participating in the Belgian energy market had reached 42 [10]. However, besides the increase in participation of different energy competitors, two major competitors supply more than 61% of the total energy requirements and as many as 34 energy competitors have a combined market share of less than 1.36% [10]. This lack of competition in the energy market is a result of the inability of government regulations or policies to level the energy market playing field. When government energy policies are mainly focused on the electricity pricing it becomes difficult for small energy competitors to enter the energy market. The consideration of factors such as environmental and socioeconomic issues above electricity pricing may be an edge over the current energy market. The management and control of these issues in power systems when using a trusted central institution is still very unpredictable, especially with the presence of Big Data from interconnected internet-of-things (IoT) devices and a large number of energy players.
The addition of different energy players into the power system, ones who are able to produce their own electricity and at the same time supply their excess electricity into the national grid requires innovative control and management techniques. A lot of research has been carried out to determine the optimal power dispatch in power grids with renewable energy sources [7,13,15,17]. Reference [13] investigates the energy and revenue savings a prosumer would get when producing electricity for their own consumption while supplying their surplus electricity into the national grid. The results show that the prosumer is able to reduce usage of electricity from the national grid, hence realize revenue savings when such a scenario is implemented. However, this kind of scenario requires complex management of the power system. Recent developments in IoT technology has enabled real-time data retrieval and storage [16,18,19], which facilitates the efficient management of power supply and consumption, as well as offering improved system security.
In 2016, the World Economic Forum (WEF 2016) reported that digitalization in the energy sector could yield more than $1.5 trillion in value by year 2025 [14]. This process needs reliable software and hardware solutions in order to transform a typical energy network into a digital platform. In this sense, the 5G mobile technology and concomitant technologies such as IoT, Big Data and machine learning can play a pivotal role in the development of digital energy platforms, while blockchain technology can ensure efficient and secure data flow within the power system. This is because of the distributed and decentralized architectures of 5G and blockchain, which align with those of distributed smart energy systems. The key technologies in blockchain are consensus mechanisms, encryption algorithms, smart contracts, and distributed data storage [20][21][22][23]. If blockchain technology is applied to the new power system, a decentralized energy trading platform can be developed based on a consensus mechanism [1,5,17]. Automated and efficient energy trading will be guaranteed through the application of IoT devices, powered by reliable and efficient 5G systems to provide real-time data flow in the power system, while blockchain technology will ensure automated execution of smart contracts between power system participants [5]. Power system participants will be allowed to query transaction data in the blockchain, thus ensuring transparency on the whole energy platform [4]. In addition, data in the power system will be protected by encryption algorithms and distributive data storage [4]. This paper proposes a framework that uses blockchain technology for energy trading in a decentralised energy network with renewable energy sources. The significant contributions of this paper are: • A general blockchain model is presented for energy trading within a smart grid with prosumers based on a consensus mechanism. • An algorithm is proposed for energy trading on a trusted and secure digital platform without the need of a third party. • A hypothetical case study is presented to illustrate automated and efficient energy trading between power system network participants using smart contracts.

Blockchain technology
Blockchain technology was developed in November 2008 by Nakamoto Sang in the published paper, 'Bitcoin: A peer-to-peer Electronic cash system' [8]. The author proposed that two parties can directly perform a transaction with each other without the need of a trusted third party. The verification or confirmation of the transaction is based on cryptographic signatures of the two participants performing the transaction. This underlying technology of Bitcoin has started to be applied in different applications such as agriculture, energy etc. [24][25][26][27][28][29]. When used in a large network with many participants, every network participant is able to directly transact with each network participant without the need of a trusted third party, while the other network participants in the network can confirm or verify the transaction. The transaction between two network participants can be triggered automatically using smart contracts. The following are the main characteristics of blockchain: • Distributed database: It is sometimes known as the distributed ledger [30]. It is a database that has all the communication and transaction records of all the network participants connected to the respective blockchain network. The information stored at each node in the blockchain network is in the form of blocks. A block of information consists of hashes of the previous and current blocks, and the transaction record which is also in the form of a cryptographic hash value. Each node stores the same information as all the other nodes on the blockchain network, while the hash-linked blocks are stored as Uniform Resource Locators (URLs) that point to a database where the actual data (communication and transaction records) for a particular node is stored. The database is not centralised or owned or secured by one institution, while every network participant is able to access the database and verify or confirm the data records. • PTP transactions: The communications and transactions executed in a blockchain network are done directly between the customer and provider without the need of an intermediary. There is no trusted third party or central node that is involved in verifying or certifying the transaction. The executed transaction is stored in the computers of all the network participants including those involved in the transaction. This means all network participants are able to see the transaction and provide verification or confirmation of the transaction. • Immutable records: The immutability of database records in a blockchain network means the database records cannot be changed or altered. When a transaction is executed, the information of the transaction is encrypted and combined with encrypted information of other transactions that are executed at the same time. This will form a new block of data, which the network participants will verify or confirm. When verified or confirmed, the new block of data is added to the chain of previously verified or confirmed blocks, so a block of data for each executed transaction will consists of the current encrypted block of data, a nonce, timestamp and a link to the previous block of data. Once the block of data is entered in the database, it cannot be changed or altered, and thus it is immutable. • Smart contracts: A smart contract is a set of rules that are agreed upon by all network participants and are therefore legally enforceable. To execute a smart contract all the set of rules or conditions must be fulfilled. Network participants define the rules or conditions that trigger automatic execution of transactions between peers in the network.
Blockchain can be implemented in three different ways, namely, private, permissioned, or public [21,29]. In a private blockchain network, a group of participants set the rules or conditions that must be fulfilled to execute a smart contract. In permissioned blockchains, the network is operated by a known entity or entities, who are responsible for setting the rules or conditions that must be fulfilled to execute a smart contract. In both private and permissioned blockchains, the power required to run the network computers to execute a transaction is very low. In public blockchains, the network participants are assigned blockchain addresses in order to conceal their real identities. All network participants can verify or confirm and write in the shared distributed database. In order to achieve anonymity, immutability and transparency, a huge amount of power is required to run the computer networks so that there is consensus in the blockchain network. This slows down the transaction speed and hence the efficiency of the network is low compared to both private and permissioned blockchain.
The use of blockchain in the energy market has the potential to improve transparency and traceability, scalability, and security, as well as to reduce electricity cost. Information sharing between prosumers, energy network providers and electricity consumers is critical to efficient and timely energy sharing in the energy network [31]. Blockchain can enhance the sharing of information across the energy network and thus improve the decision-making processes in the power system as well as the energy resource tracking, transparency, and visibility. Blockchain can also provide product description information, a comprehensive record of energy production activity, usage, location, and electricity pricing. The enhanced traceability in the blockchain network will thus provide real-time and valid information about the location and energy production activities of each energy competitor in the network. For example, attribute differences such as renewable or fossil fuel energy generation can be ensured by the use of blockchain. Blockchain can also greatly improve and streamline the implementation of pricing policies as it allows prosumers to collect and share data with different tiers of the blockchain in realtime. Finally, blockchain can provide solutions to manage energy delivery and transactions among prosumers within the network thus creating a secure digital communication platform for the energy network. The collected information can also be implemented for different environmental management scenarios. For example, energy from fossil fuel energy-generation sources can be redistributed to the final consumption points, e.g., energy intensive consumers, on a premium in the form of carbon tax.

Proposed blockchain powered energy network
Initially, blockchain technology was designed to provide solutions in currency transactions. Over the past few years, the technology has been extended to non-currency solutions. The application of blockchain technology in most non-currency transactions focuses mainly on security mechanisms. Blockchain technology is also proposed for use in IoT devices, and the combination of blockchain technology and IoT is expected to facilitate the sharing of devices and resources, and allow secure execution of workflows in several industries including the energy sector.
Typically, energy production involves all the energy generation and supply practices; and energy supply uses, including the natural resources used for power generation and the type of transmission lines and transformers used for electricity distribution. Activities differ throughout the energy sector depending on the different actors (energy suppliers, power system planners, wholesale energy traders and markets, and electricity consumer) within the power system. From the energy sector perspective, it is evident that electricity supply is prone to security issues in the areas of electricity storage, transmission, provenance of power generation as well as power system management strategies. In this regard, blockchain technology could be the answer to solving security issues on the route from energy generation to consumption, thus providing visibility throughout the energy supply chain. Figure 2 illustrates the proposed blockchain framework for distributed energy systems. The proposed blockchain powered energy network has prosumer energy records gathered at each microgrid and communicated through local gateways. The prosumer energy records are stored in distributed cloud servers, which will include personal information and energy generation and/or consumption history recorded through the individual prosumer smart meter. Each prosumer will have a personal identity (ID) and will be classified based on the microgrid area in which the prosumer is connected. In the proposed model, the assumption is that the microgrid is private and is managed by local prosumers connected to it. Therefore, the address of each prosumer on the blockchain will have the address ID of the prosumer's smart meter, microgrid ID to which the prosumer is connected, and the address of the grid administrator, i.e., smart meter address ID, Microgrid ID, and GridAdmin ID. Since it is too expensive to store large datasets in the blockchain, it is more desirable to store only the prosumer addresses in the blockchain while the prosumer records are stored on a decentralised cloud storage. Consequently, only a URL linking the data set to the cloud storage is shared in the blockchain system. To retrieve a prosumer record on the decentralised cloud storage, the participating entity, e.g., system controller or regulator, needs to know the prosumer address which is visible in the blockchain. The arrows in Fig. 2 show the data flow of the proposed blockchain powered energy network. The storage and access of data are done on the blockchain platform to ensure that the interactions between prosumers in the blockchain network are visible, immutable, and transparent. The data stored on the blockchain platform acts as pointers to the information of prosumers stored in the external distributed cloud server, so each data block on the blockchain platform will point to particular prosumer information in the distributed cloud server. The proposed blockchain powered energy network is a permissioned blockchain system, and below are detailed descriptions of the different components of the proposed blockchain powered energy network.
Microgrid manager: The microgrid manager plays an important role in sharing prosumer energy records in the energy network. This includes the control of all the prosumer transactions on the blockchain platform, including the process of data storage in local gateways and data access by prosumers. The information management capability is enabled through executing smart contracts that are built based on agreed policies of local prosumers connected to the respective microgrid.
Smartgrid administrator: The Smartgrid administrator manages all the transactions and operations of the decentralised cloud server. This is achieved through giving permission to prosumers and/or the regulator to add, change or revoke access to the decentralised cloud server. The Smartgrid administrator will deploy smart contracts to the Smartgrid and is the only entity that is able to add or modify policies in smart contracts of the smart grid. The Smartgrid administrator is not involved in the management of each local microgrid and will only interact with the microgrid when the latter needs to feed power into the national grid. The policies that are used in the smart contracts of the smart grid are adopted from the regulator. The Smartgrid Administrator is therefore the centre of communication between the regulator and the prosumer. Decentralised cloud storage: Prosumer energy records are stored in a decentralised cloud storage e.g., the Interplanetary File System (IPFS), the Amazon cloud storage system etc, considering the functional capability of the distributed cloud storage system such as data retrieval, high storage throughput, no single point of failure etc. While the prosumer energy records are encrypted and stored in the decentralised cloud server system nodes, the hash values of the energy records are recorded and stored by the Smartgrid administrator in the blockchain platform. This is integrated with the smart contracts executed only by the Microgrid manager to ensure improved security and better data access management.

5G
Smart contracts: Smart contracts are the core software in the proposed blockchain powered energy network, and can be accessed by all entities. The smart contracts are able to validate requests, grant access permissions and also identify the entity or prosumer triggering transactions or messages.
Energy records: The records are generated from execution of smart contracts. Each energy record is a transactional record that is generated by executing a smart contract and is a block of data. In order to access the energy record of a prosumer, the entity needs to provide information (e.g., prosumer smart meter address ID, microgrid ID) which must be signed using the prosumer cryptographic key at a certain given time (timestamp). The prosumer is able to grant, revoke, verify or confirm the data access request. The digital signature establishes trust between the prosumer and decentralised cloud server.
System controller/ regulator: The system controller and/or regulator is the entity that sets the policies to be followed by all prosumers in the grid. For example, it sets the electricity price at any given time of the day and the rules for each microgrid to feed electricity to the whole grid. The amount of electricity that must be fed into the grid at any given time is also determined by the system controller/regulator. It does this by liaising with the base load supplier to determine the deficit required in the grid. The regulator communicates with the prosumer through the Smartgrid administrator and microgrid manager. The regulator is also able to request information from the cloud server for any electricity customer or prosumer but is not able to write or change any information of the prosumer. This is required in cases where any malpractice in energy delivery needs to be investigated. In addition, the regulator also sets the policies to be observed when supplying electricity to the grid, e.g., electricity price and energy mix to be achieved in the grid at any given time etc.
Base load supplier/Eskom: The base load supplier is the main supplier of electricity to the national grid. It is usually for targeted supply such as industrial customers but also provides electricity for critical customers such as hospitals, security facilities etc. The base load supplier normally uses fossil fuel for electricity generation, e.g., Eskom in South Africa.
The proposed blockchain powered energy network enables data to remain private while allowing entities within the energy network to have the advantage of immutability and traceability. This means the management of complex supply chains like the energy supply chain and its payment can be automated. For example, a prosumer can order electricity and be assured of the source and location of the generating entity, whether it is generated using clean energy production etc., since the data would have been recorded in the smart contract. Furthermore, this is advantageous as it prevents any single point of failure in the network and a single node from controlling the whole network.

Case study
A prototype that simulates blockchain based energy network is implemented on the Ethereum Blockchain technology platform to manage the energy trading of prosumers in a decentralized architecture. A smart contract for secure exchange of energy records is implemented using the Solidity programming language. The validation results are acquired by deploying the blockchain locally on a computer, while for better user interface (UI) interactions, the blockchain is deployed on the remix online platform (see Fig. 3).
In Ethereum, the payment used for energy transactions is the Ethereum coin or Ether, which is the currency used in our blockchain network. Each distributed energy prosumer (DEP) has its own coins, and can obtain more through energy trading and mining. The energy data for each DEP in the energy network is randomly generated at a reasonable energy production value ranging from 10 to 100 kW. In the case study, 3 DEPs are deployed with the following addresses in a blockchain, as seen in Fig. 3: One Microgrid manager is also deployed as the DSO to manage and balance the above microgrid, with address: DSO -xD7ACd2a9FD159E69Bb102A1ca21C9a3e-3A5F771B The architecture models the energy network as a network of blockchain nodes composed of 3 DEPs and 1 DSO. In Fig. 4, the general architectural model is presented where each node N is a DEP that is composed of a smart contract, which defines validation rules and a list of transactions T n (where T is a transaction and n is the number of transactions). Each DEP is a node in a peerto-peer network that has smart IoT metering devices for monitoring and recording energy generated (see Fig. 5) and energy used at any given time t. Monitored data is recorded by DEPs, stored locally, and distributed to all peers in the network for validation. DEPs have digital identities that help the network to identify who is distributing data.
This decentralized approach complies with data and security standards by keeping data locally and not in a centralized location. As new energy data values are recorded, the DSO calculates and balances the grid based on excess and/or deficit energy of each DEP. Energy production should be equal to energy consumption but, in our simulation, there are points where DEPs have more energy than expected (excess). In those cases, the DSO will allow DEPs that have excess energy to sell to DEPs that have deficit energy. If there is not enough energy to trade, the grid will be unbalanced and the affected DEPs will have to curtail their excess load to match the power generation. The following is a recursive algorithm used to balance energy trading between peers in the microgrid.

DEP stage
Step 1: Record energy values from the smart IoT metering device: energy generation (E G ) and energy consumption (E C ).
Step 2: Determine the energy deficit/excess using the following formula: Step 3: Send the data to the microgrid manager/DSO, including smart meter ID address, E G , E C , and energy deficit/excess value.

DSO stage
Step 4: Read the data received from all the DEPs in the microgrid.
Step 5: Find the DEP that has energy deficit/excess.
Step 6: Trade energy from DEP that has excess to the one with energy deficit.
Step 7: Repeat Step 5 and 6 and stop if one of the following conditions are true: a. No DEP with energy deficit.
(1)  In the implementation, public keys are visible to every node in the network, and DEPs use private keys to sign information before it is distributed to all the nodes. A public key is calculated with an algorithm common to all the nodes to ensure that only network participants on the blockchain can compute and get the public key for any transaction. Through IoT smart metering devices, energy generated or monitored is shared across all nodes on the network, so all DEPs have visibility of how much energy each DEP is willing to trade. Transactions containing energy trading by each DEP is also shared to all nodes in the network for validation, and once the transaction is verified it is then added to the immutable distributed ledger. Verification includes matching transaction data with the agreed values on the microgrid. In the implementation, smart contracts are defined for each DEP and DSO. As energy is being produced by DEPs and measured through IoT smart metering devices, smart contracts check the balance in the microgrid and create various events to keep the grid stable. The IoT smart metering devices in a smart contract monitor the energy generated continuously, and for each new energy value the DSO triggers the execution of a smart contract. All DEPs receive a signal event from DSO requiring DEPs to trade their excess energy. This signal contains the amount of energy required to balance the energy demand at microgrid level. The smart contract keeps track of energy deviation at each DEP and calculates the overall balance of energy production and consumption at microgrid level.

Results
Figures 6a, 7a and 8a show unbalanced energy at the three DEPs in a microgrid without the DSO managing and balancing the microgrid. The DEPs monitor the energy values and send their data to the DSO, so the DSO triggers the smart contracts to balance the whole microgrid. Figures 6b, 7b and 8b show that the DSO can efficiently balance the microgrid in almost real-time using the blockchain-distributed architecture. In some instances, it can be seen that a DEP is forced to curtail its load because there is insufficient energy generation from other DEPs to cater for the energy deficit. For example, at time t = 7 the energy generation for DEP 2 is 20 kW while the load requirement is 60 kW. Since there is not enough energy production in the microgrid to cater for the 40 kW energy deficit, DEP 2 is forced to curtail its load to match the available electricity. Figure 9 shows the PTP energy trading transactions between DEPs for a single iteration. The getfromaddress shows the smart meter ID addresses from which energy was supplied and the getToaddress shows the smart meter ID addresses of the DEPs that had energy deficit and received the energy supply. The energy values that were traded between the DEPs are also indicated.
Increasing the number of DEPs in the microgrid will result in more energy generated as well as energy consumed. However, with more DEPs added to the blockchain network, data storage, processing and sharing will require more energy resources to maintain realtime monitoring of the system. Energy transaction data can be stored locally and a high number of transactions can be grouped, processed, and shared to all peers in the network. This will increase processing speed, rate of transmission, and reduce communication between network nodes. Another alternative to sharing data in a blockchain is to group the transaction data and the data is then hashed and stored in a tree data structure. Thus, the nodes that do not have capacity (light nodes) to store raw data only need to store the data URLs pointing to the cloud storage server, and therefore can search for the actual data in the cloud servers.

Conclusion
The management of consent and access in the energy supply chain now places more emphasis on prosumers being provided with the ability to define rules of access to their energy supply and consumption. Real-time tracking and reliable recording of all transactions across the energy sector can enhance regulatory compliance, profit margins and inventory management, while also ensuring sustainable, scalable, transparent and consumer-oriented electricity services. Blockchain technology can link information flow to the energy supply chain and enable the delivery of reliable information to all stakeholders for decision-making activities. However, it is important to note that blockchain technology is no universal panacea, and thus power system operators and planners should still focus on balancing the technology and human factors in the energy sector.
In this paper, a distributed blockchain-based architecture model for balancing and managing microgrids in a smart grid is proposed. A case study is presented, and the key elements of the microgrid and their functionality are simulated. In the implementation, the DSO manages the microgrid and facilitates energy trading between DEP peers until the microgrid is balanced. The smart contracts used in the microgrid are implemented using the Solidity programming language and deployed on the online Ethereum Virtual Machine Blockchain platform for verification. The results show that, with the distributed blockchain-based architecture, it is possible to have PTP energy trading between DEP peers in a microgrid and the microgrid can be balanced in real-time. In future work we will include the type of fuel used by the DEPs to generate energy, the energy bidding process and DEP location in the blockchain-based architecture. Future work will also focus on implementing a secure access control model of the proposed blockchain powered energy network.