Block consensus processing method and device and related equipment

By acquiring data elements from the blockchain network, performing feature extraction and machine learning model prediction, and dynamically selecting the target consensus algorithm, the problem that consensus algorithms in blockchain networks cannot take into account multiple indicators is solved, thereby improving network performance and adaptability.

CN121508795APending Publication Date: 2026-02-10CHINA MOBILE ZIJIN INNOVATION INST CO LTD +2
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511795962.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-02
Publication Date
2026-02-10

AI Technical Summary

Technical Problem

Applying a fixed consensus algorithm in a blockchain network makes it difficult to consider multiple network metrics, resulting in low network performance.

Method used

By acquiring data elements from the blockchain, performing feature extraction and machine learning model prediction, the target consensus algorithm most suitable for the current network environment is dynamically selected, and the blockchain consensus algorithm is adjusted.

Benefits of technology

It improves the performance of the blockchain network, enhances the flexibility and adaptability of the consensus mechanism, and optimizes the network environment's adaptability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121508795A_ABST
    Figure CN121508795A_ABST
Patent Text Reader

Abstract

The invention provides a block consensus processing method, a block consensus processing device and related equipment. The method comprises the following steps: acquiring a first data element of a block chain in a time period t; performing feature extraction on the first data element to obtain a first feature set; based on the first feature set, utilizing a first model to predict M pieces of score information in one-to-one correspondence with M preset consensus algorithms, the score information indicating network performance when the preset consensus algorithms are applied to the block chain; based on the M pieces of score information, a target consensus algorithm applied to the block chain is selected from M preset consensus algorithms, the block chain network performance indicated by the first score information is better than the block chain network performance indicated by the second score information, and the first score information is score information corresponding to the target consensus algorithm; the second score information is score information corresponding to other preset consensus algorithms except the target consensus algorithm in the M preset consensus algorithms; and adjusting the consensus algorithm of the block chain in the time period t + 1 into a target consensus algorithm.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of blockchain technology, and in particular to a block consensus processing method, apparatus and related equipment. Background Technology

[0002] Blockchain technology is considered one of the most revolutionary emerging technologies in the information field and has developed rapidly in recent years. Its core principle is a decentralized distributed ledger that integrates three elements: a peer-to-peer network as the physical foundation, a consensus mechanism to establish a decentralized trust model, and cryptographic technology for identity security authentication.

[0003] As a distributed and decentralized innovative technology, blockchain can effectively solve the problem of information sharing among multiple parties and two parties. It also has advantages such as data immutability, traceability, trust establishment, reduced transaction costs, and intelligent execution, and can be widely used in various industries such as finance.

[0004] Consensus mechanisms are arguably one of the core elements of blockchain, ensuring data consistency within the blockchain network. Common traditional consensus algorithms in blockchain include: Proof of Work (PoW), Proof of Stake (PoS), Delegated Proof of Stake (DPoS), Practical Byzantine Fault Tolerance (PBFT), and the Raft distributed consensus protocol.

[0005] Currently, blockchain networks typically use fixed consensus algorithms for block processing. This mechanism makes it difficult to consider multiple network metrics, resulting in relatively low network performance. Summary of the Invention

[0006] This application provides a block consensus processing method, apparatus, and related equipment, which can solve the technical problem that blockchain networks in related technologies typically use fixed consensus algorithms for block processing. This mechanism is difficult to take into account multiple network indicators, resulting in relatively low network performance of the blockchain.

[0007] In a first aspect, embodiments of this application provide a block consensus processing method, the method comprising:

[0008] Obtain the first data element of the blockchain within time period t;

[0009] Feature extraction is performed on the first data element to obtain a first feature set, which is a set of feature representations of the first data element;

[0010] Based on the first feature set, the first model is used to predict M score information corresponding to M preset consensus algorithms. The score information indicates the network performance when the preset consensus algorithm is applied to the blockchain, and M is a positive integer greater than 1.

[0011] Based on the M rating information, a target consensus algorithm is selected from the M preset consensus algorithms for application to the blockchain. The blockchain network performance indicated by the first rating information in the M rating information is better than the blockchain network performance indicated by the second rating information in the M rating information. The first rating information is the rating information corresponding to the target consensus algorithm, and the second rating information is the rating information corresponding to other preset consensus algorithms in the M preset consensus algorithms besides the target consensus algorithm.

[0012] The consensus algorithm of the blockchain within the time period t+1 is adjusted to the target consensus algorithm.

[0013] Secondly, embodiments of this application provide a block consensus processing apparatus, the apparatus comprising:

[0014] The first acquisition module is used to acquire the first data element of the blockchain within the time period t.

[0015] The first feature extraction module is used to extract features from the first data element to obtain a first feature set, wherein the first feature set is a set of feature representations of the first data element.

[0016] The prediction module is used to predict M score information corresponding to M preset consensus algorithms based on the first feature set and using the first model. The score information indicates the network performance when the preset consensus algorithm is applied to the blockchain, and M is a positive integer greater than 1.

[0017] The selection module is used to select a target consensus algorithm for the blockchain from the M preset consensus algorithms based on the M rating information. The blockchain network performance indicated by the first rating information in the M rating information is better than the blockchain network performance indicated by the second rating information in the M rating information. The first rating information is the rating information corresponding to the target consensus algorithm, and the second rating information is the rating information corresponding to other preset consensus algorithms in the M preset consensus algorithms besides the target consensus algorithm.

