WO2024113956A1 - 节点选取方法、装置、第一节点、存储介质及程序产品 - Google Patents
节点选取方法、装置、第一节点、存储介质及程序产品 Download PDFInfo
- Publication number
- WO2024113956A1 WO2024113956A1 PCT/CN2023/112944 CN2023112944W WO2024113956A1 WO 2024113956 A1 WO2024113956 A1 WO 2024113956A1 CN 2023112944 W CN2023112944 W CN 2023112944W WO 2024113956 A1 WO2024113956 A1 WO 2024113956A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- node
- group
- target
- nodes
- node group
- Prior art date
Links
- 238000010187 selection method Methods 0.000 title claims abstract description 44
- 238000012795 verification Methods 0.000 claims abstract description 79
- 238000012216 screening Methods 0.000 claims abstract description 45
- 238000004590 computer program Methods 0.000 claims description 33
- 238000000034 method Methods 0.000 abstract description 42
- 230000006870 function Effects 0.000 description 22
- 238000010586 diagram Methods 0.000 description 20
- 238000013507 mapping Methods 0.000 description 12
- 238000004891 communication Methods 0.000 description 6
- 230000009286 beneficial effect Effects 0.000 description 5
- 238000007726 management method Methods 0.000 description 4
- 230000007246 mechanism Effects 0.000 description 4
- 238000001914 filtration Methods 0.000 description 3
- 238000012545 processing Methods 0.000 description 3
- 230000006399 behavior Effects 0.000 description 2
- 238000004422 calculation algorithm Methods 0.000 description 2
- 238000004364 calculation method Methods 0.000 description 2
- 238000013500 data storage Methods 0.000 description 2
- 101000827703 Homo sapiens Polyphosphoinositide phosphatase Proteins 0.000 description 1
- 102100023591 Polyphosphoinositide phosphatase Human genes 0.000 description 1
- 101100012902 Saccharomyces cerevisiae (strain ATCC 204508 / S288c) FIG2 gene Proteins 0.000 description 1
- 101100233916 Saccharomyces cerevisiae (strain ATCC 204508 / S288c) KAR5 gene Proteins 0.000 description 1
- 230000001133 acceleration Effects 0.000 description 1
- 238000013473 artificial intelligence Methods 0.000 description 1
- 230000001174 ascending effect Effects 0.000 description 1
- 230000005540 biological transmission Effects 0.000 description 1
- 238000006243 chemical reaction Methods 0.000 description 1
- 238000012790 confirmation Methods 0.000 description 1
- 238000001514 detection method Methods 0.000 description 1
- 238000007599 discharging Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 238000004806 packaging method and process Methods 0.000 description 1
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L41/00—Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
- H04L41/06—Management of faults, events, alarms or notifications
- H04L41/0654—Management of faults, events, alarms or notifications using network fault recovery
- H04L41/0663—Performing the actions predefined by failover planning, e.g. switching to standby network elements
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/10—Protocols in which an application is distributed across nodes in the network
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Definitions
- the present application relates to the field of blockchain technology, and specifically to a node selection method, device, first node, storage medium and program product.
- Blockchain refers to a chain composed of blocks. Each block stores information. They are connected into a chain in the order of their generation, and this chain is stored in all nodes in the blockchain.
- consensus mechanisms are adopted in blockchain, including proof-of-work, proof-of-stake, and delegated proof-of-stake.
- consensus nodes need to be selected to package and verify blocks.
- the current method of selecting consensus nodes makes the stability of the blockchain network poor.
- the embodiments of the present application provide a node selection method, device, first node, storage medium and program product, which can enhance the stability of the blockchain network.
- the present application provides a node selection method, including:
- the non-candidate consensus nodes in the target node group are stored in the initial node group, where the initial node group is a group in the multiple node groups other than the target node group and matching the target node group;
- the above initial node group is used as the above target node group, and the execution from the above target node is returned.
- the candidate consensus node will be used as the target consensus node of the blockchain.
- an embodiment of the present application provides a node selection device, comprising:
- An acquisition module is configured to acquire the attribute weight corresponding to each node in the blockchain, and group each node in order of the attribute weight to obtain multiple node groups;
- a screening module is configured to screen out a node group whose attribute weights meet a preset condition from the above-mentioned multiple node groups, obtain a target node group, and screen out a preset number of candidate consensus nodes from the above-mentioned target node group;
- a storage module configured to store the non-candidate consensus nodes in the target node group into an initial node group, where the initial node group is a group in the multiple node groups other than the target node group and matching the target node group;
- a return module is configured to use the initial node group as the target node group, and return to execute the step of screening candidate consensus nodes from the target node group until the screening of all node groups in the multiple node groups is completed;
- a verification module configured to broadcast the candidate consensus node to the second node among the above nodes for verification
- the candidate consensus node As a module, it is configured to use the candidate consensus node as the target consensus node of the blockchain if the verification information of the candidate consensus node is received from the second node within a preset time.
- the acquisition module is specifically configured to execute:
- the above sorting queue is divided into multiple node groups.
- the storage module is specifically configured to execute:
- the non-candidate consensus nodes in the above target node group are stored in the above initial node group.
- the node group includes a first preset number of nodes. Accordingly, the screening module is specifically configured to execute:
- a preset number of candidate consensus nodes are selected from the target node group.
- the screening module is specifically configured to execute:
- the preset number is used as the target number of random numbers corresponding to the target node group
- a random number of the target number corresponding to the target node group is generated.
- the screening module is specifically configured to execute:
- the node corresponding to the above node serial number is used as the candidate consensus node corresponding to the above target node group.
- the verification module is specifically configured to execute:
- the Merkle root is broadcasted to the second node among the above nodes for verification.
- the acquisition module is specifically configured to execute:
- the attribute weight corresponding to the node is determined.
- the acquisition module is specifically configured to execute:
- the above information weight is adjusted according to the above adjustment coefficient to obtain the adjusted information weight
- the attribute weights corresponding to the nodes are determined.
- the node selection device also includes:
- Block storage module configured to execute:
- the above-mentioned block to be verified will be stored in the above-mentioned blockchain.
- the block storage module is specifically configured to execute:
- the block to be verified will be broadcast to the non-consensus nodes in the blockchain for verification;
- the above-mentioned block to be verified will be stored in the above-mentioned blockchain.
- an embodiment of the present application also provides a first node, including a processor and a memory, the memory stores a computer program, and the processor is used to run the computer program in the memory to implement the node selection method provided in the embodiment of the present application.
- an embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and the computer program is suitable for loading by a processor to execute any node selection method provided in the embodiment of the present application.
- an embodiment of the present application also provides a computer program product, including a computer program, and when the computer program is executed by a processor, any node selection method provided in the embodiment of the present application is implemented.
- the target node group whose attribute weight meets the preset conditions can be Considering that the node group has a larger attribute weight and the initial node group is a group among multiple node groups other than the target node group and matching the target node group, therefore, storing the non-candidate consensus nodes in the target node group into the initial node group to participate in the screening again can increase the number of screening times of the nodes with larger attribute weights among multiple nodes, thereby increasing the probability of the nodes with larger attribute weights among multiple nodes being screened as candidate consensus nodes.
- the candidate consensus nodes screened out from the target node group may be nodes with larger attribute weights in the target node group, or may be nodes with smaller attribute weights in the target node group
- the candidate consensus nodes screened out from the initial node group may also be nodes with larger attribute weights in the initial node group, or may be nodes with smaller attribute weights in the initial node group. Therefore, when the screening is completed, the candidate consensus nodes obtained may be nodes with larger attribute weights among multiple nodes, or may be nodes with smaller attribute weights among multiple nodes. This can not only provide a higher probability of being selected for nodes with larger attribute weights, but also provide nodes with smaller attribute weights with the opportunity to be selected, thereby improving the stability of the blockchain network.
- FIG1A is a schematic diagram of a data sharing system provided in an embodiment of the present application.
- FIG1B is a schematic diagram of a blockchain provided in an embodiment of the present application.
- FIG1C is a schematic diagram of a block generation process provided by an embodiment of the present application.
- FIG2 is a schematic diagram of a process flow of a node selection method provided in an embodiment of the present application.
- FIG3 is a schematic diagram of consensus node generation provided in an embodiment of the present application.
- FIG4 is a schematic diagram of attribute information provided in an embodiment of the present application.
- FIG5 is a schematic diagram of a node group provided in an embodiment of the present application.
- FIG6 is a schematic diagram of a candidate consensus node screening process provided in an embodiment of the present application.
- FIG7 is a schematic diagram of a calculation process of the Merkle root of a candidate consensus node provided in an embodiment of the present application.
- FIG8 is a schematic diagram of another blockchain provided in an embodiment of the present application.
- FIG9 is a schematic diagram of another block generation provided by an embodiment of the present application.
- FIG10 is a schematic diagram of another blockchain provided in an embodiment of the present application.
- FIG11 is a schematic diagram of another block generation provided in an embodiment of the present application.
- FIG12 is a schematic diagram of a flow chart of another node selection method provided in an embodiment of the present application.
- FIG13 is a schematic diagram of generation switching provided in an embodiment of the present application.
- FIG14 is a schematic diagram of a flow chart of another node selection method provided in an embodiment of the present application.
- FIG15 is a schematic diagram of the structure of a node selection device provided in an embodiment of the present application.
- FIG. 16 is a schematic diagram of the structure of the first node provided in an embodiment of the present application.
- the embodiment of the present application provides a node selection method, device, first node, storage medium and program product, wherein the storage medium can be a computer storage medium, and the program product can be a computer program product.
- the node selection device can be integrated in the first node, and the first node can be a server or a terminal.
- the server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, network acceleration services (Content Delivery Network, CDN), as well as big data and artificial intelligence platforms.
- cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, network acceleration services (Content Delivery Network, CDN), as well as big data and artificial intelligence platforms.
- CDN Network acceleration services
- the terminal may be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited thereto.
- the terminal and the server may be directly or indirectly connected via wired or wireless communication, which is not limited in the embodiments of the present application.
- the term “plurality” in the embodiments of the present application refers to two or more than two.
- the terms “first” and “second” in the embodiments of the present application are used to distinguish descriptions and should not be understood as implying relative importance.
- the data sharing system 100 refers to a system for sharing data between nodes.
- the data sharing system may include multiple nodes 101, and the multiple nodes 101 may refer to various clients in the data sharing system.
- Each node 101 may receive input information during normal operation, and maintain the shared data in the data sharing system based on the received input information.
- information connections may exist between each node in the data sharing system, and the nodes may communicate with each other through the above information connections.
- Information transmission For example, when any node in the data sharing system receives input information, other nodes in the data sharing system obtain the input information according to the consensus algorithm and store the input information as data in the shared data, so that the data stored on all nodes in the data sharing system are consistent.
- Each node in the data sharing system has a node identifier corresponding to it, and each node in the data sharing system can store the node identifiers of other nodes in the data sharing system, so that the generated blocks can be broadcast to other nodes in the data sharing system according to the node identifiers of other nodes.
- a node identifier list as shown in the following table can be maintained in each node, and the node name and node identifier are stored in the node identifier list accordingly.
- the node identifier can be the Internet Protocol (IP) address of the interconnection protocol between networks and any other information that can be used to identify the node. Table 1 only takes the IP address as an example for explanation.
- IP Internet Protocol
- Each node in the data sharing system stores an identical blockchain.
- the blockchain consists of multiple blocks. See Figure 1B.
- the blockchain consists of multiple blocks.
- the genesis block includes a block header and a block body.
- the block header stores input information feature values, version numbers, timestamps, and difficulty values, and the block body stores input information.
- the next block of the genesis block uses the genesis block as the parent block.
- the next block also includes a block header and a block body.
- the block header stores the input information feature values of the current block, the block header feature values, version numbers, timestamps, and difficulty values of the parent block, and so on.
- the block data stored in each block in the blockchain is associated with the block data stored in the parent block, ensuring the security of the input information in the block.
- SHA256 is the eigenvalue algorithm used to calculate the eigenvalue
- the version number (version) is the version information of the relevant block protocol in the blockchain
- prev_hash is the block header eigenvalue of the parent block of the current block
- merkle_root is the eigenvalue of the input information
- ntime is the update time of the update timestamp
- nbits is the current difficulty, which is a fixed value within a period of time and is determined again after exceeding the fixed time period
- x is a random number
- TARGET is the eigenvalue threshold, which can be determined according to nbits.
- the information can be stored accordingly.
- the node where the blockchain is located sends the newly generated block to other nodes in the data sharing system according to the node identification of other nodes in the data sharing system.
- Other nodes verify the newly generated block and add the newly generated block to the blockchain stored in them after the verification is completed.
- the description will be made from the perspective of the node selection device.
- the node selection device will be integrated into the first node for detailed description, that is, the first node will be used as the execution subject for detailed description.
- the node selection method may include:
- the first node may be any node among the nodes, that is, the embodiment of the present application may be executed by any node in the blockchain.
- the attribute weight indicates the contribution of a node in the blockchain, and the contribution can be the attribute information of the node.
- the attribute information of a node may include the node's pledged assets or the number of votes the node has received.
- determining the attribute weight of a node based on the node's pledged assets and the number of votes the node has received requires that the user corresponding to the node first invest assets before participating in the consensus, which reduces the participation of the user corresponding to the node.
- determining the attribute weight of a node based solely on the pledged assets without considering other factors will be lacking in terms of the distribution and coverage of the entire blockchain network scale, which is not conducive to the stability of the entire blockchain network.
- the nodes of the blockchain become proposers by staking assets. If the assets pledged by the node meet the requirements, the node can become a candidate to participate in the election. If the election is successful, the node successfully verifies the person and becomes a consensus node.
- the attribute information of a node may include the total number of blocks produced, the total number of blocks produced in the previous generation (generation refers to the period in which the role conversion is truly effective), voting maliciously (for blocks of the same height, each node is only allowed to vote once in favor, that is, it cannot vote in favor of multiple blocks of the same height.
- a node If a node does so, it indicates that the node voted maliciously), acting maliciously as a master node (the master node is a consensus node that generates blocks), identity authentication, and at least one of geographic location, so that when the attribute weight of a node is determined based on the attribute information of the node, it is not necessary to determine the attribute weight of the node based on the pledged assets and the number of votes of the node, and when the attribute weight of a node is determined based on multiple attribute information of the node, it is possible to consider the attribute weight of the node from multiple angles, so that when a consensus node is selected based on the attribute weight, the probability of a malicious node being selected as a consensus node can be reduced, thereby reducing the probability of errors in consensus nodes during the consensus process and improving the stability of the blockchain network.
- the stability of the blockchain network refers to the probability of errors occurring in consensus nodes during the consensus process. Within the error range, the blockchain network can still operate normally.
- obtaining the attribute weights corresponding to each node in the blockchain includes: obtaining multiple attribute information corresponding to each node in the blockchain; and determining the attribute weight corresponding to the node according to the information weight corresponding to the attribute information.
- the attribute weight corresponding to the node is determined by the information weights corresponding to multiple attribute information, and multiple factors are fully considered to further improve the stability of the entire blockchain network.
- the first node may directly add the information weights corresponding to the attribute information to obtain the attribute weights corresponding to the node.
- the first node may obtain the adjustment coefficient corresponding to each information weight, and then adjust the information weight according to the adjustment coefficient to obtain the adjusted information weight, and finally add the adjusted information weights to obtain the attribute weights corresponding to each node.
- the information weight corresponding to each attribute information in each process of selecting a consensus node, may be the same, or the information weight corresponding to each attribute information may be different in different processes of selecting a consensus node.
- the information weight corresponding to the attribute information it can be determined based on the behavior information of the node of the attribute information in the blockchain network.
- the attribute information may be voting maliciously, and the information weight corresponding to voting maliciously may be a negative weight. If node n1 voted maliciously multiple times in the previous generation, then in the current node selection process, the information weight corresponding to voting maliciously may be increased according to a set ratio (e.g., 5%).
- a set ratio e.g., 5%
- the first node may group each node according to the order of the attribute weights to obtain multiple node groups.
- the first node may obtain multiple preset weight intervals, and then store nodes corresponding to attribute weights belonging to the same preset weight interval into the same node group, so as to store nodes with larger attribute weights into the same node group.
- the first node may also sort the nodes in order of attribute weights to obtain a sorted queue, and then divide the sorted queue into multiple node groups.
- the sorting may be descending or ascending, and the division may be an average division or division according to a preset value.
- each node includes node n1, node n2, ... and node nz
- the first node is node n1
- the sorting queue can be as shown in Figure 5
- the node groups that can be obtained can be as shown in Figure 5.
- the first node may obtain the attribute weights corresponding to each node in the blockchain, and group each node in order of the attribute weights to obtain multiple node groups. Alternatively, the first node may also obtain the attribute weights corresponding to each node in the blockchain when receiving a selection instruction. This embodiment of the present application is not limited here.
- S202 Filter out a node group whose attribute weights meet preset conditions from multiple node groups to obtain a target node group, and filter out a preset number of candidate consensus nodes from the target node group.
- the node group whose attribute weight meets the preset condition may refer to the node group with the larger attribute weight in the node group.
- the node group with the second largest attribute weight in the node group may be used as the target node group, or the node group with the largest attribute weight in the node group may be used as the target node group.
- the first node may first determine the attribute weight of the node group according to the attribute weight of each node in the node group, and then compare the attribute weights of the node groups to obtain the node group with the largest attribute weight among the node groups.
- the first node may also compare the maximum attribute weight of the nodes in one node group with the minimum attribute weight of the nodes in another node group. If the maximum attribute weight is less than the minimum attribute weight, it indicates that the attribute weight of the node group corresponding to the minimum attribute weight is greater than the attribute weight of the other node group.
- the node group in the front order can be directly used as the target node group.
- the node group g1 is directly used as the target node group.
- the first node can screen out a preset number of candidate consensus nodes from the target node group.
- the candidate consensus nodes can be nodes with larger attribute weights in the target node group, that is, multiple nodes starting from the head in descending order of attribute weights, or the candidate consensus nodes can also be multiple nodes with smaller attribute weights in the target node group, that is, multiple nodes starting from the tail in descending order of attribute weights.
- the candidate consensus nodes are node n1 and node n2, and the non-candidate consensus node is node n3. Since the attribute weight of node n1 is greater than the attribute weight of node n2, and the attribute weight of node n2 is greater than the attribute weight of node n3, at this time, the candidate consensus node selected is the node with a larger attribute weight.
- the first node can obtain a preset threshold of the target node group, and then use the nodes corresponding to the attribute weights greater than the preset threshold as candidate consensus nodes, or the first node can also use the nodes corresponding to the attribute weights less than the preset threshold as candidate consensus nodes.
- the preset threshold corresponding to each target node group is different, and each target node group may use the nodes corresponding to the attribute weights greater than the preset threshold as candidate consensus nodes or the nodes corresponding to the attribute weights less than the preset threshold as candidate consensus nodes. It can also be different, so that the candidate consensus node is a node with a larger attribute weight in the target node group or a node with a smaller attribute weight in the target node group.
- node group g1 and node group g2 corresponds to the preset threshold t1
- node group g2 corresponds to the preset threshold t2.
- node group g1 is used as the target node group
- the nodes corresponding to the attribute weights greater than the preset threshold t1 can be used as candidate consensus nodes.
- node group g2 is used as the target node group
- the nodes corresponding to the attribute weights less than the preset threshold t2 can be used as candidate consensus nodes.
- the first node may also randomly select a preset number of candidate consensus nodes from the target node group, so that the candidate consensus nodes are nodes with larger attribute weights in the target node group or nodes with smaller attribute weights in the target node group.
- the method of randomly selecting a preset number of candidate consensus nodes from the target node group can be selected according to the actual situation. For example, a preset number of candidate consensus nodes can be selected from the target node group through a random function.
- the number of candidate consensus nodes, the random function may be a verifiable random function (VRF) random function or a pseudo-random function, which is not limited in the embodiments of the present application.
- VRF verifiable random function
- the preset number of candidate consensus nodes are screened out from the target node group, including: determining a random number corresponding to the target node group according to a first preset number and a preset number; and randomly screening out a preset number of candidate consensus nodes from the target node group according to the random number.
- the first node may determine the probability of each preset value according to the first preset number and the preset number through a random function, and then use the preset value with the largest probability as the random number corresponding to the target node group.
- the first node may also use a random function to take a preset number as the target number of random numbers corresponding to the target node group, and then generate the target number of random numbers corresponding to the target node group within the first preset number, that is, the value of the random number is less than or equal to the first preset number, and greater than or equal to 0.
- the preset number represents the number of random numbers
- the first preset number represents the numerical interval in which the random number is located.
- the first preset number is 3 and the preset number is 2, which means that two random numbers are generated in [0, 3].
- the first node After obtaining the random number, the first node selects a preset number of candidate consensus nodes from the target node group based on the random number.
- the first node can use the random number as the node serial number in the target node group, and then use the node corresponding to the node serial number as the candidate consensus node corresponding to the target node group.
- node n1 and node n2 are used as candidate consensus nodes corresponding to the target node group.
- a random number is used as a node serial number in a target node group, and then the node corresponding to the node serial number is used as a candidate consensus node corresponding to the target node group, thereby randomly screening out candidate consensus nodes from the target node group, so that the candidate consensus node is a node with a larger attribute weight in the target node group or a node with a smaller attribute weight in the target node group.
- Node groups other than the target node group in the multiple node groups may become candidate node groups.
- the multiple node groups may be as shown in FIG. 6
- the target node group is g1
- the candidate node groups may include node group g2, node group g3, ..., and node group gm, etc.
- the initial node group is a group among multiple node groups that is excluding the target node group and matches the target node group. It can be understood as a node group among the candidate node groups that also meets the preset conditions as the target node group. For example, if the target node group is the node group with the largest attribute weight among the node groups, then the initial node group can be understood as the node group with the largest attribute weight among the candidate node groups.
- the non-candidate consensus node in the target node group can be stored in the initial In the node group, the candidate consensus nodes are then screened out from the initial node group, so that nodes with larger attribute weights participate in multiple screenings, thereby increasing the probability that nodes with larger attribute weights are selected as candidate consensus nodes.
- each node group can be as shown in Figure 6, the target node group is node group g1, the initial node group is node group g2, the candidate consensus nodes corresponding to the target node group are node n1 and node n2, and the non-candidate consensus node in the target node group is node n3, then node n3 is stored in node group g2.
- node group g2 can be as shown in Figure 6.
- the non-candidate consensus nodes in the target node group are stored in the initial node group, including:
- the first node after obtaining each node group, the first node directly uses the node group g1 ranked first as the target node group.
- node group g2 is a node group with an attribute weight less than that of node group g2 and adjacent to node group g2
- node group g2 is used as the initial node group, and the non-candidate consensus node n3 of node group g1 is stored in node group g2.
- the node group ranked first can be used as the initial node group. For example, as shown in FIG6 , after obtaining the candidate consensus nodes and non-candidate consensus nodes of node group g1, node group g1 does not exist. At this time, node group g2 is ranked first, and the first node can still use the first node group g2 as the initial node group.
- S204 Take the initial node group as the target node group, and return to execute the step of screening out candidate consensus nodes from the target node group until the screening of all node groups in the multiple node groups is completed.
- the first node After obtaining the initial node group, uses the initial node group as the target node group and returns to execute the step of screening candidate consensus nodes from the target node group until the screening of all node groups in the multiple node groups is completed.
- the first node selects the node group g1 with the largest attribute weight in the node group as the target node group, and then selects nodes n1 and n2 from the target node group as candidate consensus nodes, and node n3 as a non-candidate consensus node.
- the first node selects the node group g2 with the largest attribute weight in the candidate node group as the initial node group, and stores the node n3 in the node group g2. Then, the first node selects nodes n4 and n5 from the node group g2 as candidate consensus nodes, and nodes n3 and n6 as non-candidate consensus nodes.
- the first node uses the node group g3 with the largest attribute weight in the candidate node group as the initial node group, and stores the nodes n3 and n6 in the node group g3, and then continues to screen out candidate consensus nodes and non-candidate consensus nodes from the node group g3, repeating the process until the candidate consensus nodes are screened out from the node group gm, and the selection of candidate consensus nodes is stopped.
- the number of times the step of selecting candidate consensus nodes from the target node group is performed can be determined based on the number of node groups. For example, when the number of node groups is m, it indicates that the first node repeats the step of selecting candidate consensus nodes from the target node group m times.
- the candidate consensus nodes filtered out from the initial node group may be nodes with larger attribute weights in the initial node group, or may be nodes with smaller attribute weights in the initial node group.
- the first node selects the node group g1 with the largest attribute weight in the node group as the target node group, and then selects nodes n1 and n2 from the target node group as candidate consensus nodes, and node n3 as a non-candidate consensus node.
- the node with a larger attribute weight in the target node group is used as a candidate consensus node.
- the first node selects the node group g2 with the largest attribute weight in the candidate node group as the initial node group, and stores the node n3 in the node group g2. Then, the first node selects nodes n4 and n5 from the node group g2 as candidate consensus nodes, and nodes n3 and n6 as non-candidate consensus nodes.
- the nodes with smaller attribute weights in the initial node group are used as candidate consensus nodes.
- the number of nodes included in the initial node group changes.
- the first preset number may refer to the number of nodes included in the initial node group.
- a node can be a candidate consensus node or a non-candidate consensus node in different node groups.
- nodes n1 and n2 are used as candidate consensus nodes corresponding to node group g1
- node n3 is used as a non-candidate consensus node corresponding to node group g1.
- nodes n3 and n5 are used as candidate consensus nodes corresponding to node group g2. That is, in node group g1, node n3 is a non-candidate consensus node, and in node group g2, node n3 is a candidate consensus node.
- node n1 selects candidate consensus nodes from each node group
- node n2 also selects candidate consensus nodes from each node group.
- Node n1 and node n2 are both called first nodes.
- node n1 selects candidate consensus nodes from each node group, if it receives the candidate consensus node broadcast by node n2, node n1 is called a second node.
- node n2 selects candidate consensus nodes from each node group, if it receives the candidate consensus node broadcast by node n1, node n2 is called a second node.
- the first node After obtaining a candidate consensus node of a target node group, the first node can first The first node may broadcast the candidate consensus nodes of the target node group, that is, after the first node selects a preset number of candidate consensus nodes from the target node group, first execute step S205 and then execute step S203. Alternatively, the first node may also broadcast all the candidate consensus nodes after obtaining the candidate consensus nodes of all node groups, that is, after the first node selects a preset number of candidate consensus nodes from the target node group, first execute steps S203 and step 204 and then execute step S205.
- the embodiment of the present application is not limited here.
- Broadcasting the candidate consensus node to the second node among each node for verification can be understood as broadcasting the identifier corresponding to the candidate consensus node to the second node among each node for verification.
- the identifier of the candidate consensus node can be mapped first to obtain the mapping result, and then the mapping result can be broadcast to the second node among each node for verification.
- the identifiers of the candidate consensus nodes are mapped to obtain a mapping result, and then the mapping result is broadcasted to the second node in each node for verification
- the identifiers of multiple candidate consensus nodes can be spliced to obtain a spliced identifier, and then the spliced identifier is hash mapped to obtain the mapping result.
- the identifiers of each candidate consensus node can be hash mapped separately to obtain a sub-mapping result of each candidate consensus node, and then the mapping result is determined according to the sub-mapping result of each candidate consensus node.
- the candidate consensus node is broadcast to the second node in each node for verification, including:
- the Merkle root is broadcast to the second node among all nodes for verification.
- Merkle root refers to the hash value obtained by hashing each object separately and then adding the hash results of each object or the hash value obtained by hashing the hash results of each object again.
- the object can be a transaction, or the object can also be a node.
- the process of calculating the Merkle root of the candidate consensus node can be: the first node first hashes each candidate consensus node separately to obtain the hash value corresponding to each candidate consensus node, and then hashes the hash value of the adjacent candidate consensus node again to obtain the candidate hash value. If the candidate hash value is not one, the adjacent candidate hash value is hashed again until the candidate hash value obtained is one, and the candidate hash value is used as the Merkle root of the candidate consensus node.
- the candidate consensus nodes include node n1, node n2, node n3, node n4, node n5, node n6, node n7 and node n8.
- Nodes n1-n8 are hashed respectively to obtain hash values corresponding to nodes n1-n8, and then the hash value of node n1 and the hash value of node n2 are hashed again to obtain candidate hash value 12, the hash value of node n3 and the hash value of node n4 are hashed again to obtain candidate hash value 34, the hash value of node n5 and the hash value of node n6 are hashed again to obtain candidate hash value 56, and the hash value of node n7 and the hash value of node n8 are hashed again to obtain candidate hash value 78.
- the Merkle root of the candidate consensus node is broadcasted, thereby simplifying the complexity of message communication between nodes. Moreover, when broadcasting the Merkle root, only the Merkle root of the candidate consensus node is broadcasted, and there is no need to broadcast the Merkle root of all nodes, thereby further simplifying the complexity of message communication between nodes.
- the consensus nodes of blockchains in different generations are different. Taking candidate consensus nodes as the target consensus nodes of blockchains can be understood as taking candidate consensus nodes as the target consensus nodes of the next generation of blockchains.
- the second node After receiving the candidate consensus node, the second node can compare the candidate consensus node with the candidate consensus node screened by the second node from the node group. If the comparison result is the same, the verification of the candidate consensus node is passed; if the comparison result is different, the verification of the candidate consensus node is failed.
- the second node receives a Merkle root
- the received Merkle root is compared with the Merkle root calculated by the second node. If the comparison results are the same, the verification of the candidate consensus node is passed. If the comparison results are different, the verification of the candidate consensus node fails.
- the first node When the first node first broadcasts a candidate consensus node of a target node group, the first node can receive the verification information of the candidate consensus node from the second node within a preset time, and after using the candidate consensus node as the target consensus node of the blockchain, the non-candidate consensus nodes of the target node group are stored in the initial node group, and the initial node group is used as the target node group, and the step of filtering out the candidate consensus nodes from the target node group is returned.
- the first node may also broadcast the candidate consensus nodes of a target node group while storing the non-candidate consensus nodes of the target node group to the initial node group, and use the initial node group as the target node group, and return to execute the step of screening out the candidate consensus nodes from the target node group.
- the embodiments of the present application are not limited here.
- the first node may also use the candidate consensus node as the target consensus node of the blockchain only when the number of verification pass information received for the candidate consensus node within the preset time meets the preset number.
- the preset number is 3, node n1 broadcasts the candidate consensus node to node n2, node n3, node n4 and node n5 for verification, and receives the verification information of the candidate consensus node from node n2, node n3 and node n4 within the preset time. Since the verification information of the candidate consensus node is received from 3 nodes within the preset time, the candidate consensus node is used as the target consensus node of the blockchain.
- the second node does not receive the candidate consensus node within the preset time, If the information is verified, the candidate consensus node will not be used as the target consensus node of the blockchain. At this time, it may be because the attribute information of the node contained in the memory of the first node is inconsistent with the attribute information of the node contained in the memory of other nodes.
- the first node can obtain the attribute information of each node from other nodes through the state synchronization method, and then select the candidate consensus node again, that is, execute steps S201-S206 again.
- transactions can be packaged into blocks to be verified and verified through each target consensus node. If the target consensus node passes the verification of the block to be verified, the block to be verified will be broadcasted in the blockchain, so that the non-consensus nodes and the target consensus nodes in the blockchain will store the block to be verified on the blockchain stored by themselves.
- the blockchain can be shown in Figure 8, where nodes n1, n2, n3 and n4 are target consensus nodes in the blockchain, and nodes n5, n6, n7, n8, n9, n10, n11 and n12 are non-consensus nodes in the blockchain.
- the solid line indicates that the node can participate in the consensus
- the dotted line indicates that the node only synchronizes the blocks to be verified, passively receives the blocks, and cannot participate in the consensus.
- the process of packaging transactions into blocks to be verified and verifying the blocks to be verified by each target consensus node is as follows:
- a target consensus node is selected from the target consensus nodes as the master node to package the transaction into a block to be verified, and the block to be verified is sent to other consensus nodes in the target consensus node.
- the other consensus nodes in the target consensus node are the target consensus results of the target consensus node except the master node. Then the other consensus nodes in the target consensus node verify the block to be verified. If the verification of the block to be verified by other consensus nodes is passed, the master node broadcasts the block to be verified in the blockchain, so that the non-consensus nodes in the blockchain can store the block to be verified on the blockchain stored by itself, and the target consensus node in the blockchain can store the block to be verified on the blockchain stored by itself.
- the first node when the first node is the master node, after taking the candidate consensus node as the target consensus node of the blockchain, it also includes:
- the block to be verified will be stored in the blockchain.
- the first node can obtain the current transaction data and then package the current transaction data into a block to be verified. If the consensus on the block to be verified is passed, the block to be verified is stored in the blockchain stored by the first node, and the block to be verified is broadcasted in the blockchain at the same time, so that other nodes in the blockchain can store the block to be verified in the blockchain stored by themselves.
- blocks are generated and verified by each target consensus node in the blockchain, thereby reducing the number of nodes that generate blocks and verify blocks, thereby reducing communication complexity and improving consensus efficiency.
- the block to be verified will be stored in the blockchain, including:
- the block to be verified will be broadcast to the non-consensus nodes in the blockchain for verification;
- the block to be verified will be stored in the blockchain.
- the master node After the master node generates a block to be verified, it sends the block to be verified to other consensus nodes for verification. If other consensus nodes pass the verification of the block to be verified, the block to be verified will be broadcast in the blockchain. If the number of non-consensus nodes that pass the verification of the block to be verified meets the preset number requirement, the block to be verified will be stored in the blockchain.
- the target consensus node will broadcast the block to be verified in the blockchain, so that the non-consensus nodes receive the block to be verified.
- Each non-consensus node will vote on the block after receiving it.
- the confirmation of a block to be verified is based on the approval votes of the majority of non-consensus nodes.
- the block to be verified is recognized, which is called the commit stage.
- the blockchain can be as shown in Figure 10, node n1, node n2, node n3 and node n4 are target consensus nodes in the blockchain, node n5, node n6, node n7, node n8, node n9, node n10, node n11, and node n12 are non-consensus nodes in the blockchain, and the solid line indicates that the node can participate in the consensus, that is, it indicates that non-consensus nodes can also participate in the consensus.
- the block to be verified when the target consensus node passes the consensus on the block to be verified, the block to be verified is not immediately stored in the blockchain. Instead, the block to be verified is verified by the non-consensus nodes in the blockchain. When the number of non-consensus nodes that have passed the verification of the block to be verified meets the preset number requirement, the block to be verified is stored in the blockchain, so that the non-consensus nodes in the blockchain can also participate in the consensus process, thereby reducing the degree of centralization.
- the block to be verified is stored in the blockchain, including:
- the block to be verified will be stored in the blockchain.
- blocks will be voted for and against. As long as the number of votes against reaches the requirement, it means that the block cannot be agreed upon. For a consensus node, it must detect whether the previous block of the block it generated received enough votes in favor. If the previous block is agreed upon, the block to be verified will be stored in the blockchain.
- the consensus node needs to take over the responsibility of the consensus node that generated the previous block and generate the previous block. At this time, if the number of non-consensus nodes that have passed the verification of the block to be verified meets the preset number requirement, after obtaining the previous block of the block to be verified, it also includes:
- a previous block is generated and used as the block to be verified
- block 2 is the current block.
- node n2 finds that the number of non-consensus nodes that have passed the verification of block 1 does not meet the preset number requirement. Then node n2 generates block 1' and generates block 2' through node n3.
- the attribute weights corresponding to each node in the blockchain are obtained, and each node is grouped in order of the size of the attribute weight to obtain multiple node groups, and the node group whose attribute weight meets the preset conditions is screened out from the multiple node groups to obtain the target node group, and a preset number of candidate consensus nodes are screened out from the target node group, and the non-candidate consensus nodes in the target node group are stored in the initial node group.
- the initial node group is a group in the multiple node groups other than the target node group and matching the target node group.
- the initial node group is used as the target node group, and the step of screening out candidate consensus nodes from the target node group is returned until the screening of all node groups in the multiple node groups is completed; the candidate consensus node is broadcast to the second node among each node for verification; if the verification pass information of the candidate consensus node is received from the second node within the preset time, the candidate consensus node is used as the target consensus node of the blockchain.
- the nodes are grouped in order of the size of the attribute weights, the node group whose attribute weights meet the preset conditions is taken as the target node group, and the candidate consensus nodes are screened out from the target node group.
- the candidate consensus nodes screened out from the target node group may be nodes with larger attribute weights in the target node group, or may be nodes with smaller attribute weights in the target node group.
- the non-candidate consensus nodes in the target node group are stored in the initial node group, and the candidate consensus nodes are continuously screened out from the initial node group.
- the candidate consensus nodes screened out from the initial node group may be nodes with larger attribute weights in the initial node group, or may be nodes with smaller attribute weights in the initial node group.
- the target node group whose attribute weights meet the preset conditions can be, for example, a node group with a larger attribute weight
- the initial node group is a group among multiple node groups other than the target node group and matching the target node group, therefore, storing the non-candidate consensus nodes in the target node group into the initial node group to participate in screening again can increase the number of screening times of nodes with larger attribute weights among multiple nodes, thereby increasing the probability of nodes with larger attribute weights among multiple nodes being screened as candidate consensus nodes.
- the candidate consensus nodes selected from the target node group may be nodes with larger attribute weights or nodes with smaller attribute weights in the target node group
- the candidate consensus nodes selected from the initial node group may be nodes with larger attribute weights or nodes with smaller attribute weights in the initial node group
- the candidate consensus nodes obtained may be nodes with larger attribute weights or nodes with smaller attribute weights among multiple nodes. This can not only provide a higher probability of being selected for nodes with larger attribute weights, but also provide nodes with smaller attribute weights with a chance of being selected, reducing The probability of malicious nodes being selected as consensus nodes is reduced, thereby reducing the probability of errors in consensus nodes during the consensus process, thereby improving the stability of the blockchain network.
- the node selection method in the embodiment of the present application can be applied to the consensus node selection process in the blockchain.
- the node selection method in the embodiment of the present application is applied to the consensus node selection process in the DPoS consensus mechanism of the blockchain.
- the node selection method process may include:
- the first node detects that it is in the generation switching stage, it obtains multiple attribute information corresponding to each node in the blockchain, and determines the attribute weight corresponding to the node according to the information weight corresponding to the attribute information.
- the information of the consensus nodes of the next generation is usually confirmed in the last block of a generation, and the information of the consensus nodes of the next generation is stored in the blockchain.
- the number of consensus nodes will be larger, which makes the information of the consensus nodes of the next generation more, resulting in a larger block storing the information of the consensus nodes of the next generation.
- consensus nodes may deliberately do evil and choose themselves as candidate nodes for the next generation. This process does not involve other nodes, making it difficult to ensure security.
- the information of consensus nodes is not stored in the blockchain, but only recorded locally in the node, thereby reducing the size of the blockchain.
- generation k when generation k is received, it enters the generation switching stage. In the generation switching stage, a consensus node is selected and no blocks are generated. When the generation switching stage ends, blocks are generated starting from generation (k+1).
- the first node when the first node obtains the transaction data, it can detect whether it is in the generation switching stage. If it is in the generation switching stage, it obtains multiple attribute information corresponding to each node in the blockchain. If it is not in the generation switching stage, it determines whether the first node is the main node. As shown in Figure 14.
- the first node sorts each node in order of attribute weight to obtain a sorted queue, and evenly divides the sorted queue to obtain multiple node groups.
- the first node selects a node group with the largest attribute weight from multiple node groups, obtains a target node group, and obtains a preset number.
- the first node uses a preset number as the target number of random numbers corresponding to the target node group, and generates a target number of random numbers corresponding to the target node group within the first preset number through a random function.
- the first preset number is the number of nodes included in the target node group.
- the first node uses the random number as the node serial number in the target node group, and uses the node corresponding to the node serial number as the candidate consensus node corresponding to the target node group.
- the first node selects candidate node groups that are adjacent to the target node group and have attribute weights less than the target node group from the candidate node groups to obtain an initial node group that matches the target node group.
- the candidate node groups are node groups other than the target node group in the multiple node groups.
- the first node stores the non-candidate consensus nodes corresponding to the target node group into the initial node group, uses the initial node group as the target node group, and returns to execute step S1204.
- the first node calculates the Merkle root of the candidate consensus node, and broadcasts the Merkle root to the second node among each node for verification.
- S1209 The second node compares the received Merkle root with the Merkle root calculated by itself to obtain a comparison result.
- the first node will use the candidate consensus node as the target consensus node of the blockchain.
- the first node calculates and saves the block generation order of each target consensus node.
- the first node screens out candidate consensus nodes from the node group in the zeroth round, it can determine the seed of the random function according to the hash value (BlockHash) in the last block of the previous generation, and then obtain the random number of the target node group according to the random function. If the verification of the candidate consensus node in the zeroth round fails, then in the process of returning to execution, the seed of the random function can be determined according to the number of rounds (the number of rounds can be, for example, the zeroth round, the first round, the second round, etc., and when the random function is a VRF function, the number of rounds can refer to round) and the hash value in the last block of the previous generation.
- the number of rounds can be, for example, the zeroth round, the first round, the second round, etc., and when the random function is a VRF function, the number of rounds can refer to round
- the seed of the random function is determined according to the hash value (BlockHash) in the last block of the previous generation. Since the hash value in the last block of the previous generation cannot be predicted before the last block of the previous generation is generated, the randomness of the random number can be guaranteed.
- the target consensus node obtains the current transaction data and determines whether it is the master node based on the block generation order of the target consensus node.
- the master node If the target consensus node is the master node, the master node generates a block to be verified corresponding to the current transaction data.
- the master node sends the block to be verified to other consensus nodes, where the other consensus nodes are the consensus nodes in the target consensus nodes except the master node.
- the target consensus node when the target consensus node obtains the transaction data and determines that it is the master node of the current block, the target consensus node generates a block to be verified corresponding to the transaction data.
- the master node will broadcast the block to be verified to the non-consensus nodes in the blockchain for verification.
- the master node regenerates the block to be verified based on the transaction data of the previous block and returns to execute step S12016.
- the embodiment of the present application also provides a device based on the above node selection method.
- the meanings of the terms are the same as those in the above node selection method, and the specific implementation details can refer to the description in the method embodiment.
- the node selection device may include:
- the acquisition module 1501 is configured to obtain the attribute weight corresponding to each node in the blockchain, and group each node in order of the attribute weight to obtain multiple node groups.
- the screening module 1502 is configured to screen out a node group whose attribute weights meet a preset condition from multiple node groups, obtain a target node group, and screen out a preset number of candidate consensus nodes from the target node group.
- the storage module 1503 is configured to store the non-candidate consensus nodes in the target node group into the initial node group, where the initial node group is a group of multiple node groups other than the target node group and matching the target node group.
- Return module 1504 is configured to use the initial node group as the target node group, and return to execute the step of screening candidate consensus nodes from the target node group until the screening of all node groups in the multiple node groups is completed.
- the verification module 1505 is configured to broadcast the candidate consensus node to the second node among each node for verification.
- module 1506 it is configured to use the candidate consensus node as the target consensus node of the blockchain if the verification information of the candidate consensus node is received from the second node within a preset time.
- the acquisition module 1501 is specifically configured to execute:
- the sorting queue is divided into a plurality of node groups.
- the storage module 1503 is specifically configured to execute:
- the node group includes a first preset number of nodes. Accordingly, the screening module 1502 is specifically configured to execute:
- a preset number of candidate consensus nodes are selected from the target node group.
- the screening module 1502 is specifically configured to execute: taking the preset number as the target number of random numbers corresponding to the target node group; and generating the target number of random numbers corresponding to the target node group within the first preset number.
- the screening module 1502 is specifically configured to execute: using the random number as the node serial number in the target node group; using the node corresponding to the node serial number as the candidate consensus node corresponding to the target node group.
- the verification module 1505 is specifically configured to execute: calculating the Merkle root of the candidate consensus node; broadcasting the Merkle root to the second node among each node for verification.
- the acquisition module 1501 is specifically configured to execute: obtaining multiple attribute information corresponding to each node in the blockchain; and determining the attribute weight corresponding to the node according to the information weight corresponding to the attribute information.
- the acquisition module 1501 is specifically configured to execute: obtain the information weight corresponding to the attribute information, and obtain the adjustment coefficient corresponding to the information weight; adjust the information weight according to the adjustment coefficient to obtain the adjusted information weight; determine the attribute weight corresponding to the node according to the adjusted information weight.
- the node selection device also includes: a block storage module, configured to execute: obtaining the block to be verified, and reaching a consensus on the block to be verified through the target consensus node; if the consensus on the block to be verified is passed, the block to be verified is stored in the blockchain.
- the block storage module is specifically configured to execute: if the consensus on the block to be verified is passed, the block to be verified is broadcast to the non-consensus nodes in the blockchain for verification; if the number of non-consensus nodes that have passed the verification of the block to be verified meets the preset number requirement, the block to be verified is stored in the blockchain.
- the above modules can be implemented as independent entities, or can be arbitrarily combined to be implemented as the same or several entities.
- the specific implementation methods and corresponding beneficial effects of the above modules can be found in the previous method embodiments, which will not be repeated here.
- the embodiment of the present application further provides a first node, which may be a server or a terminal, etc.
- a first node which may be a server or a terminal, etc.
- FIG. 16 it shows a schematic diagram of the structure of the first node involved in the embodiment of the present application. Specifically:
- the first node may include components such as a processor 1601 of one or more processing cores, a memory 1602 of one or more computer-readable storage media, a power supply 1603, and an input unit 1604.
- a processor 1601 of one or more processing cores such as a central processing unit 1601, a central processing unit 162, and a central processing unit 1604.
- the processor 1601 is the control center of the first node, and uses various interfaces and lines to connect various parts of the entire first node, and executes various functions of the first node and processes data by running or executing computer programs and/or modules stored in the memory 1602, and calling data stored in the memory 1602.
- the processor 1601 may include one or more processing cores; preferably, The processor 1601 may integrate an application processor and a modem processor, wherein the application processor mainly processes an operating system, a user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the modem processor may not be integrated into the processor 1601.
- the memory 1602 can be used to store computer programs and modules.
- the processor 1601 executes various functional applications and data processing by running the computer programs and modules stored in the memory 1602.
- the memory 1602 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, a computer program required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the first node, etc.
- the memory 1602 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 1602 may also include a memory controller to provide the processor 1601 with access to the memory 1602.
- the first node also includes a power supply 1603 for supplying power to each component.
- the power supply 1603 can be logically connected to the processor 1601 through a power management system, so as to realize functions such as management of charging, discharging, and power consumption management through the power management system.
- the power supply 1603 can also include any components such as one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, and power status indicators.
- the first node may further include an input unit 1604, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.
- an input unit 1604 which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.
- the first node may also include a display unit, etc., which will not be described in detail here.
- the processor 1601 in the first node will load the executable file corresponding to the process of one or more computer programs into the memory 1602 according to the following instructions, and the processor 1601 will run the computer program stored in the memory 1602, so as to realize various functions, such as: obtaining the attribute weight corresponding to each node in the blockchain, and grouping each node in the order of the attribute weight to obtain multiple node groups; screening out the node group whose attribute weight meets the preset conditions from the multiple node groups to obtain the target node group, and screening out a preset number of candidate consensus nodes from the target node group; storing the non-candidate consensus nodes in the target node group to the initial node group, which is a group other than the target node group in the multiple node groups and matching the target node group; taking the initial node group as the target node group, and returning to execute the step
- an embodiment of the present application provides a computer-readable storage medium, in which a computer program is stored, and the computer program can be loaded by a processor to execute the steps in any node selection method provided in the embodiment of the present application.
- the computer program can execute the following steps:
- the non-candidate consensus nodes in the target node group are stored in the initial node group, where the initial node group is a group of node groups other than the target node group and matching the target node group;
- the initial node group is used as the target node group, and the step of screening candidate consensus nodes from the target node group is returned to be executed until the screening of all node groups in the multiple node groups is completed;
- the candidate consensus node will be used as the target consensus node of the blockchain.
- the computer readable storage medium may include: read-only memory (ROM), random access memory (RAM), disk or CD, etc.
- the computer program stored in the computer-readable storage medium can execute the steps in any node selection method provided in the embodiments of the present application, the beneficial effects that can be achieved by any node selection method provided in the embodiments of the present application can be achieved. Please refer to the previous embodiments for details and will not be repeated here.
- a computer program product or a computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium.
- a processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the above-mentioned node selection method.
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本申请实施例公开了一种节点选取方法、装置、第一节点、存储介质及程序产品;在本申请实施例中,按照区块链中各个节点的属性权重的大小顺序对各个节点进行分组,得到多个节点组;从多个节点组中筛选出属性权重满足预设条件的节点组,得到目标节点组,并从目标节点组中筛选出预设数量的候选共识节点;将目标节点组中非候选共识节点存储至初始节点组;将初始节点组作为目标节点组,并返回执行从目标节点组中筛选出候选共识节点的步骤;将候选共识节点广播至各个节点中的第二节点进行验证;若在预设时间内接收到第二节点对候选共识节点的验证通过信息,则将候选共识节点作为区块链的目标共识节点。
Description
相关申请的交叉引用
本申请基于申请号为202211530053.5、申请日为2022年11月30日的中国专利申请提出,并要求该中国专利申请的优先权,该中国专利申请的全部内容在此引入本申请作为参考。
本申请涉及区块链技术领域,具体涉及一种节点选取方法、装置、第一节点、存储介质及程序产品。
区块链,指由一个个区块组成的链条,每一个区块中保存了信息,它们按照各自产生的时间顺序连接成链条,这个链条被保存在区块链中所有的节点中。
为了去中心化,在区块链中采用了共识机制,共识机制包括工作量证明机制、权益证明机制以及委托权益证明机制等。在委托权益证明机制中,需要选取出共识节点去打包区块和验证区块。然而,目前,目前共识节点的选取方法使得区块链网络的稳定性较差。
发明内容
本申请实施例提供一种节点选取方法、装置、第一节点、存储介质及程序产品,可以增强区块链网络的稳定性。
本申请实施例提供一种节点选取方法,包括:
获取区块链中各个节点对应的属性权重,并按照属性权重的大小顺序对各个节点进行分组,得到多个节点组;
从上述多个节点组中筛选出属性权重满足预设条件的节点组,得到目标节点组,并从上述目标节点组中筛选出预设数量的候选共识节点;
将上述目标节点组中非候选共识节点存储至初始节点组,上述初始节点组为上述多个节点组中除了上述目标节点组之外的且与上述目标节点组匹配的组;
将上述初始节点组作为上述目标节点组,并返回执行从上述目标节点
组中筛选出候选共识节点的步骤,直至完成上述多个节点组中所有节点组的筛选;
将上述候选共识节点广播至各个上述节点中的第二节点进行验证;
若在预设时间内接收到上述第二节点对上述候选共识节点的验证通过信息,则将上述候选共识节点作为上述区块链的目标共识节点。
相应地,本申请实施例提供一种节点选取装置,包括:
获取模块,配置为获取区块链中各个节点对应的属性权重,并按照属性权重的大小顺序对各个节点进行分组,得到多个节点组;
筛选模块,配置为从上述多个节点组中筛选出属性权重满足预设条件的节点组,得到目标节点组,并从上述目标节点组中筛选出预设数量的候选共识节点;
存储模块,配置为将上述目标节点组中非候选共识节点存储至初始节点组,上述初始节点组为上述多个节点组中除了上述目标节点组之外的且与上述目标节点组匹配的组;
返回模块,配置为将上述初始节点组作为上述目标节点组,并返回执行从上述目标节点组中筛选出候选共识节点的步骤,直至完成上述多个节点组中所有节点组的筛选;
验证模块,配置为将上述候选共识节点广播至各个上述节点中的第二节点进行验证;
作为模块,配置为若在预设时间内接收到上述第二节点对上述候选共识节点的验证通过信息,则将上述候选共识节点作为上述区块链的目标共识节点。
上述方案中,获取模块具体配置为执行:
按照属性权重的大小顺序对各个节点进行排序,得到排序队列;
对上述排序队列划分为多个节点组。
上述方案中,存储模块具体配置为执行:
从候选节点组中筛选出与上述目标节点组相邻且属性权重小于上述目标节点组的候选节点组,得到与上述目标节点组匹配的初始节点组,上述候选节点组为多个节点组中除了目标节点组之外的节点组;
将上述目标节点组中非候选共识节点存储至上述初始节点组。
上述方案中,上述节点组中包括第一预设数量的节点。相应地,筛选模块具体配置为执行:
根据上述第一预设数量和上述预设数量,确定上述目标节点组对应的随机数;
根据上述随机数,从上述目标节点组中筛选出预设数量的候选共识节点。
上述方案中,筛选模块具体配置为执行:
将上述预设数量,作为上述目标节点组对应的随机数的目标数量;
在上述第一预设数量内,生成上述目标节点组对应的上述目标数量的随机数。
上述方案中,筛选模块具体配置为执行:
将上述随机数作为上述目标节点组中的节点序号;
将上述节点序号对应的节点,作为上述目标节点组对应的候选共识节点。
上述方案中,验证模块具体配置为执行:
计算上述候选共识节点的默尔克根;
将上述默尔克根广播至各个上述节点中的第二节点进行验证。
上述方案中,获取模块具体配置为执行:
获取区块链中每个节点对应的多个属性信息;
根据上述属性信息对应的信息权重,确定上述节点对应的属性权重。
上述方案中,获取模块具体配置为执行:
获取上述属性信息对应的信息权重,并获取上述信息权重对应的调整系数;
根据上述调整系数对上述信息权重进行调整,得到调整后信息权重;
根据上述调整后信息权重,确定上述节点对应的属性权重。
上述方案中,节点选取装置还包括:
区块存储模块,配置为执行:
获取待验证区块,并通过上述目标共识节点对上述待验证区块进行共识;
若对上述待验证区块的共识通过,则将上述待验证区块存储至上述区块链中。
上述方案中,区块存储模块具体配置为执行:
若对上述待验证区块的共识通过,则将上述待验证区块广播至上述区块链中非共识节点进行验证;
若对上述待验证区块的验证通过的非共识节点的数量满足预设数量要求,则将上述待验证区块存储至上述区块链中。
此外,本申请实施例还提供一种第一节点,包括处理器和存储器,上述存储器存储有计算机程序,上述处理器用于运行上述存储器内的计算机程序实现本申请实施例提供的节点选取方法。
此外,本申请实施例还提供一种计算机可读存储介质,上述计算机可读存储介质存储有计算机程序,上述计算机程序适于处理器进行加载,以执行本申请实施例所提供的任一种节点选取方法。
此外,本申请实施例还提供一种计算机程序产品,包括计算机程序,所述计算机程序被处理器执行时实现本申请实施例所提供的任一种节点选取方法。
在本申请实施例中,由于属性权重满足预设条件的目标节点组比如可
以为属性权重较大的节点组且初始节点组为多个节点组中除了目标节点组之外的且与目标节点组匹配的组,因此,将目标节点组中非候选共识节点存储至初始节点组中再次参与筛选,可以提高多个节点中属性权重较大的节点的筛选次数,从而提高多个节点中属性权重较大的节点被筛选为候选共识节点的概率。
因为从目标节点组中筛选出的候选共识节点可能为目标节点组中属性权重较大的节点,也可能为目标节点组中属性权重较小的节点,从初始节点组中筛选出的候选共识节点也可能为初始节点组中属性权重较大的节点,也可能为初始节点组中属性权重较小的节点,所以,当筛选完成时得到的候选共识节点可能为多个节点中属性权重较大的节点,也可能为多个节点中属性权重较小的节点,实现不但可以为属性权重较大的节点提供更高的被选中概率,而且也可以为属性权重较小的节点提供被选中的机会,从而提高区块链网络的稳定性。
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1A是本申请实施例提供的数据共享系统的示意图;
图1B是本申请实施例提供的区块链的示意图;
图1C是本申请实施例提供的区块产生过程的示意图;
图2是本申请实施例提供的节点选取方法的流程示意图;
图3是本申请实施例提供的共识节点产生的示意图;
图4是本申请实施例提供的属性信息的示意图;
图5是本申请实施例提供的节点组的示意图;
图6是本申请实施例提供的候选共识节点的筛选过程的示意图;
图7是本申请实施例提供的候选共识节点的默尔克根的计算过程的示意图;
图8是本申请实施例提供的另一种区块链的示意图;
图9是本申请实施例提供的另一种区块产生的示意图;
图10是本申请实施例提供的另一种区块链的示意图;
图11是本申请实施例提供的另一种区块产生的示意图;
图12是本申请实施例提供的另一种节点选取方法的流程示意图;
图13是本申请实施例提供的世代切换的示意图;
图14是本申请实施例提供的另一种节点选取方法的流程示意图;
图15是本申请实施例提供的节点选取装置的结构示意图;
图16是本申请实施例提供的第一节点的结构示意图。
为了使本申请的目的、技术方案和优点更加清楚,下面将结合附图对本申请作进一步地详细描述,所描述的实施例不应视为对本申请的限制,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其它实施例,都属于本申请保护的范围。
在以下的描述中,涉及到“一些实施例”,其描述了所有可能实施例的子集,但是可以理解,“一些实施例”可以是所有可能实施例的相同子集或不同子集,并且可以在不冲突的情况下相互结合。
除非另有定义,本文所使用的所有的技术和科学术语与属于本申请的技术领域的技术人员通常理解的含义相同。本文中所使用的术语只是为了描述本申请实施例的目的,不是旨在限制本申请。
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
本申请实施例提供一种节点选取方法、装置、第一节点、存储介质及程序产品,其中,存储介质可以为计算机存储介质,程序产品可以为计算机程序产品。该节点选取装置可以集成在第一节点中,该第一节点可以是服务器,也可以是终端等设备。
其中,服务器可以是独立的物理服务器,也可以是多个物理服务器构成的服务器集群或者分布式系统,还可以是提供云服务、云数据库、云计算、云函数、云存储、网络服务、云通信、中间件服务、域名服务、安全服务、网络加速服务(Content Delivery Network,CDN)、以及大数据和人工智能平台等基础云计算服务的云服务器。
终端可以是智能手机、平板电脑、笔记本电脑、台式计算机、智能音箱、智能手表等,但并不局限于此。终端以及服务器可以通过有线或无线通信方式进行直接或间接地连接,本申请实施例在此不做限制。
另外,本申请实施例中的“多个”指两个或两个以上。本申请实施例中的“第一”和“第二”等用于区分描述,而不能理解为暗示相对重要性。
参见图1A所示的数据共享系统,数据共享系统100是指用于进行节点与节点之间数据共享的系统,该数据共享系统中可以包括多个节点101,多个节点101可以是指数据共享系统中各个客户端。每个节点101在进行正常工作可以接收到输入信息,并基于接收到的输入信息维护该数据共享系统内的共享数据。为了保证数据共享系统内的信息互通,数据共享系统中的每个节点之间可以存在信息连接,节点之间可以通过上述信息连接进行
信息传输。例如,当数据共享系统中的任意节点接收到输入信息时,数据共享系统中的其他节点便根据共识算法获取该输入信息,将该输入信息作为共享数据中的数据进行存储,使得数据共享系统中全部节点上存储的数据均一致。
对于数据共享系统中的每个节点,均具有与其对应的节点标识,而且数据共享系统中的每个节点均可以存储有数据共享系统中其他节点的节点标识,以便后续根据其他节点的节点标识,将生成的区块广播至数据共享系统中的其他节点。每个节点中可维护一个如下表所示的节点标识列表,将节点名称和节点标识对应存储至该节点标识列表中。其中,节点标识可为网络之间互联的协议(Internet Protocol,IP)地址以及其他任一种能够用于标识该节点的信息,表1中仅以IP地址为例进行说明。
数据共享系统中的每个节点均存储一条相同的区块链。区块链由多个区块组成,参见图1B,区块链由多个区块组成,创始块中包括区块头和区块主体,区块头中存储有输入信息特征值、版本号、时间戳和难度值,区块主体中存储有输入信息;创始块的下一区块以创始块为父区块,下一区块中同样包括区块头和区块主体,区块头中存储有当前区块的输入信息特征值、父区块的区块头特征值、版本号、时间戳和难度值,并以此类推,使得区块链中每个区块中存储的区块数据均与父区块中存储的区块数据存在关联,保证了区块中输入信息的安全性。
在生成区块链中的各个区块时,参见图1C,区块链所在的节点在接收到输入信息时,对输入信息进行校验,完成校验后,将输入信息存储至内存池中,并更新其用于记录输入信息的哈希树;之后,将更新时间戳更新为接收到输入信息的时间,并尝试不同的随机数,多次进行特征值计算,使得计算得到的特征值可以满足下述公式:
SHA256(SHA256(version+prev_hash+merkle_root+ntime+nbits+x))<TARGET
SHA256(SHA256(version+prev_hash+merkle_root+ntime+nbits+x))<TARGET
其中,SHA256为计算特征值所用的特征值算法;版本号(version)为区块链中相关区块协议的版本信息;prev_hash为当前区块的父区块的区块头特征值;merkle_root为输入信息的特征值;ntime为更新时间戳的更新时间;nbits为当前难度,在一段时间内为定值,并在超出固定时间段后再次进行确定;x为随机数;TARGET为特征值阈值,该特征值阈值可以根据nbits确定。
这样,当计算得到满足上述公式的随机数时,便可将信息对应存储,
生成区块头和区块主体,得到当前区块。随后,区块链所在节点根据数据共享系统中其他节点的节点标识,将新生成的区块分别发送给其所在的数据共享系统中的其他节点,由其他节点对新生成的区块进行校验,并在完成校验后将新生成的区块添加至其存储的区块链中。
以下分别进行详细说明。需要说明的是,以下实施例的描述顺序不作为对实施例优选顺序的限定。
在本申请实施例中,将从节点选取装置的角度进行描述,为了方便对本申请的节点选取方法进行说明,以下将以节点选取装置集成在第一节点中进行详细说明,即以第一节点作为执行主体进行详细说明。
请参阅图2,图2是本申请一实施例提供的节点选取方法的流程示意图。该节点选取方法可以包括:
S201、获取区块链中各个节点对应的属性权重,并按照属性权重的大小顺序对各个节点进行分组,得到多个节点组。
第一节点可以为各个节点中任一节点,即本申请实施例可以由区块链中任意一个节点执行。
属性权重表示节点在区块链中的贡献度,贡献度可以是节点的属性信息。
在一些实施例中,节点的属性信息可以包括节点的质押资产或节点得到的投票数。然而,根据节点的质押资产和投票数确定节点的属性权重,导致节点对应的用户需要先投入资产才能参与共识,降低了节点对应的用户的参与度,并且,仅仅根据质押资产确定节点的属性权重,没有考虑其他因素,从整个区块链网络规模的分布度、覆盖度上会有所欠缺,不利于整个区块链网络的稳定。
比如,如图3所示,区块链的节点通过质押资产成为提案者,如果节点质押的资产达标,则节点可以成为候选人参与选举,如果选举成功,则成功验证人,即成为共识节点。
因此,在另一些实施例中,如图4所示,节点的属性信息可以包括产块总数、上个世代(世代指角色转换真正生效的周期)产块总数、投票作恶(对于同一个高度区块而言,每个节点只允许投一次赞成票,也就是不能对同一个高度的多个区块投赞成票,若节点如此操作,则表明该节点投票作恶)、作为主节点作恶(主节点为产生区块的共识节点)、身份认证以及地理位置中的至少一种,使得当根据节点的属性信息确定节点的属性权重时,无需根据节点的质押资产和投票数确定节点的属性权重,并且,当根据节点的多种属性信息确定节点的属性权重时,可以实现从多个角度考虑节点的属性权重,以便当根据属性权重选取共识节点时,可以降低作恶节点被选取作为共识节点的概率,从而降低在共识的过程中共识节点出现错误的概率,提高区块链网络的稳定性。
区块链网络的稳定性指在共识过程中,共识节点出现错误的概率在容
错范围内,区块链网络仍可以正常运行。
当节点的属性信息包括多种时,获取区块链中各个节点对应的属性权重,包括:获取区块链中每个节点对应的多个属性信息;根据属性信息对应的信息权重,确定节点对应的属性权重。
在本申请实施例中,通过多个属性信息对应的信息权重,确定节点对应的属性权重,充分考虑多个因素,从而进一步提高整个区块链网络的稳定。
其中,第一节点可以直接将属性信息对应的信息权重相加,从而得到节点对应的属性权重。或者,第一节点也可以获取每个信息权重对应的调整系数,然后可以根据调整系数对信息权重进行调整,得到调整后信息权重,最后再将调整信息权重相加从而得到每个节点对应的属性权重。
上述方案中,在每次选取共识节点的过程中,每个属性信息对应的信息权重可以是相同的,或者,每个属性信息对应的信息权重在不同次选取共识节点的过程中也可以是不同的。当属性信息对应的信息权重在不同次选取共识节点的过程中不同时,可以根据该属性信息的节点在区块链网络当中的行为信息确定。
比如,属性信息可以为投票作恶,投票作恶对应的信息权重可以为负权重,节点n1在上个世代中多次投票作恶,则在当前的节点选取过程中,可以按照设定的比例(例如5%)增大投票作恶对应的信息权重。
第一节点在得到各个节点的属性权重之后,可以根据属性权重的大小顺序,对各个节点进行分组,得到多个节点组。
其中,第一节点可以获取多个预设权重区间,然后将属于同一个预设权重区间的属性权重对应的节点存储至同一个节点组中,实现将属性权重较大的节点存储到同一个节点组中。
或者,第一节点也可以按照属性权重的大小顺序对各个节点进行排序,得到排序队列,然后将排序队列划分为多个节点组。其中,排序可以是降序排序或升序排序,划分可以是平均划分,或者按照预先设置的数值进行划分。
比如,各个节点包括节点n1、节点n2、...以及节点nz,第一节点为节点n1,节点n1的属性权重w1>节点n2的属性权重w2>...>节点nz的属性权重wz,则排序队列可以为如图5所示,对排序队列进行平均划分之后,可以得到的各个节点组可以如图5所示。
第一节点可以在检测到需要进行世代切换时,获取区块链中各个节点对应的属性权重,并按照属性权重的大小顺序对各个节点进行分组,得到多个节点组,或者,第一节点也可以在接收到选取指令时,获取区块链中各个节点对应的属性权重,本申请实施例在此不做限定。
S202、从多个节点组中筛选出属性权重满足预设条件的节点组,得到目标节点组,并从目标节点组中筛选出预设数量的候选共识节点。
属性权重满足预设条件的节点组,可以指节点组中属性权重较大的节点组。比如,可以将节点组中属性权重第二大的节点组作为目标节点组,或者,也可以将节点组中属性权重最大的节点组作为目标节点组。
第一节点在得到各个节点组之后,可以先根据节点组中各个节点的属性权重确定节点组的属性权重,然后将节点组的属性权重进行比较,从而得到节点组中属性权重最大的节点组。
或者,第一节点也可以将一个节点组中节点的最大属性权重与另外一个节点组中节点的最小属性权重进行比较,如果最大属性权重小于最小属性权重,表明最小属性权重对应的节点组的属性权重,相较于另一个节点组的属性权重更大。
又或者,如果是对排序队列(降序排序)进行划分之后得到节点组,则可以直接将排序在前的节点组作为目标节点组。比如,如图6所示,直接将节点组g1作为目标节点组。
第一节点在得到目标节点组之后,可以从目标节点组中筛选出预设数量的候选共识节点,候选共识节点可以为目标节点组中属性权重较大的节点,即在属性权重的降序排序中从头部开始的多个节点,或者,候选共识节点也可以为目标节点组中属性权重较小的多个节点,即在属性权重的降序排序中从尾部开始的多个节点。
比如,当目标节点组为节点组g1时,候选共识节点为节点n1和节点n2,非候选共识节点为节点n3,由于节点n1的属性权重大于节点n2的属性权重,节点n2的属性权重大于节点n3的属性权重,因此,此时,选取出的候选共识节点为属性权重较大的节点。
其中,第一节点可以获取目标节点组的预设阈值,然后将大于预设阈值的属性权重对应的节点作为候选共识节点,或者,第一节点也可以将小于预设阈值的属性权重对应的节点作为候选共识节点,每个目标节点组对应的预设阈值不相同,每个目标节点组是将大于预设阈值的属性权重对应的节点作为候选共识节点还是将小于预设阈值的属性权重对应的节点作为候选共识节点也可以不相同,以便使得候选共识节点为目标节点组中属性权重较大的节点或者为目标节点组中属性权重较小的节点。
比如,节点组g1和节点组g2,节点组g1对应预设阈值t1,节点组g2对应预设阈值t2,当节点组g1作为目标节点组时,可以是将大于预设阈值t1的属性权重对应的节点作为候选共识节点,当节点组g2作为目标节点组时,可以是将小于预设阈值t2的属性权重对应的节点作为候选共识节点。
或者,第一节点也可以随机从目标节点组中筛选出预设数量的候选共识节点,从而使得候选共识节点为目标节点组中属性权重较大的节点或者为目标节点组中属性权重较小的节点。
随机从目标节点组中筛选出预设数量的候选共识节点的方法可以根据实际情况进行选择,比如,可以通过随机函数从目标节点组中筛选出预设
数量的候选共识节点,随机函数可以为可验证随机函数(Verifiable Random Function,VRF)随机函数或伪随机函数,本申请实施例在此不做限定。
当随机从目标节点组中筛选出预设数量的候选共识节点时,从目标节点组中筛选出预设数量的候选共识节点,包括:根据第一预设数量和预设数量,确定目标节点组对应的随机数;根据随机数,从目标节点组中随机筛选出预设数量的候选共识节点。
其中,第一节点可以通过随机函数根据第一预设数量和预设数量,确定每个预设数值的概率,然后将概率最大的预设数值作为目标节点组对应的随机数。
或者,第一节点也可以通过随机函数,将预设数量,作为目标节点组对应的随机数的目标数量,然后在第一预设数量内,生成目标节点组对应的目标数量的随机数,即随机数的取值小于或等于第一预设数量,且大于或等于0。此时,预设数量表示随机数的数量,第一预设数量表示随机数所在的数值区间。
比如,第一预设数量为3,预设数量为2,则表示在[0,3]内生成两个随机数。
第一节点在得到随机数之后,再根据随机数,从目标节点组中筛选出预设数量的候选共识节点。
上述方案中,第一节点可以将随机数作为目标节点组中的节点序号,然后将节点序号对应的节点,作为目标节点组对应的候选共识节点。
比如,随机数为1和2,序号1对应的节点为节点n1,序号2对应的节点为节点n2,则将节点n1和节点n2作为目标节点组对应的候选共识节点。
在本申请实施例中,将随机数作为目标节点组中的节点序号,然后将节点序号对应的节点,作为目标节点组对应的候选共识节点,从而实现随机从目标节点组中筛选出候选共识节点,使得候选共识节点为目标节点组中属性权重较大的节点或者为目标节点组中属性权重较小的节点。
S203、将目标节点组中非候选共识节点存储至初始节点组,初始节点组为多个节点组中除了目标节点组之外的且与目标节点组匹配的组。
多个节点组中除了目标节点组之外的节点组可以成为候选节点组,比如,多个节点组可以如图6所示,目标节点组为g1,则候选节点组包括可以节点组g2、节点组g3、...、以及节点组gm等。
初始节点组为多个节点组中除了目标节点组之外的且与目标节点组匹配的组,可以理解为候选节点组中与目标节点组同样满足预设条件的节点组,比如,目标节点组为节点组中属性权重最大的节点组,则初始节点组可以理解为候选节点组中属性权重最大的节点组。
在本申请实施例中,在目标节点组中的节点被确定为目标节点组对应的非候选共识节点时,可以将目标节点组中的非候选共识节点存储至初始
节点组中,然后继续从初始节点组中筛选出候选共识节点,使得属性权重较大的节点参与多次筛选,提高属性权重较大的节点被选为候选共识节点的概率。
比如,各个节点组可以如图6所示,目标节点组为节点组g1,初始节点组为节点组g2,目标节点组对应的候选共识节点为节点n1和节点n2,目标节点组中的非候选共识节点为节点n3,则将节点n3存储至节点组g2,此时,节点组g2可以如图6所示。
当通过对排序队列进行划分,得到节点组时,将目标节点组中非候选共识节点存储至初始节点组,包括:
从候选节点组中筛选出与目标节点组相邻且属性权重小于目标节点组的候选节点组,得到与目标节点组匹配的初始节点组,候选节点组为多个节点组中除了目标节点组之外的节点组;
将目标节点组中非候选共识节点存储至初始节点组。
比如,如图6所示,第一节点在得到各个节点组之后,直接将排序在第一位的节点组g1作为目标节点组,在从节点组g1筛选出节点n1和节点n2作为候选共识节点之后,由于节点组g2为与属性权重小于节点组g2的且与节点组g2相邻的节点组,因此,将节点组g2作为初始节点组,并将节点组g1的非候选共识节点n3存储至节点组g2中。
或者,在得到目标节点组的候选共识节点和非候选共识节点之后,目标节点组不存在,则可以将排序在前的节点组作为初始节点组。比如,如图6所示,在得到节点组g1的候选共识节点和非候选共识节点之后,节点组g1不存在,此时,节点组g2排序在第一位,第一节点则仍然可以将第一位的节点组g2作为初始节点组。
S204、将初始节点组作为目标节点组,并返回执行从目标节点组中筛选出候选共识节点的步骤,直至完成多个节点组中所有节点组的筛选。
第一节点在得到初始节点组之后,再将初始节点组作为目标节点组,并返回执行从目标节点组中筛选出候选共识节点的步骤,直至完成多个节点组中所有节点组的筛选。
比如,如图6所示,第一节点在得到各个节点组之后,将节点组中属性权重最大的节点组g1作为目标节点组,然后从目标节点组中筛选出节点n1和节点n2作为候选共识节点,节点n3作为非候选共识节点。
第一节点将候选节点组中属性权重最大的节点组g2作为初始节点组,并将节点n3存储至节点组g2中,然后,第一节点从节点组g2中筛选出节点n4和n5作为候选共识节点,节点n3和节点n6作为非候选共识节点。
第一节点将候选节点组中属性权重最大的节点组g3作为初始节点组,并将节点n3和节点n6存储至节点组g3中,然后继续从节点组g3中筛选出候选共识节点和非候选共识节点,重复循环该过程,直至从节点组gm中筛选出候选共识节点,停止候选共识节点的选取。
应理解,从目标节点组中筛选出候选共识节点的执行的次数可以根据节点组的个数确定,比如,当节点组的个数为m时,表明第一节点重复执行m次从目标节点组中筛选出候选共识节点的步骤。
当将初始节点组作为目标节点组,并返回执行从目标节点组中筛选出候选共识节点的步骤时,从初始节点组筛选出的候选共识节点可能为初始节点组中属性权重较大的节点,也可能为初始节点组中属性权重较小的节点。
比如,如图6所示,第一节点在得到各个节点组之后,将节点组中属性权重最大的节点组g1作为目标节点组,然后从目标节点组中筛选出节点n1和节点n2作为候选共识节点,节点n3作为非候选共识节点。
由于节点n1的属性权重大于节点n2的属性权重,节点n2的属性权重大于节点n3的属性权重,因此,此时,将目标节点组中属性权重较大的节点作为候选共识节点。
第一节点将候选节点组中属性权重最大的节点组g2作为初始节点组,并将节点n3存储至节点组g2中,然后,第一节点从节点组g2中筛选出节点n4和n5作为候选共识节点,节点n3和节点n6作为非候选共识节点。
由于节点n3的属性权重大于节点n4的属性权重,节点n4的属性权重大于节点n5的属性权重,节点n5的属性权重大于节点n6的属性权重,因此,此时,将初始节点组中属性权重较小的节点作为候选共识节点。
需要说明的是,当将非候选共识节点存储至初始节点组之后,初始节点组中包括的节点的数量发生了变化,则在返回从目标节点组中筛选出候选共识节点的步骤时,第一预设数量可以指初始节点组中包括的节点的数量。
一个节点在不同的节点组中可以是候选共识节点,也可以是非候选共识节点。比如,在节点组g1组为目标节点组时,将节点n1和节点n2作为节点组g1对应的候选共识节点,节点n3为节点组g1对应的非候选共识节点,在节点组g2为目标节点组时,将节点n3和节点n5作为节点组g2对应的候选共识节点,也即是,在节点组g1中,节点n3是非候选共识节点,在节点组g2中,节点n3是候选共识节点。
S205、将候选共识节点广播至各个节点中的第二节点进行验证。
当一个节点接收到广播的候选共识节点时,该节点可以称为第二节点。应理解,一个节点可以同时为第一节点和第二节点。比如,节点n1从各个节点组中筛选出候选共识节点,节点n2也从各个节点组中筛选出候选共识节点,节点n1和节点n2均称为第一节点,节点n1在从各个节点组中筛选出候选共识节点之后,如果接收到节点n2广播的候选共识节点,则节点n1称为第二节点,节点n2在从各个节点组中筛选出候选共识节点之后,如果接收到节点n1广播的候选共识节点,则节点n2称为第二节点。
第一节点在得到一个目标节点组的候选共识节点之后,可以先将该目
标节点组的候选共识节点进行广播,即第一节点在从目标节点组中筛选出预设数量的候选共识节点之后,先执行步骤S205,然后再执行步骤S203,或者,第一节点也可以在得到所有节点组的候选共识节点之后,再将所有的候选共识节点进行广播,即第一节点在从目标节点组中筛选出预设数量的候选共识节点后,先步骤S203和步骤204,再执行步骤S205,本申请实施例在此不做限定。
将候选共识节点广播至各个节点中的第二节点进行验证,可以理解为将候选共识节点对应的标识广播至各个节点中的第二节点进行验证,或者,也可以先对候选共识节点的标识进行映射,得到映射结果,然后再将映射结果广播至各个节点中的第二节点进行验证。
当对候选共识节点的标识进行映射,得到映射结果,然后再将映射结果广播至各个节点中的第二节点进行验证时,可以将多个候选共识节点的标识进行拼接,得到拼接标识,然后再对拼接标识进行哈希映射,从而得到映射结果。或者,也可以是对每个候选共识节点的标识分别进行哈希映射,得到每个候选共识节点的子映射结果,然后再根据每个候选共识节点的子映射结果确定映射结果。
当对每个候选共识节点的标识分别进行哈希映射,得到每个候选共识节点的子映射结果,然后再根据每个候选共识节点的子映射结果确定映射结果时,将候选共识节点广播至各个节点中的第二节点进行验证,包括:
计算候选共识节点的默尔克根;
将默尔克根广播至各个节点中的第二节点进行验证。
默尔克根指对各个对象进行分别哈希,然后将各个对象的哈希结果进行相加后得到的哈希值或将各个对象的哈希结果再次进行哈希相加后得到的哈希值。对象可以为交易,或者,对象也可以为节点。
其中,计算候选共识节点的默尔克根的过程可以为:第一节点先分别对每个候选共识节点进行哈希,得到每个候选共识节点对应的哈希值,然后对相邻的候选共识节点的哈希值再次进行哈希,得到候选哈希值,如果候选哈希值的不是一个,则再将相邻的候选哈希值进行哈希,直至得到的候选哈希值为一个时,将候选哈希值作为候选共识节点的默尔克根。
比如,如图7所示,候选共识节点包括节点n1、节点n2、节点n3、节点n4、节点n5、节点n6、节点n7以及节点n8,则对节点n1-n8分别进行哈希,得到节点n1-n8对应的哈希值,然后将节点n1的哈希值和节点n2的哈希值再次进行哈希,得到候选哈希值12,将节点n3的哈希值和节点n4的哈希值再次进行哈希,得到候选哈希值34,将节点n5的哈希值和节点n6的哈希值再次进行哈希,得到候选哈希值56,将节点n7的哈希值和节点n8的哈希值再次进行哈希,得到候选哈希值78。
由于存在四个候选哈希值,因此,继续对候选哈希值12和候选哈希值34再次进行哈希,得到候选哈希值1234,对候选哈希值56和候选哈希值
78再次进行哈希,得到候选哈希值5678。此时,存在两个候选哈希值,则继续对候选哈希值1234和候选哈希值5678进行进行哈希,得到候选哈希值12345678,此时,只剩下一个候选哈希值12345678,则将候选哈希值12345678作为候选共识节点对应的默尔克根。
在本申请实施例中,通过将候选共识节点的默尔克根进行广播,从而简化节点之间的消息通信复杂度。并且,在广播默尔克根时,只广播候选共识节点的默尔克根,无需广播所有节点的默尔克根,从而进一步简化节点之间的消息通信复杂度。
S206、若在预设时间内接收到第二节点对候选共识节点的验证通过信息,则将候选共识节点作为区块链的目标共识节点。
区块链在不同的世代中的共识节点不相同,将候选共识节点作为区块链的目标共识节点,可以理解为将候选共识节点作为区块链的下个世代的目标共识节点。
第二节点在接收到候选共识节点之后,可以候选共识节点与第二节点从节点组筛选出的候选共识节点进行比对,如果比对结果为相同,则对候选共识节点的验证通过,如果比对结果不相同,则对候选共识节点的验证不通过。
如果第二节点接收到的是默尔克根,则将接收到的默尔克根和第二节点计算到的默尔克根进行比对,如果比对结果为相同,则对候选共识节点的验证通过,如果比对结果不相同,则对候选共识节点的验证不通过。
当第一节点先将一个目标节点组的候选共识节点进行广播时,第一节点可以在预设时间内接收到第二节点对候选共识节点的验证通过信息,将候选共识节点作为区块链的目标共识节点之后,再将目标节点组的非候选共识节点存储至初始节点组,并将初始节点组作为目标节点组,返回执行从目标节点组中筛选出候选共识节点的步骤。
或者,第一节点也可以将一个目标节点组的候选共识节点进行广播的同时,将目标节点组的非候选共识节点存储至初始节点组,并将初始节点组作为目标节点组,返回执行从目标节点组中筛选出候选共识节点的步骤,本申请实施例在此不做限定。
上述方案中,第一节点也可以在预设时间内接收到对候选共识节点的验证通过信息的个数满足预设个数时,才将候选共识节点作为区块链的目标共识节点。
比如,预设个数为3个,节点n1将候选共识节点广播至节点n2、节点n3、节点n4以及节点n5中进行验证,并在预设时间内接收到节点n2、节点n3以及节点n4对候选共识节点的验证通过信息,由于在预设时间内接收到3个节点对候选共识节点的验证通过信息,因此,将候选共识节点作为区块链的目标共识节点。
需要说明的是,若在预设时间内未接收到第二节点对候选共识节点的
验证通过信息,则不将候选共识节点作为区块链的目标共识节点,此时,可能是因为第一节点内存中所包含的节点的属性信息与其他节点内存中所包含的节点的属性信息不一致导致,则第一节点可以通过状态同步的方法,从其他节点中获取各个节点的属性信息,然后再次进行候选共识节点的选取,即再次执行步骤S201-S206。
在得到区块链的各个目标共识节点之后,可以通过各个目标共识节点将交易打包成待验证区块和对待验证区块进行验证。如果目标共识节点对待验证区块的验证通过,则将待验证区块在区块链中广播,使得区块链中非共识节点和目标共识节点将待验证区块存储至本身存储的区块链上。
比如,区块链可以如图8所示,节点n1、节点n2、节点n3以及节点n4为区块链中目标共识节点,节点n5、节点n6、节点n7、节点n8、节点n9、节点n10、节点n11、以及节点n12为区块链中非共识节点,实线表示该节点可以参与共识,虚线表示该节点只是同步待验证区块,被动地接收区块,不能参与共识。
在一些实施例中,通过各个目标共识节点对交易打包成待验证区块和对待验证区块进行验证的过程为:
从目标共识节点中筛选出一个目标共识节点作为主节点将交易打包成待验证区块,并将待验证区块发送至目标共识节点中其他共识节点,目标共识节点中其他共识节点为目标共识节点中除了主节点之外的目标共识结果,然后目标共识节点中其他共识节点对待验证区块进行验证,如果其他共识节点对待验证区块的验证通过,主节点则将待验证区块在区块链中广播,使得区块链中非共识节点可以将待验证区块存储至本身存储的区块链上,区块链中目标共识节点可以将待验证区块存储至本身存储的区块链上。
因此,当第一节点为主节点时,在将候选共识节点作为区块链的目标共识节点之后,还包括:
获取待验证区块,并通过目标共识节点对待验证区块进行共识;
若对待验证区块的共识通过,则将待验证区块存储至区块链中。
其中,第一节点可以获取当前交易数据,然后将当前交易数据打包成待验证区块。如果对待验证区块的共识通过,则将待验证区块存储至第一节点存储的区块链中,并同时将待验证区块在区块链中进行广播,使得区块链中其他节点可以将待验证区块存储至本身存储的的区块链中。
在本申请实施例中,通过区块链中各个目标共识节点生成区块和验证区块,减少生成区块和验证区块的节点的数量,从而降低通信复杂度,提高共识效率。
然而,通过各个目标共识节点生成区块和验证区块,使得区块链中多数节点没有参与到共识中,也就是没有对区块有投票权,投票的权利掌握在少数节点上,导致存在中心化的问题。
为了解决中心化的问题,在另一些实施例中,若对待验证区块的共识
通过,则将待验证区块存储至区块链中,包括:
若对待验证区块的共识通过,则将待验证区块广播至区块链中非共识节点进行验证;
若对待验证区块的验证通过的非共识节点的数量满足预设数量要求,则将待验证区块存储至区块链中。
比如,如图9所示,主节点产生待验证区块之后,将待验证区块发送至其他共识节点进行验证,如果其他共识节点对待验证区块的验证通过,则将待验证区块在区块链中进行广播,如果对待验证区块的验证通过的非共识节点的数量满足预设数量要求,则将待验证区块存储至区块链中。
此时,待验证区块在目标共识节点间达成一致后,可以仅仅表示待验证区块被提案,称之为propose阶段,propose阶段后,目标共识节点会在区块链中广播该待验证区块,使得非共识节点接收到该待验证区块,每个非共识节点收到该待验证区块后都会对其进行投票,一个待验证区块的确认以收到大多数非共识节点的赞成票为准,当收到大多数节点的赞成票后,该待验证区块被认可,称之为commit阶段。
也即是,此时,区块链可以如图10所示,节点n1、节点n2、节点n3以及节点n4为区块链中目标共识节点,节点n5、节点n6、节点n7、节点n8、节点n9、节点n10、节点n11、以及节点n12为区块链中非共识节点,实线表示该节点可以参与共识,也即是,表明非共识节点也可以参与共识。
在本申请实施例中,当目标共识节点对待验证区块的共识通过时,并不立即将待验证区块存储至区块链中,而是通过区块链中非共识节点对待验证区块进行验证,当对待验证区块的验证通过的非共识节点的数量满足预设数量要求时,才将待验证区块存储至区块链中,使得区块链中非共识节点也可以参与共识过程,从而减少中心化的程度。
在另一些实施例中,若对待验证区块的验证通过的非共识节点的数量满足预设数量要求,则将待验证区块存储至区块链中,包括:
若对待验证区块的验证通过的非共识节点的数量满足预设数量要求,则获取待验证区块的上一区块;
如果对上一区块的验证通过的非共识节点的数量满足预设数量要求,则将待验证区块存储至区块链中。
在整个区块链中会区块会被投赞成票与不赞成票,只要不赞成票达到要求就说明该区块无法被达成一致,对于一个共识节点而言,它要检测自己产生区块的上一区块是否收到足够的赞成票,如果上一区块被达成一致,才将待验证区块存储至区块链中。
如果上一区块无法被达成一致,需要该共识节点接替产生上一区块的共识节点的职责,产生上一区块,此时,在若对待验证区块的验证通过的非共识节点的数量满足预设数量要求,则获取待验证区块的上一区块之后,还包括:
若对上一区块的验证通过的非共识节点的数量不满足预设数量要求,则生成上一区块,并将上一区块作为待验证区块;
返回执行获取待验证区块,并通过目标共识节点对待验证区块进行共识的步骤。
此时,当前区块由该共识节点的下一个共识节点进行打包。
比如,如图11所示,区块2为当前区块,节点n2在验证区块2的过程中,发现对区块1的验证通过的非共识节点的数量不满足预设数量要求,则节点n2生成区块1’,并通过节点n3生成区块2’。
由以上可知,在本申请实施例中,获取区块链中各个节点对应的属性权重,并按照属性权重的大小顺序对各个节点进行分组,得到多个节点组,从多个节点组中筛选出属性权重满足预设条件的节点组,得到目标节点组,并从目标节点组中筛选出预设数量的候选共识节点,将目标节点组中非候选共识节点存储至初始节点组,初始节点组为多个节点组中除了目标节点组之外的且与目标节点组匹配的组,将初始节点组作为目标节点组,并返回执行从目标节点组中筛选出候选共识节点的步骤,直至完成多个节点组中所有节点组的筛选;将候选共识节点广播至各个节点中的第二节点进行验证;若在预设时间内接收到第二节点对候选共识节点的验证通过信息,则将候选共识节点作为区块链的目标共识节点。
即在本申请实施例中,按照属性权重的大小顺序对节点进行分组,将属性权重满足预设条件的节点组作为目标节点组,从目标节点组中筛选出候选共识节点,从目标节点组中筛选出的候选共识节点可能为目标节点组中属性权重较大的节点,也可能为目标节点组中属性权重较小的节点。
将目标节点组中非候选共识节点存储至初始节点组中,从初始节点组继续中筛选出候选共识节点,从初始节点组中筛选出的候选共识节点可能为初始节点组中属性权重较大的节点,也可能为初始节点组中属性权重较小的节点。
由于属性权重满足预设条件的目标节点组比如可以为属性权重较大的节点组且初始节点组为多个节点组中除了目标节点组之外的且与目标节点组匹配的组,因此,将目标节点组中非候选共识节点存储至初始节点组中再次参与筛选,可以提高多个节点中属性权重较大的节点的筛选次数,从而提高多个节点中属性权重较大的节点被筛选为候选共识节点的概率。
因为从目标节点组中筛选出的候选共识节点可能为目标节点组中属性权重较大的节点,也可能为目标节点组中属性权重较小的节点,从初始节点组中筛选出的候选共识节点也可能为初始节点组中属性权重较大的节点,也可能为初始节点组中属性权重较小的节点,所以,当筛选完成时得到的候选共识节点可能为多个节点中属性权重较大的节点,也可能为多个节点中属性权重较小的节点,实现不但可以为属性权重较大的节点提供更高的被选中概率,而且也可以为属性权重较小的节点提供被选中的机会,降低
作恶节点被选取为共识节点的概率,从而降低在共识的过程中共识节点出现错误的概率,进而提高区块链网络的稳定性。
根据上述实施例所描述的方法,以下将举例作进一步详细说明。
本申请实施例中的节点选取方法可以应用于区块链中的共识节点的选取过程,下面将本申请实施例中节点选取方法应用于区块链的DPoS共识机制中共识节点选取过程。
请参阅图12,图12为本申请实施例提供的节点选取方法的流程示意图。该节点选取方法流程可以包括:
S1201、第一节点检测到处于世代切换阶段时,获取区块链中每个节点对应的多个属性信息,并根据属性信息对应的信息权重,确定节点对应的属性权重。
在DPoS共识机制中,通常是在一个世代的最后一个区块中确认下个世代的共识节点的信息,并将下个世代的共识节点的信息存储至区块链中。然而,为了保证较多的共识节点,共识节点的数量会较大,使得下个世代的共识节点的信息较多,导致存储下个世代的共识节点的信息的区块会较大。
另外,有时候为了利益,共识节点可能故意作恶,选择自己作为下一个世代的候选人节点,该过程没有其他节点的参与,导致安全性比较难保证。
因此,在本申请实施例中,通过添加世代切换阶段实现共识节点的选取,即可以避免共识节点的作恶,提高安全性,而且不将共识节点的信息存储至区块链中,仅仅记录在节点的本地,从而减少区块链的大小。
比如,如图13所示,在世代k接收时,进入世代切换阶段,在世代切换阶段,选取共识节点,不产生区块,当世代切换阶段结束时,在世代(k+1)开始产生区块。
也即是,当第一节点获取到交易数据时,可以检测是否处于世代切换阶段,如果处于世代切换阶段,则获取区块链中每个节点对应的多个属性信息,如果不是处于世代切换阶段,则判断第一节点是否为主节点。如图14所示。
S1202、第一节点按照属性权重的大小顺序对各个节点进行排序,得到排序队列,并对排序队列进行平均划分,得到多个节点组。
S1203、第一节点从多个节点组中筛选出属性权重最大的节点组,得到目标节点组,并获取预设数量。
S1204、第一节点将预设数量,作为目标节点组对应的随机数的目标数量,并通过随机函数在第一预设数量内,生成目标节点组对应的目标数量的随机数,第一预设数量为目标节点组包括的节点的数量。
S1205、第一节点将随机数作为目标节点组中的节点序号,并将节点序号对应的节点,作为目标节点组对应的候选共识节点。
S1206、第一节点从候选节点组中筛选出与目标节点组相邻且属性权重小于目标节点组的候选节点组,得到与目标节点组匹配的初始节点组,候选节点组为多个节点组中除了目标节点组之外的节点组。
S1207、第一节点将目标节点组对应的非候选共识节点存储至初始节点组,并将初始节点组作为目标节点组,以及返回执行步骤S1204。
S1208、第一节点计算候选共识节点的默尔克根,并将默尔克根广播至各个节点中的第二节点进行验证。
S1209、第二节点将接收到的默尔克根与本身计算到的默尔克根进行比对,得到比对结果。
S12010、若比对结果为相同,则返回验证通过消息至第一节点,若比对结果为不相同,则返回验证不通过消息至第一节点。
S12011、若在预设时间内,接收到对候选共识节点的验证通过信息的个数满足预设个数,第一节点则将候选共识节点作为区块链的目标共识节点。
S12012、第一节点计算各个目标共识节点的出块顺序并保存。
S12013、若在预设时间内,接收到对候选共识节点的验证通过信息的个数不要满足预设个数,则更新属性信息,并返回执行根据属性信息对应的信息权重,确定节点对应的属性权重的步骤。
应理解,第一节点在第零轮从节点组中筛选出候选共识节点时,可以根据上个世代的最后一个区块中的哈希值(BlockHash)确定随机函数的种子,然后根据随机函数得到目标节点组的随机数,如果第零轮得到候选共识节点的验证不通过,则在返回执行的过程中,可以根据轮数(轮数比如可以为第零轮、第一轮、第二轮等,当随机函数为VRF函数时,轮数可以指round)和上个世代的最后一个区块中哈希值确定随机函数的种子。
根据上个世代的最后一个区块中的哈希值(BlockHash)确定随机函数的种子,由于上个世代的最后一个区块中的哈希值在上个世代的最后一个区块未产生之前是无法预测的,因此,可以保证随机数的随机性。
S12014、目标共识节点获取当前交易数据,并根据目标共识节点的出块顺序,确定本身是否为主节点。
S12015、若目标共识节点为主节点,主节点则生成当前交易数据对应的待验证区块。
S12016、主节点将待验证区块发送至其他共识节点,其他共识节点为目标共识节点中除了主节点之外的共识节点。
如图14所示,当目标共识节点获取到交易数据,并确定自己是当前区块的主节点时,目标共识节点生成交易数据对应的待验证区块。
S12017、若其他共识节点对待验证区块的共识通过,主节点则将待验证区块广播至区块链中非共识节点进行验证。
S12018、若对待验证区块的验证通过的非共识节点的数量满足预设数
量要求,主节点则获取待验证区块的上一区块。
S12019、若对上一区块的验证通过的非共识节点的数量满足预设数量要求,主节点则将待验证区块存储至区块链中。
S12020、若对上一区块的验证通过的非共识节点的数量不满足预设数量要求,主节点则根据上一区块的交易数据重新生成待验证区块,并返回执行步骤S12016。
本申请实施例中具体实现过程以及对应的有益效果,具体可以参照上述节点选取方法实施例,本实例在此不再赘述。
为便于更好的实施本申请实施例提供的节点选取方法,本申请实施例还提供一种基于上述节点选取方法的装置。其中名词的含义与上述节点选取方法中相同,具体实现细节可以参考方法实施例中的说明。
例如,如图15所示,该节点选取装置可以包括:
获取模块1501,配置为获取区块链中各个节点对应的属性权重,并按照属性权重的大小顺序对各个节点进行分组,得到多个节点组。
筛选模块1502,配置为从多个节点组中筛选出属性权重满足预设条件的节点组,得到目标节点组,并从目标节点组中筛选出预设数量的候选共识节点。
存储模块1503,配置为将目标节点组中非候选共识节点存储至初始节点组,初始节点组为多个节点组中除了目标节点组之外的且与目标节点组匹配的组。
返回模块1504,配置为将初始节点组作为目标节点组,并返回执行从目标节点组中筛选出候选共识节点的步骤,直至完成多个节点组中所有节点组的筛选。
验证模块1505,配置为将候选共识节点广播至各个节点中的第二节点进行验证。
作为模块1506,配置为若在预设时间内接收到第二节点对候选共识节点的验证通过信息,则将候选共识节点作为区块链的目标共识节点。
上述方案中,获取模块1501具体配置为执行:
按照属性权重的大小顺序对各个节点进行排序,得到排序队列;
将所述排序队列划分为多个节点组。
上述方案中,存储模块1503具体配置为执行:
从候选节点组中筛选出与目标节点组相邻且属性权重小于目标节点组的候选节点组,得到与目标节点组匹配的初始节点组,候选节点组为多个节点组中除了目标节点组之外的节点组;
将目标节点组中非候选共识节点存储至初始节点组。
上述方案中,节点组中包括第一预设数量的节点。相应地,筛选模块1502具体配置为执行:
根据第一预设数量和预设数量,确定目标节点组对应的随机数;
根据随机数,从目标节点组中筛选出预设数量的候选共识节点。
上述方案中,筛选模块1502具体配置为执行:将预设数量,作为目标节点组对应的随机数的目标数量;在第一预设数量内,生成目标节点组对应的目标数量的随机数。
上述方案中,筛选模块1502具体配置为执行:将随机数作为目标节点组中的节点序号;将节点序号对应的节点,作为目标节点组对应的候选共识节点。
上述方案中,验证模块1505具体配置为执行:计算候选共识节点的默尔克根;将默尔克根广播至各个节点中的第二节点进行验证。
上述方案中,获取模块1501具体配置为执行:获取区块链中每个节点对应的多个属性信息;根据属性信息对应的信息权重,确定节点对应的属性权重。
上述方案中,获取模块1501具体配置为执行:获取属性信息对应的信息权重,并获取信息权重对应的调整系数;根据调整系数对信息权重进行调整,得到调整后信息权重;根据调整后信息权重,确定节点对应的属性权重。
上述方案中,节点选取装置还包括:区块存储模块,配置为执行:获取待验证区块,并通过目标共识节点对待验证区块进行共识;若对待验证区块的共识通过,则将待验证区块存储至区块链中。
上述方案中,区块存储模块具体配置为执行:若对待验证区块的共识通过,则将待验证区块广播至区块链中非共识节点进行验证;若对待验证区块的验证通过的非共识节点的数量满足预设数量要求,则将待验证区块存储至区块链中。
具体实施时,以上各个模块可以作为独立的实体来实现,也可以进行任意组合,作为同一或若干个实体来实现,以上各个模块的具体实施方式以及对应的有益效果可参见前面的方法实施例,在此不再赘述。
本申请实施例还提供一种第一节点,该第一节点可以是服务器或终端等,如图16所示,其示出了本申请实施例所涉及的第一节点的结构示意图,具体来讲:
该第一节点可以包括一个或者一个以上处理核心的处理器1601、一个或一个以上计算机可读存储介质的存储器1602、电源1603和输入单元1604等部件。本领域技术人员可以理解,图16中示出的第一节点结构并不构成对第一节点的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。其中:
处理器1601是该第一节点的控制中心,利用各种接口和线路连接整个第一节点的各个部分,通过运行或执行存储在存储器1602内的计算机程序和/或模块,以及调用存储在存储器1602内的数据,执行第一节点的各种功能和处理数据。可选的,处理器1601可包括一个或多个处理核心;优选的,
处理器1601可集成应用处理器和调制解调处理器,其中,应用处理器主要处理操作系统、用户界面和应用程序等,调制解调处理器主要处理无线通信。可以理解的是,上述调制解调处理器也可以不集成到处理器1601中。
存储器1602可用于存储计算机程序以及模块,处理器1601通过运行存储在存储器1602的计算机程序以及模块,从而执行各种功能应用以及数据处理。存储器1602可主要包括存储程序区和存储数据区,其中,存储程序区可存储操作系统、至少一个功能所需的计算机程序(比如声音播放功能、图像播放功能等)等;存储数据区可存储根据第一节点的使用所创建的数据等。此外,存储器1602可以包括高速随机存取存储器,还可以包括非易失性存储器,例如至少一个磁盘存储器件、闪存器件、或其他易失性固态存储器件。相应地,存储器1602还可以包括存储器控制器,以提供处理器1601对存储器1602的访问。
第一节点还包括给各个部件供电的电源1603,优选的,电源1603可以通过电源管理系统与处理器1601逻辑相连,从而通过电源管理系统实现管理充电、放电、以及功耗管理等功能。电源1603还可以包括一个或一个以上的直流或交流电源、再充电系统、电源故障检测电路、电源转换器或者逆变器、电源状态指示器等任意组件。
该第一节点还可包括输入单元1604,该输入单元1604可用于接收输入的数字或字符信息,以及产生与用户设置以及功能控制有关的键盘、鼠标、操作杆、光学或者轨迹球信号输入。
尽管未示出,第一节点还可以包括显示单元等,在此不再赘述。具体在本申请实施例中,第一节点中的处理器1601会按照如下的指令,将一个或一个以上的计算机程序的进程对应的可执行文件加载到存储器1602中,并由处理器1601来运行存储在存储器1602中的计算机程序,从而实现各种功能,比如:获取区块链中各个节点对应的属性权重,并按照属性权重的大小顺序对各个节点进行分组,得到多个节点组;从多个节点组中筛选出属性权重满足预设条件的节点组,得到目标节点组,并从目标节点组中筛选出预设数量的候选共识节点;将目标节点组中非候选共识节点存储至初始节点组,初始节点组为多个节点组中除了目标节点组之外的且与目标节点组匹配的组;将初始节点组作为目标节点组,并返回执行从目标节点组中筛选出候选共识节点的步骤,直至完成多个节点组中所有节点组的筛选;将候选共识节点广播至各个节点中的第二节点进行验证;若在预设时间内接收到第二节点对候选共识节点的验证通过信息,则将候选共识节点作为区块链的目标共识节点。
以上各个操作的具体实施方式以及对应的有益效果可参见上文对节点选取方法的详细描述,在此不作赘述。
本领域普通技术人员可以理解,上述实施例的各种方法中的全部或部分步骤可以通过计算机程序来完成,或通过计算机程序控制相关的硬件来
完成,该计算机程序可以存储于一计算机可读存储介质中,并由处理器进行加载和执行。
为此,本申请实施例提供一种计算机可读存储介质,其中存储有计算机程序,该计算机程序能够被处理器进行加载,以执行本申请实施例所提供的任一种节点选取方法中的步骤。例如,该计算机程序可以执行如下步骤:
获取区块链中各个节点对应的属性权重,并按照属性权重的大小顺序对各个节点进行分组,得到多个节点组;
从多个节点组中筛选出属性权重满足预设条件的节点组,得到目标节点组,并从目标节点组中筛选出预设数量的候选共识节点;
将目标节点组中非候选共识节点存储至初始节点组,初始节点组为多个节点组中除了目标节点组之外的且与目标节点组匹配的组;
将初始节点组作为目标节点组,并返回执行从目标节点组中筛选出候选共识节点的步骤,直至完成多个节点组中所有节点组的筛选;
将候选共识节点广播至各个节点中的第二节点进行验证;
若在预设时间内接收到第二节点对候选共识节点的验证通过信息,则将候选共识节点作为区块链的目标共识节点。
以上各个操作的具体实施方式以及对应的有益效果可参见前面的实施例,在此不再赘述。
其中,该计算机可读存储介质可以包括:只读存储器(ROM,Read Only Memory)、随机存取记忆体(RAM,Random Access Memory)、磁盘或光盘等。
由于该计算机可读存储介质中所存储的计算机程序,可以执行本申请实施例所提供的任一种节点选取方法中的步骤,因此,可以实现本申请实施例所提供的任一种节点选取方法所能实现的有益效果,详见前面的实施例,在此不再赘述。
其中,根据本申请的一个方面,提供了一种计算机程序产品或计算机程序,该计算机程序产品或计算机程序包括计算机指令,该计算机指令存储在计算机可读存储介质中。计算机设备的处理器从计算机可读存储介质读取该计算机指令,处理器执行该计算机指令,使得该计算机设备执行上述节点选取方法。
以上对本申请实施例所提供的一种节点选取方法、装置、第一节点、存储介质及程序产品进行了详细介绍,本文中应用了具体个例对本申请的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本申请的方法及其核心思想;同时,对于本领域的技术人员,依据本申请的思想,在具体实施方式及应用范围上均会有改变之处,综上所述,本说明书内容不应理解为对本申请的限制。
Claims (16)
- 一种节点选取方法,应用于区块链中第一节点,包括:获取区块链中各个节点对应的属性权重,并按照所述属性权重的大小顺序对所述各个节点进行分组,得到多个节点组;从所述多个节点组中筛选出属性权重满足预设条件的节点组,得到目标节点组,并从所述目标节点组中筛选出预设数量的候选共识节点;将所述目标节点组中非候选共识节点存储至初始节点组,所述初始节点组为所述多个节点组中除了所述目标节点组之外的且与所述目标节点组匹配的组;将所述初始节点组作为所述目标节点组,并返回执行从所述目标节点组中筛选出候选共识节点的步骤,直至完成所述多个节点组中所有节点组的筛选;将所述候选共识节点广播至各个所述节点中的第二节点进行验证;若在预设时间内接收到所述第二节点对所述候选共识节点的验证通过信息,则将所述候选共识节点作为所述区块链的目标共识节点。
- 根据权利要求1所述的节点选取方法,其中,所述按照所述属性权重的大小顺序对各个节点进行分组,得到多个节点组,包括:按照所述属性权重的大小顺序对各个节点进行排序,得到排序队列;将所述排序队列划分为多个节点组。
- 根据权利要求2所述的节点选取方法,其中,所述将所述目标节点组中非候选共识节点存储至初始节点组,包括:从候选节点组中筛选出与所述目标节点组相邻且属性权重小于所述目标节点组的候选节点组,以作为与所述目标节点组匹配的初始节点组,所述候选节点组为所述多个节点组中除了目标节点组之外的节点组;将所述目标节点组中非候选共识节点存储至所述初始节点组。
- 根据权利要求1至3任一项所述的节点选取方法,其中,所述节点组中包括第一预设数量的节点,所述从所述目标节点组中筛选出预设数量的候选共识节点,包括:根据所述第一预设数量和所述预设数量,确定所述目标节点组对应的随机数;根据所述随机数从所述目标节点组中筛选出预设数量的候选共识节点。
- 根据权利要求4所述的节点选取方法,其中,所述根据所述第一预设数量和所述预设数量,确定所述目标节点组对应的随机数,包括:将所述预设数量作为所述目标节点组对应的随机数的目标数量;在所述第一预设数量内,生成所述目标节点组对应的所述目标数量的随机数。
- 根据权利要求5所述的节点选取方法,其中,所述根据所述随机数,从所述目标节点组中随机筛选出预设数量的候选共识节点,包括:将所述随机数作为所述目标节点组中的节点序号;将所述节点序号对应的节点,作为所述目标节点组对应的候选共识节点。
- 根据权利要求1至6任一项所述的节点选取方法,其中,所述将所述候选共识节点广播至各个所述节点中的第二节点进行验证,包括:计算所述候选共识节点的默尔克根;将所述默尔克根广播至各个所述节点中的第二节点进行验证。
- 根据权利要求1至6任一项所述的节点选取方法,其中,所述获取区块链中各个节点对应的属性权重,包括:获取区块链中每个节点对应的多个属性信息;根据所述属性信息对应的信息权重,确定所述节点对应的属性权重。
- 根据权利要求8所述的节点选取方法,其中,所述根据所述属性信息对应的信息权重,确定所述节点对应的属性权重,包括:将所述属性信息对应的信息权重相加,得到所述节点对应的属性权重;或者,获取每个所述信息权重对应的调整系数,根据所述调整系数对所述信息权重进行调整,得到调整后的信息权重,将所述调整后的信息权重相加,得到每个节点对应的属性权重。
- 根据权利要求8所述的节点选取方法,其中,所述根据所述属性信息对应的信息权重,确定所述节点对应的属性权重,包括:获取所述属性信息对应的信息权重,并获取所述信息权重对应的调整系数;根据所述调整系数对所述信息权重进行调整,得到调整后信息权重;根据所述调整后信息权重,确定所述节点对应的属性权重。
- 根据权利要求1-10任一项所述的节点选取方法,其中,在所述将所述候选共识节点作为所述区块链的目标共识节点之后,还包括:获取待验证区块,并通过所述目标共识节点对所述待验证区块进行共识;若对所述待验证区块的共识通过,则将所述待验证区块存储至所述区块链中。
- 根据权利要求11所述的节点选取方法,其中,所述若对所述待验证区块的共识通过,则将所述待验证区块存储至所述区块链中,包括:若对所述待验证区块的共识通过,则将所述待验证区块广播至所述区块链中非共识节点进行验证;若对所述待验证区块的验证通过的非共识节点的数量满足预设数量要求,则将所述待验证区块存储至所述区块链中。
- 一种节点选取装置,包括:获取模块,配置为获取区块链中各个节点对应的属性权重,并按照属性权重的大小顺序对各个节点进行分组,得到多个节点组;筛选模块,配置为从所述多个节点组中筛选出属性权重满足预设条件的节点组,得到目标节点组,并从所述目标节点组中筛选出预设数量的候选共识节点;存储模块,配置为将所述目标节点组中非候选共识节点存储至初始节点组,所述初始节点组为所述多个节点组中除了所述目标节点组之外的且与所述目标节点组匹配的组;返回模块,配置为将所述初始节点组作为所述目标节点组,并返回执行从所述目标节点组中筛选出候选共识节点的步骤,直至完成所述多个节点组中所有节点组的筛选;验证模块,配置为将所述候选共识节点广播至各个所述节点中的第二节点进行验证;作为模块,配置为若在预设时间内接收到所述第二节点对所述候选共识节点的验证通过信息,则将所述候选共识节点作为所述区块链的目标共识节点。
- 一种第一节点,包括处理器和存储器,所述存储器存储有计算机程序,所述处理器用于运行所述存储器内的计算机程序,以执行权利要求1至12任一项所述的节点选取方法。
- 一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序适于处理器进行加载,以执行权利要求1至12任一项所述的节点选取方法。
- 一种计算机程序产品,所述计算机程序产品存储有计算机程序,所述计算机程序适于处理器进行加载,以执行权利要求1至12任一项所述的节点选取方法。
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
US18/388,501 US20240179018A1 (en) | 2022-11-30 | 2023-11-09 | Node selection method and apparatus, first node, storage medium, and program product |
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211530053.5A CN116980281A (zh) | 2022-11-30 | 2022-11-30 | 节点选取方法、装置、第一节点、存储介质及程序产品 |
CN202211530053.5 | 2022-11-30 |
Related Child Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
US18/388,501 Continuation US20240179018A1 (en) | 2022-11-30 | 2023-11-09 | Node selection method and apparatus, first node, storage medium, and program product |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2024113956A1 true WO2024113956A1 (zh) | 2024-06-06 |
Family
ID=88483767
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2023/112944 WO2024113956A1 (zh) | 2022-11-30 | 2023-08-14 | 节点选取方法、装置、第一节点、存储介质及程序产品 |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN116980281A (zh) |
WO (1) | WO2024113956A1 (zh) |
Families Citing this family (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117478299B (zh) * | 2023-12-27 | 2024-03-01 | 湖南天河国云科技有限公司 | 区块链共识算法切换方法、装置和计算机设备 |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110049029A (zh) * | 2019-04-04 | 2019-07-23 | 矩阵元技术(深圳)有限公司 | 共识节点确定方法、装置、计算机设备和存储介质 |
US20200162261A1 (en) * | 2018-11-18 | 2020-05-21 | Ramachandran Iyer | System and method of blockchain consensus mechanism with custom hardware based on geographic distribution, density, node asset and reputation |
CN111523890A (zh) * | 2020-04-23 | 2020-08-11 | 腾讯科技(深圳)有限公司 | 基于区块链的数据处理方法、装置、存储介质及设备 |
CN113448694A (zh) * | 2021-06-11 | 2021-09-28 | 电子科技大学 | 一种提高事务处理能力的区块链共识方法 |
CN114372588A (zh) * | 2021-12-30 | 2022-04-19 | 远光软件股份有限公司 | 一种共识节点的选取方法及相关装置 |
CN115374216A (zh) * | 2022-08-10 | 2022-11-22 | 深圳市沃享科技有限公司 | 共识方案的构建方法、装置、终端设备及计算机介质 |
-
2022
- 2022-11-30 CN CN202211530053.5A patent/CN116980281A/zh active Pending
-
2023
- 2023-08-14 WO PCT/CN2023/112944 patent/WO2024113956A1/zh active Application Filing
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20200162261A1 (en) * | 2018-11-18 | 2020-05-21 | Ramachandran Iyer | System and method of blockchain consensus mechanism with custom hardware based on geographic distribution, density, node asset and reputation |
CN110049029A (zh) * | 2019-04-04 | 2019-07-23 | 矩阵元技术(深圳)有限公司 | 共识节点确定方法、装置、计算机设备和存储介质 |
CN111523890A (zh) * | 2020-04-23 | 2020-08-11 | 腾讯科技(深圳)有限公司 | 基于区块链的数据处理方法、装置、存储介质及设备 |
CN113448694A (zh) * | 2021-06-11 | 2021-09-28 | 电子科技大学 | 一种提高事务处理能力的区块链共识方法 |
CN114372588A (zh) * | 2021-12-30 | 2022-04-19 | 远光软件股份有限公司 | 一种共识节点的选取方法及相关装置 |
CN115374216A (zh) * | 2022-08-10 | 2022-11-22 | 深圳市沃享科技有限公司 | 共识方案的构建方法、装置、终端设备及计算机介质 |
Also Published As
Publication number | Publication date |
---|---|
CN116980281A (zh) | 2023-10-31 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN112738820B (zh) | 一种服务功能链的动态部署方法、装置及计算机设备 | |
CN110503558B (zh) | 一种基于区块链系统的处理方法及装置 | |
US8867400B2 (en) | Method and apparatus for tracking clock sources | |
US20220245173A1 (en) | Blockchain-based data synchronization method, apparatus, and computer-readable storage medium | |
CN110798517B (zh) | 去中心化集群负载均衡方法、系统、移动终端及存储介质 | |
CN108958882A (zh) | 一种容器调整方法、装置和系统 | |
US20210058382A1 (en) | Block sequencing method and system based on tree-graph structure, and data processing terminal | |
CN115665170B (zh) | 基于信誉和节点压缩机制的区块链共识方法 | |
US11102284B2 (en) | Service processing methods and systems based on a consortium blockchain network | |
CN111935207A (zh) | 基于改进型c4.5算法区块链系统共识方法 | |
CN111698094A (zh) | 一种基于区块链系统的共识方法及区块链系统 | |
CN112468552A (zh) | 双层分布式区块链网络模型的轻量级信誉共识实现方法 | |
WO2024113956A1 (zh) | 节点选取方法、装置、第一节点、存储介质及程序产品 | |
CN113342893B (zh) | 基于区块链的节点同步方法、装置、存储介质及服务器 | |
CN112561700B (zh) | 区块链中交易数据的验证方法、及区块链系统 | |
CN110570311A (zh) | 区块链的共识方法、装置及设备 | |
CN110619020B (zh) | 一种基于机器学习的区块链分片方法 | |
CN108648076B (zh) | 一种选举共识节点及生成节点信息表格的方法及系统 | |
US20240111785A1 (en) | Method and apparatus of adding additional chain to blockchain, and method and apparatus of generating shard for the same | |
CN113364874B (zh) | 基于区块链的节点同步方法、装置、存储介质及服务器 | |
WO2024113334A1 (zh) | 一种基于Raft改进的共识方法及相关设备 | |
US20240179018A1 (en) | Node selection method and apparatus, first node, storage medium, and program product | |
CN112258184B (zh) | 冻结区块链网络的方法、装置、电子设备及可读存储介质 | |
CN112054926B (zh) | 集群管理方法、装置、电子设备及存储介质 | |
CN114978913A (zh) | 一种基于切链的服务功能链跨域部署方法及系统 |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 23896117 Country of ref document: EP Kind code of ref document: A1 |
|
WWE | Wipo information: entry into national phase |
Ref document number: 11202308133Q Country of ref document: SG |