A cross-chain gateway redundant switching method and system based on relay chain

By setting up multiple cross-chain gateways on the relay chain for redundant switching, and using the main gateway election and heartbeat mechanism, the single point of failure problem of the relay cross-chain system is solved, high reliability and business continuity are achieved, and the satisfaction of the The demand in the medical field.

CN118827336BActive Publication Date: 2025-02-07ZHEJIANG UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411268732.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-11
Publication Date
2025-02-07
Estimated Expiration
2044-09-11

AI Technical Summary

Technical Problem

The existing relay cross-chain system has a single point of failure problem, which cannot meet the high reliability requirements of cross-chain gateways in the medical field.

Method used

By setting up multiple cross-chain gateways on the relay chain for redundant switching, the main gateway campaign and heartbeat mechanism are used to determine and maintain the roles of the main gateway and slave gateway, ensuring that the system has at least one cross-chain gateway to assume the main at any time. Gateway function.

Benefits of technology

It effectively avoids single point of failure caused by cross-chain gateway failure, ensures the stability and reliability of the relay cross-chain system, and ensures the effective interoperability of medical resource data and the continuity of business collaboration.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118827336B_ABST
    Figure CN118827336B_ABST
Patent Text Reader

Abstract

The present invention discloses a cross-chain gateway redundant switching method and system based on relay chain, which belongs to the field of cross-chain gateway technology, including: the relay chain is connected to the application chain through a plurality of cross-chain gateways; a plurality of cross-chain gateways send a master gateway election request to the relay chain node directly connected to themselves, and determine the master gateway and the slave gateway based on the master gateway election reply of the relay chain node; the master gateway and the slave gateway send heartbeat information to the relay chain node directly connected to themselves, and the relay chain node replies to the heartbeat information based on the reply information of the consensus node; the master gateway maintains the master gateway mode or enters the slave gateway mode based on the heartbeat information reply; the slave gateway maintains the slave gateway mode or conducts the master gateway election based on the heartbeat information reply. The present invention avoids the single point failure problem of the cross-chain gateway, ensures that the blockchain system of the medical institution can be continuously and stably connected to the relay cross-chain system, ensures the effective intercommunication of medical resource data and the continuity of business collaboration, and meets the reliability requirements.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of cross-chain gateway technology, and in particular to a cross-chain gateway redundant switching method and system based on a relay chain. Background Art

[0002] Medical institutions can use blockchain technology to solve problems such as internal resource integration and trusted deployment, and achieve efficient governance of resource information by building an independent management system that is tightly coupled with its own underlying technical facilities. However, since each medical institution independently builds and operates its own blockchain infrastructure, these heterogeneous systems lack effective interoperability. In order to solve this problem, relay cross-chain technology was proposed, which can enable the intercommunication of data resources between blockchain systems of different medical institutions and promote the scheduling and collaboration of medical resources across institutions. As a component of relay cross-chain technology, the cross-chain gateway undertakes the important tasks of docking different blockchain systems, converting data protocols, and promoting cross-chain interactions. In practical applications, the non-persistent storage characteristics of the cross-chain gateway make the general relay cross-chain system often ignore its continuous availability issues. Once the cross-chain gateway fails, the blockchain system loses the connection bridge with the relay cross-chain system, resulting in the interruption of cross-chain collaborative business, which in turn affects the intercommunication and business collaboration of upper-level resource data. In the medical field, especially in emergency situations, such fault interruption is unacceptable.

[0003] The "A method, system and terminal device for determining a cross-chain gateway of a blockchain" disclosed in Chinese patent documents has a publication number of CN112636987A and a publication date of 20210409, including: when receiving a request instruction sent by a target node to apply to become a cross-chain gateway of an application chain, querying whether the master node information of the cross-chain gateway of the application chain has been determined in the relay chain; when the master node information of the cross-chain gateway of the application chain has not been queried, the target node is used as the master node of the cross-chain gateway, and a first message is sent to the target node; wherein the master node of the cross-chain gateway is used to exercise the cross-chain gateway function; when the master node information of the cross-chain gateway of the application chain has been queried, the target node is used as the slave node of the cross-chain gateway, and a second message is sent to the target node; wherein the slave node of the cross-chain gateway is an alternative node of the master node of the cross-chain gateway. This technology can improve the reliability of the cross-chain gateway by gateway redundancy. However, when multiple gateways are connected to the same relay chain node in this technology, if the connected relay chain node fails, all gateways will not work; if multiple gateways are connected to different relay chain nodes, it is very likely that there will be two surviving main gateways at the same time; therefore, in the complete relay mode cross-chain deployment architecture, this technology still has a single point of failure problem. Summary of the invention

[0004] The present invention aims to overcome the problem that the relay cross-chain system in the prior art still has a single point failure problem and cannot meet the high reliability requirements of the cross-chain gateway in the medical field, and provides a cross-chain gateway redundant switching method and system based on a relay chain.

[0005] In order to achieve the above object, the present invention adopts the following technical solutions:

[0006] A cross-chain gateway redundancy switching method based on a relay chain, comprising:

[0007] The relay chain is connected to the application chain through several cross-chain gateways;

[0008] The plurality of cross-chain gateways send master gateway election requests to the relay chain nodes directly connected to them, and determine the master gateway and the slave gateway based on the master gateway election replies of the relay chain nodes;

[0009] The master gateway and slave gateway send heartbeat information to the relay chain nodes directly connected to them, and the relay chain nodes reply with heartbeat information based on the reply information of the consensus node;

[0010] The master gateway maintains the master gateway mode or enters the slave gateway mode based on the heartbeat message reply;

[0011] The slave gateway maintains the slave gateway mode or conducts the master gateway election based on the heartbeat message reply.

[0012] The present invention makes technical improvements on the basis of using multiple cross-chain gateways for redundant settings, sets the master gateway and the slave gateway through the master gateway election, and provides technical content on how to select the master gateway from multiple cross-chain gateways, so that the system has at least one cross-chain gateway to assume the function of the master gateway at any time, ensuring the stability and reliability of the relay cross-chain system; at the same time, through the setting of the heartbeat mechanism, the slave gateway can automatically set the process of the master gateway in the absence of the master gateway, select one from all the slave gateways to assume the function of the master gateway, avoid the single point failure problem caused by the failure of the cross-chain gateway, and can also correct the situation where multiple cross-chain gateways mistakenly believe that they are the master gateway, and only retain one master gateway; fundamentally solve the single point failure problem in the relay cross-chain mode.

