A Blockchain-Enabled Trading Framework for Distributed Photovoltaic Power Using Federated Learning

,


Introduction
Escalating global environmental problems and energy demand, coupled with the steady development of new energy technologies, have been opening up new opportunities for the promotion of new energy sources.In the context of global advocacy of energy conservation and emission reduction, photovoltaic (PV) power, as an important part of new energy, has been vigorously utilized in recent years, and the demand for PV power is increasing yearly [1,2].In 2019, more than 200 GW of renewable energy capacity was added globally, with PV power accounting for about 2.8% of global power generation [3].An increase in PV power generation capacity typically requires a stronger consumption capability.
However, considering the instability of renewable energy sources, insufficient energy storage technology, inaccurate load forecasting, and many other reasons, the selfregulation ability of power grid is limited.In addition, there are still some inadequacies in the existing electricity trading mechanism that need to be improved [4,5].For example, the traditional electricity trading mechanisms may not be able to respond effectively and accurately to customers' demand.As a result, the problem of how to improve the consumption capacity of distributed PV power generation has become increasingly prominent.
Therefore, a more effective and efficient electricity trading framework is urgently needed to satisfy the requirements of both energy producers and consumers to the greatest extent.And then, the new energy consumption can be facilitated while the needs of producers and consumers can be met [4,5].This requires cooperation between both power producers and consumers: the producers are supposed to accurately forecast their own power generation to avoid oversupply or undersupply and ensure a stable trading environment, while the consumers have to trade with the most suitable power producers to secure their own interests.
This paper explores the application of federated learning (FL) and blockchain technology in peer-to-peer (P2P) electricity trading and proposes a novel blockchain-enabled trading framework for distributed photovoltaic power using FL.The main contributions of this paper are as follows: (i) We design a decentralized collaborative model training approach using blockchain-based federated learning (BFL) with the consideration of data privacy preservation in distributed PV power stations (ii) We develop a graph-based matching algorithm by abstracting the producers and consumers of electricity trading into an equivalent graph model and utilize a smart contract to execute the proposed matching algorithm automatically (iii) We implement the proposed framework, called blockchain-based federated learning with smart contract (BFLSC) framework, on the Hyperledger Fabric platform and validate its effectiveness using real-world datasets, which provides a better reference for the developers of blockchain The rest of our paper is organized as follows.The related work is surveyed in Section 2, followed by the description of the decentralized collaborative power prediction model designed by BFL in Section 3.Then, Section 4 gives the design of transaction matching algorithm and the implementation of smart contract.Section 5 introduces the proposed BFLSC framework.The experiment and analysis are provided in Section 6.Eventually, we conclude our work with a summary in Section 7.

Related Work
Recently, there have been many researches on prediction of power generation and on blockchain technologies in electricity trading.For power predicting, Dutta et al. [6], in the context of short-term PV power forecasting, shift from meteorological-based prediction to an approach grounded in historical electricity data.This modification has led to heightened accuracy.However, the method exhibits limitations in predicting large-scale variations, necessitating additional recent historical data as supplementary support.Zhou et al. [7] propose a multivariate hybrid prediction system that integrates signal decomposition and artificial intelligence techniques.This system leverages independent variable features to enhance the accuracy of solar power generation predictions.But the incorporation of multiple variables implies a greater demand for data.Almonacid et al. [8] try to employ a dynamic artificial neural network for PV power prediction and achieve a satisfactory margin of error.Their method is regarded as a new prediction strategy with better generalization capability.Hossain and Mahmood [9] select features according to the correlation between different weather variables and PV power and introduce long short-term memory for prediction.Different from the previous centralized processing, Yoo et al. [10] utilize FL to build a solar power generation prediction model based on data collected from local generators.
On the aspect of applying blockchain in electricity trading, Oprea et al. [11] embed two novel settlement mechanisms for P2P electricity exchange into smart contracts as stored procedures, improving the classic pairwise settlement.Alao and Cuffe [12] devise the trading strategy based on smart contract arrangements, thus reducing the volatility risk for power producers.In addition to combining smart contracts with settlement mechanisms and trading strategies, Liu et al. [13] execute smart contracts to implement the proposed proof-of-benefit consensus protocol and protect the system from potential risks.Vieira and Zhang [14] rely on blockchain technology and auction mechanism to develop two market frameworks, facilitating autonomous P2P energy transactions in microgrids.Han et al. [15] make use of the fact that smart contracts can strictly implement the designed trading and payment rules to encourage direct energy trading between producers and consumers.Furthermore, Ping et al. [16] propose a joint energy-reserve prosumer-centric market based on blockchain, contributing to an autonomous and trustworthy prosumer-centric market.
As summarized in Table 1, previous studies have extensively explored various strategies for the smart sustainable grid.In the realm of power prediction research, a predominant approach involves relying on large-scale data aggregated from individual power stations to enhance accuracy.However, the growing emphasis on data security has made the aggregation of large-scale data increasingly challenging.FL, as a distributed machine learning approach, presents itself as a novel method for collaborative multiparty data analysis.
While there have been efforts to address the issue of insufficient local data through FL, the traditional FL model faces challenges such as single-point failure and potential malicious data, stemming from its centralized architecture and dependence on a central server [17].Furthermore, in the domain of electricity trading, the application of smart contracts [18] has predominantly focused on transaction pricing and arrangements.However, achieving accurate matching between producers and consumers is equally vital for establishing a reliable and trusted trading environment.