[0018] The adjustment module is used to adjust the consensus algorithm of the blockchain to the target consensus algorithm within the time period t+1.

[0019] Thirdly, embodiments of this application provide an electronic device, including: a processor, a memory, and a program stored in the memory and executable on the processor, wherein when the program is executed by the processor, it implements the steps of the block consensus processing method as described in the first aspect.

[0020] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the block consensus processing method as described in the first aspect.

[0021] Fifthly, embodiments of this application provide a computer program product, including computer instructions that, when executed by a processor, implement the steps of the block consensus processing method as described in the first aspect.

[0022] In this embodiment, a first data element of the blockchain within a time period t is obtained; features are extracted from the first data element to obtain a first feature set, which is a set of feature representations of the first data element; based on the first feature set, a first model is used to predict M score information corresponding to M preset consensus algorithms, where the score information indicates the network performance of the preset consensus algorithm when applied to the blockchain, and M is a positive integer greater than 1; based on the M score information, a target consensus algorithm is selected from the M preset consensus algorithms for application to the blockchain, wherein the blockchain network performance indicated by the first score information among the M score information is better than the blockchain network performance indicated by the second score information among the M score information, where the first score information is the score information corresponding to the target consensus algorithm, and the second score information is the score information corresponding to other preset consensus algorithms among the M preset consensus algorithms besides the target consensus algorithm; the consensus algorithm of the blockchain within a time period t+1 is adjusted to the target consensus algorithm. In this way, by using the first model, we can combine the data elements of the blockchain to predict the M score information corresponding to the M preset consensus algorithms. Based on the M score information, we can select a target consensus algorithm that is suitable for the current network environment from the M preset consensus algorithms, and dynamically update the consensus algorithm in the blockchain based on the target consensus algorithm to adapt to different network environments. This solves the problem that existing consensus algorithms are difficult to take into account multiple network indicators and are not flexible enough, thus improving the network performance of the blockchain. Attached Figure Description

[0023] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0024] Figure 1 This is a flowchart of a block consensus processing method provided in an embodiment of this application;

[0025] Figure 2 This is a diagram illustrating the training and deployment framework for the first and second models.

[0026] Figure 3 This is an implementation architecture diagram of a block consensus processing method provided in a specific example of an embodiment of this application;

[0027] Figure 4 This is a schematic diagram of the structure of a block consensus processing device provided in an embodiment of this application;

[0028] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0029] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0030] Consensus mechanisms are arguably one of the core elements of blockchain, ensuring data consistency within the blockchain network. For any public blockchain, its underlying architecture requires a consensus mechanism to regulate how nodes compete for record-keeping. Based on current mainstream public blockchain architectures, the most common and mainstream consensus algorithms include: Proof of Work (PoW), Proof of Stake (PoS), Delegated Proof of Stake (DPoS), Practical Byzantine Fault Tolerance (PBFT), and the Raft distributed consensus protocol. Their network performance is compared in Table 1 below.

[0031] Table 1. Network Performance Comparison of Common Consensus Algorithms

[0032]

[0033] As shown in Table 1, it is difficult to simultaneously meet key performance indicators such as latency, energy consumption, and decentralization of consensus algorithms. Therefore, trade-offs must be made in practical applications. Taking the commercial distributed blockchain system (Enterprise Operation System, EOS) as an example, to avoid the problem of excessive latency in the PoW algorithm rendering it unusable for commercial purposes, the DPoS algorithm was adopted. However, this resulted in insufficient decentralization and compromised system security. The problems caused by the shortcomings of these algorithms far outweigh their advantages.

[0034] In addition, different application scenarios have different emphases on various indicators such as latency, scale, and energy consumption of consensus algorithms. To compensate for the disadvantages of a single consensus algorithm and to meet different needs, hybrid consensus has emerged. By combining existing consensus algorithms, two or more consensus mechanisms are applied to the underlying architecture of the same blockchain public chain. The reasonable use of hybrid consensus can make up for the inefficiencies, lack of security protection, or sacrifice of centralization brought about by a single consensus mechanism, and make up for the shortcomings of traditional consensus mechanisms.

[0035] Hybrid consensus algorithms, such as Delegated Proof of Stake Work (DPoSW), which uses Delegated Proof of Stake (DPoS) for block verification and Proof of Work (PoW) for block creation, effectively address the network integrity issue. This method makes it more difficult for attackers to control the network because verification and block creation are handled by different mechanisms. Other algorithms include Proof of Stake and Work (PoSW), Proof-of-Stake Combining of CASBFT (PoCASBFT), and Delegated Byzantine Fault-Tolerant Proof of Stake (DBPoS). These algorithms are specifically optimized for different needs and use cases, achieving good results. However, during blockchain operation, parameters such as block size, difficulty adjustment, time, and verification rules change. Even with hybrid consensus, it remains difficult to dynamically and promptly adjust these parameters to adapt to real-world requirements.

[0036] Based on this, the present application provides a block consensus processing method, which aims to solve the technical problem that the application of a fixed consensus algorithm for block processing in a blockchain network makes it difficult to take into account multiple network indicators, resulting in relatively low network performance of the blockchain.

