A method for dynamic account allocation in a sharded blockchain considering transaction type

By optimizing account allocation in a sharded blockchain system using graph attention networks and deep reinforcement learning algorithms, the problem of uneven resource consumption caused by differences in transaction types is solved, thereby improving the system's scalability and performance.

CN120931284BActive Publication Date: 2026-07-24HUBEI UNIV OF TECH
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HUBEI UNIV OF TECH
Filing Date
2025-06-25
Publication Date
2026-07-24

AI Technical Summary

Technical Problem

Existing sharded blockchain systems fail to effectively consider differences in transaction types when allocating accounts, resulting in uneven resource consumption, difficulty in coping with complex and ever-changing transaction patterns, and impact on system scalability and performance.

Method used

By employing graph attention networks and deep reinforcement learning algorithms, combined with transaction type weights, an account allocation strategy is optimized. The account migration process is modeled through a GA-PPO agent to achieve dynamic account allocation.

Benefits of technology

It improves the scalability and performance of sharded blockchain systems, optimizes resource utilization, and reduces cross-shard transaction rates and system load imbalance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120931284B_ABST
    Figure CN120931284B_ABST
Patent Text Reader

Abstract

The application provides a kind of sharded blockchain dynamic account allocation method considering transaction type, comprising: based on the consensus protocol within the sharding of sharded blockchain system and each transaction type weight executes transaction, generates local transaction graph;Aggregating all local transaction graphs to build a global transaction graph, and extracting a feature vector representing the system state from the global transaction graph through a graph attention network (GAT) and outputting an account allocation strategy prediction result;Optimize the prediction result through GA-PPO agent to obtain the optimization result of account allocation strategy;Based on the consensus protocol within the sharding, the decision result of the mapping relationship between the account and the sharding is generated according to the optimization result of the account allocation strategy, and the account migration operation is executed according to the decision result.The process data of the account migration operation executed according to the new strategy can also be recorded, and the recorded process data is used for continuous training of GA-PPO agent.The application optimizes the dynamic account allocation strategy in the sharded blockchain system, and improves the scalability and performance of the system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of blockchain technology, and more specifically, to a method, system, electronic device, and storage medium for dynamic account allocation in a sharded blockchain that takes into account transaction types. Background Technology

[0002] As the underlying architecture for digital assets and decentralized applications, blockchain has seen significant development in areas such as decentralized finance and tokenization. However, its scalability issues severely limit its large-scale deployment and application. The transaction processing speed of mainstream blockchains is far slower than traditional centralized payment systems, primarily due to the blockchain's global consensus mechanism, where each node needs to verify all transactions, leading to bottlenecks in processing speed and scalability. To overcome this limitation, sharding technology has emerged. By dividing the nodes in the blockchain network into multiple smaller groups (shards), each shard can process transactions in parallel, improving the overall transaction processing capacity of the network.

[0003] However, sharding technology faces numerous challenges in practical applications, such as processing cross-shard transactions, balancing workloads between shards, and the efficiency of account migration. Existing account allocation methods in sharded blockchains mainly rely on graph partitioning and community detection algorithms, which are only suitable for scenarios with relatively stable transaction patterns. They struggle to cope with the complex and ever-changing transaction patterns in real-world blockchain systems and do not consider the distinction between transaction types. Different transaction types lead to different resource consumption, which needs to be taken into account during account allocation.

[0004] Therefore, it is necessary to study a sharded blockchain dynamic account allocation scheme that takes into account transaction types. Summary of the Invention

[0005] This invention addresses the technical problems existing in the prior art by providing a dynamic account allocation method for sharded blockchains that considers transaction types. It combines graph attention networks and deep reinforcement learning algorithms, and explicitly models the heterogeneous resource consumption of transaction types to quantify the weights of each transaction type. This optimizes the dynamic account allocation strategy in the sharded blockchain system and improves the system's scalability and performance.

[0006] According to a first aspect of the present invention, a method for dynamic account allocation in a sharded blockchain considering transaction type is provided, the method comprising:

[0007] S1 executes transactions based on the intra-shard consensus protocol of the sharded blockchain system and the weights of each transaction type to generate a local transaction graph;

[0008] S2, aggregate all local transaction graphs to construct a global transaction graph, extract feature vectors representing the system state from the global transaction graph through the graph attention network GAT, and output the account allocation strategy prediction results;

[0009] S3, the account allocation problem is modeled as a Markov decision process by the GA-PPO agent, and the prediction result of the account allocation strategy is optimized based on the state space, action space and reward function to output the optimized account allocation strategy result; based on the intra-shard consensus protocol, the decision result of the account-to-shard mapping relationship is generated according to the optimized account allocation strategy result, and the account migration operation is executed according to the decision result.

[0010] Based on the above technical solution, the present invention can also be improved as follows.

[0011] Optionally, before step S1, the system also includes building a sharded blockchain system, specifically including:

[0012] A sharded blockchain system architecture is constructed based on decision sharding and multiple working shards, wherein the working shards are at least used to execute transactions, generate transaction blocks, and manage local account states; and the decision shards are at least used to be responsible for global state maintenance, strategy learning, and decision generation.

[0013] Determine the consensus protocol within the shards of the system to ensure that transactions within the shards reach consensus in the event that no more than one-third of the nodes act maliciously;

[0014] Define a set of transaction types, and quantify the weight of each transaction type in the set based on the differences in resource consumption among the various transaction types.

[0015] Optionally, step S1 includes:

[0016] S101: The working shard retrieves transactions from the local transaction pool and packages them into transaction blocks. After reaching a consensus based on the consensus protocol within the shard, the transaction is executed within the working shard.

[0017] S102, Work sharding constructs the local transaction graph G local = (V′, E′), where node V′ represents the set of accounts, edge set E′ represents the set of transaction relationships between accounts, and the edge weight e′ is the weight of each edge e′ in edge set E′. i,j The weight ρ of transaction frequency and corresponding transaction type type Joint decision;

