Blockchain consensus method, device, electronic device, and program
By enabling flexible online switching between multiple consensus algorithms, the method enhances the adaptability and efficiency of blockchain networks, addressing the inflexibility of unified consensus algorithms and reducing service disruptions.
Patent Information
- Application Number
- JP2024532392
- Authority / Receiving Office
- JP · JP
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2022-06-02
- Filing Date
- 2023-04-03
- Publication Date
- 2024-11-15
- Estimated Expiration
- 2043-04-03
AI Technical Summary
Current blockchain networks face challenges in flexibility due to the use of a unified consensus algorithm, which struggles to adapt to the diverse and changing requirements of business systems, leading to inefficiencies and service disruptions during algorithm switching.
Implementing a method that allows for flexible online switching between multiple consensus algorithms, enabling blockchain nodes to execute at least two different types of consensus algorithms and synchronize results based on the number of nodes satisfying specific conditions, thereby enhancing flexibility and reducing service interruptions.
This approach enables blockchain networks to adapt to varying business demands without stopping services, improving efficiency and reliability by allowing seamless transitions between consensus algorithms.
Smart Images

Figure 2024542677000001_ABST
Abstract
Description
[Technical field]
[0001] This application seeks priority from a Chinese patent application filed with the China Patent Office on June 2, 2022, bearing application number 202210622140.7 and entitled "Blockchain consensus method, apparatus, medium and electronic device", the entire contents of which are incorporated herein by reference.
[0002] This application belongs to the field of blockchain technology, and specifically relates to blockchain consensus. [Background technology]
[0003] In a blockchain network that includes multiple blockchain nodes, in order to realize a distributed trust environment, all blockchain nodes generally need to run a unified consensus algorithm to synchronize data consistency between each node. However, the unified consensus algorithm has problems in that it is difficult to meet the business requirements of a diversified system and has low flexibility. Summary of the Invention [Problem to be solved by the invention]
[0004] The present application provides a blockchain consensus method, a blockchain consensus device, a computer-readable medium, an electronic device and a computer program product, the purpose of which is to enhance the flexibility of blockchain consensus. [Means for solving the problem]
[0005] Additional features and advantages of the present application will become apparent from the following detailed description, or in part will be learned by the practice of the present application.
[0006] According to one aspect of an embodiment of the present application, a blockchain consensus method is provided, the method being executed by a current blockchain node in a blockchain network, the method comprising: Broadcasting a consensus request corresponding to at least two consensus stages in the blockchain network, the blockchain network including at least two blockchain nodes executing different types of consensus algorithms, the different types of consensus algorithms including a first consensus algorithm and a second consensus algorithm; respectively obtaining a response message broadcast by the blockchain network in each of the consensus stages, the response message being a message in which the blockchain node responds to the consensus request; Counting the number of blockchain nodes that issued the response messages in the same consensus stage, the number of nodes including the number of blockchain nodes that execute at least two different types of consensus algorithms; If the number of nodes satisfies the consensus condition of the first consensus algorithm, achieving consensus on the blockchain nodes that execute the first consensus algorithm, and synchronizing the consensus result of the first consensus algorithm to the blockchain nodes that execute the second consensus algorithm.
[0007] According to one aspect of the present embodiment, there is provided a blockchain consensus device, the device comprising: A request module configured to broadcast a consensus request corresponding to at least two consensus stages in a blockchain network, the blockchain network including at least two blockchain nodes implementing different types of consensus algorithms, the different types of consensus algorithms including a first consensus algorithm and a second consensus algorithm; A response module configured to respectively obtain a response message broadcast by the blockchain network in each of the consensus stages, the response message being a message in which the blockchain node responds to the consensus request; A statistics module configured to count the number of blockchain nodes that issued the response message in the same consensus stage, the number of nodes including the number of blockchain nodes that execute at least two different types of consensus algorithms; and a synchronization module configured to achieve consensus on blockchain nodes that execute the first consensus algorithm if the number of nodes satisfies a consensus condition of the first consensus algorithm, and synchronize a consensus result of the first consensus algorithm to blockchain nodes that execute the second consensus algorithm.
[0008] According to one aspect of the present embodiment, a computer-readable medium is provided, which stores a computer program, and when the computer program is executed by a processor, the blockchain consensus method in the above technical solution is realized.
[0009] According to one aspect of an embodiment of the present application, an electronic device is provided, the electronic device including a processor and a memory for storing executable instructions of the processor, the processor being configured to execute the blockchain consensus method in the above technical solution by executing the executable instructions.
[0010] According to one aspect of an embodiment of the present application, a computer program product is provided, which includes a computer program, and when the computer program is executed by a processor, the blockchain consensus method in the above technical solution is realized.
[0011] In some embodiments of the present application, the computer program product or computer program includes a computer program, and the computer program is stored in a computer-readable storage medium. A processor of a computer device reads the computer program from the computer-readable storage medium, and the processor executes the computer program to cause the computer device to perform the blockchain consensus method in the above technical solution.
[0012] In the technical solution provided by the embodiments of the present application, by configuring at least two blockchain nodes that run different types of consensus algorithms in a blockchain network, the number of blockchain nodes that issue consensus responses can be counted in the process of implementing node consensus. When the number of nodes meets the consensus conditions of any one consensus algorithm, the consensus result can be synchronized from the blockchain nodes that meet the consensus conditions to the blockchain nodes that do not meet the consensus conditions, thereby improving the flexibility of blockchain consensus.
[0013] It should be understood that the above general description and the latter detailed description are merely illustrative and explanatory, and are not intended to limit the present application. [Brief description of the drawings]
[0014] [Figure 1] FIG. 1 is a schematic diagram of a block chain system according to an embodiment of the present invention. [Diagram 2] It is the structural structure of a blockchain that is maintained on a blockchain network. [Diagram 3] 1 is an exemplary network structure of a blockchain network to which the technical solution of the present application is applied. [Figure 4] FIG. 1 is a step flow diagram of a blockchain consensus method in one embodiment of the present application. [Diagram 5] 1 illustrates a data structure of a response message in one embodiment of the present application. [Figure 6] In one embodiment of the present application, a blockchain consensus method for counting the number of nodes based on the consensus stage is provided. [Figure 7] 1 illustrates a consensus flow of a low fault-tolerant consensus algorithm in one embodiment of the present application. [Figure 8] 1 illustrates a consensus flow of a highly fault-tolerant consensus algorithm in one embodiment of the present application. [Figure 9] 11 is a diagram illustrating an example of a scene in the process of executing algorithm switching according to an embodiment of the present invention. [Figure 10] FIG. 1 is a step flow diagram of a method for performing consensus authentication in an application scenario according to an embodiment of the present application. [Figure 11] FIG. 2 is a structural block diagram of a blockchain consensus device provided by an exemplary embodiment of the present application. [Figure 12] FIG. 2 is a structural block diagram of a computer system of an electronic device suitable for implementing the exemplary embodiments of the present application. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS
[0015] Exemplary embodiments will now be described more fully with reference to the accompanying drawings, in which: FIG. 1 is a schematic diagram of an exemplary embodiment of a semiconductor memory device according to the present invention; FIG. 2 is a schematic diagram of an exemplary embodiment of a semiconductor memory device according to the present invention;
[0016] Furthermore, the depicted features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to facilitate a thorough understanding of the embodiments of the present application. However, as will be recognized by those skilled in the art, one or more of the details may not be specified when implementing the technical solutions of the present application, or other methods, units, devices, steps, etc. may be employed. In other cases, well-known methods, devices, implementations, and operations are not shown or described in detail to avoid obscuring aspects of the present application.
[0017] The block diagrams shown in the accompanying drawings are merely functional entities that do not necessarily correspond to each other physically separate entities, i.e. they may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor and / or microcontroller devices.
[0018] The flow charts shown in the accompanying drawings are merely illustrative and do not necessarily include all contents and operations / steps, and do not necessarily have to be performed in the order depicted. For example, some operations / steps can be further decomposed, and some operations / steps can be merged or partially merged, so that the order of actual execution may be changed according to actual circumstances.
[0019] In specific embodiments of the present application, with regard to relevant data such as requests, responses and the like generated by users when applying blockchain products, permission or consent from users must be obtained when implementing each embodiment of the present application in a specific product or technology, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions.
[0020] Blockchain is a digital ledger with a chained-block data structure that is built by transparent and reliable rules in a peer network environment, and is shared in a manner that is anti-counterfeit, anti-tamper and traceable. Blockchain data structures store transactions that occur within a certain period of time as blocks, and link the blocks to a chain in chronological order using an encryption algorithm. The ledger is distributed to all member nodes in the network, and the history of asset transactions that occur between peer nodes in the network is permanently recorded in a sequential chain of blocks linked by a hash encryption algorithm. All confirmed and verified transactions are chained from the chain header to the latest block, hence the name blockchain, and the blockchain can be used as a single source of truth, and members in the blockchain network can only confirm transactions related to them.
[0021] FIG. 1 shows a schematic diagram of the composition of a blockchain system in an embodiment of the present application. The blockchain system 100 may include at least one client 110 and a blockchain network 120, and the blockchain network 120 includes at least one blockchain node 121. The client 110 may be various electronic devices such as a smart phone, a tablet PC, a laptop, a desktop computer, a wearable device, a smart in-vehicle device, a smart payment terminal, a face recognition terminal, etc., and may provide users with blockchain data services by implementing corresponding client application programs. The blockchain node 121 may be a terminal device or a server. For example, the blockchain node 121 may be an independent physical server, or may be a server group composed of multiple physical servers, or may even be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud memory, network services, cloud communications, middleware services, domain services, security services, CDN, and big data and artificial intelligence platforms.
[0022] In the blockchain network 120, each blockchain node 121 can receive input information during normal operation and maintain shared data in the blockchain network based on the received input information. To ensure information interconnection, there can be information connections between each blockchain node 121, and each blockchain node 121 can transmit information to each other through the information connections. For example, when any blockchain node 121 in the blockchain network 120 receives input information and broadcasts the input information in the blockchain network 120, other node devices in the blockchain network 120 can obtain the input information based on a consensus algorithm and store the input information as shared data.
[0023] Each blockchain node 121 in the blockchain network 120 has a corresponding node identifier, and each blockchain node 121 in the blockchain network 120 stores the node identifiers of other blockchain nodes in the same blockchain network, and in a subsequent process can broadcast the generated blocks to other nodes in the blockchain network 120 based on the node identifiers of other blockchain nodes. The blockchain node 121 can maintain a node identifier list shown in Table 1, and can store the node name and the node identifier in the node identifier list in association with each other. The node identifier can be an IP (Internet Protocol, an interconnection protocol between networks) address or any other type of information that can be used to identify the node, and Table 1 is a node identifier list using an IP address as an example.
[0024] [Table 1]
[0025] FIG. 2 shows the configuration structure of a blockchain maintained on a blockchain network. As shown in FIG. 2, a blockchain is composed of multiple sequentially linked blocks, and when new data needs to be written to the blockchain, the data is aggregated into one newly generated block, and the newly generated block is linked to the end of the blockchain, and a consensus algorithm can ensure that the blocks newly added by each node device 121 are completely identical. The data of the current block is recorded in the block body of each block, and at the same time, the hash value of the previous block linked to it is stored in the block header, and when a change occurs in the transaction data in the previous block, the hash value of the current block also changes accordingly. Therefore, it becomes difficult to tamper with the data uploaded in the blockchain network, and the reliability of the shared data can be improved.
[0026] The network structure of a block chain network to which the technical solution of the present application is applied is shown in Figure 3. As shown in Figure 3, in the application scenario of realizing network transactions and network payments, a transaction subject node 310, a transaction platform node 320 and a resource allocation node 330 located in the block chain network jointly maintain one or more block chains 340.
[0027] The transaction subject node 310 is a blockchain node that provides transaction services for users, and may be, for example, a shop or individual merchant that conducts network transactions with users.
[0028] The transaction platform node 320 is a blockchain node that provides a transaction scene for network transactions, and may be, for example, an e-commerce site, an online shopping mall, or various business platforms that provide network transaction services.
[0029] The resource allocation node 330 is a blockchain node that provides fund management and allocation services for network transactions, and may be, for example, a third-party payment institution.
[0030] When a user conducts a network transaction with the transaction subject node 310, the user pays the transaction funds to the transaction subject node 310 through an account opened on the resource allocation node 330, and the transaction platform node 320 needs to deduct a certain amount of funds from the transaction funds as a platform service fee in providing the transaction scene. In order to realize reliable fund allocation between the transaction subject node 310 and the transaction platform node 320, a smart contract (e.g., a separate account contract) can be concluded for appropriate fund allocation based on the blockchain network. When a network transaction occurs, the resource allocation node 330 allocates funds to each target in the transaction scene according to the smart contract, and the transaction data generated by the network transaction on each blockchain node can be uploaded and stored through the blockchain 340, and the distributed data storage can effectively avoid the crisis of losing trust.
[0031] Although errors such as node down, network failure, software error, and malicious node may cause data stored between each blockchain node to become inconsistent, the consensus algorithm defines a distributed algorithm of network interaction between a pair of nodes, and even in a system environment where the above errors occur, the consistency of data between each blockchain node can still be ensured. In the related technology of the present application, all blockchain nodes in a blockchain network must adopt a unified consensus algorithm to perform consensus authentication and ensure the consistency of the consensus process and the consensus result. However, in the actual blockchain business processing process, the upper-layer business system using the blockchain service is constantly changed according to the user's demand, and has different requirements in terms of performance, availability, fault tolerance, scalability, etc. Current blockchain networks only adopt a single consensus algorithm, and therefore cannot adapt to the requirements of the upper-layer business system. When it is necessary to change the consensus algorithm of a blockchain node on a blockchain network, the service of the entire blockchain network must be stopped, and after waiting for the algorithm change for all blockchain nodes to be completed, the blockchain network with the new consensus algorithm configured must be started again. This type of consensus algorithm switching method is prone to long-term and frequent service interruptions, which not only reduces the efficiency of consensus algorithm switching, but also has a significant impact on the continuity and stable reliability of services in the blockchain network.
[0032] In response to the above technical problems existing in the related art, the present application provides a technical solution that enables flexibly switching between multiple different types of consensus algorithms online, so that the consensus algorithm can be changed in real time to meet the requirements of the business system while the blockchain system does not stop service.
[0033] The following provides a detailed description of the technical solutions provided by the present application, including the blockchain consensus method, the blockchain consensus device, the computer-readable medium, the electronic device, and the computer program product, in combination with specific embodiments.
[0034] Fig. 4 shows a step flow diagram of a blockchain consensus method in one embodiment of the present application, and the blockchain consensus method can be executed by the client or blockchain node shown in Fig. 1. However, for convenience of explanation, any one blockchain node in the blockchain network is set as the current blockchain node, the current blockchain node is set as the executing entity that executes the embodiment of the present application, and the current blockchain node is set as the client shown in Fig. 1. The blockchain consensus method executed on the current blockchain node in the embodiment of the present application will be described as an example. As shown in Fig. 4, the blockchain consensus method in the embodiment of the present application includes the following S410 to S440.
[0035] S410: Broadcast a consensus request corresponding to at least two consensus stages in a blockchain network, where the blockchain network includes at least two blockchain nodes that execute different types of consensus algorithms.
[0036] The blockchain network in the embodiment of the present application may include any one of the following: a public block chain, a private block chain, or a consortium block chain. The public chain has the highest degree of decentralization. Any node / participant who joins the public chain can read data on the chain, propose transactions, and compete for the right to record new blocks, and each node / participant can freely join and leave the public chain. The private chain is the opposite, in that the right to record in the private chain is controlled by an organization or institution, and the right to read data is also controlled by the organization or institution, there are few participants, and participants cannot join the private chain at will, but must pass the screening of the organization or institution. The consortium chain is also called a community blockchain, and refers to a blockchain in which the consensus process is controlled by pre-selected nodes. It is a combination of a public chain and a private chain, and can achieve a "partial decentralization". Each node on the chain usually has a corresponding entity or organization, and participants are authorized to join the network and form interest-related consortia to jointly maintain the operation of the blockchain. A consortium chain allows new participants to join an already-formed blockchain and share data, without having to build it from scratch. Whether it is a public chain, private chain, or consortium chain, they can all provide smart contract functionality. A smart contract on a blockchain is a contract that can be executed in response to transactions on the blockchain system. A smart contract can be defined in the form of code.
[0037] A smart contract, also called chaincode or application code, is a computer protocol that aims to transmit, verify, or execute contracts in an informationized way. It is placed in a program in a node of a blockchain network, is equipped with business logic to execute transactions, and operates in an isolated operating environment (e.g., a container or virtual machine). Each node in a blockchain system can manipulate data stored on the chain based on a contract program that is automatically executed under certain conditions, and is an important route for realizing business logic using blockchain, as the business entity and the blockchain interact bidirectionally. The purpose of a smart contract is to provide a better security method than traditional contracts and reduce other transaction costs related to contracts, allowing reliable transactions without a third party, and those transactions are traceable and irreversible.
[0038] The transaction data generated based on the smart contract must be authenticated by consensus among different blockchain nodes through a consensus algorithm to ensure that the corresponding transaction data can be stored on each blockchain node. In one embodiment of the present application, when a user performs a network transaction through a client that operates a blockchain system to generate transaction data, the client can send a consensus request to the blockchain node that communicates with it, and the blockchain node that receives the consensus request can broadcast it on the blockchain network, so that the consensus request can be transmitted to all blockchain nodes in the blockchain network.
[0039] In the present embodiment, at least two different types of consensus algorithms can be simultaneously operated on the blockchain network, for example, some blockchain nodes in the blockchain network can run a first consensus algorithm, and other blockchain nodes can run a second consensus algorithm different from the first consensus algorithm. The first consensus algorithm and the second consensus algorithm can have the same consensus condition or different consensus condition. The first consensus algorithm and the second consensus algorithm can have the same number of consensus stages or different numbers of consensus stages.
[0040] In one embodiment of the present application, one or more blockchain nodes from the blockchain network can be selected as master nodes to process the consensus request, and other blockchain nodes in the blockchain network except the master node are slave nodes. When a client generates a consensus request, it can first send the consensus request to the master node, and the master node again distributes the consensus request to each slave node. The master node can be generated by voting election, rotation designation, random selection, etc.
[0041] S420: Obtain a response message broadcast by the blockchain network at each consensus stage, where the response message is a message in which the blockchain node responds to the consensus request.
[0042] When a blockchain node in a blockchain network receives a consensus request, it may generate a response message and broadcast the response message on the blockchain network in response to the consensus request.
[0043] In one embodiment of the present application, a blockchain node can perform consensus verification on a received consensus request, and broadcast a response message on the blockchain network after passing the verification. The consensus verification of a blockchain node on a consensus request can include two aspects: signature verification and data verification. Signature verification is used to verify the authenticity of the source of the consensus request, and data verification is used to verify the authenticity of the content of the consensus request.
[0044] In one embodiment of the present application, a consensus request broadcast in the blockchain network carries a digital signature of the blockchain node that issued the consensus request, and a response message broadcast in the blockchain network also carries a digital signature of the blockchain node that issued the response message. Each blockchain node in the blockchain network may possess a public key and a private key that constitute an asymmetric cryptographic key pair. When digitally signing a consensus request or a response message, the blockchain node first extracts a content digest from the data content through a digest extraction algorithm, and then further uses the private key to encrypt the content digest to form a digital signature, and the digital signature can be verified by the public key.
[0045] A content digest is a character string with a fixed length that is uniquely associated with one item of data content, and is generated by applying a one-way hash encryption function to the data content. If the data content is tampered with during network transmission, it is possible to determine whether the data content has been altered by comparing the content digests of the data content before and after transmission. Therefore, the integrity of the data content can be verified based on the content digest. The content digest employs a one-way hash function to map the plaintext of the data content to be transmitted into a series of ciphertexts, which are also called digital fingerprints. The content digest has a fixed length, and when different plaintext digests are ciphertexted, the results are always different, but similar plaintext always has a matching digest. The digest extraction algorithm in the present embodiment can include algorithms such as MD (Message Digest), SHA (Secure Hash Algorithm), and MAC (Message Authentication Code).
[0046] Digital signature is a message digest algorithm with encryption keys, including public and private keys, which is used to verify data integrity, authenticate data source and non-repudiation, comply with the OSI reference model, and verify private key signature and public key verification. It is also a combination of asymmetric encryption algorithm and message digest algorithm, and the three most commonly seen digital signature algorithms are RSA, DSA, and ECDSA.
[0047] Based on the RSA algorithm, a pair of RSA private keys can be generated first, one of which is a private key that is kept secret and is stored by the business entity, and the other is a public private key that can be registered in a network server and can be made public. In order to improve the strength of confidentiality, it is recommended that the RSA private key be at least 500 bits long, and generally 1024 bits. This makes the calculation amount of encryption very large. In order to reduce the calculation amount, a method that combines traditional encryption method and public key encryption method is always adopted when transmitting information, that is, the information is encrypted by adopting an improved DES or IDEA session key, and then the RSA encryption key is used to encrypt the session key and the information digest. After the other party receives the information, it can use a different private key to decrypt it and check the information digest.
[0048] One important feature of the Digital Signature Algorithm (DSA) is the publication of two prime numbers, so that anyone using p and q of another entity can verify whether they were generated randomly or whether they were forged or altered, without knowing the private key.
[0049] ECDSA (Elliptic Curve Digital Signature Algorithm) is a combination of ECC (Elliptic Curve Cryptography) and DSA. The whole signing process is similar to DSA, except that the algorithm used for signing is ECC, and the final signed value is also divided into two parameters, r and s.
[0050] In one embodiment of the present application, after the signature verification for the consensus request is completed, the data content included in the consensus request can be verified. The data verification method can include, for example, checking the consistency between the data content included in the consensus request and the data content temporarily stored locally in the current blockchain node. If the verification is passed, it indicates that the same data content is temporarily stored in the blockchain node that issued the consensus request and the current blockchain node, and the data content has not been modified during the network transmission process.
[0051] S430: Count the number of blockchain nodes that issue response messages in the same consensus stage, where the number of nodes includes the number of blockchain nodes that execute at least two different types of consensus algorithms.
[0052] When a blockchain node receives the response message broadcast in the blockchain network, the response message can be analyzed to determine the message source of each response message, and the statistics of the response messages with different message sources can be used to count the number of blockchain nodes that issue response messages, which indicates the number of blockchain nodes that execute different types of consensus algorithms in the blockchain network in response to the consensus request.
[0053] In one embodiment of the present application, each blockchain node can receive and count response messages issued by other blockchain nodes. For example, if a blockchain network includes n blockchain nodes, each blockchain node can receive at most n-1 response messages issued by other blockchain nodes. At the same time, each blockchain node also sends a response message externally. Therefore, the number of blockchain nodes that have issued response messages counted by one blockchain node is at most the total number of blockchain nodes in the blockchain network. Each blockchain node performs statistics on message sources, which can improve the reliability of the consensus process.
[0054] In one embodiment of the present application, one or more master nodes in a blockchain network can take source statistics for response messages, but other slave nodes do not need to perform quantity statistics. For example, in one consensus process, a master node is generated by voting election, rotation designation, random selection, etc., and after sending a consensus request in the blockchain network, the master node can monitor the response messages returned from the slave nodes in the blockchain network and count the number of slave nodes that have issued response messages. The advantage of performing message source statistics through a master node is that it can reduce the computational costs of other slave nodes and avoid the occurrence of extra data costs.
[0055] In one embodiment of the present application, in order to improve consensus efficiency, the number of blockchain nodes that issue response messages within a preset time range can be counted. If a new response message is received beyond the time range, it can be discarded and not included in the statistics.
[0056] In one embodiment of the present application, the time range for counting the number of nodes can be a fixed time window having a specified time length with the starting point of the range being a first time point when the current blockchain node receives a consensus request, and can also be a fixed time window having a specified time length with the starting point of the range being a second time point when the current blockchain node issues a response message.
[0057] In one embodiment of the present application, the time range for counting the number of nodes can be a dynamic time window with a variable length, the end point of which is determined based on the third time point when the most recent response message was received and a preset time length. For example, if the time point when a blockchain node received a response message most recently is A, the end point of the time range can be determined as A+B based on the time length B. If the blockchain node does not receive a new response message between time points A and A+B, the source statistics of the response message can be stopped. If the blockchain node further receives a new response message between time points A and A+B, for example, when a new response message is received at time point C, the end point of the time range can be updated to C+B, and similarly, if the blockchain node does not receive a new response message for a long period of time, the source statistics of the response message can be stopped.
[0058] In one embodiment of the present application, the time range for performing source statistics of response messages can be a time range with a static start point and a dynamic end point, for example, the static start point is any one of receiving a consensus request, issuing a response message, or receiving a response message for the first time, and the dynamic end point is determined according to the most recent reception of a new response message and a preset time length. By using a dynamically changing time range to perform statistics of message sources, the efficiency of statistics can be improved while ensuring the accuracy of data statistics, and the impact on consensus progress caused by an excessively long time range can be avoided, and the problem of incomplete data statistics caused by an excessively short time range can be avoided.
[0059] S440: If the number of nodes meets the consensus condition of the first consensus algorithm, achieve consensus on the blockchain node that runs the first consensus algorithm, and synchronize the consensus result of the first consensus algorithm to the blockchain node that runs the second consensus algorithm, where the first consensus algorithm and the second consensus algorithm are different types of consensus algorithms.
[0060] The consensus condition of the consensus algorithm is used to determine whether the judgment condition of the consensus result can be obtained, for example, the consensus condition of one consensus algorithm can be that the number of the blockchain nodes that issue the response message exceeds a preset ratio to the total number of blockchain nodes. Different types of consensus algorithms configured in the blockchain network may have the same consensus condition or different consensus conditions.
[0061] In one embodiment of the present application, a blockchain node in a blockchain network can determine whether the number of nodes obtained by statistics meets the consensus condition based on the consensus algorithm it executes. For example, if the consensus algorithm executed by the current blockchain node is a first consensus algorithm, it can determine whether the consensus condition of the first consensus algorithm is met based on the number of nodes obtained by statistics, and if the consensus algorithm executed by the current blockchain node is a second consensus algorithm, it can determine whether the consensus condition of the second consensus algorithm is met based on the number of nodes obtained by statistics.
[0062] In one embodiment of the present application, when some blockchain nodes in a blockchain network run a first consensus algorithm and another part of blockchain nodes run a second consensus algorithm, the consensus condition of the first consensus algorithm is that the statistical proportion of the number of blockchain nodes that issue a response message to the total number of blockchain nodes exceeds a first proportion threshold, and the consensus condition of the second consensus algorithm is that the statistical proportion of the number of blockchain nodes that issue a response message to the total number of blockchain nodes exceeds a second proportion threshold, and the second proportion threshold is greater than the first proportion threshold. If the proportion of the number of nodes obtained by the statistics to the total number of blockchain nodes is greater than the first proportion threshold but less than the second proportion threshold, it can be determined that the number of nodes meets the consensus condition of the first consensus algorithm but does not meet the consensus condition of the second consensus algorithm. Based on this, the blockchain node that implemented the first consensus algorithm can obtain a consensus result of successful consensus, and the blockchain node that implemented the second consensus algorithm has not yet succeeded in consensus, but can synchronize data with the blockchain node that implemented the second consensus algorithm through the blockchain node that implemented the first consensus algorithm, and the blockchain node that implemented the second consensus algorithm can also complete consensus.
[0063] In the blockchain consensus method provided by the embodiments of the present application, by configuring blockchain nodes that run at least two different types of consensus algorithms in a blockchain network, the number of blockchain nodes that issue consensus response messages in the process of implementing node consensus can be counted. When the number of nodes meets the consensus conditions of any one consensus algorithm, the consensus result can be synchronized from the blockchain nodes that meet the consensus conditions to the blockchain nodes that do not meet the consensus conditions, thereby improving the flexibility of blockchain consensus.
[0064] In one embodiment of the present application, different types of consensus algorithms have different numbers of consensus stages, and the response message transmits the algorithm type and node signature of the blockchain node, where the algorithm type is used to indicate the consensus algorithm executed by the blockchain node, and the node signature includes the digital signature of the blockchain node at each consensus stage.
[0065] A data structure of a response message in one embodiment of the present application is shown in Fig. 5. As shown in Fig. 5, a response message generated based on a certain consensus algorithm may include a type field 501, a signature field 502, and a data field 503.
[0066] The type field 501 is used to indicate the algorithm type of the consensus algorithm implemented by the blockchain node that issued the response message, and may include, for example, a CFT-based consensus algorithm or a BFT-based consensus algorithm.
[0067] A CFT-based consensus algorithm, or a crash fault tolerance algorithm (CFT), is a type of consensus algorithm that can guarantee the consistency of node data when faced with a crash error, including benign errors such as node downs and network errors.
[0068] A BFT-based consensus algorithm, or Byzantine Fault Tolerance algorithm (BFT), is a type of consensus algorithm that can guarantee the consistency of node data when faced with a Byzantine error. Byzantine errors include the above-mentioned fault errors, as well as software errors and malicious errors such as malicious nodes.
[0069] The signature field 502 is used to store the digital signatures of each consensus stage of the blockchain node that issued the response message, and may include, for example, a pre-preparation signature, a preparation signature, and a commit signature.
[0070] When a blockchain node that runs a CFT-based consensus algorithm generates a response message, it can use the pre-preparation phase signature and the commit phase signature in the data structure, and when a blockchain node that runs a BFT-based consensus algorithm generates a response message, it can use all three phases of signatures.
[0071] In one embodiment of the present application, a response message of one stage carries the digital signatures of all previous stages, for example, a first-stage response message carries the digital signature of the first stage, a second-stage response message carries the digital signatures of the first and second stages simultaneously, and a third-stage response message carries the digital signatures of the first, second and third stages simultaneously.
[0072] The data field 503 is used to store data requiring consensus authentication, which may be, for example, transaction data of a network transaction.
[0073] The response message data structure provided by the present embodiment can be applied to multiple different types of consensus algorithms at the same time, and consensus algorithms with different numbers of consensus stages can be consensus authenticated through the same response message, thereby improving the matching diversity of different consensus algorithms in the blockchain network.
[0074] For a consensus algorithm with different numbers of consensus stages, each blockchain node in a blockchain network has a certain difference in computing power and network transmission speed, so that in the process of performing consensus authentication, each blockchain node may be in a different consensus stage. Therefore, when a previous blockchain node receives a response message issued by another blockchain node, it should identify the corresponding consensus stage based on the response message to effectively count the node numbers of blockchain nodes located in different consensus stages. Figure 6 shows a blockchain consensus method for counting the node number based on the consensus stage in one embodiment of the present application. As shown in Figure 6, the method includes the following steps S610 to S670.
[0075] S610: Broadcast a consensus request corresponding to at least two consensus stages in a blockchain network, where the blockchain network includes at least two blockchain nodes that execute different types of consensus algorithms.
[0076] In the embodiment of the present application, at least two different types of consensus algorithms can be simultaneously operated on the blockchain network, for example, some blockchain nodes in the blockchain network run a first consensus algorithm, and another blockchain node runs a second consensus algorithm different from the first consensus algorithm. The first consensus algorithm and the second consensus algorithm can have the same consensus conditions or different consensus conditions.
[0077] In one embodiment of the present application, one or more blockchain nodes can be selected from the blockchain network as master nodes to process the consensus request, and other blockchain nodes in the blockchain network except the master node can be slave nodes. When a client generates a consensus request, it can first send the consensus request to the master node, and the master node can further distribute the consensus request to each slave node, and the master node can be generated by voting election, rotation designation, random selection, etc.
[0078] S620: Obtain a response message broadcast by the blockchain network at each consensus stage, where the response message is a message in which the blockchain node responds to the consensus request.
[0079] When a blockchain node in a blockchain network receives a consensus request, it may generate a response message and broadcast the response message on the blockchain network in response to the consensus request.
[0080] In one embodiment of the present application, a blockchain node can perform consensus verification on a received consensus request, and broadcast a response message on the blockchain network after passing the verification. The consensus verification of a blockchain node on a consensus request can include two aspects: signature verification and data verification. Signature verification is used to verify the source authenticity of the consensus request, and data verification is used to verify the authenticity of the content of the consensus request.
[0081] In one embodiment of the present application, a consensus request broadcast in the blockchain network carries a digital signature of the blockchain node that issued the consensus request, and a response message broadcast in the blockchain network also carries a digital signature of the blockchain node that issued the response message. Each blockchain node in the blockchain network may possess a public key and a private key that constitute an asymmetric cryptographic key pair, and when digitally signing a consensus request or a response message, it first extracts a content digest from the data content through a digest extraction algorithm, and then further uses the private key to encrypt the content digest to form a digital signature, and the digital signature can be verified by the public key.
[0082] In one embodiment of the present application, after the signature verification for the consensus request is completed, data verification can be performed on the data content included in the consensus request. The data verification method can include, for example, checking the consistency between the data content included in the consensus request and the data content temporarily stored locally in the current blockchain node. If the verification is passed, it indicates that the same data content is temporarily stored in the blockchain node that issued the consensus request and the current blockchain node, and the data content has not been modified during the network transmission process.
[0083] S630: Parse the response message to obtain the algorithm type and node signature contained in the response message.
[0084] The response message transmits the algorithm type and node signature of the blockchain node, where the algorithm type is used to indicate the consensus algorithm implemented by the blockchain node, and the node signature includes the digital signature of the blockchain node at each consensus stage.
[0085] By parsing the response message, we can obtain the data structure shown in Figure 6, from which we can obtain the algorithm type based on the type field, and the node signature corresponding to each consensus stage based on the signature field.
[0086] S640: Based on the algorithm type, identify the consensus algorithm executed by the message sending node, the message sending node being the blockchain node that issued the response message.
[0087] Each blockchain node in the blockchain network has a corresponding node identifier, and each blockchain node in the blockchain network stores the node identifiers of other blockchain nodes in the blockchain network, and in the subsequent process, can broadcast data such as generated consensus requests, response messages, and blocks waiting to be linked to the chain to other blockchain nodes in the blockchain network based on the node identifiers of other blockchain nodes. A node identifier list can be maintained in each blockchain node, and the node name and node identifier are correspondingly stored in the node identifier list. The node identifier can be an IP (Internet Protocol, an interconnection protocol between networks) address and any other information that can be used to identify the blockchain node.
[0088] When a blockchain node broadcasts a response message to the blockchain network, it can package its own node identifier in the response message.When the current blockchain node receives the response message broadcast on the blockchain network, it can determine the message sending node that issued the response message based on the node identifier obtained by parsing in the response message.It can determine the consensus algorithm that the message sending node is running based on the algorithm type obtained by parsing in the response message.
[0089] S650: Identify the consensus stage in which the message sending node is located based on the node signature.
[0090] By analyzing the response message, the signature field can be read to obtain the node signature corresponding to each consensus stage. Since each blockchain node may have a different consensus progress, the response message broadcast on the blockchain network may also transmit the node signature corresponding to different consensus stages. For example, if a blockchain node is in the pre-preparation stage, it transmits the node signature of the pre-preparation stage in the response message it issues; for example, if a blockchain node has already completed the consensus authentication of the pre-preparation stage and is currently in the preparation stage, it transmits the node signatures of both the pre-preparation stage and the preparation stage in the response message it issues.
[0091] In one embodiment of the present application, the response message can be analyzed to screen one or more consensus stages of the node signatures present therein, and the consensus stage in which the message sending node is currently located can be determined based on the execution order of each consensus stage.
[0092] If a node signature exists in only one consensus stage in a signature field, it can be determined that the message sending node is in that consensus stage. For example, if a node signature exists only in the pre-preparation stage in the signature field of a response message and the signature fields corresponding to the other consensus stages are blank, it can be determined that the message sending node that issued the response message is currently in the pre-preparation stage.
[0093] When a node signature exists in at least two consensus stages in a signature field, it can be determined based on the execution order of the at least two consensus stages that the consensus stage with the later execution order is the consensus stage in which the message sending node is currently located. For example, when a node signature exists in both the pre-preparation stage and the preparation stage in the signature field of a response message, and the signature fields corresponding to the other consensus stages are blank, it can be determined that the message sending node of the response message is currently in the preparation stage, because the preparation stage in the consensus algorithm is executed after the pre-preparation stage.
[0094] S660: Count the number of message sending nodes in the same consensus stage as the current blockchain node based on the consensus algorithm executed by the message sending node and the consensus stage in which the message sending node is located.
[0095] According to the consensus algorithm executed by the message sending node, it can be determined whether the message sending node is executing the same type of consensus algorithm as the current blockchain node. If the message sending node is executing the same type of consensus algorithm as the current blockchain node, it can be directly determined whether the message sending node is in the same consensus stage as the current blockchain node according to the consensus stage in which the message sending node is located. If the message sending node is executing a different type of consensus algorithm from the current blockchain node, it is necessary to determine whether the consensus stage in which the message sending node is located is the same as the current blockchain node according to the preset matching relationship.
[0096] Before counting the number of message sending nodes in the same consensus stage as the current blockchain node, the current blockchain node can first obtain the matching relationship of the consensus stages between different types of consensus algorithms. If the message sending node is running a different type of consensus algorithm than the current blockchain node, determine the message sending node in the same consensus stage as the current blockchain node based on the matching relationship.
[0097] For any two different types of consensus algorithms, it can be determined whether each blockchain node is in the same consensus stage based on the matching relationship. For example, if a message sending node executes one of the first consensus algorithm and the second consensus algorithm, and a current blockchain node executes the other of the first consensus algorithm and the second consensus algorithm, where the first consensus algorithm includes N consensus stages and the second consensus algorithm includes M consensus stages, the matching relationship of the consensus stages between different types of consensus algorithms includes the mutual matching of the first P consensus stages of the first consensus algorithm and the second consensus algorithm, where P is the smaller value of N-1 and M-1, and the mutual matching of the latter NP consensus stages of the first consensus algorithm and the latter MP consensus algorithm of the second consensus algorithm.
[0098] For example, if the first consensus algorithm is a CFT-based consensus algorithm, it includes two consensus stages, namely, a preparation stage and a commitment stage, and if the second consensus algorithm is a BFT-based consensus algorithm, it includes three consensus stages, namely, a pre-preparation stage, a preparation stage, and a commitment stage.
[0099] Based on the above matching relationships, the first consensus phase of the first consensus algorithm matches with the first consensus phase of the second consensus algorithm, that is, the preparation phase of the CFT-based consensus algorithm matches with the pre-preparation phase of the BFT-based consensus algorithm, the last consensus phase of the second consensus algorithm matches with the last two consensus phases of the second consensus algorithm, that is, the commit phase of the CFT-based consensus algorithm matches with the preparation phase and the commit phase of the BFT-based consensus algorithm.
[0100] Based on this, when one blockchain node is in the preparation stage of a CFT-based consensus algorithm and another blockchain node is in the pre-preparation stage of a BFT-based consensus algorithm, it can be determined that the two are in the same consensus stage; similarly, when one blockchain node is in the commit stage of a CFT-based consensus algorithm and another blockchain node is in the preparation stage or commit stage of a BFT-based consensus algorithm, it can be determined that the two are in the same consensus stage.
[0101] In one embodiment of the present application, after counting the number of message sending nodes in the same consensus stage as the current blockchain node, the current blockchain node can determine the subsequent algorithm execution operation according to the consensus stage in which it is located. If the consensus stage in which the current blockchain node is located is the last consensus stage in which the consensus algorithm is executed, determine the consensus result of the consensus algorithm according to whether the number of nodes meets the consensus conditions of the consensus algorithm; if the consensus stage in which the current blockchain node is located is not the last consensus stage in which the consensus algorithm is executed, determine whether to execute the next consensus stage of the consensus algorithm according to whether the number of nodes meets the consensus conditions of the consensus algorithm.
[0102] For example, if the consensus stage in which the current blockchain node is located is the preparation stage of the CFT-based consensus algorithm, it is possible to determine whether the number of nodes satisfies the consensus conditions of the CFT-based consensus algorithm by counting the number of blockchain nodes in the same consensus stage (including the preparation stage of the CFT-based consensus algorithm or the pre-preparation stage of the BFT-based consensus algorithm). If the consensus conditions of the CFT-based consensus algorithm are met, it can proceed to the commit stage. If the consensus conditions of the CFT-based consensus algorithm are not met, it is necessary to continue waiting for the reception of response messages issued by other blockchain nodes and update the statistical number of nodes in real time.
[0103] In one embodiment of the present application, each blockchain node can receive and count response messages issued by other blockchain nodes. For example, if a blockchain network includes n blockchain nodes, each blockchain node can receive n-1 response messages issued by other blockchain nodes at most, and at the same time, each blockchain node also sends a response message to the outside. Therefore, the maximum number of blockchain nodes that have issued response messages counted by one blockchain node is the total number of blockchain nodes in the blockchain network. Each blockchain node performs statistics on message sources, which can improve the reliability of the consensus process.
[0104] In one embodiment of the present application, one or more master nodes in a blockchain network can perform source statistics of response messages, but other slave nodes do not need to perform quantity statistics. For example, in one consensus process, a master node is generated by voting election, rotation designation, random selection, or other methods, and when the master node sends a consensus request to the blockchain network, it can monitor the response messages returned from the slave nodes in the blockchain network and count the number of slave nodes that issue response messages. The advantage of performing message source statistics through a master node is that it can reduce the computational costs of other slave nodes and avoid the occurrence of extra data costs.
[0105] In one embodiment of the present application, in order to improve consensus efficiency, the number of blockchain nodes that issue response messages within a preset time range can be counted. If a new response message is received beyond the time range, it can be discarded and not included in the statistics.
[0106] In one embodiment of the present application, the time range for counting the number of nodes can be a fixed time window having a specified time length with the starting point of the range being a first time point when the current blockchain node receives a consensus request, and can also be a fixed time window having a specified time length with the starting point of the range being a second time point when the current blockchain node issues a response message.
[0107] In one embodiment of the present application, the time range for counting the number of nodes can be a dynamic time window with a varying length, the end point of which is determined based on the third time point at which the most recent response message was received and a preset time length. For example, if the time point at which a blockchain node received a response message most recently is A, the end point of the time range can be determined as A+B based on the time length B. If the blockchain node does not receive a new response message between time points A and A+B, the source statistics of the response message can be stopped. If the blockchain node further receives a new response message between time points A and A+B, for example, if a new response message is received at time point C, the end point of the time range can be updated to C+B, and similarly, if the blockchain node does not receive a response message for a long period of time, the source statistics of the response message can be stopped.
[0108] In one embodiment of the present application, the time range for performing source statistics of response messages can be a time range with a static start point and a dynamic end point, for example, the static start point is any one of receiving a consensus request, issuing a response message, or receiving a response message for the first time, and the dynamic end point is determined according to the most recent reception of a new response message and a preset time length. By using a dynamically changing time range to perform statistics of message sources, the efficiency of statistics can be improved while ensuring the accuracy of data statistics, and the impact on consensus progress caused by an excessively long time range can be avoided, and the problem of incomplete data statistics caused by an excessively short time range can be avoided.
[0109] S670: If the number of nodes meets the consensus condition of the first consensus algorithm, achieve consensus on the blockchain nodes that run the first consensus algorithm, and synchronize the consensus result of the first consensus algorithm to the blockchain nodes that run the second consensus algorithm, where the first consensus algorithm and the second consensus algorithm are different types of consensus algorithms.
[0110] The consensus condition of the consensus algorithm is used to determine whether the judgment condition of the consensus result can be obtained, for example, the consensus condition of one consensus algorithm can be that the number of the blockchain nodes that issue the response message exceeds a preset ratio to the total number of blockchain nodes. Different types of consensus algorithms configured in the blockchain network may have the same consensus condition or different consensus conditions.
[0111] In one embodiment of the present application, a blockchain node in a blockchain network can determine whether the number of nodes obtained by statistics meets the consensus condition based on the consensus algorithm it executes. For example, if the consensus algorithm executed by the current blockchain node is a first consensus algorithm, it can determine whether the consensus condition of the first consensus algorithm is met based on the number of nodes obtained by statistics, and if the consensus algorithm executed by the current blockchain node is a second consensus algorithm, it can determine whether the consensus condition of the second consensus algorithm is met based on the number of nodes obtained by statistics.
[0112] In one embodiment of the present application, when some blockchain nodes in a blockchain network run a first consensus algorithm and another part of blockchain nodes run a second consensus algorithm, the consensus condition of the first consensus algorithm is that the statistical proportion of the number of blockchain nodes that issue a response message to the total number of blockchain nodes exceeds a first proportion threshold, and the consensus condition of the second consensus algorithm is that the statistical proportion of the number of blockchain nodes that issue a response message to the total number of blockchain nodes exceeds a second proportion threshold, and the second proportion threshold is greater than the first proportion threshold. If the proportion of the number of nodes obtained by the statistics to the total number of blockchain nodes is greater than the first proportion threshold but less than the second proportion threshold, it can be determined that the number of nodes meets the consensus condition of the first consensus algorithm but does not meet the consensus condition of the second consensus algorithm. Based on this, the blockchain node that implemented the first consensus algorithm can obtain a consensus result of successful consensus, and the blockchain node that implemented the second consensus algorithm has not yet succeeded in consensus, but can synchronize data with the blockchain node that implemented the second consensus algorithm through the blockchain node that implemented the first consensus algorithm, and the blockchain node that implemented the second consensus algorithm can also complete consensus.
[0113] In one embodiment of the present application, the first consensus algorithm is one of a low fault-tolerance consensus algorithm and a high fault-tolerance consensus algorithm, and the second consensus algorithm is another one of the low fault-tolerance consensus algorithm and the high fault-tolerance consensus algorithm that is different from the first consensus algorithm. The consensus condition of the low fault-tolerance consensus algorithm is that the proportion of the number of blockchain nodes that issue a response message to all blockchain nodes is greater than a first proportion threshold, and the consensus condition of the high fault-tolerance consensus algorithm is that the proportion of the number of blockchain nodes that issue a response message to all blockchain nodes is greater than a second proportion threshold, and the first proportion threshold is smaller than the second proportion threshold. The first proportion threshold and the second proportion threshold are both constants greater than 0 and less than 1. For example, the first proportion threshold is 1 / 2, and the second proportion threshold is 2 / 3.
[0114] If the ratio of the number of blockchain nodes that issue response messages to all blockchain nodes is less than 1 / 2, the number of nodes not only does not meet the consensus conditions of the low fault-tolerance consensus algorithm, but also does not meet the consensus conditions of the high fault-tolerance consensus algorithm, and all blockchain nodes running the two consensus algorithms cannot complete consensus authentication.
[0115] If the proportion of the number of blockchain nodes that issue response messages to all blockchain nodes is greater than 1 / 2 and less than 2 / 3, the number of nodes meets the consensus conditions of the low fault-tolerance consensus algorithm but does not meet the consensus conditions of the high fault-tolerance consensus algorithm, and the blockchain nodes that implement the low fault-tolerance consensus algorithm can complete consensus authentication, but the blockchain nodes that implement the high fault-tolerance consensus algorithm cannot complete consensus authentication. On this basis, the blockchain nodes that implement the low fault-tolerance consensus algorithm can synchronize the consensus result with the blockchain nodes that implement the high fault-tolerance consensus algorithm, allowing all blockchain nodes in the blockchain network to complete consensus authentication.
[0116] If the proportion of the number of blockchain nodes that issue response messages to all blockchain nodes is greater than 2 / 3, the number of nodes not only meets the consensus conditions of the low fault-tolerance consensus algorithm, but also meets the consensus conditions of the high fault-tolerance consensus algorithm, and all blockchain nodes running the two consensus algorithms can complete consensus authentication.
[0117] In one embodiment of the present application, the low fault-tolerance consensus algorithm has a first number of consensus stages and the high fault-tolerance consensus algorithm has a second number of consensus stages, the first number being less than the second number. Increasing the number of consensus stages can increase the fault-tolerance of the consensus algorithm.
[0118] In one embodiment of the present application, the consensus phase of the low fault-tolerance consensus algorithm includes a preparation phase and a commit phase that are executed sequentially, and the consensus phase of the high fault-tolerance consensus algorithm includes a pre-preparation phase, a preparation phase and a commit phase that are executed sequentially, the preparation phase of the low fault-tolerance consensus algorithm and the pre-preparation phase of the high fault-tolerance consensus algorithm match each other, and the commit phase of the low fault-tolerance consensus algorithm and the preparation phase and the commit phase of the high fault-tolerance consensus algorithm match each other.
[0119] 7 shows the consensus flow of a low-fault-tolerance consensus algorithm in one embodiment of the present application, where the low-fault-tolerance consensus algorithm is, for example, the Paxos algorithm of the CFT-based consensus algorithm. The low-fault-tolerance consensus algorithm in the embodiment of the present application is based on two-stage node-to-node interaction, and the advantage is that the node-to-node interaction is relatively simple, so it is easier to implement and has relatively high performance.
[0120] As shown in FIG. 7, the flow of implementing consensus authentication based on a low fault-tolerance consensus algorithm may include the following steps:
[0121] S701: A client sends a consensus request to a master node. The consensus request may be, for example, a data write request to write data to a blockchain.
[0122] S702: The master node performs the first stage of node interaction (preparation stage) and distributes the authentication request to other slave nodes. When the slave node receives the authentication request and performs consensus processing, it can return a response message to the master node.
[0123] In the preparation stage, the authentication request sent by the master node to other slave nodes contains the data that needs to be written to the blockchain, and the digital signature of the master node obtained after digesting and encrypting the data using the master node's private key. Taking the data structure shown in Figure 5 as an example, the authentication request sent by the master node to the slave nodes contains the master node digital signature written in the field "pre-preparation stage signature".
[0124] When the slave node receives the authentication request sent by the master node, it can use the public key of the master node to verify the signature of the digital signature included in the authentication request. After passing the signature verification, the slave node can obtain the slave node digital signature after digesting and encrypting the data to be written to the blockchain using its private key. Taking the data structure shown in FIG. 5 as an example, the master node digital signature and the slave node digital signature written in the field "pre-preparation signature" are included in the preparation response message sent back by the slave node to the master node.
[0125] S703: When the master node receives a response message from more than half of the total number of nodes (including the master node itself), the master node executes the second phase (commit phase), in which the master node commits the data and notifies other slave nodes of the data commit. When the slave node receives the commit notification, it can write the data to the blockchain it stores and return a response message to the master node.
[0126] When the master node receives the preliminary response messages sent back by the slave nodes, it can collect and aggregate the digital signatures of the slave nodes included in each response message.
[0127] After proceeding to the commit phase, the master node can send a commit notification carrying the aggregated digital signature to each slave node. Taking the data structure shown in FIG. 5 as an example, the commit notification sent by the master node to the slave node includes the master node digital signature and multiple slave node digital signatures written in the field "pre-preparation phase signature", and also includes the master node digital signature written in the field "commit phase signature". The number of master node digital signatures and slave node digital signatures in the field "pre-preparation phase signature" must be more than 1 / 2 of the total number of nodes, that is, it must meet the consensus condition in the preparation phase of the low fault-tolerance consensus algorithm.
[0128] When a slave node receives a commit notification sent by a master node, it can verify the signature by adopting the same method as in the previous stage, and write its own slave node digital signature in the response message after passing the verification. Taking the data structure shown in Fig. 5 as an example, the response message in the commit stage sent back by the slave node to the master node contains the master node digital signature and multiple slave node digital signatures written in the field "pre-preparation stage signature", and at the same time, it further contains the master node digital signature and the slave node's own slave node digital signature written in the field "commit stage signature".
[0129] S704: The master node returns a response to the client indicating that the data has been successfully written, at which point the client can determine that the data has been successfully written to the entire blockchain system.
[0130] When the master node receives the reply message of the commit phase returned by the slave node, the slave node digital signatures included in each reply message can be collected and aggregated. Taking the data structure shown in FIG. 5 as an example, the reply message returned by the master node to the client includes the master node digital signature and multiple slave node digital signatures written in the field "pre-preparation phase signature", and also includes the master node digital signature and multiple slave node digital signatures written in the field "commit phase signature". The number of master node digital signatures and slave node digital signatures in the field "pre-preparation phase signature" must exceed 1 / 2 of the total number of nodes, and the number of master node digital signatures and slave node digital signatures in the field "commit phase signature" must also exceed 1 / 2 of the total number of nodes, that is, the consensus conditions in the preparation phase and the commit phase of the low fault-tolerance consensus algorithm must be met.
[0131] 8 shows the consensus flow of a highly fault-tolerant consensus algorithm in one embodiment of the present application, and the highly fault-tolerant consensus algorithm is, for example, the PBFT algorithm of the BFT-based consensus algorithm. Compared with the CFT-based consensus algorithm, the BFT-based consensus algorithm still needs to ensure the consistency of the system even if there is a software error or a node is malicious, so the node interaction of the BFT-based algorithm is more complicated, generally requiring three stages of interaction, and the number of fault-tolerant nodes is further reduced, and generally 1 / 3 error nodes are allowed.
[0132] As shown in FIG. 8, the flow of implementing consensus authentication based on a highly fault-tolerant consensus algorithm may include the following steps:
[0133] S801: A client sends a consensus request to a master node. The consensus request may be, for example, a data write request to write data to a blockchain.
[0134] S802: The master node executes the first stage of node interaction (preparation stage) and distributes the authentication request to other slave nodes. When a slave node receives the authentication request and performs a consensus process, it can send a response message back to the master node. The purpose of this stage is to confirm that the requests received by multiple slave nodes are the same, and to prevent the master node from maliciously sending different messages to different slave nodes.
[0135] In the pre-preparation stage, the authentication request sent by the master node to other slave nodes contains the data to be written to the blockchain, and the digital signature of the master node obtained after digesting and encrypting the data using the master node's private key. Taking the data structure shown in Figure 5 as an example, the authentication request sent by the master node to the slave nodes contains the master node digital signature written in the field "pre-preparation stage signature".
[0136] When a slave node receives an authentication request sent by a master node, it can use the public key of the master node to verify the signature of the digital signature included in the authentication request. If the signature verification passes, the slave node can obtain the slave node digital signature after digesting and encrypting the data to be written to the blockchain using its private key. Taking the data structure shown in Figure 5 as an example, the response message of the pre-preparation stage sent back by the slave node to the master node contains the master node digital signature and the slave node digital signature written in the field "pre-preparation stage signature".
[0137] S803: When the master node receives a pre-preparation response message that exceeds 2 / 3 of the total number of nodes (including the master node itself), the master node executes the second stage (preparation stage) and the master node again sends the message signature to other slave nodes. The slave node verifies whether the number of message signatures exceeds 2 / 3 of the total number of nodes, and if it does, the slave node returns a response message of successful voting to the master node.
[0138] When the master node receives the pre-preparation response messages sent back by the slave nodes, it can collect and aggregate the slave node digital signatures included in each response message.
[0139] After proceeding to the preparation stage, the master node can send a preparation message carrying the aggregated digital signature to each slave node. Taking the data structure shown in FIG. 5 as an example, the preparation message sent by the master node to the slave node includes the master node digital signature and multiple slave node digital signatures written in the field "pre-preparation stage signature", and also includes the master node digital signature written in the field "pre-preparation stage signature". The number of master node digital signatures and slave node digital signatures in the field "pre-preparation stage signature" must exceed 2 / 3 of the total number of nodes, that is, it must meet the consensus condition in the pre-preparation stage of the high fault-tolerance consensus algorithm.
[0140] When a slave node receives the preparation message sent by the master node, it can verify the signature by adopting the same method as in the previous stage, and write its own slave node digital signature in the response message after passing the verification. Taking the data structure shown in Fig. 5 as an example, the response message of the preparation stage sent back by the slave node to the master node includes the master node digital signature and multiple slave node digital signatures written in the field "pre-preparation stage signature", and at the same time, it further includes the master node digital signature and the slave node's own slave node digital signature written in the field "commit stage signature".
[0141] S804: When the master node receives a response message from more than 2 / 3 of the total number of nodes (including the master node itself), the master node executes the third phase (commit phase), in which the master node commits the data and notifies other slave nodes of the data commit. When a slave node receives a commit notification, it can write the data to the blockchain it stores and send a response message back to the master node.
[0142] When the master node receives the preliminary response messages sent back by the slave nodes, it can collect and aggregate the slave node digital signatures included in each response message.
[0143] After proceeding to the commit phase, the master node can send a commit notification carrying the aggregated digital signature to each slave node. Taking the data structure shown in FIG. 5 as an example, the commit notification sent by the master node to the slave node includes the master node digital signature and multiple slave node digital signatures written in the field "pre-preparation phase signature", and also includes the master node digital signature and multiple slave node digital signatures written in the field "preparation phase signature", and the master node digital signature written in the field "commit phase signature". The number of master node digital signatures and slave node digital signatures in the field "pre-preparation phase signature" must exceed 2 / 3 of the total number of nodes, and the number of master node digital signatures and slave node digital signatures in the field "preparation phase signature" must also exceed 2 / 3 of the total number of nodes, that is, the consensus conditions in the pre-preparation phase and preparation phase of the high fault-tolerance consensus algorithm must be met.
[0144] When a slave node receives the prepare message sent by the master node, it can verify the signature by adopting the same method as in the previous stage, and write its own slave node digital signature in the response message after passing the verification. Taking the data structure shown in Fig. 5 as an example, the response message in the commit stage returned by the slave node to the master node includes the master node digital signature and multiple slave node digital signatures written in the field "pre-preparation stage signature", and at the same time, further includes the master node digital signature and multiple slave node digital signatures written in the field "preparation stage signature", and the master node signature and the slave node's own slave node digital signature written in the field "commit stage signature".
[0145] S805: The slave node returns a response to the client indicating that the data has been successfully written, at which point the client can determine that the data has been successfully written to the entire blockchain system.
[0146] When the master node receives the reply message of the commit phase returned by the slave node, the slave node digital signatures included in each reply message can be collected and aggregated. Taking the data structure shown in FIG. 5 as an example, the reply message returned by the master node to the client includes the master node digital signature and multiple slave node digital signatures written in the field "pre-preparation phase signature", and also includes the master node digital signature and multiple slave node digital signatures written in the field "preparation phase signature", and the master node digital signature and multiple slave node digital signatures written in the field "commit phase signature". The number of master node digital signatures and slave node digital signatures in the field "pre-preparation phase signature" must exceed 2 / 3 of the total number of nodes, the number of master node digital signatures and slave node digital signatures in the field "preparation phase signature" must also exceed 2 / 3 of the total number of nodes, and the number of master node digital signatures and slave node digital signatures in the field "commit phase signature" must also exceed 2 / 3 of the total number of nodes, that is, the consensus conditions in the pre-preparation phase, preparation phase, and commit phase of the high fault-tolerance consensus algorithm must be met.
[0147] In the blockchain systems of the related art, a series of systems pursue system performance and adopt CFT-based consensus, such as Fabric, while another series of systems pursue more extensive fault tolerance and adopt BFT-based consensus, such as Tendermint. In actual enterprise-level applications, the upper-level business systems that use blockchain services have different requirements in terms of performance, availability, fault tolerance, scalability, etc., due to the constant changes in user demand. And the current blockchain systems all adopt a single consensus algorithm, which cannot adapt to the requirements of the upper-level business systems. The technical solution of flexibly switching between CFT and BFT algorithms online provided by the embodiments of the present application allows the blockchain system to change the consensus algorithm to meet the requirements of the business system without stopping the service.
[0148] In one embodiment of the present application, in the process of broadcasting a consensus request in a blockchain network, some or all of the blockchain nodes in the blockchain network may switch algorithms to change the consensus algorithm executed by some or all of the blockchain nodes.
[0149] When some blockchain nodes have completed algorithm switching while other blockchain nodes have not yet completed algorithm switching, there are at least two blockchain nodes running different consensus algorithms in the blockchain network. On this basis, consensus authentication can be implemented using the above embodiment of the present application.
[0150] In one embodiment of the present application, a method for switching algorithms of some or all blockchain nodes in a blockchain network includes: Performing a trust prediction on the blockchain network to determine whether the operating environment of the blockchain network is a trust environment; When the operating environment of the blockchain network is a trust environment, switching some or all of the blockchain nodes that run a low fault-tolerance consensus algorithm in the blockchain network to run a high fault-tolerance consensus algorithm; If the operating environment of the blockchain network is not a trusted environment, the method may include switching some or all of the blockchain nodes in the blockchain network that run a high fault-tolerance consensus algorithm to run a low fault-tolerance consensus algorithm.
[0151] In one embodiment of the present application, a method for predicting the trustworthiness of a blockchain network includes: Obtaining an operation time length of each blockchain node in the blockchain network; If the operation time length is shorter than the time length threshold, determining the blockchain node as an untrusted node; If the number of untrusted nodes in the blockchain network is greater than a threshold number, determining that the operating environment of the blockchain network is an untrusted environment; If the number of untrusted nodes in the blockchain network is less than a number threshold, determining that the operating environment of the blockchain network is a trusted environment may include:
[0152] For example, in the scenario of managing the supply chain, a blockchain system is often proposed by some enterprises in the supply chain flow. In this case, the blockchain system can be recognized as being in a trusted environment, and there is no need to consider the situation of malicious nodes, and a simple CFT algorithm can be used as the consensus algorithm. However, when other enterprises in the supply chain join the blockchain system, it is necessary to prevent the other enterprises from being malicious. Therefore, the algorithm switching step of the embodiment of the present application can be performed to switch the consensus algorithm to a BFT-based algorithm without stopping the service. After the blockchain system has been operating stably for a certain period of time and each participating enterprise has been recognized as a reliable node, the algorithm switching step of the embodiment of the present application can be performed again to switch the consensus algorithm to a CFT-based algorithm, thereby improving the performance of the blockchain system.
[0153] Figure 9 illustrates a scenario in which an algorithm switching process is performed in an embodiment of the present application. Taking the algorithm switching of four nodes as an example, each blockchain node runs a different consensus algorithm at different times of algorithm switching.
[0154] When there are two consensus algorithms with different distribution ratios in a blockchain network, five scenes can be formed, as shown in Figure 8. When CFT consensus is switched to BFT consensus, the nodes will gradually switch from the all-CFT consensus algorithm to the all-BFT consensus algorithm, and scene 1 will gradually switch to scene 5. When BFT consensus is switched to CFT consensus, the nodes will gradually switch from the all-BFT consensus algorithm to the all-CFT consensus algorithm, and scene 5 will gradually switch to scene 1.
[0155] Table 2 shows the percentage of blockchain nodes that run different consensus algorithms in the total number of nodes in five scenarios.
[0156] [Table 2]
[0157] Below, we will explain the consensus proposals for five different application scenarios.
[0158] Scene 1: In scene 1, the consensus algorithm of all nodes is CFT, so this scene corresponds to the scene using the CFT algorithm alone. All nodes only need to follow their local CFT algorithm steps to reach a consensus on the system data.
[0159] Scene 2: In scene 2, only node 1's consensus algorithm is the BFT algorithm, and the remaining three nodes all use the CFT algorithm. In this case, the total number of CFT nodes (3) is greater than half the total number of nodes (4), so a consensus can be reached among the three CFT nodes according to the consensus conditions of the CFT algorithm. After the consensus is reached, node 1 can synchronize with the consensus result to ensure the consistency of the system data.
[0160] Scene 3: In scene 3, the number of CFT nodes cannot meet the consensus condition of being greater than 1 / 2 required by the CFT algorithm, and at the same time, the number of BFT nodes cannot meet the consensus condition of being greater than 2 / 3 required by the BFT algorithm. In this case, according to the normal CFT algorithm or BFT algorithm, none of the nodes in the system can reach a consensus.
[0161] In this scenario, the embodiment of the present application can implement data interaction between nodes using a response message having a data structure as shown in FIG.
[0162] 5, the data structure includes three signature fields: pre-preparation signature, pre-preparation signature, and commit signature, in which the CFT consensus node uses the pre-preparation signature and the commit signature, and the BFT consensus node uses all three signatures.
[0163] A flow diagram of the method steps for implementing consensus authentication in an application scenario of an embodiment of the present application is shown in Figure 10. As shown in Figure 10, in the above scenario 3, the method for performing consensus authentication can include the following steps:
[0164] S1001: The master node receives a consensus request sent by a client.
[0165] S1002: The master node transmits a <preparation> message to the slave node.
[0166] S1003: The slave node returns a <preparation> message to the master node.
[0167] Since the preparation stage of the CFT-based consensus algorithm is mutually matched with the pre-preparation stage of the BFT-based consensus algorithm, nodes using the CFT-based consensus algorithm can respond by substituting a <preparation> message for a <preparation> message. In this case, both slave nodes using the CFT-based consensus and slave nodes using the BFT-based consensus return a <preparation> message to the master node.
[0168] S1004: The master node judges whether or not it has received <preparation> messages at a rate exceeding 2 / 3 of the total number of nodes.
[0169] If it is not more than 2 / 3, return to S1003 and continue to receive <preparation> messages returned by other slave nodes. If it is more than 2 / 3, the consensus authentication of the preparatory stage is completed, so proceed to the preparation stage and execute S1005.
[0170] S1005: The master node sends a <prepare> message to the slave node.
[0171] S1006: <Preparation> Determine whether the slave node that received the message is a CFT node that executes a CFT-based consensus algorithm. If the result of the determination is "Yes", execute S1007. If the result of the determination is "No", this indicates that the slave node is a BFT node that executes a BFT-based consensus algorithm, so skip to S10010.
[0172] S1007: The slave node commits the data.
[0173] When a slave node using a CFT-based consensus algorithm receives a <prepare> message from a master node, it can be explained that the master node has already received a <pre-prepare> message that is greater than 2 / 3, which is greater than the 1 / 2 condition required by the CFT algorithm. At this time, the slave node running the CFT-based consensus algorithm can apply the <prepare> message to the <commit> message and directly commit the data, at which point the nodes using the CFT-based consensus algorithm can reach consensus and the data is consistent.
[0174] S1008: The slave node returns a <commit> message to the master node.
[0175] After completing the data commit, the slave node that executes the CFT consensus algorithm returns a <commit> message to the master node, and makes other BFT nodes achieve the commit condition that the total number of <prepare> + <commit> reaches 2 / 3. Then, execute S1010.
[0176] S1009: The slave node returns a <prepare> message to the master node.
[0177] S1010: The master node judges whether or not it has received <prepare> messages at a rate exceeding 2 / 3 of the total number of nodes.
[0178] If it is determined that the number of participants is not more than 2 / 3, continue to execute S1011. If it is determined that the number of participants is more than 2 / 3, the consensus verification for the preparation phase has been completed, so proceed to the commit phase and skip to execute S1012.
[0179] S1011: The master node judges whether or not it has received <prepare> messages and <commit> messages at a rate exceeding 2 / 3 of the total number of nodes.
[0180] The commit phase of the CFT consensus algorithm is mutually matched with the prepare phase and commit phase of the BFT consensus algorithm. Therefore, when the master node receives a response to the <commit> message returned by the CFT node, the master node can use the response to the <commit> message as a response to the <prepare> message. Based on this, if the master node determines that it has received <prepare> messages and <commit> messages at a rate of more than 2 / 3 of the total number of nodes, the consensus authentication of the prepare phase is completed, so it proceeds to the commit phase and continues to execute S1012. If the master node determines that it has not received <prepare> messages and <commit> messages at a rate of more than 2 / 3 of the total number of nodes, it returns to S1005 and the master node continues to send <prepare> messages to other slave nodes.
[0181] S1012: The master node sends a <commit> message to the slave node.
[0182] S1013: Each slave node commits the data and returns a <commit> message to the master node, and the system reaches a consensus.
[0183] Nodes using BFT-based consensus can reach a condition for responding to <prepare> messages that is greater than 2 / 3, while still being able to reach consensus according to the steps of the BFT-based algorithm and guaranteeing data consistency with CFT-based nodes.
[0184] Scene 4: In scene 4, node 4 runs a CFT-based consensus algorithm, and the remaining three nodes run a BFT-based consensus algorithm. At this time, since the total number of BFT nodes (3) is greater than 2 / 3 of the total number of nodes (4), a consensus can be reached among the three BFT nodes according to the BFT-based consensus algorithm. After the consensus is reached, node 4 can synchronize with the consensus result to ensure the consistency of the system data.
[0185] Scene 5: In scene 5, all nodes are running the BFT-based consensus algorithm, so the system can reach a consistency consensus by following the steps of the BFT-based consensus algorithm.
[0186] Based on the above description of various application scenarios, it is found that the online consensus algorithm switching scheme provided in the embodiments of the present application supports consensus algorithm switching without service interruption, so that the block chain system can be more flexibly adapted to the needs of upper-level business, and the block chain system can be applied more widely in different scenarios.
[0187] It should be noted that although the accompanying figures depict steps in the methods of the present application in a particular order, this does not require or imply that the steps must be performed in that particular order or that all steps presented must be performed in order to achieve the desired results. Additionally or alternatively, certain steps may be omitted, multiple steps may be combined into a single step, and / or a single step may be broken down into multiple steps.
[0188] The following introduces an embodiment of the present application that can be used to implement the blockchain consensus method in the above embodiment of the present application. Figure 11 shows a schematic structural block diagram of the blockchain consensus device provided in the embodiment of the present application. As shown in Figure 11, the blockchain consensus device 1100 includes: A request module 1110 configured to broadcast a consensus request corresponding to at least two consensus stages in a blockchain network, the blockchain network including at least two blockchain nodes implementing different types of consensus algorithms; and A response module 1120 configured to respectively obtain a response message broadcast by the blockchain network in each of the consensus stages, the response message being a message in which the blockchain node responds to the consensus request, and the different types of consensus algorithms include a first consensus algorithm and a second consensus algorithm; A statistics module 1130 configured to count the number of blockchain nodes that issued the response message in the same consensus stage, the number of nodes including the number of blockchain nodes that execute at least two different types of consensus algorithms; and a synchronization module 1140 configured to achieve consensus on blockchain nodes that execute the first consensus algorithm and synchronize a consensus result of the first consensus algorithm to blockchain nodes that execute the second consensus algorithm if the number of nodes satisfies a consensus condition of the first consensus algorithm.
[0189] In one embodiment of the present application, based on each of the above embodiments, different types of consensus algorithms have different numbers of consensus stages, and the algorithm type and node signature of the blockchain node are included in the response message, where the algorithm type is used to indicate the consensus algorithm executed by the blockchain node, and the node signature includes the digital signature of the blockchain node at each consensus stage.
[0190] In one embodiment of the present application, based on the above embodiments, the statistics module 1030 further comprises: a parsing module configured to parse the response message to obtain an algorithm type and a node signature included in the response message; an algorithm identification module configured to identify a consensus algorithm executed by a message sending node based on the algorithm type, the message sending node being the blockchain node that issued the response message; and a phasing identification module configured to identify a consensus phasing in which the message sending node is located based on the node signature; and a quantity statistics module configured to count the number of message sending nodes that are in the same consensus stage as a current blockchain node based on the consensus algorithm executed by the message sending node and the consensus stage in which the message sending node is located.
[0191] In one embodiment of the present application, based on the above embodiments, the statistics module 1030 further comprises: A relationship acquisition module configured to acquire a matching relationship of consensus stages between different types of consensus algorithms; and a node determination module configured to determine, if the message sending node is running a different type of consensus algorithm than the current blockchain node, a message sending node that is in the same consensus stage as the current blockchain node based on the matching relationship.
[0192] In one embodiment of the present application, based on the above embodiments, the first consensus algorithm includes N consensus stages, and the second consensus algorithm includes M consensus stages, and the matching relationship of the consensus stages between different types of consensus algorithms includes: Matching the first P consensus steps of the first consensus algorithm and the second consensus algorithm with each other, where P is the smaller of N-1 and M-1; and matching the last NP consensus stages of the first consensus algorithm with the last MP consensus stages of the second consensus algorithm.
[0193] In one embodiment of the present application, based on the above embodiments, after the current blockchain node counts the number of message sending nodes in the same consensus stage, the statistics module 1030 further: a consensus result determination module configured to determine a consensus result of a consensus algorithm according to whether the number of nodes meets the consensus condition for executing a consensus algorithm when the consensus stage in which the current blockchain node is located is the last consensus stage for executing a consensus algorithm; and a consensus stage execution module configured to determine whether to execute a next consensus stage of a consensus algorithm based on whether the number of nodes meets a consensus condition for executing a consensus algorithm if the consensus stage in which the current blockchain node is located is not the last consensus stage for executing a consensus algorithm.
[0194] In one embodiment of the present application, based on each of the above embodiments, the first consensus algorithm is one of a low fault-tolerance consensus algorithm and a high fault-tolerance consensus algorithm, and the second consensus algorithm is another one of the low fault-tolerance consensus algorithm and the high fault-tolerance consensus algorithm that is different from the first consensus algorithm.
[0195] The consensus condition of the low fault-tolerance consensus algorithm is that the proportion of the number of blockchain nodes that issue response messages to all blockchain nodes is greater than a first proportion threshold, and the consensus condition of the high fault-tolerance consensus algorithm is that the proportion of the number of blockchain nodes that issue response messages to all blockchain nodes is greater than a second proportion threshold, and the first proportion threshold is smaller than the second proportion threshold.
[0196] In one embodiment of the present application, based on each of the above embodiments, the low fault-tolerance consensus algorithm has a first number of consensus stages, and the high fault-tolerance consensus algorithm has a second number of consensus stages, the first number being smaller than the second number.
[0197] In one embodiment of the present application, based on each of the above embodiments, the consensus phase of the low fault-tolerance consensus algorithm includes a preparation phase and a commit phase that are executed sequentially, the consensus phase of the high fault-tolerance consensus algorithm includes a pre-preparation phase, a preparation phase and a commit phase that are executed sequentially, the preparation phase of the low fault-tolerance consensus algorithm is mutually matched with the pre-preparation phase of the high fault-tolerance consensus algorithm, and the commit phase of the low fault-tolerance consensus algorithm is mutually matched with the preparation phase and the commit phase of the high fault-tolerance consensus algorithm.
[0198] In one embodiment of the present application, based on each of the above embodiments, the blockchain consensus apparatus 1000 further comprises: The blockchain network may also include an algorithm switching module configured to cause some or all of the blockchain nodes in the blockchain network to switch algorithms to change the consensus algorithm executed by the some or all of the blockchain nodes.
[0199] In one embodiment of the present application, based on the above embodiments, the algorithm switching module further comprises: A trust detection module configured to perform a trust prediction on the blockchain network to determine whether the operation environment of the blockchain network is a trust environment; A first algorithm switching module configured to switch some or all of the blockchain nodes that run a low fault-tolerance consensus algorithm in the blockchain network to run a high fault-tolerance consensus algorithm when the operation environment of the blockchain network is a trust environment; and a second algorithm switching module configured to switch some or all of the blockchain nodes that run a high fault-tolerance consensus algorithm in the blockchain network to run a low fault-tolerance consensus algorithm if the operating environment of the blockchain network is not a trusted environment.
[0200] In one embodiment of the present application, based on each of the above embodiments, a reliability detection module that performs reliability prediction on the blockchain network further comprises: A time length acquisition module configured to acquire an operation time length of each blockchain node in the blockchain network; an untrusted node determination module configured to determine the blockchain node as an untrusted node if the operation time length is shorter than a time length threshold; An untrusted environment determination module configured to determine an operation environment of the blockchain network as an untrusted environment when the number of untrusted nodes in the blockchain network is greater than a number threshold; and a trust environment determination module configured to determine that the operating environment of the blockchain network is a trust environment if the number of untrusted nodes in the blockchain network is less than a number threshold.
[0201] The specific details of the blockchain consensus device provided in each embodiment of the present application have already been described in detail in the corresponding method embodiments, so they will not be described in detail again here.
[0202] FIG. 12 is a schematic block diagram showing the structure of a computer system in an electronic device for implementing the present embodiment.
[0203] It should be noted that the computer system 1200 of the electronic device shown in FIG. 12 is merely an example and does not pose any limitations on the functions and scope of use of the embodiments of the present application.
[0204] As shown in Fig. 12, the computer system 1200 includes a central processing unit 1201 (CPU), which performs various appropriate operations and processes based on programs stored in a read-only memory 1202 (ROM) or programs loaded from a memory portion 1208 into a random access memory 1203 (RAM). The random access memory 1203 further stores various programs and data required for the operation of the system. The central processing unit 1201, the read-only memory 1202, and the random access memory 1203 are interconnected via a bus 1204. An input / output port 1205 (I / O port) is also connected to the bus 1204.
[0205] The following components are connected to the input / output port 1205: an input section 1206 including a keyboard, a mouse, etc.; an output section 1207 including, for example, a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, a storage section 1208 including a hard disk, etc.; and a communication section 1209 of a network interface card including a local area network card, a modem, etc. The communication section 1209 executes communication processing via a network such as the Internet. A driver 1210 is also connected to the input / output port 1205 as necessary. A removable medium 1211, for example, a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is implemented in the driver 1210 as necessary, and a computer program read from the removable medium 1211 is implemented in the storage section 1208 as necessary.
[0206] In particular, in accordance with an embodiment of the present application, the steps depicted in the flow diagrams of each method are implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program stored on a computer-readable medium, and the computer program includes program code for executing the method illustrated in the flow diagram. In such an embodiment, the computer program is downloaded and implemented from a network via the communication unit 1209 and / or implemented from a removable medium 1211. When the computer program is executed by the central processing unit 1201, various functions defined in the system of the present application are performed.
[0207] It should be noted that the computer-readable medium shown in the embodiments of the present application can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the above. The computer-readable storage medium can be, for example, but is not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of the computer-readable storage medium can include, but are not limited to, an electrical connection having one or more conductors, a compact computer magnetic disk, a hardware disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, the computer-readable storage medium can be a tangible medium that contains or stores any program, and the program is used by or in conjunction with an instruction execution system, apparatus, or device. In this application, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, having computer-readable program code embodied therein. Such propagated data signals may take a number of forms, including, but not limited to, electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which may transmit, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device.The program code contained in the computer readable medium may be transmitted using any suitable medium, including but not limited to wireless, wired, or the like, or any suitable combination of the above.
[0208] The flow diagrams and block diagrams in the accompanying drawings illustrate possible system structures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present application. In this regard, each block in the flow diagram or block diagram may represent a module, program section, or part of code, which includes executable instructions for implementing one or more specified logical functions. It should also be noted that in some alternative implementations, the functions depicted in the blocks may occur in a different order than those depicted in the accompanying drawings. For example, two blocks shown as connected may actually be essentially performed in parallel, and they may sometimes be executed in the reverse order, depending on the functions described. It should also be noted that each block in the block diagram or flow diagram, and combinations of blocks in the block diagram or flow diagram, may be realized by a dedicated hardware-based system that performs the specified functions or operations, or by a combination of dedicated hardware and computer instructions.
[0209] It should be noted that although the detailed description in the above text refers to some modules or units used in the device to perform the operations, this type of division is not mandatory. In fact, based on the embodiment of the present application, the features and functions of two or more modules or units described in the above text can be embodied in one module or unit. Conversely, the features and functions of one module or unit described in the above text can be further divided to be embodied in multiple modules or units.
[0210] Regarding the above description of the embodiments, as can be understood by those skilled in the art, the exemplary embodiments described herein can be realized by software, and can also be realized by combining necessary hardware through software. Therefore, the technical solutions according to the embodiments of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, USB, portable hard disk, etc.) or on a network, and includes some instructions to make a computing device (which can be a personal computer, a server, a touch control terminal, or a network device, etc.) execute the method according to the embodiments of the present application.
[0211] Those skilled in the art can easily conceive of other implementations of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any variations, uses or preferred modifications of the present application, which variations, uses or preferred modifications comply with the general principles of the present application and include common knowledge or conventional technical means in the art that are not disclosed in the present application.
[0212] It should be understood that the present application is not limited to the exact construction already described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from the scope thereof, which is to be limited by the appended claims.
Claims
1. A blockchain consensus method executed by a current blockchain node in a blockchain network, comprising: Broadcasting a consensus request corresponding to at least two consensus stages in the blockchain network, the blockchain network including blockchain nodes executing at least two different types of consensus algorithms, the different types of consensus algorithms including a first consensus algorithm and a second consensus algorithm; Obtaining a response message broadcast by the blockchain network in each consensus stage, respectively, the response message being a message in which the blockchain node responds to the consensus request; Counting the number of blockchain nodes that issue the response messages in the same consensus stage, the number of nodes including the number of blockchain nodes that execute at least two different types of consensus algorithms; and If the number of nodes satisfies the consensus condition of the first consensus algorithm, achieving consensus on the blockchain nodes that execute the first consensus algorithm, and synchronizing the consensus result of the first consensus algorithm to the blockchain nodes that execute the second consensus algorithm.
2. 2. The blockchain consensus method of claim 1, wherein different types of consensus algorithms have different numbers of consensus stages, and the response message transmits an algorithm type and a node signature of the blockchain node, the algorithm type is used to indicate the consensus algorithm executed by the blockchain node, and the node signature includes a digital signature of the blockchain node at each consensus stage.
3. Counting the number of blockchain nodes that issued the response messages in the same consensus stage Parsing the response message to obtain an algorithm type and a node signature included in the response message; Identifying a consensus algorithm executed by a message sending node according to the algorithm type, the message sending node being a blockchain node that issued the response message; and identifying a consensus phase in which the message sending node is located according to the node signature; Counting the number of message sending nodes in the same consensus stage as the current blockchain node according to the consensus algorithm executed by the message sending node and the consensus stage in which the message sending node is located.
4. Before counting the number of message sending nodes that are in the same consensus stage as the current blockchain node, Obtaining a matching relationship of consensus stages between the different types of consensus algorithms; and The blockchain consensus method of claim 3, further comprising: if the message sending node and the current blockchain node are running different types of consensus algorithms, determining a message sending node that is in the same consensus stage as the current blockchain node according to the matching relationship.
5. The first consensus algorithm includes N consensus steps, and the second consensus algorithm includes M consensus steps, and the matching relationship of the consensus steps between the different types of consensus algorithms is: Matching the first P consensus steps of the first consensus algorithm and the second consensus algorithm with each other, where P is the smaller of N-1 and M-1; The blockchain consensus method of claim 4, further comprising: matching the last N-P consensus stages of the first consensus algorithm with the last M-P consensus stages of the second consensus algorithm.
6. Counting the number of message sending nodes that are in the same consensus stage as the current blockchain node, and then If the consensus stage in which the current blockchain node is located is the final consensus stage in which a consensus algorithm is executed, determining a consensus result of the consensus algorithm according to whether the number of nodes meets the consensus condition of the consensus algorithm executed; If the consensus stage in which the current blockchain node is located is not the final one of the consensus stages that executes a consensus algorithm, determining whether it is the next consensus stage that executes a consensus algorithm according to whether the number of nodes satisfies the consensus condition of the consensus algorithm to be executed. The blockchain consensus method of claim 3, further comprising:
7. The first consensus algorithm is one of a low-fault-tolerance consensus algorithm and a high-fault-tolerance consensus algorithm, and the second consensus algorithm is another of the low-fault-tolerance consensus algorithm and the high-fault-tolerance consensus algorithm that is different from the first consensus algorithm; 2. The blockchain consensus method of claim 1, wherein the consensus condition of the low fault-tolerance consensus algorithm is that a proportion of the number of blockchain nodes that issue response messages to all blockchain nodes is greater than a first proportion threshold, and the consensus condition of the high fault-tolerance consensus algorithm is that a proportion of the number of blockchain nodes that issue response messages to all blockchain nodes is greater than a second proportion threshold, and the first proportion threshold is smaller than the second proportion threshold.
8. 8. The blockchain consensus method of claim 7, wherein the low fault-tolerance consensus algorithm has a first number of consensus stages and the high fault-tolerance consensus algorithm has a second number of consensus stages, the first number being less than the second number.
9. 9. The blockchain consensus method of claim 8, wherein the consensus phase of the low fault-tolerance consensus algorithm includes a preparation phase and a commit phase that are executed sequentially, and the consensus phase of the high fault-tolerance consensus algorithm includes a pre-preparation phase, a preparation phase, and a commit phase that are executed sequentially, the preparation phase of the low fault-tolerance consensus algorithm is mutually matched with the pre-preparation phase of the high fault-tolerance consensus algorithm, and the commit phase of the low fault-tolerance consensus algorithm is mutually matched with the preparation phase and the commit phase of the high fault-tolerance consensus algorithm.
10. In the step of broadcasting a consensus request in the blockchain network, the method further comprises:
2. The blockchain consensus method of claim 1, comprising switching algorithms of some or all of the blockchain nodes in the blockchain network to change the consensus algorithm executed by the some or all of the blockchain nodes.
11. Switching the algorithm of some or all of the blockchain nodes in the blockchain network includes: Performing a trust prediction on the block chain network to determine whether the operation environment of the block chain network is a trust environment; When the operating environment of the blockchain network is a trust environment, switching some or all of the blockchain nodes that run a low fault-tolerance consensus algorithm in the blockchain network to run a high fault-tolerance consensus algorithm; The blockchain consensus method of claim 10, further comprising: if the operating environment of the blockchain network is not a trusted environment, switching some or all of the blockchain nodes in the blockchain network that execute a high fault-tolerance consensus algorithm to execute a low fault-tolerance consensus algorithm.
12. The performing of a trust prediction on the blockchain network includes: Obtaining an operation time length of each blockchain node in the blockchain network; If the operation time length is shorter than a time length threshold, determining the blockchain node as an untrusted node; When the number of untrusted nodes in the blockchain network is greater than a threshold number, determining that the operating environment of the blockchain network is an untrusted environment; The blockchain consensus method of claim 11, further comprising: if the number of untrusted nodes in the blockchain network is less than a number threshold, determining that the operating environment of the blockchain network is a trusted environment.
13. A request module configured to broadcast a consensus request corresponding to at least two consensus stages in a blockchain network, the blockchain network including at least two blockchain nodes executing different types of consensus algorithms, the different types of consensus algorithms including a first consensus algorithm and a second consensus algorithm; and A response module configured to respectively obtain a response message broadcast by the blockchain network in each of the consensus stages, the response message being a message in which the blockchain node responds to the consensus request; A statistics module configured to count the number of blockchain nodes that issued the response message in the same consensus stage, the number of nodes including the number of blockchain nodes that execute at least two different types of consensus algorithms; and and a synchronization module configured to achieve consensus on blockchain nodes that execute the first consensus algorithm if the number of nodes satisfies a consensus condition of the first consensus algorithm, and synchronize a consensus result of the first consensus algorithm to blockchain nodes that execute the second consensus algorithm.
14. A computer-readable medium having a computer program stored thereon, the computer program implementing the blockchain consensus method according to any one of claims 1 to 12 when executed by a processor.
15. A processor; a memory for storing executable instructions of said processor, The processor is configured to cause the electronic device to execute the blockchain consensus method described in any one of claims 1 to 12 by executing the executable instructions.
16. A computer program product comprising a computer program, the computer program implementing the blockchain consensus method according to any one of claims 1 to 12 when executed by a processor.
Citation Information
Patent Citations
Distributed system, message processing method, node, client, and storage medium
EP3605947A1
Method and apparatus for establishing a local consensus and computer-readable storage medium
JP2019526945A
Blockchain-based consensus method and device
JP2020514865A
Method, apparatus and system for blockchain consensus
JP2020515976A