[0013] Preferably, the process of the plurality of cross-chain gateways electing a master gateway includes:

[0014] Each cross-chain gateway sets its own unique identifier and the identity ID of the application chain responsible for communication;

[0015] Send a query request to the relay chain node directly connected to itself, including the identity ID;

[0016] The relay chain node asks the main gateway for a reply, including the identity ID and unique identifier of the current main gateway;

[0017] The cross-chain gateway sets the master gateway request or enters the slave gateway mode according to the reply from the master gateway.

[0018] Preferably, the relay chain node inquiring the main gateway for a reply includes:

[0019] When the relay chain node queries the master gateway corresponding to the identity ID locally and the master gateway is legitimate, it replies with the identity ID and unique identifier of the current master gateway;

[0020] Otherwise, the relay chain node sends a query request to the consensus node for the master gateway. Based on the legitimate master gateway reply of the consensus node, the current master gateway is determined and the identity ID and unique identifier are replied.

[0021] When all relay chain nodes indicate that there is no legitimate master gateway, they reply that there is no master gateway.

[0022] Preferably, the judgment of the cross-chain gateway entering the slave gateway mode includes:

[0023] The relay chain node replies to the cross-chain gateway with the unique identifier of the current main gateway, and the unique identifier of the cross-chain gateway does not meet the main gateway switching conditions compared with the unique identifier of the current main gateway.

[0024] Preferably, the cross-chain gateway determines the request to set the main gateway including:

[0025] The relay chain node replies to the cross-chain gateway that there is no master gateway; or

[0026] The relay chain node replies to the cross-chain gateway with the unique identifier of the current main gateway, and the unique identifier of the cross-chain gateway meets the main gateway switching condition compared with the unique identifier of the current main gateway.

[0027] Preferably, the relay chain node sets the main gateway reply including:

[0028] The cross-chain gateway sets the main gateway request including the identity ID and unique identifier;

[0029] If the relay chain node finds that there is no master gateway under the corresponding identity ID in the local query, or the unique identifier of the current master gateway meets the master gateway switching conditions compared with the unique identifier of the requested cross-chain gateway, the requested cross-chain gateway will be updated to the current master gateway;

[0030] Otherwise, the relay chain node does not update the current main gateway;

[0031] Reply to the unique identifier of the current primary gateway.

[0032] Preferably, the relay chain node replies to the heartbeat information based on the reply information of the consensus node, including:

[0033] The relay chain node sends a query request to the consensus node for the master gateway. Based on the legitimate master gateway reply of the consensus node, the current master gateway is determined and the identity ID and unique identifier are replied.

[0034] When all relay chain nodes indicate that there is no legitimate master gateway, they reply that there is no master gateway.

[0035] Preferably, the conditions for the master gateway to enter the slave gateway mode are:

[0036] The heartbeat message replies that there is no master gateway, or

[0037] The unique identifier of the current primary gateway in the heartbeat message reply is different from its own unique identifier;

[0038] The condition for a slave gateway to run for master gateway is that the heartbeat message replies that there is no master gateway.

[0039] As a preferred embodiment, the legitimacy judgment process of the main gateway includes:

[0040] After the relay chain node determines the primary gateway, it caches the timestamp of the most recent heartbeat information sent by the primary gateway;

[0041] Compare the difference between the timestamp of the most recent heartbeat message sent by the main gateway and the current timestamp to see if it exceeds the gateway switching duration threshold; if so, the main gateway is illegal.

[0042] A cross-chain gateway redundant switching system based on a relay chain, including an application chain connected to the relay chain through a plurality of cross-chain gateways;

[0043] Any two relay chain nodes in the relay chain are connected to each other in communication;

[0044] The cross-chain gateway sets its own unique identifier and the identity ID of the application chain responsible for communication, and sends a master gateway election request or heartbeat information to the relay chain node directly connected to it;

[0045] The relay chain node caches the unique identifier of the master gateway corresponding to the identity ID and the timestamp of the most recent heartbeat message sent by the master gateway, and responds to the cross-chain gateway for the master gateway election or heartbeat message.

[0046] The present invention has the following beneficial effects: through the redundant setting of connecting the application chain and the relay chain by multiple cross-chain gateways, when a cross-chain gateway fails, it can switch to other cross-chain gateways to continue to maintain the cross-chain process, avoiding the impact of the cross-chain gateway failure on the stability and reliability of the entire relay cross-chain system. After the redundancy setting of the cross-chain gateway is performed, multiple cross-chain gateways are connected to different relay chain nodes in the relay chain, and even if a relay chain node fails, it does not affect the work between other relay chain nodes and the cross-chain gateway. The master gateway and slave gateway are set up through the master gateway election, so that there is at least one cross-chain gateway in the system at any time to assume the function of the master gateway; at the same time, the heartbeat mechanism is set up so that the slave gateway can automatically set the master gateway process in the absence of the master gateway, avoiding the single point failure problem of the cross-chain gateway. It can also correct the situation when multiple cross-chain gateways mistakenly think they are the master gateway and only retain one master gateway; fundamentally solve the single point failure problem in the relay cross-chain mode, ensure that the blockchain system of the medical institution can be continuously and stably connected to the relay cross-chain system, ensure the effective intercommunication of medical resource data and the continuity of business collaboration, and meet the extremely high reliability and real-time requirements in the medical field. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] Figure 1 It is a flow chart of the cross-chain gateway redundant switching method in the present invention.

[0048] Figure 2 It is a flow chart of the main gateway election in the present invention.

[0049] Figure 3 It is a schematic diagram of the cross-chain gateway redundant switching system in the present invention. DETAILED DESCRIPTION

[0050] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments.

