The distributed trading platform design based on blockchain technology

. At present, Chinese renewable energy generation is growing rapidly, distributed power trading as a market-oriented means to promote the consumption of renewable energy power has attracted wide attention. It is urgent to optimize the mechanism design and build a credible and efficient trading environment to meet the needs of credibility and timeliness of large-scale multi-agent transactions. This paper first constructs a distributed power trading mechanism considering multi-subject transactions, and then elaborates the design idea of the power distributed trading platform based on blockchain technology from three aspects: total volume architecture, platform core technology and platform deployment. Finally, based on the operation of the actual power trading center in a certain region, field application verification is carried out, which proves the effectiveness and superiority of the distributed trading platform designed in this paper based on blockchain technology. The next research will continue to expand the typical model application pilot in the applicable areas to further improve the platform functions.


Introduction
In recent years, Chinese renewable energy industry has been booming.As of the end of September 2019, the capacity of renewable energy generation and installation machines in the country was 764 GW, an increase of 8.2% year-on-year [1].However, due to the uneven distribution of wind and scenery resources, the high cost of power grid supporting investment and operation and maintenance, and the imperfect market trading mechanism, etc.Under the new situation of accelerating the low-carbon transformation of China's energy structure and greatly increasing the power generation of renewable energy, the marketization of distributed power trading provides a new way to promote the consumption of renewable energy [2][3].
Under the background of China's power grid construction and market reform in the field of electricity sales, there will be a large number of energy producers and consumers with trading qualifications to enter the distribution network and participate in market trading competition.In this case, distributed trading has many advantages, such as large number of participants, small single trading volume and low participation threshold [4][5].Literature [6] takes into account the impact of randomness of renewable energy generation on multimicrogrid trading.The privacy issues and information security issues in multi-microgrid markets, and the countermeasures of different microgrids to market fluctuations are also considered.Combined with multimicrogrid decentralized power trading smart contracts, this paper provides decision support for day-ahead robust power trading in microgrids, and explores the optimal scheme through a two-stage transmission cycle.In [7], the literature proposed that the electricity market trading on adopts the mode of alternate bidding.In the negotiation stage, the buyer and seller first reach a temporary contract, then use the power transmission distribution coefficient and voltage sensitivity coefficient to verify the power grid security, and sign a formal contract after the successful verification.In [8], the literature proposed a distributed P2P energy trading mechanism based on two-way auction market.Consumers firstly use the distributed energy management model to independently generate energy supply and demand information, and then set a price with the goal of maximizing profits.
Because distributed power trading involves multisubject and cross-regional transactions, the trading system will face the dual challenges of trust and efficiency.Blockchain technology has the technical characteristics of multi-party consensus, immutable, and fully traceable, which provides a feasible solution.Blockchain is a new type of distributed network in which all participants receive private encryption keys from blockchain servers for addressing and sending signed transactions in a distributed transaction center.And blockchain servers can verify and authenticate the identities of networked traders.In addition, it can verify the authenticity and privacy of any transaction.Many research institutions at home and abroad have conducted many studies on the application of blockchain in power trading.Literature [9] proposed a P2P electricity trading mechanism based on blockchain environment.Literature [10] proposes a Unified permissioned blockchain-based P2P-ET Architecture (UBETA) that integrates three different types of energy markets and provides a unified energy trading and payment settlement model.Literature [11][12] established the renewable energy excess consumption trading system through blockchain technology.
Large-scale power trading has high requirements for transparency, reliability and efficiency of the trading system, and it is urgent to customize the system mechanism and architecture suitable for large-scale distributed power trading.This paper first constructs a distributed power trading mechanism considering multisubject transactions, and then elaborates the design idea of the power distributed trading platform based on blockchain technology from three aspects: total volume architecture, platform core technology and platform deployment.Finally, based on the operation of the actual power trading center in a certain region, field application verification is carried out, which proves the effectiveness and superiority of the distributed trading platform designed in this paper based on blockchain technology.