[0018] S103, based on local transaction graph G local =(V′,E′) generates a block-level digest and sends it to the decision shard.

[0019] Optionally, in step S103, the block-level digest includes at least:

[0020] Key information about the adjacency matrix of the local transaction graph, transaction volume, and account status update information.

[0021] Optionally, step S2 includes:

[0022] S201, aggregates all local transaction charts G local = (V′, E′) to construct the global transaction graph G global = (V, E), where the edge weight e is the weight e of each edge e in the edge set E. i,j The weight ρ of transaction frequency and corresponding transaction type type Joint decision;

[0023] S202 uses the Graph Attention Network (GAT) to analyze the adjacency matrix to detect global transaction graphs G. global The non-zero elements in the edge set E are used to generate the edge index matrix edge, which represents the source and target nodes of each edge. index ;

[0024] S203, convert the feature vectors X of each node i The features are concatenated to form a feature matrix X, and the feature vector X of each node is... i It is a d-dimensional real vector;

[0025] S204, based on the index matrix edge index With feature matrix X, a graph attention mechanism is used to aggregate neighborhood information, capture transaction relationships between accounts, and generate node-level hidden representations;

[0026] S205 integrates the node-level hidden representations of each node and projects them onto the action dimension, using the inferred optimal action vector A′ as the prediction result for the account allocation strategy.

[0027] Optionally, step S204 includes:

[0028] S2041, based on the index matrix edge index The attention weight α is calculated from the feature matrix X. ij The attention weights α of multiple adjacent nodes are... ij The attention weight matrix α is aggregated to obtain the first layer of hidden features Z1;

[0029] S2042, perform deeper neighborhood aggregation on the first-layer hidden feature Z1 to generate the second-layer output hidden feature Z2.

[0030] Optionally, step S205 includes:

[0031] S2051, Construct the action probability distribution space, project the second layer output hidden feature Z2 onto the action dimension A, and generate the prediction score matrix logits;

[0032] S2052, logits of the predicted score vector of node i. i After normalization, the action probability distribution π of node i is obtained.i ;

[0033] S2053, Node i is based on the action probability distribution π i Action index a i ~Categorical(·π) i By sampling using the categorical distribution Categorical(·), the action 'a' of each node is inferred. i The actions corresponding to the associated accounts are collectively constituted by action vector A′, which serves as the prediction result for the account allocation strategy.

[0034] Optionally, in step S3, the step of modeling the account allocation problem as a Markov decision process using a GA-PPO agent, and optimizing the account allocation strategy prediction result based on the state space, action space, and reward function to output the optimized account allocation strategy result includes:

[0035] S301 models the account allocation problem as a Markov decision process, defining the state space S, action space A, and reward function R. t ,in:

[0036] The state space at each time step t is formally defined as:

[0037] S t =[E,K,L sh ,L ac ] t ,

[0038] Where E represents the transaction relationship between accounts, K is an H-dimensional heat vector, H is the number of shards, and represents the distribution of accounts participating in the transaction; L sh Indicates a fragmented workload, L ac Record the workload status of a single account;

[0039] Action space A explicitly represents account allocation decisions using integer encoding. At each time step t, an action vector is selected:

[0040] A t =[a1,a2,…,a i ,…,a N ] t,1≤i≤N ,

[0041] Define reward function R t for:

[0042] R t =-ξ1·η-ξ2·μ-ξ3·ν+C,

[0043] Where ν represents the account migration rate, μ represents the system workload imbalance, η represents the cross-shard transaction rate, ξ1, ξ2 and ξ3 are preset weighting coefficients, and C is a scaling constant used for reward calibration;

[0044] S302, at each time step t, the observed state space S t According to the current account allocation strategy π θ Generate action a t ; Perform action a t Afterwards, the environment returns a reward R. t And transition to the next state S t+1 ;

[0045] Empirical tuples (S) t A t ,R t ,S t+1 The data is stored in the experience replay buffer B. During each training cycle, a small batch of data is sampled from buffer B to train the network parameters.

[0046] S303 actively samples M batches of trajectory segments from historical interaction data;

[0047] Based on the critic's value estimate, the state-action pairs are parameterized to approximate discounted cumulative returns; based on the variance-reduced advantage function, a generalized advantage estimate (GAE) with time regularization is adopted to reduce the variance of the long-term advantage estimate, and its corresponding formula is as follows:

[0048]

[0049] Where γ represents the discount factor, λ is the GAE smoothing coefficient, and V φ Corresponding to the Critic's state value prediction, r t The immediate reward obtained at time step t, where T is the total number of time steps in a round, δ t δ t+l Discount rewards for time steps t and t+1;

[0050] Importance sampling ratio Strategically reclaim M batches of trajectory segments from historical strategy data, while simultaneously forcibly updating constraints through gradient pruning operations:

[0051]

[0052] Wherein, ∈ serves as the pruning threshold to prevent excessive deviation from the previous strategy;

[0053] The network parameters φ are iteratively refined by minimizing the squared error loss between the value prediction and the empirical reward signal.

[0054]

[0055] in, This indicates cumulative discount rewards;

[0056] Calculate the total loss L total :

[0057] L total =-L CLIP +c1L VF -c2H(π θ ),

[0058] Where H(π) θ ) is the strategy (π) θ The policy entropy under (c1, c2) is used to encourage exploration; c1 and c2 are preset weights.

[0059] The Actor network parameters θ and the Critic network parameters φ are updated using gradient descent, and the updated policy parameters θ are periodically compared with the old policy. synchronous.

[0060] Optionally, in step S3, the step of generating a decision result of the account-to-shard mapping relationship based on the intra-shard consensus protocol and the account allocation strategy optimization result, and performing an account migration operation based on the decision result, includes:

[0061] The optimal action A output by the GA-PPO agent based on the intra-shard consensus protocol. t A consensus was reached that the optimal action A t Assign a strategy to the accounts for the next period t+1;