[0051] In the relay cross-chain mode, the relay chain assumes important management roles in the cross-chain system, such as cross-chain management and state maintenance, while the responsibilities of the cross-chain gateway are mainly: application chain data monitoring, conversion, packaging and transmission to the relay chain. The cross-chain trust model in the relay cross-chain mode relies on the immutability of data on the application chain and the alliance governance mechanism on the relay chain (regardless of the gateway component), so the gateway component itself is a component that does not need to provide a trust mechanism. At the same time, the data of the cross-chain gateway comes entirely from the application chain and relay chain to which it is connected, so the cross-chain gateway itself can be implemented as a gateway component that "does not have any state that needs to be persisted". However, because the gateway component provides the only channel for the circulation of data between the application chain and the relay chain, the downtime of the gateway component will cause the cross-chain process to be interrupted. This single point of failure problem needs to be solved to ensure the working stability and reliability of the relay cross-chain system.

[0052] The present invention solves the single point failure problem by providing a cross-chain gateway with redundant backup, such as Figure 1 As shown, a cross-chain gateway redundancy switching method based on a relay chain includes:

[0053] The relay chain is connected to the application chain through several cross-chain gateways;

[0054] Several cross-chain gateways send master gateway election requests to the relay chain nodes directly connected to them, and determine the master gateway and slave gateway based on the master gateway election replies of the relay chain nodes;

[0055] The master gateway and slave gateway send heartbeat information to the relay chain nodes directly connected to them, and the relay chain nodes reply with heartbeat information based on the reply information of the consensus node;

[0056] The master gateway maintains the master gateway mode or enters the slave gateway mode based on the heartbeat message reply;

[0057] The slave gateway maintains the slave gateway mode or conducts the master gateway election based on the heartbeat message reply.

[0058] It should be noted that the present invention makes technical improvements on the basis of using multiple cross-chain gateways for redundant settings, sets the master gateway and the slave gateway through the master gateway election, and provides technical content on how to select the master gateway from multiple cross-chain gateways, so that the system has at least one cross-chain gateway to assume the function of the master gateway at any time, ensuring the stability and reliability of the relay cross-chain system; at the same time, through the setting of the heartbeat mechanism, the slave gateway can automatically set the process of the master gateway in the absence of the master gateway, and select one from all the slave gateways to assume the function of the master gateway, avoiding the single point failure problem caused by the failure of the cross-chain gateway, and can also correct the situation where multiple cross-chain gateways mistakenly believe that they are the master gateway, and only retain one master gateway; fundamentally solve the single point failure problem in the relay cross-chain mode, ensure that the blockchain system of the medical institution can be continuously and stably connected to the relay cross-chain system, ensure the effective intercommunication of medical resource data and the continuity of business collaboration, and meet the extremely high reliability and real-time requirements in the medical field.

[0059] It is worth noting that the core of the cross-chain gateway redundant switching method includes two parts: the election of the main gateway of several cross-chain gateways and the heartbeat mechanism of the network; the election of the main gateway is used to select the main gateway to perform the corresponding function; the heartbeat mechanism is used to monitor the legitimacy of the main gateway to determine whether to switch the main gateway. Based on the method flow of these two parts, the cross-chain gateway can realize the function of automatically completing the identity switching of the new main gateway when the main gateway fails during the execution process.

[0060] As a specific example, Figure 2As shown in the figure, the process of several cross-chain gateways running for the main gateway includes:

[0061] Each cross-chain gateway sets its own unique identifier and the identity ID of the application chain responsible for communication;

[0062] Send a query request to the relay chain node directly connected to itself, including the identity ID;

[0063] The relay chain node asks the main gateway for a reply, including the identity ID and unique identifier of the current main gateway;

[0064] The cross-chain gateway sets the master gateway request or enters the slave gateway mode according to the reply from the master gateway.

[0065] It should be noted that the client component of the relay chain is integrated into the cross-chain gateway. When the gateway component is started, before starting the core cross-chain related protocols, it first enters the main gateway election phase. During this phase, the cross-chain gateway itself needs to maintain two state values ​​in memory: identity ID and unique identifier (instance ID). The identity ID represents the identity of the application chain that the current cross-chain gateway is responsible for communicating with, while the unique identifier is a globally unique ID generated by the cross-chain gateway itself, which is unique. The unique identifier needs to be a data type that can compare sizes, such as integer, string type, etc., which is used to compare the unique identifiers of different cross-chain gateways when judging the subsequent main gateway switching conditions.

[0066] Specifically, after completing the prerequisite settings for the main gateway election, several cross-chain gateways begin the main gateway election. After each cross-chain gateway is started, it first generates its own unique identifier (instance ID). The cross-chain gateway sends a request to inquire about the main gateway to the relay chain node directly connected to it through the integrated relay chain client. The request contains the application chain identity ID that the cross-chain gateway is responsible for communicating with, and synchronously waits for the reply of the relay chain node. If no reply is received after the timeout, the request to inquire about the main gateway is retried until the relay chain node gives a reply.

[0067] As a specific embodiment, after receiving the query request to the main gateway, the relay chain node queries the main gateway for a reply, including:

[0068] When the relay chain node queries the master gateway corresponding to the identity ID locally and the master gateway is legitimate, it replies with the identity ID and unique identifier of the current master gateway;

[0069] Otherwise, the relay chain node sends a query request to the consensus node for the master gateway. Based on the legitimate master gateway reply of the consensus node, the current master gateway is determined and the identity ID and unique identifier are replied.

[0070] When all relay chain nodes indicate that there is no legitimate master gateway, they reply that there is no master gateway.

[0071] Specifically, a map structure (key-value mapping structure) named pierStatus (gateway instance status) will be continuously maintained in the memory of the relay chain node to manage the mapping of the identity ID to the current primary gateway, that is, the unique identification information of the primary gateway under a certain application chain identity ID and the gateway switching time threshold of the primary gateway are stored for local query by the relay chain node.

[0072] In response to the request to inquire about the main gateway, the relay chain node will first query its own pierStatus locally. If the identity ID in the request to inquire about the main gateway and its corresponding main gateway are found, the gateway switching time threshold of the cross-chain gateway is used to determine whether the current main gateway information is expired, that is, whether the difference between the timestamp of the last time the main gateway sent a heartbeat message and the current timestamp exceeds the gateway switching time threshold; if not, the current main gateway information is legal, and the relay chain node directly replies to the requesting cross-chain gateway with the identity ID and unique flag of the current main gateway.

