Block chain consensus method, system and device applied to energy power and medium
By adopting a random number generation algorithm based on node time synchronization based on limited distance range and a verifiable delay function in the blockchain, the problem of unbalanced computing resource consumption and consensus efficiency in the energy and power industry is solved, and the time synchronization efficiency and Its attack resistance ability meets the needs of transaction consensus business.
Patent Information
- Application Number
- CN202410834733.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-26
- Publication Date
- 2024-10-11
AI Technical Summary
The existing blockchain consensus mechanism is difficult to balance computing resource consumption and consensus efficiency in the energy and power industry, resulting in low time synchronization efficiency and low difficulty in attacking malicious nodes, and cannot effectively meet the needs of transaction consensus business.
Using a random number generation algorithm based on node time synchronization based on a limited distance range combined with a verifiable delay function, the Kademlia protocol calculates logical distance and generates a time synchronization scale network, filters candidate consensus nodes for voting, arranges the number of votes in descending order to determine the packaging node, and Replace the packaged nodes if necessary to ensure block generation efficiency.
It improves time synchronization efficiency and consensus efficiency, reduces the difficulty and cost of malicious node attacks, ensures that consensus voting results can be verified, improves anti-network attack capabilities, and meets the transaction consensus business needs of the energy and power industry.
Smart Images

