Credible Peer-to-Peer Trading with Double-Layer Energy Blockchain Network in Distributed Electricity Markets

: Blockchain-based peer-to-peer (P2P) energy trading is one of the most viable solutions to incentivize prosumers in distributed electricity markets. However, P2P energy trading through an open-end blockchain network is not conducive to mutual credit and the privacy protection of stakeholders. Therefore, improving the credibility of P2P energy trading is an urgent problem for distributed electricity markets. In this paper, a novel double-layer energy blockchain network is proposed that stores private trading data separately from publicly available information. This blockchain network is based on optimized cross-chain interoperability technology and fully considers the special attributes of energy trading. Firstly, an optimized ring mapping encryption algorithm is designed to resist malicious nodes. Secondly, a consensus veriﬁcation subgroup is built according to contract performance, consensus participation and trading enthusiasm. This subgroup veriﬁes the consensus information through the credit-threshold digital signature. Thirdly, an energy trading model is embedded in the blockchain network, featuring dynamic bidding and credit incentives. Finally, the Erenhot distributed electricity market in China is utilized for example analysis, which demonstrates the proposed method could improve the credibility of P2P trading and realize effective supervision.


Introduction
The global electricity market is undergoing drastic changes, and consumers are increasingly demanding renewable resources to reduce greenhouse gas emissions [1]. According to the commitment made by the Chinese government at the 75th UN General Assembly, China will strive to ensure their carbon dioxide emissions reach their peak by 2030 and achieve carbon neutrality by 2060 [2]. This development strategy would increase the share and utilization efficiency of renewable energy in energy production. It is predicted that by 2030, China's total installed capacity of wind power and solar power will be more than double to 1.2 billion kW [3]. There is an impact on the safe operation of the grid, due to the intermittence and uncertainty of renewable energy power generation [4]. Moreover, a large number of renewable energy infrastructures has brought about a surplus of power supply and decline in the utilization rate of base stations, which need to be solved urgently [5,6].
In general, power grids are based on a centralized single current system, where power flows from large utility generators to user loads [7]. This kind of energy trading mode is not conducive to solving the problems caused by the large-scale integration of renewable energy [8,9]. In order to allow renewable energy and small-scale energy prosumers to participate more actively in the distributed electricity market, P2P energy trading has gradually become the next-generation energy management technology for smart grids [10].
(1) It is difficult to authenticate participants in plug-and-play energy blockchain networks.
Some nodes could re-register their IDs (Identity Documents) and rejoin the system after performing malicious behaviors [23]. The distributed data structure also exposes the privacy of users to the risk of leakage and reduces enthusiasm to participate [24]. (2) The credibility of the distributed electricity market is not guaranteed. In two-way auctions and matching transactions, participants with good credit behavior are not encouraged. Then, participants with malicious behavior also have no clear punishment measures. Ignoring rewards and penalties for credible behavior is not conducive to the large-scale implementation of blockchain-based P2P energy trading. (3) Ineffective supervision is also an urgent problem in the current P2P energy trading market. Some energy trading based on consortium blockchain isolates trading information from the outside, and leads to value islands [25]. Then, in the absence of supervision, energy sellers may underreport electricity to evade taxes, and industrial users may underreport electricity to falsify energy consumption targets.
To address these gaps, this paper proposes a double-layer energy blockchain network for credible P2P trading. The novelty and contributions of this article are as follows: (1) A double-layer energy blockchain network is proposed based on the cross-chain interoperability and notary scheme. This blockchain network that includes several Sub Chains and a Main Chain can ensure the effective separation and combination of different trading functions. (2) The ring mapping identity authentication and credit-threshold notary schemes are designed for P2P energy trading. The ring mapping gives each participant an accurate, traceable identity. In addition, the nodes with higher credit evaluation results are more credible as notaries to verify the system information.
(3) A dynamic credit incentive trading model is embedded into the double-layer blockchain network. Different from previous studies, this two-way auction rewards or punishes participants according to their behaviors. This incentive model guarantees the rights and economic profits of credible prosumers. (4) A real case of Erenhot, China is simulated and analyzed to prove that the presented mode provides a reference for the effective implementation of credible P2P energy trading. The real case scenario is more convincing to demonstrate the credibility and value of this work.
Section 2 in this paper first presents a comprehensive literature review of state-ofthe-art research on the P2P energy trading and blockchain-based energy management. Section 3 explains the proposed double-layer energy blockchain network and Section 4 introduces the energy trading model for distributed electricity markets. The case study and results are presented in Section 5. Conclusions are drawn in Section 6.

Literature Review
This section reviews and comments on existing academic studies on P2P energy trading and blockchain-based energy management.