[0073] If the relay chain node does not query the primary gateway corresponding to the identity ID locally or the difference in timestamps exceeds the gateway switching time threshold, it means that the relay chain node has not queried the result of the legal primary gateway. The relay chain node will send a request to query the primary gateway for the identity ID to all consensus nodes in the relay chain network, and wait for the replies of each consensus node until all the replies of all consensus nodes are collected or the collection time threshold (such as 5s) is exceeded. After receiving the request to query the primary gateway from the relay chain node, each consensus node (relay chain node) will give a reply of the current legal primary gateway based on its local pierStatus structure. If there is a legal primary gateway, it will reply with the identity ID and unique mark of the current primary gateway of the relay chain node. If there is no legal primary gateway, it will reply that the relay chain node has no legal primary gateway.

[0074] After the relay chain node collects the replies from all consensus nodes, it sorts and selects the cross-chain gateway with the smallest unique identifier as the identity ID of the main gateway and replies the unique identifier to the requesting cross-chain gateway. Optionally, the cross-chain gateway with the largest unique identifier can also be sorted and selected as the identity ID of the main gateway and reply the unique identifier to the requesting cross-chain gateway. The comparison result between the unique identifiers is used as the criterion for selecting the main gateway, and the uniformity of the selection criteria during the entire cross-chain gateway switching process needs to be ensured. In the subsequent description of the present invention, the criterion for selecting the main gateway is the smallest unique identifier.

[0075] If all relay chain nodes (including the relay chain node itself) give a query result that there is no legitimate master gateway, then the requesting cross-chain gateway will be replied with no master gateway. In the specific implementation process, a preset constant identifier can be used to represent the masterless gateway. The constant identifier can be in the same form as the unique identifier to facilitate subsequent judgment and comparison. That is, when there is a master gateway, the identity ID and unique identifier are replied to the cross-chain gateway; when there is no master gateway, the identity ID and constant identifier are replied to the cross-chain gateway.

[0076] As a specific embodiment, the cross-chain gateway receives a reply from the relay chain node asking for the master gateway, including the identity ID and unique identifier of the current master gateway. If there is no master gateway at present, the identity ID and constant identifier are received; the cross-chain gateway performs different processing according to the received reply content. The processing process includes the cross-chain gateway making a request to set the master gateway and the cross-chain gateway entering the slave gateway mode.

[0077] Optionally, the judgment of the cross-chain gateway entering the slave gateway mode includes:

[0078] The relay chain node replies to the cross-chain gateway with the unique identifier of the current main gateway, and the unique identifier of the cross-chain gateway does not meet the main gateway switching conditions compared with the unique identifier of the current main gateway.

[0079] Specifically, the cross-chain gateway receives the identity ID and unique identifier of the current master gateway from the relay chain node, compares the unique identifier of the current master gateway with its own unique identifier, and enters slave gateway mode when the unique identifier of the current master gateway is smaller than its own unique identifier. When the smallest unique identifier is used as the criterion for selecting the master gateway, the master gateway switching condition is that the unique identifier of the cross-chain gateway is smaller than the unique identifier of the current master gateway, or there is no master gateway at present.

[0080] Optionally, the cross-chain gateway's judgment on setting the main gateway request includes:

[0081] The relay chain node replies to the cross-chain gateway that there is no master gateway; or

[0082] The relay chain node replies to the cross-chain gateway with the unique identifier of the current main gateway, and the unique identifier of the cross-chain gateway meets the main gateway switching condition compared with the unique identifier of the current main gateway.

[0083] Specifically, in the first case, when the cross-chain gateway receives a reply from the relay chain node that there is currently no master gateway, it performs the process of setting the master gateway request; the cross-chain gateway sends a request to set the master gateway to the relay chain node directly connected to it through the integrated relay chain client, requesting to set itself as the master gateway. The request includes the application chain identity ID of the cross-chain gateway responsible for communication, the unique identifier of the cross-chain gateway itself, and the gateway switching time threshold of the cross-chain gateway; wait for the relay chain node to reply to set the master gateway.

[0084] In the second case, the cross-chain gateway receives the unique identifier of the current main gateway from the relay chain node, compares the unique identifier of the current main gateway with its own unique identifier, and when its own unique identifier is less than the unique identifier of the current main gateway, the cross-chain gateway performs the request process to set the main gateway; the cross-chain gateway sends a request to set the main gateway to the relay chain node directly connected to it through the integrated relay chain client, requesting to set itself as the main gateway. The request includes the application chain identity ID of the cross-chain gateway responsible for communication, the unique identifier of the cross-chain gateway itself, and the gateway switching time threshold of the cross-chain gateway; wait for the relay chain node to reply to set the main gateway.

[0085] It should be noted that the gateway switching time threshold carried by the cross-chain gateway when setting the master gateway request indicates how long the relay chain node has not received the heartbeat information given by the cross-chain gateway as the master gateway before it considers itself to be faulty and allows the master gateway switch of other gateways. The gateway switching time threshold needs to work in conjunction with the heartbeat mechanism of the cross-chain gateway.

[0086] As a specific embodiment, after receiving the request for setting the main gateway from the cross-chain gateway, the relay chain node sets the main gateway reply, including:

[0087] The cross-chain gateway sets the main gateway request including the identity ID and unique identifier;

[0088] If the relay chain node finds that there is no master gateway under the corresponding identity ID in the local query, or the unique identifier of the current master gateway meets the master gateway switching conditions compared with the unique identifier of the requested cross-chain gateway, the requested cross-chain gateway will be updated to the current master gateway;

[0089] Otherwise, the relay chain node does not update the current main gateway;

[0090] Reply to the unique identifier of the current primary gateway.

[0091] Specifically, after receiving the cross-chain gateway's request to set the main gateway, the relay chain node first queries the local pierStatus structure to see if there is a main gateway corresponding to the identity ID. When the relay chain node does not query the main gateway corresponding to the identity ID, it means that there is no main gateway at present (when the main gateway corresponding to the identity ID is queried, but the main gateway is illegal, it is also considered that the main gateway corresponding to the identity ID is not queried), then the cross-chain gateway making the request can be set as the main gateway, and the corresponding identity ID and unique identifier can be updated to the local pierStatus.

[0092] If the relay chain node finds the main gateway corresponding to the identity ID in the local pierStatus structure, the unique identifier of the main gateway is compared with the unique identifier of the cross-chain gateway. When the unique identifier of the cross-chain gateway is less than the unique identifier of the main gateway, the cross-chain gateway making the request can be set as the main gateway, and the corresponding identity ID and unique identifier are updated to the local pierStatus. When the unique identifier of the cross-chain gateway is greater than or equal to the unique identifier of the main gateway, it is considered that the main gateway switching condition is not met, and the information in pierStatus is not updated.

