A cross-chain transaction processing method, computer device and medium
By using a relay chain and counter value matching verification method, the problem of data transmission in cross-chain transactions under the instability of the blockchain network is solved, and the ordered execution and rollback of cross-chain transactions are realized, ensuring the atomicity and consistency of cross-chain transactions.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-28
- Publication Date
- 2026-04-10
AI Technical Summary
In cases of blockchain network instability, cross-chain transactions may result in unstable data transmission, causing data to fail to arrive at the destination chain in the correct order, thus affecting the atomicity of the cross-chain transaction.
Cross-chain transactions are transmitted via a relay chain, and the source and destination chains are matched and verified using counter values and transaction sequence numbers to ensure accurate processing of feedback information and enable ordered execution or rollback of cross-chain transactions.
It ensures the atomicity of cross-chain transactions, avoids duplicate calls or omissions of feedback information, and ensures the consistency of cross-chain transactions on the source chain and the destination chain.
Smart Images

Figure CN115310974B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of blockchains, and particularly relates to a cross-chain transaction processing method, a computer device and a medium. BACKGROUND
[0002] Cross-chain is to realize trusted interoperation between different blockchains. Atomicity of cross-chain transactions means that the source chain and the destination chain of cross-chain transactions are either both successfully executed or both failed, and if failed, the state before execution needs to be restored.
[0003] In cross-chain transactions, cross-chain transactions often have business logic, and therefore, cross-chain transactions have an execution order when executed. The blockchain p2p network has instability, which may cause unstable data transmission of cross-chain transactions, and cross-chain transactions cannot reach the destination chain in order, thereby possibly causing cross-chain transactions to fail to perform transactions or transaction rollback according to the execution order, and affecting the atomicity of cross-chain transactions. SUMMARY
[0004] Therefore, the embodiments of the application provide a cross-chain transaction processing method, a computer device and a medium to realize sequenced execution or rollback of cross-chain transactions and guarantee the atomicity of cross-chain transactions.
[0005] A first aspect of the embodiments of the application provides a cross-chain transaction processing method applied to a first application chain, and the method comprises the following steps.
[0006] When a first business contract initiates a cross-chain transaction, the cross-chain transaction is sent to a second application chain through a relay chain, and the second application chain is a destination chain of the cross-chain transaction;
[0007] Feedback information returned by the relay chain for the cross-chain transaction is received, and the feedback information comprises a transaction serial number and a feedback result;
[0008] A first count value recorded in a first cross-chain contract is determined, and the first count value is used to identify the number of cross-chain transaction receipts received by the first application chain;
[0009] If the transaction serial number matches the first count value, the first business contract is called according to the feedback result to process the cross-chain transaction on the first application chain;
[0010] The first count value is updated.
[0011] A second aspect of the embodiments of the application provides a cross-chain transaction processing method applied to a second application chain, and the method comprises the following steps.
[0012] A cross-chain transaction forwarded by a relay chain is received, and the cross-chain transaction has a transaction serial number;
[0013] obtaining a third count value recorded in a second cross-chain contract, the third count value being used to identify a number of cross-chain transactions received by the second application chain;
[0014] if the transaction serial number matches the third count value, performing the cross-chain transaction to obtain a transaction receipt;
[0015] sending the transaction receipt to a first application chain through the relay chain, the first application chain being an origin chain of the cross-chain transaction, and the first application chain being configured to process the cross-chain transaction according to the transaction receipt;
[0016] updating the third count value.
[0017] A third aspect of the embodiments of the present application provides a processing method of a cross-chain transaction, applied to a relay chain, and the method comprises:
[0018] when receiving a cross-chain transaction from a first application chain, verifying the cross-chain transaction, the cross-chain transaction having a timeout time;
[0019] if the cross-chain transaction passes the verification, signing the cross-chain transaction through a plurality of consensus nodes of the relay chain;
[0020] sending the signed cross-chain transaction to a second application chain, the second application chain being a destination chain of the cross-chain transaction;
[0021] if a transaction receipt returned by the second application chain for the cross-chain transaction is received within the timeout time, verifying the transaction receipt;
[0022] if the transaction receipt passes the verification, signing the transaction receipt through the plurality of consensus nodes;
[0023] sending the signed transaction receipt to the first application chain, the first application chain being configured to complete the cross-chain transaction or roll back the cross-chain transaction according to the transaction receipt.
[0024] A fourth aspect of the embodiments of the present application provides a processing device of a cross-chain transaction, applied to a first application chain, and the device comprises:
[0025] a sending module, configured to send a cross-chain transaction to a second application chain through a relay chain when a first business contract initiates the cross-chain transaction, the second application chain being a destination chain of the cross-chain transaction;
[0026] a receiving module, configured to receive feedback information returned by the relay chain for the cross-chain transaction, the feedback information comprising a transaction serial number and a feedback result;
[0027] determining a first count value recorded in a first cross-chain contract, the first count value being used to identify a number of cross-chain transaction receipts received by the first application chain;
[0028] calling the first business contract according to the feedback result to process the cross-chain transaction on the first application chain if the transaction serial number matches the first count value;
[0029] updating the first count value.
[0030] A fifth aspect of the embodiment of the application provides a cross-chain transaction processing device, applied to a second application chain, and the device comprises:
[0031] receiving a cross-chain transaction forwarded by a relay chain, the cross-chain transaction having a transaction serial number;
[0032] obtaining a third count value recorded in a second cross-chain contract, the third count value being used to identify a number of cross-chain transactions received by the second application chain;
[0033] generating a transaction receipt if the transaction serial number matches the third count value;
[0034] sending the transaction receipt to a first application chain through the relay chain, the first application chain being a source chain of the cross-chain transaction, and the first application chain being used to process the cross-chain transaction according to the transaction receipt;
[0035] updating the third count value.
[0036] A sixth aspect of the embodiment of the application provides a cross-chain transaction processing device, applied to a relay chain, and the device comprises:
[0037] a first verification module, configured to verify a cross-chain transaction from a first application chain when the cross-chain transaction is received, the cross-chain transaction having a timeout time;
[0038] a first signature module, configured to sign the cross-chain transaction through a plurality of consensus nodes of the relay chain if the cross-chain transaction passes the verification;
[0039] a first sending module, configured to send the signed cross-chain transaction to a second application chain, the second application chain being a destination chain of the cross-chain transaction;
[0040] a second verification module, configured to verify a transaction receipt returned by the second application chain for the cross-chain transaction within the timeout time;
[0041] a second signature module, configured to, if the transaction receipt is verified, sign the transaction receipt by a plurality of the consensus nodes;
[0042] a second sending module, configured to send the signed transaction receipt to the first application chain, so that the first application chain completes the cross-chain transaction or rolls back the cross-chain transaction according to the transaction receipt.
[0043] A seventh aspect of the embodiment of the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the method in the first aspect, the second aspect, or the third aspect when executing the computer program.
[0044] An eighth aspect of the embodiment of the present application provides a computer readable storage medium, which stores a computer program, and the computer program is executable by a processor to implement the method in the first aspect, the second aspect, or the third aspect.
[0045] A ninth aspect of the embodiment of the present application provides a computer program product, which, when running on a computer device, causes the computer device to execute the method in the first aspect, the second aspect, or the third aspect.
[0046] Compared with the prior art, the embodiment of the present application has the following advantages:
[0047] In the embodiment of the present application, the cross-chain transaction of the first application chain can be sent to the second application chain through the relay chain, then the first application chain can receive the feedback information returned by the relay chain, the feedback information can include a transaction serial number and a feedback result, and the transaction serial number is determined according to the order of the transaction receipt sent by the second application chain to the first application chain. The first cross-chain contract of the first application chain includes a first count value, and the first count value can be used to identify the number of transaction receipts received by the first application chain from the second application chain. If the transaction serial number of the feedback information received by the first application chain matches the first count value, it means that the feedback information is the feedback information corresponding to the cross-chain transaction currently processed by the first application chain. At this time, the first application chain can process the cross-chain transaction according to the feedback result and update the first count value. In this embodiment, the feedback information is processed according to the matching of the transaction serial number of the feedback information and the first count value, which can avoid repeated calling or omission of the feedback information, and ensures that the cross-chain transaction can be executed in sequence, and ensures that the first application chain only processes each feedback information once, thereby ensuring the atomicity of the cross-chain transaction. BRIEF DESCRIPTION OF DRAWINGS
[0048] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the embodiments or prior art description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and for those skilled in the art, other drawings can also be obtained from these drawings without creative labor.
[0049] Figure 1 is a schematic diagram of a cross-chain system provided by an embodiment of the present application;
[0050] Figure 2 is a schematic diagram of a step flow of a processing method of cross-chain transaction provided by an embodiment of the present application;
[0051] Figure 3 is a schematic diagram of a step flow of another processing method of cross-chain transaction provided by an embodiment of the present application;
[0052] Figure 4 is a schematic diagram of a processing method of cross-chain transaction provided by an embodiment of the present application;
[0053] Figure 5 is a schematic diagram of a processing device of cross-chain transaction provided by an embodiment of the present application;
[0054] Figure 6 is a schematic diagram of another processing device of cross-chain transaction provided by an embodiment of the present application;
[0055] Figure 7 is a schematic diagram of another processing device of cross-chain transaction provided by an embodiment of the present application;
[0056] Figure 8 is a schematic diagram of a computer device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0057] In the following description, for the purpose of explanation and not limitation, specific details are set forth, such as particular system configurations, techniques, etc., in order to provide a thorough understanding of the embodiments of the present application. However, it will be apparent to those skilled in the art that the present application can be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present application with unnecessary detail.
[0058] It should be understood that, when used in the specification and the appended claims of the present application, the term "comprising" indicates the presence of the described features, integers, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.
[0059] In addition, in the description of the present application and the appended claims, the terms "first", "second", "third", etc. are used only to distinguish descriptions and cannot be understood as indicating or implying relative importance.
[0060] Reference to "one embodiment" or "some embodiments" or "one implementation" or "some implementations" or "one example" or "some examples" described in the present application means that a particular feature, structure, or characteristic described in connection with the embodiment is included in at least one embodiment of the present application. Therefore, the phrases "in one embodiment", "in some embodiments", "in other some embodiments", "in yet some embodiments", etc. appearing in different places in the specification are not necessarily all referring to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically noted. The terms "include", "contain", "have" and their variants mean "including but not limited to", unless otherwise specifically noted.
[0061] To achieve security and trust across chains, there are some requirements for cross-chain mechanisms and steps, the most important of which is the atomicity of cross-chain transactions. For ordinary intra-chain transactions, transactions need to support atomicity; the same is true for cross-chain transactions. When cross-chain fails, the two application chains involved in the cross-chain transaction are rolled back.
[0062] To ensure the atomicity of cross-chain transactions, most mainstream cross-chain solutions currently use the classic two-phase commit to complete, two transactions are mutual anchors, and if the anchor is still invalid for more than a period of time, the rollback of the transaction can be initiated. However, this solution requires all nodes to reach a consensus on the validity of the anchor, cannot rely on remote access proof, and due to network instability factors, it can cause verification difficulties.
[0063] In view of the unstable characteristics of the blockchain p2p network, the present application provides a processing method for cross-chain transactions, which can ensure the sequential execution and rollback of cross-chain transactions, and ultimately ensure the atomicity of cross-chain transactions.
[0064] Figure 1 is a schematic diagram of a cross-chain system provided by an embodiment of the present application, as shown in Figure 1 The cross-chain system includes a relay chain, which can provide cross-chain relay services; business chain A and business chain B in the cross-chain system can perform cross-chain transactions through the relay chain. Business chain A and business chain B are application chains of the cross-chain system, and each application chain can include a business contract and a cross-chain contract, as shown in Figure 1 Business chain A can include business contract A and cross-chain contract A, and business chain B can include business contract B and cross-chain contract B. The business contract can initiate a cross-chain transaction; the cross-chain contract can be used to manage the cross-chain transaction, and the cross-chain transaction data can be stored in the cross-chain contract. In the present application, the cross-chain contract can serve as a coordinator of the cross-chain transaction execution sequence.
[0065] The method of cross-chain transaction processing provided by the embodiment can be applied to Figure 1 The cross-chain system is shown. The scheme of the present application is described below with specific embodiments.
[0066] Referring to Figure 2 , a step flow diagram of a method for processing cross-chain transactions provided by an embodiment of the present application is shown, which can specifically include the following steps:
[0067] S201, when the first business contract initiates a cross-chain transaction, the cross-chain transaction is sent to the second application chain through the relay chain, and the second application chain is the destination chain of the cross-chain transaction.
[0068] The execution subject of the embodiment is the first application chain. In the present application, in order to facilitate the description of the scheme, the first application chain is used to represent the application chain that initiates the cross-chain transaction, that is, the first application chain is the source chain of the cross-chain transaction. It should be clear to those skilled in the art that the first application chain, as an application chain, can be both the source chain and the destination chain of the cross-chain transaction. That is, the first application chain can also implement the steps in S301-S305.
[0069] The first application chain can include multiple business contracts, and different transactions can be executed based on the business contract application chain. In the process of executing the transaction, data of other application chains or contract services provided by business contracts on other application chains may be needed, at which time the business contract can initiate a cross-chain transaction.
[0070] The first business contract is a business contract in the first application chain that can initiate a cross-chain transaction. The first cross-chain contract is a cross-chain contract on the first application chain, which can be used to manage the cross-chain transactions of the first application chain and coordinate the execution order of the cross-chain transactions on the first application chain.
[0071] When the first cross-chain business contract initiates a cross-chain transaction, the first application chain can send the cross-chain transaction to the relay chain through the corresponding cross-chain gateway; the relay chain can forward the received cross-chain transaction to the destination chain of the cross-chain transaction, that is, the second application chain.
[0072] The cross-chain transaction has corresponding transaction information, which can include transaction serial number, transaction ID, transaction content, and transaction call information, etc. Among them, the transaction serial number can be obtained according to the order of the cross-chain transactions sent by the first application chain to the second application chain. For example, the transaction serial number of the first cross-chain transaction sent by the first application chain to the second application chain is 1; the transaction serial number of the second cross-chain transaction sent by the first application chain to the second application chain is 2; the transaction serial number of the nth cross-chain transaction sent by the first application chain to the second application chain is n. Therefore, the transaction serial number of the cross-chain transaction can reflect the execution order of the cross-chain transaction.
[0073] In a possible implementation, the first cross-chain contract can include multiple counters, respectively used for counting the initiated cross-chain transactions, the returned transaction receipts, the received cross-chain transactions, and the received rollback notifications from the relay chain. When the business contract initiates a cross-chain transaction, the cross-chain contract can update the counter recording the number of cross-chain transactions initiated by the first application chain to the second application chain, and increase the count value of the counter by 1. For the convenience of description, the count value of the counter is denoted as a second count value.
[0074] Exemplarily, the counters in the cross-chain contract in the application chain in this embodiment can include outCounter, callbackCounter, inCounter, and dstRollbackCounter. The outCounter can be used to record the number of cross-chain requests initiated by the current application chain service as a source service to the services of other chains. The callbackCounter can record the number of feedback information received by the current application chain service as a source service from the services of other chains through cross-chaining. The inCounter can record the number of cross-chain transactions received by the current application chain service as a destination service from the services of other chains. The dstRollbackCounter can be used to record the rollback of the destination chain after the relay chain discovers that the destination chain fails to execute the cross-chain transaction within a timeout period, and sends a timeout rollback notification to the destination chain.
[0075] In addition to recording the serial numbers of the corresponding cross-chain transactions, since the cross-chain contract needs to call the business contract to execute the corresponding call, callback, and rollback operations, the cross-chain contract also needs to record the call, callback, and rollback information of the cross-chain transaction and the result information of the execution of the cross-chain transaction for query. Exemplarily, the cross-chain contract can further include outMessages and receiptMessages. The outMessages can be used to record the IDs of the cross-chain transactions thrown out by the current application chain and the call / callback / rollback information of the transactions. The receiptMessages can be used to record the IDs of the cross-chain transactions received by the current application chain and the receipt information returned after the execution of the cross-chain transactions.
[0076] In this embodiment, the first cross-chain contract can include first cross-chain transaction information, i.e., the above-mentioned outMessages, and the first cross-chain transaction information can record the transaction information of the cross-chain transactions initiated by the first application chain. After the business contract initiates a cross-chain transaction, the cross-chain contract can record the transaction information of the cross-chain transaction in the first cross-chain transaction information. When the cross-chain transaction is lost, the cross-chain transaction can be re-sent according to the first cross-chain transaction information.
[0077] In a possible implementation, the first application chain sends the cross-chain transaction to the relay chain through the first cross-chain gateway; the relay chain has a corresponding counter to record the number of transactions of the cross-chain transaction sent by the first application chain to the second application chain, and the value of the counter is the received transaction count value. Due to network instability, the cross-chain transaction can be lost; or the first cross-chain gateway fails, which also causes the cross-chain transaction to be unable to be forwarded to the relay chain.
[0078] When the first cross-chain gateway corresponding to the first application chain is restarted, the first application chain can obtain the received transaction count value and the second count value, that is, the value of outCounter. If the second count value and the received transaction count value are not equal, it indicates that some cross-chain transactions initiated by the first application cross-chain are not sent to the relay chain. At this time, the cross-chain transactions with the transaction serial number greater than the received transaction count value and less than or equal to the second count value can be sent to the relay chain through the first cross-chain gateway according to the first cross-chain transaction information.
[0079] S202, receiving feedback information returned by the relay chain for the second application chain, the feedback information including a transaction serial number and a feedback result.
[0080] The feedback information can include a transaction receipt from the second application chain or a timeout rollback notification from the relay chain. The second application chain is the destination chain of the cross-chain transaction, can execute the cross-chain transaction to obtain a transaction execution result, and then generate a transaction receipt. After generating the transaction receipt, the second application chain can send the transaction receipt to the relay chain, and the relay chain can send the transaction receipt to the first application chain after receiving the transaction receipt.
[0081] The transaction receipt has a transaction serial number, and the transaction serial number of the transaction receipt can be used to identify the order of the cross-chain transaction sent by the second application chain to the first application chain. For example, the transaction serial number of the first transaction receipt returned by the second application chain to the first application chain is 1; the transaction serial number of the second transaction receipt returned by the second application chain to the first application chain is 2; and the transaction serial number of the nth transaction receipt returned by the second application chain to the first application chain is n. That is, the transaction serial number can identify the number of transaction receipts sent by the second application chain to the first application chain.
[0082] The cross-chain transaction has a corresponding timeout time, and the relay chain can send the cross-chain transaction to the second application chain after receiving the cross-chain transaction. If the relay chain does not receive the transaction receipt returned by the second application chain within the timeout time, it can be determined that the cross-chain transaction fails, and the relay chain can return a timeout rollback notification to the first application chain and the second application chain respectively. The timeout rollback notification also has a transaction serial number, and the serial number of the timeout rollback notification can match the transaction serial number of the corresponding cross-chain transaction. The feedback result of the timeout rollback notification is timeout rollback.
[0083] S203, determine a first count value recorded in the first cross-chain contract, the first count value being used to identify a number of feedback information received by the first application chain.
[0084] For one cross-chain transaction, the first application chain can receive a corresponding feedback information, and the first count value is used to record the number of received feedback information, i.e., the value of callbackCounter.
[0085] The initial value of the first count value can be 0, and the first count value can be incremented by 1 each time the first application chain receives a corresponding feedback information and the feedback information is verified. That is, the first count value can also be equivalent to the number of feedback information processed by the first application chain.
[0086] S204, if the transaction serial number matches the first count value, the first business contract is called according to the transaction execution result to process the cross-chain transaction on the first application chain.
[0087] Since the first count value can identify the number of feedback information received by the first application chain, and the transaction serial number of the feedback information can identify the number of feedback information sent to the first application chain, the current value of the first count value plus 1 is the transaction serial number of the next received feedback information. If the first count value plus 1 equals the transaction serial number, it means that the first count value matches the transaction serial number, and the order of the received transaction receipt is correct.
[0088] In the embodiment, the relay chain includes a plurality of consensus nodes, and the relay chain can use multiple consensus nodes to multi-sign the cross-chain transaction, transaction receipt or timeout rollback notification that needs to be forwarded, so that the cross-chain transaction, transaction receipt or timeout rollback notification can carry the signature information of the relay chain. Therefore, the feedback information received by the first application chain carries the signature information of the relay chain, and based on the signature information, the existence and validity of the feedback information can be verified.
[0089] If the first count value matches the transaction serial number, the first application chain can verify the signature information of the feedback information; when the first application chain is registered in the relay chain, the signature verification method of the relay chain can be obtained, so that the signature information can be verified by using the signature verification method. For example, the relay chain can use a public key cryptography system to sign, and the first application chain can obtain the public keys of the consensus nodes; so that after receiving the transaction receipt, the signature information is verified by using the public keys of the consensus nodes.
[0090] If the signature information of the feedback information is verified, a corresponding interface of the first business contract is invoked according to the feedback result to process the cross-chain transaction on the first application chain. Specifically, if the feedback result is transaction success, it indicates that the second application chain has successfully executed the cross-chain transaction, and the first application chain can call the callback interface of the first business contract to complete the cross-chain transaction, thereby ensuring that the cross-chain transaction is successfully executed on the first application chain and the second application chain. If the feedback result is transaction failure or timeout rollback, it indicates that the cross-chain transaction fails to execute on the second application chain, and the first application chain can call the rollback interface of the first business contract to rollback the cross-chain transaction, thereby ensuring that the cross-chain transaction fails to execute on the first application chain and the second application chain.
[0091] If the first count value does not match the transaction serial number, the relationship between the first count value and the transaction serial number can be determined.
[0092] If the first count value plus one is greater than the transaction serial number, and the feedback information is a transaction receipt, it indicates that the transaction receipt has been processed by the first application chain, at which time the transaction receipt can be discarded, thereby avoiding repeated processing of the transaction receipt.
[0093] If the first count value plus one is less than the transaction serial number, and the feedback information is a transaction receipt, it indicates that there is a transaction receipt that has not reached the first application chain, at which time the transaction receipt can be waited for. Alternatively, the transaction serial number of the missing transaction receipt can be sent to the second application chain through the relay chain to instruct the second application chain to resend the missing transaction receipt.
[0094] If the first count value does not match the transaction serial number and the feedback information is a timeout rollback notification, the timeout rollback notification can be discarded directly.
[0095] By way of example, the first application chain sends a cross-chain transaction to the second application chain, the transaction serial number of the cross-chain transaction is 16, at which time outCounter in the first application chain = 16, that is, there are 15 cross-chain transactions previously sent by the first application chain to the second application chain, inCounter in the second application chain = 15; the first application chain has sent 15 cross-chain transactions to the second application chain, if all the 15 cross-chain transactions have been processed, at which time outCounter in the first application chain = 15.
[0096] When the second application link receives the cross-chain transaction, it can determine that the transaction sequence number of the cross-chain transaction is 16, and inCounter+1 is also 16, indicating that the cross-chain transaction is indeed the next cross-chain transaction to be processed. At this time, the second application chain executes the cross-chain transaction and generates a transaction receipt, and the transaction sequence number of the transaction receipt can be 16. The inCounter of the second application chain is updated to 16. If the first application link receives the transaction receipt returned by the second application chain through the relay chain, it can determine that the transaction sequence number of the transaction receipt is 16. At this time, the outCounter+1 of the first application chain is also 16, and the first application chain can process the cross-chain transaction according to the transaction receipt.
[0097] In another case, the relay chain does not receive the transaction receipt from the second application chain within the timeout time, and then returns a timeout rollback notification to the first application chain and the second application chain respectively. The transaction sequence number of the timeout rollback notification is 16, and the feedback result is timeout rollback. After the first relay link receives the timeout rollback notification, it determines that the transaction sequence number 16 = outCounter+1, and then calls the rollback interface according to the timeout rollback to rollback the cross-chain transaction.
[0098] After the first application chain processes the feedback information corresponding to the cross-chain transaction, it can update the outCounter, i.e. outCounter = 16.
[0099] S205, updating the first count value.
[0100] After the signature information of the feedback information is verified, it indicates that the first application chain will process the feedback information, and the first count value can be increased by one. The updated first count value is used to determine whether the sequence number of the feedback information from the second application chain is correct when it is received next time.
[0101] In a possible implementation, the cross-chain transaction has a timeout time. When the relay chain forwards the cross-chain transaction to the second application chain, if it does not receive a transaction receipt within the timeout time, it can determine that the execution result of the cross-chain transaction is transaction failure, and then sends a rollback notification to the first application chain and the second application chain.
[0102] The rollback notification can also have a transaction sequence number. In the first cross-chain contract, the fourth count value, i.e. the value of dstRollbackCounter, can be determined after the first application chain receives the rollback notification. If the fourth count value matches the transaction sequence number of the rollback notification, the signature information of the rollback notification can be verified. After the signature information is verified, the rollback interface of the first business contract can be called according to the rollback notification, so as to rollback the cross-chain transaction.
[0103] In the embodiments of the present application, the transaction serial number is incremented by one, and the scheme of the present application is described by taking this as an example. Those skilled in the art should know that if the transaction serial number can determine the corresponding sequence, the updating method can be performed in any other possible way.
[0104] In the embodiments of the present application, the feedback information has a corresponding transaction serial number, and the first cross-chain contract can include a first count value, which can identify the number of feedback information received by the first application link. Thus, whether the feedback information has been processed and whether there is missing feedback information can be determined according to the transaction serial number of the feedback information and the first count value, avoiding repeated processing or omission of the feedback information. When the transaction serial number matches the first count value, the first application chain will only call back or roll back the cross-chain transaction according to the transaction processing result of the feedback information, thereby ensuring the state synchronization of the cross-chain transaction on the first application chain and the second application chain, and ensuring the atomicity of the cross-chain transaction. In addition, in the present embodiment, based on the second count value, when the cross-chain transaction is lost due to network instability, the cross-chain contract can be used to recover and resend the cross-chain transaction. In the present embodiment, the cross-chain contract in the application chain can count the cross-chain transaction and the feedback information, and the cross-chain transaction and the feedback information have a transaction serial number matching the count value, so the orderliness of the cross-chain service can be maintained.
[0105] Referring to Figure 3 , another step flow diagram of the processing method of the cross-chain transaction provided by the embodiments of the present application is shown, which can specifically include the following steps:
[0106] S301, receiving the cross-chain transaction forwarded by the relay chain, the cross-chain transaction having a transaction serial number.
[0107] The execution subject of the present embodiment is the second application chain. In the present application, in order to facilitate the description of the scheme, the second application chain is used to represent the application chain receiving the cross-chain transaction, that is, the second application chain is the destination chain of the cross-chain transaction. Those skilled in the art should know that the second application chain as an application chain can be both the source chain and the destination chain of the cross-chain transaction. That is, the second application chain can also implement the steps in S201-S205.
[0108] The cross-chain transaction has a transaction serial number. As described in the above S202 step, the transaction serial number can identify the execution order of the cross-chain transaction. In addition, since the transaction serial number is obtained by sequentially adding one according to the execution order of the cross-chain transaction, the transaction serial number can be equivalent to the number of cross-chain transactions sent by the first application chain to the second application chain.
[0109] The second application chain can receive the cross-chain transaction from the first application chain through the relay link. The cross-chain transaction is sent to the second application chain because the execution of the cross-chain transaction needs the contract service provided by the business contract in the second application chain.
[0110] S302, acquire a third count value recorded in the second cross-chain contract, the third count value being used to identify a number of cross-chain transactions received by the second application chain.
[0111] The second cross-chain contract can include a third count value, i.e., a value of incounter. An initial value of the third count value can be 0, and the third count value can be increased by 1 each time a cross-chain transaction from the first application chain is received and verified, so that the third count value can identify a number of cross-chain transactions received by the second application chain from the first application chain.
[0112] In an embodiment of the present application, receiving a cross-chain transaction or a transaction receipt from another application chain by the application chain can specifically be manifested as: verifying the cross-chain transaction or the transaction receipt.
[0113] S303, if the transaction serial number matches the third count value, execute the cross-chain transaction to obtain a transaction receipt.
[0114] The transaction serial number can be equivalent to a number of cross-chain transactions sent by the first application chain to the second application chain, and the third count value can identify a number of cross-chain transactions received by the second application chain from the first application chain. If the cross-chain transaction reaches the second application chain in a normal execution order, the transaction serial number of the cross-chain transaction should be equal to the third count value plus 1. If the transaction serial number of the cross-chain transaction is less than the third count value plus 1, it indicates that the second application chain has already processed the cross-chain transaction, and in order to avoid repeated execution of the cross-chain transaction, the cross-chain transaction can be discarded. If the transaction serial number of the cross-chain transaction is greater than the third count value plus 1, it indicates that there is an unprocessed cross-chain transaction in the middle. Then the second application chain can send a cross-chain transaction request to the first application chain through the relay chain to instruct the first application chain to send cross-chain transactions with transaction serial numbers greater than the third count value and less than the transaction serial number to the second application chain, so that the second application chain can execute the cross-chain transactions in order.
[0115] If the transaction serial number is equal to the third count value plus one, it indicates that the transaction serial number matches the third count value. After determining that the transaction serial number matches the third count value, in order to ensure that the cross-chain transaction is safe and effective, the cross-chain transaction needs to be verified. The cross-chain transaction can include signature information, which can be signed by the plurality of consensus nodes of the relay chain through a preset signature rule. The signature rule can be agreed upon by the second application chain and the relay chain in advance, and the second application chain can store a verification algorithm corresponding to the signature rule. The second application chain can verify the signature information according to the verification algorithm, and if the signature information of the cross-chain transaction passes the verification, the second business contract of the second application chain is called to execute the cross-chain transaction to obtain a transaction execution result; and then a transaction receipt is generated according to the transaction execution result. The second business contract is a business contract that needs to be called when the cross-chain transaction is completed. In one possible implementation, the cross-chain transaction can include description information of the second business contract, so that the second application chain can call the corresponding second business contract.
[0116] The transaction execution result can include transaction success and transaction failure. If the transaction execution result is transaction failure, the rollback interface of the second business contract can be called to restore the second application chain to the state before the cross-chain transaction is executed. After the first application chain receives the transaction receipt, the cross-chain transaction can also be rolled back according to the transaction execution result, so that the first application chain and the second application chain are both restored to the state before the cross-chain transaction is executed, thereby guaranteeing the atomicity of the cross-chain transaction.
[0117] S304, sending the transaction receipt to the first application chain through the relay chain, the first application chain being a source chain of the cross-chain transaction, and the first application chain being configured to process the cross-chain transaction according to the transaction receipt.
[0118] After generating the transaction receipt, the second application chain can send the transaction receipt to the relay chain; after the relay chain receives the transaction receipt, the relay chain can send the transaction receipt to the first application chain. After the first application chain receives the transaction receipt, the cross-chain transaction can be rolled back or completed according to the transaction execution result, thereby ensuring that the state of the cross-chain transaction on the first application chain and the second application chain is consistent.
[0119] S305, updating the third count value.
[0120] The third count value is incremented by one, thereby indicating that the second application chain has received the cross-chain transaction. The new third count value can be used to determine whether the order of the cross-chain transaction is correct according to the transaction serial number and the third count value when the second application chain receives the cross-chain transaction from the first application chain next time.
[0121] In a possible implementation, the cross-chain transaction has a timeout time, and when forwarding the cross-chain transaction to the second application chain, if a transaction receipt is not received within the timeout time, the relay chain can determine that the execution result of the cross-chain transaction is a transaction failure, and then send a rollback notification to the first application chain and the second application chain.
[0122] When receiving the rollback notification from the relay chain, the second application chain can determine the transaction serial number of the cross-chain transaction to be rolled back corresponding to the rollback notification. If the third count value is less than the transaction serial number of the cross-chain transaction to be rolled back, it indicates that the second application chain has not received the cross-chain transaction to be rolled back and has not processed the cross-chain transaction to be rolled back, and the second application chain can directly return information that the cross-chain transaction to be rolled back is rolled back successfully to the relay chain. If the third count value is greater than or equal to the transaction serial number of the cross-chain transaction to be rolled back, it indicates that the cross-chain transaction to be rolled back has been executed, and the second application chain can call the business contract corresponding to the cross-chain transaction to be rolled back to roll back the cross-chain transaction to be rolled back.
[0123] In this embodiment, the cross-chain transaction has a transaction serial number, and the cross-chain contract of the application chain can record the number of received cross-chain transactions. Therefore, based on the transaction serial number and the information recorded by the cross-chain contract, it can be determined whether the order of the cross-chain transaction is correct, so that the cross-chain transaction can be executed in the correct order. Since the cross-chain transactions are processed in order, it can be ensured that each cross-chain transaction with a transaction serial number is only processed once, and when there is a missing cross-chain transaction, it can be found and processed in time. This embodiment is based on the sequencing execution or rollback of the cross-chain transaction, and avoids repeated calling or omission of the cross-chain transaction due to unstable network.
[0124] Referring to Figure 4 , a step flowchart of another cross-chain transaction processing method provided by an embodiment of the application is shown, which can specifically include the following steps:
[0125] S401, when receiving a cross-chain transaction from a first application chain, verifying the cross-chain transaction, the cross-chain transaction having a timeout time.
[0126] The execution subject of this embodiment is a relay chain, which can provide cross-chain intermediate services for application chains. An application chain that needs the relay chain to provide cross-chain relay services can be pre-registered in the relay chain.
[0127] The first application chain can send a cross-chain transaction to the second application chain through the relay chain. The cross-chain transaction sent by the first application chain can carry verification information of the first application chain. The relay chain can verify the validity of the cross-chain transaction based on the verification message.
[0128] Because different blockchains have different architectures, the relay chain needs to take different verification measures for different application chains. Therefore, when an application chain registers with the relay chain, it can also register its own chain verification rules with the relay chain. The relay chain will review the verification rules, and once the review is approved, they will be deployed on the relay chain. After that, cross-chain transactions issued by the application chain will be checked for validity on the relay chain using the verification rules.
[0129] The relay chain can also perform existence checks on cross-chain transactions. Generally, different application chains encapsulate their verification information in different ways when sending cross-chain transactions. For example, cross-chain transactions can carry a proof, which is a Merkle tree proof signed by the consensus nodes on the chain, used to prove that the transaction does indeed exist on the application chain. The relay chain can use this proof to verify the existence of cross-chain transactions.
[0130] S402, if the cross-chain transaction passes verification, the cross-chain transaction is signed by multiple consensus nodes of the relay chain.
[0131] After a cross-chain transaction passes existence and validity verification, the relay chain can consider the cross-chain transaction secure and trustworthy. The relay chain can sign the cross-chain transaction based on multiple consensus nodes. When the second application receives the cross-chain transaction, it can verify the existence and validity of the cross-chain transaction by verifying the signature information.
[0132] In one possible implementation, each consensus node in the relay chain possesses a public key and a private key. Cross-chain transactions can be signed using the private keys of multiple consensus nodes to obtain an aggregated signature. This aggregated signature can be verified using the public keys of the signing consensus nodes. Application chains registered in the relay chain can obtain the public keys of multiple consensus nodes, thus enabling them to verify the aggregated signature upon receiving cross-chain transactions.
[0133] S403, the signed cross-chain transaction is sent to the second application chain, which is the destination chain of the cross-chain transaction.
[0134] S404, if a transaction receipt is received from the second application chain for the cross-chain transaction within the timeout period, the transaction receipt is verified.
[0135] S405, if the transaction receipt passes verification, the transaction receipt is signed by multiple consensus nodes.
[0136] Cross-chain transactions may include a timeout period during which the relay chain can receive a transaction receipt. Once the cross-chain transaction receives the transaction receipt, it can be verified and signed using the same methods as described in S402-S403.
[0137] In a possible implementation, when the cross-chain transaction or the transaction receipt fails to pass the verification, it can be determined that the cross-chain transaction or the transaction receipt is illegal, so as to discard the cross-chain transaction or the transaction receipt.
[0138] S406, sending the signed transaction receipt to the first application chain, so that the first application chain completes the cross-chain transaction or rolls back the cross-chain transaction according to the transaction receipt.
[0139] If the relay chain does not receive the transaction receipt of the cross-chain transaction within the timeout time, the relay chain can determine that the cross-chain transaction fails, and can send a rollback notification to the first application chain and the second application chain respectively, so as to instruct the first application chain and the second application chain to roll back the cross-chain transaction.
[0140] In order to ensure the security and credibility of the cross-chain transaction, the cross-chain transaction needs to be verified. Different application chains have different verification rules. If the application chain verifies the received cross-chain transaction, the application chain needs to encapsulate the verification rules of multiple other application chains, so that the burden of the application chain is increased. In the embodiment, the relay chain can be used to verify the cross-chain transaction or the transaction receipt. After the verification is passed, the relay chain can sign the cross-chain transaction or the transaction receipt. In this way, the application chain can verify according to the signature after receiving the cross-chain transaction or the transaction receipt. By using the method in the embodiment, the application chain only needs to store the verification rule of the relay chain signature, and then verifies all received cross-chain transactions or transaction receipts according to the rule. The application chain does not need to store the verification rules of multiple other application chains, thereby reducing the burden of the application chain.
[0141] The third-party relay chain verifies the effectiveness of the cross-chain transaction, signs the cross-chain transaction, and then forwards the cross-chain transaction to the application chain cross-chain contract for verification and execution, which can effectively solve the problem of cross-chain transaction verification difficulty caused by unstable network.
[0142] It should be noted that the size of the serial number of each step in the above embodiment does not mean the execution order. The execution order of each process should be determined according to its function and inherent logic, and should not constitute any limitation on the implementation process of the embodiment of the application.
[0143] In order to better illustrate the method in the application, the cross-chain system in Figure 1 is taken as an application scenario, and the cross-chain transaction sent by the business chain A to the business chain B is taken as an example to illustrate the method in the application.
[0144] The cross-chain transaction processing flow when the cross-chain transaction is successfully executed is as follows:
[0145] Business chain A invokes business contract A to initiate a cross-chain transaction, and the cross-chain transaction carries a corresponding timeout time.
[0146] Cross-chain contract A records the cross-chain transaction and updates outCounter and outMessage, and then throws the cross-chain transaction to the relay chain.
[0147] After the relay chain receives the cross-chain transaction, it first verifies the existence and validity of the cross-chain transaction. If the validity and existence of the cross-chain transaction are verified, the consensus nodes in the relay chain can multi-sign the cross-chain transaction and forward the signed cross-chain transaction to the cross-chain contract B of business chain B.
[0148] Cross-chain contract B receives the cross-chain transaction, first checks whether inCounter + 1 recorded in the contract is the serial number of the cross-chain transaction, and if inCounter + 1 is the serial number of the cross-chain transaction, verifies whether the relay chain multi-signature is legal. If the relay chain multi-signature verification is passed, update the contract inCounter and call the corresponding interface of business contract B; if the interface call is successful, record the call result in receiptMessages and throw the cross-chain transaction receipt to the relay chain.
[0149] After the relay chain receives the transaction receipt, it first verifies the existence and validity of the cross-chain transaction receipt. After the existence and validity of the transaction receipt are verified, the consensus nodes in the relay chain multi-sign the transaction receipt and forward it to the cross-chain contract A.
[0150] Cross-chain contract A receives the transaction receipt, first checks whether callbackCounter + 1 recorded in the contract is the serial number of the transaction receipt, and if callbackCounter + 1 is the serial number of the transaction receipt, verifies whether the relay chain multi-signature is legal. If the relay chain multi-signature verification is passed, the callbackCounter in the contract can be updated and the callback interface in business contract A can be called to complete the cross-chain transaction. At this point, the cross-chain transaction is successfully executed on both business chain A and business chain B.
[0151] The cross-chain transaction processing flow when the cross-chain transaction fails is as follows:
[0152] Business chain A invokes business contract A to initiate a cross-chain transaction, and the cross-chain transaction carries a corresponding timeout time.
[0153] Cross-chain contract A records the cross-chain transaction and updates outCounter and outMessage, and then throws the cross-chain transaction to the relay chain.
[0154] After the relay link receives the cross-chain transaction, it first verifies the existence and validity of the cross-chain transaction. If the validity and existence of the cross-chain transaction are verified, the consensus nodes in the relay chain can multi-sign the cross-chain transaction and forward the signed cross-chain transaction to the cross-chain contract B of the business chain B.
[0155] After the cross-chain contract B receives the cross-chain transaction, it first checks whether inCounter+1 recorded in the contract is the serial number of the cross-chain transaction. If inCounter+1 is the serial number of the cross-chain transaction, it verifies whether the relay chain multi-signature is legal. If the relay chain multi-signature verification is passed, the contract inCounter is updated and the corresponding interface of the business contract B is called. If the interface call fails, the business contract B will automatically revert and restore the state to before the cross-chain transaction execution. The cross-chain contract B records the call result in receiptMessages and throws the cross-chain transaction receipt to the relay chain.
[0156] After the relay link receives the transaction receipt, it first verifies the existence and validity of the cross-chain transaction receipt. After the existence and validity of the transaction receipt are verified, the consensus nodes in the relay chain multi-sign the transaction receipt and forward it to the cross-chain contract A.
[0157] After the cross-chain contract A receives the transaction receipt, it first checks whether callbackCounter+1 recorded in the contract is the serial number of the transaction receipt. If callbackCounter+1 is the serial number of the transaction receipt, it verifies whether the relay chain multi-signature is legal. If the relay chain multi-signature verification is passed, the contract callbackCounter can be updated and the rollback interface in the business contract A can be called to rollback the cross-chain transaction. At this point, the cross-chain transaction fails to execute on both business chain A and business chain B.
[0158] The process of cross-chain transaction timeout rollback is as follows:
[0159] The business chain A calls the business contract A to initiate a cross-chain transaction, and the cross-chain transaction carries the corresponding timeout time.
[0160] The cross-chain contract A records the cross-chain transaction and updates outCounter and outMessage, and then throws the cross-chain transaction to the relay chain.
[0161] After the relay link receives the cross-chain transaction, it first verifies the existence and validity of the cross-chain transaction. If the validity and existence of the cross-chain transaction are verified, the consensus nodes in the relay chain can multi-sign the cross-chain transaction and forward the signed cross-chain transaction to the cross-chain contract B of the business chain B.
[0162] In case the relay chain does not receive the transaction receipt submitted by the business chain B due to various reasons such as poor network conditions, the relay chain as the coordinator can generate a cross-chain transaction rollback notification and send the notification to the cross-chain contract A and the cross-chain contract B after multi-signature, notifying the business chain A and the business chain B to rollback.
[0163] After receiving the cross-chain transaction rollback notification, the cross-chain contract A first checks whether callbackCounter+1 recorded in the contract is the serial number of the cross-chain transaction rollback notification; if callbackCounter+1 is the serial number of the cross-chain transaction rollback notification, the multi-signature of the relay chain is verified; if the multi-signature of the relay chain is verified, callbackCounter in the contract can be updated and the rollback interface in the business contract A is called to rollback the cross-chain transaction.
[0164] After receiving the cross-chain transaction rollback notification, the cross-chain contract B first checks whether inCounter recorded in the contract is greater than or equal to the serial number of the cross-chain transaction rollback notification, that is, whether the cross-chain transaction has been executed on the business chain B. If inCounter is greater than or equal to the serial number of the cross-chain transaction rollback notification, it indicates that the cross-chain transaction has been executed on the business chain B, then the multi-signature of the relay chain is verified and dstRollbackCounter recorded in the contract is updated, then the rollback logic of the corresponding interface of the business contract B is called, finally the cross-chain contract B records the calling result in receiptMessages and notifies the relay chain that the business chain B has been successfully rolled back. If inCounter is less than the serial number of the cross-chain transaction rollback notification, it indicates that the cross-chain transaction has not been executed on the business chain B, then no operation is needed, only dstRollbackCounter, inCounter and receiptMessages recorded in the contract are updated, and the relay chain is notified that the business chain B has been successfully rolled back.
[0165] In this embodiment, the business contract initiates the cross-chain transaction by calling the corresponding interface of the cross-chain contract, and explicitly calls the corresponding interface and parameters of the target chain business contract, and explicitly calls the corresponding callback / rollback interface and parameters. The interface of the business contract for cross-chain calling by other application chains needs to implement the logic of normal execution of cross-chain transactions and the corresponding timeout rollback logic. Cross-chain transactions will automatically revert if they fail to execute on the target chain, so the failure rollback is mainly for the source chain, and the timeout rollback is coordinated by the relay chain, and then the source chain and the target chain are notified to rollback.
[0166] Based on the above example, the counter counter is used to implement the sequential execution and failure / timeout rollback of cross-chain transactions.
[0167] Referring toFigure 5 Fig. 5 shows a schematic diagram of a device for processing cross-chain transaction according to an embodiment of the present application. The device can be applied to a first application chain and can include a sending module 51, a receiving module 52, a determining module 53, a calling module 54 and an updating module 55. The sending module 51 is configured to send a cross-chain transaction to a second application chain through a relay chain when a first service contract initiates the cross-chain transaction, the second application chain being a destination chain of the cross-chain transaction.
[0168] The sending module 51 is configured to send a cross-chain transaction to a second application chain through a relay chain when a first service contract initiates the cross-chain transaction, the second application chain being a destination chain of the cross-chain transaction.
[0169] The receiving module 52 is configured to receive feedback information returned by the relay chain for the cross-chain transaction, the feedback information including a transaction serial number and a feedback result.
[0170] The determining module 53 is configured to determine a first count value recorded in a first cross-chain contract, the first count value being used to identify a number of feedback information received by the first application chain.
[0171] The calling module 54 is configured to call the first service contract according to the feedback result to process the cross-chain transaction on the first application chain if the transaction serial number matches the first count value.
[0172] The updating module 55 is configured to update the first count value.
[0173] In a possible implementation, the calling module 54 includes:
[0174] The verifying sub-module is configured to verify signature information of the transaction receipt, the signature information being obtained by signing the transaction receipt by a plurality of consensus nodes of the relay chain.
[0175] The interface calling sub-module is configured to call a corresponding interface of the first service contract according to the feedback result to process the cross-chain transaction on the first application chain if the signature information of the transaction receipt passes the verification.
[0176] In a possible implementation, the interface calling sub-module includes:
[0177] The callback unit is configured to call a callback interface of the first service contract to complete the cross-chain transaction if the feedback result is transaction success.
[0178] The rollback unit is configured to call a rollback interface of the first service contract to rollback the cross-chain transaction if the feedback result is transaction failure.
[0179] In a possible implementation, the device further includes:
[0180] The cross-chain contract updating module is configured to update, in the first cross-chain contract, first cross-chain transaction information of the first application chain and a second count value, the first cross-chain transaction information being used to describe information of a cross-chain transaction initiated by the first application chain as a source chain, and the second count value being used to identify a number of cross-chain transactions initiated by the first application chain.
[0181] The count value determining module is configured to determine the second count value and a received transaction count value in the relay chain, the received transaction count value being used to identify a number of cross-chain transactions received by the relay chain from the first application chain.
[0182] The resending module is configured to, if the second count value and the received transaction count value are not equal, send, according to the first cross-chain transaction information, a cross-chain transaction with a transaction serial number greater than the received transaction count value and less than or equal to the second count value to the relay chain through the first cross-chain gateway.
[0183] Reference Figure 6 , a schematic diagram of a cross-chain transaction processing device provided by an embodiment of the present application is shown, the device being applied to a second application chain and specifically can include a receiving module 61, an obtaining module 62, a generating module 63, a sending module 64, and an updating module 65, where:
[0184] The receiving module 61 is configured to receive a cross-chain transaction forwarded by a relay chain, the cross-chain transaction having a transaction serial number.
[0185] The obtaining module 62 is configured to obtain a third count value recorded in a second cross-chain contract, the third count value being used to identify a number of cross-chain transactions received by the second application chain.
[0186] The generating module 63 is configured to, if the transaction serial number matches the third count value, execute the cross-chain transaction to obtain a transaction receipt.
[0187] The sending module 64 is configured to send the transaction receipt to a first application chain through the relay chain, the first application chain being a source chain of the cross-chain transaction, and the first application chain being configured to process the cross-chain transaction according to the transaction receipt.
[0188] The updating module 65 is configured to update the third count value.
[0189] In a possible implementation, the generating module 63 includes:
[0190] The verifying submodule is configured to verify signature information of the cross-chain transaction, the signature information being obtained by signature of the cross-chain transaction by a plurality of consensus nodes of the relay chain.
[0191] The calling submodule is configured to, if the signature information of the cross-chain transaction is verified, invoke a second business contract of the second application chain to execute the cross-chain transaction, and obtain a transaction execution result.
[0192] The generating submodule is configured to generate the transaction receipt according to the transaction execution result.
[0193] In a possible implementation, the apparatus further includes:
[0194] The rollback module is configured to, if the transaction execution result is a transaction failure, invoke a rollback interface of the second business contract to restore the second application chain to a state before the execution of the cross-chain transaction.
[0195] In a possible implementation, the apparatus further includes:
[0196] The rollback notification receiving module is configured to, when receiving a rollback notification from the relay chain, determine a transaction serial number of a cross-chain transaction to be rolled back corresponding to the rollback notification.
[0197] The first rollback module is configured to, if the third count value is less than the transaction serial number of the cross-chain transaction to be rolled back, return information that the cross-chain transaction to be rolled back is successfully rolled back to the relay chain.
[0198] The second rollback module is configured to, if the third count value is greater than or equal to the transaction serial number of the cross-chain transaction to be rolled back, invoke a business contract corresponding to the cross-chain transaction to be rolled back to roll back the cross-chain transaction to be rolled back.
[0199] Referring to Figure 7 , a schematic diagram of a cross-chain transaction processing apparatus provided by an embodiment of the present application is shown, which can be applied to a relay chain and specifically can include a first verification module 71, a first signature module 72, a first sending module 73, a second verification module 74, a second signature module 75, and a second sending module 76, where:
[0200] The first verification module 71 is configured to, when receiving a cross-chain transaction from a first application chain, verify the cross-chain transaction, the cross-chain transaction having a timeout time.
[0201] The first signature module 72 is configured to, if the cross-chain transaction is verified, sign the cross-chain transaction by a plurality of consensus nodes of the relay chain.
[0202] The first sending module 73 is configured to send the signed cross-chain transaction to a second application chain, the second application chain being a destination chain of the cross-chain transaction.
[0203] The second verification module 74 is configured to, within the timeout time, if the transaction receipt returned by the second application chain for the cross-chain transaction is received, verify the transaction receipt.
[0204] The second signature module 75 is configured to, if the transaction receipt is verified, sign the transaction receipt by the plurality of consensus nodes.
[0205] The second sending module 76 is configured to send the signed transaction receipt to the first application chain, so that the first application chain completes the cross-chain transaction or rolls back the cross-chain transaction according to the transaction receipt.
[0206] In a possible implementation, the apparatus further includes:
[0207] The rollback notification sending module is configured to, if the transaction receipt returned by the second application chain for the cross-chain transaction is not received within the timeout time, send a rollback notification for the cross-chain transaction to the first application chain and the second application chain.
[0208] For the apparatus embodiment, since it is basically similar to the method embodiment, it is described more simply, and the related parts refer to the description in the method embodiment.
[0209] Figure 8 A structural schematic diagram of a computer device is provided for an embodiment of the present application. As shown in the figure, the computer device 8 of the embodiment includes at least one processor 80 (only one processor is shown in the figure), a memory 81, and a computer program 82 stored in the memory 81 and executable on the at least one processor 80, wherein the processor 80 implements the steps in any of the above method embodiments when executing the computer program 82. Figure 8 Figure 8 The computer device 8 can be a desktop computer, a notebook computer, a palm computer, and a cloud computer device, etc. The computer device can include, but is not limited to, the processor 80 and the memory 81. Those skilled in the art can understand that the computer device 8 is only an example, and does not constitute a limitation on the computer device 8, and can include more or fewer components than those shown, or combine certain components, or different components, for example, can also include an input / output device, a network access device, etc.
[0210] The computer device 8 can be a desktop computer, a notebook computer, a palm computer, and a cloud computer device, etc. The computer device can include, but is not limited to, the processor 80 and the memory 81. Those skilled in the art can understand that the computer device 8 is only an example, and does not constitute a limitation on the computer device 8, and can include more or fewer components than those shown, or combine certain components, or different components, for example, can also include an input / output device, a network access device, etc. Figure 8
[0211] The processor 80 can be a central processing unit (CPU), and can also be other general-purpose processors, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or the like. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor.
[0212] The memory 81 can be an internal storage unit of the computer device 8 in some embodiments, for example, a hard disk or a memory of the computer device 8. The memory 81 can also be an external storage device of the computer device 8 in other embodiments, for example, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, or the like. Further, the memory 81 can include both an internal storage unit and an external storage device of the computer device 8. The memory 81 is used to store an operating system, an application program, a boot loader, data, and other programs, for example, program codes of the computer program, and the like. The memory 81 can also be used to temporarily store data that has been output or will be output.
[0213] The embodiments of the present application further provide a computer readable storage medium, which stores a computer program. The computer program is executed by a processor to implement the steps in each of the above-mentioned method embodiments.
[0214] The embodiments of the present application provide a computer program product. When the computer program product is run on a computer device, the computer device is enabled to implement the steps in each of the above-mentioned method embodiments.
[0215] In the above embodiments, the description of each embodiment has its own focus, and the parts not described or recorded in detail in a certain embodiment can be referred to the relevant description of other embodiments.
[0216] The above-described embodiments are merely used to illustrate the technical solutions of the present application, but not to limit the same. Although the present application is described in detail with reference to the foregoing embodiments, it should be understood by those skilled in the art that the technical solutions recorded in the foregoing embodiments can be modified, or some of the technical features can be replaced equivalently, and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application.
Claims
1. A method for processing cross-chain transactions, characterized in that, The method applied to the first application chain comprises: When the first service contract initiates a cross-chain transaction, sending the cross-chain transaction to a second application chain through a relay chain, the second application chain being a destination chain of the cross-chain transaction; Receiving feedback information returned by the relay chain for the cross-chain transaction, the feedback information comprising a transaction serial number and a feedback result, the transaction serial number being used to identify the order of the cross-chain transaction sent by the second application chain to the first application chain; Determining a first count value recorded in a first cross-chain contract, the first count value being used to identify the number of feedback information received by the first application chain; If the transaction serial number matches the first count value, calling the first service contract according to the feedback result to process the cross-chain transaction on the first application chain; Updating the first count value.
2. The method of claim 1, wherein, The calling of the first service contract according to the feedback result comprises: Verifying signature information of the feedback information, the signature information being obtained by signing the feedback information by a plurality of consensus nodes of the relay chain; If the signature information of the feedback information passes the verification, calling a corresponding interface of the first service contract according to the feedback result to process the cross-chain transaction on the first application chain.
3. The method of claim 2, wherein, The calling of the corresponding interface of the first service contract according to the feedback result to process the cross-chain transaction on the first application chain comprises: If the feedback result is a transaction success, calling a callback interface of the first service contract to complete the cross-chain transaction; If the feedback result is a transaction failure or a timeout rollback, calling a rollback interface of the first service contract to rollback the cross-chain transaction.
4. The method according to any one of claims 1 to 3, characterized in that, The method further comprises: In the first cross-chain contract, updating first cross-chain transaction information of the first application chain and a second count value, the first cross-chain transaction information being used to describe information of the cross-chain transaction initiated by the first application chain as a source chain, and the second count value being used to identify the number of cross-chain transactions initiated by the first application chain; Determining the second count value and a received transaction count value in the relay chain, the received transaction count value being used to identify the number of cross-chain transactions received by the relay chain from the first application chain; If the second count value and the received transaction count value are not equal, sending, according to the first cross-chain transaction information, a cross-chain transaction with a transaction serial number greater than the received transaction count value and less than or equal to the second count value to the relay chain through the first cross-chain gateway.
5. A method for processing cross-chain transactions, characterized in that, The method applied to the second application chain comprises: Receiving a cross-chain transaction forwarded by a relay chain, the cross-chain transaction having a transaction serial number, the transaction serial number being used to identify the order of the cross-chain transaction sent by the second application chain to a first application chain; Obtaining a third count value recorded in a second cross-chain contract, the third count value being used to identify the number of cross-chain transactions received by the second application chain; If the transaction serial number matches the third count value, executing the cross-chain transaction to obtain a transaction receipt; sending the transaction receipt to a first application chain through the relay chain, the first application chain being an origin chain of the cross-chain transaction, the first application chain being configured to process the cross-chain transaction according to the transaction receipt; updating the third count value.
6. The method of claim 5, wherein, The method further comprises: when receiving a rollback notification from the relay chain, determining a transaction serial number of a cross-chain transaction to be rolled back corresponding to the rollback notification; if the third count value is less than the transaction serial number of the cross-chain transaction to be rolled back, returning information that the cross-chain transaction to be rolled back is successfully rolled back to the relay chain; if the third count value is greater than or equal to the transaction serial number of the cross-chain transaction to be rolled back, calling a business contract corresponding to the cross-chain transaction to be rolled back to roll back the cross-chain transaction to be rolled back.
7. A method for processing cross-chain transactions, characterized in that, The method applied to a relay chain, the method comprising: when receiving a cross-chain transaction from a first application chain, verifying the cross-chain transaction, the cross-chain transaction having a timeout time; if the cross-chain transaction passes the verification, signing the cross-chain transaction by a plurality of consensus nodes of the relay chain; sending the signed cross-chain transaction to a second application chain, the second application chain being a destination chain of the cross-chain transaction; within the timeout time, if receiving a transaction receipt returned by the second application chain for the cross-chain transaction, verifying the transaction receipt; if the transaction receipt passes the verification, signing the transaction receipt by the plurality of consensus nodes; sending the signed transaction receipt to the first application chain, the first application chain being configured to complete the cross-chain transaction or roll back the cross-chain transaction according to the transaction receipt, the transaction receipt having a transaction serial number, the transaction serial number being used to identify an order of the cross-chain transaction sent by the second application chain to the first application chain.
8. The method of claim 7, wherein, The method further comprises: if within the timeout time, the transaction receipt returned by the second application chain for the cross-chain transaction is not received, sending a rollback notification for the cross-chain transaction to the first application chain and the second application chain.
9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, The processor implements the method of any one of claims 1-8 when executing the computer program.
10. A computer-readable storage medium storing a computer program, the computer program comprising instructions that, when executed by a computer, cause the computer to perform the method of any one of claims 1 to 9. The computer program implements the method of any one of claims 1-8 when executed by the processor.
Citation Information
Patent Citations
Cross-chain relay platform-based cross-chain method and system
CN108269190A
Block chain cross-chain transaction method based on smart contract sequencing
CN114548993A