Peer-to-Peer Energy Trading
P2P trading has emerged as a next-generation energy management technique for the smart grid that can enable the owners of small-scale energy producers or consumers-also known as prosumers-to actively participate in the distributed electricity market. With the prosumers able to trade energy within the neighborhood, it allows local funds to remain within the local electricity markets [26]. In this trading method, multiple prosumers in the system are connected to the distribution network. The combined load is subject to random coincidence of the individual loads, which averages stochastic fluctuations [27]. This means that the surplus electric energy in the area can be used by other distributed energy users [28].
The P2P trading is likely to bring higher economic benefits to consumers as well as provide a better distributed electricity and energy balance for the electricity system [29]. Based on a reverse auction model, Cintuglu et al. [30] created a competitive market environment for distributed energy suppliers in the microgrid. In this model, due to the competitive behavior of all energy suppliers, users can purchase energy at a lower transaction price. A multi-agent system was designed and implemented to verify the proposed method in the smart grid test system of Florida International University. Shamsi et al. [31] also proposed a distributed electricity market which targeted a grid-connected community microgrid. In this market, each prosumer is capable of trading electricity with others based on P2P energy trading. Paola et al. [32] proposed price-based schemes for the distributed coordination of flexible demand within a game theoretical framework. Even though this work did not consider distributed generation or energy storage systems, it also showed the advantages of P2P trading in the energy market.
Some scholars have carried out research on the P2P trading mechanism and bidding strategy to improve energy interaction efficiency. Zhou et al. [33] developed a systematic index system to evaluate the performance of various P2P energy-sharing mechanisms based on a multiagent-based simulation framework. The simulation framework is composed of three types of agents and three corresponding models. The proposed methods were applied to simulate and evaluate some existing P2P energy-sharing mechanisms for residential customers in current and future scenarios of Great Britain. This work assumes that all agents make decisions with perfect predictions about the future, and does not take into account mistrust between individuals. Long et al. [34] proposed a two-stage aggregated control to realize P2P energy trading in community microgrids, where only the measurements at the point of common coupling and one-way communication are required. This method has been applied to the microgrid of residential districts containing photovoltaic cell systems. The results show that compared with traditional P2G energy transaction, the P2P mode can reduce the energy cost of the community by 30%. Nguyen et al. [35] proposed an optimization model to maximize the economic benefits for rooftop PV-battery-distributed generation in a P2P energy trading environment. The goal of the proposed model was to investigate the feasibility of such renewable sources participating in P2P energy trading by examining the economic benefits. Moreover, the feasibility of the model was verified through simulation in a local community with 500 households. El-Baz et al. [36] described a novel discrete timely double-sided auction model that facilitates P2P energy trading between prosumers in near real-time and forward markets. The models of the integrated devices are based on either field tests or testbeds to ensure the accuracy of the integrated model. On the other hand, a probabilistic PV prediction system is integrated into the market model to show the mechanism of PV energy trading, given its generation uncertainty. E Lucchi et al. [37] provided an inspiring view on the need for environmental, economic and cultural sustainability in the field of heritage renovation and preservation, and addresses the importance of being aware of eco-friendly techniques and policies in heritage preservation. This work has a very valuable guiding role for P2P energy trade between buildings in Europe. However, the P2P energy trading will face real-time price fluctuations, a dynamically adjusted power consumption plan and frequent electricity fee settlements [38]. There must be a distributed and dependable energy management platform to handle the flexible and complex trading mode [39].

Blockchain-Based Energy Management
Blockchain technology is a distributed framework and computing paradigm using blockchain data structures to verify and store data, distributed node consensus algorithms to generate and update data, cryptography to ensure the security of data transmission and access, and smart contracts which are composed of automated script codes to program and manipulate data [40]. This distributed data structure integrates the technical characteristics of decentralization, security, and trustworthiness, which is compatible with the P2P energy trading mode [41]. The blockchain-based energy management platform is expected to provide a robust, efficient, and low-cost system for P2P energy trading.
From electricity trading to the energy industry, as the most promising application in the context of blockchains, smart contracts have implemented machine to machine energy management in the industry 4.0 environment. Wu et al. [42] proposed a method based on blockchains to manage the demand and transaction of grids. It realized the independent maintenance and management of transaction information through smart contracts of blockchain technology. Tsao et al. [43] proved that blockchain could reduce the default risk in distributed electricity markets and uncertainty on the energy demand side. Sikorski et al. [44] designed a novel trade on a blockchain including two power producers and one power consumer in the chemical industry background. This trading pattern uses electricity to exchange currency. Li et al. [45] also took advantage of blockchains and smart contracts, and designed a distributed renewable energy system with heterogeneous end-users. This system is aimed at energy demand-side management through P2P exchange of real-time energy information. Wang et al. [46] proposed an original bidding strategy for multi-energy trading based on blockchain network framework. This energy management mode ensures the theoretical model can be applied in practice, and facilitates the comprehensive utilization of renewable energy through free trading and real-time price. Hua et al. [47] proposed a novel blockchain-based P2P trading framework to trade energy and carbon allowance. The bidding/selling prices of prosumers can directly incentivize the reshaping of energy prosumers to achieve regional energy balance and carbon emissions mitigation. Zhang et al. [48] proposed a key management scheme for service providers and smart meters in smart grid systems. They introduced the concept of the blockchain to solve the centralization and data-tampering problems. Han et al. [49] presented a universal framework for a blockchain platform that enables P2P energy trading in the retail electricity market. This study adopted the double auction principle to enhance the vitality of the market. These research results expound the application value of blockchain technology in power systems from different angles.
With the increase in energy blockchain projects, the difficulty of data communication and value islands between blockchain networks have become open issues. Cross-chain interoperability technology is an important technical means for blockchains to realize interconnection and improve scalability [50]. Therefore, some scholars have begun to pay attention to the application of cross-chain technology in the field of energy, which could solve the problem of poor scalability and flexibility for existing energy blockchains. Pop et al. [51] proposed a technique for the tamper-evident registration of smart meters' energy data and associated energy transactions using digital fingerprinting, which allows the energy transaction to be linked hashed-back on-chain, while the sensors' data are stored off-chain. In the proposed architecture, the authors innovatively introduce cross-chain interaction into the energy scenario. In the current centralized IoT ecosystems, Firoozjaei et al. [52] proposed a hybrid blockchain with a subnetwork that aims to protect the privacy of users and provides a trusted workflow for billing and charging transactions. The information of users' P2P energy transactions in this work is anonymized by the bridge and no private information is leaked to the main power grid. He et al. [53] used a structure of the Main Chain plus a side chain to achieve combined distributed photovoltaic power generation market and the carbon market. Wang et al. [54] proposed a dynamic adaptive cross-chain trading mode for multi-microgrid joint operation. This work can ensure the adaptive consistency of cross-chain information without changing the existing blockchain architecture of each system. Recently, a number of individuals proposed ideas on the application of cross-chain in P2P energy trading-especially the double-layer blockchain structure-in order to build flexible trading systems. Some of the proposals present worthy ideas to be explored, yet almost all of them lack some elements to make a feasible and practical implementation. The most significant is the lack of research on highly credible and effective supervision for energy blockchains. This is also one of the main reasons for the lack of large-scale application in the P2P energy trading field.