[0093] After the relay chain node completes the query and update of the main gateway, it replies the identity ID and unique identifier of the current main gateway to the cross-chain gateway that made the request.

[0094] It is worth noting that since a relay chain node may be connected to multiple cross-chain gateways, it will receive multiple cross-chain gateways simultaneously sent requests to set the main gateway. In this case, it is possible that multiple cross-chain gateways meet the main gateway switching conditions (that is, when there is no main gateway, multiple cross-chain gateways simultaneously request to set the main gateway; or when there is a main gateway, the unique identifiers of multiple cross-chain gateways are smaller than the unique identifier of the current main gateway). At this time, according to the selection criteria of the main gateway, the one with the smallest unique identifier among the multiple cross-chain gateways making requests is selected as the main gateway, and the corresponding identity ID and unique identifier are updated to the local pierStatus.

[0095] Furthermore, after receiving the master gateway setting reply from the relay chain node, the cross-chain gateway chooses to enter the master gateway mode or the slave gateway mode according to the reply content.

[0096] Specifically, when the cross-chain gateway receives a reply to set the master gateway, if the unique identifier of the current master gateway in the reply is its own unique identifier, the cross-chain gateway enters the master gateway mode; if the unique identifier of the current master gateway in the reply is not its own unique identifier, the cross-chain gateway enters the slave gateway mode or continues to remain in the slave gateway mode.

[0097] It is worth noting that after the cross-chain gateway enters the process of setting the master gateway, regardless of whether it is elected as the master gateway from the perspective of the relay chain node, the cross-chain gateway can enter the master gateway mode by itself. The effect that can be achieved by this processing method is that at any time in the system, there is at least one cross-chain gateway that plays the role of the master gateway. If a cross-chain gateway mistakenly thinks that it is the master gateway in the future, the cross-chain gateway will discover the problem in the heartbeat mechanism and automatically downgrade to the slave gateway mode.

[0098] As a specific embodiment, when the master gateway and the slave gateway send heartbeat information to the relay chain nodes directly connected to themselves, they are divided into two categories: master network heartbeat information and slave network heartbeat information.

[0099] If the cross-chain gateway is the master gateway, the cross-chain gateway will actively initiate a Heartbeat message (heartbeat protocol message) to send a heartbeat message to the relay chain node to notify that it is still alive; if the heartbeat message reply indicates that it should not be the current master gateway, the cross-chain gateway will actively exit the master gateway mode and enter the slave gateway mode.

[0100] If the cross-chain gateway is a slave gateway, it will actively initiate a request to inquire about the master gateway when sending heartbeat information to the relay chain node. If the slave gateway detects that the relay chain node’s reply at a certain moment indicates that it should become the master gateway, it will actively make a request for the master gateway election.

[0101] Furthermore, after receiving the heartbeat information from the cross-chain gateway, the relay chain node responds to the heartbeat information based on the reply information from the consensus node, including:

[0102] The relay chain node sends a query request to the consensus node for the master gateway. Based on the legitimate master gateway reply of the consensus node, the current master gateway is determined and the identity ID and unique identifier are replied.

[0103] When all relay chain nodes indicate that there is no legitimate master gateway, they reply that there is no master gateway.

[0104] Specifically, the relay chain node will send a query to the main gateway for the identity ID to all consensus nodes in the relay chain network, and wait for the responses from each consensus node until all the consensus nodes have responded or the collection time threshold (for example, 5s) is exceeded.

[0105] After receiving the request from the relay chain node to inquire about the main gateway, each consensus node (relay chain node) responds to the current legal main gateway based on its local pierStatus structure. If there is a legal main gateway, it replies with the identity ID and unique mark of the current main gateway of the relay chain node. If there is no legal main gateway, it replies that the relay chain node has no legal main gateway.

[0106] The legitimacy judgment process of the main gateway includes: after the relay chain node determines the main gateway, it caches the timestamp of the main gateway's most recent heartbeat message; compares the difference between the timestamp of the main gateway's most recent heartbeat message and the current timestamp to see if it exceeds the gateway switching duration threshold; if so, the main gateway is not legal.

[0107] After the relay chain node collects the replies from all consensus nodes, it sorts and selects the cross-chain gateway with the smallest unique identifier as the identity ID of the main gateway and replies the unique identifier to the requesting cross-chain gateway. Optionally, the cross-chain gateway with the largest unique identifier can also be sorted and selected as the identity ID of the main gateway and reply the unique identifier to the requesting cross-chain gateway. The comparison result between the unique identifiers is used as the criterion for selecting the main gateway, and the uniformity of the selection criteria during the entire cross-chain gateway switching process needs to be ensured. In the subsequent description of the present invention, the criterion for selecting the main gateway is the smallest unique identifier.

[0108] If all relay chain nodes (including the relay chain node itself) give a query result that there is no legitimate master gateway, the requested cross-chain gateway will be replied with no master gateway.

[0109] Furthermore, the conditions for the master gateway to enter the slave gateway mode are:

[0110] The heartbeat message replies that there is no master gateway, or the unique identifier of the current master gateway in the heartbeat message reply is different from its own unique identifier; in other cases, the master gateway still maintains the master gateway mode.

[0111] The condition for a slave gateway to run for master gateway is: the heartbeat message replies that there is no master gateway; in other cases, the slave gateway remains in slave gateway mode.

[0112] It is worth noting that based on the cross-chain gateway redundant switching method of the present invention, all relay chain nodes will theoretically share a master gateway instance information table, because in the relay chain network, the failure of less than a certain number of relay chain nodes is within the fault tolerance range. Therefore, there is a very likely scenario: cross-chain gateways A and B are connected to relay chain nodes X and Y respectively, where cross-chain gateway A serves as the master gateway; and there is a problem in the network between X and Y and they are not interoperable. At this time, although the relay chain node Y cannot directly obtain the normal information of the cross-chain gateway A from the relay chain node X every time from the heartbeat information of the cross-chain gateway B, the timestamp of the last heartbeat information sent by the cross-chain gateway A can still be obtained from other relay chain nodes such as M and N (assuming that the relay chain is a 4-node cluster), that is, it can be determined that there is a legitimate master gateway A in the system, and the cross-chain gateway B should continue to run as a slave gateway. In this way, when the relay chain node that currently initiates the inquiry cannot connect to the relay chain node directly connected to the master gateway, the correctness of the master gateway election process and the acquisition of the master gateway information in the heartbeat mechanism can still be guaranteed.