[0062] The decision shard generates a decision block containing the account-to-shard mapping relationship and broadcasts it to each working shard;

[0063] The corresponding working segment receives and verifies the decision block, based on the obtained new strategy K. (t+1) Execute the corresponding account migration operation.

[0064] Optional, also includes:

[0065] S4 records the process data of performing account migration operations according to the new strategy, and uses the recorded process data to continuously train the GA-PPO agent.

[0066] This invention provides a dynamic account allocation method for sharded blockchains that considers transaction types. By combining graph attention networks and deep reinforcement learning algorithms, and by explicitly modeling the heterogeneous resource consumption of transaction types by quantifying the weight of each transaction type, the method optimizes account allocation in sharded blockchain systems, thereby improving the scalability and performance of the system. Attached Figure Description

[0067] Figure 1 A flowchart of a sharded blockchain dynamic account allocation method considering transaction type provided by the present invention;

[0068] Figure 2 A schematic diagram of a sharded blockchain system architecture provided for one embodiment;

[0069] Figure 3 A detailed flowchart of step S2 provided for one embodiment;

[0070] Figure 4 A schematic diagram of the workflow of a GA-PPO agent provided for one embodiment;

[0071] Figure 5 For based on Figure 1 A flowchart of another embodiment of the illustrated example;

[0072] Figure 6 A schematic diagram of a possible hardware structure of an electronic device provided by the present invention;

[0073] Figure 7 This is a schematic diagram of the hardware structure of a possible computer-readable storage medium provided by the present invention. Detailed Implementation

[0074] The specific embodiments of the present invention will be described in further detail below with reference to the accompanying drawings and examples. The following examples are for illustrative purposes only and are not intended to limit the scope of the invention.

[0075] Figure 1 This invention provides a flowchart of a sharded blockchain dynamic account allocation method that considers transaction types. Figure 2 The embodiment provided with Figure 1 A schematic diagram of a sharded blockchain system architecture that matches the method shown.

[0076] Please see Figure 2 In this embodiment, during execution Figure 1 Before implementing the method shown, a sharded blockchain system must first be built and initialized. The system building process specifically includes:

[0077] 1. A sharded blockchain system architecture is constructed based on decision shard (D-shard) and multiple working shards (W-shard), wherein the working shards are at least used to execute transactions, generate transaction blocks, and manage local account states; the decision shards act as DRL agents and are at least responsible for global state maintenance, policy learning, and decision generation.

[0078] 2. Determine the consensus protocol within the shards of the system. For example, the system may use Practical Byzantine Fault Tolerance (PBFT) as the consensus protocol within the shards to ensure that transactions within the shards reach consensus even if no more than one-third of the nodes act maliciously.

[0079] 3. Define a set of transaction types and quantify the weight of each transaction type in the set based on the differences in resource consumption among various transaction types.

[0080] More specifically, define the set of transaction types T. type (For example, it includes 14 types: swap, stake, prove, mint, withdraw, delegate, contract transfer, claim, call, bridge, loan, batch, approve, and transfer), and quantifies the weight ρ of each transaction type based on the differences in resource consumption (mainly based on gas cost). type :

[0081]

[0082] Where type represents the condition that type∈T type Transaction category, Gas type This indicates the gas consumption for this type of transaction. Similarly, Gas... transfer Gas consumption for transfer transactions. ρ transfer The weight of the transfer transaction has been normalized to 1. In this embodiment of the invention, ρ... transfer As a weighting benchmark for other transaction types, the weights of other transaction types can be used relative to ρ. transfer It is calculated based on the proportion of gas consumption.

[0083] like Figure 1 As shown, an embodiment of the present invention provides a sharded blockchain dynamic account allocation method considering transaction type, including steps S1 to S3:

[0084] S1 executes transactions based on the intra-shard consensus protocol of the sharded blockchain system and the weights of each transaction type to generate a local transaction graph;

[0085] S2, aggregate all local transaction graphs to construct a global transaction graph, extract feature vectors representing the system state from the global transaction graph through the graph attention network GAT, and output the account allocation strategy prediction results;

[0086] S3. Input the account allocation strategy prediction result into the GA-PPO agent. The GA-PPO agent models the account allocation problem as a Markov decision process. Based on the state space, action space, and reward function, the GA-PPO agent optimizes the account allocation strategy prediction result and outputs the optimized account allocation strategy result. Based on the intra-shard consensus protocol, the GA-PPO agent generates the decision result of the account-to-shard mapping relationship according to the optimized account allocation strategy result and executes the account migration operation according to the decision result.

[0087] Understandably, given the shortcomings in the background technology, this invention proposes a dynamic account allocation method for sharded blockchains that considers transaction types. This method combines graph neural networks, attention mechanisms, and deep reinforcement learning algorithms, and explicitly models the heterogeneous resource consumption of transaction types by quantifying the weights of each transaction type. This optimizes account allocation in the sharded blockchain system, thereby improving the system's scalability and performance.

[0088] In one possible embodiment, step S1 is performed within each work segment, and step S1 includes sub-steps S101 to S103:

[0089] S101, in each time period (Epoch)t, the working shard W-shard retrieves transactions from the local transaction pool and packages them into transaction blocks. After reaching a consensus based on the consensus protocol within the shard, the transactions are executed within the working shard.

[0090] S102, Work sharding constructs the local transaction graph G lical = (V′, E′), where node V′ represents the set of accounts, edge set E′ represents the set of transaction relationships between accounts, e′∈E′, and the edge weight e′ of each edge e′ in edge set E′ is... i,j The weight ρ of transaction frequency and corresponding transaction type type Joint decision;

[0091] S103, based on local transaction graph G local =(V′,E′) generates a block-level digest and sends it to the decision shard D-shard.

[0092] The block-level digest includes at least: the local transaction graph G. local Key information about the adjacency matrix, transaction volume, and account status updates.

[0093] In one possible embodiment, step S2 includes sub-steps S201 to S205.