Conclusions from the Literature Review and Objectives
To summarize, P2P energy trading can stimulate the vitality of the distributed electricity market, especially in the distributed renewable energy-rich areas or remote areas where the grid cannot be extended. There are many studies on blockchain-based two-way auctions in electricity trading. These approaches mainly focus on designing auction models and bidding strategies to increase the electricity market economy or renewable energy consumption. However, P2P energy trading based on blockchain technology has not been implemented on a large scale so far. One of the main reasons is that the existing research pays more attention to economic benefits and ignores the improvement of the credibility of transactions. It is embodied in the lack of several aspects, including the accurate identification of the participants, credibility evaluation and incentive, punishment for bad trading behavior, and a lack of effective supervision. Therefore, we focus on the credibility and effective supervision of the electricity market and propose a two-way auction mode considering credibility incentives/punishments.
On the other hand, the P2P trading method requires a more flexible and efficient energy management system, and the blockchain distributed network has become one of the options available. Then, P2P energy trading through a public blockchain is not conducive to mutual credit and the privacy protection of stakeholders, and trading through a consortium blockchain would form data islands which result in ineffective supervision. In this context, an energy blockchain network often fails to operate efficiently and leads to P2P energy trading not being widely used in practice.
To address existing technical deficiencies, a ring mapping algorithm is used to give each energy prosumer an exclusive identity entity which can optimize the notary scheme to effectively verify the energy system information. In addition, the credit incentive feature can further ensure the credibility of the distributed electricity market. The original double-layer blockchain network could pave the way for the implementation of P2P energy trading and blockchain-based energy management.

Double-Layer Energy Blockchain Network
This section describes the novel double-layer energy blockchain network in distributed electricity markets. We illustrate the system structure of the proposed blockchain network. Next, we describe the ring mapping identity authentication and credit-threshold notary scheme, which improve the credibility of P2P energy trading.

System Structure
A double-layer energy blockchain network for information interaction is built on the basis of complete power transmission and distribution lines. The bottom layer comprises a number of independent Sub Chains, and the upper layer is a Main Chain. Each Sub Chain carries out energy management on the distributed electricity market in the region, and has the features of identity authentication, energy trading and credit evaluation. Through the cross-chain interoperability mechanism, Sub Chains periodically send data that do not involve privacy to the Main Chain. These data are publicized across the network after being verified by the consensus nodes group. The system structure of a double-layer energy blockchain network is shown in Figure 1, and the pseudocode is shown in Figure 2.  Each Sub Chain is a typical point-to-point energy trading platform, which aims to provide a standardized matching transaction, automatic execution, and reputation calculation, etc. These functions are implemented through smart contracts, which are jointly formulated by all energy prosumers on the platform. In order to improve the efficiency and overall revenue of energy trading, this study uses a double auction mechanism and dynamic bidding strategy to conduct P2P trading. In time slot t, each participant can publish the trading demand of time slot t + 1 through its network node and upload information to the distributed Sub Chain. Trading requirements include buying/selling energy quantities, bidding prices, etc. The platform sorts the bidding information of the buyer and the seller respectively according to the expected price. When the buyer's highest bid is equal to or less than the seller's lowest bid, a transaction protocol is reached. In the matching process, the buyer's highest bidding price is matched with the seller's lowest bidding price, and the transaction price is the average of the bidding prices of both parties. This process continues until the buyer's highest bid is lower than the seller's lowest bid. Each participant dynamically adjusts the bidding strategy based on the real-time information and the bidding mechanism mentioned in Section 4.1. If prosumers fail to reach a deal, they adjust the bidding strategy according to the market information to reach a transaction protocol in the next auction. This mode effectively shortens the time of the matching process and improves platform operating efficiency.
The Sub Chain also calculates credibility and gives an incentive mechanism, which is introduced in Section 4.2. The trading data and credit value in each Sub Chain are regularly sent to notaries for cross-chain verification. When information is verified correctly, it is protected and stored in the Main Chain in the form of blocks by using the Secure Hash Algorithm SHA-256. This kind of cross-chain interoperation uses the notary scheme to complete the anchoring of information from the Sub Chain to the Main Chain. The information on the Main Chain cannot be tampered with and is visible to the entire network broadcast. Therefore, any node can check the credibility and transaction status of all energy prosumers. Moreover, the privacy of prosumers in the P2P energy trading platform is not exposed, such as equipment models, energy usage rules, sources of funds, and real-time power dispatch data. Based on the system structure, this study improves the credibility through two methods: the ring mapping identity authentication and credit-threshold notary scheme, which are illustrated in Sections 3.2 and 3.3, respectively. The operation process of the double-layer energy blockchain network is shown in Figure 3, and the corresponding pseudocode is shown in Figure 4.