Decentralized FL Training Model for Prediction
FL is a distributed machine learning approach which enables model training on a large corpus of decentralized data [19,20].1.The model input is the time-series data composed of power generation and related environmental factors considering the influence of external environment, such as illumination and temperature.The time-series data is a one-dimensional grid obtained by regular sampling on the time axis.Therefore, CNN with strong capabilities in grid-like structured data processing is used to extract features of the power generation data.The CNN layer consists of two 1D convolution layers and two pooling layers; this is simple but effective.The first convolution constitutes the feature map of input data, and the second convolution is conducted on the feature map created in the first convolution with an attempt to further amplify the significant features.The pooling layer uses max-pooling which selects the maximum value on feature area for down-sampling to reduce the number of features and simplify the feature map.The activation function in the CNN layer is the ReLU function, and its formula is ReLU x = def max 0, x .The LSTM layer is used to learn the variation law of power generation because it is apt at processing longer sequences of time data [21].The LSTM employs gating mechanism to selectively retain or forget historical information with a forget gate f t , input gate i t , and output gate o t .The f t selectively retains the hidden state information of the previous cell to the current cell, the i t selectively retains the information of input to the cell unit, and the o t selectively retains the current internal state information and outputs it to the next cell unit.The basic cell structure of the LSTM network model is shown in Figure 2.
In the figure, x t and g t are the input and candidate state of the current cell, respectively, c t−1 and c t are the internal state of the previous cell and the current cell, respectively, h t−1 and h t are the hidden state of the previous cell and current cell, respectively, and σ and tanh are the sigmoid function and hyperbolic tangent function, respectively.The calculation formulas are shown in the following.Additionally, to improve the efficiency of model and saving computing resources, we also introduce attention mechanism into the model, which is a processing method simulating the cognitive attention of the human brain [22].The attention mechanism distributes feature weights according to the feature importance; then, the neural network will only select the key information for processing when a large amount of input information from the previous layer needs to be processed.The parameters of attention mechanism are calculated by the following.Power predicting [6] An approach grounded in historical electricity data Additional recent historical data [7] The combination of multiple variables Greater demand for data [8] Dynamic artificial neural network Greater demand for data [9] The correlation between different weather variables and PV power Greater demand for data [10] FL Insecurity and single-point failure Blockchain in electricity trading [11] The introduction of settlement mechanism Neglect of transaction subjects [12] Blockchain for risk management Neglect of transaction subjects [13] New consensus protocol Neglect of blockchain performance [14] Auction mechanism for microgrids Incapability of automated transactions [15] Smart contract for implementation of rules Without considering future generation capacity Eventually, the future power generation is acquired through the full connected layer and output layer.

The Execution Process of BFL.
Traditional FL counts on a central server to aggregate parameters and update the global model [23] as shown in Figure 3(a).Despite the datapreserving capability of traditional FL, its centralized architecture is vulnerable to the malfunction of the server.Fortunately, the advent of blockchain provides more opportunities for the development of FL, by which the aggregation and update can be realized in a distributed and secure manner as shown in Figure 3(b).In our BFL, the

Input layer
Output layer CNN layer LSTM layer Attention layer Pooling layer

Maximum pooling
Convolutional layer 1D convolution

