Peer-to-Peer Energy Trading in Microgrids: Towards an Integrated Open and Distributed Market

This work focuses on the electric power market, comparing the status quo with the recent trend towards the increase in distributed self-generation capabilities by prosumers. Starting from the existing tension between the intrinsically hierarchical current structure of the electricity distribution network and the substantially distributed and self-organising nature of the self-generation, we explore the limitations imposed by the current conditions. Initially, we introduce a potential multi-layered architecture for a Peer-to-Peer (P2P) energy market, discussing the fundamental aspects of local production and local consumption as part of a microgrid. Secondly, we analyse the consequent changes for the different users’ roles, also in connection with some incentive models connected with the decentralisation of the power production. To give a full picture to the reader, we also scrutinise relevant elements of energy trading, such as Smart Contract and grid stability. Thirdly, we present an example of a typical P2P settlement, showcasing the role of all the previously analysed aspects. To conclude, we performed a review of relevant activities in this domain, to showcase where existing projects are going and what are the most important themes covered. Being this a work in progress, many open questions are still on the table and will be addressed in the next stages of the research. Eventually, by providing a reference model as base for further discussions and improvements, we would like to engage ourselves in a dialog with the different users and the broad community, oriented towards a more fair and ecological-friendly solution for the electricity market of the future.


I. INTRODUCTION
One of the recent trends in the electric market is the focus on energy self-production from small plants, which are directly located on the consumers premises [1], [2]. These installations mainly consist of solar panels installed on roofs, but have recently included other renewable sources such as small dams or wind turbines. New technologies and decreasing costs in sustainable power production and storage utilities make a local individual-use power production increasingly attractive [3]. As a result, an increasing number of actors using microenergy generation has contributed towards the aggregated power production [4]. This leads to a more decentralised production, which stands in direct contrast to the legacy production modality, where a small number of centralised producer with a large energy generation have to fully cover the energy demand [5]. The decentralised production that mainly consists of renewable energies sources such as Photo Voltaic (PV) and wind, has increased within the European Union (EU) from approximately 15% in 2005 to almost 31% in 2017 [6]. It is noteworthy that concurrent with the increase in total production, the number of different users with renewable energy production possibilities also grew steadily [7]. This indicates a trend towards a distributed self-production [8]. For example, in 2016 Germany registered about 1 million and UK about half a million end users with electricity self-production capabilities from renewable sources [9].
This increase is a given in the current power market setting, which does not account for a significant number of selfproducing users and not provide any incentive for their further expansions. Strict regulation limits the use of individually produced power: either it is fed-in to the public power grid for a given price set by the Local Power Distributor (LPD) or it is consumed by the producer [10]. This issue is being tackled by an ongoing deregulation effort of the energy market, which has opened up new opportunities for self-generated power usage for both private and industrial parties [11]. One of the aims of market deregulation is to allow customers to freely select the energy provider, which offers the possibility to sell and trade power between any actor [12]. In combination with the undergoing digitisation in power measurement and payment possibilities, this energy market deregulation provides incentives for sharing energy within peer-to-peer energy communities [13]. These new incentives, paired with the improvements in capabilities from the technological side, enforce a redesign of the existing business models on all levels. Nevertheless, all these new opportunities bring also new challenges -on the technical, legal as well as the economic side. Additionally, the ongoing diffusion of Electric Vehicles (EVs), with their capability, depending on load status and usage plans, of being either heavy loads or mobile storage units, requires an adaptive approach to guarantee grid stability.
Throughout this paper, the reader will be presented with an overview of relevant building blocks needed for the creation of  a decentralised peer-to-peer energy market. First, a discussion about the transition from the status quo towards the new setup will be presented including a discussion of benefits from having in place a decentralised solution. This includes the incentives for having a local production and consumption, the new distribution of roles for the actors, the multilayered architecture of such a setup, the need for a decentralised auction house and transaction settling (smart contract) [14] as well as a possible approach for preserving grid stability [15]. In addition, an overview of existing projects and initiatives is given.
The remainder of this paper is structured as follows: in the two following sections, the status quo (Sect. II) and a possible future power grid architecture with producers, prosumers and consumers (Sect. III) are discussed. Starting from the innovate aspect of the distributed self-production, Sect. IV explores the incentives and the changes in roles connected with this paradigm shift from top-down to decentralised. Aspects of local energy trading are then covered in Sect. V, where a typical P2P settlement is explained. Finally, the chapter is finished by arguing the case for an incomplete energy settlement compensation which will highlight the roles of the network and local distributor operators. To complement this theoretical development, section VI overviews existing project and activities found in the literature, by analysing some aspects to draw conclusions about the most important themes in the decentralised P2P energy market, the Distributed Ledger Technologies (DLT) adopted and the consensus algorithm embraced. Eventually, section VII recaps this work contribution by drawing some conclusions. Being this a work in progress, many open questions are still on the table and will be addressed in the next stages of the research.