Ring Mapping Identity Authentication
In 2001, Rivest, Shamir and Tauman proposed the concept of a ring signature. A ring signature is a simple group signature, which enables users to sign in a completely anonymous manner. The receiver of the message can only determine which group the signature comes from, not which user. Compared with previous group signatures, ring signatures no longer require the systematic establishment and revocation of administrators. Only the signer himself can recover the identity of the signer and realize the complete anonymity of the signer's identity.
Traditional authentication schemes tend to use a centralized approach, whereby a central node manages all businesses requiring authentication. However, centralization means network security risks, and there are also problems of efficiency and privacy disclosure. The distributed data structure and decentralizing verification method of blockchain bring new value to ring mapping identity authentication.
Ring mapping is a corresponding behavior, which mainly abstracts things in reality into a special entity and corresponds to a fixed-size virtual ring space [55]. This is in order to avoid incredible prosumers joining the Sub Chain though re-registering ID (identity document). The entity mapping makes these IDs unable to be tampered with, and constructs a set including four basic pieces of information: their geographic location, account balance, credit value, and attributes. Set i is shown in Equation (1).
where a i denotes the geographical location of node i, and it can be considered immutable because energy facilities are not readily removed. b i , c i , and d i , respectively, denote the account balance, credit value, and other attributes.  The Set i of every new node generates respective key pairs from the certification authority (CA), which obtains a valid public key signature and verifies consistency based on the RSA (Rivest-Shamir-Adleman) algorithm. Identity authentication is authenticated by the clockwise forward and backward nodes on the ring. The system calculates the corresponding hash value encrypted by the private key and sends the generated original signature and its own public key signature to the next ring node. The next ring node decrypts the signature with the sent public key to verify the consistency between the original signature and the target signature. Authentication is successful if the information is consistent, otherwise identity authentication fails. The ring mapping identity authentication diagram is shown in Figure 5. The CA is generally held by local energy authorities and high-credit node groups, and its public key and private key are, respectively, IPK = (E, N) and ISK = (D, N). The public and private keys of the user node are set to LPK = (E , N ) and LSK = (D , N ). The new node joins the blockchain network and needs to submit identity information Set i to CA for registration and obtain the corresponding key pair. CA equal to probability selects two very large prime number p and q , and the specific calculation formula is as follows: where E and D can generate random numbers between 1 and L, and obtain the public and private keys of ring nodes through verification, namely LPK = (E , N ) and LSK = (D , N ). CA randomly selects integer values n integer ∈ L n , and encrypts the public key of ring nodes with its private key to generate the digital signature Set L . The ring node can decrypt the public key signature to verify through the public key of CA. The result of decryption verification is n integer , and compares with n integer . If these are the same, ring nodes save the public key signature in the system. The process is shown in Equations (6) and (7).
According to the mapping space L n , the reference count of each ring node is initialized as n count . A new ring node appends the fill field pad to the end of message m to obtain the filled message m pad . The ring node runs the collision-resistant hash function SHA-256 on the m pad to generate the hash value H m of the message, and can be summarized as shown in Equation (8).
The ring node uses its own private key LSK = (D , N ) to encrypt the hash value H m to generate the original signature Set ori , which can be generally expressed as Equation (9). Next, the data of m pad , H m , and Set L are sent to the next valid node in the clockwise direction. This valid node uses the public key signature Set L of the current ring node to decrypt the original signature Set ori and output the target signature Set tar . The process can be summarized as shown in Equation (10). The new node is successful for identity authentication if the signature verification output value A{Set i } is 1.

