A Cross-chain Transaction Processing Method, Device, Computing Device, and Medium
Through relay chain management of cross-chain transaction status tables, cross-chain transactions are analyzed and constructed, the problem of insufficient atomicity of cross-chain transactions in the existing technology is solved, and the atomicity and process simplification of cross-chain transactions are achieved.
Patent Information
- Application Number
- CN202111590196.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-23
- Publication Date
- 2025-07-18
- Estimated Expiration
- 2041-12-23
AI Technical Summary
The existing cross-chain transaction processing mechanism has limitations in ensuring the atomicity of cross-chain transactions, and the application scenarios of the hash time lock mechanism are limited. The two-stage mechanism based on the relay chain requires the freezing of assets and involves two chain-turning operations.
The cross-chain transaction status table is initialized through the relay chain, the transaction destination chain is parsed, the cross-chain transaction is constructed and sent, the execution results are received and updated, and the cross-chain process is simplified to ensure atomicity. It only needs to be linked to the destination chain once.
It realizes the atomicity of cross-chain transactions, simplifies the cross-chain process, ensures the consistency of cross-chain transaction processing results of the source chain and the destination chain, and reduces the number of transactions.
Smart Images

Figure CN114217911B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of blockchain technology, and particularly relates to a cross-chain transaction processing method, apparatus, computing device, and medium. Background Art
[0002] Cross-chain means achieving trusted interoperability between different blockchains. The atomicity of a cross-chain transaction means that either both the source chain and the destination chain of the cross-chain transaction are successfully executed, or both fail. If the execution fails, it needs to be restored to the unexecuted state.
[0003] Existing cross-chain transaction processing mechanisms are roughly divided into two types: the hash time-locked mechanism (Hash Time Locked Contract, abbreviated as HTLC), and the two-phase mechanism based on a relay chain. The hash time-locked mechanism is a decentralized cross-chain atomic exchange protocol that does not require a trusted third-party intermediary. However, the application scenario of the hash locking mechanism is very limited, only used for asset exchange, and has a strict time clock limit. If one party cannot process the cross-chain transaction within the clock limit due to network, device, etc. issues, the atomicity of the cross-chain transaction cannot be fully guaranteed. The two-phase mechanism based on the relay chain needs to freeze the relevant assets of the source chain and the destination chain in advance, and execute or roll back according to the transaction processing result returned by the relay chain. But this method requires two transactions to be uploaded to the destination chain. Summary of the Invention
[0004] In view of this, the embodiments of this application provide a cross-chain transaction processing method, apparatus, computing device, and medium, which are used to ensure the atomicity in the cross-chain transaction processing process and simplify the cross-chain process of the destination chain.
[0005] The first aspect of the embodiments of this application provides a cross-chain transaction processing method, which is applied to a relay chain. The method includes:
[0006] When receiving a first cross-chain transaction initiated by a source chain, initialize the transaction status table of the first cross-chain transaction. The first cross-chain transaction has a corresponding cross-chain transaction;
[0007] Parse the first cross-chain transaction to determine the destination chain of the first cross-chain transaction;
[0008] If the source chain and the destination chain are registered in the relay chain, construct a second cross-chain transaction according to the first cross-chain transaction and the transaction status table;
[0009] Send the second cross-chain transaction to the destination chain;
[0010] Receive a third cross-chain transaction returned by the destination chain according to the second cross-chain transaction. The third cross-chain transaction includes the execution result of the cross-chain transaction by the destination chain;
[0011] Update the transaction status table according to the execution result;
[0012] Construct a fourth cross-chain transaction according to the third cross-chain transaction and the updated transaction status table, where the fourth cross-chain transaction includes the execution result and the transaction status of the cross-chain transaction;
[0013] Return the fourth cross-chain transaction to the source chain for the source chain to process the cross-chain transaction according to the execution result and the transaction status.
[0014] The second aspect of the embodiments of the present application provides a cross-chain transaction processing device applied to a relay chain. The device includes:
[0015] A transaction status table initialization module, configured to initialize the transaction status table of the first cross-chain transaction when receiving the first cross-chain transaction initiated by the source chain, where the first cross-chain transaction has a corresponding cross-chain transaction;
[0016] A destination chain determination module, configured to parse the first cross-chain transaction to determine the destination chain of the first cross-chain transaction;
[0017] A second cross-chain transaction construction module, configured to construct a second cross-chain transaction according to the first cross-chain transaction and the transaction status table if the source chain and the destination chain are registered in the relay chain;
[0018] A second cross-chain transaction sending module, configured to send the second cross-chain transaction to the destination chain;
[0019] A third cross-chain transaction receiving module, configured to receive the third cross-chain transaction returned by the destination chain according to the second cross-chain transaction, where the third cross-chain transaction includes the execution result of the destination chain for the cross-chain transaction;
[0020] A transaction status table update module, configured to update the transaction status table according to the execution result;
[0021] A fourth cross-chain transaction construction module, configured to construct a fourth cross-chain transaction according to the third cross-chain transaction and the updated transaction status table, where the fourth cross-chain transaction includes the execution result and the transaction status of the cross-chain transaction;
[0022] A fourth cross-chain transaction sending module, configured to return the fourth cross-chain transaction to the source chain for the source chain to process the cross-chain transaction according to the execution result and the transaction status.
[0023] The third aspect of the embodiments of the present application provides a computing device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the method described in the first aspect above is implemented.
[0024] The fourth aspect of the embodiments of the present application provides a computer-readable storage medium storing a computer program, which when executed by a processor implements the method described in the first aspect above.
[0025] The fifth aspect of the embodiments of the present application provides a computer program product, which when running on a computing device causes the computing device to execute the method described in the first aspect above.
[0026] Compared with the prior art, the embodiments of the present application have the following advantages:
[0027] In the embodiments of the present application, cross-chain transactions between the source chain and the destination chain can be carried out through the relay chain. The source chain initiates a first cross-chain transaction, and the first cross-chain transaction has a corresponding cross-chain transaction; the source chain sends the first cross-chain transaction to the relay chain through the cross-chain gateway; after receiving the first cross-chain transaction, the relay chain initializes the transaction status table of the first cross-chain transaction, and the transaction status of the cross-chain transaction can be recorded in the relay chain using this transaction status table. The relay chain parses the first cross-chain transaction to determine the destination chain of the cross-chain transaction; if the destination chain is registered in the relay chain, a second cross-chain transaction can be constructed based on the first cross-chain transaction and the transaction status table, and then the second cross-chain transaction is sent to the destination chain through the cross-chain gateway. After receiving the second cross-chain transaction, the destination chain can execute the cross-chain transaction, and then return a third cross-chain transaction according to the execution result of the cross-chain transaction; after receiving the third cross-chain transaction, the relay chain can obtain the execution result of the cross-chain transaction according to the third cross-chain transaction, update the transaction status table according to the execution result, and then construct a fourth cross-chain transaction based on the updated transaction status table and the third cross-chain transaction, and send the fourth cross-chain transaction to the source chain through the cross-chain gateway. After receiving the fourth cross-chain transaction, the source chain can parse the fourth cross-chain transaction to determine the execution result of the cross-chain transaction, and the source chain updates the processing status of the cross-chain transaction according to the execution result. In the embodiments of the present application, in the destination chain, the relay chain, and the source chain, the execution results of cross-chain transactions can be kept unified, realizing the transaction atomicity of cross-chain transactions. At the same time, during the execution process of cross-chain transactions, only one on-chain operation is required in the destination chain, simplifying the cross-chain process of the destination chain. Description of the Drawings
[0028] To more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the accompanying drawings required for description in the embodiments or the prior art. Obviously, the accompanying drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0029] Figure 1 It is a schematic flowchart of the steps of a cross-chain transaction processing method provided by an embodiment of the present application;
[0030] Figure 2 It is a schematic diagram showing the successful execution of a cross-chain transaction provided by an embodiment of the present application;
[0031] Figure 3 It is a schematic diagram showing the failure of the execution of a cross-chain transaction provided by an embodiment of the present application;
[0032] Figure 4 It is a schematic diagram showing the failure of the execution of another cross-chain transaction provided by an embodiment of the present application;
[0033] Figure 5 It is a flowchart of another cross-chain transaction processing method provided by an embodiment of the present application;
[0034] Figure 6 It is a schematic diagram of a cross-chain transaction processing device provided by an embodiment of the present application;
[0035] Figure 7 It is a schematic diagram of a computing device provided by an embodiment of the present application. Detailed implementation manners
[0036] In the following description, specific details such as specific system architectures and technologies are presented for the purpose of illustration rather than limitation, so as to thoroughly understand the embodiments of the present application. However, those skilled in the art should clearly understand that the present application can also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid unnecessary details from interfering with the description of the present application.
[0037] It should be understood that when used in the specification of the present application and the appended claims, the term "comprising" indicates the presence of the described features, wholes, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components, and / or their combinations.
[0038] It should also be understood that the term "and / or" used in the specification of the present application and the appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0039] As used in the specification of this application and the appended claims, the term "if" may be construed, depending on the context, as "when", "once", "in response to determining", or "in response to detecting". Similarly, the phrase "if determined" or "if [the described condition or event] is detected" may be construed, depending on the context, to mean "once determined", "in response to determining", "once [the described condition or event] is detected", or "in response to detecting [the described condition or event]".
[0040] In addition, in the description of the specification of this application and the appended claims, the terms "first", "second", "third", etc. are used only for distinguishing descriptions and cannot be construed as indicating or implying relative importance.
[0041] Reference to "one embodiment" or "some embodiments" or the like described in the specification of this application means that a specific feature, structure, or characteristic described in connection with that embodiment is included in one or more embodiments of this application. Thus, statements such as "in one embodiment", "in some embodiments", "in other some embodiments", "in still other embodiments", etc. that appear in different places in this specification do not necessarily all refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "comprising", "including", "having", and their variants all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0042] The technical solution of this application will be described below through specific embodiments.
[0043] In the embodiments of this application, the source chain refers to the source blockchain that initiates a cross-chain transaction in a cross-chain transaction scenario. The destination chain refers to the destination blockchain that receives the cross-chain transaction in a cross-chain transaction scenario. The relay chain refers to the blockchain that is responsible for relaying the cross-chain transaction of the source chain to the destination chain in a cross-chain scenario.
[0044] Refer to Figure 1 , which shows a schematic flow chart of the steps of a cross-chain transaction processing method provided by an embodiment of this application, and specifically may include the following steps:
[0045] S101. When receiving a first cross-chain transaction initiated by the source chain, the relay chain initializes a transaction status table for the first cross-chain transaction, and the first cross-chain transaction has a corresponding cross-chain transaction.
[0046] The execution entity of this embodiment is the relay chain. In this embodiment, communication can be carried out between the source chain and the relay chain through a cross-chain gateway; communication can be carried out between the destination chain and the relay chain through a cross-chain gateway. To achieve trusted interoperability between different blockchains for cross-chain transactions, a third party with credibility can be relied on for cross-chain transactions. In this embodiment, the relay chain can be a public chain, serving as a third party to ensure that cross-chain transactions can be carried out between different application chains in a mutually trusted manner.
[0047] In the embodiment of the present application, both the source chain and the destination chain can deploy cross-chain smart contracts, and then the cross-chain smart contracts can be called to register on the relay chain.
[0048] When a cross-chain transaction needs to be processed, the source chain can generate a first cross-chain transaction according to the cross-chain transaction. The first cross-chain transaction can carry information such as the source chain address, destination chain address, cross-chain transaction information, and cross-chain related proof information. The source chain throws the first cross-chain transaction according to the deployed cross-chain smart contract. The cross-chain gateway can capture the first cross-chain transaction and construct the first cross-chain transaction into a cross-chain transaction in the format of the Inter Blockchain Transfer Protocol (IBTP), and then send the first cross-chain transaction to the relay chain. IBTP is a general message transmission protocol for cross-chain interaction.
[0049] After receiving the cross-chain transaction, the relay chain initializes the transaction status table. The transaction status table can include the previous transaction status and the current transaction status of the cross-chain transaction. The transaction status table can include a first status value and a second status value. The first status value is used to identify the previous transaction status of the cross-chain transaction, and the second status value is used to identify the current transaction status of the cross-chain transaction. When initializing, the first status value is updated to an initial value, and the initial value is used to indicate that the cross-chain transaction has not started to be processed; the second status value is updated to a start value, and the start value is used to indicate that the cross-chain transaction has started to be processed. For example: when initializing, record the previous transaction status as INIT and the current transaction status as BEGIN, and the transaction status table is: INIT-->BEGIN.
[0050] S102, The relay chain parses the first cross-chain transaction to determine the destination chain of the first cross-chain transaction.
[0051] Since the first cross-chain transaction includes the source chain address and the destination chain address, the relay chain can parse the first cross-chain transaction to determine the source chain and the destination chain of the cross-chain transaction.
[0052] S103, If the source chain and the destination chain are registered in the relay chain, the relay chain constructs a second cross-chain transaction according to the first cross-chain transaction and the transaction status table.
[0053] Specifically, if the destination chain or the source chain has been registered in the relay chain, the relay chain can find the corresponding registration information.
[0054] If the relay chain finds the registration information of the destination chain, it indicates that the destination chain has been registered in the relay chain, and the relay chain can process the cross-chain transaction. At this time, the relay chain can construct a second cross-chain transaction based on the first cross-chain transaction and the transaction status table. The second cross-chain transaction may include the source chain address, the destination chain address, the cross-chain transaction, the signature of the relay chain, and the status of the updated cross-chain transaction.
[0055] If the relay chain does not find the registration information of the destination chain, it indicates that the destination chain has not been registered in the relay chain. The relay chain cannot send the cross-chain transaction information to the destination chain and thus cannot process the cross-chain transaction. At this time, the transaction status table can be updated by updating the first status value to the start value, updating the second status value to the start failure value, then constructing a fifth cross-chain transaction based on the first cross-chain transaction and the updated transaction status table, and sending the fifth cross-chain transaction to the source chain. After receiving the fifth cross-chain transaction, the source chain can determine that the cross-chain transaction fails because the destination chain has not been registered in the relay chain, and the source chain can roll back the cross-chain transaction to restore the source chain to its previous state. For example, if the destination chain has not been registered in the relay chain, the transaction status table is updated as BEGIN-->BEGIN_FAILURE.
[0056] After the source chain finishes rolling back the cross-chain transaction, the source chain needs to return a receipt to the relay chain. After receiving the rollback receipt returned by the destination chain, the relay chain changes the transaction status of the cross-chain transaction from BEGIN_FAILURE to FAILURE. Thus, the cross-chain transaction processing is completed.
[0057] In a possible implementation, if the destination chain has not been registered in the relay chain, the relay chain can notify the destination chain and the source chain. When the destination chain completes registration, the cross-chain gateway of the destination chain will increment the index of the relay chain by 1. The index records the cross-chain transactions between the relay chain and the source chain, thus preventing the gateway from missing some transactions during forwarding due to network downtime or other reasons. However, because the transaction status is BEGIN_FAILURE, the first cross-chain transaction will still not be forwarded to the destination chain.
[0058] Of course, if the source chain has not been registered in the relay chain, the relay chain cannot perform the cross-chain transaction either. In a possible implementation, if the source chain is not registered in the relay chain, the relay chain can directly return an error to the cross-chain gateway of the source chain. The relay chain will not put the first cross-chain transaction on the chain, which can be equivalent to the non-existence of this cross-chain transaction.
[0059] S104. The relay chain sends the second cross-chain transaction to the destination chain.
[0060] Specifically, the relay chain can determine the cross-chain gateway of the destination chain according to the registration information of the destination chain; then the relay chain can send the second cross-chain transaction to the cross-chain gateway of the destination chain, and the cross-chain gateway of the destination chain will then send the second cross-chain transaction to the destination chain.
[0061] S105. The relay chain receives a third cross-chain transaction returned by the destination chain according to the second cross-chain transaction. The third cross-chain transaction includes the execution result of the cross-chain transaction on the destination chain.
[0062] Specifically, after receiving the second cross-chain transaction, the destination chain can parse the second cross-chain transaction to determine the cross-chain transaction corresponding to the second cross-chain transaction; then call relevant methods through the cross-chain smart contract to execute the cross-chain transaction and obtain the execution result of the cross-chain transaction. The execution result of the cross-chain transaction includes successful execution and failed execution. Successful execution can be RECEIPT_SUCCESS, and failed execution can be RECEIPT_FAILURE.
[0063] Based on the execution result, the destination chain can construct a third cross-chain transaction. Then, through the cross-chain gateway, the third cross-chain transaction is sent to the relay chain. After receiving the third cross-chain transaction, the relay chain can parse the third cross-chain transaction to obtain the execution result of the cross-chain transaction.
[0064] S106. The relay chain updates the transaction status table according to the execution result.
[0065] According to the execution result of the cross-chain transaction, the relay chain can update the transaction status table. Specifically, since the first status value is used to identify the previous processing status, the first status value can be set to the current second status value, and then the second status value is updated according to the execution result. If the execution result is failed execution, the second status value is updated to the failure value. If the execution result is successful execution, the second status value is updated to the success value.
[0066] For example, if the cross-chain transaction fails to execute, the transaction status is: BEGIN-->FAILURE; if the cross-chain transaction is successfully executed, the transaction status is BEGIN-->SUCCESS.
[0067] S107. The relay chain constructs a fourth cross-chain transaction according to the third cross-chain transaction and the updated transaction status table. The fourth cross-chain transaction includes the execution result and the transaction status of the cross-chain transaction.
[0068] The relay chain constructs a fourth cross-chain transaction according to the third cross-chain transaction and the updated transaction status. The fourth cross-chain transaction center can include the source chain address, the destination chain address, the cross-chain transaction, the signature of the relay chain, and the status of the updated cross-chain transaction.
[0069] Specifically, the transaction status of a cross-chain transaction can be sourced from the transaction status table. The transaction status can include: INIT --> BEGIN, BEGIN --> BEGIN_FAILURE, BEGIN --> FAILURE, BEGIN --> SUCCESS, BEGIN_FAILURE --> FAILURE. INIT --> BEGIN is used to indicate that the cross-chain transaction starts to be processed; BEGIN --> BEGIN_FAILURE is used to indicate that the cross-chain transaction cannot be sent to the destination chain; BEGIN --> FAILURE is used to indicate that the cross-chain transaction fails to execute on the destination chain; BEGIN --> SUCCESS is used to indicate that the cross-chain transaction executes successfully on the destination chain; BEGIN_FAILURE --> FAILURE is used to indicate that the cross-chain transaction is not sent to the destination chain and fails to execute, and the rollback on the source chain has been completed.
[0070] S108, the relay chain returns the fourth cross-chain transaction to the source chain for the source chain to process the cross-chain transaction according to the execution result and the transaction status.
[0071] The relay chain can determine the cross-chain gateway of the source chain based on the registration information of the source chain; then, through the cross-chain gateway of the source chain, send the fourth cross-chain transaction to the source chain.
[0072] After receiving the fourth cross-chain transaction, the source chain can parse the fourth cross-chain transaction to obtain the execution result of the cross-chain transaction. If the execution result is a failure, the source chain rolls back the cross-chain transaction. If the execution result is a success, the source chain completes the cross-chain transaction.
[0073] After the source chain rolls back the cross-chain transaction, it can also send a rollback receipt to the relay chain. After receiving the rollback receipt, the relay chain can update the transaction status table to BEGIN_FAILURE --> FAILURE, thereby determining that the cross-chain transaction has been completed and executed unsuccessfully.
[0074] At this time, the processing result of the cross-chain transaction in the destination chain is the same as that in the source chain, ensuring the atomicity in the process of cross-chain transaction processing.
[0075] In this embodiment, the transaction status table includes the previous transaction status and the current transaction status, and the information sent by the relay chain to the source chain and the destination chain includes the information in the transaction status table, enabling the source chain and the transaction chain to clearly know the processing status of the current transaction; in addition, when the cross-chain transaction fails to execute, the source chain can also determine whether it fails because the destination chain is not registered in the relay chain or because the destination chain fails to execute the transaction according to the previous transaction status and the current transaction status in the transaction status table.
[0076] This embodiment optimizes the two-phase mechanism based on the relay chain, selects the multi-chain transaction status table solution, and realizes the transaction management of cross-chain transactions through the built-in relay chain transaction management contract. In the cross-chain process, the two transactions on the destination chain are simplified into one, simplifying the on-chain process of the destination chain.
[0077] It should be noted that the sequence numbers of the steps in the above embodiments do not indicate the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.
[0078] A specific example is used to illustrate the method in this application. The background of this example is: the source chain is Chain A, and the destination chain is Chain B. The account Alice on Chain A wants to obtain the data dataB of Bob located on Chain B.
[0079] The execution process for the account Alice on Chain A to successfully obtain the data dataB of Bob located on Chain B can be Figure 2 as shown. Figure 2 It is a schematic diagram of a successful cross-chain transaction execution provided by an embodiment of the present application.
[0080] First, smart contracts for cross-chain need to be deployed on Chain A and Chain B. Denote the cross-chain smart contract on Chain A as SCa, and the cross-chain smart contract on Chain B as SCb.
[0081] Then, Chain A and Chain B can call the register method of the deployed cross-chain smart contract to register on the relay chain.
[0082] When the account Alice on Chain A wants to obtain the data dataB of Bob located on Chain B, Chain A constructs a transaction Tx1 according to this cross-chain transaction. Tx1 is a cross-chain transaction encapsulated by the cross-chain gateway into the cross-chain general IBTP network protocol format, and the content includes: cross-chain transaction type, source chain address, destination chain address, cross-chain related proof information, cross-chain transaction specific content, etc.
[0083] The relay chain receives the cross-chain transaction Tx1, initializes the transaction status table of Tx1 as INIT-->BEGIN, where INIT is the previous transaction status of the cross-chain transaction, and BEGIN is the current transaction status of the cross-chain transaction. Then it parses the cross-chain transaction Tx1 and checks whether Chain A and Chain B are registered on the relay chain.
[0084] If both Chain A and Chain B have been registered on the relay chain, the relay chain encapsulates the cross-chain transaction Tx2 and submits Tx2 to the destination chain.
[0085] The destination chain successfully executes a cross-chain transaction, and the returned content is dataB of chain B, with the type of RECEIPT_SUCCESS and the format of the cross-chain transaction Tx3 of the general network protocol IBTP. Then Tx3 is submitted to the relay chain.
[0086] The relay chain parses the received cross-chain transaction Tx3, updates the transaction status to BEGIN-->SUCCESS according to the RECEIPT_SUCCESS type of Tx3. Then it constructs a cross-chain transaction Tx4 and submits it to the source chain.
[0087] The source chain parses the received cross-chain transaction Tx4, finds that the transaction type is RECEIPT_SUCCESS and the transaction status is BEGIN-->SUCCESS, executes the transaction content, obtains the data dataB, and the cross-chain transaction operation is completed.
[0088] The execution process in which the account Alice on chain A cannot obtain the data dataB of Bob on chain B due to the failure of chain B to execute can be Figure 3 as shown. Figure 3 is a schematic diagram of the failure of a cross-chain transaction execution provided by an embodiment of the present application.
[0089] The execution process in which the account Alice on chain A successfully obtains the data dataB of Bob on chain B can be Figure 2 as shown. Figure 2 Figure 4 is a schematic diagram of the successful execution of a cross-chain transaction provided by an embodiment of the present application.
[0090] First, chain A and chain B need to deploy smart contracts for cross-chain. Denote the cross-chain smart contract of chain A as SCa and the cross-chain smart contract of chain B as SCb.
[0091] Then, chain A and chain B can call the register method of the deployed cross-chain smart contract to register on the relay chain.
[0092] When the account Alice on chain A wants to obtain the data dataB of Bob on chain B, chain A constructs a transaction Tx1 according to this cross-chain transaction. Tx1 is a cross-chain transaction encapsulated by the cross-chain gateway into the cross-chain general IBTP network protocol format, and the content includes: cross-chain transaction type, source chain address, destination chain address, cross-chain related proof information, cross-chain transaction specific content, etc.
[0093] The relay chain receives the cross-chain transaction Tx1, initializes the transaction status of Tx1 to INIT-->BEGIN, where INIT is the previous transaction status of the cross-chain transaction and BEGIN is the current transaction status of the cross-chain transaction. It parses the cross-chain transaction Tx1 and checks whether chain A and chain B are registered on the relay chain.
[0094] If both Chain A and Chain B have been registered on the relay chain, the relay chain encapsulates the cross-chain transaction Tx2 and submits it to the destination chain.
[0095] The execution of the cross-chain transaction on the destination chain fails because Bob does not have the data dataB. The returned content is empty, the type is RECEIPT_FAILURE, and the format is the cross-chain transaction Tx3 of the general network protocol IBTP. And Tx3 is submitted to the relay chain.
[0096] The relay chain parses the received cross-chain transaction Tx3, updates the transaction status to BEGIN-->FAILURE according to the RECEIPT_FAILURE type of Tx3. The relay chain constructs a cross-chain transaction Tx4 and submits it to the source chain.
[0097] The source chain parses the received cross-chain transaction Tx4, and finds that the type of the transaction is RECEIPT_SUCCESS and the transaction status is BEGIN-->FAILURE, indicating that the cross-chain transaction execution fails, and performs a cross-chain transaction rollback. The cross-chain transaction operation is completed.
[0098] The execution process in which the account Alice on Chain A cannot obtain the data dataB of Bob on Chain B due to Chain B not being registered on the relay chain can be Figure 4 as shown. Figure 4 It is a schematic diagram of another failure in the execution of a cross-chain transaction provided by an embodiment of the present application.
[0099] When the account Alice on Chain A wants to obtain the data dataB of Bob on Chain B, Chain A constructs a transaction Tx1 according to this cross-chain transaction. Tx1 is a cross-chain transaction encapsulated by the cross-chain gateway into the cross-chain general IBTP network protocol format, and the content includes: cross-chain transaction type, source chain address, destination chain address, cross-chain related proof information, specific content of the cross-chain transaction, etc.
[0100] The relay chain parses the cross-chain transaction Tx1, initializes the transaction status of Tx1 to INIT-->BEGIN, checks whether Chain A and Chain B are registered on the relay chain, and finds that Chain B is not registered, and updates the transaction status to BEGIN-->BEGIN_FAILURE. The relay chain transaction manager constructs a cross-chain transaction Tx2, the cross-chain transaction type is INTERCHAIN, and submits it to the source chain Chain A.
[0101] Chain A receives the cross-chain transaction Tx2. Since the received cross-chain transaction type is INTERCHAIN and the transaction status is BEGIN_FAILURE, it indicates that the cross-chain transaction execution has failed and this cross-chain transaction needs to be rolled back. The cross-chain transaction operation is completed. After the source chain finishes rolling back the cross-chain transaction, the source chain needs to return the receipt to the relay chain; after the relay chain receives the rollback receipt returned by the destination chain, it changes the transaction status of the cross-chain transaction from BEGIN_FAILURE to FAILURE. Thus, the cross-chain transaction processing is completed.
[0102] Figure 5 It is a flowchart of another cross-chain transaction processing method provided by an embodiment of this application. Refer to Figure 5 , the source chain and the destination chain deploy cross-chain contracts, and call relevant methods of the cross-chain contracts to register on the relay chain.
[0103] When a cross-chain transaction is carried out, the source chain initiates a cross-chain transaction. The cross-chain contract SC1 deployed by the source chain throws a cross-chain transaction according to the transaction request. The cross-chain gateway captures this cross-chain transaction and constructs it into the first cross-chain transaction Tx1 in the format of the public network protocol IBTP for transmission to the relay chain.
[0104] The relay chain receives the first cross-chain transaction Tx1, conducts transaction inspection, transaction packaging, and transaction execution. Before the transaction execution starts, it initializes the transaction status table. The transaction status table maintains the previous transaction status and the current transaction status. When initializing, it records the previous transaction status as INIT and the current transaction status as BEGIN.
[0105] After the first cross-chain transaction Tx1 is successfully chained on the relay chain, the relay chain checks the relevant information of the destination chain and updates the transaction status. If the destination chain is not registered on the relay chain, it enters step 5.1; if the destination chain is already registered, it enters step 5.2.
[0106] 5.1) The relay chain changes the cross-chain transaction status from BEGIN to BEGIN_FAILURE. The relay chain transaction manager will construct the fifth cross-chain transaction Tx2.1 and notify the source chain to roll back.
[0107] 5.2) The relay chain transaction manager constructs the second cross-chain transaction Tx2.2 according to the content of the first cross-chain transaction Tx1 and routes the second cross-chain transaction Tx2.2 to the destination chain through the cross-chain gateway. The second cross-chain transaction Tx2.2 includes the source chain address, the destination chain address, the cross-chain transaction, the signature of the relay chain, and the status of the updated cross-chain transaction.
[0108] After the destination chain receives the second cross-chain transaction Tx2.2, it parses the cross-chain transaction and invokes relevant methods through the cross-chain contract SC2 to execute the cross-chain transaction. The execution result of the cross-chain transaction is sent to the relay chain by constructing the third cross-chain transaction Tx3. The third cross-chain transaction Tx3 contains the execution result of the cross-chain transaction. The execution results of the cross-chain transaction are divided into two categories: RECEIPT_SUCCESS is returned for successful execution, and RECIPT_FAILURE is returned for failed execution.
[0109] The relay chain changes the transaction status according to whether the execution result of the received cross-chain transaction Tx3 is successful. A successful execution result updates the transaction status from BEGIN to SUCCESS, and a failed execution result updates the transaction status from BEGIN to FAILURE; constructs the fourth cross-chain transaction Tx4 based on the third cross-chain transaction Tx3 and forwards the fourth cross-chain transaction Tx4 to the source chain.
[0110] The source chain performs relevant operations according to the transaction status of the received fourth cross-chain transaction Tx4. The smart contract SC1 of the source chain invokes relevant methods to execute the cross-chain transaction. If a cross-chain receipt transaction is received and the transaction status of the transaction is SUCCESS, it indicates that the cross-chain transaction is executed normally. If a cross-chain receipt transaction is received and the transaction status of the transaction is FAILURE, it indicates that the cross-chain transaction execution fails and the cross-chain transaction needs to be rolled back. If a cross-chain transaction is received and the transaction status of the transaction is BEGIN_FAILURE, it indicates that the cross-chain transaction execution fails and the cross-chain transaction needs to be rolled back. After the source chain finishes rolling back the cross-chain transaction, the source chain needs to return the receipt to the relay chain; after the relay chain receives the rollback receipt returned by the destination chain, it changes the transaction status of the cross-chain transaction from BEGIN_FAILURE to FAILURE. Thus, a cross-chain transaction process ends, and this method ensures the atomicity of the cross-chain transaction.
[0111] Refer to Figure 6 , which shows a schematic diagram of a cross-chain transaction processing device according to an embodiment of the present application. Specifically, it may include a transaction status table initialization module 61, a destination chain determination module 62, a second cross-chain transaction construction module 63, a second cross-chain transaction sending module 64, a third cross-chain transaction receiving module 65, a transaction status table update module 66, a fourth cross-chain transaction construction module 67, and a fourth cross-chain transaction sending module 68, where:
[0112] The transaction status table initialization module 61 is used to initialize the transaction status table of the first cross-chain transaction when receiving the first cross-chain transaction initiated by the source chain, and the first cross-chain transaction has a corresponding cross-chain transaction;
[0113] The destination chain determination module 62 is used to parse the first cross-chain transaction and determine the destination chain of the first cross-chain transaction;
[0114] The second cross-chain transaction construction module 63 is used to construct a second cross-chain transaction according to the first cross-chain transaction and the transaction status table if the source chain and the destination chain are registered in the relay chain;
[0115] The second cross-chain transaction sending module 64 is used to send the second cross-chain transaction to the destination chain;
[0116] The third cross-chain transaction receiving module 65 is used to receive a third cross-chain transaction returned by the destination chain according to the second cross-chain transaction, and the third cross-chain transaction includes the execution result of the cross-chain transaction by the destination chain;
[0117] The transaction status table update module 66 is used to update the transaction status table according to the execution result;
[0118] The fourth cross-chain transaction construction module 67 is used to construct a fourth cross-chain transaction according to the third cross-chain transaction and the updated transaction status table, and the fourth cross-chain transaction includes the execution result and the transaction status of the cross-chain transaction;
[0119] The fourth cross-chain transaction sending module 68 is used to return the fourth cross-chain transaction to the source chain for the source chain to process the cross-chain transaction according to the execution result and the transaction status.
[0120] In a possible implementation manner, the above-mentioned transaction status table initialization module 61 includes:
[0121] The first initialization sub-module is used to update the first status value to an initial value, and the first status value is used to identify the previous transaction status of the cross-chain transaction;
[0122] The second initialization sub-module is used to update the second status value to a start value, and the second status value is used to identify the current transaction status of the cross-chain transaction.
[0123] In a possible implementation manner, the above-mentioned cross-chain transaction processing device further includes:
[0124] The first update module is used to update the first status value to a start value if the destination chain is not registered in the relay chain; update the second status value to a start failure value, and the start failure value is used to represent that the destination chain has not been sent to the destination chain;
[0125] The second update module is used to construct a fifth cross-chain transaction according to the first cross-chain transaction and the updated transaction status table;
[0126] The fifth cross-chain transaction sending module is used to send the fifth cross-chain transaction to the source chain, so that the source chain can roll back the cross-chain transaction according to the fifth cross-chain transaction;
[0127] The rollback receipt receiving sub-module is used to receive the rollback receipt returned by the source chain;
[0128] The third update sub-module is used to update the second status value in the transaction status table to a failure value according to the rollback receipt, and the failure value is used to indicate that the cross-chain transaction execution fails.
[0129] In a possible implementation manner, the above-mentioned second cross-chain transaction sending module 64 includes:
[0130] The destination cross-chain gateway determination sub-module is used to determine the cross-chain gateway of the destination chain according to the registration information of the destination chain;
[0131] The second cross-chain transaction sending sub-module is used to send the second cross-chain transaction to the cross-chain gateway of the destination chain, and the cross-chain gateway of the destination chain is used to send the second cross-chain transaction to the destination chain.
[0132] In a possible implementation manner, the above-mentioned transaction status table update module 66 includes:
[0133] The fourth update sub-module is used to update the first status value to the second status value and update the second status value to a failure value if the execution result is execution failure.
[0134] In a possible implementation manner, the above-mentioned fourth cross-chain transaction sending module 68 includes:
[0135] The first source cross-chain gateway determination sub-module is used to determine the cross-chain gateway of the source chain;
[0136] The first sending sub-module is used to send the fourth cross-chain transaction to the source chain through the cross-chain gateway of the source chain, so that the source chain can roll back the cross-chain transaction in the source chain according to the fourth cross-chain transaction.
[0137] In another possible implementation manner, the above-mentioned transaction status table update module 66 further includes:
[0138] The fifth update sub-module is used to update the first status value to the second status value and update the second status value to a success value if the execution result is execution success.
[0139] In another possible implementation manner, the above-mentioned fourth cross-chain transaction sending module 68 includes:
[0140] The second-source cross-chain gateway determination sub-module is used to determine the cross-chain gateway of the source chain;
[0141] The second sending sub-module is used to send the fourth cross-chain transaction to the source chain through the cross-chain gateway of the source chain, so that the source chain can complete the cross-chain transaction in the source chain according to the fourth cross-chain transaction.
[0142] For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple. For related parts, please refer to the description in the method embodiment section.
[0143] Figure 7 It is a schematic structural diagram of a computing device provided by an embodiment of the present application. As Figure 7 shown, the computing device 7 of this embodiment includes: at least one processor 70 ( Figure 7 only one is shown in the figure), a processor, a memory 71, and a computer program 72 stored in the memory 71 and executable on the at least one processor 70. When the processor 70 executes the computer program 72, it implements the steps in any of the above method embodiments.
[0144] The computing device 7 may be a desktop computer, a notebook, a palm computer, a cloud computing device, or other computing devices. The computing device may include, but is not limited to, a processor 70 and a memory 71. Those skilled in the art can understand that Figure 7 merely examples of the computing device 7, which do not constitute a limitation on the computing device 7. It may include more or fewer components than shown in the figure, or combine some components, or different components. For example, it may also include input / output devices, network access devices, etc.
[0145] The so-called processor 70 may be a central processing unit (CPU), and this processor 70 may also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), off-the-shelf programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or this processor may also be any conventional processor, etc.
[0146] The memory 71 may be an internal storage unit of the computing device 7 in some embodiments, such as a hard disk or memory of the computing device 7. The memory 71 may also be an external storage device of the computing device 7 in other embodiments, such as a plug-in hard disk equipped on the computing device 7, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, etc. Further, the memory 71 may also include both the internal storage unit and the external storage device of the computing device 7. The memory 71 is used to store an operating system, application programs, a BootLoader, data, and other programs, such as the program code of the computer program. The memory 71 may also be used to temporarily store data that has been output or is to be output.
[0147] An embodiment of the present application also provides a computer-readable storage medium storing a computer program, which when executed by a processor can implement the steps in the above-mentioned method embodiments.
[0148] An embodiment of the present application provides a computer program product, which when running on a computing device enables the computing device to implement the steps in the above-mentioned method embodiments.
[0149] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, to implement all or part of the processes in the above-mentioned method embodiments of the present application, a computer program can be used to instruct relevant hardware to complete. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented. Wherein, the computer program includes computer program code, and the computer program code can be in the form of source code, object code, executable file, or some intermediate form, etc. The computer-readable medium may at least include: any entity or device capable of carrying the computer program code to the photographing device / computing device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium. Such as a USB flash drive, a mobile hard disk, a magnetic disk, or an optical disc, etc. In some jurisdictions, according to legislation and patent practice, the computer-readable medium may not be an electrical carrier signal and a telecommunication signal.
[0150] In the above embodiments, the descriptions of the respective embodiments have their own emphases. For parts not detailed or recorded in a certain embodiment, reference may be made to the relevant descriptions of other embodiments.
[0151] Those of ordinary skill in the art will realize that the units and algorithm steps of the examples described in combination with the embodiments disclosed herein can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Skilled professionals can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.
[0152] In the embodiments provided in this application, it should be understood that the disclosed device / calculation device and method can be implemented in other ways. For example, the device / calculation device embodiments described above are merely illustrative. For example, the division of the modules or units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some interfaces. The indirect couplings or communication connections of the devices or units can be in electrical, mechanical or other forms.
[0153] The units described as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0154] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.
Claims
1. A cross-chain transaction processing method, characterized in that, Applied to a relay chain, the method includes: When receiving a first cross-chain transaction initiated by a source chain, initialize a transaction status table for the first cross-chain transaction, where the first cross-chain transaction has a corresponding cross-chain transaction; Parse the first cross-chain transaction to determine the destination chain of the first cross-chain transaction; If the source chain and the destination chain are registered in the relay chain, construct a second cross-chain transaction based on the first cross-chain transaction and the transaction status table; Send the second cross-chain transaction to the destination chain; Receive a third cross-chain transaction returned by the destination chain based on the second cross-chain transaction, where the third cross-chain transaction includes the execution result of the cross-chain transaction by the destination chain; Update the transaction status table according to the execution result; Construct a fourth cross-chain transaction based on the third cross-chain transaction and the updated transaction status table, where the fourth cross-chain transaction includes the execution result and the transaction status of the cross-chain transaction; Return the fourth cross-chain transaction to the source chain for the source chain to process the cross-chain transaction according to the execution result and the transaction status; Wherein, the transaction status table includes a first status value and a second status value, and initializing the transaction status table of the first cross-chain transaction includes: Update the first status value to an initial value, where the first status value is used to identify the previous transaction status of the cross-chain transaction, and the initial value is used to identify that the cross-chain transaction has not started to be processed; Update the second status value to a start value, where the second status value is used to identify the current transaction status of the cross-chain transaction, and the start value is used to identify that the cross-chain transaction starts to be processed.
2. The method according to claim 1, wherein After the step of parsing the first cross-chain transaction to determine the destination chain of the first cross-chain transaction, it further includes: If the destination chain is not registered in the relay chain, update the first status value to the start value; update the second status value to a start failure value, where the start failure value is used to indicate that the cross-chain transaction has not been sent to the destination chain; Construct a fifth cross-chain transaction based on the first cross-chain transaction and the updated transaction status table; Send the fifth cross-chain transaction to the source chain for the source chain to roll back the cross-chain transaction according to the fifth cross-chain transaction; Receive a rollback receipt returned by the source chain; Update the second status value of the transaction status table to a failure value according to the rollback receipt, where the failure value is used to indicate that the cross-chain transaction execution fails.
3. The method according to any one of claims 1-2, characterized in that, The step of sending the second cross-chain transaction to the destination chain includes: Determine the cross-chain gateway of the destination chain according to the registration information of the destination chain; Send the second cross-chain transaction to the cross-chain gateway of the destination chain, where the cross-chain gateway of the destination chain is used to send the second cross-chain transaction to the destination chain.
4. The method according to any one of claims 1 or 2, characterized in that, The step of updating the transaction status table according to the execution result includes: If the execution result is execution failure, update the first status value to the second status value and update the second status value to the failure value.
5. The method according to claim 4, wherein Returning the fourth cross-chain transaction to the source chain for the source chain to process the cross-chain transaction according to the execution result and the transaction status includes: Determining the cross-chain gateway of the source chain; Sending the fourth cross-chain transaction to the source chain through the cross-chain gateway of the source chain for the source chain to roll back the cross-chain transaction according to the execution result and the transaction status.
6. The method according to any one of claims 1 or 2, characterized in that The updating the transaction status table according to the execution result further includes: If the execution result is successful execution, updating the first status value to the second status value and updating the second status value to a success value.
7. The method according to claim 6, wherein Returning the fourth cross-chain transaction to the source chain for the source chain to process the cross-chain transaction according to the execution result and the transaction status includes: Determining the cross-chain gateway of the source chain; Sending the fourth cross-chain transaction to the source chain through the cross-chain gateway of the source chain for the source chain to complete the cross-chain transaction according to the execution result and the transaction status.
8. A computing device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, the method described in any one of claims 1-7 is implemented.
9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, the method described in any one of claims 1-7 is implemented.
Citation Information
Patent Citations
Cross-chain resource exchange method, device and system based on relay chain
CN112491959A
Cross-chain processing method and device, electronic equipment and readable storage medium
CN113420090A