[0037] It should be noted that the block consensus processing method provided in this application embodiment is applied to a blockchain system, which may include multiple functional modules to implement the block consensus processing method.

[0038] See Figure 1, Figure 1 This is a flowchart of a block consensus processing method provided in an embodiment of this application, such as... Figure 1 As shown, the method includes the following steps:

[0039] Step 101: Obtain the first data element of the blockchain within the time period t;

[0040] Step 102: Extract features from the first data element to obtain a first feature set, which is a set of feature representations of the first data element;

[0041] Step 103: Based on the first feature set, use the first model to predict M score information corresponding to M preset consensus algorithms, wherein the score information indicates the network performance when the preset consensus algorithm is applied to the blockchain, and M is a positive integer greater than 1.

[0042] Step 104: Based on the M rating information, select a target consensus algorithm from the M preset consensus algorithms to be applied to the blockchain. The blockchain network performance indicated by the first rating information in the M rating information is better than the blockchain network performance indicated by the second rating information in the M rating information. The first rating information is the rating information corresponding to the target consensus algorithm, and the second rating information is the rating information corresponding to other preset consensus algorithms in the M preset consensus algorithms besides the target consensus algorithm.

[0043] Step 105: Adjust the consensus algorithm of the blockchain within the time period t+1 to the target consensus algorithm.

[0044] In step 101, since the real-world blockchain network is so large that it is impossible to change the consensus algorithm at any time, and model training, such as the training of the first model, also consumes a lot of energy, the blockchain network N is monitored at certain intervals, with time T as the period, in order to extract information within the current time period t.

[0045] In some embodiments, information monitoring hardware can be used to monitor the state of the blockchain network and obtain real-time data elements, denoted as dataset D, for use... This indicates that dataset D is the first data element.

[0046] Data elements, in particular, refer to data resources that exist in electronic form, participate in production and business activities through computation, and play a significant role in value. They are the core engine driving the development of the digital economy. Data elements are a new type of production factor, referring to data resources that exist in electronic form and participate in production, distribution, circulation, consumption, and social service management through computation. This data can be reused by multiple entities, achieving multiplied value. In the digital economy, data elements are on par with traditional production factors (such as labor, capital, and land), becoming a crucial support for economic development.

[0047] In this embodiment of the application, the first data element includes transaction data, block data, node data, network status, etc. in the blockchain network.

[0048] In step 102, features can be extracted from the first data element to obtain a first feature set, wherein the first feature set is a set of feature representations of the first data element. The feature extraction model deployed in the feature extraction module can be used to extract features from the first data element. The feature extraction module is a functional module of the blockchain system.

[0049] In some embodiments, to ensure the accuracy of network performance evaluation for the current network environment using the preset consensus algorithm, the first feature set can be filtered, i.e., step 102 specifically includes:

[0050] The first data element is subjected to feature extraction to obtain the second feature set;

[0051] Anomaly detection is performed on the second feature set using the second model to obtain the first feature set, which is the feature set obtained after filtering out abnormal features from the second feature set.

[0052] The second model can be a machine learning model, which can be trained based on the feature data of the second data element within the historical time period of the blockchain. The second model can be deployed in the anomaly detection module, which is a functional module of the blockchain system.

[0053] In this embodiment, by using a machine learning model, abnormal transactions and attacks can be filtered out, thereby enhancing the stability of the consensus mechanism.

[0054] In some embodiments, after feature extraction from dataset D, the extracted feature set F (i.e., the second feature set) can be filtered using the second model in the anomaly detection module to obtain the filtered safe feature set Fs (i.e., the first feature set). Let M represent the second model.

[0055] In step 103, the security feature set Fs can be input into the first model to calculate the scoring information of the preset consensus algorithm in the current network environment. It means that, among them, This represents the i-th pre-defined consensus algorithm among M pre-defined consensus algorithms.

[0056] The rating information can indicate the network performance when the preset consensus algorithm is applied to the blockchain. Accordingly, in step 104, the target consensus algorithm to be applied to the blockchain can be selected from the M preset consensus algorithms based on the M rating information.

[0057] In some embodiments, the lower the score information, the better the performance of the blockchain network under the preset consensus algorithm. Accordingly, the preset consensus algorithm corresponding to the smallest score information among the M score information can be selected as the target consensus algorithm. In this case, the first score information is less than the second score information.

[0058] In some embodiments, a higher score indicates better performance of the blockchain network under the preset consensus algorithm. Accordingly, the preset consensus algorithm corresponding to the highest score among the M score information can be selected as the target consensus algorithm. In this case, the first score information is greater than the second score information.

[0059] Accordingly, a target consensus algorithm that best performs the network performance of the blockchain can be selected from M preset consensus algorithms to adapt to the current network environment.

[0060] It should be noted that the preset consensus algorithm can be a single consensus algorithm or a hybrid consensus algorithm. In order to take into account the needs of various network metrics, the preset consensus algorithm can be a hybrid consensus algorithm.

[0061] In step 105, the selected target consensus algorithm can be passed to the blockchain network, the contract and algorithm are updated, and the update is broadcast to all blocks, entering the consensus execution module. This consensus execution module is a functional module of the blockchain system, through which the blockchain system can create block B.

