A method for selecting consensus nodes and related devices
By dynamically selecting consensus nodes in federated learning, using random numbers and distribution algorithms, the risk of consensus nodes being attacked is reduced, the security and stability of federated learning is improved, and the problem of excessive dependence of central servers is solved.
Patent Information
- Application Number
- CN202111651030.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-30
- Publication Date
- 2025-07-25
- Estimated Expiration
- 2041-12-30
AI Technical Summary
In the existing federated learning architecture, the dependence between clients and central servers is too large, resulting in the inability to generate accurate machine learning models in case of central server failure or malicious attacks, which poses security risks.
By obtaining information on the current training round, historical random numbers and global parameters from the previous round of federated learning from the chain node, the random numbers are calculated and the selection probability is generated. Combined with the random verifiable function and the binomial distribution algorithm, the consensus node is dynamically selected to reduce the risk of attack.
It improves the security of federated learning, reduces the risk of consensus nodes being attacked, and enhances the stability and security of the system.
Smart Images

Figure CN114372588B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of federated learning technology, and particularly to a method for selecting consensus nodes and related devices. Background Art
[0002] In order to achieve rapid learning to obtain a machine learning model, Google's Artificial Intelligence Laboratory proposed a federated learning architecture, specifically for enabling multiple decentralized clients and a central server to collaborate in learning a machine learning model to improve the efficiency of training to obtain a machine learning model. However, in the existing federated learning architecture, the collaboration between decentralized clients highly depends on the central server, that is, there is a problem of excessive dependence on the central server. Once the central server fails or is maliciously attacked, it will directly lead to the inability to generate an accurate machine learning model, or even the inability to generate a machine learning model. Therefore, blockchain technology is applied to federated learning. However, how to further reduce the risk of federated learning based on blockchain technology and further improve the security of federated learning is a technical problem that urgently needs to be solved at present. Summary of the Invention
[0003] The main technical problem to be solved by this application is to provide a method for selecting consensus nodes and related devices, which can reduce the risk of selecting consensus nodes and improve the security of federated learning.
[0004] To solve the above technical problem, a technical solution adopted by this application is: to provide a method for selecting consensus nodes, which is executed by a slave chain node in a slave chain. The slave chain includes a plurality of the slave chain nodes, and the slave chain nodes can interact with the master chain nodes in the master chain. The method includes:
[0005] The slave chain node obtains first-class information, where the first-class information includes at least one of current training round information, historical random numbers in the previous round of federated learning, the first global parameter output in the previous round of federated learning, and the number of consensus nodes to be selected in this round;
[0006] Calculate the random number of the current round based on the first-class information;
[0007] Calculate the selection probability of its own current round based on the random number;
[0008] If the selection probability is less than or equal to the comparison threshold, determine that it is selected as a consensus node in the current round.
[0009] Further, before calculating the selection probability of its own current round based on the random number, the method further includes:
[0010] Obtain preset security parameters and generate auxiliary global parameters based on the preset security parameters;
[0011] Generate a verification public key and a verification private key based on the auxiliary global parameters.
[0012] Furthermore, the calculating the selection probability of its own current round based on the random number further includes:
[0013] Generate a hash result by using a random verifiable function based on the random number and the verification private key;
[0014] Perform normalization processing on the hash result to obtain a normalized result, and output the normalized result as the selection probability.
[0015] Still further, the random verifiable function is announced by the system according to a preset rule based on the random number calculated in each round.
[0016] Further, the calculating the random number of the current round based on the first type of information includes:
[0017] If it is determined that the current round is the first round based on the current training round information, then determine the preset initial random number as the random number of the current round; or
[0018] If it is determined that the current round is not the first round based on the current training round information, then use the private key of the leading node of the publicity committee in the previous round to perform signature calculation on the first type of information to obtain the random number of the current round.
[0019] Further, before determining that it is selected as a consensus node in the current round if the selection probability is less than or equal to the comparison threshold, the method further includes:
[0020] The slave chain node calculates the comparison threshold by using the binomial distribution algorithm.
[0021] Furthermore, the calculating the comparison threshold by using the binomial distribution algorithm further includes:
[0022] Obtain second type of information, where the second type of information includes at least one of: a first processed value of the rewards obtained in the previous round of federated learning, the sum of the rewards obtained by each of the slave chain nodes in the previous round of federated learning, the number of consensus nodes to be selected in this round, and the number of valid rewards in the previous round of federated learning;
[0023] Based on the second type of information, obtain a binomial distribution result by using the binomial distribution algorithm;
[0024] Determine the comparison threshold in the current round based on the binomial distribution result.
[0025] Further, after determining that it is selected as a consensus node in the current round if the selection probability is less than or equal to the comparison threshold, the method further includes:
[0026] Sending a leader node application request to at least some of the slave chain nodes in the slave chain to be selected as the leader node; and / or
[0027] Receiving the first local parameter to be verified sent by the training node and performing consensus verification on the first local parameter.
[0028] To solve the above technical problems, another technical solution adopted by this application is: providing an electronic device, the electronic device includes a processor and a memory coupled to the processor; wherein,
[0029] The memory is used to store a computer program;
[0030] The processor is used to run the computer program to execute the method described in any one of the above.
[0031] To solve the above technical problems, yet another technical solution adopted by this application is: providing a computer-readable storage medium, the computer-readable storage medium stores a computer program that can be run by a processor, and the computer program is used to implement the method described in any one of the above.
[0032] The beneficial effect of this application is: different from the prior art, in the technical solution provided by this application, the slave chain nodes in the slave chain obtain the first type of information, and the first type of information includes at least one of the current training round information, the historical random number in the previous round of federated learning, the first global parameter output in the previous round of federated learning, and the number of consensus nodes to be selected in this round; after the slave chain node obtains the first type of information, it further calculates the random number of the current round based on the first type of information; then calculates its own selection probability of the current round based on the random number; and determines that it is selected as a consensus node in the current round when it is determined that the obtained selection probability is less than or equal to the comparison threshold. The method provided by this application can determine a dynamic random number by combining the first type of information that changes dynamically with the federated learning rounds, and then determine its own selection probability of the current round based on the random number, which can reduce the risk of being attacked in the process of selecting consensus nodes, improve the security of federated learning, and achieve good technical effects. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Figure 1 It is a schematic diagram of an application scenario of a method for selecting a consensus node in this application;
[0034] Figure 2 It is a schematic flowchart of an embodiment of a method for selecting a consensus node in this application;
[0035] Figure 3 Schematic flowchart of another embodiment of a method for selecting consensus nodes in this application;
[0036] Figure 4 Schematic flowchart of yet another embodiment of a method for selecting consensus nodes in this application;
[0037] Figure 5 Schematic structural diagram of an electronic device in an embodiment of this application;
[0038] Figure 6 Schematic structural diagram of a computer-readable storage medium in an embodiment of this application. Detailed implementation manners
[0039] Next, in combination with the accompanying drawings in the embodiments of this application, the technical solutions in the embodiments of this application will be clearly and completely described. It can be understood that the specific embodiments described herein are only used to explain this application, rather than limiting this application. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of this application.
[0040] In the description of this application, "a plurality of" means at least two, such as two, three, etc., unless otherwise specifically defined. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the listed steps or units, but optionally further includes unlisted steps or units, or optionally further includes other steps or units inherent to these processes, methods, products, or devices.
[0041] Referring to "embodiment" herein means that the specific features, structures, or characteristics described in connection with the embodiment can be included in at least one embodiment of this application. The phrase appears in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art will explicitly and implicitly understand that the embodiments described herein can be combined with other embodiments.
[0042] First, for the convenience of understanding the technical solutions provided by this application, the federated learning system to which the method provided by this application is applied is first described. Please refer to Figure 1 , Figure 1 Schematic diagram of the application scenario of a method for selecting consensus nodes in this application.
[0043] In the current embodiment, the method for selecting consensus nodes provided by the present application is applied to a federated learning system. The federated learning system 100 includes a slave chain A and a master chain B that can interact with each other. Among them, the slave chain A is a blockchain structure for training and obtaining target local parameters. The slave chain A includes several slave chain nodes ( Figure 1 as shown by A1 to Am). According to the functions performed by the slave chain nodes, the slave chain nodes include training nodes and consensus nodes. Specifically, it can be understood that according to the functions performed by each slave chain node in the current round, each slave chain node in the current slave chain A is divided into a training node and a consensus node. The master chain B is a consortium chain structure for executing and aggregating the target local parameters obtained by training the slave chain A to obtain global parameters. The master chain B includes several master chain nodes.
[0044] Furthermore, the slave chain node can be any one of electronic devices such as terminal devices, sensors, wearable devices, etc. that can perform training functions. And the slave chain nodes included in the same slave chain A can be different types of devices, which are not limited herein. For example, the device types of several slave chain nodes included in the same slave chain A can include terminal devices, intercom devices, sensors, and wearable devices. Each slave chain node and the user corresponding to the slave chain node have their own private keys and public keys. Among them, the hash value of the public key of the slave chain node can be used as the ID for identifying its identity and / or the wallet account address of the slave chain node.
[0045] As described above, according to the functions performed by the slave chain nodes in each round, the slave chain nodes can be classified into training nodes and consensus nodes. Among them, the training node is a slave chain node for executing training to obtain target local parameters, and the consensus node is a slave chain node for performing consensus verification on the local parameters obtained by training the training node. It should be noted that during the federated learning process of different rounds, the training nodes and the consensus nodes are both dynamically changing. For example, a certain slave chain node acts as a consensus node to perform the consensus verification function in the first round of training, and in the next round or other rounds, this slave chain node cannot act as a consensus node to perform the consensus verification function. As Figure 1 shown by A1 to An referring to the training nodes in the slave chain A in the current round of federated learning, and An+1 to Am referring to the consensus nodes in the current round of the slave chain A. An+1 to Am constitute the consensus committee 101.
[0046] Furthermore, it should be noted that when each slave chain node in the slave chain A executes the federated learning process of the current round, it is first necessary to clarify its own function in the current training round. Specifically, when executing the federated learning of the current round, any slave chain node within the slave chain can become a consensus node through a campaign, so as to obtain the qualification to perform consensus verification.
[0047] Each main-chain node can perform data interaction with at least some of the sub-chain nodes in Sub-chain A. The device types corresponding to the main-chain nodes include server devices and computer devices. It can be understood that in other embodiments, the main-chain nodes can also be other types of devices, which will not be enumerated one by one here. For example Figure 1 , Figure 1 as shown in B1 to Bk shown in refer to the main-chain nodes in Main-chain B.
[0048] Furthermore, the training node is used to train and obtain the first local parameter, and is also used to determine the first local parameter that has passed the consensus verification of the consensus committee as the target local parameter, and upload the target local parameter to the main-chain node. The consensus nodes in the sub-chain are used to perform consensus verification on the first local parameter obtained by the training node. In other embodiments, it can also be set that the target local parameter is uploaded to the main-chain node through the consensus node, specifically according to the actual settings.
[0049] Please refer to Figure 2 , Figure 2 which is a schematic flowchart of an embodiment of a method for selecting a consensus node in this application. In the current embodiment, the method provided in this application can be executed by any sub-chain node in the sub-chain. As described above, the sub-chain includes several sub-chain nodes, and the sub-chain nodes can directly interact with the main-chain nodes in the main-chain or indirectly interact through other nodes. Specifically, in the current embodiment, the method provided in this application includes S210 to S240. If a certain sub-chain node in the sub-chain expects to perform the consensus verification function in the current round of federated learning, then this sub-chain node needs to execute the following steps S210 to step S240 to become a consensus node in the current round of federated learning.
[0050] S210: The sub-chain node obtains the first type of information.
[0051] When the sub-chain node is running for a consensus node, the sub-chain node first needs to obtain the first type of information. In the current embodiment, the sub-chain node can obtain the first type of information from the chain of the sub-chain.
[0052] Among them, the first type of information includes at least one of the current training round information, the historical random number in the previous round of federated learning, the first global parameter output in the previous round of federated learning, and the number of consensus nodes to be selected in this round.
[0053] Specifically, the current training round information refers to the number of times of training the same global machine learning model using the federated learning system. For example, when the federated learning system is used for the first time to train and obtain a certain global machine learning model, the current training round information at this time is 1; when the federated learning system is used for the ninth time to train and obtain a certain global machine learning model, the current training round information at this time is 9.
[0054] The historical random number in the previous round of federated learning is the random number calculated when selecting members of the consensus committee in the previous round of federated learning. It should be noted that when selecting the consensus committee during the same round of federated learning, each sub-chain node in the chain will calculate the same random number based on the first type of information. However, in different rounds of training the same global machine learning model based on federated learning, the calculated random numbers may not be equal. It should be noted that if it is currently the first round of federated learning to select the consensus committee, the directly preset initial random number will be determined as the random number for the current round.
[0055] The first global parameter output by the previous round of federated learning is the global parameter finally aggregated by the main chain during the previous round of federated learning. If it is currently the first round of federated learning to select the consensus committee, the directly preset initial global parameter will be output as the first type of information for calculating the random number for the current round.
[0056] The number of consensus nodes to be selected in this round can be set according to requirements. Specifically, the main chain node in the main chain can adjust and set the number of consensus nodes to be selected in this round, and the main chain node can select different numbers of consensus nodes during different rounds of federated learning according to requirements.
[0057] S220: Calculate the random number for the current round based on the first type of information.
[0058] After obtaining the first type of information, further calculate the random number for the current round based on the obtained first type of information.
[0059] Further, in one embodiment, step S220 calculates the random number for the current round based on the first type of information, including: if it is determined that the current round is the first round based on the current training round information, the preset initial random number is determined as the random number for the current round.
[0060] In another embodiment, if it is determined that the current round is not the first round based on the current training round information, the private key of the leader node of the previous round's publicity committee is used to sign and calculate the first type of information to obtain the random number for the current round.
[0061] Specifically, the calculation formula for calculating the random number for the current round based on the first type of information is as follows:
[0062]
[0063] Among them, seed0 represents the initial random number, which can also be understood as the initialization random seed, that is, the preset random number for selecting consensus nodes in the first round of training, seed eIt represents the random number of the current round. "Epoch" refers to the information of the current training round. "Epoch = 1" indicates that the round of training a certain global machine learning model based on the current federated learning is the first round, and "epoch ≥ 1" indicates the second and subsequent rounds.
[0064] It represents the private key signature of the leader node (Leader) selected by the consensus nodes in the previous round of federated learning process.
[0065] "e" represents the information of the current training round, which is used to refer to the round of federated learning for the same machine learning model currently.
[0066] seed e-1 It represents the random number calculated when selecting consensus nodes in the previous round of training.
[0067] It represents the first global parameter obtained from the previous round of federated learning.
[0068] "τ" represents the number of consensus nodes to be selected in the current round of federated learning preset, and it can be set that the number of consensus nodes to be selected in different rounds of federated learning for the same machine learning model can be unequal, that is, the number of consensus nodes required in each round of federated learning process can be adjusted according to needs.
[0069] S230: Calculate the selection probability of its own current round based on the random number.
[0070] After calculating the random number, the chain node further calculates the selection probability of its own current round based on the random number. Among them, the selection probability refers to the probability that the chain node is selected as a consensus node in the current round.
[0071] Specifically, it is based on the verification private key of the chain node itself and the random number for hash operation to obtain a hash result, and then the hash result is normalized to obtain a normalized result, and the normalized result is determined as its own selection probability. Further, step S230 can refer to steps S303 to S304 in the embodiment corresponding to the following text. Figure 3 The corresponding steps S303 to S304 in the embodiment.
[0072] S240: If the selection probability is less than or equal to the comparison threshold, determine that it is selected as a consensus node in the current round.
[0073] After the slave chain node calculates its own selection probability for the current round, it further determines whether it is selected as a consensus node in the current round based on the selection probability. Specifically, it compares its own selection probability for the current round with the comparison threshold. If it is determined that the selection probability is less than or equal to the comparison threshold, it is determined that it is selected as a consensus node in the current round; otherwise, if it is determined that the selection probability is greater than the comparison threshold, it is determined that it is not selected as a consensus node in the current round, that is, in the current round of federated learning process, the slave chain node is a training node and is used to perform the function of training the first local parameter. When the slave chain node is selected as a consensus node, the slave chain node will perform the function of a consensus node in the current round. If the slave chain node determines that it is not selected as a consensus node in its own current round, the slave chain node will perform the function of a training node in the current round.
[0074] As described above, the slave chain in the federated learning system includes multiple slave chain nodes. For each slave chain node that expects to be selected as a consensus node and is successfully selected as a consensus node in the current round, the above steps S210 to S240 need to be executed.
[0075] This application Figure 2 In the corresponding embodiment, the slave chain node in the slave chain obtains the first type of information, where the first type of information includes at least one of the current training round information, the historical random number in the previous round of federated learning, the first global parameter output in the previous round of federated learning, and the number of consensus nodes to be selected in this round; after the slave chain node obtains the first type of information, it further calculates the random number for the current round based on the first type of information; then calculates its own selection probability for the current round based on the random number; and if it is determined that the selection probability is less than or equal to the comparison threshold, it is determined that it is selected as a consensus node in the current round. The method provided by this application can determine the dynamic random number by combining the first type of information that dynamically changes with the federated learning rounds, and then determine its own selection probability for the current round based on the random number, which can reduce the risk of being attacked during the process of selecting consensus nodes and improve the security of federated learning.
[0076] Please refer to Figure 3 , Figure 3 which is a schematic flowchart of another embodiment of a method for selecting a consensus node in this application. In the current embodiment, the method provided by this application includes steps S301 to S307.
[0077] S301: The slave chain node obtains the first type of information.
[0078] S302: Calculate the random number for the current round based on the first type of information.
[0079] In the current embodiment, steps S301 to S302 are respectively the same as the above steps S210 to S220. For specific details, reference can be made to the corresponding parts described above, and details will not be repeated here. In the current embodiment, before calculating the selection probability of the current round based on the random number in the above step S230, the method provided by the present application further includes steps S303 to S304.
[0080] S303: Obtain a preset security parameter, and generate an auxiliary global parameter based on the preset security parameter.
[0081] Among them, the global parameter is a parameter shared by each slave chain node in the chain. For each slave chain node that expects to run for the consensus node, before calculating the random number, it will also obtain a preset security parameter, and further generate an auxiliary global parameter based on the preset security parameter. Specifically, the slave chain node can obtain the global parameter from the chain of the slave chain.
[0082] Specifically, in one embodiment, the preset security parameter obtained by the slave chain node is 1 λ , then the slave chain node can generate an auxiliary global parameter common in the slave chain by calling a preset probability algorithm based on the preset security parameter. The formula is as follows: ParamGen(1 λ ) → pp. Where pp is the auxiliary global parameter, and ParamGen is the called probability algorithm. It can be understood that in other embodiments, the slave chain node can also call other types of probability algorithms, and it is not necessarily ParamGen here. Specifically, it can be based on actual settings.
[0083] S304: Generate a verification public key and a verification private key based on the auxiliary global parameter.
[0084] After calculating the auxiliary global parameter, the slave chain node further generates a verification public key and a verification private key based on the auxiliary global parameter. The slave chain node that intends to run for the consensus node generates a verification key and a verification private key based on the auxiliary global parameter generated by each of them by further using a key generation algorithm. Among them, the verification key and the verification private key are used in the process of performing consensus verification on the first local parameter uploaded by the training node after the election is successful.
[0085] For example, in one embodiment, the formula for generating a verification key and a verification private key based on the auxiliary global parameter is as follows: KeyGen(pp) → (PK i , SK i) Among them, KeyGen refers to the key generation algorithm. The input is the auxiliary global parameter pp. The generated verification public key and verification private key are represented by PK and SK respectively. The subscript i refers to the identification number of the slave chain node. Among them, the verification private key is used to perform consensus verification on the first local parameter uploaded by the training node after the slave chain node is selected as a consensus node, and when generating the consensus verification result, use this verification private key to sign and encrypt the consensus verification result, and then transmit the consensus verification result to other nodes or devices. The verification public key is used to decrypt the signature encryption of the verified private key. The verification public key will be published within the chain so that other slave chain nodes can obtain the data (such as the consensus verification result) encrypted by the signature of the verified private key based on the verification public key.
[0086] In the current embodiment, the above step S230 calculates its own selection probability for the current round based on a random number, and further includes steps S305 to S306.
[0087] S305: Based on the random number and the verification private key, use a random verifiable function to generate a hash result.
[0088] After obtaining the verification private key and the random number, further based on the random number and the verification private key, use a random verifiable function to generate a hash result. Among them, the random verifiable function is a function published by the system according to a preset rule based on the random number calculated in each round.
[0089] Furthermore, specifically, each (slave chain node intending to participate in consensus) calls the hash function in the random verifiable function to perform a hash operation on the verification private key and the random number to obtain a hash result.
[0090] For example, a slave chain node in the slave chain can call the VRF_Hash(.) function and use the verification private key and the random number obtained in the above steps as inputs to output a hash result, denoted as hash = VRF_val(SK,S e )
[0091] Furthermore, in another embodiment, while generating a hash result based on the random number and the verification private key using a random verifiable function, the method provided by the present application further includes: calculating a selection proof based on the verification private key and the random number. Specifically, it is to call the Prove function of VRF (i.e., VRF_proof(·)), use the verification private key and the random number obtained in the above steps as inputs, and output a selection proof π, denoted as π = VRF_proof(SK,Se). The calculated selection proof can be used for calling during the consensus verification process after being selected as a consensus node.
[0092] S306: Normalize the hash result to obtain a normalized result, and output the normalized result as the selection probability.
[0093] Normalize the hash results calculated by each slave node from the chain nodes, and output the normalized result obtained from the normalization process as the selection probability of the current slave node from the chain nodes in the current round.
[0094] Then compare the selection probability with the comparison threshold, and determine whether it is selected as the consensus node in the current round based on the comparison result. If the normalized result is less than or equal to the comparison threshold, the slave node from the chain can privately know that it is selected as the consensus node; otherwise, it knows that it is not selected as the consensus node.
[0095] Specifically, use the formula Calculate the normalized result d (which can also be understood as the selection probability) from the hash result. Among them, d also represents the difficulty value = maximum target value / current target value (the solution formula of d can also be understood as: the hash result to the power of 2 to the length of the hash result), d ∈ [0, 1), and hashlen represents the length of the hash result output by the hash algorithm (which can also be understood as the number of bits of the hash result).
[0096] Furthermore, the process of the slave node from the chain normalizing the hash result can also be understood as the process of converting the hash result to a value in the interval [0, 1).
[0097] Use λ to identify the comparison threshold. Furthermore, the comparison threshold can be calculated by constructing a binomial distribution function, and specifically, refer to the corresponding embodiments below Figure 4 The corresponding embodiments.
[0098] Furthermore, in an embodiment, the comparison threshold is obtained based on the second type of information. The second type of information includes at least one of the first processed value of the reward obtained by the slave node from the chain in the previous round of federated learning process, the sum of the rewards obtained by each slave node from the chain, the number of consensus nodes to be selected in this round, and the second processed value of the reward obtained by the slave node from the chain in the previous round of federated learning process. Specifically, based on the second type of information, use the binomial distribution algorithm to obtain the binomial distribution, and then determine the comparison threshold in the current round based on the binomial distribution result.
[0099] S307: If the selection probability is less than or equal to the comparison threshold, determine that it is selected as the consensus node in the current round.
[0100] In the current embodiment, step S307 is the same as the above step S240. Specifically, refer to the corresponding part of the above description, and details will not be repeated here.
[0101] In order to further improve the security of selecting consensus nodes, and to better select consensus nodes with stronger business capabilities, and to avoid the setting threshold remaining unchanged all the time and being easily maliciously attacked by attackers, before determining that itself is selected as a consensus node in the current round in step S240 if the selection probability is less than or equal to the comparison threshold, the method provided by this application further includes: calculating the comparison threshold from the chain nodes using the binomial distribution algorithm.
[0102] Further, please refer to Figure 4 , Figure 4 which is a schematic flowchart of another embodiment of a method for selecting consensus nodes in this application. In the current embodiment, the above step of calculating the comparison threshold from the chain nodes using the binomial distribution algorithm further includes steps S401 to S403.
[0103] S401: Obtain the second type of information.
[0104] When calculating the comparison threshold from the chain nodes using the binomial distribution algorithm, the second type of information will be obtained first. The from-chain nodes can obtain the second type of information from the chain of the sub-chain and / or its own storage area, specifically subject to actual settings.
[0105] Among them, the second type of information includes at least one of: the first processed value of the rewards obtained in the previous round of federated learning, the sum of the rewards obtained by each from-chain node in the from-chain in the previous round of federated learning, the consensus nodes to be selected in this round, and the number of valid rewards in the previous round of federated learning.
[0106] Specifically, the rewards obtained in the previous round of federated learning refer to the rewards obtained by the from-chain nodes in the previous round of federated learning. The first processed value of the rewards obtained in the previous round of federated learning refers to: the value obtained after standard integerization of the rewards obtained by the from-chain nodes in the previous round of federated learning. For example, when the rewards obtained by the from-chain node in the previous round of federated learning are recorded as m i , then it will be calculated according to the standard integerization formula where, is the average value of the rewards obtained by all from-chain nodes in the previous round of federated learning, is the standard deviation of the rewards obtained by all from-chain nodes in the previous round of federated learning. For example, when m i = 8.6, based on the average value of all rewards and the standard deviation and using the above standard integerization formula to standardize 8.6, the obtained first processed value is 10.
[0107] Among them, the larger the value of m i , the more times the from-chain node is allowed to draw lots, and the greater the probability of being selected as a consensus node.
[0108] The sum of the rewards obtained by each sub-chain node in the previous round of federated learning in the sub-chain can be obtained based on the rewards obtained by each sub-chain node in the previous round of federated learning. Specifically, if the sum of the rewards obtained by each sub-chain node in the previous round of federated learning in the sub-chain is denoted as R, then R = ∑m i .
[0109] The number of effective rewards in the previous round of federated learning refers to the increased rewards of the sub-chain nodes in the previous round of federated learning. It should be noted that if, during the previous round of federated learning, the accuracy of the first global parameter decreased due to the first local parameters provided by the sub-chain nodes, and a certain number of digital tokens were deducted or no rewards were obtained, it can be understood that the rewards obtained by the sub-chain nodes are negative at this time, and the effective rewards of the sub-chain nodes at this time are 0.
[0110] S402: Obtain the binomial distribution result using the binomial distribution algorithm based on the second type of information.
[0111] After obtaining the second type of information, further use the binomial distribution algorithm to obtain the binomial distribution result. Among them, the binomial distribution result is constructed based on the following formula:
[0112]
[0113] Among them, the constructed binomial distribution represents the probability that a certain sub-chain node i is selected as the consensus node after multiple draws.
[0114] Among them: B(.) represents the binomial distribution algorithm.
[0115] m represents the reward obtained by each sub-chain node (sub-chain node i) during the previous round of federated learning. Further, here m is the value obtained by standard integerizing the rewards obtained by the sub-chain nodes, specifically calculated based on the above standard integerization formula.
[0116] R = ∑r i Represents the sum of the rewards of all participating sub-chain nodes in one round of training.
[0117] k represents the number of consensus nodes expected to be selected in this round of model training. For example, when a certain sub-chain node m i = 10, k = 4 means that the sub-chain node is allowed to draw 10 times, and 4 of the lots are written as "selected", that is, there are 4 possibilities to be drawn as the consensus node.
[0118] τ represents the effective reward value, and all "effective" refers to the sub-chain nodes that have actually contributed to the first global parameter in the previous round of model training.
[0119] Among them, is used to represent the probability of being selected as a consensus node in a single lottery draw.
[0120] S403: Determine the comparison threshold in the current round based on the binomial distribution result.
[0121] After calculating the binomial distribution result, further determine the comparison threshold in the current round based on the binomial distribution result. Specifically, it can be to use the binomial distribution result to determine the cumulative probability density curve of the binomial distribution, and determine the selection result based on the cumulative probability density curve and the normalization result.
[0122] After completing the construction of the binomial distribution, further determine the cumulative probability density curve of the currently constructed binomial distribution:
[0123] Each slave chain node conducts a lottery draw from 0 to m times, and accumulates the probability of each lottery draw, which is recorded as the probability of the slave chain node being drawn. Finally, based on the cumulative probability density curve of the determined binomial distribution and the normalization result of the hash result d, determine whether it can become a consensus node.
[0124] Specifically, if the normalization result d satisfies d < f(j), then record j = 0, indicating that the slave chain node is not selected in this election for the consensus node; if there exists a j in the above curve that satisfies f(j) ≤ d < f(j + 1), record the value of j at this time, and further determine whether the current j is greater than zero. If it is determined that j > 0 such that f(j) ≤ d < f(j + 1) holds, then the slave chain node successfully becomes a consensus node in the current round of the federated learning process. Further, when the slave chain node is successfully drawn as a consensus node, the consensus node will announce its own hash result, selection proof, and the draw count j that makes the formula f(j) ≤ d < f(j + 1) hold to other slave chain nodes.
[0125] In another embodiment, determining the selection result based on the cumulative probability density curve and the normalization result is to determine whether the normalization result obtained by normalizing the hash result belongs to the interval where the set threshold is located. Specifically, it can also be understood as a process of determining whether the following formula holds:
[0126] Among them, the interval range corresponding to the set threshold λ is as follows: Determine whether the normalization result d is within the set threshold range; if it is within this range, it means that the current slave chain node is selected as the consensus node of the current round of federated learning, and if it is not within this range, it means that the current slave chain node is not selected as the consensus node.
[0127] Further, in the technical solution provided by this application, if the selection probability is less than or equal to the comparison threshold, after determining that it is selected as a consensus node in the current round, the method provided by this application further includes: sending a leader node application request to at least some of the slave chain nodes in the slave chain to select to become a leader node (Leader node).
[0128] First, according to the above method, multiple consensus nodes are selected from several slave chain nodes in the slave chain, and the selected multiple consensus nodes form a consensus committee for the current round of federated learning process. Then, these consensus nodes can each independently send requests to all slave chain nodes in the slave chain to elect themselves as leader nodes, requesting other slave chain nodes to vote for themselves. Then wait for a set time, during which each slave chain node chooses to conduct a leader node voting election. Within a certain time (counted by a timer), the consensus node with the most votes will become the leader node for the current round of federated learning process. The leader node has the function of sending instructions to other slave chain nodes in the slave chain. For example, if a certain slave chain node uploads the first local parameter, and the first local parameter passes the consensus verification of the consensus nodes in the consensus committee and is determined to be the target local parameter, the leader node is used to send instructions for ledger synchronization to other slave chain nodes in the slave chain, so that each slave chain node in the slave chain saves the target local parameter to its own distributed ledger.
[0129] Furthermore, if during the process of selecting the leader node, it is determined through the vote count of the consensus nodes that two (or more) consensus nodes have equal votes, the method provided by this application further includes: initiating a new round of voting election process for the consensus nodes with equal votes. The consensus node with the most votes in the new round of voting election process becomes the leading consensus node.
[0130] Furthermore, in another embodiment, if during the process of selecting the leader node, it is determined through the vote count of the consensus nodes that two (or more) consensus nodes have equal votes, the final leader node can be further determined by combining the scores and / or rewards obtained by each consensus node. Specifically, the consensus node with the highest score and / or the most rewards obtained is determined as the leader node in the current round of federated learning.
[0131] Specifically, the technical solution provided by this application completes the consensus verification of the first local parameter by optimizing the traditional RAFT consensus.
[0132] Further, after the slave chain node is selected as a consensus node, the slave chain node is further used to receive the first local parameter to be verified sent by the training node and perform consensus verification on the first local parameter.
[0133] The process of consensus verification is as follows: Continuing with the above example, the leading node in the consensus committee packages the first local parameter (w) transmitted by the training node, along with the selection proof and random number generated during the process of the training node competing for the consensus node (selection proof: π, random number: seede), into a candidate block, and then broadcasts the candidate block to the consensus nodes in the sub-chain. After receiving the candidate block, the consensus nodes will convert the selection proof (π) in the candidate block into a hash value, that is, perform a hash operation on the selection proof in the candidate block to obtain VRF_proof_to_hash(π). Verify whether VRF_verify(PK, w, π, seede) = True / False, and use the public key of the leading node to check whether the selection proof π is a proof generated based on the original parameter w, that is, check whether VRF_hash(SK, w) is equal to VRF_proof_to_hash(π), and output whether it is legal. If it is legal, the candidate block passes the consensus verification and becomes a valid block, that is, it is determined that the first local parameter is obtained by training based on the legal data stored by itself. Here, SK is the verification private key generated by the sub-chain node during the process of competing for the consensus node, and PK is the public key of the leading node.
[0134] Please refer to Figure 5 , Figure 5 which is a schematic structural diagram of an electronic device according to an embodiment of the present application. In the current embodiment, the electronic device 500 provided by the present application includes a processor 501 and a memory 502 coupled to the processor 501. The electronic device 500 can execute Figures 1 to 4 the method in and any corresponding embodiment thereof, that is, the electronic device 500 can be a server or a client.
[0135] Among them, the memory 502 includes local storage (not shown in the figure), and is used to store a computer program, and when the computer program is executed, it can implement Figures 1 to 4 the method in and any corresponding embodiment thereof.
[0136] The processor 501 is coupled to the memory 502, and the processor 501 is used to run the computer program to execute the above Figures 1 to 4 and the method in any corresponding embodiment thereof.
[0137] Further, in some embodiments, the electronic device 500 may include any one of a mobile terminal, a handheld terminal, a wearable device, a vehicle-mounted terminal, a computer terminal, a server, and other types of electronic devices with computing and storage capabilities.
[0138] Refer to Figure 6 , Figure 6Schematic structural diagram of an embodiment of a computer-readable storage medium of the present application. The computer-readable storage medium 600 stores a computer program 601 that can be run by a processor. The computer program 601 is used to implement the method described in the above Figures 1 to 4 and any one of its corresponding embodiments. Specifically, the above computer-readable storage medium 600 may be one of a memory, a personal computer, a server, a network device, or a USB flash drive, etc., and no specific limitation is made here.
[0139] The above is only the implementation manner of the present application, and does not limit the patent scope of the present application. Any equivalent structural or equivalent process transformation made by using the content of the specification and drawings of the present application, or directly or indirectly applied in other related technical fields, shall be equally included in the patent protection scope of the present application.
Claims
1. A method for selecting consensus nodes, characterized in that, The method is executed by slave chain nodes in a slave chain. The slave chain includes a plurality of the slave chain nodes, and the slave chain nodes can interact with master chain nodes in a master chain. The master chain is used to execute aggregating target local parameters obtained from slave chain training to obtain global parameters. The method includes: A slave chain node obtains first type of information, where the first type of information includes at least one of current training round information, historical random numbers in the previous round of federated learning, first global parameters output in the previous round of federated learning, and the number of consensus nodes to be selected in this round. Calculate a random number for the current round based on the first type of information. Calculate its own selection probability for the current round based on the random number. If the selection probability is less than or equal to a comparison threshold, determine that it is selected as a consensus node in the current round. Wherein, the comparison threshold is calculated based on second type of information, and the second type of information includes at least one of: a first processed value of the reward obtained in the previous round of federated learning, the sum of the rewards obtained by each of the slave chain nodes in the slave chain in the previous round of federated learning, the consensus nodes to be selected in this round, and the number of valid rewards in the previous round of federated learning. Before calculating its own selection probability for the current round based on the random number, the method further includes: obtaining a preset security parameter, and generating an auxiliary global parameter based on the preset security parameter; generating a verification public key and a verification private key based on the auxiliary global parameter.
2. The method according to claim 1, wherein The calculating its own selection probability for the current round based on the random number further includes: Generating a hash result by using a random verifiable function based on the random number and the verification private key. Performing a normalization process on the hash result to obtain a normalized result, and outputting the normalized result as the selection probability.
3. The method according to claim 2, wherein The random verifiable function is announced by the system according to a preset rule based on the random number calculated in each round.
4. The method according to claim 1, wherein The calculating a random number for the current round based on the first type of information includes: If it is determined that the current round is the first round based on the current training round information, determine a preset initial random number as the random number for the current round; or If it is determined that the current round is not the first round based on the current training round information, perform a signature calculation on the first type of information by using the private key of the leading node of the previous round's publicity committee to obtain the random number for the current round.
5. The method according to claim 1, characterized in that, Before the step of if the selection probability is less than or equal to a comparison threshold, determine that it is selected as a consensus node in the current round, the method further includes: The slave chain node calculates the comparison threshold by using the binomial distribution algorithm.
6. The method according to claim 5, characterized in that, The calculating the comparison threshold by using the binomial distribution algorithm further includes: Obtaining the second type of information; Based on the second type of information, obtaining a binomial distribution result by using the binomial distribution algorithm; Determining the comparison threshold in the current round based on the binomial distribution result.
7. The method according to claim 1, wherein After the step of if the selection probability is less than or equal to a comparison threshold, determine that it is selected as a consensus node in the current round, the method further includes: Sending a leading node application request to at least some of the slave chain nodes in the slave chain to be selected as the leading node; and / or Receive the first local parameter to be verified sent by the training node, and perform consensus verification on the first local parameter.
8. An electronic device, characterized in that, The electronic device includes a processor and a memory coupled to the processor; wherein, The memory is used to store computer programs; The processor is used to run the computer program to execute the method according to any one of claims 1 to 7.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that can be run by a processor, and the computer program is used to implement the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Federated learning defense method based on block chain
CN112434280A
Federal learning method and related device
CN114372589A