Trading rules
(1) The trading center initiates a distributed trading for the next hour every 1 hour.From the beginning of the trading, each market member submits the first round of trading power and quotation according to the predicted supply and demand power within 15 minutes, the market member completes multiple rounds of declaration and matching trading according to the trading rules within 15-45 minutes, clears the market, and settles the trading and records the trading results within 45-60 minutes [13].
(2) After the end of each round of trading, the trading center will disclose the current round of trading records.Users whose demand is met can choose to withdraw from this trading, or continue to declare the trading power and price, and participate in the next round of trading.Users who do not complete the trading of declared electricity can modify the declared electricity and electricity prices according to the public market trading records and continue to participate in subsequent trading [14].
(3) If the quotation of all power purchasing users is lower than the quotation of power generation users, the current round of trading will be suspended, all trading applications will be returned, and the user will re-quote or choose to exit the trading directly [15].
(4) When no market member continues to report or the trading time ends, the trading is completely closed.

Trading processes
Figure 1 illustrates the trading processes carried out in the distributed trading platform.There are five main steps as follows: (1) Before the start of the trading, the price declared by the users participating in the trading is arranged in the order from high to low, and the power purchase price is arranged from low to high, and the power sale price of the power generation user is arranged from low to high, giving priority to matching the trading between the power purchase user with the highest price and the power sale user with the lowest price.If the quotation is the same, according to the chronological order of the application trading, from fast to slow, priority is given to the user with the fastest quotation [16].
(2) When conducting the first trading, the optimal power purchase price of the round is the highest target price of the power purchase user, and the optimal power sale price of the round is the lowest target price of the distributed power generation user.The condition of the distributed trading is that the optimal power purchase price of the round is higher than or equal to the optimal power sale price.
(3) When trading in the two-way auction market, first clear the lowest price of electricity sold.After the end of this round of trading, the user whose trading demand is fully satisfied exits the trading and records the result of this round of trading.
(4) In the round k trading, the optimal selling price is the power generation quotation of the last trading in the previous round, and the optimal purchasing price is the power purchase quotation of the last trading in the previous round.Compare the value of the initial price declared by the remaining power selling users with the optimal power selling price.If the initial price of distributed generation is lower than the optimal power selling price, the risk coefficient needs to be increased, λ is set to 0.05, and vice versa is set to -0.05.Similarly, comparing the initial price declared by the remaining power purchase users with the optimal power purchase price, when the initial target price of the user is higher than the best purchase price, it means that it is necessary to increase its risk coefficient, λ is set to 0.05, and vice versa is set to -0.05 [17].By substituting the changed risk factors into the formula, the quotations of market members can be adjusted.Repeat steps (1) -(3), if the power of a party in the distributed trading market has been all cleared before the end of the trading time, or the trading time is closed, then all trading in the trading period will end.
(5) Network fees generated by trading are calculated according to the generated trading records, and the network fees generated by each trading are jointly borne by both sides.Based on the demand of power transaction, the overall architecture including application layer, service layer and data layer is designed by applying blockchain technology, as shown in Figure 2. Fig. 2. The overall architecture of power trading platform 1) Application architecture.The application layer includes external service business and internal control management business of the platform.The external service business includes data declaration, information query and other functions.The internal control management business includes transaction subject management, voucher transaction management, transaction accounting management and credit evaluation.Business architecture design is based on long-term business development, considering market registration, physical electricity settlement and other business inherited trading platform functions.In the later stage, the system will evolve to a microservice architecture, and integrate and migrate with the "etransaction" platform and the new generation of power trading platform [18].

E3S
2) Service structure.The service layer consists of blockchain services, trading platform sharing services and external business expansion services.Among them, the blockchain service provides data storage, certificate issuance, transaction matching, settlement, traceability and other services for the trading platform through blockchain identity authentication, blockchain digital certificate and blockchain smart contract technologies.The trading platform sharing service realizes the specific application of power trading business through the existing trading system of the trading center.External business expansion services provide standardized and standardized interface services for transaction business through blockchain [19].
3) Data architecture.The data layer adopts the combination mode of "business demand-driven topdown" and "bottom-up driven based on the status quo" to build the data model through object-oriented modelling.According to the input and output data objects, core business data abstraction and conceptual modelling are carried out to form the underlying data model with the provincial administrative region as the minimum scope on the macro level and the responsible entity enterprise law as the minimum unit on the micro level, so as to solve the problem of inconsistent granularity of different business models and meet the interaction requirements of new business expansion models.