Pooling layer
Maximum pooling The structure of the hybrid model with attention mechanism.International Journal of Energy Research blockchain serves as an immutable distributed ledger to record and store model updates; thus, a decentralized FL structure can be achieved while preventing attacks from possible malicious node.We assume that there are K number of PV power stations, and each PV power station has a corresponding computer workstation which is regarded as a node in the blockchain network.The local dataset of a node i 1 ≤ i ≤ K is denoted as D i , the total number of data in D i is denoted as n i , and ∑ K i=1 D i is denoted as N. Algorithm 1 depicts an overview on the BFL execution, and the execution process will be described in detail below.
The initial parameters of the prediction model mentioned in Section 3.1 are manually set to genesis block which is the first block of the chain at the beginning.Then, all nodes use these parameters for initialization at the beginning of training separately.We define the structure of data stored in the ledger with the node ID, denoted by nodeID; local model parameter, denoted by localParm; and the corresponding training epoch, denoted by epochNum, i.e., each data item in the ledger represents the localParm of nodeID in epochNum.

Let us denote the local model parameter of node i and the global model parameter in epoch t by w t
i and w t 0 , respectively.And the local model parameter of node i in the next epoch of t is denoted as w t+1 i .Then, w t+1 i minimizes f w i , namely, arg min f w i in the epoch, during the local model training using D i .The following Equation (3) defines the f w i , and then, w t+1 i can be obtained by Equation ( 4) according to the gradient descent algorithm.
where x i j represents the sample indexed by j in D i , σ represents the loss function, η represents the learning rate of gradient descent, and ∇f w i represents the calculated gradient of f w t i .During training, the local model parameters of each node will be updated in every epoch.For example, the current w t i will be updated to w t+1 i for a node i after local model   ance between supply and demand in the power system while accurate matching requires appropriate matching algorithms to achieve.In the following, we propose an efficient matching algorithm based on graph theory.The processing of semistructured data usually relies on graph theory which is a mathematical model describing the relationships between objects [24,25].As a model of graph theory, the bipartite graph is a graph whose vertices can be divided into two disjoint and independent sets.The properties of electricity trading can be conveniently described by means of a diagram consisting of two sets of vertices with a set of edges joining certain pairs of these vertices.Therefore, an undirected graph G = U, V, E is used to represent an electricity trading system.Where the vertex sets U and V represent the producers and consumers, respectively, the edge set E represents the transaction links between them.In the graph G, an element edge e i ∈ E has a weight w i w i ≥ 0 which represents the power quantity traded by a matched pair of producer and consumer.The elements u i ∈ U and v i ∈ V represent a producer and a consumer, respectively.For convenience of description, the predicted power of a producer u i is denoted as S i , the demanded power of a consumer v i is denoted as R i , and the weight between the u i and v i is denoted as w u i , v i .
According to the given bipartite graph G, the matching problem between the two sides of electricity trading can be modeled as Equation (6) with the purpose of promoting power consumption.The objective function f is to maximize the quantity of electricity traded with three constraint

