Block chain fragment optimization method and system based on traffic flow prediction
By building a traffic flow prediction model and dynamically adjusting the shard configuration of the blockchain network, the problem that the existing technology is difficult to meet real-time requirements during peak periods is solved, and the processing capability and user experience of the blockchain network are improved.
Patent Information
- Application Number
- CN202510120140.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-25
- Publication Date
- 2025-05-27
AI Technical Summary
The existing technology is difficult to meet the real-time requirements of blockchain networks during peak periods, and there is a lack of solutions to apply traffic flow prediction to blockchain shard optimization.
By obtaining historical traffic flow data, a traffic flow prediction model is built, future traffic flow is predicted, and the sharding adjustment mechanism is triggered based on real-time running data, and the sharding configuration of the blockchain network is dynamically adjusted.
It improves the processing power of the blockchain network, enhances scalability, avoids transaction accumulation and network congestion, shortens transaction confirmation time, improves user experience, and saves resources.
Smart Images

Figure CN120048104A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of traffic blockchain, and more specifically, to a blockchain sharding optimization method and system based on traffic flow prediction. Background Art
[0002] Due to its characteristics such as decentralization and immutability, blockchain technology has been widely used in the traffic field, such as using blockchain to store traffic data and share vehicle networking information. However, with the dynamic changes in traffic flow, the existing blockchain networks are prone to performance bottlenecks during peak periods and are difficult to meet real-time requirements.
[0003] Chinese Patent Application with Publication No. CN117671961A discloses a method and system for predicting the traffic flow state of urban road traffic based on blockchain. This method encrypts traffic data through the SHA-256 algorithm and combines technologies such as graph neural networks and time series analysis to improve the accuracy of traffic flow prediction. However, this method mainly focuses on traffic flow prediction and does not consider the application of prediction results in blockchain performance optimization. Chinese Patent Application with Publication No. CN118139050A discloses a method for sharing vehicle networking information based on blockchain sharding technology. This method uses the DPOS-VBFT consensus to record vehicle reputation and supports vehicle migration between shards. However, the sharding scheme of this method is static and cannot be dynamically adjusted according to changes in traffic flow.
[0004] In summary, most of the existing technologies only focus on traffic flow prediction or vehicle networking information sharing, lacking a solution to apply traffic flow prediction to blockchain sharding optimization. Summary of the Invention
[0005] In order to overcome the above-mentioned defects of the prior art, the present invention provides a blockchain sharding optimization method and system based on traffic flow prediction to adapt to changes in traffic flow and improve the processing capacity of the blockchain network.
[0006] To achieve the above object, the present invention provides the following technical solutions:
[0007] A blockchain sharding optimization method based on traffic flow prediction, comprising:
[0008] Obtain the first historical traffic flow data of the target blockchain network, obtain the first traffic flow characteristics based on the first historical traffic flow data, construct a traffic flow prediction model, and obtain the first predicted traffic flow data according to the first traffic flow characteristics and the traffic flow prediction model; the first predicted traffic flow data includes predicted transaction density, predicted transaction burst index, and predicted transaction mean;
[0009] Obtain the real-time operation data of the target blockchain network, obtain the second traffic flow characteristics according to the real-time operation data, compare the second traffic flow characteristics with a preset threshold, and trigger a sharding adjustment mechanism according to the comparison result; the thresholds include a transaction density threshold, a transaction burst threshold, and a transaction mean threshold;
[0010] After triggering the sharding adjustment mechanism, generate and optimize a sharding adjustment plan according to the first predicted traffic flow data and the second traffic flow characteristics, and dynamically adjust the sharding configuration of the target blockchain network.
[0011] Further, the obtaining of the first historical traffic flow data of the target blockchain network includes:
[0012] Obtain the transaction data of the target blockchain network in the past period of time, where the transaction data includes the number of transactions, transaction frequency, and transaction size;
[0013] Arrange the obtained transaction data in chronological order to form a transaction number time series, a transaction frequency time series, and a transaction size time series;
[0014] Use the transaction number time series, the transaction frequency time series, and the transaction size time series as the first historical traffic flow data;
[0015] The first traffic flow characteristics include the first transaction density, the first transaction burst index, and the first transaction mean;
[0016] Further, the second traffic flow characteristics include the second transaction density, the second transaction burst index, and the second transaction mean;
[0017] The comparing the second traffic flow characteristics with a preset threshold and triggering a sharding adjustment mechanism according to the comparison result includes: if the second transaction density exceeds the preset transaction density threshold, or the second transaction burst index exceeds the preset transaction burst threshold, or the second transaction mean exceeds the preset transaction mean threshold, then trigger the sharding adjustment mechanism;
[0018] Further, the generating and optimizing a sharding adjustment plan according to the first predicted traffic flow data and the second traffic flow characteristics includes:
[0019] Dynamically adjust the number of shards and the shard capacity of the target blockchain network according to the first predicted traffic flow data, combined with the second traffic flow characteristics, to generate a sharding adjustment plan;
[0020] After generating the sharding adjustment plan, continuously collect the operation data of the target blockchain network, obtain the second historical traffic flow data of the target blockchain network, perform feature extraction on the second historical traffic flow data to obtain the third traffic flow characteristics; dynamically calibrate the traffic flow prediction model according to the third traffic flow characteristics to obtain a calibrated traffic flow prediction model;
[0021] Use the calibrated traffic flow prediction model to perform a secondary prediction on the traffic flow within a future period to obtain second predicted traffic flow data; the second predicted traffic flow data includes a second predicted transaction density, a second predicted transaction burst index, and a second predicted transaction mean; the second predicted traffic flow data covers the same future time period as the first predicted traffic flow data.
[0022] After generating the shard adjustment plan, obtain the second real-time operation data of the target blockchain network, and obtain the fourth traffic flow feature according to the second real-time operation data; optimize the shard adjustment plan according to the second predicted traffic flow data and the fourth traffic flow feature to obtain an optimized shard adjustment plan, where the optimized shard adjustment plan includes an optimized number of shards, an optimized shard capacity requirement, an optimized number of new shards, and an optimized capacity adjustment value.
[0023] Further, the method for generating a shard adjustment plan according to the first predicted traffic flow data and combining the second traffic flow feature includes:
[0024] Calculate the number of shards N required within a future period according to the predicted transaction density, predicted transaction burst index, and predicted transaction mean in the first predicted traffic flow data f ;
[0025] Calculate the shard capacity requirement C of each shard within the current period according to the second transaction density, second transaction burst index, and second transaction mean in the second traffic flow feature s ;
[0026] According to the calculated number of shards N required in the future f and the shard capacity requirement C of each shard s Determine the shard adjustment plan, where the shard adjustment plan includes the number of shards N f and the shard capacity requirement C of each shard s , the number of new shards, and the capacity adjustment value of each shard.
[0027] Further, the method for calculating the number of shards N required within a future period according to the predicted transaction density, predicted transaction burst index, and predicted transaction mean in the first predicted traffic flow data f is:
[0028] Obtain the number of transactions λ' generated in the network within a period, the average transaction processing delay τ', and the transaction processing throughput μ' of the network, and calculate the network load index γ'.
[0029] Calculate the shard number requirement within a future period from the predicted transaction density, predicted transaction burst index, predicted transaction mean, and network load index.
[0030] Further, the method for obtaining the optimized shard adjustment plan according to the second predicted traffic flow data and the fourth traffic flow characteristics includes:
[0031] Calculating a second shard number N according to the second predicted traffic flow data f2 ;
[0032] Calculating a second shard capacity requirement C according to the fourth traffic flow characteristics s2 ;
[0033] If |N f2 - N f | ≤ N θ , then take N f as the optimized shard number; if |N f2 - N f | > N θ , then take as the optimized shard number; where N θ is a preset shard number deviation threshold, is the ceiling function;
[0034] If |C s2 - C s | ≤ C θ , then take C s as the optimized shard capacity requirement; if |C s2 - C s | > C θ , then take as the optimized shard capacity requirement; where C θ is a preset shard capacity deviation threshold;
[0035] A blockchain shard optimization system based on traffic flow prediction, which is used to implement the above-mentioned blockchain shard optimization method based on traffic flow prediction. The system includes:
[0036] Traffic flow prediction module: used to obtain the first historical traffic flow data of the target blockchain network, obtain the first traffic flow characteristics based on the first historical traffic flow data, construct a traffic flow prediction model, and obtain the first predicted traffic flow data according to the first traffic flow characteristics and the traffic flow prediction model; the first predicted traffic flow data includes predicted transaction density, predicted transaction burst index, and predicted transaction mean;
[0037] Sharding adjustment trigger module: used to obtain the real-time operation data of the target blockchain network, obtain the second traffic flow feature according to the real-time operation data, compare the second traffic flow feature with a preset threshold, and trigger the sharding adjustment mechanism according to the comparison result; the thresholds include a transaction density threshold, a transaction burst threshold, and a transaction mean threshold;
[0038] Sharding adjustment module: used to generate and optimize a sharding adjustment plan according to the first predicted traffic flow data and the second traffic flow feature after triggering the sharding adjustment mechanism, and dynamically adjust the sharding configuration of the target blockchain network.
[0039] An electronic device includes a memory, a central processing unit, and a computer program stored on the memory and executable on the central processing unit. When the central processing unit executes the computer program, it implements the above-mentioned blockchain sharding optimization method based on traffic flow prediction.
[0040] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0041] The present invention predicts the traffic flow in the future for a period of time and dynamically adjusts the sharding strategy accordingly. It can increase the number of shards in advance during the traffic peak period to relieve the processing pressure; reduce the number of shards during the traffic trough period to save computing resources; this sharding method dynamically optimized according to actual needs effectively improves the processing capacity of the blockchain network, enhances the scalability, and enables it to adapt to the dynamic changes in the transaction volume. By predicting the traffic flow in advance and adjusting the sharding strategy, the present invention can increase the number and capacity of shards in advance before the traffic flow surges; to a certain extent, this avoids transaction backlogs and network congestion, thereby shortening the transaction confirmation time and improving the user experience; at the same time, sharding optimization can also balance the load of each shard and avoid the saturation of the processing capacity of individual shards affecting the entire network. Through traffic flow prediction and sharding optimization, the present invention reduces unnecessary resource waste while ensuring performance; dynamically adjusting the number and capacity of shards can release redundant computing and storage resources during the traffic trough period, saving operating expenses. At the same time, the automatic generation and optimization of the sharding plan reduce the burden of manual configuration and maintenance and improve the operation and maintenance efficiency. Description of the Drawings
[0042] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0043] Figure 1 It is the principle flow chart of the blockchain sharding optimization method based on traffic flow prediction in the present invention;
[0044] Figure 2 This is the flowchart of the method for obtaining the first historical traffic flow data of the target blockchain network in the blockchain sharding optimization method based on traffic flow prediction of the present invention;
[0045] Figure 3 This is the flowchart of the method for obtaining the first traffic flow feature according to the first historical traffic flow data in the blockchain sharding optimization method based on traffic flow prediction of the present invention;
[0046] Figure 4 This is the flowchart of the method for obtaining the second traffic flow feature according to the real-time operation data in the blockchain sharding optimization method based on traffic flow prediction of the present invention;
[0047] Figure 5 This is the flowchart of the method for generating a shard adjustment plan according to the first predicted traffic flow data and the second traffic flow feature in the blockchain sharding optimization method based on traffic flow prediction of the present invention;
[0048] Figure 6 This is the functional module diagram of the blockchain sharding optimization system based on traffic flow prediction in the present invention. Detailed implementation manners
[0049] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0050] Embodiment 1
[0051] Please refer to Figure 1 As shown, this embodiment provides a blockchain sharding optimization method based on traffic flow prediction, including:
[0052] Step S1000, obtaining the first historical traffic flow data of the target blockchain network, obtaining the first traffic flow feature based on the first historical traffic flow data, constructing a traffic flow prediction model, and obtaining the first predicted traffic flow data according to the first traffic flow feature and the traffic flow prediction model.
[0053] Further, step S1000 includes:
[0054] Step S1100, obtaining the first historical traffic flow data of the target blockchain network;
[0055] Further, as Figure 2 shown, step S1100 includes:
[0056] Step S1110: Obtain the transaction data of the target blockchain network over a past period of time, where the transaction data includes the number of transactions, transaction frequency, and transaction size.
[0057] Step S1120: Arrange the obtained transaction data in chronological order to form a time series of the number of transactions, a time series of transaction frequency, and a time series of transaction size.
[0058] Step S1130: Use the time series of the number of transactions, the time series of transaction frequency, and the time series of transaction size as the first historical traffic flow data.
[0059] Specifically, step S1100 obtains time series data reflecting traffic flow changes by collecting the transaction data of the blockchain network over a historical period of time. First, information such as the number of transactions, transaction frequency, and transaction size is extracted from the transaction records of the blockchain network. The number of transactions represents the total number of transactions that occurred within a certain time period, the transaction frequency represents the number of transactions occurring per unit time, and the transaction size represents the data volume of each transaction. Then, these data are arranged in chronological order to form a time series of the number of transactions, a time series of transaction frequency, and a time series of transaction size. Each time series reflects the changes of the corresponding indicators at different moments. Finally, the three generated time series are used as the first historical traffic flow data, providing a data basis for subsequent analysis and modeling. The historical traffic flow data obtained in this way can comprehensively reflect the load characteristics and change rules of the blockchain network over a past period of time, laying a data foundation for traffic flow prediction and sharding optimization. At the same time, converting the transaction data into a time series form not only intuitively shows the change trend of traffic flow over time but also facilitates the application of time series analysis and prediction models.
[0060] Step S1200: Analyze the first historical traffic flow data to obtain the first traffic flow characteristics; the first traffic flow characteristics include the first transaction density, the first transaction burst index, and the first transaction mean.
[0061] Further, as Figure 3 shown, step S1200 includes:
[0062] Step S1210: Calculate the number of transactions in each time period of the first historical traffic flow data to obtain the first transaction density.
[0063] Step S1220: Calculate the fluctuation of the transaction frequency in the first historical traffic flow data to obtain the first transaction burst index.
[0064] Step S1230: Calculate the average value of the transaction size in the first historical traffic flow data to obtain the first transaction mean.
[0065] Step S1240: taking the first transaction density, the first transaction burst index and the first transaction mean as the first traffic flow feature.
[0066] Specifically, step S1200 extracts key indicators that can characterize the characteristics of traffic flow by statistically analyzing the first historical traffic flow data. The first transaction density reflects the number of transactions processed by the blockchain network per unit time, and is obtained by calculating the total number of transactions in each time period. The first transaction burst index reflects the degree of fluctuation of the transaction frequency, and is obtained by calculating the coefficient of variation (the ratio of the standard deviation to the mean) of the transaction frequency time series. The larger the burst index, the more violent the transaction frequency fluctuation and the more unstable the traffic flow. The first transaction mean reflects the average level of transaction size, and is obtained by averaging the transaction size time series. Finally, the three calculated indicators are used as the first traffic flow characteristics, which describe the traffic flow characteristics of the blockchain network from different angles. By extracting these characteristics, the overall situation and changing rules of historical traffic flow can be fully grasped, providing important input information for the subsequent prediction model construction. At the same time, indicators such as transaction density, burst index, and transaction mean are easy to calculate and understand, and can intuitively reflect multiple key attributes of traffic flow, which is convenient for practical application and analysis.
[0067] Step S1300, taking the first traffic flow feature as a model input, constructing a traffic flow prediction model, predicting the traffic flow, and obtaining first predicted traffic flow data; the first predicted traffic flow data includes predicted transaction density, predicted transaction burst index and predicted transaction mean.
[0068] Specifically, the traffic flow prediction model is trained using a long short-term memory (LSTM) neural network model to obtain a trained traffic flow prediction model; LSTM is a special type of recurrent neural network (RNN) that is particularly suitable for processing and predicting time series data. It can learn long-term dependencies and capture trends and periodicities in time series data. The basic structure of the LSTM model includes an input layer, a hidden layer (LSTM layer), and an output layer. The input layer receives the first traffic flow features, including the first transaction density, the first transaction burst index, and the first transaction mean. These features first pass through an embedding layer to map discrete variables into dense vector representations to capture the correlation between features. Then, the embedded feature sequences are sequentially input into the LSTM layer.
[0069] The LSTM layer consists of multiple LSTM units, and each unit contains an input gate, a forget gate, an output gate, and a memory cell. The input gate controls the degree to which new information enters the memory cell, the forget gate controls the degree to which past information is forgotten, and the output gate controls the degree to which the information in the memory cell is output. Through the gating mechanism, LSTM can selectively remember and forget information, thereby capturing the long-term dependencies in time series data. At each time step, the input features are first combined with the hidden state of the previous time step, and after the calculations of the input gate, forget gate, and output gate, the memory cell and hidden state are updated. This process is repeated until the entire input sequence is processed. The hidden state of the last time step contains the information of the entire sequence and is passed to the output layer. The output layer is usually a fully connected layer that converts the output of LSTM into a prediction result. For the traffic flow prediction task, the output layer predicts the transaction density, transaction burst index, and transaction mean in the future for a certain period of time.
[0070] The model training process adopts the supervised learning method. The training data includes historical traffic flow characteristics as input and the real traffic flow in the corresponding time period as labels. By minimizing the loss function (such as mean squared error) between the predicted value and the real value, the model parameters are optimized. Commonly used optimization algorithms include Stochastic Gradient Descent (SGD), Adam, etc. The trained LSTM model can predict the traffic flow in the future according to the historical traffic flow characteristics. Through the sliding window method, continuous prediction results, that is, the first predicted traffic flow data, can be generated.
[0071] The transaction density refers to the number of transactions per unit time and reflects the busyness of the blockchain network. The transaction burst index measures the mutation of the transaction density and captures the abnormal fluctuations in the transaction volume. The transaction mean represents the average transaction volume per unit time and reflects the overall transaction activity. These features comprehensively describe the traffic flow situation of the blockchain network. By using the LSTM model for traffic flow prediction, it is possible to detect in advance the possible traffic congestion or abnormal situations in the future for a certain period of time. This helps to adjust the sharding strategy in a timely manner and optimize the network performance. For example, when it is predicted that the future traffic flow will increase significantly, the number of shards can be increased in advance to disperse the transaction pressure. When it is predicted that a transaction burst may occur, more resources can be reserved to cope with the burst traffic. The LSTM model can accurately predict the future traffic conditions by learning the time dependencies and trends of the historical traffic flow. It takes into account the long-term change rules of the traffic flow and can also capture the short-term fluctuations and anomalies. This makes the prediction results more reliable and comprehensive, providing strong support for the sharding optimization decision. At the same time, the LSTM model has a certain generalization ability and can handle unseen traffic flow patterns. Through continuous training and optimization, the model can adapt to the dynamic changes of the blockchain network and continuously provide stable and reliable prediction results.
[0072] The first predicted traffic flow data includes predicted transaction density, predicted transaction burst index, and predicted transaction mean; the predicted transaction density represents the number of transactions predicted to occur in the blockchain network per unit time in the future. It reflects the total volume and frequency of transactions that the network needs to process in a future period. The predicted transaction density can estimate in advance the future transaction processing pressure and load level. By predicting the future transaction density, it can be determined whether the existing blockchain network processing capacity is sufficient and whether it is necessary to increase the number of shards to improve the transaction throughput. At the same time, the change trend of the transaction density also provides a reference for the dynamic adjustment of the shard capacity. The predicted transaction burst index measures the possible transaction burst situations in the blockchain network in a future period. It quantifies the fluctuation degree of the transaction density by calculating the ratio of the standard deviation to the mean of the transaction frequency within the predicted time window. The predicted transaction burst index can detect in advance the possible future transaction peaks and burst traffic. When the predicted transaction burst index is high, it indicates that there may be a drastic fluctuation in the transaction density in the network in a future period, and a large number of transactions will pour in in a short time. In this case, it is necessary to adjust the shard configuration in advance, increase the shard capacity and processing ability to cope with the possible transaction congestion. The predicted transaction mean represents the average data volume of each transaction in the blockchain network per unit time in the future. It reflects the scale of transaction data that the network needs to process in a future period. The predicted transaction mean can estimate in advance the future transaction data processing pressure. By predicting the average data volume of each future transaction, it can be determined whether the existing blockchain network transmission and storage capabilities match. When the predicted transaction mean is high, it indicates that the future transaction data scale is large, which may put pressure on the network bandwidth and storage space, and it is necessary to optimize the shard configuration to improve the network's data processing ability.
[0073] In summary, using the LSTM neural network to construct a traffic flow prediction model can effectively predict the traffic flow situation in a future period. By taking the first transaction density, the first transaction burst index, and the first transaction mean as the model inputs, LSTM can learn the time-dependent relationship and change law of the traffic flow. The trained model can predict the future transaction density, transaction burst index, and transaction mean, providing a decision-making basis for the shard optimization of the blockchain network. This prediction-driven shard optimization method can anticipate potential traffic congestion in advance and dynamically adjust the shard strategy, thereby improving the overall performance and throughput of the blockchain network.
[0074] Step S1000 starts with the acquisition of historical traffic flow data, extracts key traffic features through data analysis, and uses machine learning algorithms to construct a traffic flow prediction model. The acquisition and analysis of historical data are the basis for building the prediction model. By processing information such as transaction quantity, frequency, and size, time-series data and statistical indicators that comprehensively reflect the characteristics of traffic flow are generated. On this basis, machine learning algorithms are used to learn the changing patterns of historical traffic flow, and a mathematical model with predictive ability is established. These steps are closely linked and jointly construct the prediction framework for blockchain traffic flow, providing important data support and decision-making basis for subsequent sharding optimization. By predicting future traffic conditions, the sharding configuration can be adjusted in advance to achieve dynamic matching between the processing capacity of the blockchain network and the load demand, improving the overall performance. At the same time, the prediction model can be continuously optimized and updated to continuously improve the prediction accuracy and provide more reliable reference information for sharding optimization.
[0075] In step S2000, the real-time operation data of the target blockchain network is obtained, the second traffic flow feature is obtained according to the real-time operation data, the second traffic flow feature is compared with a preset threshold, and the sharding adjustment mechanism is triggered according to the comparison result.
[0076] Furthermore, step S2000 includes:
[0077] In step S2100, the real-time operation data of the target blockchain network is obtained, and the second traffic flow feature is obtained according to the real-time operation data; the second traffic flow feature includes the second transaction density, the second transaction burst index, and the second transaction mean.
[0078] Furthermore, as Figure 4 shown, step S2100 includes:
[0079] In step S2110, the real-time operation data of the current target blockchain network is collected;
[0080] In step S2120, statistical analysis is performed on the collected real-time operation data, the transaction density within the current time period is calculated, and the second transaction density is obtained;
[0081] In step S2130, burstiness analysis is performed on the collected real-time operation data, the transaction frequency fluctuation within the current time period is calculated, and the second transaction burst index is obtained;
[0082] In step S2140, mean value analysis is performed on the collected real-time operation data, the average transaction size within the current time period is calculated, and the second transaction mean is obtained;
[0083] In step S2150, the second transaction density, the second transaction burst index, and the second transaction mean are used as the second traffic flow feature.
[0084] Specifically, in step S2100, by monitoring the running status of the blockchain network in real time, key indicators reflecting the current traffic flow (transaction quantity, transaction frequency, and transaction size) are obtained. Through the monitoring interface provided by the blockchain network, running data including transaction quantity, transaction frequency, and transaction size are collected in real time. Statistical analysis is performed on the collected real-time running data. The transaction density in the current time period is calculated by dividing the total number of transactions occurring in this time period by the length of this time period, obtaining the second transaction density, which reflects the transaction processing capacity of the current network. Through burst analysis of the real-time transaction frequency, the number of transactions in this time period is divided into multiple smaller sub-time periods. For example, one hour is divided into sub-segments of each minute, the number of transactions in each sub-time period is calculated, the standard deviation and mean of the number of transactions in these sub-time periods are calculated, and the standard deviation is divided by the mean to calculate the fluctuation of transaction occurrence in the current time period, obtaining the second transaction burst index, which reflects the burst degree of current network transactions. Mean analysis is performed on the real-time transaction size, and the average data volume of each transaction in the current time period is calculated, obtaining the second transaction mean, which reflects the data scale of current network transactions. Finally, the three calculated indicators are used as the second transaction flow characteristics, comprehensively describing the real-time traffic conditions of the blockchain network. Obtaining these traffic flow characteristics in real time can accurately grasp the current load level and transaction characteristics of the network, providing a reliable judgment basis for triggering the sharding adjustment mechanism. At the same time, the monitoring and analysis of real-time data can quickly detect network anomalies and performance bottlenecks, providing support for timely taking optimization measures. By continuously monitoring the traffic flow indicators, dynamic perception and real-time control of the running status of the blockchain network can be achieved, providing a data basis for sharding optimization.
[0085] In step S2200, the second traffic flow characteristics are compared with preset thresholds, and the sharding adjustment mechanism is triggered according to the comparison results; the thresholds include a transaction density threshold, a transaction burst threshold, and a transaction mean threshold.
[0086] Furthermore, step S2200 includes:
[0087] In step S2210, the second transaction density is compared with the preset transaction density threshold. When the second transaction density exceeds the preset transaction density threshold, the sharding adjustment mechanism is triggered;
[0088] In step S2220, the second transaction burst index is compared with the preset transaction burst threshold. When the second transaction burst index exceeds the preset transaction burst threshold, the sharding adjustment mechanism is triggered;
[0089] In step S2230, the second transaction mean is compared with the preset transaction mean threshold. When the second transaction mean exceeds the preset transaction mean threshold, the sharding adjustment mechanism is triggered;
[0090] Step S2240: When any of the conditions in Steps S2210, S2220, and S2230 is satisfied, trigger the shard adjustment mechanism.
[0091] Specifically, in Step S2200, by comparing the real-time traffic flow characteristics with the preset thresholds, it is determined whether to trigger the shard adjustment mechanism. Reasonable preset thresholds for transaction density, transaction burst, and transaction mean are set, and these thresholds reflect the upper limit of the traffic flow for the normal operation of the blockchain network. When the second transaction density detected in real time exceeds the preset transaction density threshold, it indicates that the transaction processing capacity of the current network is approaching saturation, and it is necessary to adjust the shard configuration to improve the processing capacity, so the shard adjustment mechanism is triggered. Similarly, when the second transaction burst index exceeds the preset transaction burst threshold, it indicates that a large number of burst transactions have occurred in the current network, which may lead to network congestion and performance degradation, and shard adjustment is required to alleviate it, so the shard adjustment mechanism is triggered. When the second transaction mean exceeds the preset transaction mean threshold, it indicates that a large number of large-scale transactions have occurred in the current network, which may occupy too much bandwidth and computing resources, so it is necessary to trigger the shard adjustment mechanism to handle these large-scale transactions by increasing the number and capacity of shards. Considering the three indicators comprehensively, when any one of the indicators exceeds the threshold, the shard adjustment will be triggered to respond to the abnormal situation of the network in a timely manner. Through real-time monitoring and threshold comparison, it can be accurately determined whether the network needs to be optimized for sharding, improving the timeliness and pertinence of shard adjustment.
[0092] Step S3000: After triggering the shard adjustment mechanism, generate and optimize the shard adjustment plan based on the first predicted traffic flow data and the second traffic flow characteristics, and dynamically adjust the shard configuration of the target blockchain network.
[0093] Furthermore, Step S3000 includes:
[0094] Step S3100: After triggering the shard adjustment mechanism, dynamically adjust the number and capacity of shards of the target blockchain network based on the first predicted traffic flow data and combined with the second traffic flow characteristics, and generate a shard adjustment plan;
[0095] Furthermore, Step S3100 includes:
[0096] Step S3110: Calculate the required number of shards N within a future period according to the predicted transaction density, predicted transaction burst index, and predicted transaction mean in the first predicted traffic flow data f ;
[0097] Step S3120: Calculate the shard capacity requirement C for each shard within the current period according to the second transaction density, second transaction burst index, and second transaction mean in the second traffic flow characteristics s ;
[0098] Step S3130, according to the calculated future required number of shards N f and the shard capacity requirement C for each shard s determine the shard adjustment plan, where the shard adjustment plan includes the number of shards N f , the shard capacity requirement C for each shard s , the number of newly added shards and the capacity adjustment value for each shard.
[0099] Specifically, step S3100 dynamically adjusts the shard configuration of the blockchain network by comprehensively considering the predicted future traffic flow and real-time traffic flow characteristics. First, according to the predicted transaction density, predicted transaction burst index, and predicted transaction mean in the first predicted traffic flow data, estimate the number of shards required by the blockchain network in a future period. The predicted transaction density reflects the future transaction processing pressure, the predicted transaction burst index reflects the possible transaction peaks, and the predicted transaction mean reflects the data scale of the transactions. By synthesizing these three indicators, the number of shards required in a future period to ensure network performance can be estimated.
[0100] Secondly, according to the second transaction density, second transaction burst index, and second transaction mean in the second traffic flow characteristics, calculate the capacity requirement for each shard in the current period. The second transaction density reflects the number of transactions that each shard needs to process currently, the second transaction burst index reflects the requirements for shard capacity due to the current transaction burst degree, and the second transaction mean reflects the requirements for shard capacity due to the current transaction data scale. By synthesizing these three indicators, the capacity size required for each shard in the current period can be obtained, that is, the computing resources, storage resources, bandwidth resources, etc. that need to be configured for each shard to ensure the current network performance.
[0101] Finally, obtain the shard adjustment plan based on the estimated future required number of shards and the calculated current shard capacity requirement. If the estimated future required number of shards is greater than the current number of shards, the number of newly added shards needs to be included in the shard adjustment plan; if the current shard capacity requirement is greater than the existing shard capacity, the capacity adjustment value for each shard needs to be included in the shard adjustment plan. The shard adjustment plan stipulates the specific adjustment measures for the shard configuration of the blockchain network in a future period.
[0102] This method of dynamically adjusting the sharding configuration can make the number and capacity of shards match the expected traffic flow. When it is predicted that the future traffic flow will increase, increasing the number of shards in advance can prepare for the increase in transaction volume before the transaction volume rises, and improve the network's concurrent processing ability. When it is predicted that there may be a transaction peak, increasing the shard capacity in advance can better handle the sudden traffic and avoid performance degradation. At the same time, dynamically adjusting the shard capacity in combination with the real-time traffic flow characteristics can keep the sharding configuration synchronized with the current network state and improve resource utilization efficiency. This method for generating the sharding adjustment scheme comprehensively considers future traffic prediction and real-time traffic characteristics, and can improve network throughput while taking into account the stability and performance of the network.
[0103] The method for calculating the number of shards required in a future period according to the predicted transaction density, predicted transaction burst index, and predicted transaction mean in the first predicted traffic flow data is as follows:
[0104] Obtain the number of transactions λ' generated in the network within a period of time, the average transaction processing delay τ', and the transaction processing throughput μ' of the network, and calculate the network load index γ';
[0105]
[0106] λ' is the number of transactions per unit time, which can be calculated by monitoring the number of transactions generated in the blockchain network. The higher the transaction density, the greater the transaction volume processed by the network and the corresponding increase in load. The average transaction processing delay τ' refers to the average time required for a transaction to be confirmed from the start within a period of time, which is obtained by recording the processing time of each transaction and calculating the average value within this period. The greater the delay, the lower the efficiency of the network in processing transactions, indicating that there may be congestion, thus increasing the load. The transaction processing throughput μ' of the network refers to the number of transactions that the network can process per unit time within a period of time, which is estimated by monitoring the number of successfully processed transactions in the network. The stronger the processing ability, the faster the network can process transactions and reduce the load index.
[0107] The calculation formula for the network load index can effectively measure the current network load situation by combining transaction density, transaction processing delay, and network processing ability. The parameters λ', τ', and μ' in the formula can all be monitored in real time, so that the load index can dynamically reflect the network state and help adjust the number and capacity of network shards in a timely manner; as the transaction density λ' or processing delay τ' increases, the load index γ' will rise, indicating an increase in network pressure; on the contrary, when the processing ability μ' increases, the load index will decrease, indicating a reduction in the network's processing pressure.
[0108] Calculate the shard number requirements in a future period based on the predicted transaction density, predicted transaction burst index, predicted transaction mean, and network load index;
[0109]
[0110] Wherein:
[0111] N f : The number of shards required in a future period of time.
[0112] λ p : The predicted transaction density, i.e., the expected number of transactions per unit time in a future time period.
[0113] σ p : The predicted transaction burst index, i.e., a measure of the burstiness of future transactions.
[0114] α: The burstiness weighting factor, indicating the impact of the burst index on the shard demand.
[0115] β: The transaction processing efficiency factor, reflecting the regulatory role of processing capacity on the shard demand.
[0116] ξ p : The predicted transaction mean, i.e., the average level of transaction size.
[0117] δ t : The length of the future time period.
[0118] ρ f : The processing capacity per shard, indicating the processing capacity of each shard per unit time.
[0119] M p : The transaction mean adjustment factor, used to reflect the impact of the transaction mean on the shard demand.
[0120] Ceiling function to ensure the number of shards is an integer.
[0121] The higher the transaction density, the more transactions may occur in the future, and more shards will be needed to process them. The higher the burst index, the greater the fluctuation of transaction traffic, and more shards may be needed to cope with burst traffic. The burst weighting factor α adjusts the weight of the transaction burst index on the shard demand, which is obtained by technicians in this field through historical data analysis and model optimization. By adjusting this parameter, the influence of burstiness on the calculation of shard demand can be controlled. The transaction processing efficiency factor β is obtained by analyzing historical transaction processing capabilities and network performance. The higher the processing efficiency, the fewer shards are required, and vice versa. The transaction processing throughput μ' indicates the maximum transaction processing capacity of the network in the current time period, which is obtained through network performance testing and real-time monitoring. The higher the throughput, the stronger the network processing capacity, and the number of shards required may be reduced. The higher the network load index γ', the higher the pressure on the current network, and more shards may be needed to share the load. The predicted transaction mean ξ p Indicates the average size of each transaction in the future time period. The larger the transaction mean, the more processing resources a single transaction may occupy, increasing the demand for sharding. The length of the future time period δ t To predict the length of the time window, set the time period length according to demand. The longer the time period, the higher the transaction volume and load demand may be, requiring more shards. The processing capacity of a unit shard is ρ f Obtained through sharding performance testing, the stronger the processing capacity, the more transactions a single shard can process, and the number of shards required is reduced; transaction mean adjustment factor M p The transaction mean adjustment factor is obtained by technical personnel in this field through historical data analysis and model optimization. It takes into account the impact of transaction size on network load. The larger the transaction mean, the higher the sharding requirement.
[0122] This formula fully considers multiple factors such as transaction density, burstiness, transaction mean and network load, and can accurately calculate the number of shards required in the future. Through dynamic adjustment, the resource allocation of the blockchain network can be optimized, the network's responsiveness and stability can be improved, and resource waste or network overload can be avoided.
[0123] Calculating the shard capacity requirement of each shard in the current time period according to the second transaction density, the second transaction burst index, and the second transaction mean in the second traffic flow characteristic includes:
[0124]
[0125] in:
[0126] C s : The shard capacity requirement for each shard during the current time period.
[0127] λ c : The second transaction density.
[0128] σ c : The second transaction burst index.
[0129] γ': The network load index, reflecting the current network load level.
[0130] ξ c : The second transaction mean, that is, the average level of transaction size.
[0131] θ s : The sharding efficiency factor, indicating the actual processing capacity of each shard.
[0132] μ': The transaction processing throughput of the network, representing the maximum transaction processing capacity of the network within the current time period.
[0133] M c : The second transaction mean adjustment factor, used to reflect the impact of the transaction mean on the shard capacity requirement.
[0134] The second transaction density λ c is the number of transactions per unit time within the current time period. The higher the transaction density, the greater the shard capacity required; the second transaction burst index σ c reflects the degree of transaction burstiness within the current time period. The higher the burst index, the greater the shard capacity may be required to handle the burst traffic; the second transaction mean ξ c is the average size of each transaction within the current time period. The larger the transaction mean, the more processing resources a single transaction may occupy, increasing the shard capacity requirement; the sharding efficiency factor θ s is obtained through sharding performance testing and real-time data analysis. The higher the sharding efficiency, the more transactions can be processed with the same resources, and the required capacity is reduced; the second transaction mean adjustment factor M c is used to adjust the impact of the transaction mean on the shard capacity requirement, and is obtained by those skilled in the art through historical data analysis and model optimization. The transaction mean adjustment factor takes into account the impact of transaction size on network load. The larger the transaction mean, the higher the shard capacity requirement.
[0135] This formula dynamically calculates the shard capacity requirement of each shard within the current time period, considering multiple factors such as transaction density, burstiness, transaction mean, and network load, which helps to optimize shard resource allocation, improve network response ability and stability, and avoid resource waste or network overload.
[0136] Step S3200, after generating the shard adjustment plan, continuously collect the operation data of the target blockchain network, obtain the second historical traffic flow data of the target blockchain network, extract the features of the second historical traffic flow data to obtain the third traffic flow feature; dynamically calibrate the traffic flow prediction model according to the third traffic flow feature to obtain the calibrated traffic flow prediction model;
[0137] Specifically, feature extraction is performed on the second historical traffic flow data to extract the third traffic flow features and update the training data set of the traffic flow prediction model; the third traffic flow features include the third transaction density, the third transaction burst index, and the third transaction mean; using the updated training data set, the parameters of the traffic flow prediction model are calibrated by means of incremental learning to obtain a calibrated traffic flow prediction model; the second historical traffic flow data reflects the latest changes in the blockchain network traffic flow after the application of the sharding adjustment scheme. The updated training data set not only contains the historical data initially used to train the prediction model but also the latest traffic flow data after the application of the sharding adjustment scheme. This way of dynamically updating the training data enables the prediction model to continuously learn the latest traffic characteristics of the blockchain network. Incremental learning is a machine learning paradigm that fine-tunes the model using new data while retaining the existing knowledge. Specifically, based on the existing prediction model, some model parameters are fixed, and the other part of the model parameters are retrained using the updated training data set. This approach can make the model adapt to the latest traffic flow characteristics without losing the original knowledge. After incremental learning, a calibrated traffic flow prediction model is obtained.
[0138] The method of dynamically calibrating the prediction model can effectively improve the accuracy and adaptability of the prediction. Over time, the traffic flow characteristics of the blockchain network may change, and the original prediction model may not be able to adapt well to the new situation. By continuously collecting the latest historical traffic flow data and using it to dynamically calibrate the prediction model, the prediction model can capture the new characteristics of the traffic flow in a timely manner, improving the timeliness of the prediction. At the same time, incremental learning on the basis of retaining the original knowledge can prevent the prediction model from "forgetting" the existing knowledge and improve the stability of the prediction. The calibrated prediction model can more accurately predict the future traffic flow, providing reliable data support for optimizing the sharding adjustment scheme.
[0139] Step S3300, using the calibrated traffic flow prediction model to perform a secondary prediction on the traffic flow in a future period to obtain second predicted traffic flow data; the second predicted traffic flow data includes the second predicted transaction density, the second predicted transaction burst index, and the second predicted transaction mean; the second predicted traffic flow data covers the same future time period as the first predicted traffic flow data;
[0140] Specifically, in step S3300, the calibrated traffic flow prediction model is used to perform a secondary prediction on the traffic flow within a future period of time. First, determine the time span of the secondary prediction to be the same as that when generating the first predicted traffic flow data. This can ensure that the results obtained from the secondary prediction correspond to the same future time period as the previous prediction results, facilitating subsequent comparison and analysis. Using the calibrated traffic flow prediction model, predict traffic flow characteristics such as transaction density, transaction burst index, and transaction mean within a future period of time to obtain the second predicted transaction density, the second predicted transaction burst index, and the second predicted transaction mean. Similar to the previous prediction process, by inputting historical traffic flow data into the calibrated prediction model, the predicted values of future traffic flow characteristics are obtained. Since the prediction model has been dynamically calibrated, the prediction results will be more accurate than the initial prediction and can better reflect the latest traffic flow change trend of the blockchain network.
[0141] Merge the predicted second predicted transaction density, the second predicted transaction burst index, and the second predicted transaction mean to generate the second predicted traffic flow data. The second predicted traffic flow data, like the first predicted traffic flow data, is also a prediction of the overall traffic flow within a future period of time, but is obtained using the calibrated prediction model. It covers the same future time period as the first predicted traffic flow data and reflects the expected change in the traffic flow of the blockchain network after applying the initially generated shard adjustment plan.
[0142] Through the secondary prediction, after dynamically adjusting the shard configuration, the traffic flow situation within a future period of time can be re-evaluated. Since there may be a certain deviation between the actual operation of the blockchain network and the expectation after generating the first predicted traffic flow data, the original shard adjustment plan may be difficult to fully meet the actual needs. Using the dynamically calibrated prediction model for secondary prediction can correct the original prediction results based on the latest historical traffic flow data to obtain a more realistic future traffic flow expectation. The second predicted traffic flow data obtained from the secondary prediction can provide a more reliable basis for optimizing the shard adjustment plan, helping to further improve the rationality and effectiveness of the shard configuration.
[0143] In step S3400, after generating the shard adjustment plan, obtain the second real-time operation data of the target blockchain network, and obtain the fourth traffic flow characteristic based on the second real-time operation data; optimize the shard adjustment plan according to the second predicted traffic flow data and the fourth traffic flow characteristic to obtain the optimized shard adjustment plan, where the optimized shard adjustment plan includes the optimized number of shards, the optimized shard capacity requirement, the optimized number of newly added shards, and the optimized capacity adjustment value.
[0144] Furthermore, step S3400 includes:
[0145] Step S3410, calculate the second shard number N according to the second predicted traffic flow data f2 ;
[0146] Step S3420, calculate the second shard capacity requirement C according to the fourth traffic flow characteristic s2 ;
[0147] Step S3430, if |N f2 - N f | ≤ N θ , then use N f as the optimized shard number; if N f2 - N f | > N θ , then use as the optimized shard number; where N θ is the preset shard number deviation threshold, is the ceiling function;
[0148] Step S3440, if |C s2 - C s | ≤ C θ , then use C s as the optimized shard capacity requirement; if |C s2 - C s | > C θ , then use as the optimized shard capacity requirement; where C θ is the preset shard capacity deviation threshold.
[0149] Specifically, after generating the initial shard adjustment plan, step S3400 further optimizes and improves the plan by obtaining the second real-time operation data of the target blockchain network. The second real-time operation data is the latest operation status data obtained by continuously monitoring the blockchain network after generating the initial adjustment plan. It includes information such as the number of transactions, transaction frequency, and transaction size within a period of time after the adjustment, reflecting the actual operation situation of the network after the adjustment. By analyzing the second real-time operation data, the actual effect of the initial adjustment plan can be evaluated, and possible problems and deficiencies can be found. At the same time, the acquisition and analysis of real-time data also provide new training samples for the prediction model, making the prediction results more accurate and reliable. According to the second real-time operation data, the fourth traffic flow characteristics can be obtained, including the real-time transaction density, transaction burst index, and transaction mean after the adjustment. These characteristics reflect the load level and transaction pattern of the network after the adjustment.
[0150] During the optimization process, first adopt the same method as N fUsing the same calculation method, calculate the new shard quantity requirement N based on the second predicted traffic flow data f2 , and then, use the same calculation method as C s to calculate the new shard capacity requirement C based on the fourth traffic flow characteristic s2 . These two metrics respectively reflect the number of shards and the processing capacity required for each shard that the network needs in a future period after optimization. To achieve a smooth transition and avoid drastic changes in shard configuration, the optimization process introduces a shard quantity deviation threshold N θ and a shard capacity deviation threshold C θ . If the absolute value of the difference between the newly calculated shard quantity N f2 and the shard quantity N of the initial scheme f is less than or equal to N θ , then keep the shard quantity of the initial scheme unchanged; otherwise, take the ceiling of the average of the two as the optimized shard quantity. Similarly, if the absolute value of the difference between the newly calculated shard capacity requirement C s2 and the shard capacity requirement C of the initial scheme s is less than or equal to C θ , then keep the shard capacity requirement of the initial scheme unchanged; otherwise, take the average of the two as the optimized shard capacity requirement. This way of smooth adjustment can minimize the overhead caused by shard reorganization while meeting the network performance requirements
[0151] The optimized shard adjustment scheme includes the optimized shard quantity, the optimized shard capacity requirement, the optimized new shard quantity, and the optimized capacity adjustment value. Among them, the new shard quantity is the difference between the optimized shard quantity and the current actual shard quantity, reflecting the number of shards that need to be added or reduced. The capacity adjustment value is the difference between the optimized shard capacity requirement and the current actual shard capacity, reflecting the amount of expansion or contraction required for each shard. Based on these optimized parameters, a detailed shard reorganization plan can be formulated, including the creation of new shards, the expansion or contraction of existing shards, and the rebalancing of the load between shards. By dynamically adjusting the shard configuration, the processing capacity of the blockchain network can be matched with the real-time traffic demand, improving the network throughput and performance
[0152] The process of optimizing the sharding adjustment plan fully utilizes real-time monitoring data and prediction models to achieve dynamic optimization of sharding configuration. By continuously monitoring the network operating status, the second real-time operating data reflecting the actual traffic flow is obtained, and key features are extracted. These features are compared with the predicted data to evaluate the effect of the initial adjustment plan and identify potential problems. On this basis, the number and capacity of shards are optimized through smooth adjustment, which not only meets the performance requirements of the network but also minimizes the overhead of shard reorganization. The optimized sharding adjustment plan is more accurate and reliable and can better adapt to the dynamic changes of the blockchain network.
[0153] The optimization process of step S3400 makes the sharding adjustment plan more dynamic and intelligent, and can continuously optimize the sharding configuration according to the real-time status and prediction results of the blockchain network. This dynamic optimization mechanism can quickly respond to changes in traffic flow, improving the adaptability and robustness of the network. Through real-time monitoring and feedback, the optimization process continuously corrects the prediction model and adjustment strategy to make them more accurate and effective. At the same time, the introduction of smooth adjustment and threshold comparison can minimize the impact of shard reorganization while meeting the performance requirements, achieving progressive optimization of sharding configuration. The optimized sharding adjustment plan can better balance the load, improve resource utilization, and ultimately achieve the goal of enhancing the overall performance of the blockchain network.
[0154] Embodiment 2
[0155] Based on Embodiment 1, this embodiment provides a blockchain sharding optimization system based on traffic flow prediction, as Figure 6 shown, including:
[0156] Traffic flow prediction module: used to obtain the first historical traffic flow data of the target blockchain network, obtain the first traffic flow characteristics based on the first historical traffic flow data, construct a traffic flow prediction model, and obtain the first predicted traffic flow data according to the first traffic flow characteristics and the traffic flow prediction model; the first predicted traffic flow data includes predicted transaction density, predicted transaction burst index, and predicted transaction mean;
[0157] Sharding adjustment trigger module: used to obtain the real-time operating data of the target blockchain network, obtain the second traffic flow characteristics according to the real-time operating data, compare the second traffic flow characteristics with a preset threshold, and trigger the sharding adjustment mechanism according to the comparison result; the thresholds include transaction density threshold, transaction burst threshold, and transaction mean threshold;
[0158] Sharding adjustment module: used to generate and optimize the sharding adjustment plan according to the first predicted traffic flow data and the second traffic flow characteristics after triggering the sharding adjustment mechanism, and dynamically adjust the sharding configuration of the target blockchain network.
[0159] The traffic flow prediction module includes:
[0160] A traffic flow data acquisition unit: used to acquire the first historical traffic flow data of the target blockchain network;
[0161] A traffic flow data feature extraction unit: used to analyze the first historical traffic flow data to obtain the first traffic flow features; the first traffic flow features include the first transaction density, the first transaction burst index, and the first transaction mean;
[0162] A traffic flow prediction model construction unit: used to use the first traffic flow features as model inputs, construct a traffic flow prediction model, predict the traffic flow, and obtain the first predicted traffic flow data; the first predicted traffic flow data includes the predicted transaction density, the predicted transaction burst index, and the predicted transaction mean.
[0163] In the traffic flow data acquisition unit, the acquisition of the first historical traffic flow data of the target blockchain network includes:
[0164] Step S1110, acquire the transaction data of the target blockchain network in the past period of time, and the transaction data includes the number of transactions, the transaction frequency, and the transaction size;
[0165] Step S1120, arrange the acquired transaction data in chronological order to form a transaction number time series, a transaction frequency time series, and a transaction size time series;
[0166] Step S1130, use the transaction number time series, the transaction frequency time series, and the transaction size time series as the first historical traffic flow data;
[0167] In the traffic flow data feature extraction unit, the analysis of the first historical traffic flow data to obtain the first traffic flow features includes:
[0168] Step S1210, calculate the number of transactions in each time period of the first historical traffic flow data to obtain the first transaction density;
[0169] Step S1220, calculate the fluctuation of the transaction frequency in the first historical traffic flow data to obtain the first transaction burst index;
[0170] Step S1230, calculate the average value of the transaction size in the first historical traffic flow data to obtain the first transaction mean;
[0171] Step S1240, use the first transaction density, the first transaction burst index, and the first transaction mean as the first traffic flow features.
[0172] The shard adjustment trigger module includes:
[0173] Real-time operation data acquisition unit: used to acquire the real-time operation data of the target blockchain network, and obtain the second traffic flow characteristics according to the real-time operation data; the second traffic flow characteristics include the second transaction density, the second transaction burst index, and the second transaction mean;
[0174] Threshold comparison unit: used to compare the second traffic flow characteristics with preset thresholds, and trigger the sharding adjustment mechanism according to the comparison results; the thresholds include the transaction density threshold, the transaction burst threshold, and the transaction mean threshold.
[0175] In the real-time operation data acquisition unit, the acquisition of the real-time operation data of the target blockchain network and the obtaining of the second traffic flow characteristics according to the real-time operation data include:
[0176] Step S2110, collect the real-time operation data of the current target blockchain network;
[0177] Step S2120, perform statistical analysis on the collected real-time operation data, calculate the transaction density within the current time period, and obtain the second transaction density;
[0178] Step S2130, perform burst analysis on the collected real-time operation data, calculate the transaction frequency fluctuation within the current time period, and obtain the second transaction burst index;
[0179] Step S2140, perform mean analysis on the collected real-time operation data, calculate the average transaction size within the current time period, and obtain the second transaction mean;
[0180] Step S2150, use the second transaction density, the second transaction burst index, and the second transaction mean as the second traffic flow characteristics.
[0181] In the threshold comparison unit, the comparison of the second traffic flow characteristics with the preset thresholds and the triggering of the sharding adjustment mechanism according to the comparison results include:
[0182] Step S2210, compare the second transaction density with the preset transaction density threshold, and trigger the sharding adjustment mechanism when the second transaction density exceeds the preset transaction density threshold;
[0183] Step S2220, compare the second transaction burst index with the preset transaction burst threshold, and trigger the sharding adjustment mechanism when the second transaction burst index exceeds the preset transaction burst threshold;
[0184] Step S2230, compare the second transaction mean with the preset transaction mean threshold, and trigger the sharding adjustment mechanism when the second transaction mean exceeds the preset transaction mean threshold;
[0185] Step S2240: When any of the conditions in steps S2210, S2220, and S2230 is satisfied, trigger the shard adjustment mechanism.
[0186] The shard adjustment module includes:
[0187] Shard adjustment plan generation unit: After triggering the shard adjustment mechanism, it is used to dynamically adjust the number of shards and shard capacity of the target blockchain network according to the first predicted traffic flow data and in combination with the second traffic flow characteristics, and generate a shard adjustment plan;
[0188] Model calibration unit: After generating the shard adjustment plan, it is used to continuously collect the operation data of the target blockchain network, obtain the second historical traffic flow data of the target blockchain network, extract the characteristics of the second historical traffic flow data to obtain the third traffic flow characteristics; dynamically calibrate the traffic flow prediction model according to the third traffic flow characteristics to obtain the calibrated traffic flow prediction model;
[0189] Traffic flow calibration unit: It is used to perform secondary prediction on the traffic flow in a future period of time using the calibrated traffic flow prediction model to obtain the second predicted traffic flow data; the second predicted traffic flow data includes the second predicted transaction density, the second predicted transaction burst index, and the second predicted transaction mean; the second predicted traffic flow data covers the same future time period as the first predicted traffic flow data;
[0190] Optimized shard adjustment plan generation unit: After generating the shard adjustment plan, it is used to obtain the second real-time operation data of the target blockchain network, and obtain the fourth traffic flow characteristics according to the second real-time operation data; optimize the shard adjustment plan according to the second predicted traffic flow data and the fourth traffic flow characteristics to obtain the optimized shard adjustment plan, where the optimized shard adjustment plan includes the optimized number of shards, the optimized shard capacity requirement, the optimized number of newly added shards, and the optimized capacity adjustment value.
[0191] In the shard adjustment plan generation unit, the dynamically adjusting the number of shards and shard capacity of the target blockchain network according to the first predicted traffic flow data and in combination with the second traffic flow characteristics to generate a shard adjustment plan includes:
[0192] Step S3110: Calculate the number of shards N required in a future period of time according to the predicted transaction density, predicted transaction burst index, and predicted transaction mean in the first predicted traffic flow data f ;
[0193] Step S3120: Calculate the shard capacity requirement C of each shard in the current time period according to the second transaction density, second transaction burst index, and second transaction mean in the second traffic flow characteristics s;
[0194] Step S3130, determine a shard adjustment plan according to the calculated future required number of shards N f and the shard capacity requirement C for each shard s The shard adjustment plan includes the number of shards N f , the shard capacity requirement C for each shard s , the number of newly added shards, and the capacity adjustment value for each shard.
[0195] In the shard adjustment plan generation unit, the shard adjustment plan is optimized according to the second predicted traffic flow data and the fourth traffic flow feature to obtain the optimized shard adjustment plan, including:
[0196] Step S3410, calculate the second number of shards N according to the second predicted traffic flow data f2 ;
[0197] Step S3420, calculate the second shard capacity requirement C according to the fourth traffic flow feature s2 ;
[0198] Step S3430, if |N f2 -N f |≤N θ , then use N f as the optimized number of shards; if N f2 -N f |>N θ , then use as the optimized number of shards; where N θ is the preset shard number deviation threshold, is the ceiling function;
[0199] Step S3440, if |C s2 -C s |≤C θ , then use C s as the optimized shard capacity requirement; if |C s2 -C s |>C θ , then use as the optimized shard capacity requirement; where C θ is the preset shard capacity deviation threshold.
[0200] Example 3
[0201] This embodiment discloses an electronic device, which may include one or more processors and one or more memories. Among them, computer-readable code is stored in the memory, and when the computer-readable code is run by one or more processors, it can execute the blockchain sharding optimization method based on traffic flow prediction as described above.
[0202] The method or system according to the embodiments of the present application can also be implemented by means of the architecture of the following electronic device. The electronic device may include a bus, one or more CPUs, a read-only memory (ROM), a random access memory (RAM), a communication port connected to a network, input / output components, a hard disk, etc. The storage device in the electronic device, such as ROM or hard disk, can store the blockchain sharding optimization method provided by the present application. The blockchain sharding optimization method based on traffic flow prediction may, for example, include: obtaining first historical traffic flow data of a target blockchain network, obtaining first traffic flow characteristics based on the first historical traffic flow data, constructing a traffic flow prediction model, and obtaining first predicted traffic flow data according to the first traffic flow characteristics and the traffic flow prediction model; the first predicted traffic flow data includes predicted transaction density, predicted transaction burst index, and predicted transaction mean; obtaining real-time operation data of the target blockchain network, obtaining second traffic flow characteristics according to the real-time operation data, comparing the second traffic flow characteristics with a preset threshold, and triggering a sharding adjustment mechanism according to the comparison result; the threshold includes a transaction density threshold, a transaction burst threshold, and a transaction mean threshold; after triggering the sharding adjustment mechanism, generating and optimizing a sharding adjustment plan according to the first predicted traffic flow data and the second traffic flow characteristics, and dynamically adjusting the sharding configuration of the target blockchain network.
[0203] Furthermore, the electronic device may further include a user interface. Of course, the above architecture is only exemplary, and when implementing different devices, one or more components of the above electronic device may be omitted according to actual needs.
[0204] The methods, systems, and devices of the present application may be implemented in many ways. For example, the methods, systems, and devices of the present application may be implemented by software, hardware, firmware, or any combination of software, hardware, and firmware. The above order of steps for the method is only for illustration, and the steps of the method of the present application are not limited to the above specific order described unless otherwise specifically stated. In addition, in some embodiments, the present application may also be implemented as a program recorded in a recording medium, and these programs include machine-readable instructions for implementing the method according to the present application.
[0205] In addition, parts of the above technical solutions provided in the embodiments of the present application that are consistent with the corresponding technical solutions in the prior art in terms of implementation principles are not described in detail to avoid excessive elaboration.
[0206] The specific embodiments described above further elaborate in detail the objectives, technical solutions, and beneficial effects of the present invention. It should be understood that the above description is only the specific embodiments of the present invention and is not intended to limit the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention shall be included within the protection scope of the present invention.
Claims
1. A blockchain sharding optimization method based on traffic flow prediction, characterized in that: The method comprises: Acquire first historical traffic flow data of the target blockchain network, obtain first traffic flow characteristics based on the first historical traffic flow data, build a traffic flow prediction model, and obtain first predicted traffic flow data according to the first traffic flow characteristics and the traffic flow prediction model; the first predicted traffic flow data includes predicted transaction density, predicted transaction burst index, and predicted transaction mean; Acquire real-time operation data of the target blockchain network, obtain a second traffic flow characteristic according to the real-time operation data, compare the second traffic flow characteristic with a preset threshold, and trigger a sharding adjustment mechanism according to the comparison result; the threshold includes a transaction density threshold, a transaction burst threshold, and a transaction mean threshold; After the sharding adjustment mechanism is triggered, a sharding adjustment plan is generated and optimized according to the first predicted traffic flow data and the second traffic flow characteristics, and the sharding configuration of the target blockchain network is dynamically adjusted.
2. The blockchain sharding optimization method based on traffic flow prediction according to claim 1 is characterized in that: The obtaining of the first historical traffic flow data of the target blockchain network includes: Obtain transaction data of the target blockchain network over a period of time, wherein the transaction data includes transaction quantity, transaction frequency, and transaction size; Arrange the acquired transaction data in chronological order to form transaction quantity time series, transaction frequency time series and transaction size time series; The transaction quantity time series, transaction frequency time series and transaction size time series are used as the first historical traffic flow data; The first traffic flow characteristics include a first transaction density, a first transaction burst index and a first transaction mean.
3. The blockchain sharding optimization method based on traffic flow prediction according to claim 1 is characterized in that: The second traffic flow characteristics include a second transaction density, a second transaction burst index, and a second transaction mean; The comparing of the second traffic flow characteristic with the preset threshold and triggering the sharding adjustment mechanism according to the comparison result includes: if the second transaction density exceeds the preset transaction density threshold, or the second transaction burst index exceeds the preset transaction burst threshold, or the second transaction mean exceeds the preset transaction mean threshold, then the sharding adjustment mechanism is triggered.
4. The blockchain sharding optimization method based on traffic flow prediction according to claim 1 is characterized in that: The generating and optimizing the slicing adjustment scheme according to the first predicted traffic flow data and the second traffic flow characteristics includes: According to the first predicted traffic flow data and in combination with the second traffic flow characteristics, dynamically adjust the number of shards and shard capacity of the target blockchain network to generate a shard adjustment plan; After generating the sharding adjustment plan, continuously collect the operation data of the target blockchain network, obtain the second historical traffic flow data of the target blockchain network, extract features from the second historical traffic flow data, and obtain third traffic flow features; dynamically calibrate the traffic flow prediction model according to the third traffic flow features to obtain a calibrated traffic flow prediction model; The calibrated traffic flow prediction model is used to perform a second prediction of the traffic flow in a future period of time to obtain second predicted traffic flow data; the second predicted traffic flow data includes a second predicted transaction density, a second predicted transaction burst index, and a second predicted transaction mean; the second predicted traffic flow data covers the same future time period as the first predicted traffic flow data; After generating the sharding adjustment plan, the second real-time operation data of the target blockchain network is obtained, and the fourth traffic flow characteristics are obtained according to the second real-time operation data; according to the second predicted traffic flow data and the fourth traffic flow characteristics, the sharding adjustment plan is optimized to obtain an optimized sharding adjustment plan, wherein the optimized sharding adjustment plan includes the optimized number of shards, the optimized sharding capacity requirement, the optimized number of newly added shards and the optimized capacity adjustment value.
5. The blockchain sharding optimization method based on traffic flow prediction according to claim 4 is characterized in that: The method for generating a slicing adjustment scheme according to the first predicted traffic flow data and in combination with the second traffic flow characteristics comprises: According to the predicted transaction density, predicted transaction burst index and predicted transaction mean in the first predicted traffic flow data, the number of shards N required in the future period is calculated. f ; According to the second transaction density, the second transaction burst index and the second transaction mean in the second traffic flow characteristics, the shard capacity requirement C of each shard in the current time period is calculated. s ; According to the calculated number of shards N required in the future f and the shard capacity requirement C of each shard s Determine a sharding adjustment plan, the sharding adjustment plan includes the number of shards N f 、The shard capacity requirement C of each shard s , the number of newly added shards and the capacity adjustment value of each shard.
6. The blockchain sharding optimization method based on traffic flow prediction according to claim 5 is characterized in that: The number of shards N required in the future period is calculated according to the predicted transaction density, predicted transaction burst index and predicted transaction mean in the first predicted traffic flow data. f The method is: Obtain the number of transactions λ' generated in the network over a period of time, the average transaction processing delay τ' and the transaction processing throughput μ' of the network, and calculate the network load index γ'; The number of shards required in the future is calculated based on the predicted transaction density, predicted transaction burst index, predicted transaction mean, and network load index.
7. The blockchain sharding optimization method based on traffic flow prediction according to claim 4 is characterized in that: The method for obtaining the optimized slicing adjustment scheme according to the second predicted traffic flow data and the fourth traffic flow characteristics includes: Calculate the second number of fragments N according to the second predicted traffic flow data f2 ; Calculate the second slice capacity requirement C according to the fourth traffic flow characteristic s2 ; If |N f2 -N f |≤N θ , then N f as the optimized number of shards; if |N f2 -N f |>N θ , then As the optimized number of shards; where N θ is the preset shard quantity deviation threshold, is the ceiling rounding function; If |C s2 -C s |≤C θ , then C s as the optimized shard capacity requirement; if |C s2 -C s |>C θ , then As the optimized shard capacity requirement; where C θ It is the preset shard capacity deviation threshold.
8. A blockchain sharding optimization system based on traffic flow prediction, which is used to implement the blockchain sharding optimization method based on traffic flow prediction described in any one of claims 1 to 7, characterized in that: The system comprises: Traffic flow prediction module: used to obtain the first historical traffic flow data of the target blockchain network, obtain the first traffic flow characteristics based on the first historical traffic flow data, build a traffic flow prediction model, and obtain the first predicted traffic flow data according to the first traffic flow characteristics and the traffic flow prediction model; the first predicted traffic flow data includes predicted transaction density, predicted transaction burst index and predicted transaction mean; Sharding adjustment trigger module: used to obtain real-time operation data of the target blockchain network, obtain the second traffic flow characteristics according to the real-time operation data, compare the second traffic flow characteristics with a preset threshold, and trigger the sharding adjustment mechanism according to the comparison result; the threshold includes a transaction density threshold, a transaction burst threshold and a transaction mean threshold; Sharding adjustment module: used to generate and optimize the sharding adjustment plan and dynamically adjust the sharding configuration of the target blockchain network according to the first predicted traffic flow data and the second traffic flow characteristics after the sharding adjustment mechanism is triggered.
9. An electronic device comprising a memory, a central processing unit, and a computer program stored in the memory and executable on the central processing unit, characterized in that: When the central processing unit executes the computer program, the blockchain sharding optimization method based on traffic flow prediction described in any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Urban road traffic flow state estimation method and system based on block chain
CN117671961A
Internet of vehicles information sharing method based on block chain fragmentation technology
CN118139050A