[0094] S201, aggregates all local transaction charts G local = (V′, E′) to construct the global transaction graph G global = (V, E), e ∈ E, where e is the edge weight e of each edge e in the edge set E.i,j The weight ρ of transaction frequency and corresponding transaction type tyoe A joint decision.

[0095] Steps S202 to S205 are mainly used to extract feature vectors representing the system state. Feature extraction is specifically implemented through the encoder module based on the Graph Attention Network (GAT). Please refer to [link to relevant documentation]. Figure 3 As shown, the encoder includes multiple sub-modules, namely the individual encoder Per-Encoder, the interactive encoder Inter-Encoder, and the global encoder Global-Encoder.

[0096] S202, completed in the individual encoder (Per-Encoder), uses the graph attention network (GAT) to parse the adjacency matrix to detect global transaction graph G. global The non-zero elements in the edge set E are used to generate the edge index matrix edge, which represents the source and target nodes of each edge. index Where |ε| represents the number of edges, defined as:

[0097] edge index ={(i,j)|E i,j ≠0}∈R 2×|ε| (2)

[0098] Among them, edge index ∈R 2×|ε| The edge index matrix is ​​a 2-row, |ε|-column real matrix, where the first and second rows of each column correspond to the source and target nodes of each edge, respectively.

[0099] S203, completed in the individual encoder (Per-Encoder), converts the feature vectors X of each node... i The feature matrix X is formed by splicing together {X} i :1≤i≤N}, where the feature vector X of each node is... i It is a d-dimensional real vector, where Right now:

[0100]

[0101] S204, completed in the Inter-Encoder, is based on the index matrix edge. index With the feature matrix X, a graph attention mechanism is used to aggregate neighborhood information, capture transaction relationships between accounts, and generate node-level hidden representations.

[0102] Understandably, based on the output of the individual encoder (Per-Encoder), the interactive encoder (Inter-Encoder) module uses a graph attention mechanism to aggregate neighborhood information, effectively capture transaction relationships between accounts, and generate node-level hidden representations.

[0103] Specifically, the Inter-Encoder module employs a two-layer network architecture for account relationship modeling. Correspondingly, step S204 includes sub-steps S2041 and S2042.

[0104] S2041, based on the index matrix edge index The attention weight α is calculated from the feature matrix X. ij The attention weights α of multiple adjacent nodes are... ij The attention weight matrix α is aggregated to obtain the first layer of hidden features Z1.

[0105] Specifically, the first-layer network architecture processes node features X and edge indices edge. index Calculate the attention score. Let... Let X represent the attention score of node j to node i, and let X be the feature of node i and node j respectively. i and X j :

[0106]

[0107] Among them, W and W α The graph attention network (GAT) has learnable parameters, with the superscript T indicating transpose and || representing the concatenation operation. LeakyReLU(·) is the modified linear activation function. The attention weights α are... ij By analyzing attention scores Applying softmax normalization yields:

[0108]

[0109] Where, N i = {n1, n2, ...} represents the set of indices of all neighboring nodes of routing node i, N i The range of values ​​for depends on the degree of node i, which in turn depends on the specific transaction graph structure. k is a set N. i The index of any neighboring node in the [database / database]. Each attention weight α ij Aggregated into attention weight matrix α={α ij :i∈[N],j∈N i}, where N represents the set of all nodes.

[0110] The hidden feature Z1 output by the first layer of the network architecture is activated by LeakyReLU(·), that is:

[0111]

[0112] in, This represents the hidden feature of node i in the hidden feature Z1 output by the first-layer network architecture. The second-layer network architecture performs deeper neighborhood aggregation on the hidden feature Z1 to generate the hidden feature Z2 output by the second-layer network architecture.

[0113] S2042, perform deeper neighborhood aggregation on the first-layer hidden feature Z1 to generate the second-layer output hidden feature Z2.

[0114] Understandably, due to the similar structure of the two-layer network, the structure of hidden feature Z2 is the same as that of hidden feature Z1, as shown below:

[0115]

[0116] in, This represents the hidden feature of node i in the hidden feature Z2 output by the second-layer network architecture. W′ also represents the learnable weight matrix, α′ ij These are the attention weights calculated by the second-layer network architecture, and the linear activation is also corrected using the function LeakyReLU(·).

[0117] S205, completed in the Global-Encoder, integrates the node-level hidden representations of each node and projects them onto the action dimension, using the inferred optimal action vector A′ as the prediction result for the account allocation strategy.

[0118] Understandably, the Global-Encoder module integrates and processes the output of the Inter-Encoder (inter-account interaction encoder) to derive the final action. Given that account allocation naturally corresponds to a discrete action space, the GA-PPO agent constructs an action probability distribution through a fully connected layer and performs action selection using a sampling strategy. Correspondingly, step S205 includes sub-steps S2051 to S2053.

[0119] S2051, Construct the action probability distribution space, project the hidden feature Z2 of the second layer output onto the action dimension A through a fully connected layer, and generate the prediction score matrix logits, i.e.:

[0120] logits = W out Z2+b out (8)

[0121] Among them, W out and bout These are the learnable parameters of the output layer.

[0122] S2052, logits of the predicted score vector of node i. i After normalization, the action probability distribution π of node i is obtained. i ,Right now:

[0123] π i =softmax(logits) i (9)

[0124] Among them, softmax(logits) i ) is a normalization function to ensure that the sum of the probabilities of each action of node i is 1.

[0125] S2053, Node i is based on the action probability distribution π i Action index a i ~Categorical(·π) i Sampling is performed using the categorical distribution Categorical(·), represented as:

[0126] a i ~Categorical(π) i (10)

[0127] Among them, the action a of each node i The actions corresponding to the associated accounts are collectively constituted by action vector A′, which serves as the prediction result for the account allocation strategy.

