A method for allocating a fragmented blockchain state
By using the LSTM-PPO model and the adaptive local migration method, the problems of long global allocation time and slow convergence in the state allocation of sharded blockchains are solved, and fast and accurate sharded load balancing and low cross-shard transaction rate are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-28
- Publication Date
- 2026-03-17
AI Technical Summary
Existing sharded blockchain state allocation methods have long global allocation times and slow convergence, failing to effectively address the performance bottleneck caused by cross-shard transactions.
We adopt a global account allocation method based on LSTM-PPO, combined with an adaptive local account migration method. The future system state is predicted by the LSTM model and used as a pre-training step for the PPO method, which can quickly achieve load balancing between shards and low cross-shard transaction rate.
It accelerates the convergence of sharded blockchain state allocation, achieves more accurate allocation results, reduces computational complexity, and ensures load balancing between shards and a low cross-shard transaction rate.
Smart Images

Figure CN120743549B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a blockchain state allocation method, specifically a sharded blockchain state allocation method. Background Technology
[0002] Current mainstream blockchain platforms and Ethereum are limited by scalability bottlenecks and performance defects. Their transaction processing efficiency and system throughput are difficult to meet the stringent requirements of high concurrency, elastic scaling, and high throughput, which objectively restricts the expansion of this technology into application areas with higher real-time requirements and larger business scale.
[0003] Sharding is an effective solution for improving the scalability of blockchains, based on the idea of dividing and conquering all transactions submitted to the blockchain system. However, in practical applications, the limited performance improvement of sharded blockchains is caused by cross-shard transactions. As the number of shards increases, the number of cross-shard transactions increases significantly, and processing these transactions inevitably incurs expensive communication overhead. To address the performance bottleneck caused by cross-shard transactions, two solutions exist: designing efficient cross-shard protocols, such as relay schemes and atomic commit protocols, to improve the processing efficiency of cross-shard transactions and thus reduce the user-perceived confirmation latency; and designing a state reassignment algorithm to fundamentally reduce the number of cross-shard transactions by grouping closely related states into the same shard.
[0004] Currently, relevant technologies have been applied to the optimal allocation of states in sharded blockchains. For example, CLPA is an account partitioning algorithm using community detection, which balances cross-shard transaction rate and shard workload balancing as a network partitioning problem. Another example is SPRING, a state placement sharding framework based on deep reinforcement learning, which describes state placement as a Markov decision process, reducing the number of cross-shard transactions while ensuring load balancing between shards. However, most existing technologies employ global account allocation methods based on community detection or neural networks, failing to consider the problem of long runtime and slow convergence of global allocation methods as the account set grows with the continuous generation of blocks. Summary of the Invention
[0005] The purpose of this invention is to provide a sharded blockchain state allocation method to solve the problems of long running time and slow convergence of the global allocation method in sharded blockchain state allocation.
[0006] The objective of this invention is achieved as follows:
[0007] A method for sharded blockchain state allocation includes the following steps:
[0008] S1. During the blockchain reconfiguration phase, obtain historical transactions in the sharded blockchain and construct a transaction account graph, where the vertices of the transaction account graph are account addresses and the edges are relationships between accounts;
[0009] S2. Determine the optimization problem function based on the transaction volume and load in the transaction account graph;
[0010] S3. Establish an LSTM model; based on the LSTM model and historical transactions, predict the state of active accounts in each shard network at the next time step; the state includes the number of cross-shard transactions of active accounts, and the active accounts are those whose transaction volume reaches a preset number within a preset time period;
[0011] S4. Based on the state predicted by the LSTM model and the optimization problem function, perform global allocation of accounts;
[0012] S5. After globally allocating accounts, acquire cross-shard transactions in real time before the reconfiguration phase of the next epoch in this reconfiguration phase, determine the candidate shards for each account in the cross-shard transactions, calculate the revenue when an account moves to a candidate shard, and determine the accounts that need to be migrated and their corresponding migration shards based on the revenue.
[0013] Furthermore, the optimization problem function in step S2 is determined as follows:
[0014] S2-1. Determine the number of cross-shard transactions, the workload caused by intra-shard transactions, and the workload caused by cross-shard transactions based on the transaction account diagram;
[0015] S2-2. Calculate the load balancing level between shards based on the workload caused by transactions within a shard and the workload caused by transactions across shards;
[0016] S2-3. Determine the optimization problem function based on the number of cross-shard transactions and the load balancing level.
[0017] Furthermore, the LSTM model comprises two LSTM layers, and the LSTM model is pre-trained.
[0018] Furthermore, the specific method for globally allocating the sharding status of the account in step S4 is as follows:
[0019] A PPO model is established, which includes a state space, a reward function, and an action space. The state space is defined by the state information containing the predicted state and historical transaction data, the reward function is determined according to the optimization problem function, and the action space is defined by migrating accounts to the target shard. The PPO agent outputs action decisions based on the current state and simulates environmental changes through the state transition function. After completing a preset number of training rounds, the trained PPO model is used to achieve global allocation of accounts among shards.
[0020] Furthermore, the specific method for determining the accounts to be migrated and their corresponding migration shards in step S5 is as follows:
[0021] S5a-1. Select the shard containing the associated accounts in all cross-shard transactions of the target account as candidate shards, wherein the associated accounts are accounts that have cross-shard transactions with the target account;
[0022] S5a-2. Select the partition with the highest profit among the candidate partitions as the target partition and use the highest profit as the increment;
[0023] S5a-3. Take the target fragment as the source fragment, take the fragment with the highest profit among the other candidate fragments as the new target fragment, add the maximum profit to the increment, and update the increment;
[0024] S5a-4. Repeat step S5a-3 until the target account’s return from migrating from the source shard to other candidate shards is less than or equal to 0, and the updated increment is greater than the migration threshold. The target account is the account that needs to be migrated. The source shard corresponding to the return of all candidate shards is less than or equal to 0 is the migration shard.
[0025] This invention achieves a low cross-shard transaction rate while ensuring load balancing across shards. The optimal state allocation method consists of a global account allocation method based on LSTM-PPO and an adaptive local account migration method. In the global account allocation method, an LSTM model is used to predict future system states and serves as a pre-training step for the PPO method, accelerating the convergence of the allocation algorithm and resulting in more accurate allocation results. The adaptive local account migration method executes faster, no longer using all historical data, but only based on previous account allocation results and newly submitted transactions, reducing computational complexity and achieving short-term shard load balancing and a low cross-shard transaction rate. The global account allocation method and the adaptive local account migration method perform state allocation through periodic two-stage collaborative optimization, which has advantages over mainstream allocation methods. Attached Figure Description
[0026] Figure 1 This is a flowchart of the present invention.
[0027] Figure 2 This is a schematic diagram of the global allocation of the present invention in the stage of an epoch.
[0028] Figure 3 This is an account transaction topology diagram.
[0029] Figure 4 This is a schematic diagram of the global account allocation of the present invention.
[0030] Figure 5This is an experimental comparison chart of the present invention and other methods in terms of the number of cross-shard transactions.
[0031] Figure 6 This is an experimental comparison chart of the present invention and other methods in terms of fragmented load. Detailed Implementation
[0032] like Figure 1 As shown in the accompanying drawings, the present invention will be further described in detail below.
[0033] S1. During the blockchain reconfiguration phase, retrieve historical transactions from the sharded blockchain and construct a transaction account graph.
[0034] In the transaction account graph, the vertices represent account addresses, and the edges represent the relationships between accounts.
[0035] like Figure 2 As shown, in a sharded blockchain, the entire system consists of K W-Shards and one R-Shard. The system comprises three consecutive phases: node identity setup, transaction block consensus, and reconfiguration. In the node identity setup phase, to resist Sybil attacks, blockchain nodes need to register their identities to join the sharded network and are assigned to W-Shards and R-Shards based on their PoW difficulty, with R-Shard having a higher PoW difficulty than W-Shard. In the transaction block consensus phase, W-Shards perform PBFT consensus on the packaged blocks, adding the consensus-reaching blocks to their local blockchain and sending the block header and transaction hash list to R-Shards for transaction monitoring across shards. R-Shards reach consensus on the account allocation results and send the consensus results to each shard, completing the migration of accounts and transactions. In the reconfiguration phase, global account allocation is performed using the state prediction and PPO of this invention. The partitioning results are added to the state block, and after consensus is reached, they are sent to each shard, and accounts are migrated and updated.
[0036] like Figure 3 As shown, a trading account graph is constructed based on the transactions monitored by R-Shard (i.e., historical transactions). The transaction account graph is an undirected weighted graph, where V represents the account address. E is the edge associated with the account. Figure 3 Solid lines in the diagram represent transactions within a shard, while dashed lines represent transactions across shards. This indicates that an account is involved. and accounts Transactions; Account and accounts The sum of the weights of all exchanges between them The calculation formula is:
[0037]
[0038] in, Indicates accounts involved and The transaction set, This represents the number of one-to-one relationships between accounts in a transaction.
[0039] Historical transactions are those from the previous T eras.
[0040] because Since it's an undirected graph, an edge can only connect two accounts. If a transaction involves multiple input or output accounts, a single edge cannot represent the relationship between them. Therefore, we solve this problem by transforming transactions into edges with corresponding weights. For example, in a transaction where input accounts are a and b, and output account is c, the weight of the edge between accounts a and c, and the weight of the edge between accounts b and c, are both 1 / 2. Finally, the weights of the same edges in all transactions are added together. For instance, if there are 3 transactions between accounts a and d, and the weight of the edge between them in each transaction is 1, then the weight of the edge between accounts a and d is 3. Figure 3 The numbers on the middle side represent the sum of the weights of the associated accounts in the transactions monitored by R-Shard.
[0041] S2. Determine the optimization problem function based on the number of transactions and load in the transaction account graph.
[0042] The final allocation of accounts is determined by express.
[0043]
[0044] Each account a i It can only be allocated to one shard, that is... .
[0045] Account With account Being assigned to two different shards will generate an additional relay transaction; account With account They are assigned to the same shard, i.e. Otherwise, it is 0.
[0046] Calculate account allocation results Number of cross-shard transactions caused :
[0047]
[0048] in, This represents the total number of accounts on the current blockchain.
[0049] Sharded workloads arise from intra-shard transactions and cross-shard transactions. The workload for processing cross-shard transactions is defined as the workload for processing intra-shard transactions. If the workload required to process transactions within a shard is 1, then the workload required to process transactions across shards is... . This can be calculated based on historical transaction records, specifically the ratio of the average workload for processing cross-shard transactions to the average workload for processing intra-shard transactions in the previous epoch.
[0050] For fragmentation Workload caused by transactions within shards for:
[0051]
[0052] Workload caused by cross-shard transactions for:
[0053]
[0054] Therefore, fragmentation workload L k for:
[0055]
[0056] So, the account allocation results The resulting inter-shard load balancing level is expressed as
[0057]
[0058] in, It is the average workload of the shards. .
[0059] The goal of state allocation is to group closely related accounts into the same shard as much as possible, reducing the number of cross-shard transactions, while ensuring workload balance across shards. In other words, it aims to find an account allocation X that produces the minimum number of cross-shard transactions and the lowest workload. Therefore, the state allocation problem can be treated as an optimization problem function:
[0060]
[0061]
[0062]
[0063]
[0064] S3. Establish a Long Short-Term Memory (LSTM) network model; based on the LSTM model and historical transactions, predict the state of active accounts in each shard network at the next time step.
[0065] The status includes the number of cross-segment transactions of active accounts, where an active account is an account whose transaction volume reaches a preset number within a preset time period.
[0066] like Figure 4 As shown, in the LSTM-PPO-based global account allocation algorithm, the global account allocation problem can be viewed as a Markov decision process, thus Deep Reinforcement Learning (DRL) can be used to solve this problem and obtain the optimal policy. Proximal Policy Optimization (PPO) is a type of DRL that uses PPO to allocate accounts based on all historical transaction data to obtain the globally optimal solution. However, it requires a long running time and therefore cannot be run frequently for extended periods. Furthermore, slow convergence is an unavoidable problem with PPO. Trial actions may lead to significant deviations between the reward and the optimal value. In particular, they may lead to the migration of inactive accounts, resulting in additional energy consumption. Therefore, this invention proposes a prediction-aware PPO global account allocation algorithm.
[0067] R-Shard collects historical transactions from the previous T epochs. A two-layer LSTM prediction model is used to predict future system states, and this is pre-trained offline as the first step in PPO. In a real system, relying on an LSTM model to predict all accounts is extremely time-consuming and inefficient. Therefore, when predicting the number of transactions for an account, only the transaction counts between active accounts and each shard are predicted. The remaining inactive accounts are treated as a whole, called aggregate accounts, and the transaction counts between these accounts and each shard are predicted as a whole. For example, if accounts a and b are inactive accounts, and account a has 2 transactions with shard C, and account b has 1 transaction with shard C, then the total transaction count between inactive accounts and shard C is 3.
[0068] Among them, active accounts can be determined by the weight of the edges in the trading account graph. Accounts with a total edge weight greater than the preset weight are identified as active accounts, and the remaining accounts are inactive accounts. The preset weight can be set according to the needs.
[0069] The predictive perception method involves two LSTM layers to make more accurate predictions about accounts, where each LSTM layer is responsible for... The LSTM model uses historical transaction records from past epochs to predict the next state of each account. It is pre-trained; specifically, historical transactions are acquired, and a historical account count and historical transaction account graph are derived from these records. These are then input into the LSTM model for training. The changing patterns of the relationship between accounts and segments are captured in the observation vectors, after which... After each recursive update, the hidden state at the last time step can be considered as the environment. The complete representation is shown. After the second LSTM layer, a fully connected layer and an output layer are used to produce the final prediction. The output layer of this model is the current segmented network. The predicted status of an active account, i.e., the number of transactions between the active account and each shard.
[0070] S4. Based on the state predicted by the LSTM model and the optimization problem function, perform global allocation of accounts.
[0071] The PPO environment consists of an action space, a state space, and a reward function.
[0072] The predicted state output by the LSTM and the historical transactions are used as the state space of the PPO. t :
[0073]
[0074] in, The predicted state of the account output by the LSTM model, including active accounts and the number of transactions in each shard; The graph of the trading accounts obtained at time t. For the set of active accounts counted at time t, The number of unconfirmed transactions at time t can be obtained directly.
[0075] The data acquired at time t includes data from time t onwards. The active account set statistically analyzed at time t is obtained based on the transaction account graph acquired at time t.
[0076] Action space a t for:
[0077]
[0078] in, .
[0079] The action space of this invention is a discrete action space, which determines the number of cross-region transactions for all accounts in the next state and the workload caused by intra-shard transactions.
[0080] An agent is an entity in a PPO that can perceive its environment, make decisions, and execute actions. The agent aims for optimal account allocation, minimizing the number of cross-shard transactions while ensuring workload balance across shards. The global reward function r for each t... t (s t ,a t )for:
[0081]
[0082] The state transition function P is defined in the current state s. t Next, after action a t It then reached a new state s t+1 .
[0083] The agent interacts with the environment to obtain a set of empirical data, such as the state s at time t. t Action a t and reward r t And the state s of the next moment t+1 PPO also includes a policy network and an evaluation network. Data is sampled from the training buffer. The evaluation network estimates the value of the state based on the sampled data and updates its parameters. The policy network optimizes the output of the evaluation network to increase the probability of selecting high-value actions and updates the policy network. In each training round, a decision is made on whether to perform a migration operation for all accounts to be assigned. The network parameters are updated promptly after each step.
[0084] This invention allows for customized training epochs based on actual needs, ultimately outputting a fully trained model for global account allocation. After account reallocation, the transaction account graph is updated for an adaptive account migration method in the next epoch.
[0085] S5. After globally allocating accounts, acquire cross-shard transactions in real time before the reconfiguration phase of the next epoch in this reconfiguration phase, determine the candidate shards for each account in the cross-shard transactions, calculate the revenue when an account moves to a candidate shard, and determine the accounts that need to be migrated and their corresponding migration shards based on the revenue.
[0086] Retrieve the transactions at the current moment. Based on the transactions at the current moment, obtain the target account. In the reassigned transaction account graph, the shard containing the target account is the source shard of the target account. The shards containing associated accounts in cross-shard transactions are selected as candidate shards. Associated accounts are those accounts that have cross-shard transactions with the target account. Among them, account a j Is it account a? i Accounts that engage in cross-shard transactions.
[0087] In the process of selecting candidate shards, the shard with the highest profit is chosen as the target shard, and the maximum profit is used as the increment. The target shard is then chosen as the source shard. The remaining candidate shards and the initial source shard are then chosen as candidate shards. The shard with the highest profit from the candidate shards is selected as the target shard, and the maximum profit is added to the increment as the new increment. The target shard is then chosen as the source shard, and the above steps are repeated until a shard is chosen as the source shard and the corresponding gain of all candidate shards as target shards is less than or equal to 0. At this point, it is determined whether the increment is greater than or equal to the migration threshold. If it is greater than or equal to the migration threshold, the target account is the account that needs to be migrated, and the corresponding source shard is chosen as the migration shard for the account, and the account is migrated to the migration shard.
[0088] Account From source fragmentation Move to the remaining fragments Benefits for:
[0089]
[0090] in, For account The number of cross-shard transactions in source s after leaving source s. For account The number of cross-shard transactions in candidate shard t when added to the candidate shard t. For account The workload in source fragment s after leaving source fragment s It is an account The workload in candidate partition t when added to candidate partition t.
[0091] When an account is new, all shards are treated as candidate shards for that account, and the shard with the highest yield is selected as the target shard and added.
[0092] After migrating the accounts that need to be migrated to the migration shard, update the transaction account graph. Then, obtain the newly submitted cross-shard transactions and calculate the accounts that need to be migrated and their corresponding migration shards based on the updated transaction account graph.
[0093] Random is a method of randomly assigning accounts, allocating states based on the last few hexadecimal digits of the address. CPLA, in balancing the number of cross-shard transactions with shard load balancing, designed a lightweight community detection algorithm based on constraint label propagation for global account allocation. SPRING is the first solution to address the state placement problem using DRL; during the operation of the sharded blockchain, it optimally places newly arriving accounts using the PPO algorithm based on the local state of the accounts within a time window.
[0094] like Figure 5 and Figure 6 As shown, this invention consistently outperforms other comparative schemes in overall cross-shard transaction control and shard load balancing. The cumulative distribution function curve of this invention is closest to the left, and its load distribution is more balanced, surpassing the Random, CLPA, and SPRING schemes. The figure also shows that the longer SPRING runs, the worse its performance in terms of cross-shard transaction volume; furthermore, SPRING's load distribution is not balanced enough because the number of new accounts arriving is less than in the initial stage, and the cross-shard transaction volume generated by hot accounts cannot be compensated for by the proper placement of new accounts. However, the cross-shard transaction volume of this invention fluctuates significantly between different eras. This fluctuation mainly stems from the strategy design, which only places newly created accounts in shards in each era, without dynamically migrating existing hot accounts, resulting in local fluctuations. However, overall, this invention can reduce the number of cross-shard transactions while achieving workload balancing between shards.
Claims
1. A method for sharded blockchain state allocation, characterized in that, Comprising the following steps: S1. Obtain historical transactions in the sharded blockchain in the reconfiguration phase of the blockchain, and construct a transaction account graph, the vertices of the transaction account graph being account addresses and the edges being the relationships between accounts; S2. Determine an optimization problem function according to the number of transactions and the load in the transaction account graph; S3. Establish an LSTM model; the input of the LSTM model is the number of historical accounts and the historical transaction account graph, and the state of the active account in each shard network at the next time is predicted according to the LSTM model and the historical transactions; the state includes the number of cross-shard transactions of the active account, the active account being an account whose number of transactions reaches a preset number within a preset time period; when predicting the number of transactions of the account, only the number of transactions of the active account with each shard is predicted, and the remaining non-active accounts are regarded as a whole, referred to as an aggregated account, and the number of transactions between the aggregated account and each shard is predicted in a whole manner; S4. Establish a PPO model, and perform global allocation of the accounts according to the PPO model, the state predicted by the LSTM model, and the optimization problem function; S5. After the global allocation of the accounts, real-time cross-shard transactions are obtained before the reconfiguration phase of the next epoch in the reconfiguration phase, and the candidate shards of each account in the cross-shard transactions are determined; The revenue of the account when moving to the candidate shard is calculated, and the account that needs to be migrated and the corresponding migration shard are determined according to the revenue; The specific manner of global allocation of the accounts in step S4 is: A PPO model is established, the PPO model comprising a state space, a reward function and an action space; state information comprising a predicted state and historical transaction data is determined as the state space S t : ; wherein, is a predicted state of an account output by the LSTM model, comprising active accounts and transaction quantities of each shard; is a transaction account graph acquired at time t, is a set of active accounts counted at time t, is a number of unconfirmed transactions at time t; a reward function r is determined according to an optimization problem function t (s t ,a t ): , wherein, F(X) is the optimization problem function; wherein, represents a total number of accounts of the current blockchain; wherein, is an average workload of the shard; migration of the account to a target shard is taken as the action space a t : wherein, wherein, x i,k =1 indicates that the account a i is allocated to the shard k, otherwise, x i,k =0; the PPO agent outputs an action decision according to a current state, simulates environmental changes through a state transition function; after completing preset rounds of training, the trained PPO model is used to realize global allocation of the account among the shards; The specific manner of determining the account that needs to be migrated and the corresponding migration shard in step S5 is: S5a-1. The shard where the associated account of the target account is located in all cross-shard transactions of the target account is taken as a candidate shard, the associated account being an account that has cross-shard transactions with the target account; S5a-2. The shard with the maximum revenue in the candidate shards is taken as a target shard, and the maximum revenue is taken as an increment; account from the source shard to the remaining shards the benefits are: , wherein, is the account is the number of cross-shard transactions in the source shard s after leaving the source shard s, is the account is the number of cross-shard transactions in the selected shard t when joining the candidate shard t, is the account is the workload in the source shard s after leaving the source shard s, is the account is the workload in the selected shard t when joining the candidate shard t; S5a-3. The target shard is taken as a source shard, the shard with the maximum revenue in the other candidate shards is taken as a new target shard, and the maximum revenue is added to the increment to update the increment; S5a-4. Step S5a-3 is executed in a loop until the revenue of the target account when migrating from the source shard to the other candidate shards is less than or equal to 0, and the updated increment is greater than a migration threshold, the target account is the account that needs to be migrated; when the revenue of all candidate shards is less than or equal to 0, the source shard corresponding thereto is the migration shard.
2. The sharded blockchain state allocation method of claim 1, wherein, The determination manner of the optimization problem function in step S2 is: S2-1. Determine the number of cross-shard transactions, the workload caused by intra-shard transactions, and the workload caused by cross-shard transactions according to the transaction account graph; S2-2. Calculate the load balancing level between shards according to the workload caused by intra-shard transactions and the workload caused by cross-shard transactions; S2-3. Determine the optimization problem function according to the number of cross-shard transactions and the load balancing level.
3. The sharded blockchain state allocation method of claim 1, wherein, The LSTM model comprises two LSTM layers, and the LSTM model is pre-trained.
Citation Information
Patent Citations
Block chain fragmentation method based on account migration and block chain system
CN116383203A
Block chain load balancing method and system based on deep reinforcement learning
CN119232658A