II. POWER DISTRIBUTION STATUS QUO
To date, the mostly applied electrical power grid topology has implemented a top down approach where the power is starshaped distributed from the production unit. After generating the energy, the power plant transforms it in to a high voltage energy and feeds it into the distribution grid. Over several continuously decreasing voltage levels, the centralised production unit supplies the consumers. These actors represent the end nodes of the star-shaped grid. Figure 1a shows the setup of such a centralised, starshaped grid architecture, where power is mainly unidirectional supplied from production units to consumers. In such a setting the only allowed action for consumers is to receive electricity from a small number of dedicated producers.
In a classic model of the production, distribution and use of electrical energy, a producer feeds a distribution grid that connects the consumers. A LPD is the primary point of contact for the consumers and it controls the energy flow.  represents typical energy profiles for the actors in the current star-shaped power grid set-up. Worth to note is that a typical consumer obtains its full energy need from the grid, while a producer shows a large production amount coupled with a negligible amount of self consumption.
As can be seen in the figure, there is another group of grid participants, known as prosumers. These actors, along with the dominating consumption, also show a small self-generation. In the past, only few prosumers managed to cover parts of their own consumption with sel-generated energy from renewable sources.
In case of a self-gerneration of the individually produced energy, it simply reduces the prosumer overall consumption from the public grid. Thus, improvements and new technologies allow prosumers to obtain a higher proportion of self-sufficiency. Over time, the self production levels have increased significantly, leading to moments of overproduction, during certain times of the day. This overproduction should either be stored in local batteries for a later reuse or be fed into the grid.
Storage (batteries) however are expensive (both for buying and installing) and their useful life span is limited. The resulting financial viability makes them unappealing for a storage of significant amount [16].
If a prosumer sells his or her own generated power to the LPD by feeding it back into the public grid, only a small amount of money is usually paid out. In fact, there is no market that defines the price but only a LPD can buy the generated energy, thus maintaining an artificially low price. This is because the LPD is the only available trading partner, as shown in figure 2. Here an excess of self-generated energy in (1) is sold to the LPD for a fix price defined by the LPD itself. Upon request from (2), LPD will provide it for a higher price. The consequence is that prosumers have no incentives to feed in the excess of energy from self generation.
The star-shaped distribution setting dominated the energy market due to the limits of available technologies for smallscale electrical power generation and the significant investments needed, and thus elevated entry barrier, for installing (1) ( (3) (4) Fig. 3: A deregulated system allows for a direct payment and energy exchange between two parties (e.g. prosumers).
renewable energy production infrastructure. Additionally, the existing legal framework acts as a further barrier.
In fact, the law does not allow buying energy from multiple contractors, even though in some countries it is possible to choose from a limited list of LPDes, such as in England [17].
Hence, there will always be a remaining dependency on an external power distributor in a system that is designed to be hierarchical and top-down. This is particularly problematic in an environment with a continuously increasing decentralised power production.

III. ARCHITECTURE OF A PEER-TO-PEER ENERGY MARKET
An alternative approach which takes into account an increasing decentralisation of the power production and allows for a bottom-up based system architecture is the Peer-to-Peer energy market. In such a system, energy trading can happen bilaterally between two actors, a buyer and a seller, without having the LPD as an intermediary. Figure 3 displays this direct ordered settlement between the parties (1), providing the electricity, and (2), receiving and financially compensating it.
For a Peer-to-Peer energy market to work effectively, a multi-layered architecture has to be in place. Figure 4 provides insights into the different layers, their roles and interdependencies. The layer are ordered upwards based on the data aggregation level and structured as follows: 1) Device Layer includes all physical devices, either present in a household/factory, or distributed in the electric distribution network for stabilisation purposes such as batteries. Data produced in this layer ranges from simple consumption measurement up to advanced information about device usage and status. This is also due to the lifespan of the electrical apparatus, usually spanning one or more decades, and making necessary to actively include also outdated appliances. The main issues in this level are the different data quality, the granularity of the data available and its richness.
Consequently, the quality and informativeness of the aggregated information provided to the upper level can  It is imperative that the devices in this tier are not owned by the end users, in order to avoid any risk of self-beneficial manipulation. In this way, it can work as a separation of concerns between the pre-meter and post-meter part of the electric network. Consequently, all power flows pre-meter is out of control from the LPD and DSO and is transparent to the public network. The Smart Meter Layer can be organised hierarchically, meaning single apartments/units/productive units can have a local meter, but they can be aggregated at a higher level such as buildings/companies or even blocks. The first problem observed here is the original scope for which Smart Meters were designed: measuring and pushing data in a certain time interval. No additional complex functionality was envisioned, thus the very limited specification of the Hardware (HW) used, and difficulty in adopting it for usage in a P2P market. An additional limitation stems from their sealed nature that prohibits any manipulation of the on-board software by a third party, making it difficult to adapt it to different requirements, such as "faster" communication intervals of less than 15 minutes. In a fragmented market, with multiple smart meter providers, a common setting is the presence of different communication protocols and standards. This poses a barrier for implementing new solutions because it is necessary to cope with all of them. 3) Transmission Layer concentrates in the communication channel between Smart Meters and DSO or LPD. It can be implemented using different technologies, such as Long Range LPWAN (LORA), General Packet Radio Services (GPRS) and Power-Line Communication (PLC). The main issue is the communication reliability: these protocols are not immune from connection drops and offer a limited bandwidth, in particular as consequence of topological and geographical constraints. As a consequence the achievable data throughput can be negatively impacted. High security standards should be adopted on top of the used protocol to ensure data reliability and trustability. 4) Communication Layer provides the functionalities for the integration of end users into the digital P2P marketplace. This involves the identification and governance of users and HWs, which serves as the basis for an automated matching between energy offers and requests.