1) Efficient transaction consensus mechanism
According to the demand of power trading scenario, a high-performance asynchronous consensus mechanism is realized from three directions: network fragment parallel processing, consensus mechanism and final propagation confirmation.Based on the idea of network segmentation and transaction parallel processing, combined with the hybrid consensus algorithm and the final consistent broadcast method to support power trading [20].
The blockchain network nodes are divided into different sub-chains after hashing and modulo operation.Different sub-chains independently process different data in parallel, and multiple sub-chain data are recorded and verified at the same time, so that the TPS of the overall blockchain transaction system will be greatly improved.
2) Smart contract on-chain transaction Transactions based on smart contracts involve the interaction and collaboration of the mobile shield system (identity authentication key storage medium), the power trading system and the blockchain system, and the transaction declaration, confirmation, clearance and other links are executed on the chain.
All consensus nodes of the blockchain participate in the record of transaction data, and immutably register GPCC's issuance information, circulation information, derivative information and other characteristic data on the blockchain for permanent storage.Each transaction record is connected to generate a data block in the form of a time stamp, and the flow chain of recording transaction information is completely tracked to realize the traceability of the whole life cycle of the certificate.
3) Transaction user identity authentication Transaction subjects need to carry out identity authentication and verification in the process of initiating transactions and signing contracts on the platform, which is the basis for ensuring trusted transactions.At present, the authentication method used is the third party authentication based on U-shield, which has the problems of high cost and insufficient convenience in large-scale trading system.
In order to take into account the convenience and security of identity authentication, this paper uses the tamper-proof and multi-party consensus characteristics of blockchain to propose a blockchain identity authentication solution.The user first completes the registration in the trading system, which is verified through the real-name authentication mechanism, and generates a public-private key pair stored in the cloud or the mobile shield system.Then, the system sends the user information and public key to the blockchain identity management platform, and the platform writes the user information hash value and public key to the chain to obtain the identity certificate deposit number.Finally, the blockchain identity management platform generates complete identity credential information including the depository number, user information and public key through the depository number.In the interaction process between the user and the trading system, if the transaction application or contract signing is initiated, the trading system will compare the user information hash value returned on the chain and the public key with the signature value and certificate number obtained by the key storage medium through the signature operation to complete the authentication and verification of the identity.
4) Cooperative storage of transaction data Data storage is an important basis to ensure the trusted completion of transactions.In the business scenario with a large number of transactions, the limitation of on-chain storage prevents large-scale data storage and calculation.At the same time, the increase in on-chain data puts forward higher requirements for the retrieval efficiency of block transaction data.
The system adopts intelligent identification and data compression to solve the problem of on-chain transaction data redundancy.In the process of electricity trading, the number of orders and transactions do not correspond one to one.A transaction often contains several orders, for these orders, the user only need to perform a unified private key signature, packaged into a single transaction to send together, rather than having to sign each transaction.In the process of transaction verification, the node will deserialize the transaction, execute the order content in order, and the transaction after consensus will be stored in the blockchain system.In order to solve the problem of large data storage and low detection efficiency, the system adopts the combination of on-chain and off-chain storage and efficient retrieval technology.Specifically, part of the data is stored in a distributed peer-to-peer network off the chain to improve the scalability of the blockchain system [21].
At the same time, semantic information of off-chain data is extracted, inverted index is constructed according to the importance of keywords, and cooperative mapping relationship between off-chain data and on-chain data is established.Construct index structure, support semantic keyword search, range search, fuzzy search, and provide verification of search results.In the power trading business, the storage and retrieval of massive data is realized through the on-chain and off-chain collaborative data storage technology, which provides the basic guarantee for trusted transactions.

5) Transaction execution security protection
The trading center, power grid enterprises, and regulatory agencies in the power trading platform are used as node networks, and their security is crucial to the security of the entire blockchain network.Smart contract is the realization path of on-chain transaction business logic, and its security is directly related to the application security of the entire system architecture.Therefore, security protection is carried out from the two aspects of nodes and smart contracts to ensure the safety of transaction execution.The specific protection mode is as follows: Based on the different underlying facilities, service architectures, kernel systems, and application modes of each node, node authentication, user identity authentication, and access control methods are used to identify fake users and users with malicious attack behaviours and adjust their permissions.In addition, abnormal data detection is carried out on the smart contract architecture, contract operation mode, contract code layer, the amount of each function in the contract, real-time trading volume, code execution state and other processes to ensure the security and trust of on-chain contracts.Secure the execution of power transactions through node and smart contract security, providing security for trusted transactions.