[0128] In one possible embodiment, step S3 is used for DRL policy learning and optimization decision-making. Before performing step S3, as follows: Figure 4 As shown, it is also necessary to construct and train the GA-PPO agent. The construction and pre-training of the GA-PPO agent only need to be performed before the first execution of each step S3 of this invention; subsequent executions can improve the performance of the GA-PPO agent through continuous training. To train the GA-PPO agent, this embodiment of the invention employs a proximal strategy to optimize the PPO algorithm.

[0129] More specifically, in step S3, the account allocation problem is modeled as a Markov decision process by the GA-PPO agent, and the prediction result of the account allocation strategy is optimized based on the state space, action space and reward function to output the optimized result of the account allocation strategy, including sub-steps S301 to S303.

[0130] S301 models the account allocation problem as a Markov Decision Process (MDP), defining the state space S, action space A, and reward function R. t .

[0131] State Space S: The state space S aims to capture the complex transaction relationships between accounts and the real-time state of the shards. Specifically, embodiments of the present invention represent the transaction relationships between accounts as a transaction graph, enabling the agent to systematically discover potential transaction patterns and optimize account allocation decisions. The state space S at each time step t is formally defined as:

[0132] S t =[E,K,L sh ,L ac ] t (11)

[0133] Where E represents the transaction relationship between accounts, K is an H-dimensional heat vector, H is the number of shards, and represents the distribution of accounts participating in the transaction. L sh This indicates a fragmented workload, while L ac Record the workload status of a single account.

[0134] Action Space A: Action Space A explicitly represents account allocation decisions using integer encoding. At each time step t, the decision shard D-shard selects an action vector:

[0135] A t =[a1,a2,…,a i ,…,a N ] t,i≤i≤N (12)

[0136] Among them, a i This indicates that the i-th account is assigned to the a-th account. i Each work segment is a W-shard.

[0137] Reward function R t The optimization objective of this invention is to select an allocation strategy under a given transaction network topology to minimize cross-shard transaction rate, reduce system workload imbalance, and control account migration rate. The reward function of the agent GA-PPO model at each time step t can be defined as follows:

[0138] R t =-ξ1·η-ξ2·μ-ξ3·ν+C (13)

[0139] Where ν represents the account migration rate, μ represents the system workload imbalance, and η represents the cross-shard transaction rate. ξ1, ξ2, and ξ3 are preset weighting coefficients, and C is a scaling constant used for reward calibration.

[0140] S302, at each time step t, the state space S observed by the D-shard agent GA-PPO model for decision segmentation is... tThis state includes account transaction relationships, account distribution, and workloads for shards and individual accounts.

[0141] like Figure 4 As shown, the Actor network θ is based on the current account allocation strategy π θ Generate action a t Execute action a t Afterwards, the environment returns a reward R. t And transition to the next state S t+1 The empirical tuple (S) t A t ,R t ,S t+1 The data is stored in the experience replay buffer B. During each training cycle, mini-batch data is sampled from buffer B to train the network parameters.

[0142] In S303, to decouple time dependencies and enhance training stability, the GA-PPO model actively samples M batches of trajectory segments from historical interaction data. By sampling multiple trajectory segments from historical interaction data, the GA-PPO agent can acquire data from different time periods, states, and action combinations; capture changes in this data, and dynamically adjust the strategy based on historical experience to adapt to the current trading environment. This approach allows for smoother learning of strategy improvements, avoids drastic fluctuations during training, removes redundant data, and improves the efficiency of the training process.

[0143] The scheme in step S303 is implemented through two collaborative mechanisms: value estimation based on critics and variance-reduced advantage function calculation. The critic network parameterizes the state-action pairs to approximate discounted cumulative rewards. To reduce the variance of the long-term advantage estimate, a generalized advantage estimate (GAE) with time regularization is used, and its corresponding formula is as follows:

[0144]

[0145] Where γ represents the discount factor, λ is the GAE smoothing coefficient, and V φ Corresponding to the Critic's state value prediction, r t The immediate reward obtained at time step t, where T is the total number of time steps in an episode (round), δ t δ t+l Discount rewards for time steps t and t+1.

[0146] Given that neural networks, as nonlinear function approximators, are susceptible to policy oscillations and suboptimal convergence, the GA-PPO model uses an importance sampling ratio... Strategically reclaim historical policy data, while simultaneously forcing constraint updates through gradient pruning operations:

[0147]

[0148] Where ∈ is used as the pruning threshold to prevent excessive deviation from the previous strategy.

[0149] To establish reliable value estimation and effectively support policy optimization, the GA-PPO agent iteratively refines the network parameters φ by minimizing the squared error loss between the value prediction and the empirical reward signal.

[0150]

[0151] in, This indicates cumulative discount rewards.

[0152] Calculate the total loss:

[0153] L total =-L CLIP +c1L VF -c2H(π θ (17)

[0154] Where H is the policy entropy, H(π) θ ) is the strategy π θ The policy entropy is increased to enhance the randomness of the policy, thus encouraging exploration. c1 and c2 are preset weights used to balance the importance of policy loss, value function loss, and policy entropy in the total loss.

[0155] The Actor network parameters θ and the Critic network parameters φ are updated using gradient descent. Finally, the updated policy parameters θ are periodically compared with the old policy. Synchronization prepares for subsequent environmental interactions.

[0156] In one possible embodiment, step S3, which involves generating a decision result for the mapping relationship between accounts and shards based on the intra-shard consensus protocol and the optimization result of the account allocation strategy, and performing an account migration operation based on the decision result, includes sub-step S304: strategy consensus, deployment, and account migration.

[0157] S304, within the decision-making shard D-shard, determine the optimal action A output by the GA-PPO agent based on the intra-shard consensus protocol. t A consensus was reached that the optimal action A t Assign a strategy to the accounts for the next period t+1;

[0158] The decision shard (D-shard) generates a decision block containing the account-to-shard mapping and broadcasts it to all working shards (W-shard).

[0159] The corresponding working shard W-shard receives and verifies the decision block, based on the obtained new policy K. (t+1) Perform the necessary account migration operations.