Smart Met r Lay r
Here smart contracts regulate how the energy consumption and production aggregated data is publicly registered in the immutable, distributed ledger, as well as, the commitments for energy providing and consuming. One critical aspect of this layer stems from the fact that most protocols are in an early stage of development and adoption. This makes it difficult to make sustainable long term planning. The choice of protocol impacts multiple aspects, such as scalability, energetic footprint and compliance with privacy-related regulations. 5) Management Layer is the top level, responsible for processing data coming from lower layers ("Reporting" arrow), taking decisions, propagating them downwards ("Controlling" arrow) and, therewith, regulating the behaviour of the system. Amongst the main functionalities are energy production and consumption forecasts, regulation of the power flow and grid stability, dynamic tariffs setting and order settlement, as part of the decentralised auction house. The software applications sitting in this level serve as oracles, providing knowledge on the networks status and expected behaviours. All these insights are forwarded to the decentralised auction house, which serves as the logical hub of the P2P system. Here decisions are taken and then propagated downward throughout the different layers of the multilayered architecture.
Worth to note are the Reporting/Controlling data flows, interconnected by the Decentralised Auction House sitting at the heart of the distributed system. This is an original contribution, that shows the centrality of the DLT technology for such an approach. In fact, by implementing completely this architecture, all the basic elements for a full fledged P2P energy market are in place. This opens up various opportunities and incentives for building a new market structure, which focuses on decentralisation.