Credit-Threshold Notary Scheme
The selection of notaries is the key to the cross-chain notary mechanism and one of the methods to solve the decentralization degree. In this study, nodes with high reputations are selected to form a node group. This node group is a notary, which verifies the effectiveness of cross-chain information interaction.
Firstly, the threshold setting can reduce the number of notary nodes and effectively improve the operation efficiency of cross-chain communication. In the process of information cross-chain communication, the number of nodes in the verification node group directly affects the system operating efficiency. This viewpoint has been explained in existing research results. Therefore, this study selects a small number of privileged nodes through the threshold to form a node group to verify the cross-chain information, which can improve the operation efficiency of the energy system.
Next, these privileged nodes are dynamically selected based on the trusted behavior of each node. This credit evaluation includes three aspects: contract performance, participation, and trading. It is different from PoW based on hashrate and PoS based on stock rights. The notary nodes selected in this study are based on the comprehensive evaluation of behaviors in P2P energy trading.
In addition, the current cross-chain notary scheme does not specify the selection of notaries, which is not conducive to the credibility of cross-chain data transmission. In view of the defects of the existing consensus mechanism and cross-chain interoperability, this study selects nodes with high credit for energy trading to form a node group as a verification nodes subgroup (VNS). The VNS conducts real-time verification of the P2P energy trading data in each Sub Chain, and acts as a cross-chain notary to verify the information transmitted to the Main Chain. The nodes whose credit evaluation exceeds the threshold can enter the VNS and verify the consensus information through the blockchain digital signature [56]. The threshold digital signature verification process is shown in Equations (12)- (16). CPK CPK v (ET, t 1 , n 1 ; · · · ; t m , n m ; t, n) = The selection of VNS is the key process in the credit-threshold notary scheme. In this study, the energy blockchain network selects the verification nodes according to the credit evaluation of each energy prosumer. This credit evaluation includes three aspects: contract performance, consensus participation and trading enthusiasm. Contract performance is a smart contract signed by both parties to the transaction. After the physical power transmission time expires, one of the parties fails to follow the contract content, causing the other party to suffer economic losses. Consensus participation means that in the consensus process, the nodes do not legally participate in the consensus process and carry out illegal signatures or malicious voting [57]. Trading enthusiasm can promote regional energy balance and stimulate the vitality of distributed electricity markets.
An energy buyer would purchase the power shortage from the grid when the power actually provided by the seller in a certain time slot is lower than that specified in the contract. It causes economic losses to these buyers, since the grid price is generally higher than the contract price. Moreover, if the buyer's actual power consumption is lower than the contract power consumption, the power provided by the seller cannot be fully utilized in this time slot, causing economic losses to the seller. Therefore, it would cause economic losses to the other party if the transaction protocol that is matched on the trading platform could not be fully implemented. Credit evaluation of contract performance can be described as Equations (17) and (18). It can be seen that the greater the gap between the quantity actually provided or used by prosumers and the contract, the more the credit value decreases.
C sell,con C buy,con j,t =    C buy,con The trading behavior of each prosumer needs to form a block through a consensus mechanism on the Sub Chain, and build a chain structure through the sequence of timestamps. Prosumers would sign the block header during the consensus process, which verifies the block header and voting. There are two behaviors for consensus participation of network nodes, which are goodwill voting and malicious voting. Goodwill voting means that the node verifies that the block header meets the difficulty of the system and signs it legally. Malicious voting means that the node signs on block headers that do not comply with regulations. At the same time, the last node ignores the illegal signature and packs transaction data and node signatures into the block and broadcasts it to the entire network. When other nodes verify the signature or the block header is incorrect, it is stipulated that all nodes that sign the block are maliciously voting. In the process of building blocks and system operation, the credit of each node participating in the consensus is evaluated, as indicated by Equation (19).
where α t and β t denote the vicious vote and the virtuous vote within t time slots. N indicates the total number of time slots experienced. λ is a penalty factor. If the value of λ is greater, the tolerance of the system to vicious voting behavior is lower. In general, the number of λ is between 1 to 5 [54]. According to contract performance and consensus participation, the credit evaluation of sellers or buyers can be summarized as shown in Equations (20) and (21).
C buy,basics j,t = C buy,con j,t ·C consensus j,t (21) where C sell,basics i,t and C buy,basics j,t denote the basics credit evaluation of a prosumer that does not consider the enthusiasm of nodes to participate in P2P energy trading. However, it would reduce the income of the distributed electricity market and the security of the blockchain network when prosumers are not motivated to participate in P2P energy trading. It is necessary to participate in block verification even if power sellers or buyers do not participate in the trading, since the more nodes participate in consensus verification and voting in the blockchain network, the stronger the security of the system. In order to ensure the activeness of participants, credit loss is introduced in the basic credit evaluation. As long as the node participates in the consensus or voting verification process of the blockchain, its credit value will not be reduced. The credit loss of sellers or buyers for participation enthusiasm can be calculated by Equations (22) and (23).
C buy j,t = C sell,basics where ∂ and ∂ , respectively, denote the penalty factor of electricity suppliers and users for not actively participating in market operating. In general, ∂ is bigger than ∂ because electricity suppliers make a profit directly from the market and they have more complete computing equipment. l indicates the number of time slots in continuous non-participation in the blockchain network operation.
A new node sets an initial credit value that joins the Sub Chain. After performing P2P trading and consensus verification t times, the node's credit value can be calculated according to the above formula. The credit value of these nodes changes dynamically with the increase in transaction rounds. The continuous behavior impropriety of a node results in a credit value of zero, and this node is removed from the Sub Chain. Nodes with low credit values are not allowed to join other Sub Chains to ensure the trustworthiness of the P2P trading system. Furthermore, the upper limit of node credit value is set to 100, which does not increase after reaching this value. Since the growth of credit values is nonlinear, the higher the credit value, the slower the growth rate. Therefore, there is no situation where the node's credit value is too high to affect the decentralization of the blockchain network.

Energy Trading Model
The distributed electricity market realizes the matching of electricity quantity and price between buyers and sellers through continuous double auction, and it carries out transaction settlements through blockchain technology. There are multiple distributed generations (DGs) and users in the electricity market. They submit quotations and transaction power to the double auction market in each transaction cycle, and the market automatically matches the quotations of both parties. In the matching process, the market continues to publish transaction information, including transaction prices, the current optimal selling price, the optimal buying price, etc. Participants who have not completed the matching adjust the quotation according to a certain bidding strategy, or else withdraw from the distributed electricity market and trade with the main grid directly. The electricity market and the main grid connected mode, can guarantee the electricity market clearing and energy conservation. The two parties that complete the matching transaction settle through the blockchain, and DGs transfer electricity quantity to the users that they trade through the blockchain, while the users transfer electricity purchase fees to the DGs that they trade through the blockchain. After the confirmation of each node in the whole network, it can be considered that the buyer and seller transactions are successful.
In this study, the energy trading model in the double-layer energy blockchain network includes two features, which are dynamic bidding and credit incentives. Energy prosumers actively adjust quotations to improve the economic profits. Credit incentives can guarantee the rights of credible prosumers in distributed electricity markets. This section describes the two trading features.