[0160] In one possible embodiment, such as Figure 5 As shown, the method of the present invention further includes step S4:

[0161] Record the process data of performing account migration operations according to the new strategy, and use the recorded process data to continuously train the GA-PPO agent.

[0162] Specifically, in period t+1, the work shard W-shard uses the new account allocation strategy K. (t+1) Execute the transaction, generate a new block, and record the updated workload L. sh And cross-shard transaction statistics. Simultaneously, the decision shard (D-shard) monitors new blocks and obtains environmental feedback information, such as account migration rate v, cross-shard transaction rate η, load imbalance μ, and new state S. t+1 These data are used for subsequent DRL agent training (e.g., applied to steps S302-303 in the aforementioned embodiments) to achieve continuous optimization of the strategy in dynamic trading mode.

[0163] The process of global training of multiple decision shards (D-shards) based on a global system is described below. The training process in the decision shards (D-shards) occurs in a dedicated consensus phase.

[0164] The global training process includes:

[0165] 1.Proposal

[0166] The leader of the decision shard (D-shard) aggregates observations of the global system, including the latest state updates. * Action set a * Cross-shard transaction statistics and shard workload are collected. This information is packaged into a proposed training block and broadcast to all D-shard nodes for verification.

[0167] 2. Verification

[0168] Upon receiving the proposal, each D-shard node independently uses the state update s * and its local proxy copy verification action set a * The rationality of this is as follows. To accommodate minor differences in the model, an adaptive validation threshold is introduced, namely:

[0169]

[0170] Among them, Th baseIt's the base threshold, TrustScore. Leader η is the leader's reputation over the past k' rounds of training, and η' is the adjustment factor. Each node is adjusted based on its state s. * Calculate its local inference actions And use cosine similarity to validate the proposal:

[0171]

[0172] If the similarity exceeds the verification threshold Th, the proposal is considered valid. Then, the D-shard node broadcasts a verification message.

[0173] 3. Submit

[0174] Once a D-shard node receives a verification message from more than 2 / 3 of the D-shard nodes, it confirms the proposal and updates its local proxy model. The D-shard leader then concludes the training round by broadcasting the updated account allocation policy to the W-shards.

[0175] Secondly, the D-shard leader generates a new decision block based on the updated agent model, which contains the latest account allocation policy. This decision block is then broadcast to all working shards, W-shards. Each working shard, upon receiving the decision block, parses the account allocation policy within it and executes the latest policy in the next period, t+1.

[0176] Then, each working shard (W-shard) receives a decision block from the decision shard (D-shard) containing account allocation policies that specify which accounts need to be migrated to other shards. The working shard (W-shard) then parses the account allocation policies in the decision block to determine the list of accounts to be migrated and their target shards.

[0177] During the migration process, to ensure data consistency, the working shard (W-shard) temporarily locks the accounts to be migrated to prevent new transactions from occurring during the migration. The current state of the accounts to be migrated (such as balance and transaction history) is backed up for restoration in the target shard. Based on the account allocation policy, the accounts to be migrated are removed from the local state of the current shard, and their status information, including the target shard ID, is updated. The backed-up account status data is sent to the target shard. This data includes the account's basic information, current balance, and transaction history. The target shard receives and verifies the sent account data, ensuring data integrity and consistency. The account state is restored in the target shard, including updating the account's shard ID, balance, and transaction history.

[0178] After completing the account migration, the W-shard updates the state of its local shard, including workload and cross-shard transaction statistics, and packages the updated state and transaction data into a new block. The new block contains the following: the migrated account state, newly generated transaction data, updated shard workload statistics, and cross-shard transaction statistics. Executing the new block in the local shard ensures that all transactions and state updates are processed correctly.

[0179] Finally, the decision shard (D-shard) continuously monitors and receives newly generated blocks from all working shards (W-shards). These new blocks contain the latest account migration results, transaction execution data, and updated workload and cross-shard transaction statistics. The decision shard (D-shard) extracts key data from the new blocks, including the account migration rate (v), cross-shard transaction rate (η), load imbalance (μ), and the new state (S). t+1 .

[0180] Figure 2 This invention provides an architecture diagram of a sharded blockchain dynamic account allocation system that considers transaction types, as shown in the embodiment of the invention. Figure 2 As shown, a sharded blockchain dynamic account allocation system considering transaction types includes a decision shard and multiple working shards, wherein:

[0181] Work sharding is used to execute transactions based on the consensus protocol within a sharded blockchain system and the weights of each transaction type, in order to generate a local transaction graph;

[0182] Decision sharding is used to aggregate all local transaction graphs to construct a global transaction graph. The graph attention network (GAT) extracts feature vectors representing the system state from the global transaction graph and outputs the account allocation strategy prediction results.

[0183] The decision sharding is also used to input the prediction results of the account allocation strategy into the trained GA-PPO agent to output the optimized results of the account allocation strategy; based on the consensus protocol within the shard, the decision results of the account-to-shard mapping relationship are generated according to the optimized results of the account allocation strategy, and the account migration operation is executed according to the decision results.

[0184] Decision sharding can also be used to record process data of account migration operations performed according to new strategies, and the recorded process data can be used to continuously train the GA-PPO agent.

[0185] It is understood that the sharded blockchain dynamic account allocation system considering transaction type provided by the present invention corresponds to the sharded blockchain dynamic account allocation method considering transaction type provided in the foregoing embodiments. The relevant technical features of the sharded blockchain dynamic account allocation system considering transaction type can be referred to the relevant technical features of the sharded blockchain dynamic account allocation method considering transaction type, and will not be repeated here.

[0186] Please see Figure 6 , Figure 6 A schematic diagram illustrating an embodiment of the electronic device provided in this invention. For example... Figure 6 As shown, this embodiment of the invention provides an electronic device 600, including a memory 610, a processor 620, and a computer program 611 stored in the memory 610 and executable on the processor 620. When the processor 620 executes the computer program 611, it performs the following steps:

[0187] S1 executes transactions based on the intra-shard consensus protocol of the sharded blockchain system and the weights of each transaction type to generate a local transaction graph;

[0188] S2, aggregate all local transaction graphs to construct a global transaction graph, extract feature vectors representing the system state from the global transaction graph through the graph attention network GAT, and output the account allocation strategy prediction results;

[0189] S3. Input the predicted account allocation strategy into the trained GA-PPO agent. The GA-PPO agent models the account allocation problem as a Markov decision process. Based on the state space, action space, and reward function, the predicted account allocation strategy is optimized to output the optimized account allocation strategy. Based on the intra-shard consensus protocol, the decision result of the account-to-shard mapping relationship is generated according to the optimized account allocation strategy. The account migration operation is executed according to the decision result.

[0190] Optional, also includes:

[0191] S4 records the process data of performing account migration operations according to the new strategy, and uses the recorded process data to continuously train the GA-PPO agent.

[0192] Please see Figure 7 , Figure 7 This is a schematic diagram illustrating an embodiment of a computer-readable storage medium provided by the present invention. (See diagram below.) Figure 7 As shown, this embodiment provides a computer-readable storage medium 700, on which a computer program 711 is stored. When the computer program 711 is executed by a processor, it performs the following steps:

[0193] S1 executes transactions based on the intra-shard consensus protocol of the sharded blockchain system and the weights of each transaction type to generate a local transaction graph;

[0194] S2, aggregate all local transaction graphs to construct a global transaction graph, extract feature vectors representing the system state from the global transaction graph through the graph attention network GAT, and output the account allocation strategy prediction results;

[0195] S3. Input the predicted account allocation strategy into the trained GA-PPO agent. The GA-PPO agent models the account allocation problem as a Markov decision process. Based on the state space, action space, and reward function, the predicted account allocation strategy is optimized to output the optimized account allocation strategy. Based on the intra-shard consensus protocol, the decision result of the account-to-shard mapping relationship is generated according to the optimized account allocation strategy. The account migration operation is executed according to the decision result.

[0196] Optional, also includes:

[0197] S4 records the process data of performing account migration operations according to the new strategy, and uses the recorded process data to continuously train the GA-PPO agent.

[0198] The present invention provides a method, system, and storage medium for dynamic account allocation in sharded blockchains that considers transaction types, which has the following advantages:

[0199] 1. By defining multiple (e.g., the 14 types indicated in the examples) transaction types T type And quantify its weight ρ type It accurately characterizes the heterogeneous resource consumption (e.g., computation, storage, gas costs) of different types of transactions, enabling sharded workloads L sh and account workload L ac The calculations are more realistic, providing an accurate basis for load balancing optimization and effectively solving the load estimation bias and imbalance problems caused by the neglect of transaction types in existing methods.

[0200] 2. By integrating Graph Attention Network (GAT) into the DRL framework (GA-PPO), this invention effectively models the topological structure of the transaction graph (especially its scale-free properties) and implicit dependencies between accounts. GAT's attention mechanism adaptively weights neighbor nodes, highlighting key accounts (such as hub nodes), enabling the model to more accurately capture the core dependencies influencing transaction behavior. This overcomes the shortcomings of static graph algorithms in adapting to spatiotemporal dynamics and implicit dependencies, and is also superior to naive DRL methods (such as Spring) that lack effective graph structure modeling capabilities.

[0201] 3. This invention formalizes the account allocation problem as a multi-objective optimization problem that simultaneously minimizes the cross-shard transaction rate η, the system load imbalance μ, and the account migration rate ν, and explicitly reflects this in the DRL reward function. This ensures that the allocation strategy achieves the best trade-off among the three, avoiding the limitations of existing methods that focus on a single objective (such as only reducing cross-shard transactions) or ignore migration overhead.

[0202] 4. Based on DRL (especially the near-end strategy optimization algorithm PPO) and distributed consensus training mechanism, this invention can continuously learn from historical transaction sequences, adapt to the spatiotemporal dynamic changes of transaction patterns, predict future interaction possibilities, and proactively allocate accounts that may interact to the same shard. The strategy update process is efficient and can handle large-scale graph data.

[0203] It should be noted that the descriptions of each embodiment in the above embodiments have different focuses. For parts that are not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0204] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0205] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0206] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0207] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0208] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including both the preferred embodiments and all changes and modifications falling within the scope of the invention.

[0209] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends to include these modifications and variations.

Claims

1. A method for dynamic account allocation in a sharded blockchain that considers transaction type, characterized in that, The methods include: S1, construct a sharded blockchain system, execute transactions based on the consensus protocol within each shard of the sharded blockchain system and the weights of each transaction type, to generate a local transaction graph; wherein, the construction of the sharded blockchain system specifically includes: A sharded blockchain system architecture is constructed based on decision sharding and multiple working shards, wherein the working shards are at least used to execute transactions, generate transaction blocks, and manage local account states; and the decision shards are at least used to be responsible for global state maintenance, strategy learning, and decision generation. Determine the consensus protocol within the shards of the system to ensure that transactions within the shards reach consensus in the event that no more than one-third of the nodes act maliciously; Define a set of transaction types, and quantify the weight of each transaction type in the set based on the differences in resource consumption among the various transaction types; S2, aggregate all local transaction graphs to construct a global transaction graph, extract feature vectors representing the system state from the global transaction graph using a graph attention network (GAT), and output the account allocation strategy prediction results; including: S201 aggregates all local transaction charts To build a global transaction graph edge set The edge weights corresponding to each edge e in the equation. Weighted by trading frequency and corresponding trading type Joint decision; S202 uses the Graph Attention Network (GAT) to analyze the adjacency matrix to detect global transaction graphs. edge set The non-zero elements in the matrix are used to generate the edge index matrix corresponding to the source and target nodes of each edge. ; S203, convert the feature vectors of each node splicing to form a feature matrix The feature vector of each node It is a d-dimensional real vector; S204, based on the index matrix and characteristic matrix It employs a graph attention mechanism to aggregate neighborhood information, capture transaction relationships between accounts, and generate node-level hidden representations; specifically including: S2041, based on index matrix and characteristic matrix The attention weights are calculated. The attention weights of multiple adjacent nodes Aggregated into attention weight matrix The first layer of hidden features is obtained. ; S2042, hide the first layer of features Perform deeper neighborhood aggregation to generate a second layer of output hidden features. ; S205, integrate the node-level hidden representations of each node and project them onto the action dimension, then use the inferred optimal action vector A. As a result of account allocation strategy prediction; S3, the account allocation problem is modeled as a Markov decision process by the GA-PPO agent, and the prediction result of the account allocation strategy is optimized based on the state space, action space and reward function to output the optimized account allocation strategy result; based on the intra-shard consensus protocol, the decision result of the account-to-shard mapping relationship is generated according to the optimized account allocation strategy result, and the account migration operation is executed according to the decision result.