IV. MICROGRIDS, INCENTIVES AND ROLES
The transition of the network from a typically top-down approach to distributed production has implication on the exchange structure. The current trading paths are designed to always go over a centralised hub (e.g: LPD), which serves as an intermediary with the power of imposing the tariff structure. The P2P energy market, on the other end, follows a different approach, allowing intermediary-free direct trade between two parties, using a decentralised auction house as exchange platform. One of the key features of this auction house is to provide barrier-free egalitarian access to the energy market for all the actors. Consequently, the price is not set anymore by a single, privileged entity, but is decided by the free-market rules, following demand and supply. The resulting market freedom allows different incentives to be put in place for the end user supporting its maximisation of return. The excess in self-production can be either saved locally, in batterybased storage, or directly fed-in into the grid, based on the fair-priced possibility of an open market. Given the need to pay (network transportation fee) for the actual usage of the local grid to the DSO, the optimal approach is to have only local power exchanges between two actors of a community.
These abstract entities are represented in fig. 5 with dashed blue ovals, and are based on local geographical proximity and willingness to participate. As shown by a recent work, there is a structural limit for the effectiveness of this entities without affecting the global grid stability. It was demonstrated that the threshold is 10 participants, even when of different types [18]. Their objective is to foster a higher level of local production and consumption, and they are known as microgrid, due to their low limit in participants number, with respect to the typical grid dimension.
From a theoretical point of view, each microgrid could aim to a full self-sustainable environment, where local production equals the local consumption. This is also known as selfsustainability or autarchy. Despite the positive impacts such a fact will hold, this is globally a non realistic assumption: in fact exchange can happen also outside the local community, either because the demand and the request are not balanced within, or because some end user is not included in any microgrid, such as the first prosumer on the left of fig. 5. As the most part of the energy trades are supposed to happen inside the microgrid, the action house responsible for it has also the possibility to implement road pricing for fostering the self-sufficiency. In this context, road pricing refers to paying exclusively for the costs associated with transferring energy between seller and buyer on the available shortest path. This is supposed to represents only a fraction of the current transmission fees, since the entire transmission grid is not used for this order settlement.
For a better understanding of the new P2P energy market, the potential new roles are described in further details in the following section:  The main difference being that the consumer can now also access the auction house and thus profit from its services. This includes generating a personalised energy mix (combination of different energy resources), but also paying lower transportation fees, supported by the road pricing incentives model. Consumer preferences can be either managed manually or by using an artificial agent to automate the transactions. This could potentially allow the consumer to adopt optimisation strategies. 2) Prosumer is a special type of Consumer, that presents a certain level of self-production. It can presents moment of surplus in self-production, which is then fed into the grid and financially compensated, based on supply and demand in an open market place. Pre-meter trading allows for a zero-transportation-fee (ZTF) transaction, while post-meter trading inside the boundary of the microgrid can lead to reduced transportation fees. 3) Prosumer+ is a type of Prosumer with an average selfproduction that lies above the consumption. As such there is an increased need for feeding-in the energy surplus into the market. A distributed P2P energy market provides the most significant benefits for this category of market participant. 4) Producer holds the same role as in the status quo. It can also profit from the decentralised P2P system by being able to directly sale to the Consumer without a middleman. Additionally, a significant leverage to affect the price is given, in consequence to the large availability of production and storage capacity. 5) DSO ensures a congestion-less energy transmission in a free energy market by providing the grid and all smart meters. It receives a fee on every transaction for these services (road pricing). 6) LPD is responsible for the stability of the grid as a service for the community. Using large storage capabilities, it can intervene for stabilising the unbalances in the offer/demand, or to backup commitments that have not be honoured by one of the party. These storage facilities do not usually participate in the open market. Consequently, these services are subject to a stability fee, payed by the party that breaches the contract. The presence of so many different roles and conflicting interests has a significant impact on the trading architecture. As such it is critical to introduce a well-thought design that ensure that none of the parties has an advantageous position to force the system into an unstable state.
V. SMART CONTRACT TRADING Figure 6 shows a potential Smart Contract architecture for a decentralised P2P energy network. The previously described parties cooperate to create a settlement between a prosumer and a consumer. In order to achieve this, the following nonconsecutive steps should be included: (A) the Prosumer offer a given amount of self-produced available energy for sale on the network, at a certain given price range. The offer include the energy origin. The auction house generates energy tokens in accordance with the declared energy amount that can be provided into the grid in the future. These (utility) tokens are made available within the digital wallet of the Prosumer. (B) A consumer expresses the desire to purchase energy in the form of tokens in the near future. This request includes quantity, price range and type of energy, which is part of the personalised energy mix. (C) Once a matching between prices, energy origin and quantities has occurred, the shortest path between the two parties on the grid is calculated by DSO and the transportation fees derived. system needs to kick-in. This is necessary to avoid significant fluctuations in the voltage or frequency, which can damage powered devices. In the following section such a system is described in a more detailed way. To date, smaller and flexible producers as pumped-storage power plants compensate the divergence between demand and offer, while slow and large power plants are used for a basis load. Figure 7 shows the compensation of an incomplete settlement. The DSO jumps in by either absorbing the excess energy in the grid (Consumer failure to absorb the energy) or by providing the lacking amount of power (Prosumer impossibility to deliver the agreed amount). For fairness of the network, the party that correctly honours the smart contract should not be affected by the failure to comply with it on the other side. This means that the collateral deposited (stability fees) of the non-compliant partner only should be used for compensate the stabilisation task. Also in the private part of the network (pre-meter) can exist stabilisation facilities, in the form of privately owned batteries. These are responsible to provide a stability in the internal network.
Despite all the open issues presented here, a significant amount of research is already available in the area of P2P distributed energy market. A set of activities and pilot installations exists covering one or more of the criticalities presented in this paper. The next section will present a reasoned review of some of the existing studies.

