A cross-chain transaction processing method, device, equipment and medium
By determining the smart contracts and contract interfaces related to cross-chain transactions on the blockchain, generating a global transaction identifier, and adopting a double-layer locking mechanism, the complexity of cross-chain transaction request processing is solved, and efficient and atomic processing of cross-chain transactions is achieved.
Patent Information
- Application Number
- CN202411818276.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-11
- Publication Date
- 2025-09-30
- Estimated Expiration
- 2044-12-11
AI Technical Summary
Existing technologies cannot effectively process cross-chain transaction requests, especially when calling smart contracts between different blockchains, which is complicated.
By determining the smart contracts and contract interfaces related to cross-chain transactions on the source and target blockchains, generating a global transaction identifier, and adopting a double-layer locking mechanism (local lock and global lock) for resource management, the atomicity and efficiency of cross-chain transactions are ensured.
It achieves the successful processing of cross-chain transaction requests, improves the processing efficiency of cross-chain transactions, reduces the impact on non-cross-chain transactions, and supports complex calling scenarios.
Smart Images

Figure CN119629250B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of blockchain technology, and in particular to a cross-chain transaction processing method, device, equipment and medium. Background Art
[0002] Smart contracts are generally programs written in programming languages such as Solidity, Vyper, and Go that can run on the blockchain. They can be applied in scenarios such as supply chain management, financial services, and healthcare.
[0003] Users can initiate smart contract-related transaction requests on the blockchain. When the terms of the smart contract are met, the smart contract will be automatically executed without the need for third-party intervention. Related technologies can call multiple smart contracts on the same blockchain to execute related transactions based on user transaction requests, meeting user needs.
[0004] However, when the user's transaction request is a cross-chain transaction request, that is, it involves calling smart contracts on different blockchains to perform transaction processing, the operations involved are more complicated, and the relevant technology cannot effectively implement the processing of cross-chain transaction requests. Summary of the Invention
[0005] The present invention provides a cross-chain transaction processing method, device, equipment and medium to solve the defect in related technologies that cross-chain transaction requests cannot be effectively processed, and effectively process cross-chain transaction requests.
[0006] In a first aspect, the present invention provides a cross-chain transaction processing method, applied to a source blockchain; the method comprises:
[0007] The source blockchain receives a cross-chain transaction request sent by a user, wherein the cross-chain transaction request includes a blockchain identifier, a smart contract identifier, a smart contract call relationship, contract interface information, and contract call data;
[0008] The source blockchain determines the first smart contract, first contract interface, target blockchain, second smart contract, and second contract interface related to the cross-chain transaction based on the blockchain identifier, the smart contract identifier, and the contract interface information in the cross-chain transaction request, and generates a corresponding global transaction identifier based on the cross-chain transaction request; wherein the first smart contract and the second smart contract are deployed on the source blockchain and the target blockchain, respectively, and the first contract interface and the second contract interface are the contract interfaces of the first smart contract and the second smart contract, respectively;
[0009] If the source blockchain determines that the global lock state of the first smart contract is unlocked, the global lock state of the first smart contract is changed from unlocked to locked, and the first smart contract is called to perform transaction processing based on the smart contract call relationship, the first contract interface, and the contract call data to obtain a first processing result, and the first processing result and the global transaction identifier are correspondingly saved;
[0010] The source blockchain sends the cross-chain transaction request and the global transaction identifier to the target blockchain, so that the target blockchain: determines, based on the cross-chain transaction request, that the global state of the second smart contract is unlocked, modifies the global lock state of the second smart contract from unlocked to locked, and calls the second smart contract to perform transaction processing based on the smart contract call relationship, the second contract interface, and the contract call data to obtain a second processing result, correspondingly saves the second processing result and the global transaction identifier, and when determining that the second processing result is successful, returns the corresponding second processing result and the global transaction identifier to the source blockchain;
[0011] If the source blockchain determines that the first processing result and the second processing result corresponding to the global transaction identifier are successful, then the global processing result is determined to be successful.
[0012] Optionally, the first contract interface includes a locking interface and a business interface;
[0013] The calling the first smart contract to perform transaction processing to obtain a first processing result according to the smart contract calling relationship, the first contract interface, and the contract calling data includes:
[0014] The source blockchain adjusts the local lock state of the first smart contract from unlocked to locked through the locking interface in the first contract interface, and calls the first smart contract for transaction processing to obtain the first processing result according to the smart contract call relationship, the business interface in the first contract interface and the contract call data.
[0015] Optionally, the first contract interface also includes an unlocking interface;
[0016] After determining that the global processing result is successful, the method further includes:
[0017] The source blockchain adjusts the local lock state of the first smart contract from locked to unlocked through the unlocking interface, and adjusts the global lock state of the first smart contract from locked to unlocked.
[0018] Optionally, the first contract interface also includes a snapshot interface and a recovery interface;
[0019] Before the source blockchain adjusts the local lock state of the first smart contract from unlocked to locked through the lock interface in the first contract interface, the method further includes:
[0020] The source blockchain backs up the contract data of the first smart contract through the snapshot interface to obtain backup data, and saves the backup data;
[0021] After obtaining the first processing result, the method further includes:
[0022] If the source blockchain determines that the first processing result or the transaction processing result of the target blockchain is a failure, the global processing result is determined to be a failure, and the data of the first smart contract is rolled back based on the recovery interface and the backup data. The local lock state of the first smart contract is adjusted from locked to unlocked through the unlocking interface, and the global lock state of the first smart contract is adjusted from locked to unlocked.
[0023] Optionally, the source blockchain determines that the transaction processing result of the target blockchain is a failure, including:
[0024] When the source blockchain determines that the transaction processing result sent by the target blockchain is a failure, the source blockchain determines that the transaction processing result of the target blockchain is a failure;
[0025] or,
[0026] When the source blockchain sends the cross-chain transaction request to the target blockchain, it starts timing and records the timing duration; if the transaction processing result sent by the target blockchain is not received before the timing duration exceeds the preset duration threshold, it is determined that the transaction processing of the target blockchain has timed out, and the transaction processing result of the target blockchain is determined to be a failure.
[0027] Optionally, after obtaining the first processing result, the method further includes:
[0028] When the source blockchain determines that the first processing result is successful, the corresponding first processing result and the global transaction identifier are sent to the target blockchain, so that the target blockchain: when it is determined that the first processing result and the second processing result corresponding to the global transaction identifier are successful, the global processing result is determined to be successful.
[0029] Optionally, the blockchain identifier includes the chain identifier of the source blockchain and the chain identifier of the target blockchain;
[0030] The first smart contract and the second smart contract each include at least one smart contract;
[0031] The first contract interface includes the contract interface of each smart contract in the first smart contract, and the second contract interface includes the contract interface of each smart contract in the second smart contract;
[0032] The smart contract identifier includes the contract address of each smart contract in the first smart contract and the contract address of each smart contract in the second smart contract;
[0033] The smart contract calling relationship is the calling relationship between all the smart contracts.
[0034] In a second aspect, the present invention provides a cross-chain transaction processing device, which is applied to a source blockchain; the device comprises:
[0035] A receiving unit, configured to receive a cross-chain transaction request sent by a user, wherein the cross-chain transaction request includes a blockchain identifier, a smart contract identifier, a smart contract call relationship, contract interface information, and contract call data;
[0036] A first determining unit is configured to determine, based on the blockchain identifier, the smart contract identifier, and the contract interface information in the cross-chain transaction request, a first smart contract, a first contract interface, a target blockchain, a second smart contract, and a second contract interface related to the cross-chain transaction; and generate a corresponding global transaction identifier based on the cross-chain transaction request;
[0037] A generating unit, configured to generate a corresponding global transaction identifier according to the cross-chain transaction request;
[0038] a modification unit, configured to determine that the global lock state of the first smart contract is unlocked, and then modify the global lock state of the first smart contract from unlocked to locked;
[0039] a calling unit, configured to call the first smart contract to perform transaction processing to obtain a first processing result based on the smart contract calling relationship, the first contract interface, and the contract calling data;
[0040] a storage unit, configured to correspondingly store the first processing result and the global transaction identifier;
[0041] a sending unit, configured to send the cross-chain transaction request and the global transaction identifier to the target blockchain, so that the target blockchain: determines, based on the cross-chain transaction request, that the global state of the second smart contract is unlocked, modifies the global lock state of the second smart contract from unlocked to locked, and calls the second smart contract to perform transaction processing based on the smart contract call relationship, the second contract interface, and the contract call data to obtain a second processing result, correspondingly saves the second processing result and the global transaction identifier, and when determining that the second processing result is successful, returns the corresponding second processing result and the global transaction identifier to the source blockchain;
[0042] The second determining unit is configured to determine that if the first processing result and the second processing result corresponding to the global transaction identifier are successful, then determine that the global processing result is successful.
[0043] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the cross-chain transaction processing method of the first aspect or any corresponding embodiment thereof.
[0044] The cross-chain transaction processing method, apparatus, device and medium provided by the present invention, the source blockchain can receive a cross-chain transaction request sent by a user, determine the target blockchain, smart contract, contract interface, contract call data and smart contract call relationship involved in the cross-chain transaction according to the cross-chain transaction request, generate a global transaction identifier corresponding to the cross-chain transaction request, perform cross-chain transaction processing according to the target blockchain, smart contract, contract interface, contract call data and smart contract call relationship involved in the cross-chain transaction to obtain a first processing result, save the global transaction identifier and the first processing result accordingly, send the cross-chain transaction request and the global transaction identifier to the target blockchain, so that the target blockchain performs cross-chain transaction processing to obtain a second processing result and save the second processing result and the global transaction identifier accordingly, when it is determined that the first processing result and the second processing result corresponding to the global transaction identifier are successful, the global processing result of the cross-chain transaction request is determined to be successful, thereby effectively realizing the processing of the cross-chain transaction request. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the technical solutions in the present invention or the prior art, a brief introduction is given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0046] Figure 1 A flowchart of a cross-chain transaction processing method provided by an embodiment of the present invention;
[0047] Figure 2 A schematic diagram of the structure of a cross-chain transaction processing device provided by an embodiment of the present invention;
[0048] Figure 3 A schematic structural diagram of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0049] To make the objectives, technical solutions, and advantages of the present invention more clear, the technical solutions of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the embodiments described are only some of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.
[0050] The following combination Figure 1 Describe the cross-chain transaction processing method of the present invention.
[0051] like Figure 1 As shown, this embodiment proposes a first cross-chain transaction processing method, which is applied to the source blockchain. The method may include the following steps:
[0052] S101. The source blockchain receives a cross-chain transaction request sent by a user. The cross-chain transaction request includes a blockchain identifier, a smart contract identifier, a smart contract call relationship, contract interface information, and contract call data.
[0053] The source blockchain is the blockchain that directly receives the cross-chain transaction request sent by the user. It is understood that the user can upload the cross-chain transaction request to the source blockchain, which will then process the relevant cross-chain transaction based on the cross-chain transaction request to meet the user's business processing needs.
[0054] Specifically, the blockchain identifier may include the chain identifiers of each blockchain involved in this cross-chain transaction.
[0055] Among them, the smart contract identifier may include the contract address of each smart contract involved in this cross-chain transaction.
[0056] Specifically, the smart contract call relationship can be the call relationship between the various smart contracts involved in this cross-chain transaction. The smart contract call relationship can record the cascade call of the smart contracts involved in this cross-chain transaction in a tree structure. Each node in the tree represents a cross-chain business smart contract involved in the cross-chain transaction, and its child nodes represent the cross-chain business smart contracts it calls. The nodes record the specific cross-chain business smart contract call information.
[0057] The contract interface information may include information about the contract interfaces of each smart contract involved in the cross-chain transaction. The source blockchain can determine the contract interfaces of the relevant smart contracts based on the contract interface information.
[0058] Specifically, the contract call data may be the call data of the smart contract, which may include relevant parameter information required to call the smart contract interface. In this embodiment, the contract interface of the smart contract may be called based on the contract call data, so that the contract interface of the smart contract performs corresponding transaction processing.
[0059] Optionally, the blockchain identifier includes the chain identifier of the source blockchain and the chain identifier of the target blockchain;
[0060] The first smart contract and the second smart contract each include at least one smart contract;
[0061] The first contract interface includes the contract interface of each smart contract in the first smart contract, and the second contract interface includes the contract interface of each smart contract in the second smart contract;
[0062] The smart contract identifier includes the contract address of each smart contract in the first smart contract and the contract address of each smart contract in the second smart contract;
[0063] The smart contract calling relationship is the calling relationship between all smart contracts.
[0064] Optionally, the cross-chain transaction request may also include timestamp and routing information.
[0065] Optionally, a transaction registration interface may be provided in the source blockchain. In this case, the user may upload the cross-chain transaction request to the transaction registration interface in the source blockchain, triggering the transaction registration interface to start transaction processing.
[0066] In practice, users on the source and target blockchains can use the communication methods provided by the cross-chain architecture to exchange their respective chain identification information, contract information, and their own routing information. This information, such as the blockchain identification, smart contract identification, smart contract call relationships, contract interface information, and contract call data required in cross-chain transaction requests, prepares to initiate cross-chain transactions. For example, users on the two chains exchange information such as blockchain identification and smart contract identification through peer-to-peer (P2P) communication. Another example is a relay chain within the cross-chain architecture that records information such as the blockchain identification and smart contract identification of both chains, allowing users on both chains to query the relay chain.
[0067] S102. The source blockchain determines the first smart contract, first contract interface, target blockchain, second smart contract, and second contract interface related to the cross-chain transaction based on the blockchain identifier, smart contract identifier, and contract interface information in the cross-chain transaction request. The first smart contract and the second smart contract are deployed on the source blockchain and the target blockchain, respectively, and the first contract interface and the second contract interface are the contract interfaces of the first smart contract and the second smart contract, respectively.
[0068] Specifically, after receiving a cross-chain transaction request, the source blockchain can parse the request to obtain the blockchain identifier, smart contract identifier, smart contract call relationship, contract interface information, and contract call data carried in the cross-chain transaction request. The source blockchain can then use the blockchain identifier and smart contract identifier to identify all blockchains and smart contracts participating in the cross-chain transaction, specifically including the target blockchain, the first smart contract, and the second smart contract.
[0069] Among them, the target blockchain is the blockchain that the source blockchain needs to interact with to execute cross-chain transactions.
[0070] Specifically, the source blockchain may also determine the contract interface of the first smart contract, i.e., the first contract interface, and the contract interface of the second smart contract, i.e., the second contract interface, based on the contract interface information. The source blockchain may also determine the calling relationship between the smart contracts on the source blockchain and the target blockchain, i.e., the calling relationship between the first smart contract and the second smart contract, based on the smart contract calling relationship.
[0071] Optionally, when a transaction registration interface is set in the source blockchain, the transaction registration interface can receive a cross-chain transaction request and parse the cross-chain transaction request, determine and record the first smart contract, first contract interface, target blockchain, second smart contract and second contract interface related to the cross-chain transaction.
[0072] S103. The source blockchain generates a corresponding global transaction identifier based on the cross-chain transaction request.
[0073] Specifically, the source blockchain can generate a globally unique cross-chain transaction identifier, or global transaction identifier, based on the cross-chain transaction request and the related information it carries. The global transaction identifier can be used as an identifier for this cross-chain transaction on both the source and target blockchains, and can be used as an index when querying cross-chain transaction data and execution results.
[0074] Specifically, the source blockchain can generate a global transaction identifier corresponding to the cross-chain transaction request based on a universally unique identifier (UUID).
[0075] S104. If the source blockchain determines that the global lock state of the first smart contract is unlocked, the global lock state of the first smart contract is changed from unlocked to locked.
[0076] Specifically, for smart contracts that need to participate in cross-chain transaction processing, this embodiment can set a global lock on them and set a variable for identifying the global lock state. The global lock state is identified by the parameter value of the variable. It should be noted that the global lock state of a smart contract can include locked and unlocked.
[0077] Specifically, after determining the first smart contract, the source blockchain can obtain the global lock status of each smart contract in the first smart contract. If the global lock status of each smart contract in the first smart contract is unlocked, it can be determined that the cross-chain resources of each smart contract in the first smart contract are not occupied, and the global lock status of each smart contract in the first smart contract is adjusted to locked, so that this cross-chain transaction can occupy the cross-chain resources of each smart contract in the first smart contract separately, and perform subsequent cross-chain transaction processing on the first smart contract, thereby preventing other cross-chain transactions from calling any smart contract in the first smart contract for cross-chain transaction processing during the processing of this cross-chain transaction.
[0078] It is understandable that after the source blockchain obtains the global lock status of the first smart contract, if it determines that the global lock status of any smart contract in the first smart contract is locked, it can be determined that the cross-chain resources of the first smart contract are occupied and the first smart contract cannot participate in this cross-chain transaction. At this time, the source blockchain can stop executing this cross-chain transaction and can directly determine that the execution result of the cross-chain transaction is a failure.
[0079] S105. The source blockchain calls the first smart contract to perform transaction processing to obtain a first processing result based on the smart contract call relationship, the first contract interface and the contract call data.
[0080] Specifically, after changing the global lock status of each smart contract in the first smart contract from unlocked to locked, the source blockchain can call each smart contract in the first smart contract to perform business processing according to the smart contract call relationship, the first contract interface and the contract call data to obtain a first processing result.
[0081] It should be noted that the first processing result can be success or failure. It is understood that when the processing result of each smart contract in the first smart contract is success, the first processing result is success. When the processing result of any smart contract in the first smart contract is failure, the first processing result is failure.
[0082] S106: Save the first processing result and the global transaction identifier accordingly.
[0083] Specifically, the source blockchain can save the first processing result and the global transaction identifier in correspondence.
[0084] S107. The source blockchain sends the cross-chain transaction request and the global transaction identifier to the target blockchain, so that the target blockchain: determines that the global state of the second smart contract is unlocked according to the cross-chain transaction request, then changes the global lock state of the second smart contract from unlocked to locked, and calls the second smart contract to perform transaction processing based on the smart contract call relationship, the second contract interface and the contract call data to obtain a second processing result, correspondingly saves the second processing result and the global transaction identifier, and when it is determined that the second processing result is successful, returns the corresponding second processing result and the global transaction identifier to the source blockchain.
[0085] It should be noted that, in the process where the target blockchain performs transaction processing based on the cross-chain transaction request to obtain the second processing result, except that a new global transaction identifier is no longer generated based on the cross-chain transaction request, the other steps can refer to the process where the source blockchain performs transaction processing based on the cross-chain transaction request to obtain the first processing result.
[0086] Among them, after receiving the cross-chain transaction request and the global transaction identifier, the target blockchain can parse the cross-chain transaction request to obtain the blockchain identifier, smart contract identifier, smart contract call relationship, contract interface information, and contract call data carried in the cross-chain transaction request. Afterwards, the target blockchain can determine the first smart contract, the first contract interface, the target blockchain, the second smart contract, and the second contract interface related to the cross-chain transaction based on the blockchain identifier, the smart contract identifier, and the contract interface information, and obtain the global lock status of each smart contract in the second smart contract. When it is determined that the global lock status of each smart contract in the second smart contract is unlocked, the global lock status of each smart contract in the second smart contract is changed from unlocked to locked, and each smart contract in the second smart contract is called according to the smart contract call relationship, the second contract interface, and the contract call data to perform transaction processing to obtain a second processing result, and correspondingly save the second processing result and the global transaction identifier.
[0087] It is understandable that after the target blockchain obtains the global lock status of each smart contract in the second smart contract, if it is determined that the global lock status of any smart contract in the second smart contract is locked, it can be determined that the cross-chain resources of the second smart contract are occupied and the second smart contract cannot participate in this cross-chain transaction. At this time, the target blockchain can stop executing this cross-chain transaction and can directly determine that the execution result of the cross-chain transaction is a failure.
[0088] S108. The source blockchain determines that the first processing result and the second processing result corresponding to the global transaction identifier are successful, and then determines that the global processing result is successful.
[0089] Specifically, the source blockchain can determine that the global processing result is successful when it is determined that the first processing result and the second processing result corresponding to the global transaction identifier are both successful.
[0090] Optionally, when the source blockchain determines that the first processing result or the second processing result corresponding to the global transaction identifier is a failure, the global processing result is determined to be a failure.
[0091] The cross-chain transaction processing method proposed in this embodiment is that the source blockchain can receive a cross-chain transaction request sent by a user, determine the target blockchain, smart contract, contract interface, contract call data and smart contract call relationship involved in the cross-chain transaction according to the cross-chain transaction request, generate a global transaction identifier corresponding to the cross-chain transaction request, perform cross-chain transaction processing according to the target blockchain, smart contract, contract interface, contract call data and smart contract call relationship involved in the cross-chain transaction to obtain a first processing result, save the global transaction identifier and the first processing result accordingly, send the cross-chain transaction request and the global transaction identifier to the target blockchain, so that the target blockchain executes the cross-chain transaction processing to obtain a second processing result and saves the second processing result and the global transaction identifier accordingly. When it is determined that the first processing result and the second processing result corresponding to the global transaction identifier are successful, the global processing result of the cross-chain transaction request is determined to be successful, thereby effectively implementing the processing of the cross-chain transaction request.
[0092] based on Figure 1 This embodiment proposes a second cross-chain transaction processing method. In this method, the first contract interface includes a locking interface and a business interface. In this case, step S105 includes:
[0093] The source blockchain adjusts the local lock state of the first smart contract from unlocked to locked through the locking interface in the first contract interface, and calls the first smart contract for transaction processing to obtain a first processing result based on the smart contract call relationship, the business interface in the first contract interface and the contract call data.
[0094] Specifically, this embodiment can set a local lock on a smart contract on the blockchain and set a variable for identifying the local lock status. The local lock status is identified by the parameter value of the variable. It should be noted that the local lock status of a smart contract can include locked and unlocked. When the local lock status of a smart contract is locked, it indicates that the blockchain is processing transactions for the smart contract. When the local lock status of a smart contract is unlocked, it indicates that the blockchain is not processing transactions for the smart contract.
[0095] Specifically, the source blockchain can first obtain the local lock status of each smart contract in the first smart contract. When it is determined that the local lock status of each smart contract in the first smart contract is unlocked, it means that each smart contract in the first smart contract is not currently participating in other transaction processing. The source blockchain can currently perform transaction processing on each smart contract in the first smart contract. At this time, the source blockchain can adjust the local lock status of each smart contract in the first smart contract from unlocked to locked. This cross-chain transaction can occupy the chain resources of each smart contract in the first smart contract separately, and perform subsequent transaction processing on each smart contract in the first smart contract, so as to avoid other transactions calling any smart contract in the first smart contract for transaction processing during this transaction processing.
[0096] Specifically, the source blockchain can call each smart contract in the first smart contract to perform transaction processing based on the smart contract call relationship, the business interface in the first contract interface, and the contract call data.
[0097] Optionally, the first contract interface also includes an unlocking interface. After step S108, the above method may further include:
[0098] The source blockchain adjusts the local lock state of the first smart contract from locked to unlocked through the unlocking interface, and adjusts the global lock state of the first smart contract from locked to unlocked.
[0099] It should be noted that after completing the cross-chain transaction processing, the source blockchain can adjust the local lock status and global lock status of each smart contract in the first smart contract to unlocked, so as to release the occupation of chain resources of each smart contract in the first smart contract, so that each smart contract in the first smart contract can participate in other transaction processing normally.
[0100] It is understandable that the second contract interface of the second smart contract on the target blockchain may also include a locking interface, a business interface, and an unlocking interface. During the execution of this cross-chain transaction, the target blockchain may also perform resource locking, contract calling, and resource release for each smart contract in the second smart contract.
[0101] The cross-chain transaction processing method proposed in this embodiment locks the resources in the cross-chain transaction at the contract granularity and designs a dual-layer locking mechanism of local lock and global lock. Before the cross-chain transaction is executed, it can quickly determine whether the cross-chain business smart contract involved meets the execution conditions, flexibly lock and release resources, improve processing efficiency, and effectively reduce the impact of cross-chain transactions on non-cross-chain transactions.
[0102] based on Figure 1 This embodiment proposes a third cross-chain transaction processing method, in which the first contract interface also includes a snapshot interface and a recovery interface.
[0103] At this time, the method further includes:
[0104] The source blockchain backs up the contract data of the first smart contract through the snapshot interface, obtains the backup data, and saves the backup data.
[0105] At this time, after obtaining the first processing result, the method further includes:
[0106] If the source blockchain determines that the first processing result or the transaction processing result of the target blockchain is a failure, the global processing result is determined to be a failure, and the data of the first smart contract is rolled back based on the recovery interface and the backup data, and the local lock state of the first smart contract is adjusted from locked to unlocked through the unlocking interface, and the global lock state of the first smart contract is adjusted from locked to unlocked.
[0107] Specifically, this embodiment can pre-configure a snapshot interface and a recovery interface for smart contracts that need to participate in cross-chain transactions. When the source blockchain performs a cross-chain transaction on a first smart contract, it can first call the snapshot interface to back up the contract data of each smart contract in the first smart contract to obtain the corresponding backup data. If the cross-chain transaction fails, it can call the recovery interface to roll back the data based on the backup data, restoring the contract data of each smart contract in the first smart contract to the state saved by the snapshot.
[0108] It should be noted that after the source blockchain obtains the first processing result, regardless of whether the first processing result is success or failure, the local lock and global lock of each smart contract in the first smart contract can be set to unlock, so as to avoid affecting the calls of other chain transactions or cross-chain transactions to these smart contracts.
[0109] It is understood that the second contract interface of the second smart contract on the target blockchain may also include a snapshot interface and a restore interface. During the execution of this cross-chain transaction, the target blockchain may also back up and restore data for each smart contract in the second smart contract. Similarly, after obtaining the second processing result, regardless of whether the second processing result is success or failure, the target blockchain may set the local lock and global lock of each smart contract in the second smart contract to unlock, thereby preventing it from affecting the invocation of these smart contracts by transactions on other chains or cross-chain transactions.
[0110] Optionally, the source blockchain determines that the transaction processing result of the target blockchain is a failure, including:
[0111] When the source blockchain determines that the transaction processing result sent by the target blockchain is a failure, the transaction processing result of the target blockchain is determined to be a failure;
[0112] or,
[0113] When the source blockchain sends a cross-chain transaction request to the target blockchain, it starts timing and records the timing duration; if the transaction processing result sent by the target blockchain is not received before the timing duration exceeds the preset duration threshold, the transaction processing of the target blockchain is determined to have timed out, and the transaction processing result of the target blockchain is determined to have failed.
[0114] The preset time threshold can be set by technical personnel according to actual conditions and is not limited in this embodiment.
[0115] It is understandable that in the process of determining whether the transaction processing result of the target blockchain is a failure by referring to the source blockchain, the target blockchain can also use the same method to determine whether the transaction processing result of the source blockchain is a failure.
[0116] The cross-chain transaction processing method proposed in this embodiment can call the recovery interface to roll back data based on backup data when the cross-chain transaction processing result fails, and restore the contract data of the first smart contract to the state saved by the snapshot.
[0117] based on Figure 1 This embodiment proposes a fourth cross-chain transaction processing method. In this method, after step S108, the method further includes:
[0118] When the source blockchain determines that the first processing result is successful, the corresponding first processing result and the global transaction identifier are sent to the target blockchain, so that the target blockchain: when the first processing result and the second processing result corresponding to the global transaction identifier are determined to be successful, the global processing result is determined to be successful.
[0119] Specifically, the transaction processing results can be synchronized between the source blockchain and the target blockchain, so that the source blockchain and the target blockchain can synchronize the global processing results of the cross-chain transaction request and complete this cross-chain transaction.
[0120] It should be noted that the target blockchain can determine that the global processing result is a failure when it determines that the second processing result is a failure or the transaction processing result of the source blockchain is a failure.
[0121] The cross-chain transaction processing method proposed in this embodiment can synchronize transaction processing results between the source blockchain and the target blockchain, and then synchronize the global processing results of the cross-chain transaction request, further effectively realizing the processing of cross-chain transactions.
[0122] Related cross-chain blockchain solutions typically expand upon the two-phase commit scheme used in distributed databases for cross-chain transaction processing, treating individual functions within smart contracts as the smallest unit of cross-chain transaction resources. These solutions lock resources at the function level, requiring business smart contracts on the blockchain to provide a reverse interface for each cross-chain function interface, allowing for rollbacks in the event of transaction exceptions to ensure the atomicity of cross-chain transactions. For existing non-cross-chain business smart contracts, adapting these solutions to participate in cross-chain transactions requires cumbersome code modifications and high modification costs. Furthermore, these solutions fail to account for complex scenarios such as cascading smart contract calls that may occur during the cross-chain process, making them ineffective in supporting cross-chain transactions in a wider range of scenarios.
[0123] There is an urgent need for a smart contract adaptation method that is simple to use, highly atomic, and can support complex call scenarios such as cascading calls. It can modify existing non-cross-chain business smart contracts at a low modification cost so that they can be used for cross-chain transactions between blockchains involving complex calls, and can be widely used in various cross-chain architectures.
[0124] This embodiment can enable smart contracts to adapt to cross-chain transaction requirements and effectively implement cross-chain transaction processing by executing the following process.
[0125] 1) On the two blockchains that need to conduct cross-chain transactions, write and deploy their respective cross-chain management smart contracts. This contract sets a global lock and abstracts the cross-chain standard function interface of the cross-chain business smart contract. It can manage cross-chain transactions on the blockchain, call related cross-chain business smart contracts, and ensure the atomicity of cross-chain transactions. Specifically:
[0126] 1.1) Abstract cross-chain standard function interface for cross-chain business smart contracts.
[0127] Specifically, the cross-chain standard function interfaces of the cross-chain business smart contract include four, namely, the lock interface, the unlock interface, the snapshot interface, and the recovery interface.
[0128] Among them, the locking interface can lock the cross-chain business smart contract and record the information of the locker. During the period when the cross-chain business smart contract is locked, only the locker can call other business function interfaces on the cross-chain business smart contract; correspondingly, the unlocking interface can unlock the locked cross-chain business smart contract and can only be called by the current locker.
[0129] The snapshot interface encodes the data stored in the cross-chain business smart contract and returns it in binary format. This is used to save the data of the cross-chain business smart contract before the cross-chain transaction begins. Correspondingly, the recovery interface is used to recover data when the cross-chain transaction fails. The locker calls the recovery interface and inputs the snapshot data in binary format to restore the data of the cross-chain business smart contract to the state saved by the snapshot. For example, when using the Solidity language to write a cross-chain management smart contract on the Ethereum blockchain, the interface keyword can be used to abstract the cross-chain standard function interface of the business smart contract, specify the input and output data types, and enable it to be called after the cross-chain business smart contract is instantiated.
[0130] 1.2) Write the calling interface of the cross-chain standard interface of the cross-chain business smart contract.
[0131] Specifically, for the lock, unlock, snapshot, and restore interfaces of the cross-chain business smart contract in step 1.1), write corresponding call interfaces. The call interface receives the address of the cross-chain business smart contract as an input parameter and actually calls the cross-chain business smart contract corresponding to that address. For example, when using the Solidity language to write a cross-chain management smart contract on the Ethereum blockchain, the business smart contract can be abstracted into a businessContract class using the interface keyword. This class contains the lock interface lock(), and the call interface can be written as businessContract.lock().
[0132] 1.3) Write a unified calling interface for other business function interfaces of cross-chain business smart contracts.
[0133] Specifically, in addition to the four standard cross-chain function interfaces (lock, unlock, snapshot, and restore) mentioned in step 1.1), the cross-chain business smart contract also includes specific business function interfaces. The cross-chain management smart contract calls these business function interfaces through a unified call interface. This interface inputs the address of the cross-chain business smart contract to be called and the binary data required for the call, and outputs the result of calling the cross-chain business smart contract. For example, when writing a cross-chain management smart contract on the Ethereum blockchain using the Solidity language, the encoded binary data can be obtained through the abi.encodeWithSignature() method, and the cross-chain business smart contract can be called through the call() method.
[0134] 1.4) Write cross-chain transaction registration interface and result return interface.
[0135] Specifically, the transaction registration interface is responsible for receiving cross-chain transaction requests sent by users on the blockchain, parsing the parameters contained in the request, and accordingly calling the cross-chain standard interface and business function interface of the business smart contract. During this process, the cross-chain management smart contract identifies cascading calls in cross-chain transaction requests and stores the calling relationships between contracts in a tree structure. The result return interface is used to store the results of cross-chain transaction execution for user queries and final cross-chain transaction outcome determination.
[0136] 1.5) Set a global lock.
[0137] Specifically, the global lock is a variable in the cross-chain management smart contract. The global lock establishes a mapping between the address of a cross-chain business smart contract and its lock status. When registering a cross-chain transaction, this variable can be used to quickly determine whether the cross-chain business smart contract involved in the current cross-chain transaction is locked. For example, using the mapping type in Solidity, a mapping between address and bool type is established to store the business smart contract address and whether it is locked.
[0138] 1.6) Compile and deploy the cross-chain management smart contract.
[0139] For example, the cross-chain management smart contract written in Solidity is compiled through solc to obtain the binary bytecode corresponding to the cross-chain management smart contract and deploy it on the chain.
[0140] 2) On the two blockchains that need to conduct cross-chain transactions, write and deploy the required cross-chain business smart contracts to provide specific cross-chain services. At the same time, provide atomicity guarantees for cross-chain transactions by setting local locks and writing cross-chain standard function interfaces. If there is already a non-cross-chain business smart contract, you can add a standard cross-chain function interface on top of it for adaptation. Specifically:
[0141] 2.1) Set a local lock. A local lock is a variable in a cross-chain business smart contract that records the lock status of the corresponding cross-chain business smart contract. For example, when writing a cross-chain business smart contract using Solidity, a bool type variable can be used to record the lock status of the current business smart contract.
[0142] 2.2) Write a locking interface that can modify the locking status recorded by the local lock to "locked".
[0143] 2.3) Write an unlocking interface that can modify the lock status recorded by the local lock to "unlocked".
[0144] 2.4) Write lock status verification logic. For business functions, you need to check the lock status recorded by the local lock before calling it. If it is "locked", the call will be rejected. For example, when writing a cross-chain business smart contract in Solidity, you can use the modifier keyword to declare a function modifier, write lock status judgment logic, and apply it to other existing business functions.
[0145] 2.5) Write the snapshot interface.
[0146] Specifically, the snapshot interface extracts all different types of data stored in a cross-chain business smart contract, encodes them sequentially, and returns them as a binary byte stream. For example, when writing a cross-chain business smart contract using Solidity, the abi.encode method can be used to encode all data variables and uniformly return a bytes type data.
[0147] 2.6) Write the recovery interface.
[0148] Specifically, the recovery interface is used to recover data when a cross-chain transaction fails. This interface receives a binary snapshot and uses the decoding method corresponding to the snapshot interface to restore the data of the cross-chain business smart contract in sequence and different types to the state saved by the snapshot. For example, when writing a cross-chain business smart contract using Solidity, the abi.decode method can be used to parse the input bytes snapshot data and restore it to the corresponding data type.
[0149] 2.7) Compile and deploy the cross-chain business smart contract. For example, use solc to compile the cross-chain business smart contract written in Solidity, obtain the binary bytecode corresponding to the cross-chain business smart contract, and deploy it on the chain.
[0150] 3) Users on the source and destination blockchains exchange their respective chain identification information, contract information, and their own routing information through the communication methods provided by the cross-chain architecture, preparing to initiate the cross-chain transaction. Contract information includes the address of the cross-chain business smart contract, cross-chain function interface, and parameter information. For example, users on the two chains exchange contract information, chain IDs, their own IP addresses, and ports through P2P communication. Alternatively, the cross-chain architecture may include a relay chain that records the contract information, chain IDs, user IP addresses, and ports on both chains, allowing users on both chains to query the information on the relay chain.
[0151] 4) The user on the source blockchain initiates a cross-chain transaction request, which includes a timestamp, call tree information on the source and destination blockchains, starts the cross-chain transaction, and applies for a global lock on both the source and destination blockchains. Specifically:
[0152] 4.1) The user constructs a call tree for this cross-chain transaction on both the source and destination blockchains, using a tree structure to record the cascading call details of the current cross-chain transaction. Each node in the tree represents a cross-chain business smart contract involved in the cross-chain transaction, and its child nodes represent the cross-chain business smart contracts it calls. Each node records the specific cross-chain business smart contract call information. For example, if the source blockchain has two cross-chain business smart contracts A and B deployed, and the cross-chain transaction calls function A1 in A, and A1 calls function B2 in B, then A will become B's parent node, and B will become A's child node. The nodes will record information such as the contract address, call interface, and call parameters.
[0153] 4.2) When a user initiates a transaction, they call the transaction registration interface of the cross-chain management smart contract to register the cross-chain transaction. The cross-chain management smart contract generates a globally unique cross-chain transaction ID corresponding to the cross-chain transaction. This ID will serve as the identifier of this cross-chain transaction on the source and destination blockchains, and is used as an index when querying cross-chain transaction data and execution results. For example, the cross-chain management smart contract uses methods such as UUID to generate a globally unique cross-chain transaction ID.
[0154] 4.3) The cross-chain management smart contract applies for a global lock based on the call tree information on both chains recorded during the cross-chain transaction. For all smart contracts involved in the cross-chain transaction request, the global locks must be in the "unlocked" state, meaning that cross-chain resources are not occupied. If the global lock of any smart contract is in the "locked" state, the cross-chain transaction request is rejected and a failure is reported. Otherwise, the global locks of all smart contracts are changed to the "locked" state, and the cross-chain transaction continues. For example, a bool type can be used to indicate whether a contract is locked. Suppose a cross-chain transaction calls cross-chain business smart contract A on the source blockchain and cross-chain business smart contract B on the destination blockchain. The cross-chain management smart contract will modify the bool lock variables corresponding to the A and B contract addresses to true based on the chain identification information.
[0155] 4.4) The user forwards the cross-chain transaction request to the destination blockchain according to the destination blockchain routing. The destination blockchain initiates the transaction to register the cross-chain transaction and executes step 4.3) to apply for the global lock on the destination blockchain. Then, the cross-chain transaction operation after step 5) is executed.
[0156] 5) The cross-chain management smart contract applies for a local lock and takes a snapshot, preparing to execute cross-chain transactions.
[0157] Specifically, according to the smart contract call relationship recorded by the cross-chain transaction request, the lock and snapshot interfaces in the cross-chain standard interface of the cross-chain business smart contract are called successively, the local lock status of the cross-chain business smart contract is modified to "locked", and the smart contract snapshot list corresponding to the current cross-chain transaction is obtained.
[0158] 6) The cross-chain management smart contract uniformly calls the interface through the business function of the business smart contract to execute specific cross-chain transaction requests, and uploads the results returned by the corresponding cross-chain transaction ID through the result return interface. At the same time, the result is synchronized with other participants of the cross-chain transaction through the communication method provided by the cross-chain architecture.
[0159] 7) The cross-chain management smart contract confirms the final execution result of the cross-chain transaction, specifically:
[0160] 7.1) Once the cross-chain management smart contracts on both blockchains have returned and synchronized their results, or the execution time of the cross-chain transaction has reached the specified timeout, the final execution result of the cross-chain transaction will be confirmed;
[0161] 7.2) If both parties involved in the cross-chain transaction return a successful result, the cross-chain transaction is recorded as successful and only the unlock operation is performed. Otherwise, the cross-chain transaction ultimately fails and a snapshot recovery and unlock operation are required. If the execution time of the cross-chain transaction reaches the timeout, it means that at least one party has not reported the execution result of the cross-chain transaction. In this case, the cross-chain transaction ultimately fails and a snapshot recovery and unlock operation are required.
[0162] 8) The cross-chain management smart contract performs snapshot recovery based on the final execution results.
[0163] Specifically, if the cross-chain transaction in step 7) ultimately fails, the cross-chain management smart contract calls the recovery interface in the cross-chain standard interface of the cross-chain business smart contract based on the smart contract snapshot list obtained in step 5), and uses the corresponding snapshot data in the snapshot list to restore and complete the data rollback.
[0164] 9) The cross-chain management smart contract unlocks the local lock and the global lock, completing the cross-chain transaction.
[0165] Specifically, according to the smart contract call relationship obtained in step 5), the unlocking interface in the cross-chain standard interface of the cross-chain business smart contract is called to change the local lock of the cross-chain business smart contract to "unlock"; and the global lock of the cross-chain management smart contract is modified to change the global lock of the business smart contract to "unlock".
[0166] Specifically, this embodiment allows for the compilation and deployment of separate cross-chain management smart contracts on the two blockchains that require cross-chain transactions. This contract sets a global lock and abstracts the cross-chain standard function interface of the cross-chain business smart contract. It manages cross-chain transactions on the respective blockchains, calls related cross-chain business smart contracts, and ensures cross-chain transaction atomicity. On both blockchains, the required cross-chain business smart contracts are compiled and deployed, providing specific cross-chain services. At the same time, atomicity is ensured by setting local locks and compiling cross-chain standard function interfaces. If a non-cross-chain business smart contract already exists, a standard cross-chain function interface can be added to it for adaptation. Based on the above-mentioned smart contract adaptation method, the corresponding cross-chain transaction process is as follows: the user on the source blockchain initiates a cross-chain transaction request to start the cross-chain transaction; the cross-chain management smart contract applies for a local lock and takes a snapshot, preparing to execute the cross-chain transaction; the cross-chain management smart contract uniformly calls the interface through the business function of the business smart contract, executes the specific cross-chain transaction request, and uploads the result returned by the call through the result return interface, and synchronizes the result with other participants in the cross-chain transaction; the cross-chain management smart contract confirms the final execution result of the cross-chain transaction, performs a snapshot recovery based on the final execution result, unlocks the local lock and the global lock, and completes this cross-chain transaction.
[0167] This embodiment can cost-effectively transform existing non-cross-chain business smart contracts into cross-chain business smart contracts that support cross-chain features, and additionally provides a cross-chain management smart contract to manage cross-chain transactions. This embodiment can support complex call scenarios such as cascading calls while ensuring the atomicity and security of cross-chain transactions. This embodiment is designed to be highly scalable and can be migrated to any blockchain that supports smart contracts or chaincodes for cross-chain transaction processing on that blockchain.
[0168] This embodiment can adapt to mainstream smart contract development by designing a set of standard cross-chain function interfaces, reducing the cost of migrating and transforming non-cross-chain business smart contracts to cross-chain business smart contracts, avoiding the disadvantages of related technologies that require separate modifications to each business function, reducing intrusion, and better adapting to non-cross-chain smart contracts that are currently in use.
[0169] This embodiment introduces a cross-chain management smart contract to record the specific call status of cross-chain transactions. It can handle complex cascading calls formed by calls between smart contracts. It also combines snapshot and recovery mechanisms to ensure the atomicity of cross-chain transactions and the correctness of data in each business smart contract in complex cascading call scenarios. It can be applied to various cross-chain architectures.
[0170] like Figure 2 As shown, this embodiment proposes a cross-chain transaction processing device, which is applied to the source blockchain. The device includes:
[0171] Receiving unit 201, configured to receive a cross-chain transaction request sent by a user, wherein the cross-chain transaction request includes a blockchain identifier, a smart contract identifier, a smart contract call relationship, contract interface information, and contract call data;
[0172] The first determining unit 202 is configured to determine the first smart contract, first contract interface, target blockchain, second smart contract, and second contract interface related to the cross-chain transaction based on the blockchain identifier, smart contract identifier, and contract interface information in the cross-chain transaction request; and generate a corresponding global transaction identifier based on the cross-chain transaction request;
[0173] A generating unit 203 is configured to generate a corresponding global transaction identifier according to the cross-chain transaction request;
[0174] A modification unit 204 is configured to determine that the global lock state of the first smart contract is unlocked, and then modify the global lock state of the first smart contract from unlocked to locked;
[0175] A calling unit 205 is configured to call the first smart contract to perform transaction processing to obtain a first processing result based on the smart contract calling relationship, the first contract interface, and the contract calling data;
[0176] A storage unit 206 is configured to store the first processing result and the global transaction identifier accordingly;
[0177] A sending unit 207 is configured to send the cross-chain transaction request and the global transaction identifier to the target blockchain, so that the target blockchain: determines that the global state of the second smart contract is unlocked according to the cross-chain transaction request, changes the global lock state of the second smart contract from unlocked to locked, and calls the second smart contract to perform transaction processing based on the smart contract call relationship, the second contract interface, and the contract call data to obtain a second processing result, stores the second processing result and the global transaction identifier accordingly, and returns the corresponding second processing result and the global transaction identifier to the source blockchain when the second processing result is determined to be successful;
[0178] The second determining unit 208 is configured to determine that the first processing result and the second processing result corresponding to the global transaction identifier are successful, and then determine that the global processing result is successful.
[0179] It should be noted that the processing of the receiving unit 201, the first determining unit 202, the generating unit 203, the modifying unit 204, the calling unit 205, the saving unit 206, the sending unit 207 and the second determining unit 208 and the beneficial effects thereof can be referred to in detail. Figure 1 Steps S101 to S108 in the above are not described in detail.
[0180] Optionally, the first contract interface includes a locking interface and a business interface.
[0181] The calling unit 205 is further configured to:
[0182] Through the locking interface in the first contract interface, the local lock state of the first smart contract is adjusted from unlocked to locked, and according to the smart contract call relationship, the business interface in the first contract interface and the contract call data, the first smart contract is called to perform transaction processing to obtain a first processing result.
[0183] Optionally, the first contract interface also includes an unlocking interface. The above device also includes:
[0184] An adjustment unit is configured to adjust the local lock state of the first smart contract from locked to unlocked and the global lock state of the first smart contract from locked to unlocked through an unlocking interface after determining that the global processing result is successful.
[0185] Optionally, the first contract interface also includes a snapshot interface and a recovery interface. The above device also includes:
[0186] The snapshot unit is configured to back up the contract data of the first smart contract through the snapshot interface before the source blockchain adjusts the local lock state of the first smart contract from unlocked to locked through the locking interface in the first contract interface, obtain the backup data, and save the backup data.
[0187] A recovery unit is configured to, after obtaining the first processing result, determine that the first processing result or the transaction processing result of the target blockchain is a failure, then determine that the global processing result is a failure, perform data rollback on the first smart contract based on the recovery interface and the backup data, and adjust the local lock state of the first smart contract from locked to unlocked and the global lock state of the first smart contract from locked to unlocked through the unlocking interface.
[0188] Optionally, the recovery unit is also used to:
[0189] When it is determined that the transaction processing result sent by the target blockchain is a failure, the transaction processing result of the target blockchain is determined to be a failure;
[0190] or,
[0191] When a cross-chain transaction request is sent to the target blockchain, a timer is started and the time duration is recorded; if the transaction processing result sent by the target blockchain is not received before the time duration exceeds the preset time threshold, the transaction processing of the target blockchain is determined to have timed out, and the transaction processing result of the target blockchain is determined to have failed.
[0192] Optionally, the above device further includes:
[0193] The third determining unit is used to, after obtaining the first processing result, send the corresponding first processing result and the global transaction identifier to the target blockchain when it is determined that the first processing result is successful, so that the target blockchain: when it is determined that the first processing result and the second processing result corresponding to the global transaction identifier are successful, the global processing result is determined to be successful.
[0194] Optionally, the blockchain identifier includes the chain identifier of the source blockchain and the chain identifier of the target blockchain;
[0195] The first smart contract and the second smart contract each include at least one smart contract;
[0196] The first contract interface includes the contract interface of each smart contract in the first smart contract, and the second contract interface includes the contract interface of each smart contract in the second smart contract;
[0197] The smart contract identifier includes the contract address of each smart contract in the first smart contract and the contract address of each smart contract in the second smart contract;
[0198] The smart contract calling relationship is the calling relationship between all smart contracts.
[0199] The cross-chain transaction processing device proposed in this embodiment can receive a cross-chain transaction request sent by a user on the source blockchain, determine the target blockchain, smart contract, contract interface, contract call data and smart contract call relationship involved in the cross-chain transaction according to the cross-chain transaction request, generate a global transaction identifier corresponding to the cross-chain transaction request, perform cross-chain transaction processing according to the target blockchain, smart contract, contract interface, contract call data and smart contract call relationship involved in the cross-chain transaction to obtain a first processing result, save the global transaction identifier and the first processing result in correspondence, send the cross-chain transaction request and the global transaction identifier to the target blockchain, so that the target blockchain performs cross-chain transaction processing to obtain a second processing result and save the second processing result and the global transaction identifier in correspondence. When it is determined that the first processing result and the second processing result corresponding to the global transaction identifier are successful, the global processing result of the cross-chain transaction request is determined to be successful, thereby effectively processing the cross-chain transaction request.
[0200] The cross-chain transaction processing device in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.
[0201] The embodiment of the present invention also provides a computer device having the above Figure 2 The cross-chain transaction processing device shown.
[0202] See also Figure 3 , a structural diagram of a computer device provided by an optional embodiment of the present invention, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. The various components are connected to each other using different buses for communication, and can be installed on a common motherboard or installed in other ways as needed. The processor can process instructions executed in the computer device, including instructions stored in or on the memory to display graphical information of the GUI on an external input / output device (such as a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides part of the necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 3 A processor 10 is taken as an example.
[0203] The processor 10 may be a central processing unit, a network processor, or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit, a programmable logic device, or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic, or any combination thereof.
[0204] The memory 20 stores instructions that can be executed by at least one processor 10, so as to enable at least one processor 10 to execute the method shown in the above embodiment.
[0205] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and application programs required for at least one function. The data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0206] The memory 20 may include volatile memory, such as random access memory. The memory may also include non-volatile memory, such as flash memory, a hard disk, or a solid-state drive. The memory 20 may also include a combination of the above types of memory.
[0207] The computer device further includes a communication interface 30 for the computer device to communicate with other devices or a communication network.
[0208] The embodiment of the present invention also provides a computer-readable storage medium. The above-mentioned method according to the embodiment of the present invention can be implemented in hardware, firmware, or implemented as a computer code that can be recorded in a storage medium, or implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and downloaded through a network and will be stored in a local storage medium, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state drive, etc.; further, the storage medium can also include a combination of the above-mentioned types of memory. It can be understood that a computer, a processor, a microprocessor controller or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor or hardware, the method shown in the above embodiment is implemented.
[0209] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention.
Claims
1. A cross-chain transaction processing method, characterized in that: Applied to a source blockchain; the method comprises: The source blockchain receives a cross-chain transaction request sent by a user, wherein the cross-chain transaction request includes a blockchain identifier, a smart contract identifier, a smart contract call relationship, contract interface information, and contract call data; The source blockchain determines the first smart contract, first contract interface, target blockchain, second smart contract, and second contract interface related to the cross-chain transaction based on the blockchain identifier, the smart contract identifier, and the contract interface information in the cross-chain transaction request, and generates a corresponding global transaction identifier based on the cross-chain transaction request; wherein the first smart contract and the second smart contract are deployed on the source blockchain and the target blockchain, respectively, and the first contract interface and the second contract interface are the contract interfaces of the first smart contract and the second smart contract, respectively; If the source blockchain determines that the global lock state of the first smart contract is unlocked, the global lock state of the first smart contract is changed from unlocked to locked, and the first smart contract is called to perform transaction processing based on the smart contract call relationship, the first contract interface, and the contract call data to obtain a first processing result, and the first processing result and the global transaction identifier are correspondingly saved; The source blockchain sends the cross-chain transaction request and the global transaction identifier to the target blockchain, so that the target blockchain: determines, based on the cross-chain transaction request, that the global state of the second smart contract is unlocked, modifies the global lock state of the second smart contract from unlocked to locked, and calls the second smart contract to perform transaction processing based on the smart contract call relationship, the second contract interface, and the contract call data to obtain a second processing result, correspondingly saves the second processing result and the global transaction identifier, and when determining that the second processing result is successful, returns the corresponding second processing result and the global transaction identifier to the source blockchain; If the source blockchain determines that the first processing result and the second processing result corresponding to the global transaction identifier are successful, then the global processing result is determined to be successful.
2. The method according to claim 1, characterized in that The first contract interface includes a locking interface and a business interface; The calling the first smart contract to perform transaction processing to obtain a first processing result according to the smart contract calling relationship, the first contract interface, and the contract calling data includes: The source blockchain adjusts the local lock state of the first smart contract from unlocked to locked through the locking interface in the first contract interface, and calls the first smart contract for transaction processing to obtain the first processing result according to the smart contract call relationship, the business interface in the first contract interface and the contract call data.
3. The method according to claim 2, characterized in that The first contract interface also includes an unlocking interface; After determining that the global processing result is successful, the method further includes: The source blockchain adjusts the local lock state of the first smart contract from locked to unlocked through the unlocking interface, and adjusts the global lock state of the first smart contract from locked to unlocked.
4. The method according to claim 3, characterized in that The first contract interface also includes a snapshot interface and a recovery interface; Before the source blockchain adjusts the local lock state of the first smart contract from unlocked to locked through the lock interface in the first contract interface, the method further includes: The source blockchain backs up the contract data of the first smart contract through the snapshot interface to obtain backup data, and saves the backup data; After obtaining the first processing result, the method further includes: If the source blockchain determines that the first processing result or the transaction processing result of the target blockchain is a failure, the global processing result is determined to be a failure, and the data of the first smart contract is rolled back based on the recovery interface and the backup data. The local lock state of the first smart contract is adjusted from locked to unlocked through the unlocking interface, and the global lock state of the first smart contract is adjusted from locked to unlocked.
5. The method according to claim 4, characterized in that The source blockchain determines that the transaction processing result of the target blockchain is a failure, including: When the source blockchain determines that the transaction processing result sent by the target blockchain is a failure, the source blockchain determines that the transaction processing result of the target blockchain is a failure; or, When the source blockchain sends the cross-chain transaction request to the target blockchain, it starts timing and records the timing duration; if the transaction processing result sent by the target blockchain is not received before the timing duration exceeds the preset duration threshold, it is determined that the transaction processing of the target blockchain has timed out, and the transaction processing result of the target blockchain is determined to be a failure.
6. The method according to claim 1, characterized in that After obtaining the first processing result, the method further includes: When the source blockchain determines that the first processing result is successful, the corresponding first processing result and the global transaction identifier are sent to the target blockchain, so that the target blockchain: when it is determined that the first processing result and the second processing result corresponding to the global transaction identifier are successful, the global processing result is determined to be successful.
7. The method according to any one of claims 1 to 6, characterized in that The blockchain identifier includes the chain identifier of the source blockchain and the chain identifier of the target blockchain; The first smart contract and the second smart contract each include at least one smart contract; The first contract interface includes the contract interface of each smart contract in the first smart contract, and the second contract interface includes the contract interface of each smart contract in the second smart contract; The smart contract identifier includes the contract address of each smart contract in the first smart contract and the contract address of each smart contract in the second smart contract; The smart contract calling relationship is the calling relationship between all the smart contracts.
8. A cross-chain transaction processing device, characterized in that: Applied to a source blockchain; the device comprises: A receiving unit, configured to receive a cross-chain transaction request sent by a user, wherein the cross-chain transaction request includes a blockchain identifier, a smart contract identifier, a smart contract call relationship, contract interface information, and contract call data; A first determining unit, configured to determine, based on the blockchain identifier, the smart contract identifier, and the contract interface information in the cross-chain transaction request, a first smart contract, a first contract interface, a target blockchain, a second smart contract, and a second contract interface related to the cross-chain transaction; A generating unit, configured to generate a corresponding global transaction identifier according to the cross-chain transaction request; a modification unit, configured to determine that the global lock state of the first smart contract is unlocked, and then modify the global lock state of the first smart contract from unlocked to locked; a calling unit, configured to call the first smart contract to perform transaction processing to obtain a first processing result based on the smart contract calling relationship, the first contract interface, and the contract calling data; a storage unit, configured to correspondingly store the first processing result and the global transaction identifier; a sending unit, configured to send the cross-chain transaction request and the global transaction identifier to the target blockchain, so that the target blockchain: determines, based on the cross-chain transaction request, that the global state of the second smart contract is unlocked, modifies the global lock state of the second smart contract from unlocked to locked, and calls the second smart contract to perform transaction processing based on the smart contract call relationship, the second contract interface, and the contract call data to obtain a second processing result, correspondingly saves the second processing result and the global transaction identifier, and when determining that the second processing result is successful, returns the corresponding second processing result and the global transaction identifier to the source blockchain; The second determining unit is configured to determine that if the first processing result and the second processing result corresponding to the global transaction identifier are successful, then determine that the global processing result is successful.
9. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the cross-chain transaction processing method according to any one of claims 1 to 7 by executing the computer instructions.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, which are used to enable a computer to execute the cross-chain transaction processing method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Blockchain multi-chain cross-chain system and implementation mechanism thereof
CN112287029A
Method and device for generating resource identifier in block chain network
CN115203332A