Distributed Ledger Technologies for Peer-to-Peer Local Markets in Distribution Networks

: The newest Distributed Ledger Technology platforms, which delegate the execution of complex tasks in the form of Smart Contracts, make it possible to devise novel local electricity market frameworks, which are performed in a fully automated fashion. This paper proposes a novel fully automated platform for energy and ancillary service markets in distribution networks, able to run in a decentralized fashion, bypassing the need for a physical central authority. The proposed platform, able to perform the role of Virtual Decentralized Market Authority, shows excellent potential applications in the management of local ancillary service markets in local energy communities of various sizes. The proposed Virtual Decentralized Market Authority showed reasonable running costs and comparable technical management capabilities with respect to a physical, centralized managing authority.


Introduction
In recent years, different political, economic, and technical drivers have been leading the evolution of the electric power system towards the smart grid paradigm. This transition will produce fundamental changes in the structure of the power system and, in turn, on the planning and operation activities [1][2][3][4]. The architecture of the power system is moving from a centralized towards a decentralized model. This is due to the development of strategic policies and regulations, such as market liberalization and decarbonization plans, that are stimulating the decommissioning of large fossil fuel-powered power plants, and the adoption of local measures for grid management [2,3] that are capable of better integrating the deployment of renewable sources. Therefore, the future power system requires the exploitation of the flexibility offered by all of the involved parties to obtain a reliable and cost-effective power supply [1,5,6]. However, a paradigmatic change of the power system operation from a top-down to a bottom-up approach implies a shift in responsibilities from centralized authorities towards decentralized entities, encouraging the interaction of all the grid users. Decentralized energy systems are appealing, since if distributed resources can be exploited locally, the efficiency of the overall power system will be increased [7]. In this context, novel approaches that enable the active participation of grid users have been proposed in the recent literature to guarantee a safe and reliable electric power supply [8][9][10]. The loads, distributed generators, and storage devices are managed to form a unique controllable system [9], which can become a market counterparty on a higher level according to the Microgrids (MGs) and Local Energy Communities (LECs) paradigm. With MGs and LECs economic, social, and environmental benefits can be achieved by pursuing the complementarity among the participants [8][9][10][11][12].
Given the recent technological advances in Artificial Intelligence (AI) and Internet of Things (IoT), the scientific community has started to introduce the concept of Peer to Peer (P2P) energy and service of SC OPF-based markets [29]. As depicted in Figure 1, the proposed CDA allows players to place offers and asks bids as registered Balancing Responsible Parties (BRPs). These bids are then matched automatically by the SCs on the decentralized platform; hence, the peers are automatically coupled. In the offer-ask couples created by the SC, a certain amount of reserve is ensured by the offering peer to the asking one. The offering peer is then obliged to deliver the reserve to the coupled asking peer. The burden of grid balancing is moved from the SO to the BRPs, which are legally bonded by the SC. The interaction allows the balance of power without any need for intervention of a centralized management authority.
Energies 2019, 12, x FOR PEER REVIEW 3 of 20 matched automatically by the SCs on the decentralized platform; hence, the peers are automatically coupled. In the offer-ask couples created by the SC, a certain amount of reserve is ensured by the offering peer to the asking one. The offering peer is then obliged to deliver the reserve to the coupled asking peer. The burden of grid balancing is moved from the SO to the BRPs, which are legally bonded by the SC. The interaction allows the balance of power without any need for intervention of a centralized management authority. The effectiveness of the proposed methodology has been tested on a benchmark network [31]. As an additional result with respect to the previous literature, the economic costs related to the use of decentralized platforms for the implementation of electricity P2P communities have been evaluated. It has been found that the proposed method yields technical outputs comparable to those of a centralized OPF, but with very limited deploy and running costs with respect of human-based auctions. Moreover, the computing costs of the proposed framework have been tested for networks including up to 50 nodes, showing limited costs also for bigger communities and providing useful insights on the type of users and grids to which this technology can be applied.