Dynamic Bidding Strategy
A bidding strategy is designed to dynamically adjust the bidding price according to the real-time information of the distributed electricity market. The sale and purchase price are restricted to a certain fixed value in the traditional electricity market, according to which, prosumers can only accept and conduct energy transactions. However, the real-time adjustment of the bidding strategy based on electricity market information can effectively improve transaction returns and market efficiency [58]. In this study, energy prosumers could adjust their energy quotation on the Sub Chain to increase their own trading profits.
The bidding price of energy sellers is a comprehensive consideration of the users' purchasing, electricity output, and supply and demand relationship in the distributed electricity market. It uses real-time information to calculate the corresponding tendency factor through mathematical formulas and calculate the final bidding price of each round of matching transactions based on these tendency factors. The bidding price of an electricity seller can be calculated by Equations (24)- (28).
where Equations (24)- (26), respectively, calculate the propensity factors taking into account users' purchasing, electricity output, supply, and demand relationship. Equation (27) stands for the comprehensive propensity factor of prosumer i at time t, and the bidding price of power supplier i in t + 1 time can be calculated by Equation (28). The general power users determine their bidding prices according to the historical transaction prices of the double auction. The electricity bidding price is mathematically formulated as indicated by Equations (29) and (30).
where γ t+1 is the rational choice function and determines the adjustment range of quoted prices by judging the ideal degree of the market environment. The value range of γ t+1 is from 0 to 1 and means that users expect to complete the trading at the lowest price within the acceptable range to maximize the revenue.
As the demand-side response continues to deepen in the blockchain-based electricity market, some active users can revise their bidding prices according to the urgency of the power demand. Here, a tendency factor is set to reflect the degree of electricity demand, and the final bidding price of users is given by Equation (31).  This study selects trading profits (TP) and social welfare (SW) as the economic indicators to evaluate the bidding strategy for individuals and electricity markets. The TP of each prosumer refers to the difference between the transaction price and the reserve price multiplied by the electric quantity in each round of trading. SW is the sum of trading profits of buyers and sellers in all auctions. TP and SW can be generally expressed as Equations (32)- (34).

Credit Incentives
There are economic incentives for nodes with a high credit value in order to encourage users' credible behavior. P2P energy trading requires the maintenance of transmission lines and other infrastructure in any region. Taking China as an example, the maintenance costs of P2P trading facilities are paid to distribution network operators in the form of "gridthrough fees". This expenditure is calculated in accordance with the electricity transmission volume and transaction amount. Prosumers with a higher credit value in this study would be exempted from some expenditure, and this exempted expenditure would be paid by prosumers with poor credibility. The system maintenance expenditure charging electricity sellers and buyers in N time slots is indicated by Equations (35) and (37).
where V sell i,t and V buy j,t , respectively, denote the trading volume of the electricity supplier and user in the time slot of t. k sell and k buy denote the collection cost coefficient of energy prosumers for system operation. E total t denotes the total expense of electricity market operation, and it is jointly borne by all buyers and sellers according to their creditworthiness.
It should be noted that the initial credit value of each new prosumer is the same when they join the blockchain network. After several rounds of trading, the credit value changes and accordingly obtains the corresponding financial incentives. On the other hand, the distributed electricity market would set a minimum threshold, and when the credit value of a prosumer is lower than the minimum threshold, the energy prosumer is eliminated by the system.

Case Study
A case study is presented to prove the advantage of the proposed method based on a scenario in Erenhot, which is a remote city rich in distributed renewable energy. The overview of the scenario set and basic data are shown in Sections 5.1 and 5.2. The blockchain system design and implementation are illustrated in Section 5.3. The operation results and discussion are described in Sections 5.4 and 5.5.

Scenario Set
Erenhot is an important border port city in northern China. Due to remote geographical location, main power grid lines are difficult to extend. The distributed electricity market for P2P trading can effectively guarantee energy supply and improve regional economic benefits. This city has created 70 MW of renewable energy to supply regional electricity demand, including wind power generation (50 MW) and distributed photovoltaic (20 MW). This study divides wind power into 20 MW and 30 MW, which is operated by two power suppliers, namely Seller 1 and Seller 2. According to different geographical locations, distributed photovoltaic is divided into three power suppliers with powers of 10 MW, 6 MW and 4 MW, namely Seller 3, Seller 4 and Seller 5.
Five power users are also selected on the energy demand side, namely Buyer 1 to 5. Buyer 1 and 2 are commercial data centers with large and stable electricity loads. Buyer 3 and 4 are two typical community residents. Buyer 5 is a typical commercial user. The simulation scenario is the real distributed electricity market situation in Erenhot, and the geographical location of each electricity seller and buyer is shown in Figure 6.