Platform Deployment
The blockchain architecture design of power trading business includes three main levels: data layer, network layer, and consensus layer.The blockchain platform deployment architecture is shown in Figure 3.In the data layer, the external data query interface of power trading block chain is designed, as well as the data retrieval mode, data transmission format and interface response field content of the interface.The network layer setting function locates different blockchain node types, determines the mapping relationship between the scale of alliance chain nodes and the operating performance, and clearly limits the deployment upper limit of different types of nodes under the operating performance.The deployment caps for different types of blockchain nodes take into account the characteristics of the electricity trading market and the characteristics of the blockchain.Nodes can be divided into full nodes and light nodes in terms of data dimension.The physical hosts of Beijing Power Trading Center, provincial power trading centers, power grid enterprises, distribution companies, large power users, and regulatory agencies are used as full-node networking.Among them, the Beijing Power Trading Center is mainly responsible for organizing inter-provincial transactions across regions and provinces, and provincial power trading centers organize intra-provincial transactions.Other small power users participate in the transaction as light nodes.The consensus layer adopts a two-stage hybrid consensus algorithm, and the responsibility of the consensus node is shared by the regulator, the Beijing Power Trading Center and the security check node of the dispatching agency.

Cases analysis
The blockchain-based power trading system is operated by a regional power trading center, relying on market entities such as power grid enterprises, distribution companies, and power users to carry out field application verification.

Test Content and Environment
The testing of the blockchain-based green certificate trading platform includes: (1) functional testing, which is performed manually by writing test cases; (2) Blockchain network performance test, using the parallel transaction executor (PTE) tool for testing.Table 1 lists the parameters of the application server, database server, test machine, and network environment to be tested.

Test Results
The functional modules of the green certificate trading platform were tested.A total of 43 use cases were written for 35 functions of the system, and 43 of them passed the test, with a pass rate of 100%.The specific functions and number of tests are shown in Appendix Table A1.
For the evaluation of the performance of the blockchain network, the throughput rate of the invoke/query operation of the blockchain network on the standard is compared under three examples, the dimension is transactions per second (TPS), and the parameters of the example are shown in Table 1.In the test, the maximum number of transactions per block (batch size) is 50, the block interval is 2s, and the number of transactions per thread is 1000.The throughput test results of the whole blockchain network under each calculation example (the throughput of the whole network is the sum of the throughput rates of all organizations) are shown in Table 2, and the throughput rates of invoke/query operations conducted by all organizations are shown in Figure 4.

Conclusion
This paper proposes a distributed transaction mechanism based on blockchain.Design a power trading platform with core capabilities such as efficient consensus, on-chain transaction and identity authentication, and build a reliable and efficient power trading environment; Through the system test and the application demonstration of power trading and consumption certificate trading, the completeness and practicability of the distributed trading system are verified.The results of numerical examples in the fourth part of this paper effectively show that the designed platform has strong adaptability in various trading scenarios.
In the next step, the key technology optimization scheme involved in the demonstration application of blockchain-based green electricity trading system will be studied, and micro-service transformation will be carried out according to the needs of business applications.At the same time, continue to expand the typical mode application pilot in the applicable areas, track and analyse the operation effect of the pilot project, further improve the platform functions, and enhance the service capability of the blockchain-based power trading system.

Fig. 4 .
Fig. 4. Throughput for invoke/query operation of blockchain with different counts of organizationsIt can be seen from the test results that the overall throughput rate of the blockchain-based trading platform remains above 500TPS, and the average transaction processing time is less than 2ms, which can meet the needs of distributed transactions.The distribution of network resources is balanced among the alliances, which can adapt to the scenario of multi-agent participation.

Table 1 .
Trading platform test environment

Table 2 .
Performance test of blockchain network TableA1The test results of the system function