Cross-chain Transaction Method, Device, Electronic Device and Computer Readable Storage Medium
By receiving and processing cross-chain transaction requests on the relay chain, judging the timeliness of the transaction requests and determining whether the transaction is a duplicate transaction, the problem of repeated transactions caused by cross-chain gateway failure or hacker control is solved, ensuring the timeliness of the transaction and the security of the user's funds.
Patent Information
- Application Number
- CN202510118868.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-24
- Publication Date
- 2025-06-13
- Estimated Expiration
- 2045-01-24
AI Technical Summary
When the cross-chain gateway fails or is controlled by hackers in the prior art, cross-chain transaction events are encapsulated and submitted to the relay chain multiple times, causing repeated transactions on the target business chain and causing losses to users.
When receiving the target transaction request, it is determined whether the time stamp of the transaction request and the time interval between the relay chain generating the latest block exceeds the preset threshold. If it exceeds, the transaction request will be rejected; if it does not exceed, it is determined whether the transaction is a duplicate transaction based on the corresponding information of the transaction identification information and the identification packet, and clean up historical transaction information when necessary to avoid excessive space occupation.
It effectively prevents processing outdated transaction requests, ensures the timeliness of transactions, and solves the problem of repeated transactions caused by cross-chain gateway failure or hacker control, protects the security of users' funds.
Smart Images