6
International Journal of Energy Research conditions: (1) transactions made are as few as possible; (2) for all producers, the amount of electricity traded should not exceed the predicted power generation; (3) for all consumers, no more power is traded than they need.
The greedy strategy is a common strategy for solving optimal problems.This strategy greedily chooses the best available option at each step without considering any potential consequences, but it is very convenient and effective.To solve the above mathematical model, we apply the greedy strategy which makes the locally optimal choice at each stage, i.e., meeting the maximum demand with as few producers as possible at each stage.
Let us assume that the sets of U and V are sorted in descending order by the power generation and power demand, respectively.Then, S i ≥ S i+1 and R i ≥ R i+1 for all i 1, 2, 3,⋯ .Additionally, the maximum tradable quantity of electricity must be less than or equal to min ∑ S i=1 S i , ∑ R i=1 R i .In this context, there are two cases for the S 1 and R 1 : one case is that S 1 ≥ R 1 , another case is that S 1 < R 1 .For the first case, a new edge would be built in the G, and the weight of the edge would be assigned to R 1 .For another case, it should be searched backwards to k that satisfies the condition ∑ k i=1 S i ≥ R 1 .If there is a such k, the k number of new edges would be built.The weights of the first k − 1 edges would be assigned to the corresponding S i , and the weight of k-th edge would be assigned to R 1 − ∑ k−1 i=1 S i .Otherwise, a new edge would be built for each supplier, and the weight of the edge would be assigned to the corresponding S i .The following Algorithm 2 shows more details of our matching procedure.The time complexity of the matching algorithm that we designed is O n log n + m log m , where n is the data scale of the producers, and m is the data scale of the consumers.
Here, we give a proof of the correctness for our proposed greedy strategy.Without loss of generality, let us assume that the set of vertices currently connected to R 1 to build edges in G is P S 1 , S 2 , ⋯, S k k ≥ 1 .Instead of selecting, chooseS 1 to build the edge withR 1 , and now, we replaceS 1 with other elements inS.Due to the descending order of S, all elements in S are less than or equal to S 1 .If k = 1 and there is S i ∉ P S i ≥ R 1 , replacing S 1 with S i will not increase the number of edges in G, that is, the number of transactions.Otherwise, at least two elements S i ∉ P, S j ∉ P S i + S j ≥ S 1 are needed to substitute for the amount of electricity that S 1 trades to R 1 .In other words, there will be one new edge or more in G, which violates the condition of minimizing the number of edges in the graph.To sum up, this substitution method is incorrect.By analogy, replacing any element in P will not make the result better.That means the greedy strategy applied by us can get the optimal solution.4.2.Smart Contract in Trading Strategy.Relying on the consensus mechanism and immutable data of blockchain, smart contract has gradually developed from an agreement where participants jointly fulfill digital commitments to an agreement enforced automatically by computer programs without the intervention of a trusted third party [18,26].In electricity trading systems, smart contracts can be utilized to specify rules concerning how and when to conduct electricity trading [27].In our work, the smart contract is used to make the matching procedures progressed automatically in order to provide a reliable and credible environment.
The proposed BFLSC framework provides market matching services and transaction recording services for producers and consumers using smart contract as shown in Figure 4. Energy producers send predicted tradable power to the smart contract in hopes of achieving consumption of PV while energy consumers submit their energy demand which meet their production and living needs to the smart contract.
Our smart contract is built upon blockchain to ensure the correct execution.Once the smart contract is invoked, the contract clauses will be executed automatically as the business logic of electricity trading as shown in Figure 5.
Above all, producers provide the real-time-predicted power generation, and the consumers provide the power demand.These supply and demand serve as the basis for subsequent transactions between two parties.In the second place, the smart contract executes the proposed matching procedure to promote deals between them.Later, producers and consumers reach a consensus on electricity trading.Whenever new transactions are created, the transaction information will be recorded in the distributed ledger of blockchain for storage to ensure the security.Notice that the whole procedure which forms a real-time trading contract is completed between producers and consumers in a P2P manner without the intervention of a third party.As a result, the efficiency and security of trading can be greatly enhanced.

The BFLSC Framework for P2P Electricity Trading
The proposed BFLSC framework consists of two modules to summarize: the collaborative prediction method for power generation using BFL and a real-time trading strategy based on smart contract.Our approach involves using BFL to forecast the future power generation of each station and subsequently implementing real-time peer-to-peer (P2P) trading with smart contracts, as illustrated in Figure 6.In this trading framework, distinct PV stations within the same region are considered clusters.This clustering is based on the significant similarity observed in power generation among different PV stations within the same region and time frame.

International Journal of Energy Research
Moreover, the PV power generation sources and consumers should be connected within a network to facilitate communication between consumers and producers.Simultaneously, a blockchain network is established among PV stations for implementing BFL and executing smart contracts.
We employ BFL to train our innovative hybrid CNN-LSTM model, which incorporates an attention mechanism for predicting power generation in each PV power station.
The process begins with stations within a regional cluster gathering local small-scale historical power generation data and conducting data preprocessing, including normalization to eliminate noise data effects.Before BFL execution, the global model is initialized by manually setting its initial parameters to the genesis block.
Subsequently In real-time, new actual power generation data is dynamically added to the local dataset, ensuring the dataset's continuous expansion.This BFL-based approach enhances the accuracy and real-time performance of power prediction for PV power stations, showcasing excellent generalization applicable to various time-series prediction problems while maintaining data security.
For the real-time trading strategy based on smart contracts, the system relies on the blockchain's distributed ledger, with producers and consumers acting as network nodes facilitating smart contracts.The trading system incorporates a time trigger, automatically invoking the smart contract interface and executing clauses based on preset business logic at the specified interval.
The smart contract acquires predicted future power generation results from each distributed PV power station for accurate power bidding.Simultaneously, it obtains electricity demand from consumers and matches power producers with consumers using an algorithm, promoting efficient electricity consumption.All transaction records are securely   Within the same cluster, PV station nodes preprocess small-scale historical local power generation data using normalization to eliminate noise data effects.All nodes then utilize BFL to train the hybrid CNN-LSTM model with an attention mechanism.Upon completing training task orchestration, nodes use the global model to predict future power generation.The system operates with automatic matching of producers and consumers using a bipartite graph mode to maximize quantity and minimize transactions.Transaction information is recorded in the blockchain's distributed ledger to ensure genuine, trustworthy, and immutable transactions.Both transaction matching and recording services are implemented as smart contract interfaces.