[0062] This embodiment addresses the problem that fixed consensus algorithms cannot meet all needs and cannot be adjusted according to network conditions. By using machine learning models and combining real-time data elements, the consensus algorithm is optimized, enabling it to adaptively select a suitable consensus algorithm based on the blockchain's network environment, thereby enhancing the consensus mechanism and improving the blockchain's network performance.

[0063] In some embodiments, after step 105, the method further includes:

[0064] The target consensus algorithm is used to create a new block on the blockchain;

[0065] The second model is used to perform anomaly detection on the block;

[0066] If the anomaly detection result of the block indicates that the block is abnormal, a response mechanism corresponding to the attack type of the block is triggered. The attack type of the block is obtained based on the block characteristics. The response mechanism is used to process the anomaly of the block and / or update the target consensus algorithm applied to the blockchain.

[0067] The consensus execution module in the blockchain system can create a new block B using the target consensus algorithm. Since the second model deployed in the anomaly detection module is trained with feature data of the second data element within the blockchain's historical time period, it can detect block states, thereby performing anomaly detection on block B.

[0068] In some embodiments, to ensure the legitimacy of newly created blocks, the anomaly detection of the blocks using the second model includes:

[0069] If the validity of the block is verified, the third data element of the block is obtained;

[0070] Feature extraction is performed on the third data element to obtain the block features of the block;

[0071] The block features of the block are input into the second model to perform anomaly detection of the block.

[0072] When creating a new block, a request can be sent to the anomaly detection module for smart block verification. During the block verification process, the machine learning model can verify the newly generated block B based on transaction patterns. Let the verification function be V(B), which outputs whether the block is valid, as shown in the following formula.

[0073]

[0074] If block B is valid, the output is 1; otherwise, the output is 0. A machine learning model can be used to determine the validity of blocks, thereby reducing invalid blocks. This machine learning model can also be a second model.

[0075] The verification function result V(B) can be sent back to the corresponding consensus execution module as a response. If the verification passes, the second model will simultaneously establish an attack detection bridge with this block B. Through the second model in the anomaly detection module, the block state can be continuously monitored, thereby performing anomaly detection on block B. Its output is shown in the following formula.

[0076]

[0077] If block B is detected as being attacked, the output is 1; otherwise, the output is 0.

[0078] In some embodiments, if the legality verification of the block passes, the third data element of the block can be obtained. For each node or transaction, the block features of the block can be extracted based on the third data element to obtain a feature set. ,in, Indicates the presence of a third data element Extracted block features, It can be a data point in block B.

[0079] The block features of the block can be input into the second model to perform anomaly detection for the block, and the anomaly detection results can be obtained. , representing data points (The third data element, which may include transaction data from block B) Whether there are any anomalies. If an anomaly is found, the blockchain system will further determine whether the anomaly is related to a specific type of attack. For example, common attacks that may occur in blockchain systems include: 51% attacks, double-spending attacks, selfish mining attacks, and distributed denial-of-service (DDoS) attacks.

[0080] Blockchain systems can provide a range of detectors for detecting attack types. The attack type of this block can be determined based on the block's characteristics, using a detector designed to detect attack types. The system performs detection of corresponding attack types. Each detector j determines the probability of a certain attack. If the corresponding attack type is detected, the output is 1; otherwise, the output is 0. The output of the detector can be defined as follows.

[0081]

[0082] Among them, if a certain abnormal data point If attack type j is matched, then This indicates that an attack has been detected.

[0083] The blockchain system can make decisions on whether to respond to an attack based on the detector's output and anomaly detection results. Once an attack is detected, the blockchain system will automatically trigger the response mechanism corresponding to the attack type of that block to restrict the operation of malicious nodes.

[0084] Given multiple attack types, the blockchain system can make decisions based on different attack types and their severity. Decision Function Depending on the anomaly detection results and the attack detector output, it is expressed as follows.

[0085]

[0086] If an attack is detected, that is If the system triggers a response mechanism, the specific response measures will depend on the type of attack detected, for example:

[0087] Isolate Nodes: If a node is detected to have launched a 51% attack, the system will isolate that node.

[0088] Block rejection: If a double-spending attack is detected, the system will reject the malicious block.

[0089] Limit network traffic: If a DDoS attack is detected, the system will limit malicious traffic to ensure that the network is not overwhelmed.

[0090] In the event of a major malicious attack, such as the detection of multiple attack types or a targeted attack type, the blockchain system can update its consensus algorithm by re-executing steps 101-105 to enhance the overall security of the blockchain system.

[0091] It should be noted that both the first and second models need to be pre-trained before they can be deployed in the blockchain system. The first model is deployed in the consensus optimization module, which uses the first model to optimize the consensus parameters so that it can adaptively select the appropriate consensus algorithm according to the specific network environment. The second model is deployed in the anomaly detection module.

[0092] In some embodiments, data can be collected separately to train the first model and the second model.

[0093] In some embodiments, the first and second models can be trained on both ends based on historical data elements of the blockchain, taking into account both consensus algorithm optimization and security control. That is, before step 103, the method further includes:

[0094] Obtain the second data element of the blockchain, wherein the second data element is a data element within a historical time period relative to the first data element;

[0095] Feature extraction is performed on the second data element to obtain a third feature set, which is a set of feature representations of the second data element;