Basic Data
The simulation introduces real-life trading data located in Erenhot to show the operation performance of the proposed trading model. The system maintenance expenditure charged by the distribution network is 20% of the transaction income from P2P trading prosumers. This maintenance expenditure reflects the general distribution electricity market in China.
The prosumers predict the output power of the next time slot based on historical data, resulting in possible errors between the actual power value and predicted value. In order to ensure power supply on the demand side, the distributed electricity market is connected to the distribution network, which relies on existing transmission lines. According to the actual situation in Erenhot, the electricity price of distribution networks fluctuates and changes regularly throughout the day, which can play a role in peak shaving and valley filling. The peak power consumption is at 10:00-14:00 and 18:00-20:00, whose peak electricity price during this time period is USD 163.65/MWh. The valley electricity is at 23:00-6:00, whose price is USD 58.37/MWh. The rest of the day is the normal electricity period, whose electricity price is USD 101.24/MWh. The initial bidding prices and reserve prices of prosumers are shown in Table 1, which also includes the assumed credit value in one day. It is necessary to note that the credit value is the initial setting, and it will be updated the next day according to the daily credit evaluation. According to the power change data of one day in summer in Erenhot, we counted the power changes of 10 electricity buyers and sellers on that day. Wind power output (Seller 1 and 2) is larger in two periods of a day. Photovoltaic power generation (Seller 3,4,5) starts from 8:00, and reaches the peak between 12:00 and 14:00, and there is no power output at about 20:00. On the electricity demand side, data centers (Buyer 1 and 2) have a large electricity demand and stable load. For community residents (Buyer 3 and 4), load demand is not big in the daytime, but at night there is a greater demand for electricity. Buyer 5 is a typical commercial user, and its electricity consumption is relatively low at night and increases from 9 a.m. and peaks at 12 a.m. The one-day output power of these energy prosumers is shown in Figure 7.

System Design and Implementation
The proposed credible P2P trading with double-layer energy blockchain network is performed in the form of a smart contract on the Ethereum, which was established in 2014 by Vitalik Buterin through a crowdfunding project. Ethereum is a turing-complete scripting language that supports developers in creating and publishing any decentralized application on this platform. Especially, smart contracts executed on the Ethereum have a user interface (UI), facilitating users to perform transactions and query the credit value of prosumers.
With the increase in distributed renewable energy and more a flexible power market, each user could become a prosumer at the same time, selling excess electricity when energy is rich. Currently, in the model formulation, the energy blockchain network guarantees credible P2P trading and effective supervision, and the network is designed according to the scenario in Erenhot. Each new prosumer in the Sub Chain can obtain a specific account, which includes four basic pieces of information: geographical location, account balance, credit value, and attributes. The key computer code and UI for new users to join the system based on the proposed ring mapping identity authentication are shown in Figure 8. The double-layer energy blockchain network not only enables energy prosumers to conduct real-time P2P trading, but also realizes credit evaluation and effective supervision. First, the users of the Sub Chain can submit trading demands to the blockchain network and match transactions based on Section 4. Each user can access all bidding information and historical transaction records. These real-time updated data are only developed for the nodes in the Sub Chain, so that they can adjust the bidding strategy in a timely manner to obtain a higher trading income. Figure 9 shows the transaction from Seller 2 to Buyer 3 when their bid information meets transaction conditions. Next, the trading power and credit evaluation results in the Sub Chain are sent daily to the notary nodes group composed of relevant government departments, in which power information is based on statistics of smart meters in distribution networks. The information passed by the notary node group review is published on the Main Chain and visible throughout the network. The UI of the Main Chain only contains information that does not involve privacy, as shown in Figure 10. The geographical location (latitude and longitude) of each prosumer is also disclosed to prevent malicious nodes from rejoining P2P trading by registering new IDs. In summary, the double-layer energy blockchain network is implemented through a credit-threshold digital signature, timestamps, smart contracts and cross-chain interoperability.

Operation Results
The simulation introduces a real-life trading datum located in Erenhot to showcase the operation performance of the proposed trading model. The system maintenance expenditure charged by the distribution network is 20% of the transaction income from P2P trading prosumers. Basic parameters are shown in Section 4.1, such as output power, credit value and bidding parameters of all prosumers. Figure 11 compares the one-day electricity trading profits of 10 sellers and buyers in three bidding modes, including fixed bidding price, dynamic bidding price, and dynamic bidding price with credit incentive. It can be concluded that the trading profits of the dynamic bidding price strategy is significantly higher than the fixed bidding price strategy. Especially for wind power suppliers Sellers 1 and 2, fixed bidding prices make it impossible for them to sell electricity because they have no price advantage when the distribution network is in valley electricity. In the dynamic bidding price strategy, Seller 1 and 2 can adjust the bidding strategy according to market conditions in real time to obtain higher trading profits and promote renewable energy consumption. Meanwhile, in the dynamic bidding considering credit incentive, the trading profits of the prosumer with higher credit value increases, and vice versa.  To verify the feasibility of the presented dynamic bidding strategy in this study, social welfare and renewable energy consumption are simulated, including fixed bidding price, the adaptive aggressiveness (AA) strategy, dynamic bidding price and dynamic bidding price with credit incentive. The AA strategy takes the frequent price fluctuations into account in the continuous auction market, which divides bidders into three rigid categories [59].  Figures 12 and 13 compare the one-day simulation of social welfare and renewable energy consumption in the different bidding modes. The simulation result based on one day demonstrates that the proposed dynamic bidding mode has an obvious advantage in social welfare which is 34.3% higher than the fixed bidding mode, and is 11.9% higher than the AA strategy. When considering the credit incentive, social welfare only increases by 2.7%, which can be regarded as unchanged. This is because the economic incentives for higher credit prosumers is mainly due to the punishment of lower credit prosumers. However, these credit incentives can protect the interests of prosumers with high credit value and promote the honesty and trustworthiness of various stakeholders in the electricity market.
Furthermore, the efficiency of renewable energy utilization can be improved by the dynamic bidding price. The proposed dynamic bidding mode has an obvious advantage in renewable energy consumption which is 50.1% higher than the fixed bidding mode and is 12.9% higher than the AA strategy. Especially when the grid price is low, the dynamic pricing mechanism can actively adjust the quotation to increase the renewable energy consumption in the distributed electricity market. Moreover, the AA strategy divides bidders into three rigid categories which limits its flexibility in the market. The proposed bidding method adjusts the tendency parameters according to the real-time market information and has better transaction adaptability.