Experiments and Analysis
Prediction accuracy is an important indicator to measure the fit of model.It describes the degree to which the predicted value produced by the model fits the historical actual value.Transaction latency is a significant metric in blockchain systems.The latency performance of transaction is crucial to the blockchain in assessing its effectiveness.In this section, we evaluate the proposed BFLSC framework in terms of prediction accuracy and transaction latency.
P2P electricity trading has certain requirements for the identity of participants, the transaction information between them cannot be disclosed, and real-time transactions require high performance on transaction latency and throughput.In our experiments, according to the above reasons with the comparison of different blockchain types in Table 2, we built a blockchain network using the Hyperledger Fabric platform which is the most widely used consortium blockchain.The Hyperledger Fabric differs from other blockchains in that it introduces the concept of channels.The participants in the same channel have a separate ledger and maintain the ledger collaboratively.Furthermore, a fabric network can have multiple channels, and each channel is isolated from each other [28].
In our experiments, we regard each PV power station as a Hyperledger Fabric organization with two peer nodes and an orderer node.Four organizations, R1, R2, R3, and R4, establish a network with configuration, CC1 and CC2.Organization R1 has peer nodes, P1 and P2, and an orderer node, O1 and P1, hosts a copy of ledger L1, and smart contract, S1 and P2, hosts a copy of ledger L2 and smart contract S2, respectively.Organizations R2, R3, and R4 also have their own peer nodes, orderer node, distributed ledgers, and smart contracts as shown in Figure 7.There are two channels, C1 and C2.The channel C1 is used to share the local model parameters during the BFL process, and the channel C2 is used to record the transaction information.Note that all organizations are joint to the both channels.The L1 and L2 store the model parameters and transaction information, respectively.A1 is an application of predicting future power generation by BFL for the channel C1.The smart contract S1 is the operation interface of model parameters in the ledger L1.A2 is an application of real-time electricity trading for the channel C2.The smart contract S2 is the interface to provide matching services and recording services.
Our experiments are conducted on the Hyperledger Fabric v2.0 system.We deploy a two-channel fabric network on 4 physical servers in an isolated LAN with 1,000 MB/s network bandwidth.The hardware configuration of each server is a 4-Core CPU, 16 GB main memory, and 1 TB magnetic disk, and each server is installed with Ubuntu Server 20.04 LTS 64bit operating system.