[0113] In addition to a cross-chain gateway redundant switching method based on a relay chain, the present invention also provides Figure 3 A cross-chain gateway redundant switching system based on a relay chain is shown, comprising an application chain connected to the relay chain via a plurality of cross-chain gateways;

[0114] Any two relay chain nodes in the relay chain communicate with each other;

[0115] Several cross-chain gateways connect different relay chain nodes;

[0116] The cross-chain gateway sets its own unique identifier and the identity ID of the application chain responsible for communication, and sends a master gateway election request or heartbeat information to the relay chain node directly connected to it;

[0117] The relay chain node caches the unique identifier of the master gateway corresponding to the identity ID and the timestamp of the most recent heartbeat message sent by the master gateway, and responds to the cross-chain gateway for the master gateway election or heartbeat message.

[0118] It should be noted that from the deployment architecture, when an application chain is connected to the cross-chain system, N cross-chain gateways (N is an integer greater than or equal to 2) are deployed between the application chain and the relay chain, and the N cross-chain gateways are mutually redundant. Based on the existing cross-chain model of the relay mode, there are two interaction modes between the gateway component and the application chain and the relay chain:

[0119] (1) Subscribe (polling and monitoring) new cross-chain messages related to itself that appear on the chain;

[0120] (2) Actively send transactions to the target chain (application chain or relay chain);

[0121] From the perspective of protocol clarity, it is expected that only one cross-chain gateway will be selected as the main gateway at the same time among N cross-chain gateways to complete the interaction.

[0122] Based on the problem of selecting a master gateway from N cross-chain gateways, the present invention solves the problem of selecting a master gateway by introducing a coordinator, that is, each cross-chain gateway is scheduled by a coordinator to be a master gateway. However, after the introduction of the coordinator, it is necessary to consider that if the coordinator is a single-point process, then the coordinator will have a single point of failure, and the initial problem is not solved.

[0123] Therefore, the present invention defines the coordinator as all consensus nodes on the relay chain (consensus nodes are relay chain nodes), that is, all consensus nodes jointly negotiate a master gateway for a specific application chain, and the negotiation process is only a normal network message communication and does not exist as a relay chain transaction. In the case where all consensus nodes jointly negotiate a master gateway for a certain application chain, combined with the technical feature of connecting several cross-chain gateways to different relay chain nodes, the single point failure problem of all cross-chain gateways failing to work after a certain relay chain node fails can be avoided.

[0124] Specifically, Figure 3As shown in the figure, Gateway A, Gateway B, and Gateway C are three cross-chain gateways, all responsible for data interaction between application chain A and relay chain. Gateway A is connected to the first relay chain node, and Gateway B and Gateway C are connected to the second relay chain node. In the relay chain, the four relay chain nodes are connected to each other. At a certain moment, the four consensus nodes on the relay chain will negotiate a designated master gateway, and when the master gateway fails, they can automatically switch to other gateways as the master gateway.

[0125] It is worth noting that in the relay chain network, the relay chain nodes cannot be guaranteed to be connected at all times (when a certain number of relay chain nodes in the relay chain network fail, it can still operate normally), so there may be a situation where the relay chain node directly connected to the main gateway cannot communicate with some relay chain nodes. In the present invention, a communication connection is established between any two relay chain nodes to address this problem. Even if a relay chain node cannot directly communicate with the relay chain node directly connected to the main gateway, the relay chain node can also obtain the information of the main gateway through other indirect communication with the relay chain node (the relay chain node can communicate with the relay chain node between the main gateway).

[0126] In the relay chain cross-chain system, the main reason affecting the system's working stability and reliability is that network communication delays cause the order of data sent from different cross-chain gateways to different relay chain nodes to be disordered or the cross-chain gateway or relay chain node fails.

[0127] Embodiment 1: Due to network communication delay, the order of requests sent by different cross-chain gateways to different relay chain nodes becomes chaotic, causing multiple cross-chain gateways to start working in master gateway mode.

[0128] The unique identifier of cross-chain gateway A is "wangguan01", which is connected to relay chain node A; the unique identifier of cross-chain gateway B is "wangguan02", which is connected to relay chain node B; when comparing unique identifiers, "wangguan01" is smaller than "wangguan02". When cross-chain gateways A and B initiate master gateway election requests at the same time, relay chain node B first receives the master gateway election request of cross-chain gateway B due to communication delay. At this time, relay chain node B first receives the master gateway inquiry request of cross-chain gateway B based on the situation of no master gateway, then relay chain node B will start working with cross-chain gateway B as the master gateway.

[0129] Then relay chain node A receives the master gateway election request from cross-chain gateway A. At this time, when relay chain node A asks each relay chain node (consensus node) whether there is a master gateway, relay chain node B will return the unique identifier "wangguan02". After comparison, relay chain node A finds that the unique identifier of cross-chain gateway A is smaller, so the actual master gateway should be cross-chain gateway A. At this time, relay chain node A will identify cross-chain gateway A as the master gateway, and update its unique identifier "wangguan01" to its own pierStatus, and cross-chain gateway A starts to work as the master gateway.

[0130] When cross-chain gateway A and cross-chain gateway B are alive, they will both initiate heartbeat messages as the master gateway. For cross-chain gateway A, after relay chain node A receives the Heartbeat message, it will poll all relay chain nodes to confirm that the unique identifier "wangguan01" is the smallest, as the unique identifier of the current master gateway, and reply to cross-chain gateway A with the unique identifier. Cross-chain gateway A can confirm that it is the master gateway through the received reply and continue to operate in master gateway mode; similarly, for cross-chain gateway B, after relay chain node B receives the Heartbeat message, it can finally confirm that the current master gateway is the unique identifier of cross-chain gateway A through communication with each relay chain node. If the unique identifier of cross-chain gateway B in the received reply is different from its own, it will exit the master gateway mode and downgrade to slave gateway mode.