Figure CN118764160A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of blockchain technology, and in particular to a blockchain consensus method, system, computer equipment and storage medium applied to energy and electricity. Background Art
[0002] With the continuous development and progress of blockchain technology, its application areas have expanded to many industries such as energy, network and finance. For example, non-evidence scenarios such as green electricity trading and green electricity traceability in the energy and power industry are gradually introducing the use of blockchain. Such non-evidence application scenarios in the energy and power industry require both consensus efficiency to meet user transaction needs and avoid excessive consumption of computing resources to ensure the bottom line of power grid security.
[0003] The consensus mechanism of blockchain is an important technology to ensure the performance and security of blockchain applications. It completes the verification and confirmation of transactions in a very short time through special node voting, which meets the consistency and validity of consensus information. Although the existing mainstream consensus mechanisms have their own characteristics, they are difficult to effectively balance the waste of computing resources and the complexity of communication. For example, the Proof of Work (Pow) consensus mechanism wastes a lot of computing resources, and the Practical Byzantine Fault Tolerance (PBFT) algorithm has extremely high communication complexity, which cannot really effectively meet the blockchain consensus application needs of the energy and power industry. Summary of the invention
[0004] The purpose of the present invention is to provide a blockchain consensus method applied to energy and electricity. Through the node time synchronization based on a limited distance range combined with a consensus voting mechanism based on a random number generation algorithm based on a verifiable delay function, the application defect of the existing consensus mechanism that it is difficult to balance the consumption of computing resources and consensus efficiency can be solved, the time synchronization efficiency can be effectively improved, the difficulty and cost of malicious node attacks can be increased, and the probability of malicious nodes becoming packaging nodes can be reduced, thereby ensuring that the consensus voting results can be checked and improving the ability to resist network attacks.
[0005] In order to achieve the above objectives, it is necessary to provide a blockchain consensus method, system, computer equipment and storage medium applied to energy and electricity in response to the above technical problems.
[0006] In a first aspect, an embodiment of the present invention provides a blockchain consensus method applied to energy and electricity, the method comprising the following steps:
[0007] In response to the consensus processing request, obtain the time synchronization scale network and node attributes of each blockchain node; the node attributes include newly joined and joined;
[0008] According to the time synchronization scale network and node attributes of each blockchain node, all blockchain nodes are timestamped and synchronized, and according to the timestamp synchronization information of each blockchain node, candidate consensus nodes are obtained from the blockchain nodes whose node attributes are already joined;
[0009] According to the verifiable delay function, a consensus voting node is obtained from the candidate consensus nodes, and according to the preset voting rules, consensus voting is performed through each consensus voting node to obtain the number of votes of each consensus voting node;
[0010] All consensus voting nodes are arranged in descending order according to the corresponding number of votes, and the consensus voting node with the highest number of votes is used as the optimal node for new block packaging, and the new block generation task is performed by the optimal node for new block packaging.
[0011] Furthermore, the steps for generating the time synchronization scale network and node attributes of each blockchain node include:
[0012] According to the Kademlia protocol, the logical distance between each blockchain node and the adjacent blockchain node is calculated, and according to the logical distance and the preset node scale distance upper limit, the corresponding time synchronization scale network is generated;
[0013] Determine whether the deviation between the timestamp of each blockchain node and the timestamp of the latest block is less than or equal to a preset time tolerance threshold. If so, set the node attribute of the blockchain node to have been added; otherwise, set the node attribute of the blockchain node to have been newly added.
[0014] Furthermore, the step of synchronizing the timestamps of all blockchain nodes according to the time synchronization scale network and node attributes of each blockchain node includes:
[0015] When the node attribute of the blockchain node is joined, the latest block timestamp and the timestamps of each time synchronization node in the corresponding time synchronization scale network are obtained, and the timestamp of the blockchain node itself is updated according to the timestamps of each time synchronization node and the latest block timestamp;
[0016] When the node attribute of the blockchain node is newly added, the timestamp of the time synchronization node in the corresponding time synchronization scale network is obtained, and the timestamp of the blockchain node itself is obtained according to the timestamps of each time synchronization node.
[0017] Furthermore, the step of updating the timestamp of the blockchain node itself according to the timestamps of each time synchronization node and the latest block timestamp includes:
[0018] According to the timestamps of each time synchronization node, obtain the average timestamp of the synchronization node;
[0019] The difference between the average value of the synchronization node timestamp and the own timestamp is used as a random seed to generate a corresponding time synchronization deviation;
[0020] The time synchronization deviation is added to the latest block timestamp to obtain a node synchronization timestamp, and the blockchain node's own timestamp is updated according to the node synchronization timestamp.
[0021] Furthermore, the step of obtaining a consensus voting node from the candidate consensus nodes according to the verifiable delay function includes:
[0022] The number of candidate consensus nodes and the latest block height are used as input parameters of the verifiable delay function to obtain the corresponding public and private key pairs;
[0023] According to the public-private key pair, each candidate consensus node generates a random number and a corresponding proof value, and verifies the random number according to the proof value and the public key in the public-private key pair to obtain a corresponding random number verification result;
[0024] According to a preset screening ratio, the candidate consensus nodes whose random number verification results are true are screened to obtain the consensus voting nodes.
[0025] Furthermore, the step of performing consensus voting through each consensus voting node according to the preset voting rules includes:
[0026] Each consensus voting node broadcasts its own node information in the entire blockchain network; the node information includes its own generated random number and its own timestamp;
[0027] According to the preset voting rules, each consensus voting node determines the corresponding voting object based on the received information of other consensus voting nodes; the preset voting rules include that each consensus voting node takes the consensus voting node with the smallest difference with its own timestamp as the voting object.
[0028] Furthermore, the method further comprises:
[0029] When the optimal node for new block packaging fails to complete the block generation task within the preset block generation time, the next consensus voting node is obtained from top to bottom as the new block packaging node according to the descending sorting results of the number of votes of all consensus voting nodes, and the new block generation task is performed within the preset block generation time.
[0030] In a second aspect, an embodiment of the present invention provides a blockchain consensus system applied to energy and electricity, the system comprising:
[0031] A synchronization scale acquisition module, used to obtain the time synchronization scale network and node attributes of each blockchain node in response to the consensus processing request; the node attributes include newly joined and already joined;
[0032] The candidate node acquisition module is used to synchronize the timestamps of all blockchain nodes according to the time synchronization scale network and node attributes of each blockchain node, and obtain the candidate consensus nodes from the blockchain nodes with the node attributes as the joined nodes according to the timestamp synchronization information of each blockchain node;
[0033] A consensus voting module, used to obtain a consensus voting node from the candidate consensus nodes according to a verifiable delay function, and to perform consensus voting through each consensus voting node according to a preset voting rule to obtain the number of votes of each consensus voting node;
[0034] The packing node determination module is used to arrange all consensus voting nodes in descending order according to the corresponding number of votes, and use the consensus voting node with the highest number of votes as the optimal node for packing the new block, and the optimal node for packing the new block performs the new block generation task.
[0035] In a third aspect, an embodiment of the present invention further provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.
[0036] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the steps of the above method when executed by a processor.
[0037] The above-mentioned application provides a blockchain consensus method, system, computer device and storage medium applied to energy and electricity. The method realizes responding to consensus processing requests, obtaining the time synchronization scale network of each blockchain node and the attributes of newly joined and already joined nodes, and then performing timestamp synchronization on all blockchain nodes according to the time synchronization scale network and node attributes of each blockchain node, and obtaining candidate consensus nodes from the blockchain nodes with node attributes as already joined according to the timestamp synchronization information of each blockchain node, and then obtaining consensus voting nodes from the candidate consensus nodes according to a verifiable delay function, and according to preset voting rules, consensus voting is performed through each consensus voting node to obtain the number of votes of each consensus voting node, and all consensus voting nodes are arranged in descending order according to the corresponding number of votes, and the consensus voting node with the highest corresponding number of votes is used as the optimal node for new block packaging, and the new block packaging optimal node performs the new block generation task. Technical solution. Compared with the existing technology, the blockchain consensus method applied to energy and power proposes a consensus mechanism based on sequential voting by designing a time synchronization timestamp generation method for adjacent nodes of a given scale based on random beacons. It can not only effectively reduce communication complexity, reduce computing resource usage, improve time synchronization efficiency and consensus efficiency, and increase the difficulty and cost of malicious node attacks, but also reduce the probability of malicious nodes becoming packaging nodes, ensure that the consensus voting results can be checked, and thus improve the ability to resist network attacks. It can effectively meet the application scenario requirements of the energy and power industry that take into account both transaction consensus business efficiency and system overhead. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 It is a flowchart of a blockchain consensus method applied to energy and electricity in an embodiment of the present invention;
[0039] Figure 2 It is another flow chart of the blockchain consensus method applied to energy and power in an embodiment of the present invention;
[0040] Figure 3 It is a schematic diagram of the structure of a blockchain consensus system applied to energy and power in an embodiment of the present invention;
[0041] Figure 4 It is another structural schematic diagram of the blockchain consensus system applied to energy and power in an embodiment of the present invention;
[0042] Figure 5 It is a diagram of the internal structure of a computer device in an embodiment of the present invention. DETAILED DESCRIPTION
[0043] In order to make the purpose, technical scheme and beneficial effects of the present application clearer, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. Obviously, the embodiments described below are part of the embodiments of the present invention and are only used to illustrate the present invention, but are not used to limit the scope of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0044] The blockchain consensus method applied to energy and electricity provided by the present invention can be understood as the problem that the consumption of computing power resources and consensus efficiency are difficult to be compatible based on the existing consensus mechanism, and the application status that cannot truly and effectively meet the blockchain consensus application needs of the energy and power industry. A consensus mechanism based on timing voting designed by a timestamp generation synchronization method based on a random beacon is proposed. It realizes time synchronization of adjacent nodes of a given scale through random beacons, effectively reduces communication complexity, and reduces computing power resource occupancy through over-voting algorithms, improves time synchronization efficiency and consensus efficiency, and increases the difficulty and cost of malicious node attacks. At the same time, based on the consensus mechanism that uses the random time confirmed by the node as the random number sequence generation parameter, it effectively reduces the probability of malicious nodes becoming packaging nodes, ensures that the consensus voting results can be checked, and thus improves the ability to resist network attacks. The following embodiments will explain the blockchain consensus method applied to energy and electricity of the present invention in detail.
[0045] In one embodiment, Figure 1 As shown, a blockchain consensus method applied to energy and electricity is provided, comprising the following steps:
[0046] S11. In response to the consensus processing request, the time synchronization scale network and node attributes of each blockchain node are obtained; the node attributes include newly joined and already joined; wherein, the blockchain transaction content involved in the consensus processing request varies depending on the application scenario of the actual energy and power blockchain, but will not affect the application of the consensus method; it should be noted that the application scenarios that may be involved in actual applications include but are not limited to green electricity transactions (transaction accounting), consumption voucher storage and green electricity traceability, etc., and different application scenarios will only affect the permission configuration of the light nodes and global nodes at the front end of the blockchain, and will not affect the application effect of the method of the present invention.
[0047] The time synchronization scale network in this embodiment can be understood as a topological network of timestamp synchronization nodes formed by grouping all blockchain nodes in the blockchain based on the time synchronization principle within a limited distance range, and each blockchain node corresponds to a time synchronization scale network; correspondingly, the node attribute can be understood as a node tag used to identify the existence status (newly added node or existing node) of each blockchain node in the blockchain during each round of transaction consensus processing, so as to facilitate the use of different timestamp synchronization strategies according to different node types; in actual applications, the time synchronization scale network and node attributes existing in the blockchain will be adjusted due to the increase or decrease of nodes in the blockchain; specifically, the steps for generating the time synchronization scale network and node attributes of each blockchain node include:
[0048] According to the Kademlia protocol, the logical distance between each blockchain node and the adjacent blockchain node is calculated, and the corresponding time synchronization scale network is generated according to the logical distance and the preset node scale distance upper limit; wherein, the preset node scale distance upper limit can be selected and set according to the minimum threshold that can cover all nodes in actual application, and is not specifically limited here; correspondingly, the process of determining the time synchronization scale network of each blockchain node is as follows:
[0049] The node's adjacent node distance range based on the Kademlia protocol is set, and the logical distance between each node and other nodes is calculated based on the Kademlia protocol. After the node's own Bucket list is generated from near to far according to the logical distance, based on the preset node scale distance upper limit N (such as 6 or 8), the first N (such as 6, 8) nodes in the Bucket list are selected as time synchronization nodes within the synchronization timestamp range of the node, and the corresponding time synchronization scale network is obtained; through such small-scale time synchronization, time can be synchronized multiple times, which can not only reduce the network communication overhead of each time synchronization, but also effectively avoid the safety risks caused by the long synchronization time period of all nodes due to the failure of time synchronization of some nodes;
[0050] It is determined whether the deviation between the timestamp of each blockchain node and the timestamp of the latest block is less than or equal to the preset time tolerance threshold. If so, the node attribute of the blockchain node is set to have been added. Otherwise, the node attribute of the blockchain node is set to newly added. The preset time tolerance threshold ε can be selected according to the actual application requirements and is not specifically limited here. Correspondingly, the specific process of calculating whether a node is a newly added node or an already added node is as follows:
[0051] Assume that the timestamp of a blockchain node is tTime, and the timestamp of the latest block is bTime; if bTime-ε≤tTime≤bTime+ε is satisfied, the blockchain node is determined to be a joined node, and its corresponding node attribute is set to joined; otherwise, the blockchain node is determined to be a newly joined node, and its corresponding node attribute is set to newly joined; it should be noted that, in this embodiment, the node whose node attribute is determined to be newly joined does not participate in the current round of transaction consensus processing.
[0052] S12. Perform timestamp synchronization on all blockchain nodes according to the time synchronization scale network and node attributes of each blockchain node, and obtain candidate consensus nodes from the blockchain nodes whose node attributes are already joined according to the timestamp synchronization information of each blockchain node.
[0053] In order to ensure the effective synchronization of the timestamps of the existing nodes in the blockchain network while avoiding the interference of newly added nodes or malicious nodes in the subsequent transaction consensus processing, the method for synchronizing the timestamps of all blockchain nodes preferably adopted in this embodiment is as described above, which provides two different timestamp update generation strategies for the two types of nodes, namely, newly added and already added. Specifically, the steps of synchronizing the timestamps of all blockchain nodes according to the time synchronization scale network and node attributes of each blockchain node include:
[0054] When the node attribute of the blockchain node is joined, the latest block timestamp and the timestamp of each time synchronization node in the corresponding time synchronization scale network are obtained, and the self-timestamp of the blockchain node is updated according to the timestamps of each time synchronization node and the latest block timestamp; wherein, the timestamps of each time synchronization node in the time synchronization scale network corresponding to the blockchain node can be understood as being obtained by handshake message communication; correspondingly, the latest block timestamp can be obtained through the corresponding block header information; in order to ensure the accuracy of timestamp synchronization of the joined nodes, this embodiment preferably takes the latest block timestamp as the reference time, and uses the deviation between its own timestamp and the timestamp of the time synchronization node in the time synchronization scale network as the adjustment basis to synchronize and update the node's own timestamp; specifically, the step of updating the self-timestamp of the blockchain node according to the timestamps of each time synchronization node and the latest block timestamp includes:
[0055] According to the timestamps of each time synchronization node, the average timestamp of the synchronization node is obtained; wherein the average timestamp of the synchronization node is expressed as:
[0056]
[0057] Where AvgTime represents the average value of the synchronization node timestamp; cTime irepresents the timestamp of the i-th time synchronization node; N represents the number of time synchronization nodes in the time synchronization scale network;
[0058] The difference between the average value of the synchronization node timestamp and the self-timestamp is used as a random seed to generate a corresponding time synchronization deviation; wherein the time synchronization deviation is expressed as:
[0059] dTime=Rand(|AvgTime-tTime|)
[0060] In the formula, dTime represents the time synchronization deviation; Rand() represents the random function; tTime represents the current timestamp of the blockchain node;
[0061] The time synchronization deviation is added to the latest block timestamp to obtain a node synchronization timestamp, and the self-timestamp of the blockchain node is updated according to the node synchronization timestamp; wherein the self-timestamp of the blockchain node after the update is expressed as:
[0062] iTime=dTime+bTime
[0063] In the formula, iTime represents the timestamp of the blockchain node after the update; bTime represents the timestamp of the latest block;
[0064] From the above-mentioned calculation method for synchronizing the existing node timestamps in the blockchain network, it can be seen that the time synchronization communication complexity is only O(log(N)), which can not only avoid the interference of new nodes or malicious nodes in the consensus, but also effectively improve the synchronization time efficiency of the nodes in the entire blockchain network.
[0065] When the node attribute of the blockchain node is newly added, the timestamp of the time synchronization node in the corresponding time synchronization scale network is obtained, and the self-time stamp of the blockchain node is obtained according to the timestamps of each time synchronization node; that is, for the blockchain node with the node attribute being newly added, the self-time stamp is confirmed according to the timestamps of each time synchronization node in the time synchronization scale network determined by the Kademlia protocol obtained through the handshake communication method, which is specifically expressed as:
[0066]
[0067] In the formula, iTime represents the timestamp of the newly added blockchain node; cTime i Indicates the timestamp of the i-th time synchronization node in the time synchronization scale network where the blockchain node is located; N indicates the number of time synchronization nodes in the time synchronization scale network.
[0068] In this embodiment, two different timestamp synchronization strategies are designed for newly added and already added nodes with two different attributes to synchronize the timestamps of all nodes in the entire network, ensuring that the timestamps of all nodes in the entire network are close, which can lay a time foundation for subsequent consensus.
[0069] In addition, the selection process of candidate consensus nodes in this embodiment can be understood as obtaining blockchain nodes that have completed time synchronization within a preset synchronization duration by checking the timestamp synchronization information of each blockchain node as candidate consensus nodes; it should be noted that the specific method of checking the timestamp synchronization information of each blockchain node can be determined according to actual application requirements and is not specifically limited here.
[0070] S13. According to the verifiable delay function, the consensus voting node is obtained from the candidate consensus nodes, and according to the preset voting rules, consensus voting is performed through each consensus voting node to obtain the number of votes of each consensus voting node; wherein the verifiable delay function (Verifiable Delay Function, VDF) is a large-scale parallel algorithm with a fixed operation order and can be quickly verified, and is composed of an initialization algorithm Setup (generating a public-private key pair), a calculation algorithm Eval (generating a random number result and proof) and a verification algorithm Verify (random number verification); specifically, the step of obtaining a consensus voting node from the candidate consensus node according to the verifiable delay function includes:
[0071] The number of candidate consensus nodes and the latest block height are used as input parameters of the verifiable delay function to obtain the corresponding public-private key pair; wherein the public-private key pair can be understood as the private key sk and the public key pk generated based on the number of candidate consensus nodes M, the latest block height h and the initialization algorithm Setup. The specific acquisition process can be implemented with reference to the existing technology and will not be repeated here;
[0072] According to the public-private key pair, each candidate consensus node generates a random number and a corresponding proof value, and verifies the random number according to the proof value and the public key in the public-private key pair to obtain a corresponding random number verification result; wherein the random number and the corresponding proof value can be understood as the output obtained by executing the calculation algorithm Eval based on the public-private key pair obtained above; the corresponding random number verification result can be understood as the true / false result obtained by verifying the random number generated by each blockchain node based on the verification algorithm Verify; it should be noted that the specific execution process of the above-mentioned calculation algorithm Eval and verification algorithm Verify can be realized with reference to the existing technology, which will not be described in detail here;
[0073] According to a preset screening ratio, the candidate consensus nodes whose random number verification results are true are screened to obtain the consensus voting nodes; wherein the preset screening ratio can be determined according to actual application requirements, for example, it can be set to select the first 20%, 30% or 50% of the candidate consensus nodes whose random number verification results are true, which is not specifically limited here.
[0074] Specifically, the steps of performing consensus voting through each consensus voting node according to the preset voting rules include:
[0075] Each consensus voting node broadcasts its own node information in the entire blockchain network; the node information includes its own generated random number and its own timestamp; the consensus voting node can be understood as the blockchain node participating in the consensus voting elected by the above-mentioned VDF algorithm, which broadcasts its own generated random number and timestamp information in the entire network, so that the other nodes participating in the voting can obtain their corresponding timestamp information, which is convenient for subsequent voting and selecting packaging nodes based on node timestamps;
[0076] According to the preset voting rules, each consensus voting node determines the corresponding voting object based on the received information of other consensus voting nodes; the preset voting rules include that each consensus voting node takes the consensus voting node with the smallest difference with its own timestamp as the voting object, that is, each consensus voting node uses its own timestamp as the reference point, calculates the difference between the timestamps of the other participating consensus nodes and the node's own timestamp, casts the vote for the node with the smallest difference with its own timestamp (the vote cannot be cast for the node itself), and signs the vote.
[0077] This embodiment adopts the VDF algorithm for node election based on the consideration of the security risks brought by the differences in the timestamp synchronization of newly added nodes. While realizing random number generation and verification, it ensures better security based on its serial operation method. At the same time, after each consensus voting node determines the voting object through the preset voting rules and completes the consensus voting, each consensus voting node synchronizes the result information of its own vote to the other consensus voting nodes participating in the vote through the handshake protocol, so that each consensus voting node can summarize and count the votes of all consensus voting nodes to accurately determine the packaging node.
[0078] S14. Arrange all consensus voting nodes in descending order according to the corresponding number of votes, and use the consensus voting node with the highest number of votes as the optimal node for new block packaging, and the optimal node for new block packaging performs the new block generation task; wherein, the optimal node for new block packaging can be understood as the consensus voting node with the highest number of votes determined by the voting results obtained by the summary statistics of each consensus voting node, which will obtain the packaging authority of the next block and perform the new block generation task; it should be noted that when executing the new block packaging, it is preferred to add the current round of voting results to the packaged block, and by broadcasting the voting results to the network, it is ensured that other nodes in the network can obtain the previous round of voting results through the latest generated block, thereby effectively ensuring the security of block generation.
[0079] This embodiment uses a small-range multiple time synchronization method based on the Kademlia protocol to limit the time synchronization distance range of blockchain nodes, effectively reducing the complexity of time synchronization communication, reducing the time synchronization overhead and computing resource usage of the overall network, improving time synchronization efficiency and consensus efficiency, and increasing the difficulty and cost of malicious node attacks. At the same time, it also uses the consensus mechanism and node rotation mechanism of the VDF random number sequence to reduce the probability of malicious nodes becoming packaging nodes, ensure that the consensus voting results can be checked, and then improve the ability to resist network attacks.
[0080] In addition, considering that in actual applications there may be a situation where the packaging node is too slow to package for some reason, thereby affecting the transaction efficiency, in order to further ensure the efficiency of new block generation, this embodiment preferably sets an acceptable block packaging time when determining that the optimal node with the highest number of votes shall execute the packaging authority, and when the block packaging is not completed after exceeding the acceptable block packaging time, reselect the packaging node to continue to perform the packaging task; specifically, Figure 2 As shown, a blockchain consensus method applied to energy and electricity is provided, and the method also includes:
[0081] S15. When the optimal node for new block packaging fails to complete the block generation task within the preset block generation time, the next consensus voting node is obtained from top to bottom as the new block packaging node according to the descending sorting results of the number of votes of all consensus voting nodes, and the new block generation task is performed within the preset block generation time; wherein the preset block generation time can be selected according to actual application requirements and is not specifically limited here.
[0082] In actual applications, according to the descending sorting results of the number of votes of all consensus voting nodes, the process of obtaining the next consensus voting node from top to bottom as the new block packaging node and performing the new block generation task within the preset block generation time can be understood as follows: when the node with the highest number of votes fails to complete block packaging within the time limit, the node with the second highest number of votes is used as the new block packaging node to perform the packaging task, and the new block packaging node also adds the current round of voting results to the packaged block, so that other nodes can obtain the previous round of voting results through the latest generated block, so as to effectively ensure the security of block generation; it should be noted that when the node with the second highest number of votes also fails to complete block packaging within the time limit, it can be decided whether to continue to select the node with the third highest number of votes to continue to perform the packaging task, or whether to continue to select the next consensus voting node to continue to perform the task when the node with the third highest number of votes times out according to actual transaction needs and processing time limit conditions. No specific limitation is made here.
[0083] The embodiments of the present application can not only effectively reduce the complexity of time synchronization communication, reduce the consensus scope, reduce the time synchronization overhead and computing power resource usage of the overall network, improve time synchronization efficiency and consensus efficiency, and increase the difficulty and cost of malicious node attacks through a small-range multiple time synchronization method based on the Kademlia protocol to limit the time synchronization distance range of blockchain nodes, but also reduce the probability of malicious nodes becoming packaging nodes through the consensus mechanism and node rotation mechanism of the VDF random number sequence, ensure that the consensus voting results can be checked, and thus improve the ability to resist network attacks. It can also replace the packaging nodes based on the packaging time limit conditions, while ensuring the security of the system, further improve the efficiency of new block generation, and can effectively meet the application scenario requirements of the energy and power industry that take into account both the efficiency of transaction consensus business and the system overhead.
[0084] It should be noted that although the steps in the above flowchart are shown in sequence according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders.
[0085] In one embodiment, Figure 3 As shown, a blockchain consensus system applied to energy and electricity is provided, and the system includes:
[0086] The synchronization scale acquisition module 1 is used to obtain the time synchronization scale network and node attributes of each blockchain node in response to the consensus processing request; the node attributes include newly joined and already joined;
[0087] The candidate node acquisition module 2 is used to synchronize the timestamps of all blockchain nodes according to the time synchronization scale network and node attributes of each blockchain node, and obtain the candidate consensus nodes from the blockchain nodes whose node attributes are joined according to the timestamp synchronization information of each blockchain node;
[0088] The consensus voting module 3 is used to obtain the consensus voting node from the candidate consensus nodes according to the verifiable delay function, and to perform consensus voting through each consensus voting node according to the preset voting rules to obtain the number of votes of each consensus voting node;
[0089] The packing node determination module 4 is used to arrange all consensus voting nodes in descending order according to the corresponding number of votes, and use the consensus voting node with the highest number of votes as the optimal node for packing the new block, and the optimal node for packing the new block performs the new block generation task.
[0090] In one embodiment, Figure 4 As shown, a blockchain consensus system applied to energy and electricity is provided, and the system also includes:
[0091] The block generation monitoring module 5 is used to obtain the next consensus voting node from top to bottom as the new block packaging node and perform the new block generation task within the preset block generation time when the optimal node for new block packaging fails to complete the block generation task within the preset block generation time according to the descending sorting results of the number of votes of all consensus voting nodes.
[0092] For the specific limitations of the blockchain consensus system applied to energy and electricity, please refer to the limitations of the blockchain consensus method applied to energy and electricity above, and the corresponding technical effects can also be equivalently obtained, which will not be repeated here. Each module in the above-mentioned blockchain consensus system applied to energy and electricity can be implemented in whole or in part through software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0093] Figure 5 FIG. 1 shows an internal structure diagram of a computer device in an embodiment, and the computer device may specifically be a terminal or a server. Figure 5As shown, the computer device includes a processor, a memory, a network interface, a display, a camera and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a blockchain consensus method applied to energy and electricity is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covered on the display screen, or a button, trackball or touchpad set on the housing of the computer device, or an external keyboard, touchpad or mouse, etc.
[0094] It can be understood by those skilled in the art that Figure 5 The structure shown in the figure is only a block diagram of a part of the structure related to the present application scheme, and does not constitute a limitation on the computer device to which the present application scheme is applied. The specific computing device may include more or fewer components than shown in the figure, or combine certain components, or have the same component arrangement.
[0095] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the steps of the above method are implemented when the processor executes the computer program.
[0096] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the above method are implemented.
[0097] In summary, the embodiment of the present invention provides a blockchain consensus method and system for energy and power. The blockchain consensus method for energy and power implements the response to the consensus processing request, obtains the time synchronization scale network of each blockchain node and the attributes of the newly added and already added nodes, and then synchronizes the timestamps of all blockchain nodes according to the time synchronization scale network and node attributes of each blockchain node, and obtains the candidate consensus nodes from the blockchain nodes with the node attributes as the already added nodes according to the timestamp synchronization information of each blockchain node, and then obtains the consensus voting nodes from the candidate consensus nodes according to the verifiable delay function, and according to the preset voting rules, performs consensus voting through each consensus voting node to obtain the number of votes of each consensus voting node, and arranges all consensus voting nodes in descending order according to the corresponding number of votes, and the consensus voting nodes with the highest number of votes are voted. The invention discloses a technical scheme in which a node is used as the optimal node for packaging a new block, and the optimal node for packaging a new block performs the task of generating a new block, and when the optimal node for packaging a new block fails to complete the task of generating a block within the preset block generation time, a technical scheme in which a new block packaging node is selected to perform the task of generating a new block according to the descending sorting result of the number of votes of all consensus voting nodes. The method can not only effectively reduce the complexity of time synchronization communication, reduce the scope of consensus, reduce the time synchronization overhead and computing power resource occupation of the overall network, improve the time synchronization efficiency and consensus efficiency, and increase the difficulty and cost of malicious node attacks, but also reduce the probability of malicious nodes becoming packaging nodes, ensure that the consensus voting results can be checked, and improve the ability to resist network attacks. On the premise of ensuring system security, the efficiency of generating new blocks can be further improved, and the application scenario requirements of both transaction consensus business efficiency and system overhead in the energy and power industry can be effectively met.
[0098] Each embodiment in this specification is described in a progressive manner, and the same or similar parts of each embodiment can be directly referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment. It should be noted that the technical features of the above-mentioned embodiments can be combined arbitrarily. In order to make the description concise, all possible combinations of the technical features in the above-mentioned embodiments are not described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0099] The above-mentioned embodiments only express several preferred implementation modes of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for ordinary technicians in the technical field, several improvements and substitutions can be made without departing from the technical principles of the present invention, and these improvements and substitutions should also be regarded as the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be based on the protection scope of the claims.
Claims
1. A blockchain consensus method applied to energy and electricity, characterized in that: The method comprises the following steps: In response to the consensus processing request, obtain the time synchronization scale network and node attributes of each blockchain node; the node attributes include newly joined and joined; According to the time synchronization scale network and node attributes of each blockchain node, all blockchain nodes are timestamped and synchronized, and according to the timestamp synchronization information of each blockchain node, candidate consensus nodes are obtained from the blockchain nodes whose node attributes are already joined; According to the verifiable delay function, a consensus voting node is obtained from the candidate consensus nodes, and according to the preset voting rules, consensus voting is performed through each consensus voting node to obtain the number of votes of each consensus voting node; All consensus voting nodes are arranged in descending order according to the corresponding number of votes, and the consensus voting node with the highest number of votes is used as the optimal node for new block packaging, and the new block generation task is performed by the optimal node for new block packaging.
2. The blockchain consensus method for energy and power as claimed in claim 1, characterized in that: The steps for generating the time synchronization scale network and node attributes of each blockchain node include: According to the Kademlia protocol, the logical distance between each blockchain node and the adjacent blockchain node is calculated, and according to the logical distance and the preset node scale distance upper limit, the corresponding time synchronization scale network is generated; Determine whether the deviation between the timestamp of each blockchain node and the timestamp of the latest block is less than or equal to a preset time tolerance threshold. If so, set the node attribute of the blockchain node to have been added; otherwise, set the node attribute of the blockchain node to have been newly added.
3. The blockchain consensus method for energy and power as claimed in claim 1, characterized in that: The step of synchronizing the timestamps of all blockchain nodes according to the time synchronization scale network and node attributes of each blockchain node includes: When the node attribute of the blockchain node is joined, the latest block timestamp and the timestamps of each time synchronization node in the corresponding time synchronization scale network are obtained, and the timestamp of the blockchain node itself is updated according to the timestamps of each time synchronization node and the latest block timestamp; When the node attribute of the blockchain node is newly added, the timestamp of the time synchronization node in the corresponding time synchronization scale network is obtained, and the timestamp of the blockchain node itself is obtained according to the timestamps of each time synchronization node.
4. The blockchain consensus method for energy and power as claimed in claim 3, characterized in that: The step of updating the timestamp of the blockchain node itself according to the timestamps of each time synchronization node and the latest block timestamp includes: According to the timestamps of each time synchronization node, obtain the average timestamp of the synchronization node; The difference between the average value of the synchronization node timestamp and the own timestamp is used as a random seed to generate a corresponding time synchronization deviation; The time synchronization deviation is added to the latest block timestamp to obtain a node synchronization timestamp, and the blockchain node's own timestamp is updated according to the node synchronization timestamp.
5. The blockchain consensus method for energy and power as claimed in claim 1, characterized in that: The step of obtaining a consensus voting node from the candidate consensus nodes according to the verifiable delay function comprises: The number of candidate consensus nodes and the latest block height are used as input parameters of the verifiable delay function to obtain the corresponding public and private key pairs; According to the public-private key pair, each candidate consensus node generates a random number and a corresponding proof value, and verifies the random number according to the proof value and the public key in the public-private key pair to obtain a corresponding random number verification result; According to a preset screening ratio, the candidate consensus nodes whose random number verification results are true are screened to obtain the consensus voting nodes.
6. The blockchain consensus method for energy and power as claimed in claim 1, characterized in that: The steps of performing consensus voting through each consensus voting node according to the preset voting rules include: Each consensus voting node broadcasts its own node information in the entire blockchain network; the node information includes its own generated random number and its own timestamp; According to the preset voting rules, each consensus voting node determines the corresponding voting object based on the received information of other consensus voting nodes; the preset voting rules include that each consensus voting node takes the consensus voting node with the smallest difference with its own timestamp as the voting object.
7. The blockchain consensus method for energy and power as claimed in claim 1, characterized in that: The method further comprises: When the optimal node for new block packaging fails to complete the block generation task within the preset block generation time, the next consensus voting node is obtained from top to bottom as the new block packaging node according to the descending sorting results of the number of votes of all consensus voting nodes, and the new block generation task is performed within the preset block generation time.
8. A blockchain consensus system applied to energy and electricity, characterized in that: The system comprises: A synchronization scale acquisition module, used to obtain the time synchronization scale network and node attributes of each blockchain node in response to the consensus processing request; the node attributes include newly joined and already joined; The candidate node acquisition module is used to synchronize the timestamps of all blockchain nodes according to the time synchronization scale network and node attributes of each blockchain node, and obtain the candidate consensus nodes from the blockchain nodes with the node attributes as the joined nodes according to the timestamp synchronization information of each blockchain node; A consensus voting module, used to obtain a consensus voting node from the candidate consensus nodes according to a verifiable delay function, and to perform consensus voting through each consensus voting node according to a preset voting rule to obtain the number of votes of each consensus voting node; The packing node determination module is used to arrange all consensus voting nodes in descending order according to the corresponding number of votes, and use the consensus voting node with the highest number of votes as the optimal node for packing the new block, and the optimal node for packing the new block performs the new block generation task.
9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
