[go: up one dir, main page]

HK1246891B - Consensus method and device based on block chain - Google Patents

Consensus method and device based on block chain Download PDF

Info

Publication number
HK1246891B
HK1246891B HK18106134.4A HK18106134A HK1246891B HK 1246891 B HK1246891 B HK 1246891B HK 18106134 A HK18106134 A HK 18106134A HK 1246891 B HK1246891 B HK 1246891B
Authority
HK
Hong Kong
Prior art keywords
consensus
server
message
database
gateway
Prior art date
Application number
HK18106134.4A
Other languages
Chinese (zh)
Other versions
HK1246891A1 (en
Inventor
唐强
Original Assignee
创新先进技术有限公司
Filing date
Publication date
Application filed by 创新先进技术有限公司 filed Critical 创新先进技术有限公司
Priority to HK18106134.4A priority Critical patent/HK1246891B/en
Publication of HK1246891A1 publication Critical patent/HK1246891A1/en
Publication of HK1246891B publication Critical patent/HK1246891B/en

Links

Description

一种基于区块链的共识方法及装置A consensus method and device based on blockchain

技术领域Technical Field

本申请涉及计算机技术领域,尤其涉及一种基于区块链的共识方法及装置。The present application relates to the field of computer technology, and in particular to a consensus method and device based on blockchain.

背景技术Background Art

目前,区块链技术得到了广泛应用,其去中心化的模式保证了数据不易被篡改,从而提升了安全性。At present, blockchain technology has been widely used. Its decentralized model ensures that data is not easily tampered with, thereby improving security.

在实际应用场景下,区块链能够为客户端提供相应的业务服务,其中的区块链节点可以针对用户的业务请求进行处理,生成相应的处理结果。但区块链中可能包含恶意节点或故障节点,这无疑将影响客户端所获得的业务服务。为此,区块链中各节点之间可进行诸如拜占庭容错算法(Practical Byzantine Fault Tolerance,PBFT)的共识过程,以使得各节点能够共同认可正确的处理结果。In practical applications, blockchains can provide clients with relevant business services. Blockchain nodes process user business requests and generate corresponding results. However, the blockchain may contain malicious or faulty nodes, which will undoubtedly affect the business services provided to clients. To address this, blockchain nodes can use consensus processes such as the Practical Byzantine Fault Tolerance (PBFT) algorithm to ensure that all nodes agree on the correct processing results.

以基于PBFT的共识过程为例,PBFT的共识过程包含预准备阶段(pre-prepare)、准备阶段(prepare)、确认阶段(commit),如图1所示。接收到客户端(Client,图1中以C表示)的业务请求的节点(如图中编号为0的节点),会将该业务请求发送给其他节点(如图中编号为1、2、3的节点)进行共识。在每个阶段,各节点均会向彼此发送共识消息,使得各节点进行共识。经过三个阶段的共识过程,可视为共识达成,各节点便会分别处理业务请求,并向客户端反馈处理结果。Taking the PBFT-based consensus process as an example, the PBFT consensus process consists of the pre-prepare, prepare, and commit phases, as shown in Figure 1. A node (node 0) that receives a service request from a client (represented by C in Figure 1) sends the service request to other nodes (nodes 1, 2, and 3) for consensus. During each phase, each node sends a consensus message to each other, enabling them to reach consensus. After these three phases, consensus is considered reached, and each node then processes the service request and reports the results to the client.

在现有技术中的一些场景下,为了能够处理大量的共识过程,上述区块链的每个节点中,通常设置多个服务器,不同的服务器可分别参与不同的共识过程,以提升区块链的处理量及处理效率。In some scenarios in the prior art, in order to be able to handle a large number of consensus processes, multiple servers are usually set up in each node of the above-mentioned blockchain. Different servers can participate in different consensus processes respectively to improve the processing capacity and processing efficiency of the blockchain.

但是,在实际应用中,节点中的服务器存在下线或重启等异常现象,以PBFT的共识过程为例,一旦服务器出现异常现象,将导致服务器不能继续参与共识并影响共识达成的概率,若某次共识未达成,则无论区块链处于任何一种共识阶段,均会从预准备阶段起重新发起共识。显然,这无疑会影响区块链共识的效率,并进一步影响区块链对业务处理的效率。However, in actual applications, nodes may experience abnormalities such as server downtime or reboots. For example, in the PBFT consensus process, if a server anomaly occurs, it will be unable to participate in the consensus process and the probability of reaching consensus will be affected. If consensus is not reached, the blockchain will be restarted from the pre-preparation phase regardless of the consensus phase. This will undoubtedly affect the efficiency of the blockchain consensus and, by extension, the efficiency of the blockchain's business processing.

发明内容Summary of the Invention

本申请实施例提供一种基于区块链的共识方法及装置,用以解决目前节点中的服务器发生异常时导致共识效率较低的问题。The embodiments of the present application provide a blockchain-based consensus method and device to solve the problem of low consensus efficiency caused by abnormalities in the server of the current node.

本申请实施例提供的一种基于区块链的共识方法,一个区块链节点包括第一服务器、第二服务器和至少一个数据库构成,所述方法包括:An embodiment of the present application provides a consensus method based on blockchain, wherein a blockchain node includes a first server, a second server, and at least one database. The method includes:

所述数据库存储执行共识所需的共识数据,供所述第一服务器和所述第二服务器在执行共识的过程中进行调用;The database stores consensus data required for consensus execution, for the first server and the second server to call during the consensus execution process;

所述第一服务器在执行共识前或执行共识时出现异常;The first server encounters an exception before or during consensus execution;

所述第二服务器代替所述第一服务器,从所述数据库中获取共识数据,并根据所述共识数据执行共识,生成共识结果;The second server replaces the first server, obtains consensus data from the database, and performs consensus based on the consensus data to generate a consensus result;

所述第二服务器将所述共识结果存储在所述数据库中。The second server stores the consensus result in the database.

本申请实施例提供的一种基于区块链的共识装置,一个区块链节点包括第一服务器、第二服务器和至少一个数据库,其中,The embodiment of the present application provides a consensus device based on blockchain, wherein a blockchain node includes a first server, a second server, and at least one database, wherein:

所述数据库存储执行共识所需的共识数据,供所述第一服务器和所述第二服务器在执行共识的过程中进行调用;The database stores consensus data required for consensus execution, for the first server and the second server to call during the consensus execution process;

所述第一服务器在执行共识前或执行共识时出现异常;The first server encounters an exception before or during consensus execution;

所述装置包括:The device comprises:

获取模块,根据所述共识消息,从所述数据库中获取与所述共识消息对应的共识数据;An acquisition module, which acquires consensus data corresponding to the consensus message from the database according to the consensus message;

共识执行模块,根据所述共识数据执行共识,生成共识结果;A consensus execution module, executing consensus based on the consensus data and generating a consensus result;

存储模块,将所述共识消息及所述共识结果存储在所述数据库中。A storage module stores the consensus message and the consensus result in the database.

本申请实施例提供一种基于区块链的共识方法及装置,对于区块链节点中的每一服务器而言,参与了某次共识过程的服务器,会将不同共识阶段的共识消息或自身所生成的当前阶段的共识结果,进行“公开”保存,即,存储在该区块链节点内的数据库中,而该数据库对于该区块链节点内的所有服务器均可使用,这样一来,如果参与某次共识的服务器出现下线或重启等异常现象,该服务器的共识数据可被该区块链节点内的其他服务器使用,并可代替出现异常现象的服务器继续执行相应的共识过程。The embodiments of the present application provide a consensus method and device based on blockchain. For each server in a blockchain node, the server that participates in a consensus process will "publicly" save the consensus messages of different consensus stages or the consensus results of the current stage generated by itself, that is, store them in a database within the blockchain node, and the database is available to all servers within the blockchain node. In this way, if a server participating in a consensus experiences an abnormality such as going offline or restarting, the consensus data of the server can be used by other servers within the blockchain node, and the corresponding consensus process can be continued on behalf of the server that experienced the abnormality.

显然,相较于现有技术,区块链节点中的各服务器将共识数据存储在该区块链节点内数据库的方式,即使在某一服务器出现异常时,其他正常运行的服务器也能够从数据库中获取到相应的共识数据,接替异常的服务器完成共识,也就保证了共识过程的正常进行,在减少重新发起共识次数的同时,能够在一定程度上提升共识过程的成功率,进而提升区块链的业务处理效率。Obviously, compared with the existing technology, the way in which each server in the blockchain node stores the consensus data in the database within the blockchain node means that even if a server malfunctions, other normally operating servers can obtain the corresponding consensus data from the database and take over the abnormal server to complete the consensus, thus ensuring the normal progress of the consensus process. While reducing the number of times consensus is re-initiated, it can improve the success rate of the consensus process to a certain extent, thereby improving the business processing efficiency of the blockchain.

附图说明BRIEF DESCRIPTION OF THE DRAWINGS

此处所说明的附图用来提供对本申请的进一步理解,构成本申请的一部分,本申请的示意性实施例及其说明用于解释本申请,并不构成对本申请的不当限定。在附图中:The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

图1为现有技术中基于PBFT的共识过程;Figure 1 shows the consensus process based on PBFT in the prior art;

图2a为本申请实施例提供的基于区块链的共识过程中区块链的架构;FIG2a is a diagram illustrating the architecture of a blockchain-based consensus process according to an embodiment of the present application;

图2b为本申请实施例提供的基于区块链的共识过程中区块链节点的架构。Figure 2b is the architecture of the blockchain node in the blockchain-based consensus process provided by an embodiment of the present application.

图2c为本申请实施例提供的在服务器侧的基于区块链的共识过程;FIG2c is a blockchain-based consensus process on the server side provided in an embodiment of the present application;

图2d为本申请实施例提供的另一种区块链节点的架构;FIG2 d is another blockchain node architecture provided in an embodiment of the present application;

图3a和3b为本申请实施例提供的一种同一共识过程中的服务器变更过程示意图;Figures 3a and 3b are schematic diagrams of a server change process in the same consensus process provided by an embodiment of the present application;

图4为本申请实施例提供的一种在服务器侧的基于区块链的共识装置结构示意图。FIG4 is a schematic diagram of the structure of a blockchain-based consensus device on the server side provided in an embodiment of the present application.

具体实施方式DETAILED DESCRIPTION

为使本申请的目的、技术方案和优点更加清楚,下面将结合本申请具体实施例及相应的附图对本申请技术方案进行清楚、完整地描述。显然,所描述的实施例仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。To make the purpose, technical solutions, and advantages of this application more clear, the technical solutions of this application will be clearly and completely described below in conjunction with the specific embodiments of this application and the corresponding drawings. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

正如前述,在任意一次区块链内各节点之间的共识过程中,任一节点内参与本次共识的服务器可能会出现下线或重启等异常现象,导致该服务器不能继续参与共识,从而有可能会降低共识成功率,特别是在采用PBFT共识的情况下,一定次数的共识失败,便可能触发PBFT下的垃圾回收机制,清除各服务器中的共识数据,显然,这无疑将影响区块链的业务处理。As mentioned above, during any consensus process between nodes in a blockchain, a server participating in the consensus process may experience abnormalities such as going offline or restarting, causing the server to be unable to continue participating in the consensus, thereby potentially reducing the consensus success rate. Especially when using PBFT consensus, a certain number of consensus failures may trigger the garbage collection mechanism under PBFT, clearing the consensus data from each server. Obviously, this will undoubtedly affect the business processing of the blockchain.

基于此,本申请实施例中提供一种基于区块链的共识方法,通过将共识数据存储在区块链节点中的数据库,使得当服务器出现异常(下线或重启)时,该区块链节点中其他正常运行的服务器也能够读取已存储在数据库中的共识数据,代替出现异常现象的服务器继续执行共识。当然,本申请实施例中的基于区块链的共识方法并不仅限于基于PBFT的共识过程,还可用于诸如Paxos等共识算法的共识过程。Based on this, the embodiments of the present application provide a blockchain-based consensus method. By storing consensus data in a database in a blockchain node, when a server fails (goes offline or restarts), other normally operating servers in the blockchain node can also read the consensus data stored in the database and continue to execute consensus on behalf of the server that failed. Of course, the blockchain-based consensus method in the embodiments of the present application is not limited to the consensus process based on PBFT, but can also be used for the consensus process of consensus algorithms such as Paxos.

需要说明的是,在本申请实施例中,基于区块链的共识方法所采用的架构如图2a所示,从图2a中可见,区块链中包含多个区块链节点,为了便于后续描述,以下将区块链节点简称为:节点。It should be noted that in the embodiment of the present application, the architecture adopted by the blockchain-based consensus method is shown in Figure 2a. As can be seen from Figure 2a, the blockchain contains multiple blockchain nodes. For the convenience of subsequent description, the blockchain nodes will be referred to as nodes below.

多个客户端可与该区块链进行业务交互,其中,所述的区块链,可以是联盟链和/或私有链,能够向用户提供业务服务。所述的客户端,可包括浏览器、应用等,客户端可以运行在诸如终端、服务器、数据库中,这里不作具体限定。Multiple clients can interact with the blockchain for business purposes. The blockchain can be a consortium blockchain and/or a private blockchain, providing business services to users. The clients can include browsers, applications, and other applications. The clients can run on terminals, servers, and databases, without specific limitations.

基于图2a所示的架构,对于任一节点而言,其架构可如图2b所示。在图2b中可见,节点中包含n个服务器以及一个共用于各服务器的数据库。不同的服务器可参与不同的共识过程,各服务器之间可以彼此独立运行。所述的数据库用于为该节点中的各服务器提供数据存储服务。也就是说,各服务器在共识过程中,可将相应的共识数据存储在该数据库中。当然,图2b所示的节点中的数据库的数量仅是一种通用数量,在实际应用中,节点中的数据库的数量可以根据实际应用中的需要进行调整。此外,在一些场景下,节点中的服务器可替换为计算机等具有计算处理功能的设备。Based on the architecture shown in Figure 2a, for any node, its architecture can be as shown in Figure 2b. As can be seen in Figure 2b, the node contains n servers and a database shared by all servers. Different servers can participate in different consensus processes, and each server can operate independently of each other. The database is used to provide data storage services for each server in the node. In other words, each server can store the corresponding consensus data in the database during the consensus process. Of course, the number of databases in the node shown in Figure 2b is only a general number. In actual applications, the number of databases in the node can be adjusted according to the needs of the actual application. In addition, in some scenarios, the server in the node can be replaced by a computer or other device with computing and processing capabilities.

还需要说明的是,为了便于描述,在下文中,将可能在运行中出现异常的服务器称为:第一服务器。将能够正常运行的服务器称为:第二服务器。那么,在图2b所示的架构中,也就可视为包含了两类服务器,即,第一服务器和第二服务器。以上内容并不应作为对本申请的限定。It should also be noted that, for ease of description, in the following text, a server that may experience anomalies during operation is referred to as the "first server." A server that can operate normally is referred to as the "second server." Therefore, the architecture shown in Figure 2b can be considered to include two types of servers: the first server and the second server. The above content should not be construed as limiting the present application.

基于图2b中所示的关系架构,本申请实施例提供的一种基于区块链的共识过程,如图2c所示,该过程具体包括以下步骤:Based on the relational architecture shown in FIG2b , an embodiment of the present application provides a consensus process based on blockchain, as shown in FIG2c . The process specifically includes the following steps:

S201:所述数据库存储执行共识所需的共识数据,供所述第一服务器和所述第二服务器在执行共识的过程中进行调用。S201: The database stores consensus data required for executing consensus, for the first server and the second server to call during the consensus execution process.

基于如图2b中的架构,所述的数据库设置于该服务器所在的节点中,且共用于该节点中的所有服务器,该节点中的任一服务器在接收到共识消息或生成了共识结果后,会存储在数据库中。那么,服务器便可从该数据库中获取执行共识所需的共识数据。其中,所述的共识数据,可包括服务器所接收到的来自于其他节点中服务器发送的共识消息、服务器自身所生成的共识结果、由客户端发送的能够触发共识过程的业务请求等。Based on the architecture shown in Figure 2b, the database is set up in the node where the server is located and is shared by all servers in the node. After any server in the node receives a consensus message or generates a consensus result, it will be stored in the database. The server can then obtain the consensus data required to execute the consensus from the database. The consensus data may include consensus messages received by the server from servers in other nodes, consensus results generated by the server itself, and service requests sent by clients that can trigger the consensus process.

这里需要说明的是,正是采用将共识数据存储在数据库中的方式,保证了共识数据对节点中的所有服务器可用。也就是说,如果第一服务器出现异常,虽然第一服务器不能继续参与共识,但节点中的其他第二服务器可基于数据库中存储的共识数据,代替出现异常的服务器执行共识。It's important to note that storing consensus data in a database ensures that it's available to all servers in the node. That is, if a server experiences an anomaly, while it can no longer participate in consensus, other servers in the node can execute consensus on behalf of the anomalous server based on the consensus data stored in the database.

S202:所述第一服务器在执行共识前或执行共识过程中出现异常时,所述第二服务器代替所述第一服务器,从所述数据库中获取共识数据,并根据所述共识数据执行共识,生成共识结果。S202: When an exception occurs on the first server before or during consensus execution, the second server replaces the first server, obtains consensus data from the database, executes consensus based on the consensus data, and generates a consensus result.

在实际运行中,参与共识的第一服务器可能会出现异常(如:宕机、重启等)。发生异常的时机通常是随机的,但无论异常发生在执行共识前或执行共识时,都将会影响共识过程的完成。此时,为了保证共识过程不受影响,故区块链节点内的其他正常运行的第二服务器便可以代替该异常的第一服务器执行共识。In actual operation, the first server participating in the consensus process may experience anomalies (such as downtime, reboot, etc.). The timing of the anomaly is usually random, but whether it occurs before or during the consensus process, it will affect the completion of the consensus process. In this case, to ensure that the consensus process is not affected, another normally operating second server within the blockchain node can replace the abnormal first server to execute the consensus.

正是由于第一服务器出现了异常,不能继续执行共识,所以,第二服务器可代替第一服务器接收共识消息,参与到原本由第一服务器所参与的共识过程。Because the first server has an exception and cannot continue to execute consensus, the second server can receive consensus messages instead of the first server and participate in the consensus process originally participated by the first server.

如前所述,节点中的任一服务器均会将共识数据存储在数据库中,所以,第二服务器便可以在数据库中查找并获取共识过程所需的共识数据,以代替出现异常的第一服务器执行共识,并进一步生成相应的共识结果。As mentioned above, any server in the node will store the consensus data in the database, so the second server can search and obtain the consensus data required for the consensus process in the database to replace the abnormal first server to execute the consensus and further generate the corresponding consensus result.

显然,由正常运行的服务器代替异常的服务器执行共识,保证了共识过程不受影响。Obviously, the consensus is executed by the normally operating server instead of the abnormal server, ensuring that the consensus process is not affected.

S203:所述第二服务器将所述共识结果存储在所述数据库中。S203: The second server stores the consensus result in the database.

在本申请实施例中,代替第一服务器执行共识的第二服务器,同样会按照本申请中的数据存储机制,将共识结果作为一种共识数据,存储在数据库中。In an embodiment of the present application, the second server that executes consensus instead of the first server will also store the consensus result as a kind of consensus data in the database according to the data storage mechanism in the present application.

通过上述步骤,对于区块链节点中的每一服务器而言,参与了某次共识过程的服务器,会将不同共识阶段的共识消息或自身所生成的当前阶段的共识结果,进行“公开”保存,即,存储在该节点内的数据库中,而该数据库对于该节点内的所有服务器均可使用,这样一来,如果参与某次共识的服务器出现下线或重启等异常现象,该服务器的共识数据可被节点内的其他服务器使用,并可代替出现异常现象的服务器继续执行相应的共识过程。Through the above steps, for each server in the blockchain node, the server that participated in a consensus process will "publicly" save the consensus messages of different consensus stages or the consensus results of the current stage generated by itself, that is, store them in the database within the node, and the database is available to all servers in the node. In this way, if a server participating in a consensus encounters an abnormality such as going offline or restarting, the consensus data of the server can be used by other servers in the node, and can continue to execute the corresponding consensus process instead of the server with the abnormality.

显然,相较于现有技术,节点中的各服务器将共识数据存储在节点内数据库的方式,即使在某一服务器出现异常时,其他正常运行的服务器也能够从数据库中获取到相应的共识数据,接替异常的服务器完成共识,也就保证了共识过程的正常进行,在减少重新发起共识次数的同时,能够在一定程度上提升共识过程的成功率,进而提升区块链的业务处理效率。Obviously, compared with the existing technology, the way in which each server in the node stores the consensus data in the database within the node means that even if a server malfunctions, other normally operating servers can obtain the corresponding consensus data from the database and take over the abnormal server to complete the consensus, thus ensuring the normal progress of the consensus process. While reducing the number of times consensus is re-initiated, it can improve the success rate of the consensus process to a certain extent, thereby improving the business processing efficiency of the blockchain.

这里需要说明的是,在共识时,对于节点中的任一服务器而言,将会接收到参与同一共识过程的其他设备所发送的共识消息。其中,所述的其他设备包括但不限于:参与共识过程的其他节点和/或客户端。所述的共识消息,可以包括客户端发送的、能够触发共识的业务请求,也可以包括其他节点在共识过程中发送的共识数据。It should be noted that during consensus, any server in a node will receive consensus messages from other devices participating in the same consensus process. These other devices include, but are not limited to, other nodes and/or clients participating in the consensus process. These consensus messages may include service requests sent by clients that trigger consensus, as well as consensus data sent by other nodes during the consensus process.

显然,针对某一次共识过程,如果第一服务器出现了异常,则第二服务器将会代替该第一服务器接收共识消息,以便参与到第一服务器的共识过程中。Obviously, for a certain consensus process, if an exception occurs in the first server, the second server will receive the consensus message instead of the first server in order to participate in the consensus process of the first server.

所以,所述第一服务器在执行共识前出现异常时,所述第二服务器代替所述第一服务器,从所述数据库中获取共识数据,可包括:当所述第一服务器在执行共识前出现异常时,所述第二服务器代替所述第一服务器,接收参与共识过程的其他设备发送的共识消息,根据所述共识消息,从所述数据库中获取与所述共识消息对应的共识数据。Therefore, when an exception occurs before the first server executes consensus, the second server replaces the first server to obtain consensus data from the database, which may include: when an exception occurs before the first server executes consensus, the second server replaces the first server to receive consensus messages sent by other devices participating in the consensus process, and obtains consensus data corresponding to the consensus message from the database based on the consensus message.

此外,在本申请实施例中,存在一种重试机制,具体而言,参与共识过程的其他设备,在发送了某一共识消息或业务请求后,若在设定的时间内为接收到对方的响应,则会再次发送相同的共识消息或业务请求。可见,如果第一服务器在执行共识过程中出现了异常,便不能够在设定的时间向其他设备做出响应。In addition, in the embodiments of the present application, there is a retry mechanism. Specifically, after sending a consensus message or service request, if the other devices participating in the consensus process do not receive a response from the other party within a set time, they will resend the same consensus message or service request. This shows that if an abnormality occurs during the consensus execution process, the first server will not be able to respond to the other devices within the set time.

所以,当所述第一服务器在执行共识过程中出现异常时,所述第二服务器代替所述第一服务器,接收参与共识过程的其他设备重试发送共识消息,根据所述共识消息,从所述数据库中获取与所述共识消息对应的共识数据。Therefore, when an exception occurs in the consensus process of the first server, the second server replaces the first server, receives the consensus message retried by other devices participating in the consensus process, and obtains the consensus data corresponding to the consensus message from the database based on the consensus message.

第二服务器在从数据库中获取共识数据时,通常将基于共识消息中的相应标识,下面将说明从数据库中获取共识数据的过程:When the second server obtains the consensus data from the database, it is usually based on the corresponding identifier in the consensus message. The following describes the process of obtaining the consensus data from the database:

在PBFT共识中,一个业务请求对应一次共识过程,而接收到客户端业务请求的节点(也称为主节点)会针对业务请求进行编号,那么,也就是说,业务请求的编号可以唯一对应一次共识过程。In PBFT consensus, one service request corresponds to one consensus process, and the node that receives the client's service request (also called the master node) will number the service request. In other words, the service request number can uniquely correspond to one consensus process.

具体来说,节点中的任一服务器所参与的某次共识过程,该共识过程中的业务请求的编号(即,业务请求的标识),能够唯一地标识一次共识过程,通过业务请求的编号,可以区别于节点中其他服务器所参与的共识过程。所以,如果服务器接收到了携带有某一业务请求编号的共识消息,便可根据该业务请求编号在数据库中获取具有相同业务请求编号的共识数据(获取到的这些共识数据与共识消息属于同一共识过程)。Specifically, the service request number (i.e., the service request identifier) of a consensus process participated in by any server in a node can uniquely identify a consensus process. The service request number can be used to distinguish it from consensus processes participated in by other servers in the node. Therefore, if a server receives a consensus message carrying a service request number, it can retrieve the consensus data with the same service request number from the database based on the service request number (the obtained consensus data belongs to the same consensus process as the consensus message).

例如:在共识过程中,共识消息的格式可以为:<共识阶段标识,视图编号,业务请求编号,业务请求摘要>。假设,服务器接收到某一共识消息为:<commit,v,n,D(m)>,其中,commit表示该节点已进入确认阶段,v表示视图编号,n表示业务请求的编号,D(m)表示发出通知消息的节点对业务请求的签名。则服务器可根据编号“n”,在数据库中查找该编号“n”对应的所有共识数据。For example, during the consensus process, the format of a consensus message might be: <consensus stage identifier, view number, service request number, service request summary>. Suppose the server receives a consensus message: <commit, v, n, D(m)>, where commit indicates that the node has entered the confirmation phase, v represents the view number, n represents the service request number, and D(m) represents the signature of the node issuing the notification message. Based on the number "n," the server can search the database for all consensus data corresponding to that number.

基于此,第二服务器从所述数据库中获取与所述共识消息对应的共识数据的过程为:第二服务器根据所述共识消息中包含的业务请求的标识,从所述数据库中查找并获取与所述标识对应的共识数据。Based on this, the process of the second server obtaining the consensus data corresponding to the consensus message from the database is: the second server searches and obtains the consensus data corresponding to the identifier from the database according to the identifier of the business request contained in the consensus message.

除了上述内容,在实际应用时,为了避免共识消息发送给已出现异常的第一服务器的情况,故在本申请实施例中,可通过节点上的网关实现共识消息的调配。也即,所述区块链节点还包括网关,此时,节点的架构可如图2d所示,可见,网关负责为节点中的服务器调配共识消息,一旦第一服务器出现异常,则网关便不会将共识消息发送给该异常的第一服务器,而是将该共识消息发发送给正常运行的第二服务器。In addition to the above, in actual applications, to avoid the situation where consensus messages are sent to the first server that has experienced an anomaly, in embodiments of the present application, consensus messages can be dispatched through a gateway on the node. That is, the blockchain node also includes a gateway. In this case, the node architecture can be as shown in Figure 2d. It can be seen that the gateway is responsible for dispatching consensus messages to the servers in the node. If the first server experiences an anomaly, the gateway will not send the consensus message to the anomaly first server, but will instead send the consensus message to the normally functioning second server.

所以,具体而言,对于第二服务器,接收共识消息的过程可以为:Therefore, specifically, for the second server, the process of receiving the consensus message can be:

当所述网关确定出所述第一服务器在执行共识前出现异常时,所述网关将接收到的、参与共识过程的其他设备发送的共识消息,转发给正常运行的第二服务器。那么,所述第二服务器接收所述网关转发的、参与共识过程的其他设备发送的共识消息。When the gateway determines that the first server has an abnormality before executing consensus, the gateway forwards the consensus messages received from other devices participating in the consensus process to the second server that is operating normally. The second server then receives the consensus messages forwarded by the gateway from other devices participating in the consensus process.

而当所述网关确定出所述第一服务器在执行共识过程中出现异常时,所述网关将接收到的、参与共识过程的其他设备重试发送共识消息,转发给正常运行的第二服务器。相应地,所述第二服务器接收所述网关转发的、参与共识过程的其他设备重试发送共识消息。When the gateway determines that an exception has occurred during the consensus process on the first server, the gateway forwards the received consensus message from other devices participating in the consensus process to the second server that is operating normally. Correspondingly, the second server receives the consensus message from other devices participating in the consensus process forwarded by the gateway.

可以理解地,在本申请实施例中,网关会将共识消息转发给节点中未出现异常的第二服务器,换言之,网关需要获知节点中出现异常的服务器,以及仍保持正常运行的服务器。It can be understood that in an embodiment of the present application, the gateway will forward the consensus message to the second server in the node where no abnormality occurs. In other words, the gateway needs to know the server in the node where the abnormality occurs and the server that is still operating normally.

在本申请实施例中,节点中的各服务器可通过与网关之间采用心跳机制进行通信,以使得网关能够获知各服务器的运行状态,即,所述网关通过以下方式确定所述第一服务器及第二服务器的运行状态:In an embodiment of the present application, each server in the node can communicate with the gateway through a heartbeat mechanism so that the gateway can learn the operating status of each server. That is, the gateway determines the operating status of the first server and the second server in the following manner:

所述网关接收所述第一服务器及第二服务器按照预设周期向所述网关发送运行状态消息,所述网关根据所述运行状态消息,确定所述第一服务器及第二服务器的运行状态。The gateway receives operation status messages sent by the first server and the second server to the gateway according to a preset period, and the gateway determines the operation status of the first server and the second server according to the operation status messages.

也就是说,如果网关能够接收到周期性的运行状态消息,则网关可以确定发送该运行状态消息的服务器正常工作,而如果网关在一定时间内都未接收到某服务器的运行状态消息,则网关可以确定该服务器出现了异常。That is to say, if the gateway can receive periodic operation status messages, the gateway can determine that the server sending the operation status message is working normally. If the gateway does not receive the operation status message of a server within a certain period of time, the gateway can determine that the server has an abnormality.

下面以一应用实例进行说明:The following is an application example:

例如:如图3a所示,假设在某一次共识过程中,节点1中的服务器11和节点2中的服务器21均参与了该次共识过程(图3a中用灰色表示两个服务器处于同一共识过程中)。在此假设,服务器21下线(即,在节点2中,服务器21为第一服务器),此时,服务器11向服务器21发送了某一共识消息,显然,由于服务器21下线,致使该服务器21并不会作出任何反馈,那么,服务器11等待了一定时间后,将发起重试(该重试又可看作是节点1发起的重试),即重新发送该共识消息,当节点2的网关接收到了节点1重试的共识消息后,将选定其内部某一正常工作的服务器来处理节点1的重试,如图3b所示,在本示例中,节点2中的服务器22被选中(即,服务器22为第二服务器),也即,网关会将重试发送的共识消息转发给服务器22,并由该服务器22接替服务器21执行共识。For example, as shown in Figure 3a, assume that in a certain consensus process, server 11 in node 1 and server 21 in node 2 both participate in the consensus process (gray in Figure 3a indicates that the two servers are in the same consensus process). Assume that server 21 is offline (i.e., in node 2, server 21 is the first server). At this time, server 11 sends a consensus message to server 21. Obviously, since server 21 is offline, server 21 will not provide any feedback. Then, after waiting for a certain period of time, server 11 will initiate a retry (this retry can also be regarded as a retry initiated by node 1), that is, resend the consensus message. When the gateway of node 2 receives the consensus message retried by node 1, it will select a normally working server within it to handle the retry of node 1. As shown in Figure 3b, in this example, server 22 in node 2 is selected (i.e., server 22 is the second server). That is, the gateway will forward the consensus message sent in the retry to server 22, and server 22 will take over the consensus execution from server 21.

另外,对于第二服务器将共识数据存储至服务器的过程而言,作为本申请实施例中的一种方式,第二服务器可在接收到共识消息(该共识消息可认为是一种共识数据)后立即将接收到的共识消息存储在数据库中,并在执行共识生成了对应于该共识消息的共识结果(该共识结果同样也可认为是一种共识数据)后,再将共识结果存储在数据库中。In addition, with respect to the process in which the second server stores the consensus data in the server, as a method in an embodiment of the present application, the second server may store the received consensus message in the database immediately after receiving the consensus message (the consensus message may be considered as a kind of consensus data), and after executing the consensus to generate a consensus result corresponding to the consensus message (the consensus result may also be considered as a kind of consensus data), the consensus result may be stored in the database.

而作为本申请实施例中的另一种方式,第二服务器接收到共识消息后,将经过前述过程,等待生成了共识结果后,在将共识消息和共识结果一并存储在数据库中。As another method in the embodiment of the present application, after receiving the consensus message, the second server will go through the aforementioned process, wait for the consensus result to be generated, and then store the consensus message and the consensus result in the database.

以上两种存储方式并不构成对本申请的限定。The above two storage methods do not constitute a limitation to this application.

以上为本申请实施例提供的基于区块链的共识方法,基于同样的思路,本申请实施例还提供一种基于区块链的共识装置,如图4所示,其中,一个区块链节点包括多个服务器和至少一个数据库,其中,所述数据库存储执行共识所需的共识数据,供所述第一服务器和所述第二服务器在执行共识的过程中进行调用;The above is a consensus method based on blockchain provided in an embodiment of the present application. Based on the same idea, an embodiment of the present application also provides a consensus device based on blockchain, as shown in FIG4 , wherein a blockchain node includes multiple servers and at least one database, wherein the database stores the consensus data required for executing the consensus, for the first server and the second server to call during the consensus execution process;

所述第一服务器在执行共识前或执行共识时出现异常;The first server encounters an exception before or during consensus execution;

所述基于区块链的共识装置至少包括:接收模块401、获取模块402、共识执行模块403及存储模块404,其中:The blockchain-based consensus device at least includes: a receiving module 401, an acquisition module 402, a consensus execution module 403 and a storage module 404, wherein:

获取模块402,从所述数据库中获取共识数据;An acquisition module 402 acquires consensus data from the database;

共识执行模块403,根据所述共识数据执行共识,生成共识结果;The consensus execution module 403 executes consensus according to the consensus data and generates a consensus result;

存储模块404,将所述共识结果存储在所述数据库中。The storage module 404 stores the consensus result in the database.

当所述第一服务器在执行共识前出现异常时,所述接收模块401,接收参与共识过程的其他设备发送的共识消息;所述获取模块,根据所述共识消息,从所述数据库中获取与所述共识消息对应的共识数据.When an exception occurs before the first server executes consensus, the receiving module 401 receives a consensus message sent by other devices participating in the consensus process; the acquisition module obtains the consensus data corresponding to the consensus message from the database based on the consensus message.

当所述第一服务器在执行共识过程中出现异常时,所述接收模块401,接收参与共识过程的其他设备重试发送共识消息;所述获取模块,根据所述共识消息,从所述数据库中获取与所述共识消息对应的共识数据.When an exception occurs during the consensus process of the first server, the receiving module 401 receives the consensus message sent by other devices participating in the consensus process; the acquisition module obtains the consensus data corresponding to the consensus message from the database based on the consensus message.

其中,当所述其他设备在发送共识消息并经过设定时间未接收到响应时,则重试发送所述共识消息。When the other device sends a consensus message and does not receive a response after a set time, it retries to send the consensus message.

所述共识消息中包含业务请求的标识;所述获取模块402,根据所述共识消息中包含的业务请求的标识,在所述数据库中,查找并获取与所述标识对应的共识数据。The consensus message includes an identifier of the business request; the acquisition module 402 searches for and acquires consensus data corresponding to the identifier in the database according to the identifier of the business request included in the consensus message.

此外,一个区块链节点中还可以包括网关,在此情况下,所述装置至少还包括:网关接收模块405、运行状态确定模块406及转发模块407。其中:In addition, a blockchain node may also include a gateway. In this case, the device further includes at least: a gateway receiving module 405, an operating status determination module 406, and a forwarding module 407.

当所述运行状态确定模块406确定出所述第一服务器在执行共识前出现异常时,所述转发模块407,将接收到的、参与共识过程的其他设备发送的共识消息,转发给正常运行的第二服务器.When the operating status determination module 406 determines that the first server has an abnormality before executing the consensus, the forwarding module 407 forwards the consensus message received from other devices participating in the consensus process to the second server that is operating normally.

当所述运行状态确定模块406确定出所述第一服务器在执行共识过程中出现异常时,所述转发模块407,将接收到的、参与共识过程的其他设备重试发送共识消息,转发给正常运行的第二服务器。When the operation status determination module 406 determines that an exception occurs in the consensus process of the first server, the forwarding module 407 forwards the received consensus message retried by other devices participating in the consensus process to the second server that is operating normally.

网关接收模块405,接收所述第一服务器及第二服务器按照预设周期向所述网关发送运行状态消息;The gateway receiving module 405 receives the operation status message sent by the first server and the second server to the gateway according to a preset period;

所述运行状态确定模块406,根据所述运行状态消息,确定所述第一服务器及第二服务器的运行状态。The operation status determination module 406 determines the operation status of the first server and the second server according to the operation status message.

在20世纪90年代,对于一个技术的改进可以很明显地区分是硬件上的改进(例如,对二极管、晶体管、开关等电路结构的改进)还是软件上的改进(对于方法流程的改进)。然而,随着技术的发展,当今的很多方法流程的改进已经可以视为硬件电路结构的直接改进。设计人员几乎都通过将改进的方法流程编程到硬件电路中来得到相应的硬件电路结构。因此,不能说一个方法流程的改进就不能用硬件实体模块来实现。例如,可编程逻辑器件(Programmable Logic Device,PLD)(例如现场可编程门阵列(Field Programmable GateArray,FPGA))就是这样一种集成电路,其逻辑功能由用户对器件编程来确定。由设计人员自行编程来把一个数字系统“集成”在一片PLD上,而不需要请芯片制造厂商来设计和制作专用的集成电路芯片。而且,如今,取代手工地制作集成电路芯片,这种编程也多半改用“逻辑编译器(logic compiler)”软件来实现,它与程序开发撰写时所用的软件编译器相类似,而要编译之前的原始代码也得用特定的编程语言来撰写,此称之为硬件描述语言(Hardware Description Language,HDL),而HDL也并非仅有一种,而是有许多种,如ABEL(Advanced Boolean Expression Language)、AHDL(Altera Hardware DescriptionLanguage)、Confluence、CUPL(Cornell University Programming Language)、HDCal、JHDL(Java Hardware Description Language)、Lava、Lola、MyHDL、PALASM、RHDL(RubyHardware Description Language)等,目前最普遍使用的是VHDL(Very-High-SpeedIntegrated Circuit Hardware Description Language)与Verilog。本领域技术人员也应该清楚,只需要将方法流程用上述几种硬件描述语言稍作逻辑编程并编程到集成电路中,就可以很容易得到实现该逻辑方法流程的硬件电路。In the 1990s, technological improvements could be clearly distinguished as either hardware improvements (for example, improvements to circuit structures like diodes, transistors, and switches) or software improvements (improvements to process flows). However, with the advancement of technology, many process flow improvements today can now be considered direct improvements to hardware circuit structures. Designers almost always create the corresponding hardware circuit structure by programming the improved process flow into the hardware circuit. Therefore, it cannot be said that a process flow improvement cannot be implemented using hardware modules. For example, a programmable logic device (PLD), such as a field programmable gate array (FPGA), is an integrated circuit whose logical function is determined by user programming. Designers can "integrate" a digital system on a PLD through their own programming, without having to hire a chip manufacturer to design and manufacture a dedicated integrated circuit chip. Moreover, nowadays, instead of manually fabricating integrated circuit chips, this programming is mostly done using "logic compiler" software. This is similar to the software compiler used when developing programs. Before compilation, the original code must also be written in a specific programming language, called a hardware description language (HDL). There is not just one HDL, but many, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used ones are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art will also understand that by simply programming the method flow in one of these hardware description languages and then programming it into an integrated circuit, a hardware circuit that implements the logic method flow can be easily obtained.

控制器可以按任何适当的方式实现,例如,控制器可以采取例如微处理器或处理器以及存储可由该(微)处理器执行的计算机可读程序代码(例如软件或固件)的计算机可读介质、逻辑门、开关、专用集成电路(Application Specific Integrated Circuit,ASIC)、可编程逻辑控制器和嵌入微控制器的形式,控制器的例子包括但不限于以下微控制器:ARC 625D、Atmel AT91SAM、Microchip PIC18F26K20以及Silicone Labs C8051F320,存储器控制器还可以被实现为存储器的控制逻辑的一部分。本领域技术人员也知道,除了以纯计算机可读程序代码方式实现控制器以外,完全可以通过将方法步骤进行逻辑编程来使得控制器以逻辑门、开关、专用集成电路、可编程逻辑控制器和嵌入微控制器等的形式来实现相同功能。因此这种控制器可以被认为是一种硬件部件,而对其内包括的用于实现各种功能的装置也可以视为硬件部件内的结构。或者甚至,可以将用于实现各种功能的装置视为既可以是实现方法的软件模块又可以是硬件部件内的结构。The controller can be implemented in any suitable manner. For example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also know that in addition to implementing the controller in a purely computer-readable program code format, the controller can be implemented in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers by logically programming the method steps. Therefore, such a controller can be considered a hardware component, and the devices included therein for implementing various functions can also be considered as structures within the hardware component. Or even, the devices for implementing various functions can be considered as both software modules that implement the method and structures within the hardware component.

上述实施例阐明的系统、装置、模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。一种典型的实现设备为计算机。具体的,计算机例如可以为个人计算机、膝上型计算机、蜂窝电话、相机电话、智能电话、个人数字助理、媒体播放器、导航设备、电子邮件设备、游戏控制台、平板计算机、可穿戴设备或者这些设备中的任何设备的组合。The systems, devices, modules, or units described in the above embodiments may be implemented by computer chips or entities, or by products having certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.

为了描述的方便,描述以上装置时以功能分为各种单元分别描述。当然,在实施本申请时可以把各单元的功能在同一个或多个软件和/或硬件中实现。For the convenience of description, the above devices are described as being divided into various units according to their functions. Of course, when implementing this application, the functions of each unit can be implemented in the same or multiple software and/or hardware.

本领域内的技术人员应明白,本发明的实施例可提供为方法、系统、或计算机程序产品。因此,本发明可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本发明可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。It will be understood by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

本发明是参照根据本发明实施例的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。The present invention is described with reference to the flowcharts and/or block diagrams of the methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and/or box in the flowchart and/or block diagram, as well as the combination of processes and/or boxes in the flowchart and/or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device produce a device for implementing the functions specified in one or more processes in the flowchart and/or one or more boxes in the block diagram.

这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a product including an instruction device that implements the functions specified in one or more processes in the flowchart and/or one or more boxes in the block diagram.

这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more processes in the flowchart and/or one or more boxes in the block diagram.

在一个典型的配置中,计算设备包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.

内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and/or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.

计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑可读媒体(transitory media),如调制的数据信号和载波。Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.

还需要说明的是,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、商品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、商品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、商品或者设备中还存在另外的相同要素。It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.

本领域技术人员应明白,本申请的实施例可提供为方法、系统或计算机程序产品。因此,本申请可采用完全硬件实施例、完全软件实施例或结合软件和硬件方面的实施例的形式。而且,本申请可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present application may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

本申请可以在由计算机执行的计算机可执行指令的一般上下文中描述,例如程序模块。一般地,程序模块包括执行特定任务或实现特定抽象数据类型的例程、程序、对象、组件、数据结构等等。也可以在分布式计算环境中实践本申请,在这些分布式计算环境中,由通过通信网络而被连接的远程处理设备来执行任务。在分布式计算环境中,程序模块可以位于包括存储设备在内的本地和远程计算机存储介质中。The present application may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communications network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.

本说明书中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于系统实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。The various embodiments in this specification are described in a progressive manner. Similar parts between the various embodiments can be referred to in conjunction with each other. Each embodiment focuses on the differences between the other embodiments. In particular, the system embodiments are generally similar to the method embodiments, so the description is relatively simple. For relevant parts, refer to the description of the method embodiments.

以上所述仅为本申请的实施例而已,并不用于限制本申请。对于本领域技术人员来说,本申请可以有各种更改和变化。凡在本申请的精神和原理之内所作的任何修改、等同替换、改进等,均应包含在本申请的权利要求范围之内。The foregoing is merely an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should all be included within the scope of the claims of the present application.

Claims (10)

1.一种基于区块链的共识方法,其特征在于,一个区块链节点包括第一服务器、第二服务器和至少一个数据库,所述方法包括:1. A consensus method based on blockchain, characterized in that a blockchain node includes a first server, a second server, and at least one database, the method comprising: 所述数据库存储执行共识所需的共识数据,供所述第一服务器和所述第二服务器在执行共识的过程中进行调用;The database stores the consensus data required for consensus execution, which can be accessed by the first server and the second server during the consensus execution process. 所述第一服务器在执行共识前或执行共识过程中出现异常时,所述第二服务器代替所述第一服务器,从所述数据库中获取共识数据,并根据所述共识数据执行共识,生成共识结果,具体包括:If the first server encounters an anomaly before or during consensus execution, the second server takes over, retrieves consensus data from the database, executes consensus based on the consensus data, and generates a consensus result, specifically including: 当所述第一服务器在执行共识过程中出现异常时,所述第二服务器代替所述第一服务器,接收参与共识过程的其他设备重试发送共识消息,根据所述共识消息,从所述数据库中获取与所述共识消息对应的共识数据;When the first server encounters an error during the consensus process, the second server takes over from the first server, receives retry messages from other devices participating in the consensus process, and retrieves the consensus data corresponding to the consensus message from the database based on the consensus message. 其中,当所述其他设备在发送共识消息并经过设定时间未接收到响应时,则重试发送所述共识消息;所述第二服务器将所述共识结果存储在所述数据库中。If the other device sends a consensus message and does not receive a response after a set time, it will retry sending the consensus message; the second server stores the consensus result in the database. 2.如权利要求1所述的方法,其特征在于,所述第一服务器在执行共识前出现异常时,所述第二服务器代替所述第一服务器,从所述数据库中获取共识数据,具体包括:2. The method as described in claim 1, characterized in that, when the first server encounters an anomaly before executing consensus, the second server replaces the first server and retrieves consensus data from the database, specifically including: 当所述第一服务器在执行共识前出现异常时,所述第二服务器代替所述第一服务器,接收参与共识过程的其他设备发送的共识消息,根据所述共识消息,从所述数据库中获取与所述共识消息对应的共识数据。When the first server encounters an anomaly before executing consensus, the second server takes over from the first server, receives consensus messages sent by other devices participating in the consensus process, and retrieves the consensus data corresponding to the consensus messages from the database based on the consensus messages. 3.如权利要求2所述的方法,其特征在于,所述共识消息中包含业务请求的标识;3. The method as described in claim 2, wherein the consensus message includes an identifier of the service request; 根据所述共识消息,从所述数据库中获取与所述共识消息对应的共识数据,具体包括:Based on the consensus message, obtain the consensus data corresponding to the consensus message from the database, specifically including: 所述第二服务器根据所述共识消息中包含的业务请求的标识,从所述数据库中查找并获取与所述标识对应的共识数据。The second server searches for and retrieves consensus data corresponding to the business request identifier contained in the consensus message from the database. 4.如权利要求2所述的方法,其特征在于,所述区块链节点还包括网关;4. The method as described in claim 2, wherein the blockchain node further includes a gateway; 接收参与共识过程的其他设备发送的共识消息,具体包括:Receive consensus messages sent by other devices participating in the consensus process, specifically including: 当所述网关确定出所述第一服务器在执行共识前出现异常时,所述网关将接收到的、参与共识过程的其他设备发送的共识消息,转发给正常运行的第二服务器;When the gateway determines that the first server has encountered an anomaly before executing consensus, the gateway will forward the consensus messages received from other devices participating in the consensus process to the normally operating second server. 所述第二服务器接收所述网关转发的、参与共识过程的其他设备发送的共识消息;The second server receives consensus messages forwarded by the gateway from other devices participating in the consensus process; 接收参与共识过程的其他设备重试发送共识消息,具体包括:Receive retry messages from other devices participating in the consensus process, specifically including: 当所述网关确定出所述第一服务器在执行共识过程中出现异常时,所述网关将接收到的、参与共识过程的其他设备重试发送共识消息,转发给正常运行的第二服务器;When the gateway determines that the first server has encountered an anomaly during the consensus process, the gateway will resend the consensus message received from other devices participating in the consensus process and forward it to the normally operating second server. 所述第二服务器接收所述网关转发的、参与共识过程的其他设备重试发送共识消息。The second server receives consensus messages forwarded by the gateway from other devices participating in the consensus process that are retrying to send consensus messages. 5.如权利要求4所述的方法,其特征在于,所述网关通过以下方式确定所述第一服务器及第二服务器的运行状态:5. The method as described in claim 4, wherein the gateway determines the operating status of the first server and the second server in the following manner: 所述网关接收所述第一服务器及第二服务器按照预设周期向所述网关发送运行状态消息;The gateway receives operation status messages sent by the first server and the second server at a preset period. 所述网关根据所述运行状态消息,确定所述第一服务器及第二服务器的运行状态。The gateway determines the operating status of the first server and the second server based on the operating status message. 6.一种基于区块链的共识装置,其特征在于,一个区块链节点包括第一服务器、第二服务器和至少一个数据库,其中,6. A blockchain-based consensus device, characterized in that a blockchain node comprises a first server, a second server, and at least one database, wherein, 所述数据库存储执行共识所需的共识数据,供所述第一服务器和所述第二服务器在执行共识的过程中进行调用;The database stores the consensus data required for consensus execution, which can be accessed by the first server and the second server during the consensus execution process. 所述第一服务器在执行共识前或执行共识时出现异常;The first server encountered an anomaly before or during consensus execution; 所述第二服务器包括:The second server includes: 获取模块,从所述数据库中获取共识数据;The acquisition module retrieves consensus data from the database; 共识执行模块,根据所述共识数据执行共识,生成共识结果;The consensus execution module performs consensus based on the consensus data and generates a consensus result. 存储模块,将所述共识结果存储在所述数据库中;The storage module stores the consensus result in the database; 接收模块,当所述第一服务器在执行共识过程中出现异常时,所述接收模块,接收参与共识过程的其他设备重试发送共识消息;所述获取模块,根据所述共识消息,从所述数据库中获取与所述共识消息对应的共识数据;The receiving module receives retry messages from other devices participating in the consensus process when an exception occurs during the consensus process of the first server; the obtaining module obtains consensus data corresponding to the consensus message from the database based on the consensus message. 其中,当所述其他设备在发送共识消息并经过设定时间未接收到响应时,则重试发送所述共识消息。If the other device does not receive a response after sending a consensus message within a set time, it will retry sending the consensus message. 7.如权利要求6所述的装置,其特征在于,所述装置还包括:接收模块;7. The apparatus as claimed in claim 6, wherein the apparatus further comprises: a receiving module; 当所述第一服务器在执行共识前出现异常时,所述接收模块,接收参与共识过程的其他设备发送的共识消息;所述获取模块,根据所述共识消息,从所述数据库中获取与所述共识消息对应的共识数据。When the first server encounters an anomaly before executing consensus, the receiving module receives consensus messages sent by other devices participating in the consensus process; the obtaining module retrieves consensus data corresponding to the consensus messages from the database based on the consensus messages. 8.如权利要求7所述的装置,其特征在于,所述共识消息中包含业务请求的标识;8. The apparatus as described in claim 7, wherein the consensus message includes an identifier of the service request; 所述获取模块,根据所述共识消息中包含的业务请求的标识,从所述数据库中查找并获取与所述标识对应的共识数据。The acquisition module searches for and retrieves consensus data corresponding to the identifier of the business request contained in the consensus message from the database. 9.如权利要求8所述的装置,其特征在于,所述区块链节点还包括网关;9. The apparatus of claim 8, wherein the blockchain node further comprises a gateway; 所述装置还包括:运行状态确定模块及转发模块;The device further includes: an operating status determination module and a forwarding module; 当所述运行状态确定模块确定出所述第一服务器在执行共识前出现异常时,所述转发模块,将接收到的、参与共识过程的其他设备发送的共识消息,转发给正常运行的第二服务器;When the operation status determination module determines that the first server has an anomaly before executing consensus, the forwarding module forwards the consensus message received from other devices participating in the consensus process to the normally operating second server. 当所述运行状态确定模块确定出所述第一服务器在执行共识过程中出现异常时,所述转发模块,将接收到的、参与共识过程的其他设备重试发送共识消息,转发给正常运行的第二服务器。When the operation status determination module determines that the first server has encountered an anomaly during the consensus process, the forwarding module forwards the consensus message received from other devices participating in the consensus process to the normally operating second server. 10.如权利要求9所述的装置,其特征在于,所述装置还包括:网关接收模块,接收所述第一服务器及第二服务器按照预设周期向所述网关发送运行状态消息;10. The apparatus as described in claim 9, wherein the apparatus further comprises: a gateway receiving module, for receiving running status messages sent by the first server and the second server to the gateway according to a preset period; 所述运行状态确定模块,根据所述运行状态消息,确定所述第一服务器及第二服务器的运行状态。The operation status determination module determines the operation status of the first server and the second server based on the operation status message.
HK18106134.4A 2018-05-11 Consensus method and device based on block chain HK1246891B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
HK18106134.4A HK1246891B (en) 2018-05-11 Consensus method and device based on block chain

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
HK18106134.4A HK1246891B (en) 2018-05-11 Consensus method and device based on block chain

Publications (2)

Publication Number Publication Date
HK1246891A1 HK1246891A1 (en) 2018-09-14
HK1246891B true HK1246891B (en) 2021-03-05

Family

ID=

Similar Documents

Publication Publication Date Title
TWI696083B (en) A consensus method and device based on blockchain
CN107391320B (en) A consensus method and device
TWI686709B (en) Method and device for business acceptance and consensus
CN106982236B (en) An information processing method, device and system
US7793140B2 (en) Method and system for handling failover in a distributed environment that uses session affinity
JP2017538200A (en) Service addressing in a distributed environment
CN110430255A (en) The processing method of service request, system and electronic equipment in distributed type assemblies
CN107612950A (en) A kind of method, apparatus, system, electronic equipment that service is provided
CN114691309A (en) Batch business processing system, method and device
WO2024119853A1 (en) Database disaster recovery system, method and apparatus, and storage medium and electronic device
CN116743550A (en) A method for handling faulty storage nodes in distributed storage clusters
CN111628924B (en) E-mail sending method, system, storage medium and electronic device
HK1246891B (en) Consensus method and device based on block chain
CN106850354A (en) A kind of processing method and processing device of Single Point of Faliure
JP6622926B2 (en) Method and apparatus for checking integrity of distributed service processing
CN110673793B (en) Storage device node event management method and system, electronic device and storage medium
HK1246891A1 (en) Consensus method and device based on block chain
CN114612238A (en) Method and device for returning execution result of blockchain transaction
CN114327989A (en) Fault tolerant method, computer system, apparatus, electronic device and storage medium
HK1261859B (en) Communication data recovery method, device and equipment
CN116049310A (en) Transaction execution method, storage service and blockchain nodes in blockchain system
HK1247454B (en) Business acceptance and common method and device
HK1247302B (en) Consensus method and device
CN113821325A (en) A method, apparatus, device and medium for calling application program
HK1247457B (en) Block chain service acceptance and consensus methods and devices