[0131] In the whole process, considering the uncertainty of the order of network messages, it is inevitable that two cross-chain gateways will run as the main gateway at the same time for a short period of time. However, because the cross-chain protocol between the upper-level cross-chain gateway and the relay chain is designed with a business layer correctness assurance protocol that strictly preserves the order between cross-chain transactions, this short-term extreme scenario will not affect the correctness of the cross-chain system, and the situation where multiple cross-chain gateways act as the main gateway for a long time can be solved by the method of the present invention, thereby ensuring the stable and reliable operation of the system.

[0132] Embodiment 2: During normal operation, if the main gateway suddenly fails and the unique identifiers of other cross-chain gateways are greater than the unique identifier of the main gateway, the main gateway election of the slave gateway is carried out to switch to a new main gateway to continue working.

[0133] The same application chain is equipped with three cross-chain gateways, each with a unique identifier of A, B, and C, arranged in ascending order; the relay chain nodes directly connected to the three cross-chain gateways are X, Y, and Z. Cross-chain gateway A is currently providing services to the outside world as the main gateway, and cross-chain gateways B and C are running as slave gateways. At a certain moment, the cross-chain gateway A process crashes, and at this time, the relay chain node X still caches cross-chain gateway A as the main gateway, and the timestamp of the last heartbeat information sent by cross-chain gateway A is 1000; the gateway switching duration threshold is set to 500, and the current timestamp is 1400.

[0134] At this time, cross-chain gateways B and C respectively initiate a request to inquire about the main gateway. After inquiring all relay chain nodes, relay chain nodes Y and Z will give a reply that the main gateway is cross-chain gateway A. Because cross-chain gateway A is down, there is no available main gateway in the system at this time; when the system time becomes 1600, cross-chain gateways B and C will initiate a request to inquire about the main gateway again. When replying to Y and Z, relay chain node X will first compare the difference between the timestamp of the most recent heartbeat information sent by cross-chain gateway A and the current system timestamp, which is 600, which is greater than the preset gateway switching time threshold. Therefore, it will reply to Y and Z that there is no main gateway. At this time, after receiving the reply from the masterless gateway, cross-chain gateways B and C will enter the main gateway election process, and finally select a cross-chain gateway as the main gateway to work (in this embodiment, due to the size relationship of the unique identifier, the main gateway must be cross-chain gateway B). In this embodiment, the system can still eventually have a new main gateway to replace the failed main gateway to continue working, so as to maintain the stability and reliability of the system.

[0135] Example 3: When the relay chain nodes cannot communicate normally, there is still only one main gateway in the system that can provide normal services. The relay chain cluster is a 4-node cluster (the 4 nodes are: A, B, C, D). The unique identifier of the cross-chain gateway X is "wangguan01", which connects to the relay chain node A; the unique identifier of the cross-chain gateway Y is "wangguan02", which connects to the relay chain node B; the relay chain node A and the relay chain node B cannot be connected for a period of time.

[0136] In the first case, relay chain node A can be connected to relay chain nodes C and D, and relay chain node B can be connected to relay chain nodes C and D. At this time, the relay chain cluster still meets the network assumption that "there are quorum (quorum is the honest majority, corresponding to the number of nodes) honest nodes connected at the same time", and the relay chain system can continue to work, that is, the cross-chain system can operate normally. In this case, cross-chain gateway X and cross-chain gateway Y will actively initiate the main gateway election process. When relay chain node A directly connected to cross-chain gateway X asks other relay chain nodes, relay chain node B cannot give an effective reply, and C and D will give a reply of "the main gateway is gateway Y" or "no main gateway" (both cases will result in cross-chain gateway X becoming the main gateway). At this time, relay chain node A will set the main gateway to cross-chain gateway X. At the same time, when relay chain node B processes the master gateway application of cross-chain gateway Y, although relay chain node B cannot directly obtain the message "the master gateway is cross-chain gateway X" through relay chain node A, because relay chain node A can be connected to C and D, and every time relay chain node A receives a "query master gateway" message or a heartbeat message, it will communicate to all normally connected relay chain nodes, and the relay chain nodes that receive the message will calculate the master gateway information locally; therefore, relay chain nodes C and D can both give the conclusion that the master gateway is cross-chain gateway X at this time, then relay chain node B can get the message that the master gateway is cross-chain gateway X from relay chain nodes C and D, and reply to cross-chain gateway Y, and cross-chain gateway Y will enter the slave gateway mode accordingly.

[0137] In the second case, relay chain node A is only normally connected to relay chain node C, and relay chain node B is still connected to both relay chain nodes C and D. At this time, the relay chain cluster still meets the network assumption that "there are quorum honest nodes connected at the same time", and the relay chain system can continue to work, that is, the cross-chain system can operate normally. The overall specific process is basically the same as the first case. Relay chain node B can obtain the conclusion that cross-chain gateway X is the main gateway from relay chain node C, so cross-chain gateway Y can still obtain the conclusion that cross-chain gateway X is the main gateway from relay chain node B.

[0138] In the third case, relay chain nodes A are not connected to B, C, and D. At this time, although relay chain node A will locally think that the main gateway is cross-chain gateway X, because relay chain node A cannot communicate with relay chain nodes B, C, and D, the main gateway information cannot be delivered to any relay chain node, that is, relay chain nodes B, C, and D will all think that the main gateway is cross-chain gateway Y. At the same time, the message received by relay chain node A from the gateway cannot be broadcast to the quorum cluster of the relay chain. Therefore, cross-chain gateway Y can still operate normally. That is, although there are two main gateways at this time, one of the main gateways X is completely separated from the quorum nodes that normally provide services on the relay chain. From the analysis of practical runtime, it still does not destroy the setting of "ultimately there is only one main gateway that provides normal services" and can operate normally.

[0139] There is no need to analyze the situation in this embodiment where relay chain nodes A and C are connectable, and relay chain nodes B and D are connectable. At this time, a brain split occurs in the relay chain cluster, and the relay chain cannot continue to work, that is, the cross-chain system cannot work normally, and it is meaningless to analyze the correctness of the gateway service.

