Block chain management method and device, storage medium and electronic device
By determining the network performance indicators and comprehensive scores of nodes in the blockchain network, a master node with the best network status is elected, which solves the problem of frequent leader changes and log synchronization interruptions caused by the instability of wireless networks, and improves the performance and stability of the blockchain.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHINA SATENT NETWORK APPLICATION RESEARCH INSTITUTE CO LTD
- Filing Date
- 2024-10-15
- Publication Date
- 2026-04-17
AI Technical Summary
In satellite networks or mobile communication networks based on cloud-edge-device architecture, the instability of wireless networks leads to poor connection stability of terminal access nodes, causing frequent changes in leaders and interruptions in log synchronization, resulting in poor blockchain performance.
By determining the network performance indicators of each node in the target blockchain, a set of candidate nodes is established. The master node is elected based on the comprehensive network score and voting weight, ensuring that the node with the best network status is elected as the master node. A weighted voting mechanism and dynamic weight adjustment are adopted to optimize the leader election process.
It improves the stability and performance of the blockchain network, reduces network overhead caused by frequent leader outages, and enhances the continuity and efficiency of log synchronization.
Smart Images

Figure CN121887804A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of blockchain, and more specifically, to a blockchain management method, apparatus, storage medium, and electronic device. Background Technology
[0002] In the field of blockchain technology, optimizing consensus algorithms is crucial to ensuring system robustness and efficiency. This is especially true for consensus protocols relying on leader mechanisms. In cloud-edge-device architectures like satellite or mobile communication networks, there are three different types of computing nodes: central cloud, edge cloud, and terminal access nodes. Cloud-edge and edge-edge connections are via terrestrial networks, while cloud-device, edge-device, and device-device connections are via wireless networks such as mobile and satellite communications. Due to the instability of wireless networks, the connection stability of terminal access nodes is relatively poor compared to the central and edge clouds. This network instability leads to frequent leader replacements and log synchronization interruptions, which are particularly prominent issues. When the leader node, or master node, frequently goes offline, the system continuously enters a new master node election phase. This election process consumes significant network bandwidth resources, resulting in poor blockchain performance.
[0003] This indicates that there is a problem with poor blockchain performance in related technologies.
[0004] There is currently no effective solution to the aforementioned problems in the relevant technologies. Summary of the Invention
[0005] This invention provides a blockchain management method, apparatus, storage medium, and electronic device to at least address the problem of poor blockchain performance in related technologies.
[0006] According to an embodiment of the present invention, a blockchain management method is provided, comprising: determining a network performance index for each node included in a target blockchain, wherein the network performance index is used to indicate the network status of the node; determining a candidate node set from the nodes included in the target blockchain based on the network performance index, wherein the network status of the nodes included in the candidate node set is better than that of other nodes included in the target blockchain, the other nodes being nodes included in the target blockchain other than the nodes in the candidate node set; upon receiving a voting request sent by a first node included in the target blockchain, and the first node being a node included in the candidate node set, determining a voting weight for a second node based on a comprehensive network score of a second node participating in the voting, wherein the voting request is used to request the election of the first node as the master node for managing the target blockchain, and the second node being a node included in the target blockchain; and determining whether to elect the first node as the master node based on the voting result of the second node and the voting weight.
[0007] According to another embodiment of the present invention, a blockchain management device is provided, comprising: a first determining module, configured to determine a network performance index for each node included in a target blockchain, wherein the network performance index is used to indicate the network status of the node; a second determining module, configured to determine a candidate node set from the nodes included in the target blockchain based on the network performance index, wherein the network status of the nodes included in the candidate node set is better than that of other nodes included in the target blockchain, the other nodes being nodes included in the target blockchain other than the nodes in the candidate node set; a third determining module, configured to, upon receiving a voting request sent by a first node included in the target blockchain, and the first node being a node included in the candidate node set, determine a voting weight for a second node participating in the voting based on a comprehensive network score, wherein the voting request is used to request the election of the first node as the master node for managing the target blockchain, and the second node being a node included in the target blockchain; and a fourth determining module, configured to determine whether to elect the first node as the master node based on the voting result of the second node and the voting weight.
[0008] According to yet another embodiment of the present invention, a computer-readable storage medium is also provided, wherein a computer program is stored therein, wherein the computer program is configured to perform the steps in any of the above method embodiments when executed.
[0009] According to yet another embodiment of the present invention, an electronic device is also provided, including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to perform the steps in any of the above method embodiments.
[0010] According to yet another embodiment of the present invention, a computer program product is also provided, including a computer program that, when executed by a processor, implements the steps of the methods described in various embodiments of the present application.
[0011] This invention determines the network performance metrics of each node in a target blockchain, where the network performance metrics indicate the network status of the node; based on the network performance metrics, a set of candidate nodes is determined from the nodes in the target blockchain, wherein the network status of the nodes in the candidate node set is better than that of other nodes in the target blockchain, and the other nodes are nodes in the target blockchain other than those in the candidate node set; upon receiving a voting request from a first node in the target blockchain, and the first node is a node in the candidate node set, the voting weight of the second node is determined based on the comprehensive network score of the second node participating in the voting, wherein the voting request is used to request the election of the first node as the master node of the target blockchain, and the second node is a node in the target blockchain; based on the voting result and voting weight of the second node, it is determined whether to elect the first node as the master node; if the first node is elected as the master node, the target blockchain is managed by the master node. Since a set of candidate nodes can be determined from the target blockchain based on the network performance metrics of each node included in the target blockchain, and upon receiving a voting request from the first node, which is also a node in the candidate node set, the voting weight of the second node participating in the vote is determined based on its comprehensive network score. Based on the voting results of the second node and its voting weight, it is determined whether to elect the first node as the master node. This achieves the goal of electing the node with the best network state in the target blockchain as the master node, and assigning voting weights to the second node based on its comprehensive network score, ensuring the smooth election of the master node, and thus enabling the management of the target blockchain through a stable master node. Therefore, it can solve the problem of poor blockchain performance in related technologies and achieve the effect of improving blockchain performance. Attached Figure Description
[0012] Figure 1 This is a hardware structure block diagram of a mobile terminal for a blockchain management method according to an embodiment of the present invention.
[0013] Figure 2 This is a flowchart of a blockchain management method according to an embodiment of the present invention;
[0014] Figure 3 This is a schematic diagram of the process for electing a master node according to an embodiment of the present invention;
[0015] Figure 4 This is a structural block diagram of a blockchain management device according to an embodiment of the present invention. Detailed Implementation
[0016] The embodiments of the present invention will be described in detail below with reference to the accompanying drawings and examples.
[0017] It should be noted that the terms "first," "second," etc., in the specification, claims, and drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.
[0018] The methods and embodiments provided in this application can be executed on a mobile terminal, computer terminal, or similar computing device. Taking running on a mobile terminal as an example, Figure 1 This is a hardware structure block diagram of a mobile terminal for a blockchain management method according to an embodiment of the present invention. Figure 1 As shown, a mobile terminal may include one or more ( Figure 1 Only one is shown in the diagram. A processor 102 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 104 for storing data are also shown. The mobile terminal may further include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the mobile terminal described above. For example, the mobile terminal may also include components that are more... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0019] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to the blockchain management method in this embodiment of the invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, thereby implementing the above-described method. The memory 104 may include high-speed random access memory and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the mobile terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0020] The transmission device 106 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the mobile terminal's communication provider. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 may be a Radio Frequency (RF) module, used for wireless communication with the Internet.
[0021] This embodiment provides a blockchain management method. Figure 2 This is a flowchart of a method for determining the master node according to an embodiment of the present invention, such as... Figure 2 As shown, the process includes the following steps:
[0022] Step S202: Determine the network performance metrics for each node included in the target blockchain, wherein the network performance metrics are used to indicate the network status of the node;
[0023] Step S204: Based on the network performance indicators, a candidate node set is determined from the nodes included in the target blockchain, wherein the network status of the nodes included in the candidate node set is better than that of other nodes included in the target blockchain, and the other nodes are nodes included in the target blockchain other than the nodes in the candidate node set.
[0024] Step S206: Upon receiving a voting request from a first node included in the target blockchain, and the first node is a node included in the candidate node set, the voting weight of the second node is determined based on the network comprehensive score of the second node participating in the voting. The voting request is used to request the election of the first node as the master node for managing the target blockchain, and the second node is a node included in the target blockchain.
[0025] Step S208: Based on the voting results of the second node and the voting weight, determine whether to elect the first node as the master node.
[0026] In the above embodiments, the blockchain management method can be applied to satellite networks or mobile communication networks based on a cloud-edge-device architecture. In such networks, there are three different types of computing nodes: a central cloud, an edge cloud, and terminal access nodes. Cloud-edge and edge-edge connections are via terrestrial networks, while cloud-device, edge-device, and device-device connections are via wireless networks such as mobile and satellite communications. Due to the instability of wireless networks, the connection stability of terminal access nodes is relatively poor compared to the central and edge clouds. This network instability leads to frequent master node replacements and log synchronization interruptions, which are particularly prominent issues. Therefore, when electing a master node, the above method can be executed on every node in the target blockchain to determine the node with the best network condition as the master node.
[0027] In the above embodiments, the target blockchain may include multiple nodes, among which a master node, i.e., the leader, may be included. All nodes other than the master node are ordinary nodes. The master node can prove its online status to the ordinary nodes by broadcasting heartbeat information. If an ordinary node does not receive a heartbeat from the master node within a predetermined time, it can assume the master node is offline, and a new master node can be elected from among the ordinary nodes. To ensure that the newly elected master node has a low probability of going offline again, a node with good network status can be selected as the master node from among the ordinary nodes. Therefore, each node in the target blockchain can obtain network performance indicators for each node included in the target blockchain. These network performance indicators can be values determined based on parameters such as node bandwidth, network latency, packet loss rate, and jitter, reflecting the network status of the nodes. Based on the network performance indicators, a candidate node set is determined from the nodes included in the target blockchain, where the network status of nodes in the candidate node set is better than that of nodes outside the candidate node set.
[0028] In the above embodiments, the node bandwidth, network latency, packet loss rate, and interface node latency jitter of each node can be obtained. Weights are assigned to these parameters, and the weighted sum of these parameters with their respective weights is determined as the network performance index. The network performance indexes of each node are arranged in descending order, and the top N nodes are selected as the candidate node set. Alternatively, each node can be sorted in ascending order, and the next N nodes are selected as the candidate node set. Of course, nodes with network performance indices greater than a predetermined threshold can also be selected as candidate nodes, ensuring that nodes participating in the election as master nodes have superior network performance. This ensures that when a node from the candidate node set becomes the master node, it will have good network performance and will not experience disconnections.
[0029] It should be noted that each node in the target blockchain will obtain the network performance metrics of each node in real time, determine the candidate node set based on the network performance metrics, and store it locally.
[0030] In the above embodiments, if any node in the target blockchain fails to receive a heartbeat message from the master node within a predetermined time, the master node is considered offline. A first node can then initiate a voting request. This first node can be any node in the target blockchain and can broadcast the request to become the master node. All nodes in the target blockchain other than the first node can participate in the voting upon receiving the request. The first node can also vote for itself. Second nodes can be any node in the target blockchain, including the first node. Each second node can determine whether the first node is in the candidate node set. If so, the vote is in favor of the first node becoming the master node; otherwise, the vote is against it.
[0031] In the above embodiments, the overall network score of each node can be determined in real time. Nodes with scores exceeding a predetermined threshold are designated as second nodes, ensuring good network performance for participating nodes and preventing voting or election failures due to network issues. Alternatively, the overall network scores can be sorted from largest to smallest, with the top M scores corresponding to the second nodes. Similarly, the overall network scores can be sorted from smallest to largest, with the bottom M scores corresponding to the second nodes.
[0032] In the above embodiments, voting weights can be assigned to each second node according to the network comprehensive score. The network comprehensive score and voting weights are positively correlated; the higher the network comprehensive score, the higher the voting weight, and the lower the network comprehensive score, the lower the voting weight.
[0033] In the above embodiment, after assigning voting weights to each second node, the voting result of each second node can be quantified. For example, a value of 1 corresponds to a vote in favor of the first node as the master node, and a value of 0 corresponds to a vote against the first node as the master node. The value corresponding to the voting result is multiplied by its voting weight, and the multiple products are summed. If the sum is greater than a set threshold, the first node is elected as the master node; if the sum is less than or equal to the set threshold, the first node is rejected as the master node. The process continues to receive voting requests from the next first node and repeats the above steps until a master node is elected. The next first node can be a node in the target blockchain that is adjacent to the current first node and located after it. For example, the target blockchain includes nodes A, B, C, and D in sequence. If the current first node is A, then the next first node is B; if the current first node is B, then the next first node is C.
[0034] In the above embodiments, a flowchart illustrating the election of the master node can be found in the appendix. Figure 3 ,like Figure 3 As shown, the election process is simplified to an election involving 4 nodes, where Node1 and Node3 are in the candidate list.
[0035] 1) Node1, as the leader, periodically broadcasts "heartbeats" to other nodes to maintain its leader status.
[0036] 2) Node1 goes offline, and other nodes time out without receiving the "heartbeat" from Node1. Here, Node2 is the first to discover that the leader has gone offline.
[0037] 3) Node2 first discovers that the leader has gone offline, votes for itself, and broadcasts a voting request RPC to other nodes in the hope of being elected as the new leader.
[0038] 4) When other nodes receive the voting request RPC from Node2, they first check their local candidate table and find that Node2 is not in the candidate table. They then refuse to vote for Node2 and send a "reject vote" response RPC to Node2.
[0039] 5) Node2 did not receive more than half of the votes and failed to become the new leader.
[0040] 6) When Node3 discovers that the leader has gone offline, it first votes for itself and broadcasts a voting request RPC to other nodes, hoping to be elected as the new leader.
[0041] 7) When other nodes receive the voting request RPC from Node3, they first check their local candidate table and find that Node3 is in the candidate table. Node3 is the first node in the candidate table to send the voting request RPC, so they agree to vote for Node3 and send an "agree to vote" response RPC to Node3.
[0042] 8) Node3 received more than half of the votes (including the votes it cast for itself), and was successfully elected as the new leader. It broadcasts a "heartbeat" to other nodes to inform them and maintain its leadership position.
[0043] In the above embodiments, the consensus algorithm based on the leader mechanism is the core technology for ensuring log synchronization among nodes in a blockchain network. However, this mechanism has significant drawbacks in unstable network environments. When the leader node frequently goes offline, the system continuously enters new leader election phases. This election process consumes a large amount of network bandwidth resources. During leader election, log synchronization is paused, which not only prevents timely log synchronization but also reduces the system's processing capacity. Therefore, all nodes can periodically collect network performance metrics of all nodes in the entire network, including bandwidth, latency, packet loss rate, and latency jitter. Based on the collected network performance metrics data of all nodes, a comprehensive score is calculated for each node, and all nodes are sorted according to their scores to form a priority list. Based on the actual network conditions and business needs, the top N nodes with the highest scores are selected and included in the candidate list, i.e., the candidate node set. During the leader election process, nodes decide whether to vote for the node that initiated the voting request based on the candidate list. This ensures that the most stable node in the network has a higher chance of being elected as the leader. This optimizes the leader election process, avoids continuous elections due to frequent leader disconnections, and significantly reduces network overhead and enhances data synchronization efficiency. This scheme is particularly suitable for algorithms widely used in blockchains such as Raft and PBFT. By adding a candidate table creation and update step, and incorporating a judgment mechanism based on the candidate table during the election process, it can further enhance the stability and reliability of these algorithms in practical applications.
[0044] This invention determines the network performance metrics of each node in a target blockchain, where the network performance metrics indicate the network status of the node; based on the network performance metrics, a set of candidate nodes is determined from the nodes in the target blockchain, wherein the network status of the nodes in the candidate node set is better than that of other nodes in the target blockchain, and the other nodes are nodes in the target blockchain other than those in the candidate node set; upon receiving a voting request from a first node in the target blockchain, and the first node is a node in the candidate node set, the voting weight of the second node is determined based on the comprehensive network score of the second node participating in the voting, wherein the voting request is used to request the election of the first node as the master node for managing the target blockchain, and the second node is a node in the target blockchain; based on the voting result and voting weight of the second node, it is determined whether to elect the first node as the master node; if the first node is elected as the master node, the target blockchain is managed by the master node. Since a set of candidate nodes can be determined from the target blockchain based on the network performance metrics of each node included in the target blockchain, and upon receiving a voting request from the first node, which is also a node in the candidate node set, the voting weight of the second node participating in the vote is determined based on its comprehensive network score. Based on the voting results of the second node and its voting weight, it is determined whether to elect the first node as the master node. This achieves the goal of electing the node with the best network state in the target blockchain as the master node, and assigning voting weights to the second node based on its comprehensive network score, ensuring the smooth election of the master node, and thus enabling the management of the target blockchain through a stable master node. Therefore, it can solve the problem of poor blockchain performance in related technologies and achieve the effect of improving blockchain performance.
[0045] Optionally, the entity performing the above steps can be any node included in the target blockchain, but is not limited to this.
[0046] In an exemplary embodiment, determining the network performance metric for each node in the target blockchain includes: determining the network latency, packet loss rate, latency jitter, and bandwidth of all nodes in the target blockchain; determining a first performance metric for each node based on the network latency, packet loss rate, and latency jitter; determining a second performance metric for each node based on the node bandwidth; and determining the network performance metric based on the first and second performance metric. In this embodiment, the network latency, packet loss rate, latency jitter, and bandwidth of all nodes in the target blockchain can be determined. The network latency, packet loss rate, and latency jitter can be negative metrics, and the node bandwidth can be a positive metric. The first performance metric is determined based on the negative metrics, the second performance metric is determined based on the positive metrics, and the sum of the first and second performance metric is determined as the network performance metric.
[0047] In the above embodiments, for any node in the target blockchain, the node's network latency, packet loss rate, latency jitter, and bandwidth can be determined. Weights are assigned to the network latency, packet loss rate, latency jitter, and bandwidth. The weighted sum of the network latency, packet loss rate, and latency jitter is determined as the first performance indicator. The product of the node bandwidth and its weight is determined as the second performance indicator. Weights are then assigned to the first and second performance indicators, and the weighted sum of the two is determined as the network performance indicator.
[0048] In an exemplary embodiment, determining a first performance metric for each node based on the network latency, the node packet loss rate, and the node latency jitter includes: determining a maximum network latency, a minimum network latency, and a target network latency for the node, all included in the network latency; determining a maximum node packet loss rate, a minimum node packet loss rate, and a target node packet loss rate, all included in the node packet loss rate; determining a maximum node latency jitter, a minimum node latency jitter, and a target node latency jitter, all included in the node latency jitter; determining a first sub-performance metric based on the maximum network latency, the minimum network latency, and the target network latency; determining a second sub-performance metric based on the maximum node packet loss rate, the minimum node packet loss rate, and the target node packet loss rate; determining a third sub-performance metric based on the maximum node latency jitter, the minimum node latency jitter, and the target node latency jitter; and determining a first sum of the first sub-performance metric, the second sub-performance metric, and the third sub-performance metric as the first performance metric. In this embodiment, the maximum and minimum network latency times included in the network latency times of all nodes can be determined, as can the maximum and minimum packet loss rates of all nodes, and the maximum and minimum node latency jitter of all nodes. When determining the first performance metric for each node, the target network latency time, target packet loss rate, and target latency jitter of that node can also be determined. A first sub-performance metric is determined based on the maximum, minimum, and target network latency times. A second sub-performance metric is determined based on the maximum, minimum, and target packet loss rates. A third sub-performance metric is determined based on the maximum, minimum, and target latency jitter. The first sum of the first, second, and third sub-performance metric is determined as the first performance metric. The first sum may include a weighted sum or an algebraic sum.
[0049] In an exemplary embodiment, determining a first sub-performance indicator based on the maximum network latency time, the minimum network latency time, and the target network latency time includes: determining a first difference between the maximum network latency time and the target network latency time, determining a second difference between the maximum network latency time and the minimum network latency time, and determining a first ratio of the first difference to the second difference as the first sub-performance indicator; determining a second sub-performance indicator based on the maximum node packet loss rate, the minimum node packet loss rate, and the target node packet loss rate includes: determining the maximum node packet loss rate and the target node packet loss rate... The third sub-performance index is determined by: determining the third difference between the maximum and minimum node packet loss rates; determining the fourth difference between the maximum and minimum node packet loss rates; and determining the second ratio of the third and fourth differences as the second sub-performance index. The determination of the third sub-performance index based on the maximum node latency jitter, the minimum node latency jitter, and the target node latency jitter includes: determining the fifth difference between the maximum and minimum node latency jitter; determining the sixth difference between the maximum and minimum node latency jitter; and determining the third ratio of the fifth and sixth differences as the third sub-performance index. In this embodiment, the first, second, and third sub-performance indices can all be expressed as: j = 1, 2, 3, where x ij Let X be the data value of the j-th metric for the i-th node, namely the target network latency, the target node packet loss rate, and the target node latency jitter. j Max(X) represents the minimum value of the j-th index among all node data. j ) represents the maximum value of the j-th indicator among all node data.
[0050] In an exemplary embodiment, determining a second performance metric for each node based on the node bandwidth includes: determining a maximum node bandwidth, a minimum node bandwidth, and a target node bandwidth included in the node bandwidth; determining a seventh difference between the target node bandwidth and the minimum node bandwidth; determining an eighth difference between the maximum node bandwidth and the minimum node bandwidth; and determining the ratio of the seventh difference to the eighth difference as the second performance metric. In this embodiment, the second performance metric can be expressed as... Where, x ij Let the data value of the j-th metric of the i-th node be the target node bandwidth, and let Min(X) be the metric value of the j-th metric. j Max(X) represents the minimum value of the j-th index among all node data. j ) represents the maximum value of the j-th indicator among all node data.
[0051] In an exemplary embodiment, determining the network performance indicator based on the first performance indicator and the second performance indicator includes: determining a second sum of the first performance indicator and the second performance indicator; and determining the second sum as the network performance indicator. In this embodiment, network performance indicator data for each node can be obtained. A set of node performance evaluation indicators is constructed using the obtained data, where x1 is network latency, x2 is node packet loss rate, x3 is node latency jitter, and x4 is node bandwidth. The positive indicator is x4, and the negative indicators are x1, x2, and x3. Determine the first performance metric and the second performance metric. Where x ij For the data value of the j-th indicator at the i-th node, Min(X) j Max(X) represents the minimum value of the j-th index among all node data. j Let be the maximum value of the j-th metric across all nodes. The network performance metrics for each node can be expressed as: After obtaining the performance scores of all nodes and sorting them in descending order, the N nodes with the highest network performance scores are added to the candidate table based on the actual network situation and business needs.
[0052] In an exemplary embodiment, determining the voting weight of a second node based on its overall network score includes: determining the second node's network bandwidth, network latency, and cumulative number of disconnections; determining the second node's overall network score based on the network bandwidth, network latency, and cumulative number of disconnections; clustering the overall network score to obtain multiple target categories; assigning a target weight to each target category, wherein the target weight of the target category with a higher overall network score is greater than the target weight of the target category with a lower overall network score; and determining the target weight of the category to which the second node belongs as the voting weight. In this embodiment, the Raft consensus algorithm is based on a leader election mechanism, where all nodes participate in voting equally. However, this equal-weight voting strategy is relatively fragile in certain situations. In particular, when more than half of the nodes are disconnected, the "majority" vote standard required by the Raft algorithm can cause a deadlock in the leader election, leading to the shutdown of the entire blockchain network. Therefore, to further enhance the robustness and adaptability of the blockchain system, a weighted system can be introduced to assign voting weights to each node based on its stability and performance. This means that high-performance, stable nodes will have higher voting power and are therefore more likely to be elected as leaders. Furthermore, the weights can be dynamically adjusted based on the network environment and the real-time performance of the nodes, making the election mechanism more flexible and adaptive. Using this weighted voting strategy, even if a large number of nodes become offline, as long as the high-weight nodes remain online, the system can still reach the necessary vote threshold, ensuring the continuity of the leader election. By implementing this weighted voting mechanism, the resilience of the Raft consensus algorithm in the face of network fluctuations and node instability can be significantly enhanced. This solution aims to optimize the leader election process, reduce the system overhead caused by frequent leader switching, and provide a more stable and efficient operating environment for the blockchain network.
[0053] In the above embodiments, the bandwidth, latency, and cumulative disconnection count of each node in the entire network can be acquired periodically. Based on the acquired data, each node is comprehensively scored to obtain a comprehensive network score. Specifically, bandwidth, latency, and cumulative disconnection count can be weighted and summed, and the weighted sum is used as the comprehensive network score. After obtaining the comprehensive network score, clustering methods can be used to classify the nodes. For example, K-means clustering dynamically classifies nodes with different network scores, assigning different weights to nodes at different score levels; the higher the score, the greater the weight. In real-world networks, nodes with low scores exhibit poorer network stability and more frequent disconnections.
[0054] The K-means clustering algorithm process is as follows:
[0055] 1) Initialization:
[0056] Choose the number of clusters, K.
[0057] Choose k initial cluster centers. In a cloud-edge-device architecture, k is usually chosen as 3. The cluster centers can be randomly selected data points.
[0058] 2) Assign each data point to the nearest cluster center: Update the indicator variable for each data point using the following formula:
[0059]
[0060] Where, x i For data points, μ k As the cluster center, r ik It is an indicator variable.
[0061] Data point x i closest to the cluster center μ k Then x i Indicator variable r ik If the value is 1, then the value is 0; otherwise, the value is 0.
[0062] 3) Update cluster centers: For each cluster center, update using the following formula:
[0063]
[0064] Where N is the total number of data points.
[0065] 4) Calculate the objective function: To monitor the convergence of the algorithm, calculate the following objective function:
[0066]
[0067] The clustering cost function J(C,μ) is the sum of squares of the distances from all data points to their nearest cluster centers.
[0068] 5) Check convergence conditions:
[0069] If the clustering cost function is less than a given threshold (set to 0.01 here), the algorithm stops. Otherwise, return to step 2).
[0070] 6) Assign different voting weights to nodes of different levels after clustering.
[0071] In practical applications, nodes with low network scores are less stable and tend to go offline more frequently. In the event of a large-scale network outage, if more than half of the nodes go offline, in the traditional Raft algorithm, all nodes in the system will be unable to obtain enough votes, causing the Raft algorithm to malfunction. After introducing voting weights, nodes with higher network scores are less likely to go offline. In the event of a large-scale node outage, these robust nodes can still ensure that there are enough weights in the system to ensure the normal operation of the leader election process.
[0072] In an exemplary embodiment, determining whether to elect the first node as the master node based on the voting results of the second nodes and the voting weights includes: determining the product of the voting results of each second node and the voting weights; determining a third sum of the products; electing the first node as the master node if the third sum is greater than a first threshold; and rejecting the first node as the master node if the third sum is less than or equal to the first threshold. In this embodiment, the voting results of each second node can be numericalized. For example, a value of 1 corresponds to a voting result agreeing to the first node as the master node, and a value of 0 corresponds to a voting result rejecting the first node as the master node. The numerical value corresponding to the voting result is multiplied by its voting weight, and the multiple products are summed. If the sum is greater than a set threshold, the first node is elected as the master node; if the sum is less than or equal to the set threshold, the first node is rejected as the master node. The process continues to receive the next voting request from the first node and repeats the above steps until a master node is elected.
[0073] In an exemplary embodiment, before determining the voting weight of the second node based on the network comprehensive score of the second node participating in the voting, the method further includes one of the following: determining all nodes included in the target blockchain as the second node; determining nodes that broadcast voting results as the second node; determining nodes in the target blockchain whose network performance indicators are greater than a preset indicator as the second node; determining the top N nodes in the target blockchain whose network performance indicators are among the highest as the second node, where N is a positive integer. In this embodiment, all nodes included in the target blockchain can be determined as the second node, that is, when electing the master node, all nodes in the target blockchain can participate in the voting. When there are nodes with poor network conditions in the target blockchain, some nodes may not receive voting requests, and some nodes may receive voting requests but be unable to broadcast the voting results. Therefore, nodes that have already broadcast voting results can be determined as the second node, and nodes that have broadcast voting results can be determined as nodes participating in parameter voting. Of course, when there are nodes with poor network conditions in the target blockchain, there may be delays in broadcasting voting results or receiving broadcast voting results. Therefore, nodes with network performance indicators greater than the preset indicators can be identified as the second node, or the top N nodes with the highest network performance indicators can be identified as the second node.
[0074] In the above embodiments, determining the second node in the above manner can ensure the voting order and improve system performance.
[0075] In an exemplary embodiment, after receiving a voting request from a first node included in the target blockchain, the method further includes: if it is determined that the first node is not a node included in the candidate node set, casting a dissenting vote for the first node, wherein the dissenting vote indicates opposition to the first node being elected as the master node. In this embodiment, after receiving the voting request from the first node, it can be determined whether the first node is in the candidate node set. If it is a node in the candidate node set, a vote is cast for the first node. If it is not a node in the candidate node set, the first node is rejected as the master node. The process continues to wait for a voting request from the next node and repeats the above process.
[0076] In the aforementioned embodiments, addressing the issues of frequent leader changes and log synchronization interruptions caused by network instability resulting from blockchain's reliance on consensus mechanisms, a consensus algorithm based on node capabilities to establish a candidate list is proposed. First, by implementing a dynamic resource monitoring mechanism, this strategy accurately tracks the real-time performance indicators of network nodes. This monitoring system provides the data foundation for the subsequent evaluation and ranking process. Then, using this data, the strategy deploys a comprehensive scoring system to rank nodes according to their comprehensive performance indicators, thereby forming an optimized candidate list. This list identifies the nodes most likely to become the next leader. Finally, the introduced intelligent election algorithm not only makes decisions based on node stability and performance scores but also considers multiple dimensions such as real-time network conditions and node communication latency, ensuring that the optimal node is elected as the leader in each election process. The algorithm significantly enhances the blockchain network's adaptability and overall performance in dynamic environments.
[0077] In a cloud-edge-device architecture, terminal access nodes via wireless networks are prone to temporary outages. When more than half of the nodes in the entire blockchain system become disconnected, the blockchain may become unavailable or even crash. To address this issue, a network-condition-based adaptive voting weight Raft algorithm is proposed, introducing a weighted voting mechanism and a dynamic weight adjustment function. In the weighted voting mechanism, each node's voting weight is no longer fixed but dynamically allocated based on its historical stability and current performance. The weight allocation strategy comprehensively considers multiple dimensions such as node response time, service availability, processing capacity, and fault recovery speed. This algorithm assigns higher weights to more stable and higher-performing nodes, thereby giving them greater influence in the election process. The dynamic weight adjustment function allows the system to adjust voting weights based on real-time network conditions and node performance. This scheme ensures that even when multiple nodes are disconnected, the remaining high-weight nodes can still reach the necessary vote threshold to successfully elect a new leader, reducing election overhead caused by network issues and avoiding service interruptions due to frequent leader changes.
[0078] The consensus algorithm based on phased capability-driven candidate table construction considers the frequent leader changes and log synchronization interruptions caused by network instability. It employs a dynamic network performance monitoring mechanism, a comprehensive scoring system, and an intelligent election algorithm. While ensuring blockchain stability, it effectively reduces the overhead caused by leader changes and significantly improves the continuity and efficiency of log synchronization. Overall, this algorithm significantly enhances the blockchain network's adaptability and overall performance in dynamic environments. The network-condition-based adaptive voting weight Raft algorithm adds a weighted voting mechanism and dynamic weight adjustment capability, improving the blockchain system's adaptability and resilience to network fluctuations, reducing the leader election cost caused by node instability, and providing strong support for maintaining the stable operation of the blockchain network.
[0079] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of the present invention.
[0080] This embodiment also provides a blockchain management device for implementing the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can refer to a combination of software and / or hardware that performs a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0081] Figure 4 This is a structural block diagram of a blockchain management device according to an embodiment of the present invention, such as... Figure 4 As shown, the device includes:
[0082] The first determining module 42 is used to determine the network performance index of each node included in the target blockchain, wherein the network performance index is used to indicate the network status of the node;
[0083] The second determining module 44 is used to determine a candidate node set from the nodes included in the target blockchain based on the network performance indicators, wherein the network status of the nodes included in the candidate node set is better than that of other nodes included in the target blockchain, and the other nodes are nodes included in the target blockchain other than the nodes in the candidate node set.
[0084] The third determining module 46 is used to determine the voting weight of the second node based on the network comprehensive score of the second node participating in the voting when receiving a voting request sent by a first node included in the target blockchain, and the first node is a node included in the candidate node set. The voting request is used to request the election of the first node as the master node for managing the target blockchain, and the second node is a node included in the target blockchain.
[0085] The fourth determining module 48 is used to determine whether to elect the first node as the master node based on the voting result of the second node and the voting weight.
[0086] In an exemplary embodiment, the first determining module 42 may determine the network performance index of each node included in the target blockchain by: determining the network latency, packet loss rate, latency jitter, and bandwidth of all nodes included in the target blockchain; determining a first performance index of each node based on the network latency, the packet loss rate, and the latency jitter; determining a second performance index of each node based on the node bandwidth; and determining the network performance index based on the first performance index and the second performance index.
[0087] In an exemplary embodiment, the first determining module 42 may determine a first performance index for each node based on the network latency time, the node packet loss rate, and the node latency jitter in the following manner: determining the maximum network latency time, the minimum network latency time, and the target network latency time of the node included in the network latency time; determining the maximum node packet loss rate, the minimum node packet loss rate, and the target node packet loss rate of the node included in the node packet loss rate; determining the maximum node latency jitter, the minimum node latency jitter, and the target node latency jitter of the node included in the node latency jitter; determining a first sub-performance index based on the maximum network latency time, the minimum network latency time, and the target network latency time; determining a second sub-performance index based on the maximum node packet loss rate, the minimum node packet loss rate, and the target node packet loss rate; determining a third sub-performance index based on the maximum node latency jitter, the minimum node latency jitter, and the target node latency jitter; and determining a first sum of the first sub-performance index, the second sub-performance index, and the third sub-performance index as the first performance index.
[0088] In an exemplary embodiment, the first determining module 42 can determine a first sub-performance indicator based on the maximum network latency time, the minimum network latency time, and the target network latency time by: determining a first difference between the maximum network latency time and the target network latency time, determining a second difference between the maximum network latency time and the minimum network latency time, and determining a first ratio of the first difference to the second difference as the first sub-performance indicator; the first determining module 42 can also determine a second sub-performance indicator based on the maximum node packet loss rate, the minimum node packet loss rate, and the target node packet loss rate by: determining the maximum node... The first determining module 402 can determine the third sub-performance index based on the maximum node delay jitter, the minimum node delay jitter, and the target node delay jitter by: determining the fifth difference between the maximum node delay jitter and the target node delay jitter, determining the sixth difference between the maximum node delay jitter and the minimum node delay jitter, and determining the third ratio of the fifth difference to the sixth difference as the third sub-performance index.
[0089] In an exemplary embodiment, the first determining module 42 may determine a second performance index for each node based on the node bandwidth by: determining the maximum node bandwidth, the minimum node bandwidth, and the target node bandwidth included in the node bandwidth; determining a seventh difference between the target node bandwidth and the minimum node bandwidth; determining an eighth difference between the maximum node bandwidth and the minimum node bandwidth; and determining the ratio of the seventh difference to the eighth difference as the second performance index.
[0090] In an exemplary embodiment, the first determining module 42 may determine the network performance index based on the first performance index and the second performance index by: determining a second sum of the first performance index and the second performance index; and determining the second sum as the network performance index.
[0091] In an exemplary embodiment, the third determining module 46 can determine the voting weight of the second node based on the network comprehensive score of the second node participating in the voting in the following manner: determining the network bandwidth, network latency, and cumulative number of disconnections of the second node; determining the network comprehensive score of the second node based on the network bandwidth, network latency, and cumulative number of disconnections; performing clustering processing on the network comprehensive score to obtain multiple target categories; assigning a target weight to each target category, wherein the target weight of the target category with a high network comprehensive score is greater than the target weight of the target category with a low network comprehensive score; and determining the target weight of the category to which the second node belongs as the voting weight.
[0092] In an exemplary embodiment, the fourth determining module may determine whether to elect the first node as the master node based on the voting results of the second node and the voting weight in the following manner: determining the product of the voting results of each second node and the voting weight; determining a third sum of the product; electing the first node as the master node if the third sum is greater than a first threshold; and rejecting the first node as the master node if the third sum is less than or equal to the first threshold.
[0093] In an exemplary embodiment, the apparatus may further be used to perform one of the following before determining the voting weight of the second node based on the network comprehensive score of the second node participating in the voting: determining all nodes included in the target blockchain as the second node; determining the node that broadcasts the voting results as the second node; determining the node included in the target blockchain whose network performance index is greater than a preset index as the second node; determining the top N nodes included in the target blockchain whose network performance index is the highest as the second node, where N is a positive integer.
[0094] In one exemplary embodiment, the apparatus may further be configured to, upon receiving a voting request from a first node included in the target blockchain, vote against the first node if it is determined that the first node is not included in the candidate node set, wherein the vote against the first node indicates opposition to its election as the master node.
[0095] It should be noted that the above modules can be implemented by software or hardware. For the latter, they can be implemented in the following ways, but are not limited to: all the above modules are located in the same processor; or, the above modules are located in different processors in any combination.
[0096] Embodiments of the present invention also provide a computer-readable storage medium storing a computer program, wherein the computer program is configured to perform the steps in any of the above method embodiments when executed.
[0097] In one exemplary embodiment, the aforementioned computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard disk, magnetic disk, or optical disk.
[0098] Embodiments of the present invention also provide an electronic device including a memory and a processor, the memory storing a computer program and the processor being configured to run the computer program to perform the steps in any of the above method embodiments.
[0099] In one exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor and the input / output device is connected to the processor.
[0100] Embodiments of the present invention also provide a computer program product, including a computer program that, when executed by a processor, implements the steps of the methods in various embodiments of the present application.
[0101] Specific examples in this embodiment can be found in the examples described in the above embodiments and exemplary implementations, and will not be repeated here.
[0102] It is obvious to those skilled in the art that the modules or steps of the present invention described above can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. They can be implemented using computer-executable program code, and thus can be stored in a storage device for execution by a computing device. In some cases, the steps shown or described can be performed in a different order than those described herein, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any particular combination of hardware and software.
[0103] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, or improvements made within the principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A blockchain management method, characterized in that, include: Determine the network performance metrics for each node included in the target blockchain, wherein the network performance metrics are used to indicate the network status of the node; Based on the network performance metrics, a set of candidate nodes is determined from the nodes included in the target blockchain, wherein the network status of the nodes included in the candidate node set is better than that of other nodes included in the target blockchain, and the other nodes are nodes included in the target blockchain other than the nodes in the candidate node set. Upon receiving a voting request from a first node included in the target blockchain, and the first node being a node included in the candidate node set, the voting weight of the second node is determined based on the comprehensive network score of the second node participating in the voting. The voting request is used to request the election of the first node as the master node for managing the target blockchain, and the second node is a node included in the target blockchain. Based on the voting results of the second node and the voting weight, it is determined whether the first node should be elected as the master node.
2. The method according to claim 1, characterized in that, The network performance metrics for each node in the target blockchain include: Determine the network latency, packet loss rate, latency jitter, and bandwidth of all nodes included in the target blockchain; A first performance metric for each node is determined based on the network latency, the node packet loss rate, and the node latency jitter. A second performance metric for each node is determined based on the node bandwidth. The network performance metrics are determined based on the first performance metric and the second performance metric.
3. The method according to claim 2, characterized in that, The first performance metric for each node, determined based on the network latency, the node packet loss rate, and the node latency jitter, includes: Determine the maximum network latency, the minimum network latency, and the target network latency of the node, which are included in the network latency. Determine the maximum node packet loss rate, the minimum node packet loss rate, and the target node packet loss rate included in the node packet loss rate; Determine the maximum node delay jitter, the minimum node delay jitter, and the target node delay jitter of the node, which are included in the node delay jitter. The first sub-performance metric is determined based on the maximum network latency, the minimum network latency, and the target network latency. The second sub-performance index is determined based on the maximum node packet loss rate, the minimum node packet loss rate, and the target node packet loss rate. The third sub-performance index is determined based on the maximum node delay jitter, the minimum node delay jitter, and the target node delay jitter; The first performance index is determined by the first sum of the first sub-performance index, the second sub-performance index, and the third sub-performance index.
4. The method according to claim 3, characterized in that, Determining the first sub-performance index based on the maximum network latency time, the minimum network latency time, and the target network latency time includes: determining a first difference between the maximum network latency time and the target network latency time, determining a second difference between the maximum network latency time and the minimum network latency time, and determining a first ratio of the first difference to the second difference as the first sub-performance index; Determining the second sub-performance index based on the maximum node packet loss rate, the minimum node packet loss rate, and the target node packet loss rate includes: determining a third difference between the maximum node packet loss rate and the target node packet loss rate, determining a fourth difference between the maximum node packet loss rate and the minimum node packet loss rate, and determining a second ratio of the third difference to the fourth difference as the second sub-performance index; Determining the third sub-performance index based on the maximum node delay jitter, the minimum node delay jitter, and the target node delay jitter includes: determining a fifth difference between the maximum node delay jitter and the target node delay jitter, determining a sixth difference between the maximum node delay jitter and the minimum node delay jitter, and determining a third ratio between the fifth difference and the sixth difference as the third sub-performance index.
5. The method according to claim 2, characterized in that, Determining a second performance metric for each node based on the node bandwidth includes: Determine the maximum node bandwidth, minimum node bandwidth, and target node bandwidth included in the node bandwidth; Determine the seventh difference between the target node bandwidth and the minimum node bandwidth; Determine the eighth difference between the maximum node bandwidth and the minimum node bandwidth; The ratio of the seventh difference to the eighth difference is determined as the second performance index.
6. The method according to claim 2, characterized in that, Determining the network performance metrics based on the first performance metric and the second performance metric includes: Determine the second sum of the first performance index and the second performance index; The second sum is determined as the network performance metric.
7. The method according to claim 1, characterized in that, The voting weight of the second node is determined based on the overall network score of the second node participating in the voting, including: Determine the network bandwidth, network latency, and cumulative number of disconnections for the second node; The comprehensive network score of the second node is determined based on the network bandwidth, the network latency, and the cumulative number of disconnections. Clustering is performed on the network comprehensive score to obtain multiple target categories; Assign a target weight to each target category, wherein the target weight of the target category with a high network comprehensive score is greater than the target weight of the target category with a low network comprehensive score; The target weight of the category to which the second node belongs is determined as the voting weight.
8. The method according to claim 1, characterized in that, Determining whether to elect the first node as the master node based on the voting results of the second node and the voting weight includes: Determine the product of the voting result and the voting weight for each of the second nodes; Determine the third sum of the product; If the third sum is greater than the first threshold, the first node is elected as the master node; If the third sum is less than or equal to the first threshold, the first node is rejected as the master node.
9. The method according to claim 1, characterized in that, Before determining the voting weight of the second node based on the network comprehensive score of the second node participating in the voting, the method further includes one of the following: All nodes included in the target blockchain are identified as the second node; The node that broadcasts the voting results is identified as the second node; The nodes in the target blockchain whose network performance indicators are greater than the preset indicators are identified as the second node; The top N nodes in the target blockchain with the highest network performance metrics are identified as the second node, where N is a positive integer.
10. The method according to claim 1, characterized in that, After receiving a voting request from a first node included in the target blockchain, the method further includes: If it is determined that the first node is not included in the set of candidate nodes, a vote is cast against the first node, wherein the vote against the first node is opposed to its election as the master node.
11. A blockchain management device, characterized in that, include: The first determining module is used to determine the network performance index of each node included in the target blockchain, wherein the network performance index is used to indicate the network status of the node; The second determining module is used to determine a candidate node set from the nodes included in the target blockchain based on the network performance indicators, wherein the network status of the nodes included in the candidate node set is better than that of other nodes included in the target blockchain, and the other nodes are nodes included in the target blockchain other than the nodes in the candidate node set. The third determining module is used to determine the voting weight of the second node based on the network comprehensive score of the second node participating in the voting when receiving a voting request sent by a first node included in the target blockchain, and the first node is a node included in the candidate node set. The voting request is used to request the election of the first node as the master node for managing the target blockchain, and the second node is a node included in the target blockchain. The fourth determining module is used to determine whether to elect the first node as the master node based on the voting results of the second node and the voting weight.
12. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, wherein the computer program is configured to perform the method described in any one of claims 1 to 10 when executed.
13. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to run the computer program to perform the method as described in any one of claims 1 to 10.
14. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method described in any one of claims 1 to 10.