Discussion
An experiment scenario conducted on Erenhot's typical P2P electricity market for 24 h is used to verify the effectiveness of the proposed methodology. The dynamic bidding mode has an obvious advantage in social welfare opposed to the traditional fixed bidding mode. On the basis of dynamic bidding, giving economic incentives according to the credit evaluation can improve the trading profits of these high-credit prosumers. The prosumers with low credit are punished to a certain extent, and even excluded from the P2P trading platform.
It is worth noting that the experiment scenario and parameter settings are based on a typical distributed electricity market of China. With the different basic parameters of market design and the different simulation regions, the trading profits and social welfare are different. However, there is an international consensus that developing P2P trading has emerged as a next-generation energy management technique for the smart grid that can enable the prosumers to actively participate in distributed electricity markets. A large number of pilot projects have also been established in the USA, Europe, and Australia. Therefore, the experimental background of this case is representative to some extent.  All the above trading processes can be completed automatically through the doublelayer energy blockchain network. In summary, the benefits of double-layer energy blockchains for prosumers involved in the distributed electricity market include but are not limited to the following aspects: firstly, a ring mapping algorithm is added to each Sub Chain so that energy prosumers with low credibility cannot join the distributed electricity market. Secondly, the nodes with higher credit value form a VNS to verify information in the Sub Chain, and improve the real-time energy interaction efficiency through the optimized consensus mechanism. Thirdly, the important and not privacy-related data are transmitted through the Sub Chain to the Main Chain by VNS, which include the transacted electricity quantity and credit evaluation. The Main Chain data are open to the whole network to achieve the effective supervision of P2P trading. Finally, the flexible use of blockchain technology can facilitate the implementation of P2P trading in the distributed electricity market.
The simulation results of the dynamic credit incentive trading model in this study are validated. Their effectiveness and representativeness involved in the distributed electricity market include but are not limited to the following aspects: first of all, Erenhot's distributed electricity market has established good grid infrastructure, and local data centers and ordinary users can directly purchase electricity from renewable energy power generation enterprises. Secondly, the case study is based on the real distributed electricity market in Erenhot, China. The power installed capacity, power generation and basic price are the actual data of the local electricity market. Thirdly, the double-layer energy blockchain network has been actually developed and is playing a role in the local electricity market. Fourthly, different credit value is a very common phenomenon, and the simulation of prosumers with different credit values is feasible. In addition, it is also credible that the real-time adjustment of the bidding strategy according to market information is more economic and environmentally friendly than fixed bidding and inactive bidding.

Conclusions
In this paper, a trading mode is designed based on a double-layer energy blockchain network to fill the gap between creditable P2P trading and blockchain technologies. Compared to the state of the art, this study introduces a new method that facilitates the implementation of P2P trading in distributed electricity markets. The proposed method and its novelties can be summarized as follows: (1) Blockchain structure: This paper designs a double-layer energy blockchain network for distributed electricity markets to ensure privacy protection and effective supervision. The blockchain structure is constructed by cross-chain interoperability technology, and the credit-threshold notary scheme and blockchain digital signature separates P2P trading data from the information to be made public. (2) Identity authentication: The ring mapping algorithm is innovatively introduced into distributed electricity markets, allowing each energy prosumer to have a proprietary identity in the energy blockchain network. This mapping identity authentication makes entity identity traceable so that uncredible nodes are excluded from the trading platform. (3) Information verification: Credit evaluation and sorting are according to contract performance, consensus participation, and trading enthusiasm of energy prosumers. The VNS is formed by high-credit nodes, which verifies the energy trading data on each Sub Chain and the Main Chain. This mode makes the formation of new blocks with high credibility. (4) Trading model: The proposed bidding strategy can adjust quotation dynamically according to real-time market information so that the P2P trading has higher social welfare and renewable energy consumption. Moreover, the credit incentives can incite the credit behavior of energy prosumers. (5) Research value: This study is expected to solve the technical problems of insufficient credit and unregulated P2P energy trading, which can promote the application of P2P trading and blockchain technology.
This study is of strong scientific value for the energy community. First of all, the local electricity markets in most regions of China conduct distributed electricity transactions according to the case scenario of this study. Next, we discuss the economic benefits of different credit value nodes under the proposed trading model. Because of the incentive mechanism, highly credible prosumers can not only verify cross-chain information, but also obtain practical economic benefits. Then, the blockchain-distributed database enables each prosumer to obtain real-time information. The blockchain system makes it possible for the proposed bidding strategy to actively adjust the quotation to obtain better returns. In summary, with the development of P2P energy trading, the double-layer energy blockchain network and the novel trading model proposed in this paper provides references for the scientific community. is important to the successful completion of this study. In addition, thank each member of the research team.

Conflicts of Interest:
The authors declare that they have no known competing financial interests or personal relationships that could have appeared to influence the work reported in this paper. public key of CA ISK = (D, N) private key of CA LPK = (E , N ) public key of the ring node LSK = (D , N ) private key of the ring node p and q random large prime number Set L private key to generate digital signature L n ring mapping space n integer selecting random number of CA n integer result of decryption verification m pad filled message from new node H m hash value Set ori original signature Set tar target signature n k number of all nodes in VNS t k minimum number required to pass a verification t k actual number pass a verification CPK v public key of the verification nodes C sell,con