[0140] The present invention connects the application chain and the relay chain through a redundant setting of multiple cross-chain gateways. When a cross-chain gateway fails, it can switch to other cross-chain gateways to continue to maintain the cross-chain process, avoiding the impact of the cross-chain gateway failure on the stability and reliability of the entire relay cross-chain system. After the cross-chain gateway is redundantly set, multiple cross-chain gateways are connected to different relay chain nodes in the relay chain. Even if a relay chain node fails, it does not affect the work between other relay chain nodes and the cross-chain gateway. The master gateway and slave gateway are set up through the master gateway election, so that there is at least one cross-chain gateway in the system at any time to assume the function of the master gateway; at the same time, the heartbeat mechanism is set up so that the slave gateway can automatically set the master gateway process in the absence of the master gateway, avoiding the single point failure problem of the cross-chain gateway. It can also correct the situation when multiple cross-chain gateways mistakenly think they are the master gateway and only retain one master gateway; fundamentally solve the single point failure problem in the relay cross-chain mode, ensure that the blockchain system of the medical institution can be continuously and stably connected to the relay cross-chain system, ensure the effective intercommunication of medical resource data and the continuity of business collaboration, and meet the extremely high reliability and real-time requirements in the medical field.

[0141] The above embodiments are further elaborations and illustrations of the present invention for ease of understanding, and are not limitations of the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A cross-chain gateway redundancy switching method based on relay chain, characterized in that: include: The relay chain is connected to the application chain through several cross-chain gateways; any two relay chain nodes are connected in communication and share the main gateway information; The plurality of cross-chain gateways send master gateway election requests to the relay chain nodes directly connected to them, and determine the master gateway and the slave gateway based on the master gateway election replies of the relay chain nodes; The master gateway and slave gateway send heartbeat information to the relay chain nodes directly connected to them, and the relay chain nodes reply with heartbeat information based on the reply information of the consensus node; The relay chain node sends a request to the consensus node to inquire about the master gateway. Based on the legitimate master gateway reply of the consensus node, the current master gateway is determined according to the master gateway selection criteria and the identity ID and unique identifier are replied. When all relay chain nodes indicate that there is no legitimate master gateway, they reply that there is no master gateway; The master gateway maintains the master gateway mode or enters the slave gateway mode based on the heartbeat message reply; The heartbeat message replies to the masterless gateway, or The unique identifier of the current master gateway is different from its own unique identifier, and it enters the slave gateway mode; The slave gateway maintains the slave gateway mode or conducts the master gateway election based on the heartbeat message reply.

2. According to a relay chain-based cross-chain gateway redundancy switching method according to claim 1, it is characterized in that: The process of the main gateway election among the multiple cross-chain gateways includes: Each cross-chain gateway sets its own unique identifier and the identity ID of the application chain responsible for communication; Send a query request to the relay chain node directly connected to itself, including the identity ID; The relay chain node asks the main gateway for a reply, including the identity ID and unique identifier of the current main gateway; The cross-chain gateway sets the master gateway request or enters the slave gateway mode according to the reply from the master gateway.

3. According to a relay chain-based cross-chain gateway redundancy switching method according to claim 2, it is characterized in that: The relay chain node inquires the main gateway and the reply includes: When the relay chain node queries the master gateway corresponding to the identity ID locally and the master gateway is legitimate, it replies with the identity ID and unique identifier of the current master gateway; Otherwise, the relay chain node sends a query request to the consensus node for the master gateway. Based on the legitimate master gateway reply of the consensus node, the current master gateway is determined and the identity ID and unique identifier are replied. When all relay chain nodes indicate that there is no legitimate master gateway, they reply that there is no master gateway.

4. A cross-chain gateway redundancy switching method based on a relay chain according to claim 2 or 3, characterized in that: The judgment of the cross-chain gateway entering the slave gateway mode includes: The relay chain node replies to the cross-chain gateway with the unique identifier of the current main gateway, and the unique identifier of the cross-chain gateway does not meet the main gateway switching conditions compared with the unique identifier of the current main gateway.

5. According to a relay chain-based cross-chain gateway redundancy switching method according to claim 4, it is characterized in that: The cross-chain gateway determines the request to set the main gateway including: The relay chain node replies to the cross-chain gateway that there is no master gateway; or The relay chain node replies to the cross-chain gateway with the unique identifier of the current main gateway, and the unique identifier of the cross-chain gateway meets the main gateway switching condition compared with the unique identifier of the current main gateway.

6. A cross-chain gateway redundancy switching method based on relay chain according to claim 2 or 5, characterized in that: The relay chain node sets the main gateway reply including: The cross-chain gateway sets the main gateway request including the identity ID and unique identifier; If the relay chain node finds that there is no master gateway under the corresponding identity ID in the local query, or the unique identifier of the current master gateway meets the master gateway switching conditions compared with the unique identifier of the requested cross-chain gateway, the requested cross-chain gateway will be updated to the current master gateway; Otherwise, the relay chain node does not update the current main gateway; Reply to the unique identifier of the current primary gateway.

7. According to a relay chain-based cross-chain gateway redundancy switching method according to claim 1, it is characterized in that: The condition for a slave gateway to run for master gateway is that the heartbeat message replies that there is no master gateway.

8. According to a relay chain-based cross-chain gateway redundancy switching method according to claim 3, it is characterized in that: The legitimacy judgment process of the main gateway includes: After the relay chain node determines the primary gateway, it caches the timestamp of the most recent heartbeat information sent by the primary gateway; Compare the difference between the timestamp of the most recent heartbeat message sent by the main gateway and the current timestamp to see if it exceeds the gateway switching duration threshold; if so, the main gateway is illegal.

9. A cross-chain gateway redundancy switching system based on a relay chain, applicable to the cross-chain gateway redundancy switching method according to any one of claims 1 to 8, characterized in that: Including application chains connected to the relay chain through several cross-chain gateways; Any two relay chain nodes in the relay chain communicate with each other and share the main gateway information; The cross-chain gateway sets its own unique identifier and the identity ID of the application chain responsible for communication, and sends a master gateway election request or heartbeat information to the relay chain node directly connected to it; The relay chain node caches the unique identifier of the master gateway corresponding to the identity ID and the timestamp of the most recent heartbeat message sent by the master gateway, and responds to the cross-chain gateway for the master gateway election or heartbeat message.

Citation Information

Patent Citations

  • Cross-chain gateway determination method and system for block chain, and terminal device

    CN112636987A

  • Relay chain cross-chain architecture-oriented access control and resource access control method and system

    CN113572825A