Data storage method, device, equipment and computer storage medium
By using the classification weighting algorithm in the blockchain system to select the consensus node with the highest creditworthiness as the main consensus node, the problem of data storage efficiency decline caused by node downtime or tampering is solved, and more efficient data storage is achieved.
Patent Information
- Application Number
- CN202110548469.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-05-19
- Publication Date
- 2025-05-16
- Estimated Expiration
- 2041-05-19
AI Technical Summary
In massive data storage scenarios, when blockchain technology stores data, the main consensus node is down or tampered, causing the process of reselecting the main consensus node to take a long time, resulting in a decrease in data storage efficiency.
A classification weighting algorithm is used to select the consensus node with the highest credit level from multiple consensus nodes as the main consensus node, and perform data consensus based on the node to generate block and signature information to reduce time waste caused by node downtime or tampering.
By reducing the time consumption of reselecting the main consensus node, the efficiency of data storage is improved and the risks caused by the downtime or tampering of the consensus node are reduced.
Smart Images

Figure CN115374214B_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of blockchain technology and big data technology, and in particular, relates to a data storage method, device, equipment and computer storage medium. Background Art
[0002] We have entered the era of data technology (DT), and data is growing faster and faster. Therefore, how to store massive data efficiently, reliably and securely is an urgent problem that needs to be solved.
[0003] Blockchain can be understood as a distributed database in essence. The data or information stored in the blockchain has the characteristics of being unforgeable, fully traceable, traceable, open and transparent, and collectively maintained. Therefore, in the decentralized storage method based on blockchain storage technology, the rights and interests of each node are the same, the nodes are highly available, and the data storage is transparent and cannot be tampered with.
[0004] However, in massive data storage scenarios, when storing data through blockchain technology, if the main consensus node goes down or is tampered with, reselecting the main consensus node requires repeating the consensus process continuously, resulting in a long node consensus process, which in turn leads to a serious decline in data storage efficiency. Summary of the invention
[0005] The embodiments of the present application provide a data storage method, apparatus, device, and computer storage medium, which can reduce the risk of selecting a down or tampered consensus node as a master consensus node, avoid the time consumption problem caused by reselecting the master consensus node, and thus improve data storage efficiency.
[0006] In a first aspect, the present invention provides a data storage method, which is applied to a blockchain system, wherein the blockchain system includes a submission node and a plurality of consensus nodes, and the method includes:
[0007] Receiving a data storage request sent by a blockchain application, wherein the blockchain application is an application that establishes a connection with a blockchain system, and the data storage request includes data to be stored of the blockchain application;
[0008] Based on the classification weighted algorithm, select the consensus node with the highest credibility from the multiple consensus nodes as the main consensus node;
[0009] According to the master consensus node and the classification weighted algorithm, consensus is reached on the data to be stored, and a block and signature information of the block are generated, wherein the block is used to indicate a data packet after consensus on the data to be stored;
[0010] The block and the signature information of the block are sent to the submission node, so that the submission node verifies the signature information of the block and stores the block in the blockchain.
[0011] In a second aspect, the present invention provides a data storage device for use in a blockchain system, wherein the blockchain system includes a submission node and a plurality of consensus nodes, and the device includes:
[0012] A receiving module, configured to receive a data storage request sent by a blockchain application, wherein the blockchain application is an application that establishes a connection with a blockchain system, and the data storage request includes data to be stored of the blockchain application;
[0013] A selection module is used to select the consensus node with the highest credibility from the multiple consensus nodes as the main consensus node based on a classification weighted algorithm;
[0014] A generation module, used to reach a consensus on the data to be stored according to the main consensus node and the classification weighted algorithm, and generate a block and signature information of the block, wherein the block is used to indicate a data packet after the consensus of the data to be stored;
[0015] A sending module is used to send the block and the signature information of the block to the submission node, so that the submission node verifies the signature information of the block and stores the block in the blockchain.
[0016] In a third aspect, an embodiment of the present application provides a data storage device, the device comprising:
[0017] a processor and a memory storing computer program instructions;
[0018] When the processor executes the computer program instructions, the data storage method described in the first aspect of the above embodiment is implemented.
[0019] In a fourth aspect, an embodiment of the present application provides a computer storage medium having computer program instructions stored thereon, and when the computer program instructions are executed by a processor, the data storage method described in the first aspect of the above-mentioned implementation manner is implemented.
[0020] The data storage method, device, equipment and computer storage medium of the embodiment of the present application, based on the classification weighted algorithm, evaluates the credibility of all consensus nodes, selects the consensus node with the highest credibility as the main consensus node, thereby reducing the problem of time waste caused by reselecting the main consensus node due to the consensus node being tampered or down as the main consensus node, and then, based on the selected main consensus node, using the classification weighted algorithm, consensus is reached on the data to be stored, and then blocks and signature information are generated, and the blocks and signature information are sent to the submission node for storage. In this way, the data storage method of the present application can reduce the time consumption in the consensus process and improve the data storage efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solution of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0022] Figure 1 This is a system architecture diagram of a blockchain system provided by an embodiment of the present application;
[0023] Figure 2 It is a flowchart of a data storage method provided by an embodiment of the present application;
[0024] Figure 3 This is a main flow chart of data storage in an exemplary blockchain system provided by an embodiment of the present application;
[0025] Figure 4 is a schematic diagram of the structure of a data storage device provided by an embodiment of the present application;
[0026] Figure 5 It is a structural schematic diagram of a data storage device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0027] The features and exemplary embodiments of various aspects of the present application will be described in detail below. In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain the present application, rather than to limit the present application. For those skilled in the art, the present application can be implemented without the need for some of these specific details. The following description of the embodiments is only to provide a better understanding of the present application by illustrating the examples of the present application.
[0028] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "include..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0029] In order to facilitate a detailed explanation of the technical solution of a data storage method of the present application, the system architecture of the blockchain system involved in the present application and the role types in the blockchain system are briefly described below.
[0030] first, Figure 1 The system architecture diagram of the blockchain system provided by one embodiment of the present application is shown. Figure 1 As shown, the system architecture of the blockchain system in this application includes a smart contract network layer, a consensus layer, a data layer, and an application layer. Specifically, each layer of the blockchain system is briefly introduced below.
[0031] Smart contract network layer: defines that the underlying blockchain system uses a peer-to-peer (P2P) protocol to transmit blocks, and provides a containerized way for clients to transmit data by calling an application program interface (API).
[0032] Consensus layer: The manager node is responsible for collecting data from the consensus process, such as the number of times each consensus node was elected as the master node, consensus voting status, normal operation time, etc. The consensus layer uses a consensus algorithm based on classification weighting, which optimizes the shortcomings of the existing Practical Byzantine Fault Tolerance (PBFT) algorithm to achieve consensus among the consensus nodes.
[0033] Data layer: Blockchain system data is stored in CouchDB (an open source document-oriented database) or LevelDB (Google's open source persistent stand-alone database). For example, the operator's massive signaling data and call data are stored in the form of key-value pairs (KV). Every time the underlying data of the blockchain is changed, it will be recorded in the ledger and the operation log will be stored in the ledger to prevent tampering and track the history of data changes.
[0034] Application layer: defines the application system that stores data based on the blockchain system at the bottom of the blockchain system. For example, in a recruitment system based on massive location data analysis, each application layer system can store data in the blockchain based on the smart contract network layer API interface.
[0035] Secondly, according to the connection between the various levels of the above blockchain system, the blockchain system in this application mainly includes three types of roles, namely, client, peer node and consensus node. Specifically, the three types of roles of the blockchain system are briefly described below.
[0036] Client (i.e. blockchain application): The client calls the API interface of the blockchain system and sends the transaction request to the blockchain network. For example, the operator system can store user call record data in the blockchain network by calling the API interface.
[0037] Peer node: Peer node is mainly responsible for maintaining the blockchain ledger, and can be divided into endorsing peers and committing peers. Endoring peers endorse transactions, verify requests, and sign requests, while committing peers receive packaged blocks and then write them into the blockchain network.
[0038] Consensus node: receives transaction information sent by the client, sorts it according to the consensus algorithm, packages it into blocks, puts it into the blockchain network, and finally returns the result to the Committing Peer, which then performs data preservation operations.
[0039] Based on the system architecture of the above-mentioned blockchain system and the definition of three types of roles, the embodiments of the present application provide a data storage method, apparatus, device and computer storage medium, which are applied to the blockchain system. The data storage method provided in the embodiments of the present application is first introduced below.
[0040] Figure 2 A schematic diagram of a data storage method provided by an embodiment of the present application is shown. Figure 2As shown, the following steps are included:
[0041] Step 201, receiving a data storage request sent by a blockchain application, wherein the blockchain application is an application that establishes a connection with a blockchain system, and the data storage request includes data to be stored of the blockchain application;
[0042] Step 202: Based on the classification weighted algorithm, select the consensus node with the highest credibility from the multiple consensus nodes as the main consensus node;
[0043] Step 203: according to the master consensus node and the classification weighted algorithm, consensus is reached on the data to be stored, and a block and signature information of the block are generated, wherein the block is used to indicate a data packet after consensus on the data to be stored;
[0044] Step 204: Send the block and the signature information of the block to the submission node, so that the submission node verifies the signature information of the block and stores the block in the blockchain.
[0045] Based on this, in the embodiment of the present application, based on the classification weighted algorithm, all consensus nodes are evaluated for their credibility, and the consensus node with the highest credibility is selected as the main consensus node, thereby reducing the time wasted by reselecting the main consensus node due to the consensus node being tampered with or downtime as the main consensus node. Then, based on the selected main consensus node, the classification weighted algorithm is used to reach a consensus on the data to be stored, and then the block and signature information are generated, and the block and signature information are sent to the submission node for storage. In this way, through the data storage method of the present application, the time consumption in the consensus process can be reduced and the data storage efficiency can be improved.
[0046] In the above step 201, the blockchain application can send the data to be stored to the consensus node in the blockchain network by calling the API interface of the blockchain system smart contract network layer, and the consensus node receives the data storage request sent by the blockchain application.
[0047] The data storage request may include the data to be stored of the blockchain application and signature information of the data to be stored, and the signature information may be used to verify the data to be stored.
[0048] In the above step 202, the consensus node needs to sort the data to be stored in the received data storage request by consensus. Therefore, it is first necessary to select a master consensus node from multiple consensus nodes to initiate a consensus request. In this step, a classification weighted algorithm can be used to select the consensus node with the highest credibility among multiple consensus nodes as the master consensus node.
[0049] Specifically, the above classification weighted algorithm is based on selecting the consensus node with the highest credibility from the multiple consensus nodes as the main consensus node, which can be completed by the following steps:
[0050] Acquire feature vectors of the plurality of consensus nodes within a preset time period, wherein the feature vectors are feature vectors corresponding to a plurality of predefined feature attributes respectively;
[0051] Inputting the feature vector into a pre-trained classification model to obtain the credibility corresponding to each of the multiple consensus nodes;
[0052] Any consensus node among the multiple consensus nodes with the highest credibility is determined as the main consensus node.
[0053] Based on this, through the classification weighted algorithm, the consensus node with the highest credibility among multiple consensus nodes is selected as the main consensus node, which can prevent the selection of tampered or down consensus nodes as the main consensus nodes, thereby avoiding the time consumption problem caused by reselecting the main consensus node and improving the consensus efficiency.
[0054] The above-mentioned feature vectors may be feature vectors corresponding to different feature attributes predefined according to actual needs. For example, the feature attributes shown in Table 1 may be predefined.
[0055] Table 1 Feature attribute table
[0056]
[0057] Then, the feature vectors corresponding to multiple consensus nodes can be obtained according to the feature attributes in Table 1. For example, through the ManagerNode node, at 2 o'clock, the feature vectors corresponding to the feature attributes of each consensus node from 1:50 to 2:00 are collected in real time, and the obtained feature vectors are input into the pre-trained classification model to calculate the corresponding credit of each consensus node. The calculation results are shown in Table 2.
[0058] Table 2 Characteristic vector and credit table
[0059]
[0060] According to Table 2, the credibility "1" is the highest credibility, that is, the node Peer2 can be selected as the main consensus node.
[0061] It should be noted that the above-mentioned consensus node with the highest credibility may include multiple consensus nodes with the same credibility, and any one of the multiple consensus nodes with the same credibility can be selected as the main consensus node.
[0062] In addition, when selecting the main consensus node using the classification weighted algorithm, it is necessary to calculate the credibility of the consensus node by pre-training the classification model. The process of training the classification model can be completed through the following steps:
[0063] 1. Obtain a training sample set, wherein the training sample set includes information of multiple sample consensus nodes, wherein each sample consensus node information includes a feature vector of the sample consensus node and a label credibility corresponding to the sample consensus node, wherein the feature vector of the sample consensus node is a feature vector corresponding to multiple predefined feature attributes, and the label credibility is a credibility calculated based on the feature vector of the sample consensus node.
[0064] In an example of the present application, the feature vectors of the sample consensus nodes corresponding to the feature attributes shown in Table 1 can be selected, and the label credibility of the sample consensus nodes can be calculated based on the selected feature vectors. Specifically, the credibility score of each consensus node can be calculated based on the proportion of normal operation time and the proportion of correct times of the determined data, and then based on the credibility score, the credibility of each consensus node can be determined. The specific calculation method can be as follows:
[0065] Normal operation time ratio = normal operation time / 10 minutes;
[0066] The percentage of correct data = correct data / total number of votes;
[0067] Sort the normal operation time percentage from high to low. The higher the percentage, the higher the ranking. We can get the normal operation time percentage ranking of the consensus node f n ;
[0068] The correct number of times the data is judged is sorted from high to low. The higher the proportion, the higher the ranking. The correct number of times the data is judged by the consensus node can be ranked f m ;
[0069] According to the following formula 1, the score of each consensus node is calculated:
[0070] score=f m *0.5+f n *0.5 Formula 1
[0071] The scores of each consensus node are sorted from high to low, and the consensus nodes in the top 1 / 4 of the scores are marked as high credit, defined as 1; the consensus nodes in the top 1 / 4-1 / 2 of the scores are marked as high credit, defined as 2, the consensus nodes in the top 1 / 2-3 / 4 of the scores are marked as medium credit, defined as 3, and the remaining 1 / 4 of the consensus nodes are marked as low credit, defined as 4. The calculation results of the final sample can be shown in Table 3.
[0072] It should be noted that after obtaining the sample information shown in Table 3, it is necessary to perform a correlation analysis on any two sample consensus node feature vectors, and select only one of the sample consensus node feature vectors with a correlation coefficient greater than 0.9 to determine the final training sample set. The correlation coefficient formula between two sample consensus node feature vectors is shown in the following formula 2:
[0073]
[0074] Among them, X and Y represent the feature vectors of two sample consensus nodes; D(X) represents the variance of X data, D(Y) represents the variance of Y data, and Cov(X,Y) represents the covariance matrix of X and Y data.
[0075] Table 3 Sample consensus node information table
[0076]
[0077] 2. Using the information of multiple sample consensus nodes in the training sample set to train a preset classification model until a training stop condition is met, thereby obtaining a trained classification model.
[0078] Specifically, for each sample consensus node information, the following steps are performed respectively:
[0079] Inputting the feature vector of the sample consensus node into a preset classification model to obtain the predicted credibility of the sample consensus node;
[0080] When the prediction confidence is inconsistent with the label confidence of the sample consensus node, the model parameters of the preset classification model are adjusted, and the adjusted classification model is trained using the feature vector of the sample consensus node until the prediction confidence meets the training stop condition, thereby obtaining the trained classification model.
[0081] In the embodiment of the present application, after obtaining the training sample set, the classification model can be trained using the naive Bayes algorithm. As an example, the steps of the naive Bayes algorithm can be as follows:
[0082] Step 1: Assume x = {a1, a2, a3...a r}, is an item to be classified (i.e., the feature vector combination of sample consensus nodes), where a r is the feature vector corresponding to a feature attribute of x, and r means x has r feature attributes. As an example, a r The values of can be as follows:
[0083] a1 = normal operation time of the node within 10 minutes;
[0084] a2 = the duration of node disconnection within 10 minutes;
[0085] a3 = the number of times the master node is elected within 10 minutes;
[0086] a4=number of votes taken within 10 minutes;
[0087] a5 = the number of correct data within 10 minutes;
[0088] a6 = the number of times data errors are determined within 10 minutes.
[0089] Step 2: Assume that there is a category set C = {y1, y2, y3...y k}, combined with the example of this application, C = {high credit, relatively high credit, medium credit, low credit}.
[0090] Step 3: According to the Bayesian principle, the probability of the item to be classified in each category is calculated by formula 3:
[0091]
[0092] Since P(x1, x2, x3…x n ) is the same for all classification probabilities, so Formula 3 can be simplified to Formula 4:
[0093] P(y k |x1,x2,x3...x n )=P(x1,x2,x3…x n |y k )P(y k ) Formula 4
[0094] Where P(y k ) represents the probability of high credit, relatively high credit, medium credit and low credit;
[0095] P(x1, x2, x3...x n |y k ) can be expressed as the probability of occurrence of each feature variable combination under different credit levels. Since each feature variable is independent of each other, P(x1, x2, x3...x n |y k ) can be transformed into Formula 5:
[0096] P(x1, x2, x3…x n |y k )=P(x1|y k )*P(x2|y k )*P(x3|y k )...P(x n |y k ) Formula 5
[0097] Where P(x n |y k ) are Gaussian distributed.
[0098] By calculating the mean and variance of the feature variable in each category, μ is expressed as the mean on the yk class, δ 2 Indicated as k The variance of the class. k The probability P(x) of a value in the class n |y k ), we can n Expressed as mean μ and variance δ 2 The normal distribution of can be calculated by the following formula 6:
[0099]
[0100] Combined with the example of this application, the high credit classification can be calculated by the following formula 7:
[0101] P(x1, x2, x3...x n |y k )
[0102] =P(node normal operation time within 10 minutes | high credit)
[0103] *P(node disconnection duration within 10 minutes | high credit)
[0104] *P (number of times a master node is elected within 10 minutes | high credit)
[0105] *P(number of votes participated in within 10 minutes|high credit)
[0106] *P (number of times data is judged to be correct within 10 minutes | high credit)
[0107] *P(Number of data errors within 10 minutes|High credit)
[0108] Formula 7
[0109] Step 4: According to the above steps 1 to 3, calculate P(x1, x2, x3...x n | high credit), P(x1, x2, x3...x n | higher credit), P(x1, x2, x3...x n | in credit), P(x1, x2, x3...x n | low credit), that is, to find max(P(x1, x2, x3...x n |y k )P(yk )), and then classify the credibility of the consensus nodes according to the highest probability value. According to the example of this application, the credibility categories can be represented as "high credibility" = 1, "relatively high credibility" = 2, "medium credibility" = 3, and "low credibility" = 4.
[0110] It should be noted that after the prediction credibility corresponding to each consensus node is calculated through the naive Bayes algorithm, the prediction credibility can be matched with the label credibility corresponding to each consensus node. When the prediction credibility and the label credibility are inconsistent, it is necessary to adjust the model parameters of the preset classification model and continue to train the adjusted classification model through feature vector combination until the prediction credibility meets the training stop condition to obtain the trained classification model.
[0111] Among them, the above-mentioned training stop condition can be that the prediction confidence calculated by the classification model is consistent with the label confidence, or that the difference between the prediction confidence calculated by the classification model and the label confidence meets the preset condition. The training stop condition can be set according to specific needs and is not limited here.
[0112] In addition, it should be noted that the above-mentioned trained classification model needs to be updated regularly to ensure the calculation accuracy of the classification model.
[0113] Based on this, the classification model obtained by training with information of multiple sample consensus nodes can accurately determine the credibility of each consensus node, so that the optimal consensus node can be selected as the main consensus node, thereby improving data storage efficiency. Moreover, before training the classification model, the feature vectors of any two sample consensus nodes are screened and optimized, and one of the feature vectors of multiple sample consensus nodes with a high correlation coefficient is selected to train the model, ensuring that the feature vectors of each sample consensus node in the model are independent of each other.
[0114] In the above step 203, the main consensus node selected in the above step 202 can initiate a consensus vote to other consensus nodes among the multiple consensus nodes. Specifically, it can use a classification weighted algorithm to reach a consensus on the data to be stored and generate blocks and signature information of the blocks.
[0115] Among them, the above-mentioned use of the classification weighted algorithm to reach consensus on the stored data and generate blocks and block signature information can be completed through the following steps:
[0116] The master consensus node sends a consensus request to each first consensus node, wherein the first consensus node is a consensus node other than the master consensus node among the multiple consensus nodes, and the consensus request includes the data to be stored and signature information of the data to be stored;
[0117] In the case where the first consensus node successfully verifies the signature information of the data to be stored, the first consensus node sends a response message to the second consensus node, wherein the second consensus node is a consensus node other than itself among the first consensus nodes, and the response message includes the data to be stored verified by the first consensus node and the signature information of the data to be stored;
[0118] When the second consensus node verifies the signature information of the data to be stored in the response information, the consensus score is calculated using the classification weighted algorithm;
[0119] When the consensus score reaches a preset score, a block and signature information of the block are generated.
[0120] Based on this, the consensus score of the consensus node is calculated according to the classification weighted algorithm, and when the consensus score meets the preset score, it is determined that the consensus node has reached a consensus. In this way, the consensus score calculated by the classification weighted algorithm can ensure the security of the data and improve the consensus efficiency.
[0121] In the embodiment of the present application, the above-mentioned first consensus node verifies the signature information of the data to be stored in the consensus request sent by the main consensus node. After the verification is passed, the data to be stored is retained and a response message is sent to the second consensus node. The second consensus node verifies the signature information in the response message, and determines whether the data to be stored sent by the first consensus node is consistent with the data to be stored sent by the main consensus node. If the judgment result is consistent, it is determined that the verification is passed.
[0122] In addition, when the second consensus node verifies the signature information of the data to be stored in the response information, before calculating the consensus score, it is necessary to obtain the credibility of each consensus node. According to the credibility of each consensus node, the weight value of each consensus node can be determined. It can be defined that the weight of the consensus node with high credibility is high, and the weight of the consensus node with low credibility is low.
[0123] Specifically, this can be achieved through the following steps:
[0124] Obtaining the credibility of the multiple consensus nodes;
[0125] According to the credibility of the multiple consensus nodes, a weight value of each consensus node in the multiple consensus nodes is determined.
[0126] Based on this, the weight value of the consensus node is determined according to the credibility of each consensus node, so that consensus nodes with high credibility have more voting rights, and consensus nodes with low credibility have low voting rights, thereby improving the accuracy of the consensus results.
[0127] As an example, according to the above example, multiple consensus nodes can be divided into 4 categories, namely "high credit" = 1, "relatively high credit" = 2, "medium credit" = 3 and "low credit" = 4. Therefore, based on the classification weighted algorithm, the weight value and score corresponding to each level of credit can be determined. The specific results can be shown in Table 3.
[0128] Table 3 Credit weight value table
[0129] Credit Level Weight value Score High (credibility is 1) 0.4 0.4*1 / nn is the number of all consensus nodes Higher (credibility is 2) 0.3 0.3*1 / nn is the number of all consensus nodes Medium (credibility is 3) 0.2 0.2*1 / nn is the number of all consensus nodes Low (credibility is 4) 0.1 0.1*1 / nn is the number of all consensus nodes
[0130] After determining the weight value of each consensus node, when the second consensus node verifies the signature information of the data to be stored in the response information, the classification weighted algorithm is used to calculate the consensus score, which can be specifically completed by the following steps:
[0131] If the second consensus node successfully verifies the signature information of the data to be stored in the response information, determining the second consensus node as the target consensus node;
[0132] The weight value corresponding to the target consensus node and the weight value corresponding to the main consensus node are superimposed to obtain a consensus score.
[0133] Based on this, the final consensus score is calculated according to the weight values of the consensus nodes that have reached consensus. The consensus nodes with high weight values have high scores, and the consensus nodes with low weight values have low scores, so that the final calculated consensus score is highly accurate, thereby improving the consensus efficiency.
[0134] Among them, the above-mentioned target consensus node is a consensus node that reaches consensus, which can be used to indicate that the data to be stored in the target consensus node is the same.
[0135] It should be noted that, in the embodiment of the present application, the above-mentioned preset score can be set according to specific needs and will not be elaborated here.
[0136] As an example, assuming there are n consensus nodes, among which there are k target consensus nodes, the consensus score can be calculated according to the weight values corresponding to the credibility in Table 3. According to Table 3, the scores of each target consensus node can be determined, which are f1, f2, f3...f k , the score of the main consensus node is f0, so the consensus score can be calculated as score k+1 =f1+f2+…+f k +f0, calculate the total score of all consensus nodes as score n =f1+f2+…+f n . You can set it so that when score k+1 Greater than 0.5*scoren When the consensus process is completed, the data to be stored that has reached consensus will be packaged to generate blocks and the signature information corresponding to the blocks.
[0137] In the above step 204, the main consensus node sends the generated block and the signature information of the block to the submission node, and the submission node verifies the signature information. If the verification is passed, the data to be stored is stored in the blockchain system.
[0138] In order to better explain the data transmission method of the present application, as an example, Figure 3 A main flow chart of data storage in an exemplary blockchain system provided by one embodiment of the present application is shown.
[0139] like Figure 3 As shown, the specific implementation plan of data storage can be divided into 4 steps:
[0140] Step 301: The client submits a data storage request to the Endoring Peer node
[0141] The client constructs a request using the API interface. For example, a recruitment system needs to store user call record details in the blockchain system. By calling the smart contract network layer API interface request, the call record data is sent to multiple EndoringPeer nodes. The request contains the contract identifier, contract method, parameter information, and client signature to be called for this transaction.
[0142] Step 302: Endoring Peer Simulation Transaction
[0143] After receiving the request, the Endoring Peer verifies the client signature and determines whether the submitter has the right to perform the operation. The Endoring Peer takes the requested parameter information as input, executes the transaction on the current state KV database, generates a transaction result including the execution return value, the read operation set, and the write operation set (the ledger will not be updated at this time, there is no final confirmation, and a consensus algorithm is required), and returns these values to the client as the result of the request. The client parses this information to determine whether it should be applied to subsequent transactions.
[0144] Step 303: The client sends the request to the consensus node
[0145] The client verifies the signature of the Endoring Peer node and compares the simulated transaction results returned by each Endoring Peer node to determine whether the simulated transaction results are consistent and whether they are executed in accordance with the specified endorsement policy. After the client verifies the transaction results of each Endoring Peer node, it packages the transaction together, signs it, and sends it to the consensus node.
[0146] Step 304: consensus sorting, generating new blocks, and submitting transactions (this step is the process of storing data using the classification weighted algorithm adopted in this application)
[0147] The consensus node uses the classified weighted consensus algorithm to sort the received transactions by consensus, and then packages a batch of transactions together according to the block generation strategy to generate a new block and send it to the Committing Peer. After receiving the block, the Committing Peer will verify each transaction in the block to check whether the input and output that the transaction depends on are consistent with the current blockchain status. After completion, the block will be appended to the local blockchain and the KV status database will be modified to complete a data storage process.
[0148] Figure 4 FIG. 1 is a schematic diagram showing the structure of a data storage device provided in an embodiment of the present application. Figure 4 As shown, the data storage device 400 includes:
[0149] A receiving module 401 is used to receive a data storage request sent by a blockchain application, wherein the blockchain application is an application that establishes a connection with a blockchain system, and the data storage request includes data to be stored of the blockchain application;
[0150] A selection module 402 is used to select a consensus node with the highest credibility from the multiple consensus nodes as a main consensus node based on a classification weighted algorithm;
[0151] A generation module 403 is used to reach a consensus on the data to be stored according to the main consensus node and the classification weighted algorithm, and generate a block and signature information of the block, wherein the block is used to indicate a data packet after the consensus of the data to be stored;
[0152] The sending module 404 is used to send the block and the signature information of the block to the submission node, so that the submission node verifies the signature information of the block and stores the block in the blockchain.
[0153] Optionally, the selection module 402 may include:
[0154] An acquisition unit, configured to acquire feature vectors of the plurality of consensus nodes within a preset time period, wherein the feature vectors are feature vectors corresponding to a plurality of predefined feature attributes respectively;
[0155] A computing unit, configured to input the feature vector into a pre-trained classification model to obtain a credibility corresponding to each of the plurality of consensus nodes;
[0156] The determination unit is used to determine any consensus node among the multiple consensus nodes with the highest credibility as the main consensus node.
[0157] Optionally, the device 400 further includes:
[0158] An acquisition module is used to acquire a training sample set, wherein the training sample set includes information of multiple sample consensus nodes, wherein each sample consensus node information includes a feature vector of the sample consensus node and a label credibility corresponding to the sample consensus node, wherein the feature vector of the sample consensus node is a feature vector corresponding to multiple predefined feature attributes, and the label credibility is a credibility calculated based on the feature vector of the sample consensus node;
[0159] The training module is used to train a preset classification model using the information of multiple sample consensus nodes in the training sample set until the training stop condition is met to obtain a trained classification model.
[0160] Optionally, the training module can be used to:
[0161] Inputting the feature vector of the sample consensus node into a preset classification model to obtain the predicted credibility of the sample consensus node;
[0162] When the prediction confidence is inconsistent with the label confidence of the sample consensus node, the model parameters of the preset classification model are adjusted, and the adjusted classification model is trained using the feature vector of the sample consensus node until the prediction confidence meets the training stop condition, thereby obtaining the trained classification model.
[0163] Optionally, the data storage request also includes signature information of the data to be stored;
[0164] The generating module 403 may specifically include:
[0165] A first sending unit, configured for the master consensus node to send a consensus request to each first consensus node, wherein the first consensus node is a consensus node other than the master consensus node among the plurality of consensus nodes, and the consensus request includes the data to be stored and signature information of the data to be stored;
[0166] a verification unit, wherein, when the first consensus node verifies the signature information of the data to be stored successfully, the first consensus node sends a response message to the second consensus node, wherein the second consensus node is a consensus node other than itself among the first consensus nodes, and the response message includes the data to be stored verified by the first consensus node and the signature information of the data to be stored;
[0167] a processing unit, configured to calculate a consensus score by using the classification weighted algorithm when the second consensus node successfully verifies the signature information of the data to be stored in the response information;
[0168] A generating unit is used to generate a block and signature information of the block when the consensus score reaches a preset score.
[0169] Optionally, the processing unit may further include:
[0170] If the second consensus node successfully verifies the signature information of the data to be stored in the response information, determining the second consensus node as the target consensus node;
[0171] The weight value corresponding to the target consensus node and the weight value corresponding to the main consensus node are superimposed to obtain a consensus score.
[0172] Optionally, the device 600 may further include:
[0173] Obtaining the credibility of the multiple consensus nodes;
[0174] According to the credibility of the multiple consensus nodes, a weight value of each consensus node in the multiple consensus nodes is determined.
[0175] Based on this, in the embodiment of the present application, based on the classification weighted algorithm, all consensus nodes are evaluated for their credibility, and the consensus node with the highest credibility is selected as the main consensus node, thereby reducing the time wasted by reselecting the main consensus node due to the consensus node being tampered with or downtime as the main consensus node. Then, based on the selected main consensus node, the classification weighted algorithm is used to reach a consensus on the data to be stored, and then the block and signature information are generated, and the block and signature information are sent to the submission node for storage. In this way, through the data storage method of the present application, the time consumption in the consensus process can be reduced and the data storage efficiency can be improved.
[0176] The data storage device provided in the embodiment of the present application can realize Figure 2 To avoid repetition, the various processes implemented by the method embodiment are not described here.
[0177] Figure 5 A schematic diagram of the hardware structure of a data storage device provided in an embodiment of the present application is shown.
[0178] The data storage device may include a processor 501 and a memory 502 storing computer program instructions.
[0179] Specifically, the processor 501 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.
[0180] The memory 502 may include a large capacity memory for data or instructions. By way of example and not limitation, the memory 502 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive or a combination of two or more of these. In appropriate cases, the memory 502 may include a removable or non-removable (or fixed) medium. In appropriate cases, the memory 502 may be inside or outside the integrated gateway disaster recovery device. In a specific embodiment, the memory 502 is a non-volatile solid-state memory.
[0181] The memory may include a read-only memory (ROM), a random access memory (RAM), a magnetic disk storage medium device, an optical storage medium device, a flash memory device, an electrical, optical or other physical / tangible memory storage device. Thus, typically, the memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., a memory device) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the method according to the first aspect of the present application.
[0182] The processor 501 implements any one of the data storage methods in the above embodiments by reading and executing computer program instructions stored in the memory 502 .
[0183] In one example, the data storage device may further include a communication interface 503 and a bus 510. Figure 5 As shown, the processor 501, the memory 502, and the communication interface 503 are connected via a bus 510 and communicate with each other.
[0184] The communication interface 503 is mainly used to implement communication between various modules, devices, units and / or equipment in the embodiments of the present application.
[0185] Bus 510 includes hardware, software or both, and the parts of data storage device are coupled to each other. For example, but not limitation, bus may include accelerated graphics port (AGP) or other graphics bus, enhanced industrial standard architecture (EISA) bus, front side bus (FSB), hypertransport (HT) interconnection, industrial standard architecture (ISA) bus, infinite bandwidth interconnection, low pin count (LPC) bus, memory bus, micro channel architecture (MCA) bus, peripheral component interconnection (PCI) bus, PCI-Express (PCI-X) bus, serial advanced technology attachment (SATA) bus, video electronics standard association local (VLB) bus or other suitable bus or two or more of these combinations. In appropriate cases, bus 510 may include one or more buses. Although the present application embodiment describes and shows a specific bus, the present application considers any suitable bus or interconnection.
[0186] The data storage device can use the classification weighted algorithm to execute the data storage method in the embodiment of the present application, thereby realizing the combination of Figure 2 and Figure 4 Described data storage method and device.
[0187] In addition, in combination with the data storage method in the above embodiment, the embodiment of the present application can provide a computer storage medium to implement. The computer storage medium stores computer program instructions; when the computer program instructions are executed by the processor, any one of the data storage methods in the above embodiment is implemented.
[0188] It should be clear that the present application is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present application is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present application.
[0189] The functional blocks shown in the above-described block diagram can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc. When implemented in software, the elements of the present application are programs or code segments that are used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or a communication link by a data signal carried in a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, optical fiber media, radio frequency (RF) links, etc. The code segment can be downloaded via a computer network such as the Internet, an intranet, etc.
[0190] It should also be noted that the exemplary embodiments mentioned in this application describe some methods or systems based on a series of steps or devices. However, this application is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiment, or in a different order from the embodiment, or several steps can be performed simultaneously.
[0191] The above reference is according to the method of the embodiment of the present application, the flow chart of the device (system) and the computer program product and / or the block diagram described various aspects of the present application.It should be understood that each square box in the flow chart and / or the block diagram and the combination of each square box in the flow chart and / or the block diagram can be realized by computer program instructions.These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer or other programmable data processing device to produce a machine so that these instructions executed by the processor of the computer or other programmable data processing device enable the realization of the function / action specified in one or more square boxes of the flow chart and / or the block diagram.Such a processor can be but is not limited to a general-purpose processor, a special-purpose processor, a special application processor or a field programmable logic circuit.It can also be understood that each square box in the block diagram and / or the flow chart and the combination of the square boxes in the block diagram and / or the flow chart can also be realized by the dedicated hardware that performs the specified function or action, or can be realized by the combination of dedicated hardware and computer instructions.
[0192] The above is only a specific implementation of the present application. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the systems, modules and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. It should be understood that the protection scope of the present application is not limited to this. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in this application, and these modifications or replacements should be included in the protection scope of this application.
Claims
1. A data storage method, characterized in that: Applied to a blockchain system, the blockchain system includes a submission node and multiple consensus nodes, and the method includes: Receiving a data storage request sent by a blockchain application, wherein the blockchain application is an application that establishes a connection with a blockchain system, and the data storage request includes data to be stored of the blockchain application; Based on the classification weighted algorithm, select the consensus node with the highest credibility from the multiple consensus nodes as the main consensus node; According to the master consensus node and the classification weighted algorithm, consensus is reached on the data to be stored, and a block and signature information of the block are generated, wherein the block is used to indicate a data packet after consensus on the data to be stored; Sending the block and the signature information of the block to the submission node, so that the submission node verifies the signature information of the block and stores the block in the blockchain; Wherein, according to the main consensus node and the classification weighted algorithm, consensus is reached on the data to be stored, and a block and signature information of the block are generated, including: The weight value corresponding to the target consensus node and the weight value corresponding to the main consensus node are superimposed to obtain a consensus score; the target consensus node is a consensus node that reaches a consensus, and is used to indicate that the data to be stored in the target consensus node is the same as the data to be stored in the blockchain application; When the consensus score reaches a preset score, a block and signature information of the block are generated based on the data to be stored.
2. The data storage method according to claim 1, characterized in that: The selecting the consensus node with the highest credibility from the plurality of consensus nodes as the main consensus node based on the classification weighted algorithm specifically includes: Acquire feature vectors of the plurality of consensus nodes within a preset time period, wherein the feature vectors are feature vectors corresponding to a plurality of predefined feature attributes respectively; Inputting the feature vector into a pre-trained classification model to obtain the credibility corresponding to each of the multiple consensus nodes; Any consensus node among the multiple consensus nodes with the highest credibility is determined as the main consensus node.
3. The data storage method according to claim 2, characterized in that: Before selecting the consensus node with the highest credibility from the plurality of consensus nodes as the main consensus node based on the classification weighted algorithm, the method further includes: Acquire a training sample set, the training sample set including information of multiple sample consensus nodes, wherein each sample consensus node information includes a feature vector of the sample consensus node and a label credibility corresponding to the sample consensus node, the feature vector of the sample consensus node is a feature vector corresponding to multiple predefined feature attributes, and the label credibility is a credibility calculated according to the feature vector of the sample consensus node; The preset classification model is trained using the information of multiple sample consensus nodes in the training sample set until the training stop condition is met to obtain a trained classification model.
4. The data storage method according to claim 3, characterized in that: The method of training a preset classification model using the information of the plurality of sample consensus nodes in the training sample set until a training stop condition is met to obtain a trained classification model specifically includes: For each sample consensus node information, perform the following steps respectively: Inputting the feature vector of the sample consensus node into a preset classification model to obtain the predicted credibility of the sample consensus node; When the prediction confidence is inconsistent with the label confidence of the sample consensus node, the model parameters of the preset classification model are adjusted, and the adjusted classification model is trained using the feature vector of the sample consensus node until the prediction confidence meets the training stop condition, thereby obtaining the trained classification model.
5. The data storage method according to claim 1, characterized in that: The data storage request also includes signature information of the data to be stored; The method further comprises: The master consensus node sends a consensus request to each first consensus node, wherein the first consensus node is a consensus node other than the master consensus node among the multiple consensus nodes, and the consensus request includes the data to be stored and signature information of the data to be stored; In the case where the first consensus node successfully verifies the signature information of the data to be stored, the first consensus node sends a response message to the second consensus node, wherein the second consensus node is a consensus node other than itself among the first consensus nodes, and the response message includes the data to be stored verified by the first consensus node and the signature information of the data to be stored; When the second consensus node successfully verifies the signature information of the data to be stored in the response information, the second consensus node is determined to be the target consensus node.
6. The data storage method according to claim 5, characterized in that: In the case where the second consensus node verifies the signature information of the data to be stored in the response information successfully, before determining the second consensus node as the target consensus node, the method further includes: Obtaining the credibility of the multiple consensus nodes; According to the credibility of the multiple consensus nodes, a weight value of each consensus node in the multiple consensus nodes is determined.
7. A data storage device, characterized in that: Applied to a blockchain system, the blockchain system includes a submission node and multiple consensus nodes, and the device includes: A receiving module, configured to receive a data storage request sent by a blockchain application, wherein the blockchain application is an application that establishes a connection with a blockchain system, and the data storage request includes data to be stored of the blockchain application; A selection module, configured to select a consensus node with the highest credibility from the plurality of consensus nodes as a main consensus node based on a classification weighted algorithm; A generation module, used to reach a consensus on the data to be stored according to the main consensus node and the classification weighted algorithm, and generate a block and signature information of the block, wherein the block is used to indicate a data packet after the consensus of the data to be stored; A sending module, used to send the block and the signature information of the block to the submission node, so that the submission node verifies the signature information of the block and stores the block in the blockchain; Wherein, the generation module is specifically used for: The weight value corresponding to the target consensus node and the weight value corresponding to the main consensus node are superimposed to obtain a consensus score; the target consensus node is a consensus node that reaches a consensus, and is used to indicate that the data to be stored in the target consensus node is the same as the data to be stored in the blockchain application; When the consensus score reaches a preset score, a block and signature information of the block are generated based on the data to be stored.
8. A data storage device, characterized in that: The device comprises: a processor and a memory storing computer program instructions; When the processor executes the computer program instructions, the data storage method according to any one of claims 1 to 6 is implemented.
9. A computer storage medium, characterized in that The computer storage medium stores computer program instructions, which, when executed by a processor, implement the data storage method according to any one of claims 1 to 6.
Citation Information
Patent Citations
System and method providing advanced distributed ledger capabilities via specialized data records
CA3141042A1
Consensus method and system of block chain, terminal and storage medium
CN111930845A