2. The method for dynamic account allocation in a sharded blockchain considering transaction type as described in claim 1, characterized in that, Step S1 includes: S101: The working shard retrieves transactions from the local transaction pool and packages them into transaction blocks. After reaching a consensus based on the consensus protocol within the shard, the transaction is executed within the working shard. S102, construct a local transaction graph for job sharding , where the nodes ' represent a set of accounts, and the edge set ' represents a set of transaction relationships between accounts. The edge weight corresponding to each edge e' in the edge set ' is jointly determined by the transaction frequency and the weight of the corresponding transaction type ; S103, based on local transaction graph Generate a block-level digest and send it to the decision shard.

3. The method for dynamic account allocation in a sharded blockchain considering transaction type as described in claim 2, characterized in that, In step S103, the block-level digest includes at least: Key information about the adjacency matrix of the local transaction graph, transaction volume, and account status update information.

4. The method for dynamic account allocation in a sharded blockchain considering transaction type as described in claim 1, characterized in that, Step S205 includes: S2051, Construct the action probability distribution space and hide the second layer output features. Projected onto the action dimension Generate the prediction score matrix ; S2052, will the node Predicted score vector After normalization, the nodes are obtained Action probability distribution ; S2053, will the node Based on action probability distribution Action Index By classification distribution Sampling is performed to infer the actions of each node. The actions corresponding to its associated accounts, together constitute action vector A. The action vector A As a prediction result of account allocation strategy.

5. The method for dynamic account allocation in a sharded blockchain considering transaction type as described in claim 1, characterized in that, The method of modeling the account allocation problem as a Markov decision process using a GA-PPO agent, optimizing the predicted account allocation strategy based on the state space, action space, and reward function, and outputting the optimized account allocation strategy result includes: S301 models the account allocation problem as a Markov decision process, defining the state space. Action space and reward function ,in: The state space at each time step t is formally defined as: , in, This indicates the transaction relationship between accounts. It is an H-dimensional heat vector, where H is the number of segments, representing the distribution of accounts participating in the transaction; Indicates fragmented workload, Record the workload status of a single account; Action space Account allocation decisions are explicitly represented by integer encoding, and an action vector is selected at each time step t: , Define reward function for: , in, Indicates account migration rate. Indicates the system workload imbalance. Indicates the cross-shard transaction rate; , and These are preset weighting coefficients. It is a scaling constant used for reward calibration; S302, observation state space at each time step t. According to the current account allocation policy Generate Actions ; Perform actions Afterwards, the environment returns a reward. And move to the next state. ; empirical tuples The data is stored in the experience replay buffer B. In each training cycle, a small batch of data is sampled from buffer B to train the network parameters. S303 actively samples M batches of trajectory segments from historical interaction data; Based on the critic's value estimate, the state-action pairs are parameterized to approximate discounted cumulative returns; based on the variance-reduced advantage function, a generalized advantage estimate (GAE) with time regularization is adopted to reduce the variance of the long-term advantage estimate, and its corresponding formula is as follows: , in, Indicates the discount factor. For GAE smoothing coefficients, Corresponding to the Critic's state value prediction, The immediate reward obtained at time step t, where T is the total number of time steps in a round. , Discount rewards for time steps t and t+1; Importance sampling ratio Strategically reclaim M batches of trajectory fragments from historical strategy data, while simultaneously forcibly updating constraints through gradient pruning operations: , in, As a pruning threshold, to prevent excessive deviation from the previous strategy; The network parameters are iteratively refined by minimizing the squared error loss between the value prediction and the empirical reward signal. : , in, This indicates cumulative discount rewards; Calculate total loss : , in For strategy The policy entropy below is used to encourage exploration; , These are preset weights; Update the Actor network parameters using gradient descent. and Critic network parameters And regularly update the strategy parameters Compared to the old strategy synchronous.

6. The method for dynamic account allocation in a sharded blockchain considering transaction type as described in claim 1, characterized in that, In step S3, the step of generating a decision result for the account-to-shard mapping relationship based on the intra-shard consensus protocol and the account allocation strategy optimization result, and performing an account migration operation based on the decision result, includes: Optimal action output by GA-PPO agent based on intra-shard consensus protocol A consensus was reached on the optimal action. Assign a strategy to the accounts for the next period t+1; The decision shard generates a decision block containing the account-to-shard mapping relationship and broadcasts it to each working shard; The corresponding working segment receives and verifies the decision block, based on the obtained new strategy. Execute the corresponding account migration operation.

7. The method for dynamic account allocation in a sharded blockchain considering transaction type as described in claim 1, characterized in that, Also includes: S4 records the process data of performing account migration operations according to the new strategy, and uses the recorded process data to continuously train the GA-PPO agent.

Citation Information

Patent Citations

  • Inductive block chain account distribution method and device based on graph neural network

    CN117391858A

  • Fragmented block chain account distribution method and system

    CN119322672A