[0096] Based on the third feature set, the first model and the second model are trained respectively.

[0097] The training and deployment frameworks for the first and second models are as follows: Figure 2 As shown, the blockchain network is denoted as N, and the historical data elements of the blockchain, i.e., the second data elements, are collected as the dataset for model training, denoted as dataset D1. express.

[0098] Each of them It contains multiple raw data sets, corresponding to a single raw feature set. This includes transaction data, block data, node data, and network status. These features are normalized to generate a feature set F, the third feature set, which is then used... F = This indicates that "standard" represents normalization.

[0099] The third feature set will be input into the first model and the second model respectively for model training. The first model is used for consensus prediction, and the second model is used for anomaly detection.

[0100] Anomaly detection refers to using a second model to identify and flag anomalous behavior in the network, filtering out illegitimate transactions to prevent them from affecting block consensus and ensuring that participants can promptly detect and respond to potential attacks. For complex blockchain networks, such as... Figure 2 As shown, supervised learning and unsupervised learning algorithms are used respectively to detect anomalies in on-chain data and on-chain transaction behavior based on the third feature set.

[0101] In supervised learning, for a feature set F, each sample Corresponding to a tag (1 indicates abnormality, 0 indicates normality). A classifier M is trained to predict whether a new sample is abnormal, denoted as M:F→y. This classifier M is the second model.

[0102] The loss function for training the second model can be expressed as: = ,in, It is a loss function. These are the model parameters of the second model. The loss function is used to evaluate model performance and guide model training. In supervised learning, this loss function is used to evaluate the performance of the second model, and it can also be used for the second model's self-learning updates.

[0103] In an input feature set, not all data may have explicit labels. In such cases, unsupervised learning is needed to identify and label outliers. Unsupervised learning involves unlabeled data. Clustering algorithms or isolation forests can be used to identify anomalies. The idea behind isolation forests is to randomly partition the feature space to identify samples that are more likely to be "isolated." For each sample, the isolation forest outputs an anomaly score, which reflects the sample's degree of "isolation" relative to other samples, expressed by the following formula.

[0104]

[0105] in, It is a preset abnormal scoring threshold. The larger the value, exceeding the anomaly score threshold, the more likely the sample is to be an anomaly.

[0106] After supervised and unsupervised learning, the trained second model can be used for anomaly detection. After anomaly detection and removal of abnormal data, a safe feature set can be obtained, which can be used for subsequent updates and training of the second model.

[0107] Consensus prediction refers to monitoring the blockchain network N and, in conjunction with data elements, adjusting the consensus capability weights in real time. This ensures that the predicted score information for a consensus algorithm with good network performance is small (or large), allowing for the selection of a suitable consensus algorithm to adapt to the current blockchain network state. For example... Figure 2 As shown, by analyzing historical data elements, the first model is able to predict the scoring information corresponding to the preset consensus algorithm in learning modes or in reinforcement learning mechanisms based on rewards and punishments. This rating information can represent block performance metrics, allowing the selection of the optimal consensus algorithm based on the rating information.

[0108] To achieve this goal, an evaluation function for the current network state needs to be introduced. Pre-set a hybrid consensus algorithm set That is, there are M preset consensus algorithms, and the consensus algorithm currently used by the network is denoted as C. .in, Indicates the pre-defined consensus algorithm The system selects the optimal network based on its performance score across network N. , which serves as C in the current network.

[0109] in, The calculation can be performed by combining the network indicators provided in the second data element with weights, as shown in the following formula.

[0110]