Experiments for Prediction Performance.
To verify the generality of our BFLSC framework in real-world power scenarios, we use PV power data from the Desert Knowledge Australia Solar Centre (DKASC) [29] as the dataset.More than 30 PV power station systems are installed in the center, and the power generation data with corresponding environmental parameters of the PV power station system is 10 International Journal of Energy Research publicly accessible.Short-term prediction timescales typically range from 30 minutes to 72 hours [30].Therefore, four distributed PV power stations located in DKASC, Alice Springs, are selected.The station codes are BP Solar, 2.0 kW, poly-Si, Fixed, 2008, North/Flat/East/West, and the data resolution is 5 minutes; the data ranges from November 6, 2022, to November 9, 2022.We label these four power stations as station A/B/C/D, respectively, to simplify the expression.Considering the possible influence of dimension attached to data, we scale the data by min-max normalization and then control the data range within the given interval.The following Equation (7) shows how to perform the min-max normalization.Once the data preprocessing is done, the overall statistical distribution of data will turn consistent with the elimination of noise data.Then, the dataset is divided into a training set and a test set at a ratio of 8 : 2.
The training set is used to train the model while the test set is used to compare with the prediction results of the model to calculate the prediction accuracy.
where x represents sample data, x′ represents normalized sample data, and max x and min x represent the maximum and minimum values of sample data, respectively.We adopt mean absolute error (MAE), mean square error (MSE), root mean square error (RMSE), and coefficient of determination (R 2 ) to indicate the prediction accuracy more directly as the following Equations ( 8)-( 11) [31].For MAE, MSE, and RMSE, their values measure the deviation between the predicted and actual values.So the smaller their values, the more accurate the prediction results.While for R 2 , it portrays the proximity of predicted and actual values.Therefore, the larger their values, the more accurate the prediction results.In addition, the R 2 is more informative and truthful and does not have the interpretability limitations of MAE, MSE, and RMSE [32].Tables 3-6 provide a quantitative analysis of the prediction results by error indicators.The centralized model is expected to perform better than the individual model because it has access to the data of all stations while the individual model only uses its own data.From the viewpoint of R 2 , the prediction results of the centralized model for all power stations are higher than those of the individual model, and the maximum increase of R 2 is 2.8%.Meanwhile, from the perspective of the other three indicators, the accuracy of the centralized model is similar to that of the individual model.This demonstrates that despite the pain of gathering data and the risk of data leakage, the augmentation of the dataset empowers the centralized model to predict more accurately.However, the proposed BFL achieves the better performance on the MSE and RMSE indicators than the other models without a trade-off in privacy.Although the BFL model on Station D is larger than the individual model by 18.8% and is larger than the centralized model by 18.5% on the MAE indicator, the RMSE decreases by 13.6% and 14.1%, respectively, and the R 2 especially increases by 4.0% and 2.4%, respectively.Despite certain shortcomings in performance as indicated by the MAE and R 2 metrics, the BFL model has demonstrated a significant improvement in performance according to the MSE and RMSE metrics.The reason for the comparatively lower performance on Station D compared to Station A/B/C may be attributed to the presence of more noise in the data from Station D. But from a comprehensive perspective where all metrics are taken into account, the BFL model could achieve similar or even higher accuracy than the other models.
Figure 8 shows the comparison of prediction results and actual power generation.The attention paid to the actual data quality of Station D is different from that of the other stations, evident from the observed curve.It can be found that there is a discernible gap between the prediction results of the individual model and the centralized model compared with the actual power generation.Moreover, the obvious anomalies emerge in the prediction for the Station D due to the difference of data quality.On the contrary, the prediction results of our BFL model are not only close to the actual power generation but also perform well under abnormal conditions.
In contrast, the prediction results of our BFL model not only closely align with the actual power generation but also demonstrate robust performance under abnormal conditions.6.2.Experiments for Trading Performance.In the Hyperledger Fabric, the transaction latency is the amount of time from the time point that transaction is submitted to the time point that the result is widely available in the network.The average latency refers to the average time taken in seconds between issuing a transaction and receiving the corresponding response [33].The sending rate is a measure of how many transactions are sent to the network in a given time period, expressed as transactions per second (TPS).It is mentioned in [34] that the average latency under different sending rates of transactions is an important metric to evaluate the performance of a blockchain system.Therefore, we decide to use the metric to evaluate The experiments are performed for the different Batch-Size with increasing the sending rate of transaction request from a client node in the same local network.The BatchSize is set to 100, 200, and 300, respectively, and the sending rate ranges from 20 TPS to 240 TPS with a 20 TPS interval.For the BatchTimeout, we set it to 1 second (minimum value) since a longer BatchTimeout will take longer to create blocks under the given sending rate.Table 7 provides a detailed reference of our experimental settings.Figure 9 shows the experimental results of the average transaction latency.The proposed BFLSC framework is able to cover the transactions well within one second, and the standard deviations are also  low until the sending rate reaches 200 TPS.However, not only the average latency but also the standard deviation increase significantly due to bottlenecks in server performance when the sending rate is above 200 TPS.
It is worth noting that the average latency increases during the sending rate ranges from 20 TPS and 40 TPS, and it decreases during the sending rate ranges from 40 TPS to 100 TPS.The reason is that it should be waited to create a block up to the BatchTimeout reached when the sending rate is low, but the block can be created without waiting when the sending rate is high and the higher the sending rate has the faster block creation.Additionally, the latency fluctuation is relatively stable during the sending rate ranges from 100 TPS to 200 TPS.This is because the time used to create a block within the BatchTimeout is relatively stable.