From Centralized towards Decentralized P2P AS Market Frameworks
In the context of the electric power system, the ancillary services represent all the necessary activities for guaranteeing a safe and reliable power supply by meeting the quality specifications. The ASs may be classified into frequency services and non-frequency services [32]. The frequency services are related to active power balancing and involve measures such as frequency control, load balancing, reserve capacity, and black start capability. Non-frequency services are related to voltage control. The provision of the ASs requires a flexible operation of the power plants, therefore their actual operating level is usually set below the full capacity level [13]. Until now, the ASs have been managed by a central authority (i.e., the Transmission System Operator-TSO-or the Independent System Operator-ISO) by means of control signals or behavioral arrangements defined in the grid codes or by means of bilateral agreements. In general, the flexibility guaranteed by the power plants is procured by the central authority by means of single-sided markets or by defining compulsory policies [13,[33][34][35]. However, the sustainability of the centralized provision of ASs is determined by the evolution of the power system. In fact, with the increasing penetration of Distributed Energy Sources (DERs) supplied by intermittent and unpredictable sources, the demand for ASs during The effectiveness of the proposed methodology has been tested on a benchmark network [31]. As an additional result with respect to the previous literature, the economic costs related to the use of decentralized platforms for the implementation of electricity P2P communities have been evaluated. It has been found that the proposed method yields technical outputs comparable to those of a centralized OPF, but with very limited deploy and running costs with respect of human-based auctions. Moreover, the computing costs of the proposed framework have been tested for networks including up to 50 nodes, showing limited costs also for bigger communities and providing useful insights on the type of users and grids to which this technology can be applied.

From Centralized towards Decentralized P2P as Market Frameworks
In the context of the electric power system, the ancillary services represent all the necessary activities for guaranteeing a safe and reliable power supply by meeting the quality specifications. The ASs may be classified into frequency services and non-frequency services [32]. The frequency services are related to active power balancing and involve measures such as frequency control, load balancing, reserve capacity, and black start capability. Non-frequency services are related to voltage control. The provision of the ASs requires a flexible operation of the power plants, therefore their actual operating level is usually set below the full capacity level [13]. Until now, the ASs have been managed by a central authority (i.e., the Transmission System Operator-TSO-or the Independent System Operator-ISO) by means of control signals or behavioral arrangements defined in the grid codes or by means of bilateral agreements. In general, the flexibility guaranteed by the power plants is procured by the central authority by means of single-sided markets or by defining compulsory policies [13,[33][34][35]. However, the sustainability of the centralized provision of ASs is determined by the evolution of the power system. In fact, with the increasing penetration of Distributed Energy Sources (DERs) supplied by intermittent and unpredictable sources, the demand for ASs during power system operation is growing. On the other hand, the decommissioning of traditional power plants is reducing the share of available flexibility for the power system operation. This represents a common concern for system operators and government bodies, since this may lead to a reserve capacity shortage and, as a consequence, to an increase in the social cost related to AS provision [34]. In this scenario, novel approaches that may increase the share of providers for AS procurement are required [36].
For this reason, this paper proposes a local AS market for active power balancing in which the burden of reserve procurement is assigned to the network participants. Starting from the outcomes of the day-ahead energy market, the local AS market is defined as an intraday market in which the parties trade flexibility in close to real-time. The AS market participants that form the LEC are producers, consumers, and prosumers. In this local market, each participant is represented by an agent. The role of market agents can be assumed by an aggregator or by a single entity which can, alternatively, ask for flexibility in the form of reserve or offer balancing service to the other market participants. This choice is, in principle, free, and depends on its operating needs. The ask bids will likely be placed by non-controllable entities, whereas the offer bids will likely be placed by controllable entities. In this way, the proposed AS market will define master(ask)-slave(offer) couples, in which the slave entity will provide flexibility under the total control of its master agent. In this framework, the network balancing responsibility is shifted from the SO the local agents, which must now be seen as the Balancing Responsible Parties (BRPs).
From this perspective, the authors envisage the active participation of all the actors of the distribution sector in the whole power system operation, by opening the provision of ASs to the demand side (passive, active users and prosumers). Therefore, distributed control strategies make it possible to devise AS demand-side provision mechanisms that show a reliable response and shift the responsibility of the grid operation to the final users [35].

The CDA Market Framework
The CDA is an efficient market mechanism that solves a decentralized resource allocation problem characterized by multiple suppliers and consumers [29]. In the CDA, the market is cleared by continuously matching the offers submitted by the traders. In a free market in which participants act as rational selfish agents aimed by the maximization of their utility function, the CDA shows a stable behavior, since the transaction prices will converge to the competitive equilibrium price regardless of the particular bidding strategy adopted by each agent [29]. The reduced share of information required and the low computation and communication burden make the CDA suitable for being used for developing electronic trading platforms as well as in the electricity sector [29]. In this paper, a market mechanism that allows the P2P agreement between the local grid actors to be defined based on the CDA is introduced. The CDA mechanism is characterized by a flexible protocol that can be customized according to the peculiarity of the environment. Therefore, the CDA is suitable for building a customized local electricity market in line with the needs of participants and the network requirements. Since no intermediaries are required, the CDA mechanism is appealing for ruling the transactions within a P2P market.
The proposed local P2P AS market is described with the flowchart in Figure 2. Each session is performed for two independent sections: the CDA pool for the upward service (AS + market), and the CDA pool for the downward service (AS − market). The convention adopted in this paper for the sign of the service is established according to the grid point of view. Accordingly, the upward service AS + refers to the action which increases the share of active power injected in the network; conversely, the downward service AS − refers to the action that decreases the amount of active power injected in the grid.

Decentralized Market Clearing Process
The decentralized version of the proposed NCDA smart contract runs on Ethereum, the platform devised by Vitalik Buterin in [20]. This Blockchain as a Service (BaaS) platform is an improvement of the Blockchain paradigm introduced for the first time by Satoshi Nakamoto in his game-changing  The CDA protocol, defined for both pools, specifies the characteristics of bids, trading period, clearing rule, pricing rules, and the level of transparency about the status of the market. The bids, broadcasted to the community as shouts, are the means by which local market participants offer service or ask for service. Each shout is defined by a set of parameters: the BRP identifier; the shout timestamp; the shout type (ask or offer); the quantity (asked or offered); the price (for buying or for selling); the time in which the service will be provided. The service traded among the local market participants is assumed to be provided on a fixed-term basis, and the offers last for an arbitrary period ∆t, dependent on the system peculiarities and needs. In general, these markets show the ∆t ranging from one hour to several hours. The clearing rule is the set of procedures and criteria that define the matching between demand and offer. In general, the clearing rule for the CDA is defined as "price first and time first", i.e., the asking shouts and the offering shouts are first matched according to the criterion which concerns the prices asked and offered, and then, if two shouts are equivalent, the oldest is accepted. The clearing criteria based on the price requires that the asking and offering shouts received by auction platform are continuously sorted into two different books. The offering shouts are ordered according to price from the lowest to the highest (ascending order), while the asking shouts are sorted from the highest price to the lowest (descending order). The outstanding offer represents the current lowest uncleared offer of service in the market, while the outstanding ask is the current highest uncleared request for service in the market. Once the shouts are sorted in the books, the outstanding ask is defined, and the set of suitable offers is identified. This set contains all the offers for service whose price is lower than the willingness to pay of the outstanding ask. Therefore, a potential revenue exists for the service offerors.
According to the price first criterion, the outstanding ask is first matched with the outstanding offer. The transaction round ends if the quantity offered by the sellers satisfies the quantity asked by the buyer. The price paid by the buyer is defined by the pricing rule adopted in the CDA framework. Otherwise, if the amount asked by the buyer is not satisfied by the outstanding seller, the second suitable offer in the list is then considered and matched with the outstanding buyer. This matching process continues until the quantity asked by the buyer is completely satisfied and the round of transaction ends successfully. Conversely, if there are not enough suitable offers for covering the quantity required by the buyer, the round of transaction ends with residual unsatisfied demand. In this case, the residual unsatisfied demand may be involved in a further round of transactions with new offers submitted in the meantime; this scenario is possible if the related set of suitable offers is revealed not to be empty. At the end of the trading period, the market window closes; all unsatisfied demands have to be managed by exploiting external resources. Once a round of transaction is closed, the cleared shouts are removed from the books, and a new round starts by identifying the novel outstanding ask. In any case, for each round, the market clearing process is performed in a single iteration, spanning at most all the A × O ask-offer couples, where A is the total number of ask bids, and O is the total number of offer bids. Each match between the buyer and a different seller defines a P2P transaction characterised by the quantity traded and the related price. The matching then bonds the offering party with the asking one, forcing the latter to provide the matched flexibility, if and when requested by the asking party. In this way, the model is able to couple the peers in a master-slave fashion in the AS balancing market in order to ensure frequency stability. In fact, the "slave" peer is forced to follow the deviations from the day ahead profile of the agreed master node, in order to ensure the net neutrality of the peers couple. To illustrate, the case of the producer (asker)-consumer (offeror) couple is considered. Once the P2P agreement has been cleared in the AS market, when the active power injection of the producer decreases (increases), it sends a signal to its matched offeror, specifying the level of consumption it has to decrease (increase) in order to compensate the couple balance, restoring the overall exchanged level defined in the day-ahead energy market.
Among the different pricing rules, in this paper the clearing price of each P2P transaction is calculated as the average of the price offered by the buyer and the price asked by the seller of the service [36]. However, the classic price first time first CDA forms producer/consumer couples without any consideration to the impact on network operation. Two novel matching criteria are proposed in this paper to carry out appropriate consideration of network constraints and limits in CDA. The first option is to apply the Optimal Continuous Double Auction (OCDA) that modifies the classic CDA mechanism by adding a sorting criterion for the suitable offers which is based on the output of an Optimal Power Flow (OPF) calculation. Once the set of suitable offers is found, the optimal dispatch of the flexible resources is obtained with the OPF. The OPF objective function used in the paper is the cost of power losses in the considered grid; the control variables are the offers of power from active consumers accepted by CDA; the constraints are the PF equations, the magnitude of nodal voltages and the apparent power capacity of lines. Therefore, the P2P transactions between the buyer and seller must comply with results obtained by the OPF. The OCDA gives network valid solutions, coming from the constrained optimization performed in the OPF. The second option is to use the Network-based Continuous Double Auction (NCDA), which improves the CDA mechanism by modifying its matching process [29] with the inclusion of a network topology. The matching process of the classic CDA is changed by adding a sorting criterion that considers the topology of the network and the relative position between the buyer and the sellers. With the aim of minimizing the impact on the network of the service exchange, the matching process aims at pairing the closest actors. Once a set of suitable offers is found, the distance between each suitable seller and the buyer is calculated by a smart contract in the Blockchain market platform. Then, among the possible valid ask-offer pairs, matches are assigned to the offers that minimize network distances.
The SO performs a silent check on the identified market solution looking at the reliability, fairness, and sustainability of the proposed market output. The SO can override unwanted solutions if they are susceptible to creating contingencies or operating issues on the network. Finally, the SO can purchase external flexibility services if the services provided by the local AS market are not sufficient.

Decentralized Market Clearing Process
The decentralized version of the proposed NCDA smart contract runs on Ethereum, the platform devised by Vitalik Buterin in [20]. This Blockchain as a Service (BaaS) platform is an improvement of the Blockchain paradigm introduced for the first time by Satoshi Nakamoto in his game-changing Bitcoin white paper [19]. The platform is a Distributed Virtual Machine (DVM) capable of storing information in an immutable way, as well as running computer code previously stored in its distributed storage.
This allows the definition of immutable SCs, third party-less computer protocols, making it possible to perform operations on a set of information provided by the parties. This totally new paradigm allows the decentralizing of various operations by avoiding centric organizations. In particular, this paper introduces a novel automatic and decentralized, SC-based implementation of the NCDA described in Section 2.2 and depicted in Figure 1.
The procedure for solving the market through smart contracts brings various advantages. The first one is the counterparty-less approach, which avoids the necessity of a physical authority providing a trustless platform for all the parties. This, in turn, avoids human error-prone intervention in the market and ensures fairness in the applied market algorithms. Secondly, the cryptographically distributed architecture of the Ethereum platform makes it virtually reachable by every internet-connected computer in the world, decreasing cybersecurity risk that could lead to a service interruption/failure due to cyber-attacks. Finally, since each transaction is cryptographically signed by the parties, each operation is fully traceable and auditable. For this reason, different nations around the world are starting to provide legal validity for the transactions operated by means of smart contracts. This legal validity, if successfully exploited, can make the smart contract outcomes legally binding for the participants.
However, the trustless distributed procedure makes every transaction performed through the platform extremely expensive. In fact, each transaction writes operation and code solving procedure should be in turn be executed by each of the validating nodes of the network, making it costly from both energy and computational time perspectives. For this reason, the high computational costs impose a reduction of the computational burden. Hence, it is almost impossible, or at least economically unfeasible, to perform complex calculations like OPFs on this type of platform. To avoid this limitation, all the market procedures performed in this paper were made by means of the newly proposed NCDA, which is deterministic and not computationally intensive. This procedure can be run by the BRPs by simply connecting to the Ethereum P2P network in order to submit the cryptographically signed offers. This connection can be made by every electronical device with internet connection capability.
The BRPs participate in the decentralized NCDA with their smart meters, which track their power exchanges and communicate with the Blockchain platform. According to the measured active power exchange of the parties involved in the P2P transaction, the NCDA smart contract is executed and the transaction written in the distributed ledger of the Blockchain. During the service time, it is expected that the BRP who sold the service will adapt its active power exchange according to the imbalance caused by the buyer user, by the installation of a P2P master-slave agreement defined by the NCDA market clearing. Once the balancing service has been provided, the seller receives a payment proportional to the service provided plus a fixed fee related to the reserve capacity provision. If the imbalance produced by the buyer exceeds the quantity that has been traded in the CDA AS market, the backup service is provided by the external power system, the SO will charge an extra fee to the buyer for covering the extra expenses caused.
The proposed decentralized AS smart contract works as a VDMA. The VDMA mediates among the network parties by defining the P2P offer-ask couples as the output of the decentralized AS market procedure. The AS market clearing is based on the available input information regarding the network state and topology and the BRPs shouts. These inputs must be kept updated by the respective responsible parties.
The SO is responsible of network operation and updates the state of the network stored in the ledger every time a change of topology occurs. The SO is also in charge of the operation and maintenance of the market platform. The related operational expenditure is charged to the LEC participants by means of service fees. Moreover, the BRPs are responsible for the formation and update of the ask and bid pools.

Case Study: Power System and Scenarios
In this paper, the CDA is used to create a local AS market within a Medium Voltage (MV) power distribution network considering the network developed as a European benchmark by the CIGRE Task Force (Figure 3), which devised and proposed a set of benchmark networks specifically designed for the study of the efficient use of DERs [31].
The network model is characterized by a radial topology formed by two feeders, each of which is fed by a 110/20 kV transformer. The network is composed by 15 nodes which are interconnected through both underground and overhead lines. The switches S1, S2, and S3 are normally open. At each bus of the network, a load or a generator fed by RES is connected.
In Table 1, details on loads and generators connected to the distribution network are provided. It has been assumed that the MV network is managed in a decentralized fashion with balance issues solved locally as much as possible. The users connected to the MV nodes can be generators, consumers, prosumers, and controllable LV network portions (e.g., controllable entities like MGs or smaller LECs). Each node corresponds to a market participant. The LV customers participate on the local AS market by means of an aggregator which offers the flexibility of the controlled portfolio in the local market. A model of the process is depicted in Figure 4. Task Force (Figure 3), which devised and proposed a set of benchmark networks specifically designed for the study of the efficient use of DERs [31].
The network model is characterized by a radial topology formed by two feeders, each of which is fed by a 110/20 kV transformer. The network is composed by 15 nodes which are interconnected through both underground and overhead lines. The switches S1, S2, and S3 are normally open. At each bus of the network, a load or a generator fed by RES is connected.
In Table 1, details on loads and generators connected to the distribution network are provided.    It has been assumed that the MV network is managed in a decentralized fashion with balance issues solved locally as much as possible. The users connected to the MV nodes can be generators, consumers, prosumers, and controllable LV network portions (e.g., controllable entities like MGs or smaller LECs). Each node corresponds to a market participant. The LV customers participate on the local AS market by means of an aggregator which offers the flexibility of the controlled portfolio in the local market. A model of the process is depicted in Figure 4. The case study makes it possible to evaluate the three market models by simulating the same distribution system in a large set of random scenarios. Starting from the initial set-point, a set of random service asks and offers are generated for each node according to the market roles. The simulation produces different market clearing points with CDA, OCDA and NCDA for comparison. The flowchart of the process is depicted in Figure 5. The different market conditions were generated by simulating the placement of random offers by the market operators, according to the following rules: • each generator g places an offer shout ( , ) with a probability of one half, where is the energy which should be reserved and is its price. is randomly generated from a normal The case study makes it possible to evaluate the three market models by simulating the same distribution system in a large set of random scenarios. Starting from the initial set-point, a set of random service asks and offers are generated for each node according to the market roles. The simulation produces N different market clearing points with CDA, OCDA and NCDA for comparison. The flowchart of the process is depicted in Figure 5. The N different market conditions were generated by simulating the placement of random offers by the market operators, according to the following rules: • each generator g places an offer shout E g , p g with a probability of one half, where E g is the energy which should be reserved and p g is its price. E g is randomly generated from a normal distribution with average value µ = P * ·∆t and standard deviation σ = s·P * g . P * g is the expected active power production from the generator g, ∆t is the time interval covered by the market session, and s is a parameter which sets the width of the random distribution [37,38]. p g is also randomly generated from a normal distribution, with mean value µ = 0.35 €/kWh and standard deviation σ = 0.025 €/kWh. These prices approximately reproduce the reserve formation prices in the Spanish ancillary service market [39].
• each load places a bid (E l , p l ) by following the same pattern and parameters of the generators.
The CDA, OCDA and NCDA were simulated by allowing a trading period with steps of ∆t = 1 h, and over N = 100 different market realizations for each value of s = (0.02, 0.05, 0.07, 0.1, 0.15).
The results of the CDA, OCDA and NCDA described in Section 2.1 were compared in terms of network constraint matching, line loading, and overall system losses. Then, AC Power Flow was performed on the obtained market outcomes in order to identify the impact of the retrieved market solutions on the chosen network operative parameters. Without loss of generality, the PandaPower library was used [40], but similar results can be obtained with other PF software. Starting from the results of each PF, the overall system constraints matching the system losses L, the overall line load and the mean and standard deviation of the absolute value of the nodes voltage were calculated for each value of s and for each market case.

Case Study: Computational Complexity of P2P Transactions
To provide an evaluation of the costs related to the implementation of the distributed market proposed in this paper, the smart contract has been run in a test network, which evaluates the computational complexity of each transaction that is measured using the "Gas" measurement unit. In this way, the amount of "Gas" needed for performing each given instruction in Ethereum can be calculated. Every write and execution instruction in Ethereum consumes "Gas", which has to be paid to the network validators for performing the requested operations. In particular, each unit of consumed "Gas" can be paid in "eth", the Ethereum embedded cryptocurrency. The fee to be paid for each unit of "Gas" is decided by the transaction submitter and, as a general rule, the higher the fee is, the faster the operation execution. In this paper, the daily average costs related to the smart contracts are given on the basis of the "Gas" cost of each operation, projected over one day. To calculate these costs, market rounds are simulated, and the gas costs of each phase are saved for each round. In each round, on average, a fraction of operators place a bid. Then, the "Gas" costs of the offer placements and of the market solving are saved separately. The value of transactions, € , is

Case Study: Computational Complexity of P2P Transactions
To provide an evaluation of the costs related to the implementation of the distributed market proposed in this paper, the smart contract has been run in a test network, which evaluates the computational complexity of each transaction that is measured using the "Gas" measurement unit. In this way, the amount of "Gas" needed for performing each given instruction in Ethereum can be calculated. Every write and execution instruction in Ethereum consumes "Gas", which has to be paid to the network validators for performing the requested operations. In particular, each unit of consumed "Gas" can be paid in "eth", the Ethereum embedded cryptocurrency. The fee to be paid for each unit of "Gas" is decided by the transaction submitter and, as a general rule, the higher the fee is, the faster the operation execution. In this paper, the daily average costs related to the smart contracts are given on the basis of the "Gas" cost of each operation, projected over one day. To calculate these costs, n market rounds are simulated, and the gas costs G of each phase are saved for each round. In each round, on average, a fraction f of operators place a bid. Then, the "Gas" costs of the offer placements G o and of the market solving G m are saved separately. The value of transactions, C € , is calculated by Equation (1), in which "Gas" costs are multiplied by a daily average eth fee F, and multiplied again by the conversion rate between eth and €, H € .
In this paper, it was assumed that n = 300, f = 0.5, F = 3.2·10 −9 eth. The exchange rate between € and eth was set to 273.90 €/eth, which was the exchange rate on 25 June 2019.
To provide an analysis of the evolution of the decentralized market running costs for networks of different sizes of the one used as a case study, the same analysis was performed on random tree-type networks with numbers of nodes of 5, 10, 20 and 50.

Technical Validation of the Double Auction Model
The CDA, OCDA and NCDA were simulated with the exemplary network described above. Figure 6 shows the ratio of random market solutions leading to solutions that comply with all network constraints with the CDA, OCDA and NCDA as a function of network load and generation variability. In this way, the resilience of the model for increasing node volatility (which indirectly implies a forecast error on smaller time scales) was tested. As the NCDA shows, on average, around a 95% probability of meeting the network constraints, solutions fall in the 90-100% range, depending on the size of the applied variability. Conversely, the CDA shows poor performance in terms of network constraint compliance. The solution of the market found by the CBA is technically feasible with an average in around the 70-85% probability range. Corrective measures are required to be undertaken by the SO to solve the network constraints violation.  (1), in which "Gas" costs are multiplied by a daily average eth fee , and multiplied again by the conversion rate between eth and €, € .
In this paper, it was assumed that = 300 , = 0.5, = 3.2 • 10 ℎ . The exchange rate between € and eth was set to 273.90 €/eth, which was the exchange rate on 25 June 2019.
To provide an analysis of the evolution of the decentralized market running costs for networks of different sizes of the one used as a case study, the same analysis was performed on random treetype networks with numbers of nodes of 5, 10, 20 and 50.

Technical Validation of the Double Auction Model
The CDA, OCDA and NCDA were simulated with the exemplary network described above. Figure 6 shows the ratio of random market solutions leading to solutions that comply with all network constraints with the CDA, OCDA and NCDA as a function of network load and generation variability. In this way, the resilience of the model for increasing node volatility (which indirectly implies a forecast error on smaller time scales) was tested. As the NCDA shows, on average, around a 95% probability of meeting the network constraints, solutions fall in the 90-100% range, depending on the size of the applied variability. Conversely, the CDA shows poor performance in terms of network constraint compliance. The solution of the market found by the CBA is technically feasible with an average in around the 70-85% probability range. Corrective measures are required to be undertaken by the SO to solve the network constraints violation.     (Figure 7c,d,  respectively). In all cases, the NCDA methodology shows the ability to find better quality solutions than both the classic CDA and the OCDA.

Economical Evaluation
In this section, the economic estimation of the running costs of the proposed autonomous NCDA market is discussed and analyzed. Two main sources of costs are considered. The cost for the BRPs for keeping the offer and ask pools updated with digitally signed shouts, and the cost for the SO for ensuring the AS market execution. These costs have been extensively analyzed with the methodology described in Section 2.5. The results regarding the costs occurred for placing the offers and solving the market are shown in Figure 8.
The daily cost that each BRP must sustain for updating the shouts pool show small variability, with an average daily cost of 2.3 € per day, yielding a single shout placement cost of approximatively 0.10 €. Figure 8b provides the distribution of the daily market solving costs which has to be paid by the SO to the validation nodes of the Ethereum platform. This cost is more broadly distributed, since the market solution includes more random variables that can increase or decrease the computational resources needed for the definition of a matching solution (e.g., number of offers, matching complexity and number of final matches). However, the average daily market costs are around 6.5 €/day.
The daily total cost of the market is given in Figure 9. In this figure, the daily costs sustained by these BRPs and the daily costs sustained by the SO for running the market solving function are summed. The result is the total daily cost for the system, which for the presented case study is approximatively 23 €/day. Finally, Figure 10 shows the daily costs as a function of the number of players involved, and shows an almost linear behavior. This finding is consistent with the simple writing process performed on the ledger by the offer placement function, since each shout consumes almost the same amount of "Gas" and the number of average shouts increases with the number of market participants. On the other hand, the market solving function shows a more than linear cost increase, which is due to the quadratic computational complexity for matching offer and ask sets. The evaluation of the daily cost

Economical Evaluation
In this section, the economic estimation of the running costs of the proposed autonomous NCDA market is discussed and analyzed. Two main sources of costs are considered. The cost for the BRPs for keeping the offer and ask pools updated with digitally signed shouts, and the cost for the SO for ensuring the AS market execution. These costs have been extensively analyzed with the methodology described in Section 2.5. The results regarding the costs occurred for placing the offers and solving the market are shown in Figure 8. trend was limited to 50 nodes, which was considered a realistic scenario for an MV distribution network managed as an LEC.  The daily cost that each BRP must sustain for updating the shouts pool show small variability, with an average daily cost of 2.3 € per day, yielding a single shout placement cost of approximatively 0.10 €. Figure 8b provides the distribution of the daily market solving costs which has to be paid by the SO to the validation nodes of the Ethereum platform. This cost is more broadly distributed, since the market solution includes more random variables that can increase or decrease the computational resources needed for the definition of a matching solution (e.g., number of offers, matching complexity and number of final matches). However, the average daily market costs are around 6.5 €/day.
The daily total cost of the market is given in Figure 9. In this figure, the daily costs sustained by these BRPs and the daily costs sustained by the SO for running the market solving function are summed. The result is the total daily cost for the system, which for the presented case study is approximatively 23 €/day. Finally, Figure 10 shows the daily costs as a function of the number of players involved, and shows an almost linear behavior. This finding is consistent with the simple writing process performed on the ledger by the offer placement function, since each shout consumes almost the same amount of "Gas" and the number of average shouts increases with the number of market participants. On the other hand, the market solving function shows a more than linear cost increase, which is due to the quadratic computational complexity for matching offer and ask sets. The evaluation of the daily cost trend was limited to 50 nodes, which was considered a realistic scenario for an MV distribution network managed as an LEC. trend was limited to 50 nodes, which was considered a realistic scenario for an MV distribution network managed as an LEC.

Discussion
Results show that a decentralized P2P AS market can be automatized. The market clearing process is based on the VDMA which runs on the Ethereum platform, as well as SC. Since Ethereum is a BaaS platform, fees have to be paid for performing computation and writing on its distributed ledger. Given the expensive computational and writing fees of the platform, a NCDA model was implemented instead of computational demanding OPF-based market mechanisms. The autonomous and distributed P2P AS market implementation is autonomously executed, fully transparent, and free from human intervention. The proposed model was extensively tested from both a technical and economic perspective. The technical validation expressed satisfactory results for realistic fluctuations in power generation and consumption, making it possible to run the smart contract in a silent check SO supervision. The chosen extent of the node fluctuations is assumed to represent the extent of the possible error of the current available technologies for forecasting generation and load profiles. This makes possible a fully autonomous and distributed ancillary service market procedure, which could in turn pave the way to a full automatized management of services.
The costs related to the use of the decentralized smart contract have been evaluated to understand the feasibility of the proposed approach. Results show a cost of approximately 0.10 € per submitted bid, independently of the exchanged energy and price, with very little variability. This result is a double-edged sword. A 0.10 € fee is small for high-volume operators that move high amounts of energy, but this is a high fee for small operators, since it is comparable to or higher than the value of each transaction. For this reason, the usage of such a decentralized approach is recommended for medium-and large-sized networks with a large amount of economically significant transactions, for which the estimated running fees are almost negligible. From this perspective, aggregative BRPs are crucial to small operators, since costs can be shared by a multitude of players. In any case, it is important to note that technological improvements are under development for the Ethereum (and similar) platforms that aim to drastically reduce the operation fees. Under these conditions, it is possible to estimate that reducing the cost of a single shout placement to a cost of 0.01 € will require a reduction in Blockchain platform fees of at least 90%.
By considering the number of users of the exemplary networks, the burden for the SO in running the smart contract is estimated to be less than 10 € per day. Unfortunately, it is hard to perform a comparison between these costs and the running costs of a human-based centralized market

Discussion
Results show that a decentralized P2P AS market can be automatized. The market clearing process is based on the VDMA which runs on the Ethereum platform, as well as SC. Since Ethereum is a BaaS platform, fees have to be paid for performing computation and writing on its distributed ledger. Given the expensive computational and writing fees of the platform, a NCDA model was implemented instead of computational demanding OPF-based market mechanisms. The autonomous and distributed P2P AS market implementation is autonomously executed, fully transparent, and free from human intervention. The proposed model was extensively tested from both a technical and economic perspective. The technical validation expressed satisfactory results for realistic fluctuations in power generation and consumption, making it possible to run the smart contract in a silent check SO supervision. The chosen extent of the node fluctuations is assumed to represent the extent of the possible error of the current available technologies for forecasting generation and load profiles. This makes possible a fully autonomous and distributed ancillary service market procedure, which could in turn pave the way to a full automatized management of services.
The costs related to the use of the decentralized smart contract have been evaluated to understand the feasibility of the proposed approach. Results show a cost of approximately 0.10 € per submitted bid, independently of the exchanged energy and price, with very little variability. This result is a double-edged sword. A 0.10 € fee is small for high-volume operators that move high amounts of energy, but this is a high fee for small operators, since it is comparable to or higher than the value of each transaction. For this reason, the usage of such a decentralized approach is recommended for mediumand large-sized networks with a large amount of economically significant transactions, for which the estimated running fees are almost negligible. From this perspective, aggregative BRPs are crucial to small operators, since costs can be shared by a multitude of players. In any case, it is important to note that technological improvements are under development for the Ethereum (and similar) platforms that aim to drastically reduce the operation fees. Under these conditions, it is possible to estimate that reducing the cost of a single shout placement to a cost of 0.01 € will require a reduction in Blockchain platform fees of at least 90%.
By considering the number of users of the exemplary networks, the burden for the SO in running the smart contract is estimated to be less than 10 € per day. Unfortunately, it is hard to perform a comparison between these costs and the running costs of a human-based centralized market authority, since the existing Market Authorities operate on networks of a much bigger size (mostly on a transmission level). The need for local markets at a distribution level is still debated, and several architectures have been proposed, but few examples exist in which data on costs and different market applications are gathered and compared. In any case the main benefit of the proposed market structure is that it can be realized without any new infrastructure, since only an internet connection and smart meters are necessary. In addition to the operational costs, which are difficult to compare with centralized systems, a platform that is intrinsically protected against cyberattacks and allows P2P transactions in confined portions of the power systems without capital expenditures is the real value of the proposed architecture.
Finally, in order to test the proposed method for increased network sizes, the daily market running costs have been estimated also for AS Markets including up to 50 users/nodes. The results show that the market costs increase quadratically, at most, with the number of market participants, but, in any case, remain low for bigger networks.

Conclusions
This paper proposes an autonomous and decentralized version of the Continuous Double Auction-based Ancillary Service Market based on the newly emerging Distributed Ledger technologies for applications in local energy communities.
The proposed NCDA framework makes it possible to define the offer-ask couples, and thus solves the problem of defining a P2P market mechanism. Moreover, the novel NCDA embeds the network analysis within the market clearing process. Thus, the probability of obtaining a market outputs which comply with the network constraint is increased. By comparison to the classic CDA, the overall cost related to the management of contingencies can be reduced, since the exploitation of the corrective measures becomes exceptional.
The simulations show that the proposed NCDA approach can, in principle, run in a fully autonomous, human-less, and easy-to-access platform that ensures the legal validity of the performed transactions without losing the link with the physics of power delivery. The low computational burden of the NCDA algorithm makes it possible to embed the matching process in the smart contract-based Blockchain platform. The results obtained by exploiting the proposed NCDA algorithm are comparable to the more complex OPF-based CDA mechanism. The proposed NCDA can be adapted for many different applications since the roles of the participants and the clearing mechanism have a high level of abstraction. Therefore, it can be applied to any electric local market once the roles are assigned to the participants.
The extensive analysis of the running costs of the platform for the typical cases of interest showed that the entire process can be run with limited costs. Future studies will focus on which market features necessitate of high secure, immutable and certified transactions (thus needing on-chain processes to work), and which of them has lower safety requirements (allowing off-chain processes), identifying in this way a combination of services able to further reduce the decentralized AS costs. Additionally, with the aim of also defining and evaluating the effectiveness of local markets with respect to energy and other ASs, future efforts will also focus on simplifying the network analysis (e.g., OPF) to be embedded in a Blockchain-based market mechanism.