VI. ACTIVITIES AND PILOT INSTALLATIONS OF P2P ENERGY MARKETS
Starting from some recent reviews about the Blockchain (BLC) technologies usage and perspectives for the energy domain [19]- [21], a set of 42 project related to P2P were identified.
Five main aspects are considered in the analysis, namely, the (I) country where the activity is rooted, the (II) main focus of the project, the (III) geographic scope, the (IV) BLC technology and the (V) category of consensus algorithm adopted, currently (V.a) and in the future (V.b).
For an initial classification of the countries where the activities originated, figure 8 provides a cumulative view. Due to space reasons, every country with just a single project is collected into the Others group. A clear interest in some European country is evident (in particular, the Netherlands forsaw this as one of the solutions towards a completely gasfree energy production). Also the United States of America and the centre of the EU (Germany and France) have a significant number of activities. Switzerland and UK have 3 reported projects each, where Australia, Belgium, Japan and Singapore present 2 entries each. Table II presents a division of this set based on the (II) type of application (main focus) of the project itself. The Smart Grid category groups projects where the attention is either on providing a P2P network detached from the traditional starshaped energy distribution or on designing the full architecture and the relevant assets for creating such a system. On contrast, P2P Platform represents activities that focuses on the energy producer/ prosumer LPD/ DSO Fig. 7: Overview of a peer-to-peer network in a smart grid application [22]. All members (producer, prosumer, consumer) participate on the same level while a 3rd party utility company provides the grid and all smart meters.