Conclusion
In response to the initiative of distributed generation participating in market transactions locally, this paper takes distributed PV power as the research object and proposes the BFLSC framework from the perspective of privacy protection and data security.The framework includes collaborative prediction of power generation by the BFL approach and real-time trading strategy based on smart contract.Compared to the traditional FL method, the BFL method can predict future generation more accurately while ensuring data security.Additionally, the real-time trading strategy is executed automatically by smart contract.Once the realtime power generation predicted by the BFL is obtained, the smart contract will invoke the designed graph-based algorithm to match the producers and consumers of electricity, prompting both parties to enter into power transactions.And then, the transaction information will be deposited by the blockchain.Simultaneously, the experiments implemented on the Hyperledger Fabric v2.0 network with realworld data corroborate the validity of our framework.This work has a guiding role in engineering practice for promoting the construction of blockchain-based electricity trading platform and accelerating green electricity trading.
In the current work, there are still certain limitations to the proposed approach.Optimization strategies for the performance of the blockchain network are in the exploratory stage, lacking targeted optimization measures.The latency of the blockchain network can be further reduced, and throughput can be increased.This can be achieved by designing more efficient consensus algorithms to shorten the time intervals for block generation.Additionally, optimizing the transaction processing flow and reducing the confirmation time for transactions can also enhance the scalability of the blockchain.
Faced with the shortcomings of traditional blockchain architectures in terms of scalability, throughput, latency, and other performance aspects, researchers in recent years have been exploring improvements by addressing the data structure and storage structure of blockchain.Solutions such as DAG-based blockchain and sharded blockchain have been designed.In the next phase of this research, we will continue to investigate how to achieve efficient electricity exchange on DAG-based blockchain and sharded blockchain with FL.

[ 16 ]
Proposal of a joint energy-reserve prosumer-centric market Without considering future generation capacity 3 International Journal of Energy Research where σ represents attention scoring function, w represents weight matrix, b represents bias coefficient, x i represents the input of the previous layer, h i represents the output of the previous layer and the input of the current attention mechanism layer, α i represents the value of the attention probability distribution, and y represents the output of attention mechanism layer.

Figure 2 :
Figure 2: Basic cell structure of the LSTM network.

Figure 3 :
Figure 3: The comparison of traditional FL and BFL.

Figure 4 :
Figure 4: Smart contract in the framework.

Figure 8 :
Figure 8: Prediction results of PV power stations.

1 where w f , w i , w o , w g and b f , b i , b o , b g represent the weight matrix and bias matrix of f t , i t , o t , g t , respectively, and ∘ rep- resents the Hadamard product. The process of calculation is as follows: (1) i t , o t , and g t are calculated separately. (2) c t is obtained by combining
f t and i t .(3) h t of the current network is acquired using o t .

Table 1 :
An overview of related work.

5
International Journal of Energy Research training of epoch t.Whenever the local model parameter of a node is updated, the node stores its own node ID, the number of next epoch, and the obtained new local model parameter to the distributed ledger.After that, the node waits for a time interval, denoted by t wait , in order to allow each node to determine whether the global model update can be carried out in current epoch.Once the interval reaches t wait , the node queries the amount of records where epochNum = t + 1 from the ledger.If the amount equals to K, it indicates that local model training and parameter recording have been completed on all nodes.Then, the node can gather the local model parameters of all nodes from the ledger and locally update a new global model parameter by Equation (5) which aggregates the gathered parameters based on a weighted average.Otherwise, the node has to wait for t wait time interval again until the work is done on all nodes.Overall, the whole process mentioned above including local model training, local parameter recording, and global model update is repeated until the global model training is completed.
4.1.Graph-Based Algorithm for Matching.Accurate matching of producers and consumers can better maintain the bal-

Table 2 :
A comparison between different types of blockchain.

Table 3 :
Comparison of MAE.
which directly affects the transaction latency.The Batch-Size is the desired size that is allowed in each block, and the BatchTimeout is the maximum elapsed duration for creating a block.In other words, if the size of collected transactions is less than the BatchSize, the creation of the block has to wait for the BatchTimeout.Otherwise, the block will be created directly.