Figure CN119583627B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of blockchain technology. Specifically, this application relates to a cross-chain transaction method, apparatus, electronic device, and computer-readable storage medium. Background Art
[0002] With the continuous development of blockchain technology, more and more blockchain systems adopt cross-chain technology for interoperable access and collaboration. Cross-chain technology refers to connecting homogeneous or heterogeneous blockchain systems to achieve information intercommunication between blockchains.
[0003] Currently, it is relatively common to implement cross-chain transactions using relay chain technology. Specifically, the source application chain system forwards a cross-chain transaction to the relay chain system through a cross-chain gateway. The relay chain system verifies the cross-chain transaction. After the verification passes, the relay chain system forwards the cross-chain transaction to the destination application chain system through another cross-chain gateway.
[0004] In the above cross-chain transaction method, in the case where the cross-chain gateway fails or is controlled by a hacker, multiple nonce values are obtained from the relay chain, the transaction event is encapsulated multiple times, and the encapsulated data is submitted to the relay chain, resulting in the transaction being executed multiple times and causing losses to the counterparty users. Summary of the Invention
[0005] Embodiments of this application provide a cross-chain transaction method, apparatus, electronic device, and computer-readable storage medium to solve the problem of repeated transactions in existing cross-chain transactions.
[0006] According to a first aspect of the embodiments of this application, a cross-chain transaction method is provided. The method is applied to a relay chain between a source business chain and a destination business chain, and the method includes:
[0007] Receiving a target transaction request; wherein, the target transaction request includes a timestamp of the target transaction and first transaction identification information, and the timestamp is used to represent the moment when the source business chain initiates the target transaction to the destination business chain;
[0008] If it is determined that the time interval between the timestamp and a first moment exceeds a preset threshold, rejecting the target transaction request; the first moment is the moment when the relay chain generates the latest block;
[0009] If it is determined that the time interval does not exceed the preset threshold, determining a first identification group corresponding to the first transaction identification information according to the corresponding information between the preset transaction identification information and the identification groups;
[0010] Obtaining historical transaction information corresponding to the first identification group, and determining whether the target transaction is a repeated transaction according to whether the first transaction identification information exists in the historical transaction information.
[0011] As an alternative implementation, the first transaction identification information includes at least one of an identifier of a source service chain, an identifier of the destination service chain, and a transaction number of the target transaction.
[0012] As an alternative implementation, the corresponding information between the preset transaction identification information and identification groups includes a mapping relationship between different information combinations and different identification groups, where each information combination includes an identifier of a source service chain, an identifier of a destination service chain, and a tail number of a transaction number.
[0013] Determining the first identification group corresponding to the first transaction identification information according to the corresponding information between the preset transaction identification information and identification groups includes:
[0014] Determining a first information combination according to the identifier of the source service chain, the identifier of the destination service chain, and the tail number of the transaction number of the target transaction;
[0015] Taking the identification group having a mapping relationship with the first information combination as the first identification group corresponding to the first transaction identification information.
[0016] As an alternative implementation, the first identification group further includes a storage address of historical transaction information, and the historical transaction information includes transaction numbers of at least one historical transaction of the corresponding identification group:
[0017] Obtaining the historical transaction information corresponding to the first identification group, and determining whether the target transaction is a duplicate transaction according to whether the first transaction identification information exists in the historical transaction information includes:
[0018] Obtaining transaction numbers of at least one historical transaction corresponding to the first identification group according to the address of the historical transaction information;
[0019] If the transaction number of the target transaction is included in the transaction numbers of at least one historical transaction corresponding to the first identification group, determining that the target transaction is a duplicate transaction;
[0020] If the transaction number of the target transaction is not included in the transaction numbers of at least one historical transaction corresponding to the first identification group, determining that the target transaction is not a duplicate transaction.
[0021] As an alternative implementation, the transaction numbers of at least one historical transaction included in the historical transaction information are arranged in chronological order of timestamps;
[0022] After determining that the target transaction is not a duplicate transaction, it further includes:
[0023] Store the transaction number of the target transaction in the historical transaction information corresponding to the first identification group.
[0024] As an optional implementation, after storing the transaction number of the target transaction in the historical transaction information corresponding to the first identification group, the method further includes:
[0025] Compare the capacity of the historical transaction information with the maximum allowable capacity of the historical transaction queue, where the size of the capacity is positively correlated with the number of transaction numbers included in the corresponding historical transaction information;
[0026] If the capacity is greater than the maximum allowable capacity, delete the transaction numbers corresponding to the earliest timestamps in the historical transaction information until the capacity is less than or equal to the maximum allowable capacity;
[0027] Wherein, the maximum allowable capacity of the historical transaction information is determined by a preset minimum allowable capacity and the frequency of storing transaction numbers in the historical transaction information.
[0028] As an optional implementation, the historical transaction information further includes the timestamp corresponding to the transaction number;
[0029] The relay chain further includes a first plugin, which is used to delete the transaction numbers and corresponding timestamps that meet the first condition in the historical transaction information at a preset time interval;
[0030] Wherein, the first condition is that the time interval between the timestamp corresponding to the transaction number and the first moment exceeds a preset threshold.
[0031] According to the second aspect of the embodiments of the present application, there is provided a cross-chain transaction device, which is applied to a relay chain between a source service chain and a destination service chain. The device includes:
[0032] A first receiving module, configured to receive a target transaction request; wherein, the target transaction request includes the timestamp of the target transaction and first transaction identification information, and the timestamp is used to represent the moment when the source service chain initiates the target transaction to the destination service chain;
[0033] A first processing module, configured to reject the target transaction request if it is determined that the time interval between the timestamp and the first moment exceeds a preset threshold; the first moment is the moment when the relay chain generates the latest block;
[0034] If it is determined that the time interval does not exceed the preset threshold, determine the first identification group corresponding to the first transaction identification information according to the corresponding information between the preset transaction identification information and the identification group;
[0035] A second processing module, configured to obtain historical transaction information corresponding to the first identification group, and determine whether the target transaction is a duplicate transaction according to whether the first transaction identification information exists in the historical transaction information.
[0036] According to a third aspect of the embodiments of the present application, there is provided an electronic device, including: a memory, a processor, and a computer program stored on the memory, where the processor executes the computer program to implement the steps of the method according to any one of the first aspects.
[0037] According to a fourth aspect of the embodiments of the present application, there is provided a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the method according to any one of the first aspects are implemented.
[0038] The beneficial effects brought by the technical solutions provided by the embodiments of the present application are as follows:
[0039] After receiving a target transaction request in the relay link of the embodiments of the present application, compare the timestamp of the target transaction with the time of the latest generated block in the relay chain. If the time interval between the timestamp and the time of the latest generated block is less than a preset threshold, it means that the transaction request has timed out, and the transaction request is rejected for processing to ensure the timeliness of the transaction and effectively prevent the processing of outdated transactions; further, if the time interval does not exceed the preset threshold, then according to the corresponding information between the preset transaction identification information and the identification group, determine the first identification group corresponding to the first transaction identification information; obtain the historical transaction information corresponding to the first identification group, and determine whether the target transaction is a duplicate transaction according to whether the first transaction identification information exists in the historical transaction information, effectively solving the technical problem in the prior art that when a cross-chain gateway fails or is controlled by a hacker, the transaction event is encapsulated multiple times and submitted to the relay chain, resulting in duplicate transactions on the target business chain. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for the description in the embodiments of the present application.
[0041] Figure 1a It is an interaction schematic diagram of a cross-chain transaction method applied to a relay chain in the related art provided by the embodiments of the present application;
[0042] Figure 1b It is an interaction schematic diagram of a cross-chain transaction method applied to a relay chain provided by the embodiments of the present application;
[0043] Figure 2 It is a flowchart of a cross-chain transaction method provided by the embodiments of the present application;
[0044] Figure 3A schematic flowchart of a relay chain for processing cross-chain transactions provided by an embodiment of the present application;
[0045] Figure 4 A schematic structural diagram of a cross-chain transaction device provided by an embodiment of the present application;
[0046] Figure 5 A schematic structural diagram of an electronic device provided by an embodiment of the present application. Detailed implementation manners
[0047] The embodiments of the present application will be described below with reference to the accompanying drawings in the present application. It should be understood that the embodiments described below in conjunction with the accompanying drawings are exemplary descriptions for explaining the technical solutions of the embodiments of the present application, and do not constitute limitations on the technical solutions of the embodiments of the present application.
[0048] Those skilled in the art of the present technology can understand that, unless specifically stated otherwise, the singular forms "a", "an", and "the" used herein may also include the plural forms. It should be further understood that the terms "comprising" and "including" used in the embodiments of the present application mean that the corresponding features can be implemented as the presented features, information, data, steps, operations, elements, and / or components, but do not exclude the implementation of other features, information, data, steps, operations, elements, components, and / or their combinations supported by the art of the present technology. It should be understood that when we say an element is "connected" or "coupled" to another element, the one element can be directly connected or coupled to the other element, or it can mean that the one element and the other element establish a connection relationship through an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein indicates at least one of the items defined by the term, for example, "A and / or B" can be implemented as "A", or implemented as "B", or implemented as "A and B".
[0049] In the embodiments of the present application, the term "module" or "unit" refers to a computer program with a predetermined function or a part of a computer program, which works together with other related parts to achieve a predetermined goal, and can be fully or partially implemented by using software, hardware (such as a processing circuit or a memory), or a combination thereof. Similarly, one processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be a part of an overall module or unit that includes the functions of the module or unit.
[0050] To make the purpose, technical solutions, and advantages of the present application clearer, the embodiments of the present application will be further described in detail below in conjunction with the accompanying drawings.
[0051] With the continuous development of blockchain technology, more and more blockchain systems adopt cross-chain technology for interoperable access and collaboration. Cross-chain technology refers to connecting homogeneous or heterogeneous blockchain systems to achieve information exchange between blockchains.
[0052] Currently, it is relatively common to implement cross-chain transactions using relay chain technology. Specifically, the source application chain system forwards cross-chain transactions to the relay chain system through a cross-chain gateway. The relay chain system verifies the cross-chain transactions. After successful verification, it forwards the cross-chain transactions to the destination application chain system through another cross-chain gateway.
[0053] In the above technology, the relay chain prevents replay attacks by verifying the nonce value in the encapsulated data. The nonce value is a unique value for one-time use. The method for the relay chain to prevent repeated attacks is to store the nonce values within a period of time in a pool. If the value is repeated, the transaction is considered a repeated transaction. However, in the case of cross-chain gateway failures or the cross-chain gateway being controlled, when the cross-chain gateway submits to the relay chain, it will include multiple nonce values, that is: the cross-chain gateway will encapsulate the transaction event multiple times and then submit it to the relay chain; since the encapsulated cross-chain events actually exist on the source business chain, signature verification, hash verification, etc. can all pass, thus bypassing the defense against replay attacks on the relay chain, resulting in repeated transactions on the destination business chain and causing losses to users on the destination business chain.
[0054] Furthermore, in the above technology, the transaction events submitted by the cross-chain gateway to the relay chain include nonce values, and the relay chain needs to save the received nonce values in a pool; when the transactions of each business chain are relatively frequent, the nonce values within a time threshold need to be saved, resulting in a relatively large and uncontrollable space occupied by the pool.
[0055] To solve the problems existing in the related technology, the applicant thought that the two-phase commit technology can be adopted to ensure the consistency and reliability of cross-chain transactions. Specifically, the source business chain initiating the cross-chain transaction locks the assets of its own chain and generates proceeds, and then sends a prepare request to the destination business chain; the receiving account on the destination business chain performs local operations to prepare to receive the assets. If the preparation is successful, the destination business chain sends a response to the source business chain indicating that it is ready; after receiving the response from the destination business chain, the source business chain initiates the transfer of its own chain assets and notifies the destination chain B that it can complete the asset transfer operation at the receiving end; after the destination business chain completes the asset transfer at the receiving end, it sends a confirmation message to the source business chain for cross-chain asset transfer.
[0056] The above method adopts the two-phase commit technology. Even though it is executed twice on the destination business chain, there is only one freeze on the source business chain. Therefore, the second submission will fail on the source business chain. At this time, Chain B will be notified to roll back the second transaction, thus avoiding duplicate transactions. However, this method has high technical complexity and requires rolling back twice when the submission fails on the source business chain, resulting in a problem of excessive transaction time. Therefore, while solving the problems of duplicate transactions and large occupied space of nonce values brought by cross-chain transactions using relay chain technology, without introducing other problems has become an urgent task for relay chain technology.
[0057] The cross-chain transaction method, device, electronic device, and computer-readable storage medium provided by this application aim to solve the above technical problems in the prior art.
[0058] The technical solutions of the embodiments of this application and the technical effects produced by the technical solutions of this application will be described below through the description of several exemplary embodiments. It should be noted that the following embodiments can refer to, draw on, or combine with each other. For the same terms, similar features, and similar implementation steps in different embodiments, they will not be described repeatedly.
[0059] Figure 1a It is an interaction schematic diagram of a cross-chain transaction method applied to a relay chain in the related technology provided by the embodiments of this application; as shown in the figure, it includes the following steps:
[0060] Step 1: Service A on Application Chain A makes a cross-chain service call. Application Chain A generates a cross-chain event of INTERCHAIN type and sends the cross-chain event of INTERCHAIN type to Cross-chain Gateway A.
[0061] Step 2: Cross-chain Gateway A receives the cross-chain event of INTERCHAIN type.
[0062] Step 3: Cross-chain Gateway A sends a cross-chain transaction to the relay chain.
[0063] Step 4: The relay chain verifies the validity of the cross-chain transaction.
[0064] Step 5: After verifying the validity of the cross-chain transaction, the relay chain synchronizes the cross-chain transaction to Cross-chain Gateway B.
[0065] Step 6: Cross-chain Gateway B forwards the cross-chain transaction to Application Chain B.
[0066] Step 7: Application Chain B returns the cross-chain service operation result to Cross-chain Gateway B; if the call of Application Chain B fails or times out, then the cross-chain operation will be rolled back.
[0067] Step 8: Cross-chain Gateway B forwards the cross-chain transaction of receipt type to the relay chain.
[0068] Step 9: The relay chain synchronizes the cross-chain transaction to cross-chain gateway A;
[0069] Step 10: If the call to application chain B is successful, cross-chain gateways A and B initiate a commit call; conversely, if the call to application chain B fails, cross-chain gateways A and B initiate a rollback call.
[0070] Figure 1b It is an interaction schematic diagram of the cross-chain transaction method applied to the relay chain provided by the embodiment of the present application. As shown in the figure, the relay chain adds two links, namely dynamic queue transaction and queue cleaning, to the cross-chain transaction method provided by the related technology. It can be understood that after receiving the target transaction request sent by cross-chain gateway A, the relay chain stores the transaction information included in the target transaction request in the dynamic transaction queue. The dynamic transaction queue stores the historical transaction information of the first identification group, and the first identification group is the identification group corresponding to the first transaction identification information included in the target transaction request. In the embodiment of the present application, while storing the transaction information of the target transaction into the dynamic transaction queue, the dynamic transaction queue is cleaned to reduce the space occupied by the transaction information.
[0071] The following takes the relay chain as the execution subject to illustrate the solution in the embodiment of the present application.
[0072] Figure 2 It is a flowchart of a cross-chain transaction method provided by the embodiment of the present application. This method is applied to the relay chain between the source business chain and the destination business chain. As Figure 2 shown, this method includes:
[0073] S201: Receive a target transaction request; where the target transaction request includes the timestamp of the target transaction and the first transaction identification information, and the timestamp is used to represent the moment when the source business chain initiates the target transaction to the destination business chain.
[0074] In the embodiment of the present application, when service A initiates a cross-chain call, the cross-chain plugin of the source business chain sends the cross-chain request to the cross-chain gateway on the source business chain side. The cross-chain gateway on the source business chain side encapsulates the cross-chain request to generate a target transaction request and sends the target transaction request to the relay chain. After verifying the target transaction request, the relay chain sends the target transaction request to the destination business chain for processing by the destination business chain. It should be noted that the target transaction request in the embodiment of the present application includes the timestamp of the target transaction and the first transaction identification information; where the timestamp is used to represent the moment when the source business chain initiates the target transaction to the target business chain.
[0075] S202: If it is determined that the time interval between the timestamp and the first moment exceeds a preset threshold, reject the target transaction request; the first moment is the moment when the relay chain generates the latest block;
[0076] If it is determined that the time interval does not exceed the preset threshold, then according to the corresponding information between the preset transaction identification information and the identification groups, determine the first identification group corresponding to the first transaction identification information.
[0077] In the embodiments of the present application, a new block is generated on the relay chain every once in a while, and the time when the new block is generated is recorded. Since there is no system time on the relay chain, therefore, in the embodiments of the present application, the time when the relay chain generates the latest block is approximated as the current time of the relay chain; it can be understood that when the relay chain receives a target transaction request, it will obtain the time when the latest block is generated as the first moment, and determine the time interval between the time stamp of the target transaction and the first moment. If this time interval is less than the preset threshold, it means that the target transaction has timed out, and the target transaction request is rejected.
[0078] It should be noted that in the embodiments of the present application, the preset threshold includes but is not limited to the timeout time of the source service chain; in practical applications, the relay chain is connected to multiple service chains at the same time, and the timeout times of each service chain can be the same or different.
[0079] It should also be noted that in the embodiments of the present application, after the relay chain receives a transaction request, it will group the transaction request, and save the transaction information of the transaction request according to the group corresponding to the transaction request, to become the historical transaction information corresponding to the group.
[0080] S203. Obtain the historical transaction information corresponding to the first identification group, and determine whether the target transaction is a repeated transaction according to whether the first transaction identification information exists in the historical transaction information.
[0081] In the embodiments of the present application, every time the relay chain receives a transaction request, if the transaction request is not a repeated transaction request, it will determine the corresponding representation group of the transaction request according to the corresponding relationship between the preset transaction identification information and the identification groups, and save the transaction information carried by the transaction request to obtain the historical transaction information corresponding to the first identification group, and determine whether the target transaction is a repeated transaction according to whether the first transaction identification information exists in the historical transaction information.
[0082] In the embodiments of the present application, after receiving a target transaction request, the relay link compares the timestamp of the target transaction with the time of the latest generated block in the relay chain. If the time interval between the timestamp and the time of the latest generated block is less than a preset threshold, it indicates that the transaction request has timed out, and the transaction request is rejected for processing to ensure the timeliness of the transaction and effectively prevent the processing of outdated transactions. Further, if the time interval does not exceed the preset threshold, according to the corresponding information between the preset transaction identification information and the identification groups, the first identification group corresponding to the first transaction identification information is determined; the historical transaction information corresponding to the first identification group is obtained, and whether the target transaction is a duplicate transaction is judged based on whether the first transaction identification information exists in the historical transaction information, effectively solving the technical problem in the prior art that when the cross-chain gateway fails or is controlled by a hacker, the transaction event is encapsulated multiple times and submitted to the relay chain, resulting in duplicate transactions on the target business chain.
[0083] Based on the above embodiments, as an optional embodiment, the first transaction identification information includes at least one of an identifier of the source business chain, an identifier of the destination business chain, and a transaction number of the target transaction.
[0084] In the embodiments of the present application, the identifier of the source business chain can clearly indicate the business chain of the transaction initiator to ensure the clarity of the transaction source; the identifier of the destination business chain identifies the target business chain of the transaction, which helps to ensure that the transaction is correctly sent to the expected recipient; the transaction number, as the unique identifier of the transaction, helps to accurately track and locate a specific transaction within the business chain or across business chains; by setting at least one of the identifier of the source business chain, the identifier of the destination business chain, and the transaction number of the target transaction as the first transaction identification information, the accuracy of the transaction can be improved. After receiving the target transaction request, the relay link can quickly group the first transaction identification information and determine whether the first transaction identification information is included according to the historical transaction information corresponding to the first identification group, and then determine whether the target transaction is a duplicate transaction.
[0085] Based on the above embodiments, as an optional embodiment, the corresponding information between the preset transaction identification information and the identification groups includes: the mapping relationship between different information combinations and different identification groups, where each information combination includes an identifier of the source business chain, an identifier of the destination business chain, and the tail number of the transaction number.
[0086] Determining the first identification group corresponding to the first transaction identification information according to the corresponding information between the preset transaction identification information and the identification groups includes:
[0087] Determining a first information combination according to the identifier of the source business chain, the identifier of the destination business chain, and the tail number of the transaction number of the target transaction;
[0088] Group the identifiers that have a mapping relationship with the first information combination as the first identifier group corresponding to the first transaction identifier information.
[0089] In the embodiments of the present application, the identifier of the source service chain and the identifier of the destination service chain can effectively distinguish the initiator and the receiver of the transaction request. However, there may be a large number of transaction requests in the source service chain and the destination service chain. Therefore, if the information combination only includes the identifier of the source service chain and the identifier of the destination service chain, it will cause the historical transaction information corresponding to the identifier group to be too large. Therefore, it is necessary to add the transaction number to the information combination. However, the transaction numbers included in each transaction request are different. Therefore, each transaction request between the source service chain and the destination service chain will correspond to an identifier group, resulting in a large number of identifier groups, which is not convenient for the relay chain to search later. Therefore, in the embodiments of the present application, the identifier of the source service chain, the identifier of the destination service chain, and the last digit of the transaction number are used as the first information combination to group the transaction requests. In this way, for the transaction requests between the same source service chain and destination service chain, the number of identifier groups on the relay chain can be greatly reduced, which is convenient for the relay chain to quickly locate the identifier group corresponding to the first transaction identifier information. For example, assuming that the transaction number is 6 - digit Arabic numerals, the transaction number can be at most 10 to the 6th power, that is, 1 million. For the transaction requests between the same source service chain and destination service chain, the relay chain needs to pre - set 1 million identifier groups in advance. After receiving a new transaction request later, it is necessary to search whether the transaction number of this transaction request already exists among these 1 million identifier groups. However, if the last digit of the transaction number can only be one of the 10 numbers from 0 to 9, for the transaction requests between the same source service chain and destination service chain, only 10 identifier groups need to be pre - set in advance, and the workload is greatly reduced.
[0090] Further, in the embodiments of the present application, after receiving the target transaction request, the relay chain obtains the identifier of the source service chain, the identifier of the destination service chain, and the last digit of the transaction number of the target transaction as the first information combination, and determines the identifier group corresponding to the first information combination according to the mapping relationship between different information combinations and different identifier groups as the first identifier group corresponding to the first transaction identifier information.
[0091] In the embodiments of the present application, by mapping transaction identification information (source business chain identifier, destination business chain identifier, transaction number suffix) to specific identification groups, a large amount of transaction data can be quickly classified into different groups; this classification helps subsequent data processing and analysis because similar or related transactions will be grouped together. At the same time, as the business develops and changes, the transaction types and characteristics may change. By adjusting the corresponding information between the preset transaction identification information and the identification groups, these changes can be easily adapted to maintain the flexibility and scalability of the transaction processing system. In summary, determining the first identification group corresponding to the first transaction identification information according to the corresponding information between the preset transaction identification information and the identification groups effectively improves the efficiency and accuracy of transaction processing, and also enhances the flexibility and scalability of transaction management.
[0092] Based on the above embodiments, as an optional embodiment, the first identification group further includes the storage address of historical transaction information, and the historical transaction information includes the transaction numbers of at least one historical transaction of the corresponding identification group:
[0093] Obtain the historical transaction information corresponding to the first identification group, and determine whether the target transaction is a duplicate transaction according to whether the first transaction identification information exists in the historical transaction information, including:
[0094] According to the address of the historical transaction information, obtain the transaction numbers of at least one historical transaction corresponding to the first identification group;
[0095] If the transaction number of the target transaction is included in the transaction numbers of at least one historical transaction corresponding to the first identification group, determine that the target transaction is a duplicate transaction;
[0096] If the transaction number of the target transaction is not included in the transaction numbers of at least one historical transaction corresponding to the first identification group, determine that the target transaction is not a duplicate transaction.
[0097] In the embodiments of the present application, the relay chain stores the first identification group in the following structure:
[0098]
[0099] Among them, "From" is used to represent the identifier of the source business chain; "To" is used to represent the identifier of the destination business chain, "BeginTime" is used to represent the time stamp of the earliest received transaction request, "EndTime" is used to represent the time stamp of the latest received transaction request, "QueueNum" is used to represent the number of received transaction requests, and "QueuePoint" is used to represent the address where the historical transaction information is stored.
[0100] It should be noted that in the embodiments of the present application, the relay chain stores the historical transaction information corresponding to the first identifier group in a queue. The queue can be found based on the address where the historical transaction information is stored to obtain the historical transaction information. The historical transaction information includes the transaction number of the historical transaction, that is: for transaction requests with the same identifier of the source service chain, identifier of the destination service chain, and tail number of the transaction number, the relay chain saves the transaction number included in the transaction request as transaction information in the queue. The relay chain matches the transaction number of the target transaction with the transaction numbers of the historical transactions. If there is a match, it indicates that the target transaction is a duplicate transaction; otherwise, if there is no match, it indicates that the target transaction is not a duplicate request.
[0101] In the embodiments of the present application, by checking the historical transaction information in the first identifier group, the relay chain can accurately determine whether the target transaction is a duplicate transaction. This helps prevent problems such as financial losses and data chaos caused by duplicate transactions, timely prevent potential fraud behaviors, and protect the financial security of users. At the same time, by quickly verifying the validity of transactions, the waiting time for transactions can be reduced, improving the user's transaction experience.
[0102] Based on the above embodiments, as an optional embodiment, the transaction numbers of at least one historical transaction included in the historical transaction information are arranged in the order of time stamps.
[0103] After determining that the target transaction is not a duplicate transaction, the following steps are further included:
[0104] Store the transaction number of the target transaction into the historical transaction information corresponding to the first identifier group.
[0105] In the embodiments of the present application, the historical transaction information corresponding to the first group identifier is stored in a queue. The characteristic of the queue is first in, first out, that is: the transaction number of the earliest received transaction request is stored at the head, and the transaction number of the latest received transaction request is stored at the end of the queue. Therefore, in the embodiments of the present application, when the relay chain receives a target transaction that is not a duplicate transaction, the transaction number of the target transaction is added to the historical transaction information corresponding to the first identifier group, that is: inserted at the end of the queue.
[0106] Optionally, in the embodiments of the present application, in addition to storing the transaction number of the target transaction into the historical transaction information, the time stamp of the target transaction can also be stored into the historical transaction information, that is: the transaction number and time stamp of the target transaction are inserted at the end of the queue at the same time. In the embodiments of the present application, the historical transaction information can be represented by the following structure:
[0107]
[0108] Among them, "Tx" is used to represent the transaction number of the target transaction, and "TimeStamp" is used to represent the time stamp of the target transaction.
[0109] It should be noted that in practical applications, due to network latency or the processing order of the cross-chain gateway, the order in which the target transaction requests are received by the relay chain is not exactly the same as the time when the time stamps of the target transactions included in the target transaction requests occur. That is, it is possible that the time stamp of transaction A is earlier than the time stamp of transaction B, but the request for transaction A arrives at the relay chain after the request for transaction B. At this time, under the condition of excluding non-duplicate transactions, the transaction number and time stamp are stored in the order of the received transaction requests. That is, in the historical transaction information, the transaction number and time stamp of transaction B are in front of the transaction number and time stamp of transaction A.
[0110] In the embodiments of the present application, the transaction numbers are arranged in the order of the time stamps, ensuring the chronological order of the transaction history. This enables the relay chain to search for historical transactions in chronological order and quickly determine whether the target transaction is a duplicate transaction. When verifying whether the target transaction is a duplicate transaction, the most recent historical transaction records can be checked first, reducing the verification time and improving the processing efficiency. Further, since the transaction number is associated with the time stamp, any tampering with the transaction history can be easily detected, thereby enhancing the security of the transaction.
[0111] Based on the above embodiments, as an optional embodiment, after storing the transaction number of the target transaction into the historical transaction information corresponding to the first identification group, the following further includes:
[0112] Compare the capacity of the historical transaction information with the maximum allowable capacity of the historical transaction queue. The size of the capacity is positively correlated with the number of transaction numbers included in the corresponding historical transaction information;
[0113] If the capacity is greater than the maximum allowable capacity, start deleting from the transaction number corresponding to the earliest time stamp in the historical transaction information until the capacity is less than or equal to the maximum allowable capacity;
[0114] Among them, the maximum allowable capacity of the historical transaction information is determined by a preset minimum allowable capacity and the frequency of storing transaction numbers in the historical transaction information.
[0115] In the embodiments of the present application, the historical transaction information has a minimum allowable capacity and a maximum allowable capacity. Among them, the minimum allowable capacity is a pre-set capacity, and the maximum allowable capacity is determined by the pre-set minimum allowable capacity and the frequency of storing transaction numbers in the historical transaction information. It can be understood that in the embodiments of the present application, the relay chain pre-sets a minimum allowable capacity for the historical transaction information corresponding to each identification group; and the activity levels of different service chains are different; it can be understood that the transaction frequency on some service chains is relatively high. Therefore, the minimum allowable capacity cannot meet the capacity requirements of the historical transaction information; while the transaction frequency on some service chains is relatively low, and the minimum allowable capacity can already meet the capacity requirements of the historical transaction information. Therefore, in the embodiments of the present application, considering the activity level of the service chain and the size of the storage space on the relay chain, a maximum allowable capacity is set for the historical transaction information corresponding to each identification group.
[0116] It should be noted that in the embodiments of the present application, the sum of the historical transaction information corresponding to each identification group is a fixed value, that is: the total length of the storage queue of the historical transaction information corresponding to each identification group is fixed, which can avoid the problem that the capacity of the historical transaction information stored on the relay chain is too large due to overly frequent transactions on each transaction chain.
[0117] Optionally, the maximum allowable capacity can be calculated using the following formula:
[0118]
[0119] Where i is the number of the source service chain, j is the number of the service chain connected to the relay chain, the total number of service chains connected to the relay chain is n, K is the total length of the storage queue of the historical transaction information corresponding to each identification group; is the minimum allowable capacity of the source service chain, is the minimum allowable capacity of the service chain numbered j, is the frequency of storing transaction numbers in the source service chain, is the frequency of storing transaction numbers in each service chain connected to the relay chain.
[0120] It should be noted that in the embodiments of the present application, before storing the transaction number of the target transaction into the historical transaction information corresponding to the first identification group, it is necessary to calculate the maximum allowable capacity of the historical transaction information. After inserting the transaction number of the target transaction, it is necessary to compare the current capacity of the historical transaction information with the maximum allowable capacity. If it exceeds the maximum allowable capacity, it is necessary to delete the transaction numbers corresponding to the earliest timestamps in the historical transaction information until the capacity is less than or equal to the maximum allowable capacity.
[0121] In the embodiments of the present application, by setting the minimum allowable capacity and the maximum allowable capacity according to the historical transaction information corresponding to each identifier group, it is possible to allocate more capacity to the business chains with active transactions while avoiding the problem of excessive storage space occupation on the relay chain due to frequent transactions of the business chains.
[0122] Based on the above embodiments, as an optional embodiment, the historical transaction information further includes the time stamp corresponding to the transaction number;
[0123] The relay chain further includes a first plug-in, which is used to delete the transaction numbers and the corresponding time stamps in the historical transaction information that meet the first condition at a preset time interval;
[0124] Wherein, the first condition is that the time interval between the time stamp corresponding to the transaction number and the first moment exceeds a preset threshold.
[0125] In the embodiments of the present application, the target transaction has a timeout period, that is, after this time, the relay chain will no longer process the target transaction. Therefore, the transaction numbers in the historical transaction information whose time interval from the first moment exceeds the preset threshold and the corresponding time stamps of the transaction numbers do not need to be stored anymore, and the corresponding time stamps of these transaction numbers can be deleted.
[0126] For example: The first moment is 2:00, and the timeout period of the target transaction is 10 minutes. When the relay chain receives a target transaction request with a time stamp before 1:50, the target transaction request will be directly rejected; therefore, the transaction numbers stored before 1:50 and the corresponding time stamps can be directly deleted.
[0127] In the embodiments of the present application, a first plug-in is set on the relay chain to regularly clean up the earliest transaction information in the historical transaction information corresponding to each identifier group, reducing the space occupied by the historical transaction information.
[0128] To facilitate those skilled in the art to clearly understand the process of the relay chain processing cross-chain transactions, the embodiments of the present application provide a schematic diagram of the process of the relay chain processing cross-chain transactions, as Figure 3As shown, after receiving a target transaction request, the relay link first determines whether the target transaction is a duplicate transaction based on the first transaction identification information included in the target transaction request. If it is determined to be a duplicate transaction, the target transaction request is directly rejected. If it is determined not to be a duplicate transaction, the first identification group corresponding to the first transaction identification information is determined according to the corresponding relationship between the first transaction identification information and the identification groups; calculate the maximum allowable capacity of the historical transaction information corresponding to the first identification group, then store the transaction number of the target transaction into the historical transaction information corresponding to the first identification group, and clean up the historical transaction information according to the maximum allowable capacity, so that the capacity of the historical transaction information does not exceed the maximum allowable capacity; finally, verify the authenticity of the target transaction request.
[0129] It should be noted that in the embodiments of the present application, the target transaction request further includes a cross-chain transaction certificate, which is used to verify the validity and existence of each cross-chain transaction. The authenticity of the target transaction request can be verified according to the cross-chain transaction certificate.
[0130] Figure 4 It is a schematic structural diagram of a cross-chain transaction device provided by an embodiment of the present application. The cross-chain transaction device is applied to a relay chain between a source service chain and a destination service chain; as Figure 4 shown, the device includes: a first receiving module 1001, a first processing module 1002, and a second processing module 1003.
[0131] The first receiving module 1001 is configured to receive a target transaction request; wherein, the target transaction request includes a time stamp of the target transaction and first transaction identification information, and the time stamp is used to represent the moment when the source service chain initiates the target transaction to the destination service chain;
[0132] The first processing module 1002 is configured to reject the target transaction request if it is determined that the time interval between the time stamp and the first moment exceeds a preset threshold; the first moment is the moment when the relay chain generates the latest block;
[0133] If it is determined that the time interval does not exceed the preset threshold, the first identification group corresponding to the first transaction identification information is determined according to the preset corresponding information between the transaction identification information and the identification groups;
[0134] The second processing module 1003 is configured to obtain the historical transaction information corresponding to the first identification group, and determine whether the target transaction is a duplicate transaction according to whether the first transaction identification information exists in the historical transaction information.
[0135] The cross-chain transaction device applied to the relay chain in the embodiments of the present application can execute the cross-chain transaction method provided in the embodiments of the present application, and their implementation principles are similar. The actions performed by each module in the cross-chain transaction device applied to the relay chain in the embodiments of the present application correspond to the steps in the cross-chain transaction method executed by the relay chain in the embodiments of the present application. For the detailed function descriptions of each module of the cross-chain transaction device applied to the relay chain, reference can be specifically made to the descriptions in the corresponding methods shown above, and details are not described herein again.
[0136] After the relay link in the embodiments of the present application receives a target transaction request, it compares the timestamp of the target transaction with the time of the latest generated block of the relay chain. If the time interval between the timestamp and the time of the latest generated block is less than a preset threshold, it indicates that the transaction request has timed out, and the transaction request is rejected for processing to ensure the timeliness of the transaction and effectively prevent the processing of outdated transactions. Further, if the time interval does not exceed the preset threshold, the first identification group corresponding to the first transaction identification information is determined according to the corresponding information between the preset transaction identification information and the identification groups; the historical transaction information corresponding to the first identification group is obtained, and whether the target transaction is a duplicate transaction is judged according to whether the first transaction identification information exists in the historical transaction information, effectively solving the technical problem in the prior art that when a cross-chain gateway fails or is controlled by a hacker, the transaction event is encapsulated multiple times and then submitted to the relay chain, resulting in duplicate transactions on the target business chain.
[0137] Further, in the embodiments of the present application, by dynamically adjusting the maximum allowable capacity corresponding to the historical transaction information of the identification group, while taking into account the activity level of the business chain, it can effectively avoid the problem that the storage space on the relay chain is occupied too much due to frequent transactions on the business chain; in addition, the embodiments of the present application also set up a plugin on the relay chain to regularly clean the earliest transaction information in the historical transaction information corresponding to each identification group, reducing the space occupied by the historical transaction information.
[0138] Figure 5 It is a schematic structural diagram of an electronic device provided in the embodiments of the present application, as Figure 5 shown, the electronic device 4000 includes: a processor 4001 and a memory 4003. Among them, the processor 4001 and the memory 4003 are connected, such as connected through a bus 4002. Optionally, the electronic device 4000 may further include a transceiver 4004, and the transceiver 4004 may be used for data interaction between the electronic device and other electronic devices, such as data sending and / or data receiving, etc. It should be noted that in actual applications, the transceiver 4004 is not limited to one, and the structure of the electronic device 4000 does not constitute a limitation to the embodiments of the present application.
[0139] The processor 4001 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It may implement or execute various exemplary logical blocks, modules, and circuits described in connection with the disclosure of this application. The processor 4001 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.
[0140] The bus 4002 may include a path for transmitting information between the above components. The bus 4002 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. The bus 4002 may be divided into an address bus, a data bus, a control bus, etc. For the sake of representation, Figure 5 only a thick line is used to represent it herein, but it does not mean that there is only one bus or one type of bus.
[0141] The memory 4003 may be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or it may also be an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory), or other optical disc storage, optical disc storage (including compact discs, laser discs, optical discs, digital versatile discs, Blu-ray discs, etc.), magnetic disk storage media, other magnetic storage devices, or any other medium that can be used to carry or store computer programs and can be read by a computer, which is not limited herein.
[0142] The memory 4003 is used to store the computer program for implementing the embodiments of the present application, and is controlled by the processor 4001 for execution. The processor 4001 is used to execute the computer program stored in the memory 4003 to implement the steps shown in the foregoing method embodiments.
[0143] Among them, the electronic device package may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Tablet Computers), PMPs (Portable Multimedia Players), vehicle terminals (such as vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 5 The electronic device shown is only an example and should not impose any limitations on the functions and usage scope of the embodiments of the present disclosure.
[0144] The embodiments of the present application provide a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps and corresponding contents shown in the foregoing method embodiments can be implemented. Compared with the prior art, it can achieve:
[0145] It should be noted that the computer-readable medium in the present disclosure may be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, the computer-readable storage medium may be any tangible medium that contains or stores a program, and the program can be used by or in combination with an instruction execution system, apparatus, or device. In the present disclosure, the computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium may also be any computer-readable medium other than the computer-readable storage medium, and the computer-readable signal medium can send, propagate, or transmit a program for use by or in combination with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted by any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0146] The embodiment of the present application also provides a computer program product, including a computer program, which can implement the steps and corresponding content of the foregoing method embodiment when executed by a processor. Compared with the prior art, it can achieve:
[0147] The terms "first", "second", "third", "fourth", "1", "2", etc. (if any) in the specification, claims and the above-mentioned drawings of the present application are used to distinguish similar objects, and do not necessarily need to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances, so that the embodiments of the present application described here can be implemented in an order other than the illustrated or textually described order.
[0148] It should be understood that although the flowchart in the embodiment of the present application indicates each operation step by an arrow, the execution order of these steps is not limited to the order indicated by the arrow. Unless there is a clear description in this article, in some implementation scenarios of the embodiment of the present application, the implementation steps in each flowchart can be executed in other orders according to requirements. In addition, some or all of the steps in each flowchart may include multiple sub-steps or multiple stages based on the actual implementation scenario. Some or all of these sub-steps or stages can be executed at the same time, and each sub-step or stage among these sub-steps or stages can also be executed at different times respectively. In the scenario where the execution times are different, the execution order of these sub-steps or stages can be flexibly configured according to requirements, and the embodiment of the present application does not limit this.
[0149] The above are only optional implementation manners of some implementation scenarios of the present application. It should be noted that for those of ordinary skill in the art, without departing from the technical concept of the solution of the present application, using other similar implementation means based on the technical idea of the present application also belongs to the protection scope of the embodiments of the present application.
Claims
1. A cross-chain transaction method, characterized in that: The method is applied to a relay chain between a source service chain and a destination service chain, and the method includes: Receive a target transaction request; wherein the target transaction request includes a timestamp of the target transaction and first transaction identification information, and the timestamp is used to indicate the time when the source service chain initiates the target transaction to the destination service chain; If it is determined that the time interval between the timestamp and the first time exceeds a preset threshold, the target transaction request is rejected; the first time is the time when the relay chain generates the latest block; If it is determined that the time interval does not exceed the preset threshold, determining the first identification group corresponding to the first transaction identification information according to preset correspondence information between the transaction identification information and the identification group; The historical transaction information corresponding to the first identification group is obtained, and whether the target transaction is a repeated transaction is determined based on whether the historical transaction information contains the first transaction identification information.
2. The method according to claim 1, characterized in that The first transaction identification information includes: at least one of an identifier of a source service chain, an identifier of a destination service chain, and a transaction number of the target transaction.
3. The method according to claim 2, characterized in that The correspondence information between the preset transaction identification information and the identification group includes: a mapping relationship between different information combinations and different identification groups, wherein each information combination includes an identifier of a source service chain, an identifier of a destination service chain, and a tail number of a transaction number; The determining, according to the preset correspondence information between the transaction identification information and the identification group, the first identification group corresponding to the first transaction identification information includes: Determine a first information combination according to an identifier of a source service chain of the target transaction, an identifier of a destination service chain, and a last digit of a transaction number; An identification group having a mapping relationship with the first information combination is used as a first identification group corresponding to the first transaction identification information.
4. The method according to claim 3, characterized in that The first identification group also includes a storage address of historical transaction information, and the historical transaction information includes a transaction number of at least one historical transaction of the corresponding identification group: The acquiring of historical transaction information corresponding to the first identification group, and judging whether the target transaction is a repeated transaction according to whether the historical transaction information contains the first transaction identification information, comprises: According to the address of the historical transaction information, obtaining a transaction number of at least one historical transaction corresponding to the first identification group; If the transaction number of at least one historical transaction corresponding to the first identification group includes the transaction number of the target transaction, determining that the target transaction is a repeated transaction; If the transaction number of at least one historical transaction corresponding to the first identification group does not include the transaction number of the target transaction, it is determined that the target transaction is not a duplicate transaction.
5. The method according to claim 4, characterized in that The transaction number of at least one historical transaction included in the historical transaction information is arranged in the order of the timestamps; The step of determining that the target transaction is not a duplicate transaction further includes: The transaction number of the target transaction is stored in the historical transaction information corresponding to the first identification group.
6. The method according to claim 5, characterized in that The step of storing the transaction number of the target transaction in the historical transaction information corresponding to the first identification group further includes: Comparing the capacity of the historical transaction information with the maximum allowed capacity of the historical transaction queue, wherein the size of the capacity is positively correlated with the number of transaction numbers included in the corresponding historical transaction information; If the capacity is greater than the maximum allowed capacity, then the transaction number corresponding to the earliest timestamp in the historical transaction information is deleted until the capacity is less than or equal to the maximum allowed capacity; The maximum permissible capacity of the historical transaction information is determined by a preset minimum permissible capacity and a frequency of storing transaction numbers in the historical transaction information.
7. The method according to any one of claims 4 to 6, characterized in that: The historical transaction information also includes a timestamp corresponding to the transaction number; The relay chain also includes a first plug-in, which is used to delete the transaction number and the corresponding timestamp that meet the first condition in the historical transaction information at a preset time interval; The first condition is that the time interval between the timestamp corresponding to the transaction number and the first moment exceeds a preset threshold.
8. A cross-chain transaction device, characterized in that: The device is applied to a relay chain between a source service chain and a destination service chain, and the device includes: A first receiving module, configured to receive a target transaction request; wherein the target transaction request includes a timestamp of the target transaction and first transaction identification information, wherein the timestamp is used to indicate the time when the source service chain initiates the target transaction to the destination service chain; A first processing module, configured to reject the target transaction request if it is determined that the time interval between the timestamp and a first moment exceeds a preset threshold; the first moment is the moment when the relay chain generates the latest block; If it is determined that the time interval does not exceed the preset threshold, determining the first identification group corresponding to the first transaction identification information according to preset correspondence information between the transaction identification information and the identification group; The second processing module is configured to obtain historical transaction information corresponding to the first identification group, and determine whether the target transaction is a repeated transaction based on whether the historical transaction information contains the first transaction identification information.
9. An electronic device comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the steps of the method according to any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Transaction processing method and device based on blockchain, and electronic equipment
CN112541825A
Relay chain-based cross-chain asset transaction method, system and equipment
CN115601168A