Netherlands US Germany
France Switzerland UK Australia Belgium Japan Singapore Others trading platforms without an explicit connection to the energy measurement and the relevant oracles used to providing information to the blockchain. Can be noted that the majority of them focus around smart grid, whether about a quarter main objective is in P2P platform support. The remaining ones aim to different topics and is here collected under the Other class.
Regarding the geographical scope of the activities (III) , table I reports the division into local, regional and national/global. Here is defined as local an activity that is limited to a small number of selected participants, located in close vicinity, such as for a neighbourhood or a small city district. These are typically small P2P communities especially formed for energy trading purposes. For the regional level, is taken the typical area of coverage of a LPD, such as cities and metropolitan areas, whether the national/global level covers multiple regional (or local) scopes. As potentially noted, the local scope is the prevalent focus for half of the reported exercises. This is also in accordance with the results for the application, as the smart grid focus is usually correlated with a local target, for easiness of introduction and to avoid conflicts with the current legal framework in the energy market. In fact 12 of of 16 projects with focus on smart grid have also a local deployment scope. Another interesting aspect is the prevalence of globally scoped activities over the regional ones, likely due to the broader expected impact of the project, whenever the regulating framework should anyway be taken into account.  The next relevant aspect (IV) scrutinises which DLT is adopted for the project. As evident from figure 9, there is a strong predominance of the Ethereum technology. A nonconclusive list of factors that can explain this phenomenon exists. Considering the relatively young age of this business field,  Fig. 10: Distribution of adopted type of consensus algorithms for P2P blockchain applications: currently applied algorithms.
the first players entering the domain are genrally perceived as most trustable and paving the path. In fact Ethereum got a significant traction in the early stage of DLT adoption, also because it presents very good documentation and a significant amount of well-designed and comprehensible examples for the most diffused functionalities. Cascade, whose adoption creates a vibrant and active community around the software, which guarantee continuous updates and easier access to programmable ready use for the underlying protocol. This is also an implicit signal that adopting Ethereum will be less risky from the business point of view¡¡ as this interest will realistically support the assumption that the technology will be still in place and usable in a 5-years horizon. One definitive aspect that oriented the adoption towards Ethereum is the fact that the protocol natively supports the IRC token standard, making it very easy to generate the type of utility token needed based on the specific asset that should be covered. All the Bitcoin family does not offer natively such a functionality.
This demonstrates that the native possibility of using smart contacts for the energy transactions is an important task. Other initiatives adopted the new concept of Multichain (an open infrastructure, where the different DLT solutions can coexist, also with the possibility of exchanging currency and tokens amongst them) for allowing a smooth potential integration of already existing local initiatives in the distributed P2P energy market.
The fourth aspect took into consideration is probably the most critical issue up to date for the adoption of DLT solutions in energy market, and has to do with scalability and energy consumption for running the system. This feature is the consensus algorithm adopted. Figure 10 and figure 11 present respectively the current status and the future expected consensus approach that the analysed activities declare.
It is noteworthy that in absence of information regarding these aspects in the documentation or publication from the project itself, we assumed that the "native" agreement approach from the chosen DLT is preserved. This analysis is not run at the level of the specific algorithm, but aggregating them based on the main underlying functioning mechanism. This is also useful to draw some general conclusions about the limitation and the offered properties. What can be noted here is the moving from a predominance of computationally intensive and  Fig. 11: Distribution of adopted type of consensus algorithms for P2P blockchain applications: future planned algorithms. energy voracious approaches towards more scalable algorithms that stress the recognition of nodes commitment to serve the DLT, in term of resources specifically and uniquely devoted to it. The current status, in fig. 10, demonstrates the prevalence of Proof-of-Work (PoW) approaches. Here the addition of a new block to the chain involves the resolution of a cryptographic puzzle, operation usually referred to as mining.
In contrast fig.11 indicates that other approaches will be privileged in the future, in particular the family of PoS. Another notable aspect is the fact that proprietary or peculiar algorithms that are adopted for specific reasons, tends to stay in place along the lifespan of the project. As a final note, the predefined consensus approach of Ethereum is moving in the same direction, due to the request for a significant reduction of its energy consumption [23]. This fact can be clearly read into the aggregated data from figure 12, where the relative frequency of the current and the future type of consensus mechanisms are compared. By looking only at the PoW and the PoS categories, this trend can be clearly seen, with the first reducing of 40% and the second increasing of 45%. This can partially be explained by the marketing willingness to present the project as interested into a broader profile of sustainability and scalability, but also by the new Ethereum 2.0, that will move the predefined consensus algorithm to a PoS solutions.

VII. CONCLUSIONS
This work presented an analysis of the energy market, with respect to an increasingly percentage of distribute self- generation of electricity, mainly using small-scale plant, such as PV roof-based installations. It started by analysing the current setting of the energy distribution network and the roles existing in this highly regulated market. It continues by exploring which aspects of the status quo are hindering a real diffusion of a P2P decentralised energy market, without privileged positions. By doing this, it also introduces the new roles of Prosumers and defines how the traditional players are affected. It proposes a model for the layered architecture such a system would require by depicting the features expected in each layer and by exposing the limitation currently existing, due to HW, technical or legal aspects of the level.
It continues presenting the current trends towards a more liberalised market, introducing the concepts of Microgrids and their role in facilitating localised exchange between end users, towards a focused higher energetic self-sufficiency. An analyses of the role evolution in this new P2P decentralised setting is provided, stressing the centrality of the DSO and LPD for the energy network financing (through transmission fees collection) and the grid stability (by compensating energy availability oscillations), respectively. To showcase how a decentralised market can work, this work present a theoretical model for the use of Smart Contracts in energy trading, stressing the necessary steps for its generation, and showing the mechanisms in place to compensate the network utilities (DSO and LPD) for the services provided to the community of energy users. Eventually, an analysis of existing activities and pilot projects towards a P2P decentralised energy market is reported, showing the prevalent aim, the geographical scope, the type of DLT approach and the consensus mechanism suggested. With this work, we would like to raise the awareness of the steps still to be done for a real transition towards a decentralised system without privileged actors, to reason with the community interested about models and partial components that can bring us closer to a more fair and ecological-friendly solution for the electricity market of the future.