Cross-chain transaction method and device, electronic equipment and storage medium
By encapsulating, packaging, and verifying cross-chain transaction requests using Merkle trees, the problem of high resource consumption in cross-chain transaction methods is solved, achieving more efficient transaction request transmission and reduced costs.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HANGZHOU QULIAN TECHNOLOGY CO LTD
- Filing Date
- 2022-09-02
- Publication Date
- 2026-04-24
AI Technical Summary
Existing cross-chain transaction methods consume significant resources and incur high costs when processing transaction requests.
By receiving transaction request packets sent by the application chain, parsing the encapsulation information to determine the destination chain, packaging it and sending it to the corresponding destination chain, while performing Merkle tree verification to ensure the authenticity of the transaction request, using a transaction state queue to optimize query efficiency, and temporarily storing the transaction request in the database to reduce the number of transmissions.
It effectively reduces resource consumption and network bandwidth usage when transmitting transaction requests between blockchains, reduces payment fees, improves the efficiency of cross-chain transactions, and reduces costs.
Smart Images

Figure CN115423475B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of blockchain technology, specifically to a cross-chain transaction method, device, electronic device, and storage medium. Background Technology
[0002] With the rapid development of blockchain technology, many application systems are now using blockchain to store data. Typically, different application systems will be configured with different blockchains. Due to business needs, cross-chain transactions are usually required between the blockchains of different application systems (referred to as application chains). Existing technology usually realizes cross-chain transactions between different application chains through cross-chain transaction systems.
[0003] However, with the development of blockchain, the number of cross-chain transaction requests is large, and the current cross-chain transaction methods in the cross-chain transaction system consume a lot of resources and have high costs when processing transaction requests. Summary of the Invention
[0004] This application provides a cross-chain transaction method, apparatus, electronic device, and storage medium, aiming to solve the problem of high costs in processing transaction requests in current cross-chain transaction methods.
[0005] Firstly, this application provides a cross-chain transaction method, including:
[0006] Receive a transaction request packet sent by the application chain, wherein the transaction request packet consists of multiple transaction requests carrying the same destination chain information, and the transaction request packet carries the encapsulation information of the corresponding destination chain;
[0007] The encapsulation information carried by the transaction request packet is parsed to obtain the destination chain corresponding to the transaction request packet;
[0008] Send the transaction request packet to the corresponding destination chain;
[0009] Receive the transaction receipt corresponding to the transaction request packet fed back by the destination chain.
[0010] In one possible implementation of this application, before sending the transaction request packet to the corresponding destination chain, the method further includes:
[0011] Obtain the Merkle tree corresponding to the transaction request packet, wherein the Merkle tree is constructed from the transaction information of the transaction request in the transaction request packet;
[0012] The transaction request packet is verified based on the Merkle tree root and the Merkle tree proof of the Merkle tree;
[0013] If the verification passes, then proceed with the step of sending the transaction request packet to the corresponding destination chain;
[0014] If the verification fails, the first transaction request that passes the verification is obtained from the transaction requests in the transaction request packet, and the first transaction request is sent to the destination chain corresponding to the transaction request packet.
[0015] In one possible implementation of this application, the step of verifying the transaction request packet based on the Merkle tree root and the Merkle tree proof of the Merkle tree includes:
[0016] Based on the Merkle tree root and the Merkle tree proof of the Merkle tree, the target identifier of the transaction request in the transaction request packet is calculated;
[0017] Obtain the original identifier of the transaction request in the transaction request packet;
[0018] The original identifier is compared with the target identifier. If the original identifier is the same as the target identifier, the verification passes.
[0019] In one possible implementation of this application, if the verification fails, obtaining the first verified transaction request from the transaction requests in the transaction request packet and sending the first transaction request to the destination chain corresponding to the transaction request packet includes:
[0020] If the verification fails, then the first failed second transaction request is determined from the transaction requests in the transaction request packet;
[0021] Obtain the first transaction request that precedes the second transaction request;
[0022] The first transaction request is sent to the destination chain corresponding to the transaction request packet.
[0023] In one possible implementation of this application, after sending the transaction request packet to the corresponding destination chain, the method further includes:
[0024] Obtain the transaction status queue corresponding to the transaction request packet, wherein the transaction status queue contains the transaction status of the transaction request in the transaction request packet;
[0025] Update the transaction status queue based on the processing result of the transaction request in the transaction request packet;
[0026] Receive a status query request, and determine the target queue in the transaction status queue based on the first tag in the status query request;
[0027] Based on the second tag in the status query request, the transaction status corresponding to the status query request is retrieved from the target queue.
[0028] In one possible implementation of this application, the step of packaging the transaction request according to the destination chain information carried by the transaction request to obtain a transaction request package includes:
[0029] Based on the destination chain information carried in the transaction request, the transaction request is stored in the corresponding preset database;
[0030] If the number of transaction requests in the preset database reaches a preset threshold, the transaction requests in the preset database are packaged into a transaction request package, and the transaction requests in the preset database are deleted.
[0031] Secondly, this application provides a cross-chain transaction device, comprising:
[0032] The first receiving unit is used to receive a transaction request packet sent by the application chain, wherein the transaction request packet consists of multiple transaction requests carrying the same destination chain information, and the transaction request packet carries the encapsulation information of the corresponding destination chain.
[0033] The parsing unit is used to parse the encapsulation information carried by the transaction request packet to obtain the destination chain corresponding to the transaction request packet;
[0034] A sending unit is used to send the transaction request packet to the corresponding destination chain;
[0035] The second receiving unit is used to receive the transaction receipt corresponding to the transaction request packet fed back by the destination chain.
[0036] In one possible implementation of this application, the sending unit is further configured to:
[0037] Obtain the Merkle tree corresponding to the transaction request packet, wherein the Merkle tree is constructed from the transaction information of the transaction request in the transaction request packet;
[0038] The transaction request packet is verified based on the Merkle tree root and the Merkle tree proof of the Merkle tree;
[0039] If the verification passes, then proceed with the step of sending the transaction request packet to the corresponding destination chain;
[0040] If the verification fails, the first transaction request that passes the verification is obtained from the transaction requests in the transaction request packet, and the first transaction request is sent to the destination chain corresponding to the transaction request packet.
[0041] In one possible implementation of this application, the sending unit is further configured to:
[0042] Based on the Merkle tree root and the Merkle tree proof of the Merkle tree, the target identifier of the transaction request in the transaction request packet is calculated;
[0043] Obtain the original identifier of the transaction request in the transaction request packet;
[0044] The original identifier is compared with the target identifier. If the original identifier is the same as the target identifier, the verification passes.
[0045] In one possible implementation of this application, the sending unit is further configured to:
[0046] If the verification fails, then the first failed second transaction request is determined from the transaction requests in the transaction request packet;
[0047] Obtain the first transaction request that precedes the second transaction request;
[0048] The first transaction request is sent to the destination chain corresponding to the transaction request packet.
[0049] In one possible implementation of this application, the sending unit is further configured to:
[0050] Obtain the transaction status queue corresponding to the transaction request packet, wherein the transaction status queue contains the transaction status of the transaction request in the transaction request packet;
[0051] Update the transaction status queue based on the processing result of the transaction request in the transaction request packet;
[0052] Receive a status query request, and determine the target queue in the transaction status queue based on the first tag in the status query request;
[0053] Based on the second tag in the status query request, the transaction status corresponding to the status query request is retrieved from the target queue.
[0054] In one possible implementation of this application, the first receiving unit is further configured to:
[0055] Based on the destination chain information carried in the transaction request, the transaction request is stored in the corresponding preset database;
[0056] If the number of transaction requests in the preset database reaches a preset threshold, the transaction requests in the preset database are packaged into a transaction request package, and the transaction requests in the preset database are deleted.
[0057] Thirdly, this application also provides a cross-chain transaction system, including an application chain, a relay chain, and a destination chain connected by communication; the cross-chain transaction system executes:
[0058] The application chain is used to receive transaction requests. If the transaction request is a cross-chain transaction request, the cross-chain transaction request is packaged and sent to the relay chain.
[0059] The relay chain is used to receive transaction request packets sent by the application chain, wherein the transaction request packet consists of multiple transaction requests carrying the same destination chain information, and the transaction request packet carries the encapsulation information of the corresponding destination chain.
[0060] Furthermore, the encapsulation information carried by the transaction request packet is parsed to obtain the destination chain corresponding to the transaction request packet;
[0061] And, the transaction request packet is sent to the corresponding destination chain;
[0062] The destination chain is used to send the transaction receipt corresponding to the transaction request packet back to the relay chain.
[0063] Fourthly, this application also provides an electronic device, which includes a processor, a memory, and a computer program stored in the memory and capable of running on the processor. When the processor calls the computer program in the memory, it executes the steps in any of the cross-chain transaction methods provided in this application.
[0064] Fifthly, this application also provides a storage medium storing a computer program, which, when executed by a processor, implements the steps in any of the cross-chain transaction methods provided in this application.
[0065] In summary, the cross-chain transaction method provided in this application includes: receiving a transaction request packet sent by an application chain, wherein the transaction request packet consists of multiple transaction requests carrying the same destination chain information, and the transaction request packet carries encapsulation information of the corresponding destination chain; parsing the encapsulation information carried by the transaction request packet to obtain the destination chain corresponding to the transaction request packet; sending the transaction request packet to the corresponding destination chain; and receiving a transaction receipt corresponding to the transaction request packet from the destination chain.
[0066] As can be seen, the cross-chain transaction method provided in this application embodiment performs cross-chain transactions in the form of transaction request packets, which can effectively reduce the transaction fees paid when transmitting transaction requests between blockchains, while also reducing the resource consumption and network bandwidth usage of the blockchain system. Furthermore, the cross-chain transaction method provided in this application embodiment classifies and packages transactions according to the destination chain corresponding to the transaction request, and encapsulates the corresponding destination chain information into the transaction request packet. Therefore, when the relay chain gateway determines the destination chain corresponding to the transaction request, it only needs to parse the encapsulation information carried in the transaction request packet once, further reducing the resource consumption and cost of the blockchain system. This method has high practical value when cross-chain transactions are frequent and the number of transaction requests is large. Attached Figure Description
[0067] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0068] Figure 1 This is a schematic diagram illustrating an application scenario of the cross-chain transaction method provided in the embodiments of this application;
[0069] Figure 2 This is a flowchart illustrating a cross-chain transaction method provided in the embodiments of this application;
[0070] Figure 3 This is a schematic diagram of a cross-chain transaction system provided in the embodiments of this application;
[0071] Figure 4 This is a flowchart illustrating a process for verifying a transaction request packet, as provided in an embodiment of this application.
[0072] Figure 5 This is a flowchart illustrating a method for querying transaction status provided in an embodiment of this application;
[0073] Figure 6 This is a schematic diagram of a process for obtaining a transaction request packet provided in an embodiment of this application;
[0074] Figure 7 This is a schematic diagram of an embodiment of the cross-chain transaction device provided in this application.
[0075] Figure 8 This is a schematic diagram of an embodiment of the electronic device provided in this application. Detailed Implementation
[0076] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0077] In the description of the embodiments of this application, it should be understood that the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Therefore, features defined with "first" and "second" may explicitly or implicitly include one or more of the stated features. In the description of the embodiments of this application, "multiple" means two or more, unless otherwise explicitly specified.
[0078] To enable any person skilled in the art to implement and use this application, the following description is provided. In this description, details are set forth for purposes of explanation. It should be understood that those skilled in the art will recognize that this application can be implemented without using these specific details. In other instances, well-known processes will not be described in detail to avoid obscuring the description of the embodiments of this application with unnecessary detail. Therefore, this application is not intended to be limited to the embodiments shown, but is consistent with the broadest scope of the principles and features disclosed in the embodiments of this application.
[0079] This application provides a cross-chain transaction method, apparatus, electronic device, and storage medium. The cross-chain transaction apparatus can be integrated into an electronic device, which can be a server, a terminal, or other similar device.
[0080] The execution entity of the cross-chain transaction method in this application embodiment can be the cross-chain transaction device provided in this application embodiment, or different types of electronic devices such as server equipment, physical host, or user equipment (UE) that integrate the cross-chain transaction device. The cross-chain transaction device can be implemented in hardware or software. The UE can specifically be a terminal device such as a smartphone, tablet computer, laptop computer, handheld computer, desktop computer, or personal digital assistant (PDA).
[0081] The electronic device can operate independently or in a cluster.
[0082] See Figure 1 , Figure 1This is a schematic diagram of a cross-chain transaction system provided in an embodiment of this application. The cross-chain transaction system may include an electronic device 101, which integrates a cross-chain transaction device.
[0083] In addition, such as Figure 1 As shown, the cross-chain transaction system may also include a storage device 102 for storing data, such as text data.
[0084] It should be noted that, Figure 1 The schematic diagram of the cross-chain transaction system shown is merely an example. The cross-chain transaction system and scenario described in this application are intended to more clearly illustrate the technical solutions of this application and do not constitute a limitation on the technical solutions provided in this application. As those skilled in the art will know, with the evolution of cross-chain transaction systems and the emergence of new business scenarios, the technical solutions provided in this invention are also applicable to similar technical problems.
[0085] The following describes the cross-chain transaction method provided in this application embodiment. In this application embodiment, an electronic device is used as the execution subject. For simplicity and ease of description, the execution subject will be omitted in subsequent method embodiments. The cross-chain transaction method includes: receiving a transaction request packet sent by an application chain, wherein the transaction request packet consists of multiple transaction requests carrying the same destination chain information, and the transaction request packet carries encapsulation information corresponding to the destination chain; parsing the encapsulation information carried by the transaction request packet to obtain the destination chain corresponding to the transaction request packet; sending the transaction request packet to the corresponding destination chain; and receiving a transaction receipt corresponding to the transaction request packet fed back by the destination chain.
[0086] Reference Figure 2 , Figure 2 This is a flowchart illustrating a cross-chain transaction method provided in an embodiment of this application. It should be noted that although the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than that shown here. Specifically, the cross-chain transaction method may include the following steps 201-204, wherein:
[0087] 201. Receive a transaction request packet sent by the application chain, wherein the transaction request packet consists of multiple transaction requests carrying the same destination chain information, and the transaction request packet carries the encapsulation information of the corresponding destination chain.
[0088] The cross-chain transaction method provided in this application can be applied to cross-chain transaction systems. (Refer to...) Figure 3 , Figure 3 This is a schematic diagram of a cross-chain transaction system 300. The cross-chain transaction system 300 includes at least one application chain 301, a relay chain 302, and at least one destination chain 303.
[0089] A transaction request packet refers to a batch transaction packet containing information on multiple transaction requests. In this embodiment, when an application link receives a transaction request, the application chain queries the transaction object of the transaction request to determine whether the transaction request is a cross-chain transaction request. If the transaction request is a cross-chain transaction request, it is classified and packaged according to the transaction object to obtain transaction request packets corresponding to different transaction objects, i.e., corresponding to different destination chains. The transaction requests contained in each transaction request packet all correspond to the same destination chain. For example, the application chain gateway can periodically poll and listen for cross-chain transaction requests received by each application link, and package the cross-chain transaction requests listened to during this period according to different destination chains to obtain transaction request packets corresponding to different destination chains, and send the transaction request packets to the relay chain.
[0090] When the application chain gateway packages transactions, to facilitate subsequent processes, the destination chain information corresponding to the transaction request package can be encapsulated into the transaction request package. For example, if each transaction request in the transaction request package corresponds to the destination chain "hyperchain", the application chain gateway can encapsulate the "hyperchain" information into the transaction request package.
[0091] As can be seen, the cross-chain transaction method in this embodiment packages transaction requests into a transaction request packet and sends the packet to the relay chain. Therefore, only a single cross-chain transaction fee to the relay chain needs to be paid, and network bandwidth congestion caused by the serial transmission of multiple transaction requests can be avoided. Currently, the relay chain cross-chain mode involves the gateway immediately forwarding a cross-chain transaction to the relay chain for verification after the application chain initiates it. If the application chain initiates a large number of cross-chain transactions in a short period, forwarding them one by one would result in very low efficiency. Furthermore, forwarding each transaction would cause the application chain gateway to pay substantial fees on the relay chain, leading to a waste of resources and costs. In addition, packaging transactions through the application chain gateway eliminates the need for processing via the relay chain's consensus mechanism, thus resulting in higher efficiency.
[0092] 202. Parse the encapsulation information carried by the transaction request packet to obtain the destination chain corresponding to the transaction request packet.
[0093] During step 202, the relay chain gateway can parse the encapsulation information carried in the transaction request packet to determine the destination chain of each transaction request within the packet. It is evident that by packaging transaction requests with the same destination chain into a single packet and encapsulating the corresponding destination chain information, the destination chain of multiple transaction requests can be determined with only one parsing operation. This reduces the computational cost of the relay chain gateway and lowers its network bandwidth usage, providing more available network bandwidth for the transmission of transaction request packets.
[0094] 203. Send the transaction request packet to the corresponding destination chain.
[0095] After determining the destination chain corresponding to the transaction request packet, the relay chain gateway can mark each transaction request in the packet and send the packet to the corresponding destination chain. Therefore, the cross-chain transaction method in this embodiment not only transmits transaction requests between the relay chain and the application chain via transaction request packets, but also between the relay chain and the destination chain, further reducing transmission resource consumption and network bandwidth usage.
[0096] 204. Receive the transaction receipt corresponding to the transaction request packet fed back by the destination chain.
[0097] After receiving the transaction request packet, the destination chain can parse the transaction request packet, obtain the transaction request in the transaction request packet, and upload the corresponding transaction to the chain one by one according to the transaction request.
[0098] In some embodiments, the destination chain can package multiple transaction receipts and send them as a batch packet to the destination chain to reduce transmission resource consumption and network bandwidth usage. For example, the destination chain can process the transaction request in the transaction request packet to obtain the transaction receipt corresponding to the transaction request, and then package these transaction receipts and send them to the relay chain.
[0099] After executing step 204, the relay chain sends the obtained transaction receipt to the application chain. The application chain synchronizes the information in the transaction receipt to each included block and executes the corresponding call lback and rol lback operations.
[0100] In summary, the cross-chain transaction method provided in this application includes: receiving a transaction request packet sent by an application chain, wherein the transaction request packet consists of multiple transaction requests carrying the same destination chain information, and the transaction request packet carries encapsulation information of the corresponding destination chain; parsing the encapsulation information carried by the transaction request packet to obtain the destination chain corresponding to the transaction request packet; sending the transaction request packet to the corresponding destination chain; and receiving a transaction receipt corresponding to the transaction request packet from the destination chain.
[0101] As can be seen, the cross-chain transaction method provided in this application embodiment performs cross-chain transactions in the form of transaction request packets, which can effectively reduce the transaction fees paid when transmitting transaction requests between blockchains, while also reducing the resource consumption and network bandwidth usage of the blockchain system. Furthermore, the cross-chain transaction method provided in this application embodiment classifies and packages transactions according to the destination chain corresponding to the transaction request, and encapsulates the corresponding destination chain information into the transaction request packet. Therefore, when the relay chain gateway determines the destination chain corresponding to the transaction request, it only needs to parse the encapsulation information carried in the transaction request packet once, further reducing the resource consumption and cost of the blockchain system. This method has high practical value when cross-chain transactions are frequent and the number of transaction requests is large.
[0102] In some embodiments, to prevent fraudulent transactions from being sent to the destination chain, the relay chain gateway can verify the transaction request in the transaction request packet before sending it to the corresponding destination chain. (See reference...) Figure 4 At this point, before the step of "sending the transaction request packet to the corresponding destination chain", the method further includes:
[0103] 401. Obtain the Merkle tree corresponding to the transaction request packet, wherein the Merkle tree is constructed from the transaction information of the transaction request in the transaction request packet.
[0104] A Merkle tree can be generated by the application chain gateway based on the identifier of the transaction request, where the identifier can be the hash value corresponding to the transaction request. After the application chain gateway constructs the Merkle tree based on the transaction information of the transaction request packet, it can send the Merkle tree information along with the transaction request packet to the relay chain. When executing step 401, the relay chain gateway can directly obtain the Merkle tree corresponding to the transaction request packet.
[0105] 402. Verify the transaction request packet based on the Merkle tree root and the Merkle tree proof of the Merkle tree.
[0106] In some embodiments, the transaction request packet can be verified by the following method, namely, the step "verifying the transaction request packet based on the Merkle tree root and the Merkle tree proof of the Merkle tree", including:
[0107] (1) The target identifier of the transaction request in the transaction request packet is calculated based on the Merkle tree root and the Merkle tree proof of the Merkle tree.
[0108] The target identifier is a hash value calculated based on the Merkle tree constructed from the application chain gateway, which can be understood as the hash value if no fraudulent transactions occur.
[0109] (2) Obtain the original identifier of the transaction request in the transaction request packet.
[0110] The original identifier refers to the actual hash value in the relay chain after transmission. Understandably, the original identifier may be different from or the same as the target identifier. If the transaction request is a fraudulent transaction, the original identifier should be different from the target identifier; if the transaction request is not a fraudulent transaction, the original identifier should be the same as the target identifier.
[0111] (3) Compare the original identifier with the target identifier. If the original identifier is the same as the target identifier, the verification is successful.
[0112] As can be seen, through steps 401-402, in the cross-chain transaction method of this application embodiment, the relay chain does not need to obtain the hash value of each transaction request during verification, but only needs to obtain the Merkle tree. Therefore, the transaction verification is more efficient, and the resource consumption during transmission is smaller, and the network bandwidth usage is lower.
[0113] 403A. If the verification passes, then execute the step of sending the transaction request packet to the corresponding destination chain.
[0114] If the verification passes, it means that there are no fraudulent transactions in the transaction request packet, so the transaction request packet can be sent to the corresponding destination chain.
[0115] 403B. If the verification fails, the first transaction request that has passed the verification is obtained from the transaction requests in the transaction request packet, and the first transaction request is sent to the destination chain corresponding to the transaction request packet.
[0116] If the verification fails, it means that there is a fake transaction in the transaction request packet. In this case, the fake transaction can be removed and only the real transaction request can be sent to the corresponding destination chain.
[0117] The first transaction request refers to the transaction request that has passed verification, i.e., the genuine transaction request.
[0118] In some embodiments, the step "if the verification fails, obtain the first verified transaction request from the transaction requests in the transaction request packet, and send the first transaction request to the destination chain corresponding to the transaction request packet" can be implemented in the following ways:
[0119] (A) If the verification fails, then determine the first second transaction request that fails the verification from the transaction requests in the transaction request packet.
[0120] The reason for obtaining the second transaction request that fails the first verification is that in a blockchain network, all blocks are linked in a chain. Therefore, if the initial transaction request is a fraudulent request, subsequent transaction requests based on this fraudulent request will fail when sent to the destination chain. Thus, the cross-chain transaction method in this embodiment reduces the number of transaction request verifications through step (A). When a second transaction request fails verification, there is no need to verify subsequent transaction requests; instead, it is fed back to the application chain, and the transaction is resent through the application chain's gateway until verification passes, thereby reducing computational load and lowering the cost of the relay chain.
[0121] (B) Obtain the first transaction request that precedes the second transaction request.
[0122] As explained in step (A), since the second transaction request is the first transaction request that fails the verification, the first transaction request that precedes the second transaction request must be a genuine transaction request.
[0123] (C) Send the first transaction request to the destination chain corresponding to the transaction request packet.
[0124] In some embodiments, the relay chain gateway can repackage the first transaction request and then send the generated batch packet to the destination chain to reduce resource consumption and network bandwidth usage during data transmission.
[0125] In summary, the methods in steps 401-403 can effectively verify the authenticity of transaction request packets and prevent fake transactions from being sent to the destination chain.
[0126] In some embodiments, to improve the efficiency of transaction state queries and reduce the storage space occupied by transaction states, as well as the aggregation frequency of LevelDB, the transaction states of transaction requests can be stored in the relay chain as queues. Therefore, subsequent updates and queries of transaction states can be performed using update queues and query queues, respectively. (Reference) Figure 5 At this point, after the step "sending the transaction request packet to the corresponding destination chain", the method further includes:
[0127] 501. Obtain the transaction status queue corresponding to the transaction request packet, wherein the transaction status queue contains the transaction status of the transaction request in the transaction request packet.
[0128] Transaction status can be used to reflect the processing status of a transaction request. For example, transaction status can include "pending," "completed," etc. In this embodiment, the transaction status of a transaction request is stored in the relay chain in the form of a queue, which can reduce the storage space occupied by the transaction status and reduce the aggregation frequency of LevelDB.
[0129] It should be noted that in the relay chain, each transaction request packet corresponds to a transaction state list, which stores the transaction state of the transaction request in the transaction request packet.
[0130] 502. Update the transaction status queue according to the processing result of the transaction request in the transaction request packet.
[0131] For example, the destination chain can return the processing result of the transaction request to the relay chain in the form of a transaction receipt. The relay chain gateway determines the processing result of the transaction request based on the transaction receipt and updates the transaction status of the transaction request in the transaction status queue according to the processing result.
[0132] 503. Receive a status query request, and determine the target queue in the transaction status queue based on the first tag in the status query request.
[0133] A status query request is a computer request used to query the status of a transaction. In this embodiment, since the transaction status of transaction requests is stored in the relay chain in the form of a queue, the status query request needs to contain two types of tags: one for searching the queue and one for searching the transaction requests within the queue. For example, the tags in the status query request can be in the form of hyperchain1-A, where hyperchain1 is the tag for searching the queue, and A is the tag for searching the transaction requests within the queue. It is understood that the first tag in step 503 refers to the tag for searching the queue.
[0134] 504. Based on the second tag in the status query request, retrieve the transaction status corresponding to the status query request from the target queue.
[0135] As can be seen from the description of step 503, the second label is used to find the label of the transaction request in the queue. Based on the second label, the corresponding target transaction request can be determined from the target queue, and the current transaction status of the target transaction request can be returned as the query result.
[0136] As can be seen, by using the method in steps 501-504, it is not necessary to traverse every transaction request when looking up the transaction status. Instead, after determining the target queue, only the transaction requests in the target queue can be traversed, which significantly improves the efficiency of querying the transaction status and reduces the network bandwidth usage during the query. Even if the query and transaction request are transmitted synchronously, it will not affect the performance of the relay chain.
[0137] In some embodiments, the application chain gateway can temporarily store transaction requests corresponding to different destination chains in different databases while listening for transaction requests. These requests are then packaged together only when the number of temporarily stored requests reaches a certain threshold. This improves the transmission efficiency of transaction requests by delaying packaging when the number of requests is small, thereby reducing transaction fees incurred when transmitting transaction requests between blockchains and minimizing resource consumption and network bandwidth usage within the blockchain system. (Reference) Figure 6 At this point, the step "packaging the transaction request according to the destination chain information carried in the transaction request to obtain a transaction request package" includes:
[0138] 601. Based on the destination chain information carried in the transaction request, store the transaction request in the corresponding preset database.
[0139] In this embodiment, multiple databases can be pre-set in the cross-chain transaction system, with each database corresponding to a destination chain. When the application chain determines the destination chain corresponding to a transaction request, it temporarily stores it in the corresponding database.
[0140] 602. If the number of transaction requests in the preset database reaches a preset threshold, the transaction requests in the preset database are packaged to obtain a transaction request package, and the transaction requests in the preset database are deleted.
[0141] The preset quantity threshold is used to evaluate the size of the number of transaction requests. If the number of transaction requests reaches the preset quantity threshold, it means that there are enough transaction requests temporarily stored in the preset database. At this time, these transaction requests can be packaged to obtain a transaction request package, and the temporarily stored transaction requests can be deleted so that the next transaction request package can be generated later.
[0142] To better implement the cross-chain transaction method in this application embodiment, based on the cross-chain transaction method, this application embodiment also provides a cross-chain transaction device, such as... Figure 7 The diagram shown is a structural schematic of one embodiment of the cross-chain transaction device in this application. The cross-chain transaction device 700 includes:
[0143] The first receiving unit 701 is used to receive a transaction request packet sent by the application chain, wherein the transaction request packet consists of multiple transaction requests carrying the same destination chain information, and the transaction request packet carries the encapsulation information of the corresponding destination chain.
[0144] The parsing unit 702 is used to parse the encapsulation information carried by the transaction request packet to obtain the destination chain corresponding to the transaction request packet;
[0145] The sending unit 703 is used to send the transaction request packet to the corresponding destination chain;
[0146] The second receiving unit 704 is used to receive the transaction receipt corresponding to the transaction request packet fed back by the destination chain.
[0147] In one possible implementation of this application, the sending unit 703 is further configured to:
[0148] Obtain the Merkle tree corresponding to the transaction request packet, wherein the Merkle tree is constructed from the transaction information of the transaction request in the transaction request packet;
[0149] The transaction request packet is verified based on the Merkle tree root and the Merkle tree proof of the Merkle tree;
[0150] If the verification passes, then proceed with the step of sending the transaction request packet to the corresponding destination chain;
[0151] If the verification fails, the first transaction request that passes the verification is obtained from the transaction requests in the transaction request packet, and the first transaction request is sent to the destination chain corresponding to the transaction request packet.
[0152] In one possible implementation of this application, the sending unit 703 is further configured to:
[0153] Based on the Merkle tree root and the Merkle tree proof of the Merkle tree, the target identifier of the transaction request in the transaction request packet is calculated;
[0154] Obtain the original identifier of the transaction request in the transaction request packet;
[0155] The original identifier is compared with the target identifier. If the original identifier is the same as the target identifier, the verification passes.
[0156] In one possible implementation of this application, the sending unit 703 is further configured to:
[0157] If the verification fails, then the first failed second transaction request is determined from the transaction requests in the transaction request packet;
[0158] Obtain the first transaction request that precedes the second transaction request;
[0159] The first transaction request is sent to the destination chain corresponding to the transaction request packet.
[0160] In one possible implementation of this application, the sending unit 703 is further configured to:
[0161] Obtain the transaction status queue corresponding to the transaction request packet, wherein the transaction status queue contains the transaction status of the transaction request in the transaction request packet;
[0162] Update the transaction status queue based on the processing result of the transaction request in the transaction request packet;
[0163] Receive a status query request, and determine the target queue in the transaction status queue based on the first tag in the status query request;
[0164] Based on the second tag in the status query request, the transaction status corresponding to the status query request is retrieved from the target queue.
[0165] In one possible implementation of this application, the first receiving unit 701 is further configured to:
[0166] Based on the destination chain information carried in the transaction request, the transaction request is stored in the corresponding preset database;
[0167] If the number of transaction requests in the preset database reaches a preset threshold, the transaction requests in the preset database are packaged into a transaction request package, and the transaction requests in the preset database are deleted.
[0168] In practice, each of the above units can be implemented as an independent entity or can be arbitrarily combined to be implemented as the same or several entities. For the specific implementation of each of the above units, please refer to the previous method embodiments, which will not be repeated here.
[0169] Since this cross-chain transaction device can execute the steps in the cross-chain transaction method in any embodiment, it can achieve the beneficial effects that the cross-chain transaction method in any embodiment of this application can achieve, as detailed in the preceding description, and will not be repeated here.
[0170] Furthermore, in order to better implement the cross-chain transaction method in the embodiments of this application, in the cross-chain transaction method
[0171] Based on this, embodiments of this application also provide an electronic device, see below. Figure 8 , Figure 8This illustration shows a structural diagram of an electronic device according to an embodiment of this application. Specifically, the electronic device provided in this embodiment includes a processor 801. The processor 801 is used to execute a computer program stored in a memory 802 to implement the steps of the cross-chain transaction method in any embodiment; or, the processor 801 is used to execute a computer program stored in a memory 802 to implement, for example... Figure 7 The functions of each unit in the corresponding embodiment.
[0172] For example, a computer program may be divided into one or more modules / units, one or more of which are stored in memory 802 and executed by processor 801 to complete the embodiments of this application. One or more modules / units may be a series of computer program instruction segments capable of performing a specific function, which describe the execution process of the computer program in a computer device.
[0173] The electronic device may include, but is not limited to, processor 801 and memory 802. Those skilled in the art will understand that the illustrations are merely examples of an electronic device and do not constitute a limitation on the device. It may include more or fewer components than illustrated, or combine certain components, or use different components.
[0174] The processor 801 can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor. The processor is the control center of the electronic device, connecting various parts of the electronic device through various interfaces and lines.
[0175] The memory 802 can be used to store computer programs and / or modules. The processor 801 implements various functions of the computer device by running or executing the computer programs and / or modules stored in the memory 802 and by calling the data stored in the memory 802. The memory 802 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, application programs required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device (such as audio data, video data, etc.). In addition, the memory may include high-speed random access memory, and may also include non-volatile memory, such as hard disk, RAM, plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, at least one disk storage device, flash memory device, or other volatile solid-state storage device.
[0176] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the cross-chain transaction device, electronic device and its corresponding unit described above can be referred to the description of the cross-chain transaction method in any embodiment, and will not be repeated here.
[0177] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be accomplished by instructions, or by instructions controlling related hardware. These instructions can be stored in a storage medium and loaded and executed by a processor.
[0178] Therefore, this application provides a storage medium storing a computer program. When the computer program is executed by a processor, it performs the steps in the cross-chain transaction method in any embodiment of this application. For specific operations, please refer to the description of the cross-chain transaction method in any embodiment, which will not be repeated here.
[0179] The storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0180] Since the instructions stored in the storage medium can execute the steps in the cross-chain transaction method in any embodiment of this application, the beneficial effects that the cross-chain transaction method in any embodiment of this application can achieve can be realized, as detailed in the preceding description, and will not be repeated here.
[0181] The foregoing has provided a detailed description of a cross-chain transaction method, apparatus, storage medium, and electronic device provided in the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A cross-chain transaction method, characterized in that, Applied to relay chains, including: The system receives a transaction request packet sent by the application chain and a Merkle tree corresponding to the transaction request packet. The transaction request packet consists of multiple transaction requests carrying the same destination chain information. The transaction request packet carries encapsulation information of the corresponding destination chain. The Merkle tree is constructed from the transaction information of the transaction requests in the transaction request packet. The encapsulation information carried by the transaction request packet is parsed to obtain the destination chain corresponding to the transaction request packet; The transaction request packet is verified based on the Merkle tree root and the Merkle tree proof of the Merkle tree; If the verification passes, the transaction request packet is sent to the corresponding destination chain; Receive the transaction receipt corresponding to the transaction request packet fed back by the destination chain.
2. The cross-chain transaction method according to claim 1, characterized in that, The method further includes: If the verification fails, the first transaction request that passes the verification is obtained from the transaction requests in the transaction request packet, and the first transaction request is sent to the destination chain corresponding to the transaction request packet.
3. The cross-chain transaction method according to claim 2, characterized in that, The step of verifying the transaction request packet based on the Merkle tree root and the Merkle tree proof of the Merkle tree includes: Based on the Merkle tree root and the Merkle tree proof of the Merkle tree, the target identifier of the transaction request in the transaction request packet is calculated; Obtain the original identifier of the transaction request in the transaction request packet; The original identifier is compared with the target identifier. If the original identifier is the same as the target identifier, the verification passes.
4. The cross-chain transaction method according to claim 2, characterized in that, If the verification fails, the first transaction request that passes the verification is obtained from the transaction requests in the transaction request packet, and the first transaction request is sent to the destination chain corresponding to the transaction request packet, including: If the verification fails, then the first failed second transaction request is determined from the transaction requests in the transaction request packet; Obtain the first transaction request that precedes the second transaction request; The first transaction request is sent to the destination chain corresponding to the transaction request packet.
5. The cross-chain transaction method according to claim 1, characterized in that, After sending the transaction request packet to the corresponding destination chain, the method further includes: Obtain the transaction status queue corresponding to the transaction request packet, wherein the transaction status queue contains the transaction status of the transaction request in the transaction request packet; Update the transaction status queue based on the processing result of the transaction request in the transaction request packet; Receive a status query request, and determine the target queue in the transaction status queue based on the first tag in the status query request; Based on the second tag in the status query request, the transaction status corresponding to the status query request is retrieved from the target queue.
6. The cross-chain transaction method according to claim 1, characterized in that, The step of packaging the transaction request according to the destination chain information carried in the transaction request to obtain a transaction request packet includes: Based on the destination chain information carried in the transaction request, the transaction request is stored in the corresponding preset database; If the number of transaction requests in the preset database reaches a preset threshold, the transaction requests in the preset database are packaged into a transaction request package, and the transaction requests in the preset database are deleted.
7. A cross-chain transaction system, characterized in that, This includes the application chain, relay chain, and destination chain for communication connections; the cross-chain transaction system executes: The application chain is used to receive transaction requests. If the transaction request is a cross-chain transaction request, the cross-chain transaction request is packaged and sent to the relay chain. The relay chain is used to receive transaction request packets and Merkle trees corresponding to the application chain sent by the application chain. The transaction request packet consists of multiple transaction requests carrying the same destination chain information. The transaction request packet carries the encapsulation information of the corresponding destination chain. The Merkle tree is constructed from the transaction information of the transaction requests in the transaction request packet. Furthermore, the encapsulation information carried by the transaction request packet is parsed to obtain the destination chain corresponding to the transaction request packet; Furthermore, the transaction request packet is verified based on the Merkle tree root and the Merkle tree proof of the Merkle tree; if the verification passes, the transaction request packet is sent to the corresponding destination chain. The destination chain is used to send the transaction receipt corresponding to the transaction request packet back to the relay chain.
8. A cross-chain transaction device, characterized in that, Applied to relay chains, including: The first receiving unit is used to receive a transaction request packet sent by the application chain and a Merkle tree corresponding to the transaction request packet. The transaction request packet consists of multiple transaction requests carrying the same destination chain information. The transaction request packet carries encapsulation information of the corresponding destination chain. The Merkle tree is constructed from the transaction information of the transaction requests in the transaction request packet. The parsing unit is used to parse the encapsulation information carried by the transaction request packet to obtain the destination chain corresponding to the transaction request packet; The sending unit is used to verify the transaction request packet based on the Merkle tree root and the Merkle tree proof of the Merkle tree; if the verification passes, the transaction request packet is sent to the corresponding destination chain. The second receiving unit is used to receive the transaction receipt corresponding to the transaction request packet fed back by the destination chain.
9. An electronic device, characterized in that, The electronic device includes a processor, a memory, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the steps of the cross-chain transaction method as described in any one of claims 1 to 6.
10. A storage medium, characterized in that, The storage medium stores a computer program, which, when executed by a processor, implements the steps of the cross-chain transaction method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Blockchain-based cross-chain transaction management method, cross-chain platform and medium
CN112598514A
Message passing method and system, medium, equipment and mobile terminal
CN113886487A