Block chain fragment optimization method and device, electronic equipment and readable storage medium
By using the Métis graph partitioning algorithm and utility function threshold mechanism in the blockchain system, the sharding scheme is dynamically optimized, solving the problems of load balancing and low communication efficiency in distributed environments, and achieving more efficient sharding management.
Patent Information
- Application Number
- CN202511210129.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-27
- Publication Date
- 2025-11-11
Smart Images

Figure CN120935191A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of blockchain technology, and in particular to blockchain sharding optimization methods, apparatus, electronic devices, and readable storage media. Background Technology
[0002] Against the backdrop of the rapid development of large-scale distributed systems, blockchain, as an important infrastructure for trusted data storage and sharing, is being widely applied in various fields such as the Internet of Things, edge computing, smart cities, and energy management.
[0003] Existing blockchain sharding methods typically employ sharding strategies based on fixed rules or simple performance metrics. However, nodes in a distributed environment are usually composed of various distributed devices with significant performance differences, uneven network quality, and varying computing capabilities. When existing blockchain systems are deployed in such environments, the dynamic changes in node devices make it difficult for blockchain sharding schemes to achieve efficient global load balancing and intra-shard communication efficiency. Summary of the Invention
[0004] In view of this, the embodiments of this application provide at least a blockchain sharding optimization method, apparatus, electronic device and readable storage medium. By performing local dynamic optimization of the blockchain sharding scheme through the utility function value of sharding, the global load balancing and intra-shard communication efficiency of the blockchain system can be improved.
[0005] This application mainly includes the following aspects: In a first aspect, embodiments of this application provide a blockchain sharding optimization method, applied to a blockchain sharding device in a blockchain system, wherein the blockchain system further includes multiple distributed devices; each of the distributed devices is communicatively connected to the blockchain sharding device; the method includes: Based on the initial performance parameters of each of the distributed devices and the Métis graph partitioning algorithm, the initial sharding scheme of the blockchain is determined, and the multiple distributed devices are sharded according to the initial sharding scheme. For each shard in the initial sharding scheme, the utility function value of the shard is determined based on the real-time performance index parameters of each distributed device in the shard. If the utility function value of the shard is less than the preset utility function threshold, then based on the real-time performance index parameters of each distributed device in the shard and the Métis graph partitioning algorithm, the distributed devices in the shard are re-sharded to obtain the locally optimized sharding scheme of the blockchain, and the multiple distributed devices are sharded according to the locally optimized sharding scheme.
[0006] Secondly, embodiments of this application also provide a blockchain sharding optimization device, applied to a blockchain sharding device in a blockchain system, wherein the blockchain system further includes multiple distributed devices; each of the distributed devices is communicatively connected to the blockchain sharding device; the blockchain sharding optimization device includes: The initial sharding module is used to determine the initial sharding scheme of the blockchain based on the initial performance index parameters of each of the distributed devices and the Métis graph partitioning algorithm, and to shard the multiple distributed devices according to the initial sharding scheme; The utility calculation module is used to determine the utility function value of each shard in the initial sharding scheme based on the real-time performance index parameters of each distributed device in the shard. The local optimization module is used to re-shard each distributed device in the shard based on the real-time performance index parameters of each distributed device in the shard and the Métis graph partitioning algorithm if the utility function value of the shard is less than a preset utility function threshold, thereby obtaining a locally optimized sharding scheme for the blockchain, and sharding the multiple distributed devices according to the locally optimized sharding scheme.
[0007] Thirdly, embodiments of this application also provide an electronic device, including: a processor, a memory, and a bus. The memory stores machine-readable instructions executable by the processor. When the electronic device is running, the processor communicates with the memory through the bus, and the machine-readable instructions are executed by the processor to perform the steps of the blockchain sharding optimization method as described above.
[0008] Fourthly, embodiments of this application also provide a computer-readable storage medium storing a computer program, which, when executed by a processor, performs the steps of the blockchain sharding optimization method as described above.
[0009] The blockchain sharding optimization method, apparatus, electronic device, and readable storage medium provided in this application embodiment are applied to a blockchain sharding device in a blockchain system. The blockchain system also includes multiple distributed devices; each distributed device is communicatively connected to the blockchain sharding device. The method includes: determining an initial sharding scheme for the blockchain based on the initial performance index parameters of each distributed device and the Métis graph partitioning algorithm, and sharding the multiple distributed devices according to the initial sharding scheme; for each shard in the initial sharding scheme, determining the utility function value of the shard based on the real-time performance index parameters of each distributed device in the shard; if the utility function value of the shard is less than a preset utility function threshold, then re-sharding the distributed devices in the shard based on the real-time performance index parameters of each distributed device in the shard and the Métis graph partitioning algorithm to obtain a locally optimized sharding scheme for the blockchain, and sharding the multiple distributed devices according to the locally optimized sharding scheme. In this way, by locally and dynamically optimizing the blockchain sharding scheme through the utility function value of the shard, the global load balancing and intra-shard communication efficiency of the blockchain system can be improved.
[0010] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0011] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0012] Figure 1 A schematic diagram of the blockchain system in an embodiment of this application is shown; Figure 2 A flowchart illustrating a blockchain sharding optimization method provided in an embodiment of this application is shown; Figure 3 This illustration shows one of the functional block diagrams of a blockchain sharding optimization device provided in an embodiment of this application; Figure 4 This illustration shows a second functional block diagram of a blockchain sharding optimization device provided in an embodiment of this application; Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of this application is shown. Detailed Implementation
[0013] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. The components of the embodiments of this application described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely represents selected embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0014] The following will combine Figure 1 The implementation methods of the embodiments of this application are described in detail; the embodiments of this application provide a blockchain sharding optimization method, which is applied to the blockchain sharding device of the blockchain system.
[0015] Please see Figure 1 , Figure 1 This is a schematic diagram of the blockchain system in an embodiment of this application. Figure 1 As shown, the sharding optimization method provided in this application embodiment is applied to the blockchain sharding device 110 of the blockchain system 100. The blockchain system 100 also includes multiple distributed devices 120; each distributed device 120 is communicatively connected to the blockchain sharding device 110.
[0016] In this embodiment, the blockchain system 100 can be divided into two main layers: a blockchain sharding device 110 as the blockchain operation layer and multiple distributed devices 120 as the distributed Internet of Things network layer.
[0017] The blockchain sharding device 110 is used for shard management, consensus processing, and data recovery of access data, and is the core logic and data security component of the system. Dynamic sharding models and evaluates node performance (such as computing power, bandwidth, and availability) in real time, dynamically dividing access nodes into different shards. Each shard independently runs a sub-chain, processing transaction and state data within its scope. Intra-shard communication is frequent, emphasizing low latency and high consistency. Intra-shard data recovery is automatically triggered when a node joins, leaves, or fails. A fountain code mechanism decodes and reconstructs pre-deployed redundant data blocks to achieve rapid recovery of the original data, ensuring system data integrity and continuity.
[0018] Key entities in the blockchain runtime layer include: Shards consist of multiple nodes, each independently undertaking a portion of the ledger writing and consensus tasks, supporting parallel processing to improve system throughput. During shard initialization, a digital signature mechanism can be used to verify nodes, ensuring trusted network access.
[0019] Node: As the basic unit for the operation of a blockchain subchain, a node is responsible for storing, verifying, and synchronizing the sharded ledger. The system dynamically adjusts the node's workload based on its performance metrics to ensure maximum resource utilization. Encryption mechanisms can be used to ensure data security during communication between nodes within a shard.
[0020] Data recovery node: During the data recovery process, edge computing devices with strong processing capabilities undertake the tasks of collecting and decoding redundant blocks and reconstructing data. They are key auxiliary nodes that ensure the high availability of the system.
[0021] Synchronization source node: During the data encryption process, edge computing devices with strong processing capabilities undertake the task of generating and distributing redundant blocks, and are key auxiliary nodes to ensure the high availability of the system.
[0022] Multiple distributed devices 120 are used for tasks such as sensing, data collection, preprocessing, and communication, serving as the data entry point and front-end support foundation for the blockchain system.
[0023] Typical entities in the distributed Internet of Things (IoT) network layer include: Environmental sensing devices include various sensors such as temperature, pressure, vibration, image, and radiation. They are usually equipped with low-power domestic chips and are widely deployed in industrial sites, transportation hubs, security facilities, or unmanned platforms. They are responsible for collecting scene status and equipment operation data and have low local computing and storage capabilities.
[0024] Edge computing node devices: These are intermediate processing devices with certain computing and network forwarding capabilities, which can be deployed in locations such as field control terminals, industrial vehicle platforms, and edge micro data centers. Their main function is to perform preliminary screening, aggregation, and analysis of raw data, thereby alleviating the processing load on the backend blockchain system.
[0025] Communication relay and access equipment: used to maintain stable connections between terminal nodes, support functions such as identity authentication, data on-chain scheduling, and encrypted transmission, and ensure the access security and communication reachability of the entire system.
[0026] Dynamic control terminals, such as unmanned platform controllers, vehicle-mounted command units, and portable edge access modules, have the ability to flexibly join and leave the network. They can join or leave the network as needed and adapt to node topology reconstruction under dynamic changes in the scenario.
[0027] The following is a detailed description of a blockchain sharding optimization method provided in the embodiments of this application. This blockchain sharding optimization method can be applied to the blockchain sharding device 110 of the blockchain system 100 described above.
[0028] Please see Figure 2 , Figure 2 This is a flowchart illustrating a blockchain sharding optimization method provided in an embodiment of this application. Figure 2 As shown in the embodiments of this application, the blockchain sharding optimization method includes the following steps: S201, based on the initial performance index parameters of each of the distributed devices and the Métis graph partitioning algorithm, determine the initial sharding scheme of the blockchain, and shard the multiple distributed devices according to the initial sharding scheme.
[0029] Here, in the initial stage of blockchain system 100 operation, the connected distributed devices 120 (edge devices or IoT terminals) are started as blockchain nodes. First, the performance parameters of each distributed device 120 (including computing power, communication latency, geographical location, network connectivity, etc.) are comprehensively evaluated, and a weighted graph model is constructed to model it. Subsequently, based on this graph structure, the system uses the Metis graph partitioning algorithm to reasonably shard the distributed device set. The Metis graph partitioning algorithm is a graph partitioning algorithm based on a multi-level partitioning framework, aiming to divide a large graph into multiple subgraphs while minimizing the number of edge cuts between subgraphs and maintaining load balance within subgraphs. In the partitioning process of this embodiment, nodes with strong computing power and good network conditions (especially edge computing devices) are given higher weights and are preferentially allocated to relatively weaker shards, thereby optimizing global load balancing and intra-shard communication efficiency. After this stage is completed, each node is formally mapped to the designated shard network.
[0030] S202, for each shard in the initial sharding scheme, determine the utility function value of the shard based on the real-time performance index parameters of each distributed device in the shard.
[0031] Here, for each shard in the initial sharding scheme, the utility function value of the shard is determined based on the real-time performance metrics of each distributed device within the shard. In this embodiment, as the system continues to operate, the network structure and node performance may change. To address dynamic events such as node state fluctuations and device online / offline events, this embodiment designs a local adjustment mechanism based on utility functions. A set of utility functions based on real-time multi-dimensional performance metrics is defined for each shard to evaluate the overall operating efficiency of the shard. The utility function can synthesize multiple performance metrics into a single value to represent the overall performance or efficiency of the shard.
[0032] S203, if the utility function value of the shard is less than the preset utility function threshold, then based on the real-time performance index parameters of each distributed device in the shard and the Métis graph partitioning algorithm, the distributed devices in the shard are re-sharded to obtain the locally optimized sharding scheme of the blockchain, and the multiple distributed devices are sharded according to the locally optimized sharding scheme.
[0033] Here, if the utility function value of the partition... Less than the preset utility function threshold This indicates that the overall sharding efficiency is low, triggering dynamic local adjustments. The node composition is reassessed, and addition, deletion, and migration operations are performed. Based on the real-time performance parameters of each distributed device in the shard and the Métis graph partitioning algorithm, the distributed devices in the shard are re-sharded to obtain a locally optimized sharding scheme for the blockchain. Multiple distributed devices are then sharded according to this locally optimized sharding scheme. This mechanism has higher responsiveness and adjustment frequency, and is suitable for scenarios with localized performance degradation. In this embodiment, the utility function threshold... This is the minimum utility threshold set by the system, which is determined using a trial-and-error approach. ; .like If a segment is marked as needing optimization, then proceed to local adjustments.
[0034] Furthermore, considering the risks of communication interruptions, consensus delays, and network oscillations that frequent resharding may cause, especially in IoT edge environments where node performance fluctuates frequently and may lead to sharding jitter, in a preferred embodiment of this application, if the utility function value of a shard is less than a utility function threshold for a preset continuous sampling period, then the distributed devices in the shard are resharded based on the real-time performance parameters of each distributed device in the shard and the Métis graph partitioning algorithm; the time interval between two reshardings of the same shard is greater than a preset minimum time interval threshold to avoid repeated short-term sharding adjustments. Specifically, the number of preset continuous sampling periods can be set according to network latency tolerance.
[0035] Furthermore, the performance metrics include communication latency and device bandwidth; determining the initial sharding scheme of the blockchain based on the initial performance metrics of each distributed device and the Métis graph partitioning algorithm includes: Step a1: Based on the initial communication delay and initial device bandwidth of each of the distributed devices, calculate the edge weights between the distributed devices and construct a weighted graph between the distributed devices.
[0036] Here, during the network initialization phase, distributed devices from different application scenarios join the blockchain network, forming a set of nodes to be sharded. The system first constructs a domestic performance evaluation model, establishing a performance benchmark database covering mainstream domestic chips (such as Loongson, Phytium, Kunpeng, Ascend, etc.), domestic operating systems, and domestic storage media. It collects performance metrics such as CPU computing power, memory capacity, storage I / O capability, network bandwidth, and NPU computing power from each node in real time, assigning corresponding domestic weighting coefficients (considering chip generation, maturity, and dedicated instruction set efficiency, etc.).
[0037] Specifically, before the fragmentation, the communication latency between any two distributed devices is obtained through network probing. And obtain the geographical location of distributed devices by leveraging device location services. The node then reports its computing power metrics. (Such as the number of cores, clock speed, etc.), or obtained by querying from a weight database; device bandwidth. The uplink and downlink transmission rates of the distributed devices are then measured using the iperf tool. Based on the collected multi-dimensional performance metrics, the device weight of each distributed device is calculated. The calculation formula is as follows: ; in, A standardized function representing the device's computing power; It is the inverse function of communication delay (the lower the delay, the higher the weight); This is the normalized value of the network bandwidth. This is a function representing the impact of device geographical location distribution on the slicing layout. This is a bias term used to ensure that the weight value is not zero due to the absence of individual dimensions; , , , The localization weighting coefficients for each performance indicator parameter can be flexibly configured according to the actual application scenario.
[0038] Distributed device collection The communication relationships between them can be represented as a weighted graph. ,in, Represents a set of distributed device nodes. This represents the weighted edges between them. The topological relationships and edge weights between distributed device nodes are represented by... Stored in the form of Represents distributed device nodes. This represents the weights of adjacent nodes and edges.
[0039] Specifically, firstly, an initial empty graph is constructed. For distributed device sets Each distributed device in Add a node arrive The device weight is For distributed device sets Each distributed device in ; Obtain communication delay and device bandwidth And calculate the edge weights. If communication delay Then add an edge. arrive The edge weight is Finally, a weighted graph is obtained among the various distributed devices. .
[0040] Step a2: Divide the weighted graph among the distributed devices into multiple subgraphs according to the Métis graph partitioning algorithm.
[0041] Here, after constructing the weighted graph, the Metis graph partitioning algorithm is used to divide the weighted graph among the distributed devices into multiple subgraphs (i.e., shards). The goal is to maximize the collaboration and resource matching between nodes within each shard, thereby maintaining optimal performance within the shard. This partitioning process ensures that the device nodes in each shard have relatively balanced comprehensive capabilities across multiple dimensions such as computing, communication, and bandwidth.
[0042] Specifically, Metis is used for graph partitioning: “ ".
[0043] Step a3: Identify each subgraph as a blockchain shard.
[0044] Here, each subgraph is defined as a blockchain shard, a set of distributed devices. Ultimately, they are divided into different shard sets. First, an empty shard set is initialized. ;in, This is the preset number of shards.
[0045] Step a4: Identify the nodes in each subgraph as the distributed devices corresponding to the blockchain shards.
[0046] Here, we are referring to a distributed set of devices. Any distributed device in ,Will Assigned to the shards corresponding to the Metis partitioning results Finally, the output is a list of distributed devices corresponding to each shard.
[0047] Step a5: Determine each blockchain shard and the corresponding distributed device as the initial sharding scheme for the blockchain.
[0048] Here, the various blockchain shards are divided. and the distributed devices corresponding to each blockchain shard. This was determined as the initial sharding scheme for the blockchain.
[0049] Furthermore, the performance metrics parameters also include device computing power and device geographical location; for each shard in the initial sharding scheme, determining the utility function value of the shard based on the real-time performance metrics parameters of each distributed device in the shard includes: Step b1: After sharding the multiple distributed devices according to the initial sharding scheme, collect the real-time performance index parameters of each distributed device in the shard according to the preset first sampling interval.
[0050] Here, after sharding multiple distributed devices according to the initial sharding scheme, real-time performance parameters of each distributed device, including communication latency, are continuously collected at minute intervals according to a preset first sampling interval. Equipment bandwidth Equipment computing power and the geographical location of the equipment .
[0051] Step b2: Calculate the real-time device weight of each distributed device in the shard based on the real-time performance index parameters of each distributed device in the shard.
[0052] Here, the real-time device weight of each distributed device in the shard is calculated based on the real-time performance metric parameters of each distributed device in the shard. : .
[0053] Step b3: For any sampling time according to the first sampling interval, calculate the exponentially weighted average weight of each distributed device in the shard at the sampling time based on the real-time device weight of each distributed device in the shard at the sampling time and the real-time device weight of the previous sampling time at the sampling time.
[0054] Here, for any sampling moment sampled according to the first sampling interval. Based on the sampling time of each distributed device in the shard, Real-time device weights and at sampling time The previous sampling time Real-time device weights The sampling time of each distributed device in the shard is calculated. Exponential weighted average weight The index-weighted average will be used in subsequent fragmentation utility function calculations and dynamic allocation strategies to enhance system stability.
[0055] Specifically, update the exponentially weighted average weight of the devices. : ;in, The preset exponential average weighting coefficient; Sampling time The previous sampling time The index-weighted average weight.
[0056] Step b4: Calculate the utility function value of the shard at each sampling time based on the exponentially weighted average weight of each distributed device in the shard at each sampling time.
[0057] Here, partitioning The utility function can be expressed as ;in, It is the equipment The comprehensive performance evaluation function is based on the exponentially weighted average weight, which incorporates a weighted fusion of multiple factors such as computing power, communication latency, bandwidth, and geographical topology. In this embodiment, the exponentially weighted average weight of each distributed device in the shard at each sampling time is used. The utility function values of the slices at each sampling time are calculated. Specifically, the utility function value The calculation can be performed using the following formula: ; in, Exponential weighted average weight The minimum value, Exponential weighted average weight The average value, Exponential weighted average weight variance , , These are preset weighting coefficients used to balance the performance, average load, and overall balance of the weakest node in a shard. , , Typical values can be selected based on experimental data or industry standards. In the embodiments of this application, .
[0058] Furthermore, the re-sharding of each distributed device in the shard based on the real-time performance parameters of each distributed device in the shard and the Métis graph partitioning algorithm, to obtain a locally optimized sharding scheme for the blockchain, includes: Step c1: Calculate the exponentially weighted average weight of each distributed device in the shard based on the real-time performance index parameters of each distributed device in the shard.
[0059] Here, based on the fragmentation Real-time performance metrics of each distributed device in the system are used to calculate sharding. The exponentially weighted average weight of each distributed device in the process .
[0060] Step c2: Calculate the edge weights between the distributed devices in the shard based on the exponentially weighted average weights of each distributed device in the shard, and construct a local weighted graph between the distributed devices in the shard.
[0061] Here, based on the fragmentation The exponentially weighted average weight of each distributed device in the process Calculate the partition The edge weights between the distributed devices in the data are determined, and sharding is constructed. Local weighted graph among various distributed devices in .
[0062] Specifically, inefficient fragmentation All device nodes and their communication relationships are extracted into a subgraph. Construct a locally weighted graph.
[0063] Step c3: The local weighted graph is re-partitioned according to the Métis graph partitioning algorithm to obtain the sub-partition set of the partition.
[0064] Here, the Metis graph partitioning algorithm is used to... The partitioning is performed again to obtain several sub-partitions. The goal of the partitioning is to improve intra-chip communication efficiency and load balancing. According to the new partitioning results... Distributed device nodes in the middle are reassigned to sub-shards In this process, a new structure with local optimization is formed.
[0065] Step c4: Replace the shard with the set of sub-shards of the shard to obtain the locally optimized sharding scheme of the blockchain.
[0066] Here, the original fragment is deleted. Add a new shard set And merged into the global shard set. This yields a locally optimized sharding scheme for the blockchain. This mechanism exhibits good local adaptability and is suitable for operating scenarios in distributed IoT environments characterized by frequent node fluctuations and high heterogeneity.
[0067] Furthermore, the method also includes: Step d1: Collect the exponentially weighted average weight of each of the distributed devices according to the preset second sampling interval; the second sampling interval is greater than the first sampling interval.
[0068] Here, after implementing the network sharding strategy, the system will continuously monitor each shard. When changes are detected in the network status or the internal structure of a shard, such as unexpected node downtime, node performance fluctuations, the addition of a new node, or the exit of an existing node, the system will activate the dynamic adjustment mechanism for the shards according to preset conditions and rules. This application embodiment also includes an overall sharding adjustment mechanism, namely an Epoch-based adjustment mechanism.
[0069] Specifically, an Epoch is defined as the interval between several blocks. That is, the production of a certain number of new blocks by the network is considered an Epoch. The time interval of this Epoch will be maintained between 30 and 45 minutes, and a dynamic adjustment will be triggered at the end of an Epoch. That is, according to the preset second sampling interval, the exponentially weighted average weight of each distributed device is collected; the second sampling interval (30-45 minutes) is greater than the first sampling interval (minute-level period).
[0070] Step d2: For any sampling time sampled according to the second sampling interval, the distributed devices are re-sharded according to the exponential weighted average weight of each distributed device and the Métis graph partitioning algorithm to obtain the overall optimized sharding scheme of the blockchain, and the multiple distributed devices are sharded according to the overall optimized sharding scheme.
[0071] Here, for any sampling moment according to the second sampling interval (Epoch), the distributed devices are re-sharded based on the exponentially weighted average weight of each distributed device and the Métis graph partitioning algorithm to obtain an overall optimized sharding scheme for the blockchain. Multiple distributed devices are then sharded according to this overall optimized sharding scheme. The system sets a fixed period (Epoch). At the end of each period, a unified performance re-evaluation of the current network node status is performed, and the graph partitioning and sharding optimization operations are re-executed. This mechanism is suitable for long-term evolving networks or scenarios with large-scale node changes. Specifically, in each fixed-period update, the device weight average vector is initialized. The initial values are set to the current weight values. The device weight vector from the previous epoch is initialized. The initial values are the same as above.
[0072] Further, any of the distributed devices in the shards includes master node devices and edge node devices; when sharding the plurality of distributed devices according to the locally optimized sharding scheme or the globally optimized sharding scheme, the method further includes: Step e1: For any of the shards, when any master node device is removed from the shard, at least one edge node device in the shard is selected as a data recovery node based on the real-time performance index parameters of each edge node device in the shard.
[0073] Here, distributed devices in any shard include master node devices and edge node devices. During the operation of the distributed blockchain system, due to factors such as limited device hardware resources, complex network environment, and frequent node movement caused by shard optimization adjustments, nodes within a shard may frequently go offline, fail, or experience communication anomalies, leading to missing ledger data or synchronization delays, severely affecting the overall reliability and continuity of the system. To address this, this application employs a collaborative mechanism of "edge computing nodes and Raptor fountain codes" during shard optimization, combining lightweight redundant coding with intelligent scheduling strategies to comprehensively improve data recovery efficiency and synchronization capabilities within the shard. Specifically, edge nodes dynamically select distribution paths based on device bandwidth, prioritizing high-bandwidth devices as redundant block sources. In this embodiment, the fountain code is a Raptor Q code, and the generation of redundant coded blocks satisfies k=32 original data blocks, redundancy r=1.5, and symbol size s=1024 bytes.
[0074] In this application, for any shard, when any master node device is removed from the shard, at least one edge node device in the shard is selected as the data recovery node based on the real-time performance parameters of each edge node device in the shard.
[0075] Specifically, when a master node device within a shard is removed from the shard, the system will automatically initiate the intra-shard data recovery process. The removed node first sends a recovery request to the edge node devices with stronger computing capabilities within the shard. The edge node devices will collect redundant encoded data blocks from other nodes and perform decoding and reconstruction to restore the original data content, ensuring system data consistency.
[0076] In this embodiment, when a node is removed from a shard, it automatically enters a recovery state. At this time, a network heartbeat detection mechanism can detect abnormal node states, and the edge computing node takes over the recovery process. As a scheduling unit with high computing power and high bandwidth capabilities within its local shard, the edge node initiates the following operations: First, fault detection and recovery triggering are performed. The system continuously monitors the operational status of each node device. Once a node is found to have consecutive timeouts, lost heartbeats, or failed task responses, it is marked as "failed." The blockchain sharding device determines whether to trigger data recovery based on its policy. Next, the failed node sends a data recovery request. If the failed node has self-diagnostic capabilities, it will proactively send a recovery request to the data recovery node after being restored and brought back online. If the node is completely offline (removed from the shard), the blockchain sharding device sends a recovery request to the data recovery node device on behalf of the node.
[0077] Step e2: Collect redundant coded blocks corresponding to the removed master node devices from other distributed devices in the shard, and perform data recovery on the data recovery node using the fountain code algorithm.
[0078] Here, the data recovery node collects redundant data blocks. The data recovery node maintains a coding distribution map of the data from each node within the shard. Based on the original data identifier of the failed node, it requests corresponding redundant coded blocks from multiple healthy nodes within the shard. It collects at least k redundant blocks that meet the decoding threshold (e.g., Raptor fountain code requirements). The data recovery node performs fountain code decoding using its built-in decoding module to reconstruct the original data. Successful decoding results in a complete ledger state or data snapshot.
[0079] Furthermore, if the removed master node returns to the shard, the data recovery node can push the recovered data back to that master node. After receiving and verifying the data integrity, the faulty node reloads the ledger state and resumes service. This process significantly reduces the reliance on strong consistency synchronization within the shard, enabling rapid fault-tolerant repair under soft interruption conditions and effectively avoiding shard-level transaction anomalies or chain interruptions caused by single points of failure.
[0080] Furthermore, when sharding the multiple distributed devices according to the locally optimized sharding scheme or the globally optimized sharding scheme, the method further includes: Step f1: For any of the aforementioned shards, when any master node device joins the shard, at least one edge node device in the shard is selected as the synchronization source node based on the real-time performance index parameters of each edge node device in the shard.
[0081] Here, for any shard, when any master node device joins the shard, at least one edge node device in the shard is selected as the synchronization source node based on the real-time performance parameters of each edge node device in the shard. When a new node joins the shard, the system will also automatically trigger the synchronization mechanism. The edge node device with stronger computing power in this shard is selected as the synchronization source node. The synchronization source node pushes the necessary redundant data blocks to the newly joined node according to the ledger state in the shard, helping it to quickly restore the current shard state and thus enabling it to participate in subsequent transaction processing and consensus calculation.
[0082] In this embodiment, new nodes may connect to existing shards during system operation due to task scheduling or dynamic deployment. Since these nodes do not yet hold the current ledger state of the shard, they will be unable to participate in subsequent data processing and consensus tasks if they are not synchronized in a timely manner. To ensure smooth access and system consistency for newly added master node devices, the following synchronization process is sampled: First, node initialization and access authentication are performed. After initialization, the newly added master node device requests to join a designated shard. The system allocates shards based on their performance metrics (computing power, bandwidth, stability) and triggers the data synchronization process. Next, the newly added master node device sends a synchronization request. The newly added master node device sends a data synchronization request to the synchronization source node of the shard it has joined. The synchronization request includes the identity information of the newly added master node device and the target synchronization time point.
[0083] Step f2: Based on the local ledger status and data encoding index in the synchronization source node, construct the redundant code block corresponding to the newly added master node device, and send it to the newly added master node device through the synchronization source node.
[0084] Here, the synchronization source node queries its local ledger state and data encoding index, constructs a lightweight data snapshot containing k redundant code blocks based on the current shard state, and sends the redundant code blocks back. The synchronization source node then securely transmits the redundant code blocks from the snapshot to the newly joined master node device. Data transmission is encrypted using a national cryptographic algorithm (such as SM4-GCM). The newly joined master node device uses the received encoded blocks to perform decoding, restoring the ledger state and configuration data of the current shard. After successful decoding, the node enters the synchronization state, possesses a complete ledger view, and can participate in subsequent consensus.
[0085] Furthermore, newly added master node devices can perform ledger alignment verification with at least one other master node device within the shard. After successful verification, the node status is updated to "active," and it officially joins the shard network.
[0086] This application provides a blockchain sharding optimization method applied to a blockchain sharding device within a blockchain system. The blockchain system also includes multiple distributed devices, each of which is communicatively connected to the blockchain sharding device. The method includes: determining an initial sharding scheme for the blockchain based on the initial performance index parameters of each distributed device and a Métis graph partitioning algorithm; sharding the multiple distributed devices according to the initial sharding scheme; for each shard in the initial sharding scheme, determining the utility function value of the shard based on the real-time performance index parameters of each distributed device in the shard; if the utility function value of the shard is less than a preset utility function threshold, then re-sharding the distributed devices in the shard based on the real-time performance index parameters of each distributed device in the shard and the Métis graph partitioning algorithm to obtain a locally optimized sharding scheme for the blockchain; and sharding the multiple distributed devices according to the locally optimized sharding scheme. In this way, by dynamically optimizing the blockchain sharding scheme locally through the utility function value of the shard, the global load balancing and intra-shard communication efficiency of the blockchain system can be improved.
[0087] Based on the same application concept, this application also provides a blockchain sharding optimization device corresponding to the blockchain sharding optimization method provided in the above embodiments. Since the principle of the device in this application to solve the problem is similar to the blockchain sharding optimization method in the above embodiments of this application, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be described again.
[0088] Please see Figure 3 , Figure 3 This is one of the functional block diagrams of a blockchain sharding optimization device provided in an embodiment of this application. The blockchain sharding optimization device provided in this embodiment is applied to... Figure 1 The blockchain sharding device 110 of the blockchain system 100 shown is illustrated. Figure 3 As shown, the blockchain sharding optimization device 300 includes: The initial sharding module 310 is used to determine the initial sharding scheme of the blockchain based on the initial performance index parameters of each of the distributed devices and the Métis graph partitioning algorithm, and to shard the multiple distributed devices according to the initial sharding scheme.
[0089] The utility calculation module 320 is used to determine the utility function value of each shard in the initial sharding scheme based on the real-time performance index parameters of each distributed device in the shard.
[0090] The local optimization module 330 is used to re-shard each distributed device in the shard based on the real-time performance index parameters of each distributed device in the shard and the Métis graph partitioning algorithm if the utility function value of the shard is less than a preset utility function threshold, thereby obtaining a locally optimized sharding scheme for the blockchain, and sharding the multiple distributed devices according to the locally optimized sharding scheme.
[0091] Furthermore, the performance metrics include communication latency and device bandwidth; when the initial sharding module 310 determines the initial sharding scheme of the blockchain based on the initial performance metrics of each distributed device and the Métis graph partitioning algorithm, the initial sharding module 310 is specifically used for: Based on the initial communication delay and initial device bandwidth of each of the distributed devices, the edge weights between the distributed devices are calculated, and a weighted graph between the distributed devices is constructed. The weighted graph among the distributed devices is divided into multiple subgraphs according to the Métis graph partitioning algorithm; Each subgraph is identified as a blockchain shard; Each node in the subgraph is identified as a distributed device corresponding to the blockchain shard; Each blockchain shard and the corresponding distributed device are determined as the initial sharding scheme for the blockchain.
[0092] Furthermore, the performance index parameters also include device computing power and device geographical location; for each shard in the initial sharding scheme, when the utility calculation module 320 determines the utility function value of the shard based on the real-time performance index parameters of each distributed device in the shard, the utility calculation module 320 is specifically used for: After the multiple distributed devices are sharded according to the initial sharding scheme, real-time performance index parameters of each distributed device in the shard are collected according to the preset first sampling interval. Calculate the real-time device weight of each distributed device in the shard based on the real-time performance index parameters of each distributed device in the shard. For any sampling time sampled according to the first sampling interval, the exponentially weighted average weight of each distributed device in the shard at the sampling time is calculated based on the real-time device weight of each distributed device in the shard at the sampling time and the real-time device weight of the previous sampling time at the sampling time. The utility function value of the shard at each sampling time is calculated based on the exponentially weighted average weight of each distributed device in the shard at each sampling time.
[0093] Furthermore, when the local optimization module 330 re-shards the distributed devices in the shard based on the real-time performance parameters of each distributed device in the shard and the Métis graph partitioning algorithm to obtain the locally optimized sharding scheme of the blockchain, the local optimization module 330 is specifically used for: Based on the real-time performance metrics of each distributed device in the shard, calculate the exponentially weighted average weight of each distributed device in the shard; Based on the exponentially weighted average weight of each distributed device in the shard, calculate the edge weights between each distributed device in the shard, and construct a local weighted graph between each distributed device in the shard; The local weighted graph is repartitioned according to the Métis graph partitioning algorithm to obtain the sub-partition set of the partition; The shard is replaced by a set of sub-shards to obtain a locally optimized sharding scheme for the blockchain.
[0094] Further, please refer to Figure 4 , Figure 4 This is a second functional block diagram of a blockchain sharding optimization device provided in an embodiment of this application. For example... Figure 4 As shown, the blockchain sharding optimization device 300 also includes: The weight calculation module 340 is used to collect the exponential weighted average weight of each of the distributed devices according to a preset second sampling interval; the second sampling interval is greater than the first sampling interval.
[0095] The overall optimization module 350 is used to re-shard each of the distributed devices according to the exponential weighted average weight of each distributed device and the Métis graph partitioning algorithm for any sampling time sampled according to the second sampling interval, to obtain the overall optimized sharding scheme of the blockchain, and to shard the multiple distributed devices according to the overall optimized sharding scheme.
[0096] Further, any of the distributed devices in the shards includes master node devices and edge node devices; when sharding the multiple distributed devices according to the local optimization sharding scheme or the global optimization sharding scheme, the local optimization module 330 or the global optimization module 350 is specifically used for: For any of the aforementioned shards, when any master node device is removed from the shard, at least one edge node device in the shard is selected as a data recovery node based on the real-time performance index parameters of each edge node device in the shard. The redundant coded blocks corresponding to the removed master node devices are collected from other distributed devices in the shard, and data recovery is performed on the data recovery node using the fountain code algorithm.
[0097] Furthermore, when sharding the multiple distributed devices according to the local optimization sharding scheme or the overall optimization sharding scheme, the local optimization module 330 or the overall optimization module 350 is specifically used for: For any of the aforementioned shards, when any master node device joins the shard, at least one edge node device in the shard is selected as the synchronization source node based on the real-time performance index parameters of each edge node device in the shard. Based on the local ledger status and data encoding index in the synchronization source node, a redundant code block corresponding to the newly added master node device is constructed and sent to the newly added master node device through the synchronization source node.
[0098] This application provides a blockchain sharding optimization device, applied to a blockchain sharding device in a blockchain system. The blockchain system also includes multiple distributed devices; each distributed device is communicatively connected to the blockchain sharding device. The blockchain sharding optimization device includes: an initial sharding module, used to determine an initial sharding scheme for the blockchain based on the initial performance index parameters of each distributed device and the Métis graph partitioning algorithm, and to shard the multiple distributed devices according to the initial sharding scheme; a utility calculation module, used to determine the utility function value of each shard in the initial sharding scheme based on the real-time performance index parameters of each distributed device in the shard; and a local optimization module, used to re-shard the distributed devices in the shard if the utility function value of the shard is less than a preset utility function threshold, based on the real-time performance index parameters of each distributed device in the shard and the Métis graph partitioning algorithm, to obtain a locally optimized sharding scheme for the blockchain, and to shard the multiple distributed devices according to the locally optimized sharding scheme. In this way, by dynamically optimizing the blockchain sharding scheme locally through the utility function value of the shard, the global load balancing and intra-shard communication efficiency of the blockchain system can be improved.
[0099] Based on the same application concept, please refer to Figure 5 , Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 5 As shown, the electronic device 500 includes a processor 510, a memory 520, and a bus 530.
[0100] The memory 520 stores machine-readable instructions executable by the processor 510. When the electronic device 500 is running, the processor 510 and the memory 520 communicate through the bus 530. When the machine-readable instructions are executed by the processor 510, they perform the steps of the blockchain sharding optimization method provided in the above embodiment. For specific implementation details, please refer to the method embodiment, which will not be repeated here.
[0101] Based on the same concept, this application also provides a computer-readable storage medium storing a computer program. When the computer program is run by a processor, it executes the steps of the blockchain sharding optimization method provided in the above embodiments. For specific implementation details, please refer to the method embodiments, which will not be repeated here.
[0102] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the above-described apparatus and unit can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0103] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Additionally, the displayed or discussed mutual couplings, direct couplings, or communication connections may be through some communication interfaces; indirect couplings or communication connections between devices or units may be electrical, mechanical, or other forms.
[0104] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0105] In addition, the functional units in the embodiments provided in this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0106] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0107] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. In addition, the terms "first", "second", "third", etc. are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0108] Finally, it should be noted that the above-described embodiments are merely specific implementations of this application, used to illustrate the technical solutions of this application, and not to limit them. The protection scope of this application is not limited thereto. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features, within the scope of the technology disclosed in this application; and these modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application. All should be covered within the protection scope of this application. Therefore, the protection scope of this application should be determined by the protection scope of the claims.
Claims
1. A blockchain sharding optimization method, characterized in that, A blockchain sharding device applied to a blockchain system, wherein the blockchain system further includes multiple distributed devices; each of the distributed devices is communicatively connected to the blockchain sharding device; the method includes: Based on the initial performance parameters of each of the distributed devices and the Métis graph partitioning algorithm, the initial sharding scheme of the blockchain is determined, and the multiple distributed devices are sharded according to the initial sharding scheme. For each shard in the initial sharding scheme, the utility function value of the shard is determined based on the real-time performance index parameters of each distributed device in the shard. If the utility function value of the shard is less than the preset utility function threshold, then based on the real-time performance index parameters of each distributed device in the shard and the Métis graph partitioning algorithm, the distributed devices in the shard are re-sharded to obtain the locally optimized sharding scheme of the blockchain, and the multiple distributed devices are sharded according to the locally optimized sharding scheme.
2. The blockchain sharding optimization method according to claim 1, characterized in that, The performance metrics include communication latency and device bandwidth; determining the initial sharding scheme of the blockchain based on the initial performance metrics of each distributed device and the Métis graph partitioning algorithm includes: Based on the initial communication delay and initial device bandwidth of each of the distributed devices, the edge weights between the distributed devices are calculated, and a weighted graph between the distributed devices is constructed. The weighted graph among the distributed devices is divided into multiple subgraphs according to the Métis graph partitioning algorithm; Each subgraph is identified as a blockchain shard; Each node in the subgraph is identified as a distributed device corresponding to the blockchain shard; Each blockchain shard and the corresponding distributed device are determined as the initial sharding scheme for the blockchain.
3. The blockchain sharding optimization method according to claim 2, characterized in that, The performance metrics parameters also include device computing power and device geographical location; for each shard in the initial sharding scheme, determining the utility function value of the shard based on the real-time performance metrics parameters of each distributed device in the shard includes: After the multiple distributed devices are sharded according to the initial sharding scheme, real-time performance index parameters of each distributed device in the shard are collected according to the preset first sampling interval. Calculate the real-time device weight of each distributed device in the shard based on the real-time performance index parameters of each distributed device in the shard. For any sampling time sampled according to the first sampling interval, the exponentially weighted average weight of each distributed device in the shard at the sampling time is calculated based on the real-time device weight of each distributed device in the shard at the sampling time and the real-time device weight of the previous sampling time at the sampling time. The utility function value of the shard at each sampling time is calculated based on the exponentially weighted average weight of each distributed device in the shard at each sampling time.
4. The blockchain sharding optimization method according to claim 3, characterized in that, The method of re-sharding the distributed devices in the shard based on the real-time performance parameters of each distributed device in the shard and the Métis graph partitioning algorithm to obtain a locally optimized sharding scheme for the blockchain includes: Based on the real-time performance metrics of each distributed device in the shard, calculate the exponentially weighted average weight of each distributed device in the shard; Based on the exponentially weighted average weight of each distributed device in the shard, calculate the edge weights between each distributed device in the shard, and construct a local weighted graph between each distributed device in the shard. The local weighted graph is repartitioned according to the Métis graph partitioning algorithm to obtain the sub-partition set of the partition; The shard is replaced by a set of sub-shards to obtain a locally optimized sharding scheme for the blockchain.
5. The blockchain sharding optimization method according to claim 3, characterized in that, The method further includes: According to a preset second sampling interval, the exponentially weighted average weight of each of the distributed devices is collected; the second sampling interval is greater than the first sampling interval. For any sampling time at which sampling is performed according to the second sampling interval, each of the distributed devices is re-sharded according to the exponential weighted average weight of each distributed device and the Métis graph partitioning algorithm to obtain the overall optimized sharding scheme of the blockchain, and the multiple distributed devices are sharded according to the overall optimized sharding scheme.
6. The blockchain sharding optimization method according to claim 5, characterized in that, The distributed devices in any of the shards include master node devices and edge node devices; when sharding the plurality of distributed devices according to the locally optimized sharding scheme or the globally optimized sharding scheme, the method further includes: For any of the aforementioned shards, when any master node device is removed from the shard, at least one edge node device in the shard is selected as a data recovery node based on the real-time performance index parameters of each edge node device in the shard. The redundant coded blocks corresponding to the removed master node devices are collected from other distributed devices in the shard, and data recovery is performed on the data recovery node using the fountain code algorithm.
7. The blockchain sharding optimization method according to claim 6, characterized in that, When sharding the multiple distributed devices according to the local optimization sharding scheme or the global optimization sharding scheme, the method further includes: For any of the aforementioned shards, when any master node device joins the shard, at least one edge node device in the shard is selected as the synchronization source node based on the real-time performance index parameters of each edge node device in the shard. Based on the local ledger status and data encoding index in the synchronization source node, a redundant code block corresponding to the newly added master node device is constructed and sent to the newly added master node device through the synchronization source node.
8. A blockchain sharding optimization device, characterized in that, A blockchain sharding device is applied to a blockchain system, wherein the blockchain system further includes multiple distributed devices; each of the distributed devices is communicatively connected to the blockchain sharding device; the blockchain sharding optimization device includes: The initial sharding module is used to determine the initial sharding scheme of the blockchain based on the initial performance index parameters of each of the distributed devices and the Métis graph partitioning algorithm, and to shard the multiple distributed devices according to the initial sharding scheme. The utility calculation module is used to determine the utility function value of each shard in the initial sharding scheme based on the real-time performance index parameters of each distributed device in the shard. The local optimization module is used to re-shard each distributed device in the shard based on the real-time performance index parameters of each distributed device in the shard and the Métis graph partitioning algorithm if the utility function value of the shard is less than a preset utility function threshold, thereby obtaining a locally optimized sharding scheme for the blockchain, and sharding the multiple distributed devices according to the locally optimized sharding scheme.
9. An electronic device, characterized in that, include: The device includes a processor, a memory, and a bus. The memory stores machine-readable instructions executable by the processor. When the electronic device is running, the processor communicates with the memory via the bus. The machine-readable instructions are executed by the processor to perform the steps of the blockchain sharding optimization method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, performs the steps of the blockchain sharding optimization method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Optimization method of distributed storage graph data, electronic device and storage medium
CN113254527A
5G intelligent networking method and system based on edge computing
CN119450586A
Block chain fragment optimization method and system
CN120050234A