[0111] Among them, L ( Indicates the pre-defined consensus algorithm The latency on the network is the time it takes to complete a consensus (the shorter the better, so we use that directly).

[0112] T( This indicates the use of a pre-defined consensus algorithm. Throughput is the number of transactions processed per unit of time (the higher the throughput, the better, so we take the reciprocal).

[0113] E ( Indicates the pre-defined consensus algorithm The energy consumed (Energy Efficiency) is the energy expenditure (the lower the energy expenditure, the better, so take the reciprocal).

[0114] D ( Indicates the pre-defined consensus algorithm The degree of decentralization refers to the degree of decentralization of nodes in the system (the more decentralized the better, so we take the reciprocal).

[0115] Sec ( Indicates the pre-defined consensus algorithm Security refers to its ability to resist attacks (the higher the security, the better, so we take the reciprocal).

[0116] These network metrics have different weights in different blockchain applications, therefore the calculation In this case, weights need to be assigned to each metric based on the application scenario. Weight set This indicates the calculation of various network metrics. The weighting of each time period can be adjusted according to the performance requirements of the blockchain and is set by the user.

[0117] After the first and second models are trained, the complete machine learning model is deployed into the blockchain system and applied to the blockchain's consensus decision-making and anomaly alerting, in conjunction with the consensus optimization module and the anomaly detection module.

[0118] In this embodiment, by introducing data elements and leveraging the characteristics of a large amount of blockchain data, the richness and accuracy of model parameters are ensured. Furthermore, by employing machine learning training methods to identify biased data, anomalies in the system can be efficiently and accurately identified, thereby enhancing the security of the blockchain system.

[0119] In some embodiments, after inputting the block features of the block into a second model for anomaly detection of the block, the method further includes:

[0120] Based on the target loss gradient function and the learning rate of the second model, using Update the model parameters of the second model;

[0121] in, The model parameters of the second model within the time period t. The model parameters of the second model within the time period t+1. The learning rate of the second model is... The target loss gradient function is the block feature of the block. and the anomaly detection results of the block The loss gradient function.

[0122] Each time the blockchain system detects and responds to an attack, it needs to update its system state. To cope with constantly changing attack patterns, the second model needs to continuously monitor and adaptively update. Let the current time period be denoted as t, and the update time period as t+1. Then the model parameters of the current second model are: Let the model learning rate be... If the anomaly detection result is y, then the adaptive update formula is as follows.

[0123]

[0124] in, It is based on block characteristics. The loss gradient function of the anomaly detection result y.

[0125] Through online learning or periodic retraining, the blockchain system can adaptively update the second model to adapt to new attacks and changes in the network environment.

[0126] In this embodiment, thanks to the self-learning and updating characteristics of machine learning, the model parameters can be continuously adjusted and optimized based on real-time network behavior, ensuring the security and efficient operation of the blockchain network.

[0127] The following example illustrates in detail the block consensus processing method provided in the embodiments of this application.

[0128] Figure 3 This is a schematic diagram of the implementation architecture of a block consensus processing method provided in a specific embodiment of this application. This architecture can be based on a machine learning model to dynamically determine the consensus algorithm, thereby enhancing the network performance of the blockchain. Figure 3 As shown, consensus algorithms and machine learning models are integrated into the blockchain system, enabling the machine learning model to identify attacks and optimize consensus decision parameters.

[0129] The architecture includes an information extraction module, a feature extraction module, a consensus execution module, a consensus optimization module, and an anomaly detection module. For example, Figure 3 As shown, the machine learning model ML is extracted and displayed separately. However, in reality, the machine learning model ML should be deployed in the blockchain system, such as in the anomaly detection module and consensus optimization module, rather than as a separate off-chain module communicating with the blockchain. This is only for ease of reading.

[0130] The information extraction module is used to extract data elements, the feature extraction module is used to extract features from the data elements, the anomaly detection module is used to filter the feature set F before consensus prediction, the consensus optimization module is used to use a machine learning model to predict M score information corresponding to M preset consensus algorithms, and select the target consensus algorithm based on the M score information, the consensus execution module is used to establish blocks using the target consensus algorithm, and the anomaly detection module is also used to use a machine learning model to verify the legitimacy of newly created blocks, and after the blocks are established, to establish an attack detection bridge with the blocks to detect anomalies in the blocks.

[0131] In this embodiment, the blockchain consensus mechanism combines machine learning models and data elements to fully implement a dynamic consensus mechanism with good security and scalability, from architecture to algorithm. Specifically, it consists of two parts: a dynamic consensus architecture based on a machine learning model and a machine learning model training scheme. At the beginning of the architecture construction, the machine learning model needs to be trained first. After completion, the mature model is deployed into the blockchain system to start the overall blockchain system operation and achieve block consensus processing.

[0132] This embodiment designs a consensus execution architecture by introducing machine learning models and data elements. It can select a consensus algorithm suitable for the current network environment and identify abnormal data and transaction behavior, thereby enhancing the security of the blockchain system.

[0133] The embodiments of this application can be widely applied to existing public blockchain systems. With the help of machine learning technology, the blockchain consensus algorithm can be adjusted in real time according to network conditions, and anomaly detection can be used to respond to abnormal attacks in a timely manner, thus ensuring data and block security and having broad application prospects.

[0134] See Figure 4 , Figure 4 This is a schematic diagram of the structure of a block consensus processing device provided in an embodiment of this application, as shown below. Figure 4 As shown, the block consensus processing device 400 includes:

[0135] The first acquisition module 401 is used to acquire the first data element of the blockchain within the time period t.

[0136] The first feature extraction module 402 is used to extract features from the first data element to obtain a first feature set, wherein the first feature set is a set of feature representations of the first data element.

[0137] Prediction module 403 is used to predict M score information corresponding to M preset consensus algorithms based on the first feature set and using the first model. The score information indicates the network performance when the preset consensus algorithm is applied to the blockchain, and M is a positive integer greater than 1.

[0138] Selection module 404 is used to select a target consensus algorithm for the blockchain from the M preset consensus algorithms based on the M rating information. The blockchain network performance indicated by the first rating information in the M rating information is better than the blockchain network performance indicated by the second rating information in the M rating information. The first rating information is the rating information corresponding to the target consensus algorithm, and the second rating information is the rating information corresponding to other preset consensus algorithms in the M preset consensus algorithms besides the target consensus algorithm.

[0139] The adjustment module 405 is used to adjust the consensus algorithm of the blockchain within the time period t+1 to the target consensus algorithm.

[0140] Optionally, the first feature extraction module 402 is specifically used for:

[0141] The first data element is subjected to feature extraction to obtain the second feature set;

[0142] Anomaly detection is performed on the second feature set using the second model to obtain the first feature set, which is the feature set obtained after filtering out abnormal features from the second feature set.

[0143] Optionally, the device further includes:

[0144] The second acquisition module is used to acquire the second data element of the blockchain, wherein the second data element is a data element within a historical time period relative to the first data element.

[0145] The second feature extraction module is used to extract features from the second data element to obtain a third feature set, which is a set of feature representations of the second data element.

[0146] The training module is used to train the first model and the second model respectively based on the third feature set.

[0147] Optionally, the device further includes:

[0148] A block creation module is used to create new blocks on the blockchain using the target consensus algorithm.

[0149] Anomaly detection module, used to perform anomaly detection on the block using the second model;

[0150] The triggering module is used to trigger a response mechanism corresponding to the attack type of the block when the anomaly detection result of the block indicates that the block is abnormal. The attack type of the block is obtained based on the block characteristics of the block. The response mechanism is used to process the anomaly of the block and / or update the target consensus algorithm applied to the blockchain.

[0151] Optionally, the anomaly detection module is specifically used for:

[0152] If the validity of the block is verified, the third data element of the block is obtained;

[0153] Feature extraction is performed on the third data element to obtain the block features of the block;

[0154] The block features of the block are input into the second model to perform anomaly detection of the block.

[0155] Optionally, the device further includes an update module, the update module being configured to:

[0156] Based on the target loss gradient function and the learning rate of the second model, using Update the model parameters of the second model;

[0157] in, The model parameters of the second model within the time period t. The model parameters of the second model within the time period t+1. The learning rate of the second model is... The target loss gradient function is the block feature of the block. and the anomaly detection results of the block The loss gradient function.

[0158] The block consensus processing device 400 can implement all the processes implemented in the above-described block consensus processing method embodiments and achieve the same technical effect. To avoid repetition, it will not be described again here.

[0159] See Figure 5 The figure shows a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Figure 5 As shown, the electronic device 500 includes: a processor 501, a memory 502, a user interface 503, and a bus interface 504.

[0160] Processor 501 is used to read the program from memory 502 and execute the following procedures:

[0161] Obtain the first data element of the blockchain within time period t;

[0162] Feature extraction is performed on the first data element to obtain a first feature set, which is a set of feature representations of the first data element;

[0163] Based on the first feature set, the first model is used to predict M score information corresponding to M preset consensus algorithms. The score information indicates the network performance when the preset consensus algorithm is applied to the blockchain, and M is a positive integer greater than 1.

[0164] Based on the M rating information, a target consensus algorithm is selected from the M preset consensus algorithms for application to the blockchain. The blockchain network performance indicated by the first rating information in the M rating information is better than the blockchain network performance indicated by the second rating information in the M rating information. The first rating information is the rating information corresponding to the target consensus algorithm, and the second rating information is the rating information corresponding to other preset consensus algorithms in the M preset consensus algorithms besides the target consensus algorithm.

[0165] The consensus algorithm of the blockchain within the time period t+1 is adjusted to the target consensus algorithm.

[0166] exist Figure 5 In this context, the bus architecture can include any number of interconnected buses and bridges, specifically linking various circuits of one or more processors represented by processor 501 and memory represented by memory 502 together. The bus architecture can also link various other circuits such as peripheral devices, voltage regulators, and power management circuits, which are well known in the art and therefore will not be described further herein. Bus interface 504 provides an interface. For different user devices, user interface 503 can also be an interface capable of connecting external or internal devices, including but not limited to keypads, displays, speakers, microphones, joysticks, etc.

[0167] The processor 501 is responsible for managing the bus architecture and general processing, while the memory 502 can store the data used by the processor 501 when performing operations.

[0168] In some embodiments, the processor 501 is further configured to:

[0169] The first data element is subjected to feature extraction to obtain the second feature set;

[0170] Anomaly detection is performed on the second feature set using the second model to obtain the first feature set, which is the feature set obtained after filtering out abnormal features from the second feature set.

[0171] In some embodiments, the processor 501 is further configured to:

[0172] Obtain the second data element of the blockchain, wherein the second data element is a data element within a historical time period relative to the first data element;

[0173] Feature extraction is performed on the second data element to obtain a third feature set, which is a set of feature representations of the second data element;

[0174] Based on the third feature set, the first model and the second model are trained respectively.

[0175] In some embodiments, the processor 501 is further configured to:

[0176] The target consensus algorithm is used to create a new block on the blockchain;

[0177] The second model is used to perform anomaly detection on the block;

[0178] If the anomaly detection result of the block indicates that the block is abnormal, a response mechanism corresponding to the attack type of the block is triggered. The attack type of the block is obtained based on the block characteristics. The response mechanism is used to process the anomaly of the block and / or update the target consensus algorithm applied to the blockchain.

[0179] In some embodiments, the processor 501 is further configured to:

[0180] If the validity of the block is verified, the third data element of the block is obtained;

[0181] Feature extraction is performed on the third data element to obtain the block features of the block;

[0182] The block features of the block are input into the second model to perform anomaly detection of the block.

[0183] In some embodiments, the processor 501 is further configured to:

[0184] Based on the target loss gradient function and the learning rate of the second model, using Update the model parameters of the second model;

[0185] in, The model parameters of the second model within the time period t. The model parameters of the second model within the time period t+1. The learning rate of the second model is... The target loss gradient function is the block feature of the block. and the anomaly detection results of the block The loss gradient function.

[0186] Preferably, the present invention also provides an electronic device 500, including a processor 501, a memory 502, and a computer program stored in the memory 502 and executable on the processor 501. When the computer program is executed by the processor 501, it implements the various processes of the above-described block consensus processing method embodiments and achieves the same technical effect. To avoid repetition, it will not be described again here.

[0187] This invention also provides a readable storage medium storing a computer program. When executed by a processor, this computer program implements the various processes of the above-described block consensus processing method embodiments and achieves the same technical effects. To avoid repetition, it will not be described again here. The readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc.

[0188] This application also provides a computer program product, including computer instructions. When these computer instructions are executed by a processor, they implement the various processes of the above-described block consensus processing method embodiments and achieve the same technical effects. To avoid repetition, they will not be described again here.

[0189] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.

[0190] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0191] In the embodiments provided in this application, it should be understood that the disclosed systems and methods can be implemented in other ways. For example, the system embodiments described above are merely illustrative. For instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interfaces, devices, or units, and may be electrical, mechanical, or other forms.

[0192] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of the embodiments of the present invention, depending on actual needs.

[0193] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0194] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, ROM, RAM, magnetic disks, or optical disks.

[0195] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A block consensus processing method, characterized in that, The method includes: Obtain the first data element of the blockchain within time period t; Feature extraction is performed on the first data element to obtain a first feature set, which is a set of feature representations of the first data element; Based on the first feature set, the first model is used to predict M score information corresponding to M preset consensus algorithms. The score information indicates the network performance when the preset consensus algorithm is applied to the blockchain, and M is a positive integer greater than 1. Based on the M rating information, a target consensus algorithm is selected from the M preset consensus algorithms for application to the blockchain. The blockchain network performance indicated by the first rating information in the M rating information is better than the blockchain network performance indicated by the second rating information in the M rating information. The first rating information is the rating information corresponding to the target consensus algorithm, and the second rating information is the rating information corresponding to other preset consensus algorithms in the M preset consensus algorithms besides the target consensus algorithm. The consensus algorithm of the blockchain within the time period t+1 is adjusted to the target consensus algorithm.

2. The method according to claim 1, characterized in that, The step of extracting features from the first data element to obtain a first feature set includes: The first data element is subjected to feature extraction to obtain the second feature set; Anomaly detection is performed on the second feature set using the second model to obtain the first feature set, which is the feature set obtained after filtering out abnormal features from the second feature set.

3. The method according to claim 2, characterized in that, Before predicting the M scoring information corresponding to the M preset consensus algorithms one-to-one using the first model based on the first feature set, the method further includes: Obtain the second data element of the blockchain, wherein the second data element is a data element within a historical time period relative to the first data element; Feature extraction is performed on the second data element to obtain a third feature set, which is a set of feature representations of the second data element; Based on the third feature set, the first model and the second model are trained respectively.

4. The method according to claim 1 or 2, characterized in that, After adjusting the consensus algorithm of the blockchain within the time period t+1 to the target consensus algorithm, the method further includes: The target consensus algorithm is used to create a new block on the blockchain; Anomaly detection is performed on the block using a second model; If the anomaly detection result of the block indicates that the block is abnormal, a response mechanism corresponding to the attack type of the block is triggered. The attack type of the block is obtained based on the block characteristics. The response mechanism is used to process the anomaly of the block and / or update the target consensus algorithm applied to the blockchain.

5. The method according to claim 4, characterized in that, The anomaly detection of the block using the second model includes: If the validity of the block is verified, the third data element of the block is obtained; Feature extraction is performed on the third data element to obtain the block features of the block; The block features of the block are input into the second model to perform anomaly detection of the block.

6. The method according to claim 5, characterized in that, After inputting the block features of the block into the second model for anomaly detection of the block, the method further includes: Based on the target loss gradient function and the learning rate of the second model, using Update the model parameters of the second model; in, The model parameters of the second model within the time period t. The model parameters of the second model within the time period t+1. The learning rate of the second model is... The target loss gradient function is the block feature of the block. and the anomaly detection results of the block The loss gradient function.

7. A block consensus processing device, characterized in that, The device includes: The first acquisition module is used to acquire the first data element of the blockchain within the time period t. The first feature extraction module is used to extract features from the first data element to obtain a first feature set, wherein the first feature set is a set of feature representations of the first data element. The prediction module is used to predict M score information corresponding to M preset consensus algorithms based on the first feature set and using the first model. The score information indicates the network performance when the preset consensus algorithm is applied to the blockchain, and M is a positive integer greater than 1. The selection module is used to select a target consensus algorithm for the blockchain from the M preset consensus algorithms based on the M rating information. The blockchain network performance indicated by the first rating information in the M rating information is better than the blockchain network performance indicated by the second rating information in the M rating information. The first rating information is the rating information corresponding to the target consensus algorithm, and the second rating information is the rating information corresponding to other preset consensus algorithms in the M preset consensus algorithms besides the target consensus algorithm. The adjustment module is used to adjust the consensus algorithm of the blockchain to the target consensus algorithm within the time period t+1.

8. An electronic device, characterized in that, include: A processor, a memory, and a program stored in the memory and executable on the processor, wherein the program, when executed by the processor, implements the steps of the block consensus processing method as described in any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the block consensus processing method as described in any one of claims 1 to 6.

10. A computer program product, characterized in that, It includes computer instructions that, when executed by a processor, implement the steps of the block consensus processing method as described in any one of claims 1 to 6.