+

CN114493879A - A cross-blockchain interaction method based on relay chain - Google Patents

A cross-blockchain interaction method based on relay chain Download PDF

Info

Publication number
CN114493879A
CN114493879A CN202210112115.4A CN202210112115A CN114493879A CN 114493879 A CN114493879 A CN 114493879A CN 202210112115 A CN202210112115 A CN 202210112115A CN 114493879 A CN114493879 A CN 114493879A
Authority
CN
China
Prior art keywords
chain
transaction
sub
user
cross
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210112115.4A
Other languages
Chinese (zh)
Inventor
祝清意
曾浩楠
甘臣权
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Chongqing University of Post and Telecommunications
Original Assignee
Chongqing University of Post and Telecommunications
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Chongqing University of Post and Telecommunications filed Critical Chongqing University of Post and Telecommunications
Priority to CN202210112115.4A priority Critical patent/CN114493879A/en
Publication of CN114493879A publication Critical patent/CN114493879A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q40/00Finance; Insurance; Tax strategies; Processing of corporate or income taxes
    • G06Q40/04Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange

Landscapes

  • Business, Economics & Management (AREA)
  • Accounting & Taxation (AREA)
  • Finance (AREA)
  • Engineering & Computer Science (AREA)
  • Development Economics (AREA)
  • Economics (AREA)
  • Marketing (AREA)
  • Strategic Management (AREA)
  • Technology Law (AREA)
  • Physics & Mathematics (AREA)
  • General Business, Economics & Management (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Financial Or Insurance-Related Operations Such As Payment And Settlement (AREA)

Abstract

The invention relates to a block chain crossing interaction method based on a relay chain, which belongs to the field of communication among block chains, comprises the steps of utilizing a transaction matching algorithm to match transactions, coordinating transactions by the relay chain, and verifying transactions by intelligent sub-mark contracts, and specifically comprises the following steps: s1: a user joins a relay chain; s2: a relay chain user submits a transaction requirement, the transaction requirement is packaged and stored in a block on a relay chain, the user performs matching through a transaction matching algorithm, when cross-chain transaction matching is successful, a mark intelligent contract which coordinates the cross-chain transaction at this time is generated on the relay chain, the contract generates a unique ID for marking the cross-chain transaction at this time, and matching information is sent to the user who succeeds in the matching at this time; s3: after matching is successful, entering a preparation stage, and preparing a relay chain and a block chain which specifically participates in chain crossing for the next actual chain crossing behavior; s4: after all preparation works are finished, entering a coordination stage; the coordination phase is a specific execution process of the cross-chain transaction.

Description

一种基于中继链的跨区块链交互方法A Cross-Blockchain Interaction Method Based on Relay Chain

技术领域technical field

本发明属于区块链链间通信领域,涉及一种基于中继链的跨区块链交互方法。The invention belongs to the field of inter-blockchain communication, and relates to a cross-blockchain interaction method based on a relay chain.

背景技术Background technique

区块链技术具有去中心化、去信任化、不可篡改和可追溯等优点,对于传统社会组织和 运作方式是一种颠覆性的变革和挑战,被认为是构建未来“信任互联网”“价值互联网”的 支撑性技术,受到了投资界、学术界、工业界及政府部门等的越来越多的关注。随着区块链 技术的快速发展,各种区块链应用也层出不穷,但目前的区块链项目都是由不同团队基于不 同的场景需求和设计理念,采用不同的技术架构开发出的异构区块链。由于区块链本身的隔 离性等技术特点,不同区块链存储的区块信息之间的隔离不可避免地造成了区块链的“价值 孤岛”效应。因此,如何实现区块链之间的互联互通和价值转移成为当前区块链技术的研究 重点。Blockchain technology has the advantages of decentralization, de-trust, non-tampering and traceability. It is a subversive change and challenge to traditional social organization and operation methods. "The supporting technology of the '' has received more and more attention from the investment community, academia, industry and government departments. With the rapid development of blockchain technology, various blockchain applications are emerging in an endless stream, but the current blockchain projects are heterogeneous projects developed by different teams based on different scenario requirements and design concepts and using different technical architectures. blockchain. Due to the technical characteristics such as the isolation of the blockchain itself, the isolation between the block information stored in different blockchains inevitably causes the "value island" effect of the blockchain. Therefore, how to realize the interconnection and value transfer between blockchains has become the research focus of current blockchain technology.

跨链技术,顾名思义,就是通过某些技术让价值跨过链与链之间的障碍,使得原本存储 在特定区块链上的价值转换为另一条链上的价值,从而实现价值的流通。现目前的跨链技术 主要有四种:公证人机制、侧链/中继、哈希锁定和分布式私钥控制。其中公证人技术虽然实 现简单,但公证人、交易所等可信第三方的引入明显与区块链的去中心化思想相悖,同时也 会带来性能瓶颈的问题。侧链/中继技术实现了异构区块链的跨链,通过中继链也削弱了中心 化问题,但其需要存储大量异构区块链的区块头信息用于验证,且在面对复杂的跨链交易时 性能较差。哈希锁定方案通过哈希时间锁来实现,虽然实现较为简单,也削弱了中心化问题, 但其只实现了跨链资产互换,无法实现跨链资产转移。而分布式私钥控制机制虽然保证了拥 有私钥的用户对资产的所有权不变,但在实现上有较大难度。Cross-chain technology, as the name implies, is to use certain technologies to allow value to cross the barriers between chains, so that the value originally stored on a specific blockchain is converted into the value on another chain, thereby realizing the circulation of value. There are currently four main cross-chain technologies: notary mechanism, side chain/relay, hash locking and distributed private key control. Among them, although the notary technology is simple to implement, the introduction of trusted third parties such as notaries and exchanges is obviously contrary to the decentralization idea of the blockchain, and will also bring about performance bottlenecks. The side chain/relay technology realizes the cross-chain of heterogeneous blockchains, and the centralization problem is also weakened through the relay chain, but it needs to store a large number of block header information of heterogeneous blockchains for verification, and in the face of Poor performance for complex cross-chain transactions. The hash lock scheme is implemented by hash time lock. Although the implementation is relatively simple and the centralization problem is weakened, it only realizes cross-chain asset exchange and cannot realize cross-chain asset transfer. Although the distributed private key control mechanism ensures that the ownership of the assets by the users with the private key remains unchanged, it is more difficult to implement.

发明内容SUMMARY OF THE INVENTION

有鉴于此,本发明的目的在于针对现有中继链跨链方案需要保存大量不同种类区块链区 块头信息用于验证,且可扩展性较差,性能受跨链事务复杂度上升影响较大,提供一种对于 复杂跨链事务仍能有较高效率的高可扩展性的中继链跨链方法,并且减少中继链所需存储的 信息量,提升中继链在协调跨链事务中的效率。In view of this, the purpose of the present invention is that the existing relay chain cross-chain scheme needs to save a large number of different types of blockchain block header information for verification, and the scalability is poor, and the performance is more affected by the increase in the complexity of cross-chain transactions. It provides a highly scalable relay chain cross-chain method that can still have high efficiency for complex cross-chain transactions, and reduces the amount of information that the relay chain needs to store, improving the relay chain’s ability to coordinate cross-chain transactions. efficiency in.

为达到上述目的,本发明提供如下技术方案:To achieve the above object, the present invention provides the following technical solutions:

一种基于中继链的跨区块链交互方法,包括利用交易匹配算法匹配交易,中继链协调交 易,子标志智能合约验证交易,具体包括以下步骤:A relay chain-based cross-blockchain interaction method includes matching transactions using a transaction matching algorithm, coordinating transactions in relay chains, and verifying transactions by sub-sign smart contracts, which specifically includes the following steps:

S1:用户加入中继链;S1: The user joins the relay chain;

S2:中继链用户提交交易需求,交易需求被打包存储在中继链上的区块中,中继链上的 用户通过共识算法中的交易匹配算法进行匹配,当有跨链交易匹配成功,中继链上会生成协 调此次跨链事务的标志智能合约,即跨链事务实例,该合约生成唯一的ID用于标识此次跨 链,并将匹配信息发送给此次匹配成功的用户;S2: Relay chain users submit transaction requirements, and the transaction requirements are packaged and stored in blocks on the relay chain. Users on the relay chain are matched by the transaction matching algorithm in the consensus algorithm. When a cross-chain transaction is successfully matched, The relay chain will generate a sign smart contract for coordinating this cross-chain transaction, that is, an instance of the cross-chain transaction. The contract generates a unique ID to identify this cross-chain, and sends the matching information to the users who have successfully matched this time;

S3:匹配成功后,进入准备阶段,中继链和具体参与跨链的区块链会为接下来的实际跨 链行为作准备;S3: After the matching is successful, it will enter the preparation stage, and the relay chain and the blockchain that specifically participates in the cross-chain will prepare for the actual cross-chain behavior;

S4:当所有准备工作完成后,进入协调阶段;协调阶段为跨链事务具体的执行过程。S4: When all the preparations are completed, enter the coordination stage; the coordination stage is the specific execution process of the cross-chain transaction.

进一步,所述步骤S1具体包括:步骤S1中,用户先成为中继链的用户,才能提交跨链 需求,中继链上的每个用户都拥有信誉值R和历史总收益P,其中信誉值R反映用户在中继 链行为的诚信程度,用户按照规则参与跨链事务和共识过程,信誉值R增加,否则就减少;信誉值R用于影响用户提交交易需求的用户优先级和用户获得共识的概率;历史总收益P则表示用户在中继链中参与共识所获的收益的总和,用于平衡用户间的收益,激发用户参与共识的热情,用户获得的历史总收益P越高,其在以后获得的共识的概率就越低;达成共识的用户除了获得打包权,还获得交易匹配权;中继链的用户想要参加共识,要先加入共识组,加入共识组的要求是信誉值Ri大于等于当前共识组的平均信誉值R。Further, the step S1 specifically includes: in step S1, the user first becomes a user of the relay chain before submitting cross-chain requirements, and each user on the relay chain has a reputation value R and a historical total income P, where the reputation value R reflects the integrity of the user's behavior in the relay chain. The user participates in the cross-chain transaction and consensus process according to the rules, and the reputation value R increases, otherwise it decreases; the reputation value R is used to influence the user's priority in submitting transaction requirements and the user's consensus. The probability of ; the historical total revenue P represents the sum of the benefits obtained by users participating in the consensus in the relay chain, which is used to balance the benefits among users and stimulate the enthusiasm of users to participate in the consensus. The higher the historical total revenue P obtained by users, the more The probability of obtaining a consensus in the future is lower; the users who reach a consensus not only get the packaging rights, but also the transaction matching rights; if the users of the relay chain want to participate in the consensus, they must first join the consensus group, and the requirement for joining the consensus group is the reputation value R i is greater than or equal to the average reputation value R of the current consensus group.

进一步,步骤S2中所述的交易匹配算法具体包括:引入用户权重和时间权重,交易需 求的格式为[CDid,CDnum,COid,COnum,Prior,Time],其中CDid为需求的兑换目的区块链,CDnum为兑换目的金额,COid为需求的兑换源区块链,COnum为兑换提供金额, Prior表示用户权重,Time表示时间权重;所有的待匹配交易共同组成交易需求集合P;使 用depth表示搜索深度。Further, the transaction matching algorithm described in step S2 specifically includes: introducing user weights and time weights, and the format of transaction requirements is [CDid, CDnum, COid, COnum, Prior, Time], wherein CDid is the blockchain for the exchange purpose of the demand , CDnum is the exchange purpose amount, COid is the demanded exchange source blockchain, COnum is the exchange amount provided, Prior indicates the user weight, Time indicates the time weight; all the transactions to be matched together form the transaction demand set P; use depth to indicate the search depth .

进一步,步骤S2所述的交易匹配算法包括以下步骤:Further, the transaction matching algorithm described in step S2 includes the following steps:

S211:从所有待匹配交易需求集合P中选出用户权重Prior和时间权重Time综合排序 最高的交易需求,作为此次匹配的目标需求O,所述时间权重Tme为交易需求等待周期数;S211: Select the transaction requirement with the highest comprehensive ranking of the user weight Prior and the time weight Time from all the transaction requirement sets P to be matched, as the target requirement O of this matching, and the time weight Tme is the transaction requirement waiting period number;

S212:根据目标需求O的目的区块链CDid搜索待匹配交易,找到所有源区块链COid为目标需求O目的区块链CDid的需求,并将搜索结果按用户权重Prior和时间权重Time综合排序;S212: Search the transactions to be matched according to the CDid of the destination blockchain of the target demand O, find all the source blockchain COids as the demand of the CDid of the destination blockchain of the target demand O, and comprehensively sort the search results according to the user weight Prior and the time weight Time ;

S213:在步骤S212的搜索结果中,从左往右寻找目的区块链CDid为目标需求O源区块链COid的交易需求,每找到一个符合要求的需求,累加其转入CDnum和转出金额 COnum,当和目标需求的金额匹配,则匹配成功,匹配成功后会根据匹配成功的跨链交易 中所有交易需求的用户权重Prior和时间权重Time给跨链交易打分;S213: In the search result of step S212, look for the target blockchain CDid from left to right as the target demand O source blockchain COid transaction demand, each time a demand that meets the requirements is found, accumulate its transfer CDnum and transfer amount COnum, when it matches the amount of the target demand, the match is successful. After the match is successful, the cross-chain transaction will be scored according to the user weight Prior and the time weight Time of all transaction requirements in the successfully matched cross-chain transaction;

S214:若步骤S213中没有匹配成功,针对目标需求O中剩余的未匹配金额继续进行匹 配;从步骤S212中搜索得到的交易需求列表中选取权重最大且未被步骤S213选中的交易需 求,以该交易需求的目的区块链CDid作为目标需求新的目的区块链,CDnum也变为与该需 求相同;目标需求的源区块链COid不变,但金额COnum变为剩余未匹配金额;回到步骤S212,搜索深度depth加一,重新进行搜索;设置最大搜索深度,当搜索深度depth大于最 大搜索深度,该轮匹配失败并返回。S214: If there is no successful matching in step S213, continue matching for the remaining unmatched amount in the target demand O; select the transaction demand with the largest weight and not selected in step S213 from the transaction demand list searched in step S212, and use this The destination blockchain CDid of the transaction demand is used as the new destination blockchain of the target demand, and CDnum also becomes the same as the demand; the source blockchain COid of the target demand remains unchanged, but the amount COnum becomes the remaining unmatched amount; go back to Step S212, the search depth depth is increased by one, and the search is performed again; the maximum search depth is set, and when the search depth depth is greater than the maximum search depth, this round of matching fails and returns.

进一步,所述步骤S1的共识阶段具体包括以下步骤:Further, the consensus stage of step S1 specifically includes the following steps:

S221:共识开始时,先计算共识组的平均收益P,记为:S221: At the beginning of the consensus, first calculate the average return P of the consensus group, which is recorded as:

Figure BDA0003494015220000031
Figure BDA0003494015220000031

其中,n为共识组中的用户总数,Pi为用户i的历史总收益;Among them, n is the total number of users in the consensus group, and P i is the historical total revenue of user i;

S222:根据历史总收益是否大于平均收益P,将共识组用户分为两组,G1和G2S222: According to whether the historical total return is greater than the average return P, divide the consensus group users into two groups, G 1 and G 2 :

G1={x∈G|fx≥P}G 1 ={x∈G|f x ≥P}

G2={y∈G|0<fy<P}G 2 ={y∈G|0<f y <P}

其中,G为所有共识组用户组成的集合;Among them, G is the set composed of all consensus group users;

S223:分别统计G1和G2的用户个数n1和n2以及用户i的信誉值占整个共识组所有用户总信誉值的比例,得出用户i被选为共识代表的概率:S223: Count the number of users n 1 and n 2 of G 1 and G 2 and the ratio of the reputation value of user i to the total reputation value of all users in the entire consensus group, and obtain the probability that user i is selected as the consensus representative:

Figure BDA0003494015220000032
Figure BDA0003494015220000032

其中,Ri为用户i的信誉值,Pi为用户i的历史总收益,n为共识组用户总数;Among them, Ri is the reputation value of user i , Pi is the historical total revenue of user i , and n is the total number of users in the consensus group;

S224:用户被选为共识用户后,获得下一周期的打包权和交易匹配权;共识用户打包当 前周期用户提交的交易需求,并调用匹配算法进行交易匹配,从中获取相应交易需求的佣金 和信誉值提升奖励;交易匹配成功后,将匹配信息分发给相应用户。S224: After the user is selected as the consensus user, the user obtains the packaging rights and transaction matching rights for the next cycle; the consensus user packages the transaction requirements submitted by the user in the current cycle, and invokes the matching algorithm to perform transaction matching, from which the commission and reputation of the corresponding transaction requirements are obtained. Value promotion reward; after the transaction is successfully matched, the matching information will be distributed to the corresponding users.

进一步,步骤S3具体包括以下步骤:Further, step S3 specifically includes the following steps:

S31:所有参与链中的子标志智能合约都已提交后,每条链中的参与跨链的用户根据匹 配结果提交相关的具体子事务,并以子标志智能合约的状态作为子事务智能合约的触发依 据;提交完毕后,与子标志智能合约协调,子标志智能合约会保存所有当前链中跨链子事务 的block id和transaction id,而跨链子事务保存所处链的标志智能合约的block id和 transaction id;S31: After all the sub-flag smart contracts in the participating chains have been submitted, the users participating in the cross-chain in each chain submit the relevant specific sub-transactions according to the matching results, and use the status of the sub-flag smart contracts as the sub-transaction smart contracts. Trigger basis; after the submission is completed, coordinate with the sub-flag smart contract, the sub-flag smart contract will save the block id and transaction id of all cross-chain sub-transactions in the current chain, and the cross-chain sub-transaction will save the block id and transaction id;

S32:子标志智能合约会验证所处链上本次跨链事务的跨链子事务是否已提交且信息正 确,如果均无误,向中继链上的跨链事务实例同步状态为Ready;若有用户想中止交易,在 向子标志智能合约发起中断请求后,子标志智能合约会向中继链上的跨链事务实例同步状态 为Abort;S32: The sub-flag smart contract will verify whether the cross-chain sub-transaction of the current cross-chain transaction on the chain where it is located has been submitted and the information is correct. If both are correct, the synchronization status to the cross-chain transaction instance on the relay chain is Ready; if there is a user If you want to abort the transaction, after sending an interrupt request to the sub-flag smart contract, the sub-flag smart contract will synchronize the status of Abort to the cross-chain transaction instance on the relay chain;

S33:跨链事务实例检测所有子标志智能合约的状态,当所有子标志智能合约的状态都 为Ready,向所有子标志智能合约发送状态转移指令,将状态转为Commit,各链中的跨链 子事务在检测到子标志智能合约的状态变为Commit后,自动触发交易;若有子标志智能合 约的状态变为Abort,向所有子标志智能合约发送状态转移指令,将状态转为Abort,各链 中的跨链子事务在检测到子标志智能合约的状态变为Abort后,自动中止交易。S33: The cross-chain transaction instance detects the status of all sub-flag smart contracts. When the status of all sub-flag smart contracts is Ready, a state transfer instruction is sent to all sub-flag smart contracts, and the state is converted to Commit. After the transaction detects that the status of the sub-flag smart contract changes to Commit, the transaction is automatically triggered; if the status of any sub-flag smart contract becomes Abort, it sends a state transfer instruction to all sub-flag smart contracts to change the status to Abort, and each chain The cross-chain sub-transaction in the token automatically aborts the transaction after detecting that the status of the sub-flag smart contract has changed to Abort.

进一步,步骤S4具体包括以下步骤:Further, step S4 specifically includes the following steps:

S41:跨链事务实例定时检测它所记录的所有子标志智能合约的状态,当所有子标志智 能合约的状态都为Ready,向所有子标志智能合约发送状态转移指令,将状态转为Commit,各链中的跨链子事务在检测到子标志智能合约的状态变为Commit后,自动触发交易,将锁定在智能合约中的虚拟货币转到对相应的账户;S41: The cross-chain transaction instance regularly detects the status of all sub-flag smart contracts recorded by it. When the status of all sub-flag smart contracts is Ready, a state transfer instruction is sent to all sub-flag smart contracts, and the status is changed to Commit. The cross-chain sub-transaction in the chain will automatically trigger the transaction after detecting that the status of the sub-flag smart contract has changed to Commit, and transfer the virtual currency locked in the smart contract to the corresponding account;

S42:若有子标志智能合约的状态变为Abort,向所有子标志智能合约发送状态转移指 令,将状态转为Abort,各链中的跨链子事务在检测到子标志智能合约的状态变为Abort 后,自动中止交易;若收到了子标志智能合约发来的交易信息错误,跨链事务实例会记录交 易信息错误的用户,降低其信誉值作为惩罚,并中止交易,向所有子标志智能合约发送状态 转移指令,将状态转为Abort;跨链子事务在检测到子标志智能合约的状态为Abort后,中 断交易,将锁定的虚拟货币返回给相应用户。S42: If the status of any sub-flag smart contracts changes to Abort, send a state transfer instruction to all sub-flag smart contracts to change the state to Abort, and the cross-chain sub-transactions in each chain detect the status of the sub-flag smart contracts to Abort After that, the transaction is automatically terminated; if the wrong transaction information sent by the sub-flag smart contract is received, the cross-chain transaction instance will record the user with the wrong transaction information, reduce its reputation value as a penalty, and suspend the transaction and send it to all sub-flag smart contracts. The state transfer instruction changes the state to Abort; after the cross-chain sub-transaction detects that the state of the sub-flag smart contract is Abort, it interrupts the transaction and returns the locked virtual currency to the corresponding user.

本发明的有益效果在于:The beneficial effects of the present invention are:

(1)本发明针对跨链交易的交易匹配,设计了一种交易匹配算法,并根据此算法设计 了新的共识算法,最后基于此共识算法的设计了中继链方案。实现了跨链交易匹配、协调、 实现一体化的中继链跨链方法,同时将中继链的职责所在分散到各个参与链上,避免了过度 集中。(1) The present invention designs a transaction matching algorithm for the transaction matching of cross-chain transactions, and designs a new consensus algorithm according to this algorithm, and finally designs a relay chain scheme based on this consensus algorithm. The relay chain cross-chain method of matching, coordinating and realizing cross-chain transactions is realized, and at the same time, the responsibilities of the relay chain are distributed to each participating chain to avoid excessive concentration.

(2)本发明通过跨链事务实例、子标志智能合约和子跨链事务的三层设置,并通过分 层验证,在保证交易可靠性的同时,减少了中继链需要存储的数据,并且避免了过多的链间 通信。通过链内验证,链间同步状态进一步提升了跨链效率。(2) The present invention reduces the data that needs to be stored in the relay chain while ensuring the reliability of the transaction through the three-layer setting of cross-chain transaction instances, sub-sign smart contracts and sub-cross-chain transactions, and avoids Excessive interchain communication. Through in-chain verification, inter-chain synchronization status further improves cross-chain efficiency.

本发明的其他优点、目标和特征在某种程度上将在随后的说明书中进行阐述,并且在某 种程度上,基于对下文的考察研究对本领域技术人员而言将是显而易见的,或者可以从本发 明的实践中得到教导。本发明的目标和其他优点可以通过下面的说明书来实现和获得。Other advantages, objects, and features of the present invention will be set forth in the description that follows, and will be apparent to those skilled in the art based on a study of the following, to the extent that is taught in the practice of the present invention. The objectives and other advantages of the present invention may be realized and attained by the following description.

附图说明Description of drawings

为了使本发明的目的、技术方案和优点更加清楚,下面将结合附图对本发明作优选的详 细描述,其中:In order to make the purpose, technical scheme and advantages of the present invention clearer, the present invention will be preferably described in detail below in conjunction with the accompanying drawings, wherein:

图1为本发明实施例中子标志智能合约状态转移图;1 is a state transition diagram of a neutron token smart contract according to an embodiment of the present invention;

图2为本发明实施例中一种基于交易匹配共识的中继链的跨链方法流程图;FIG. 2 is a flowchart of a cross-chain method for relay chains based on transaction matching consensus in an embodiment of the present invention;

图3为本发明实施例中跨链事务协调阶段的时序图;3 is a sequence diagram of a cross-chain transaction coordination phase in an embodiment of the present invention;

图4为本发明实施例中跨链交易需求匹配流程图;FIG. 4 is a flowchart of cross-chain transaction demand matching in an embodiment of the present invention;

图5为本发明实施例中跨链交易需求匹配的实例示意图。FIG. 5 is a schematic diagram of an example of cross-chain transaction requirement matching in an embodiment of the present invention.

具体实施方式Detailed ways

以下通过特定的具体实例说明本发明的实施方式,本领域技术人员可由本说明书所揭露 的内容轻易地了解本发明的其他优点与功效。本发明还可以通过另外不同的具体实施方式加 以实施或应用,本说明书中的各项细节也可以基于不同观点与应用,在没有背离本发明的精 神下进行各种修饰或改变。需要说明的是,以下实施例中所提供的图示仅以示意方式说明本 发明的基本构想,在不冲突的情况下,以下实施例及实施例中的特征可以相互组合。The embodiments of the present invention are described below through specific specific examples, and those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the drawings provided in the following embodiments are only used to illustrate the basic idea of the present invention in a schematic manner, and the following embodiments and features in the embodiments can be combined with each other without conflict.

其中,附图仅用于示例性说明,表示的仅是示意图,而非实物图,不能理解为对本发明 的限制;为了更好地说明本发明的实施例,附图某些部件会有省略、放大或缩小,并不代表 实际产品的尺寸;对本领域技术人员来说,附图中某些公知结构及其说明可能省略是可以理 解的。Among them, the accompanying drawings are only used for exemplary description, and represent only schematic diagrams, not physical drawings, and should not be construed as limitations of the present invention; in order to better illustrate the embodiments of the present invention, some parts of the accompanying drawings will be omitted, The enlargement or reduction does not represent the size of the actual product; it is understandable to those skilled in the art that some well-known structures and their descriptions in the accompanying drawings may be omitted.

本发明实施例的附图中相同或相似的标号对应相同或相似的部件;在本发明的描述中, 需要理解的是,若有术语“上”、“下”、“左”、“右”、“前”、“后”等指示的方位或 位置关系为基于附图所示的方位或位置关系,仅是为了便于描述本发明和简化描述,而不是 指示或暗示所指的装置或元件必须具有特定的方位、以特定的方位构造和操作,因此附图中 描述位置关系的用语仅用于示例性说明,不能理解为对本发明的限制,对于本领域的普通技术人员而言,可以根据具体情况理解上述术语的具体含义。The same or similar numbers in the drawings of the embodiments of the present invention correspond to the same or similar components; in the description of the present invention, it should be understood that if there are terms "upper", "lower", "left" and "right" , "front", "rear" and other indicated orientations or positional relationships are based on the orientations or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the indicated device or element must be It has a specific orientation, is constructed and operated in a specific orientation, so the terms describing the positional relationship in the accompanying drawings are only used for exemplary illustration, and should not be construed as a limitation of the present invention. situation to understand the specific meaning of the above terms.

本发明提供一种带优先级的跨链交易匹配算法。该算法区别于传统匹配论中的算法,跨 链交易匹配不同于以物换物,除了种类匹配,还需要满足金额匹配,且待匹配交易的兑换率 存在差异,还存在一对多和多对多的情况。该算法根据提交交易需求用户的优先级和交易需 求排队时间,对跨链交易进行差异化匹配,其中每项交易的存储格式为[CDid,CDnum,COid, COnum,Prior,Time],其中CDid为需求的兑换目的区块链,CDnum为兑换目的金额,COid 为需求的兑换源区块链,COnum为兑换提供金额,最后的Prior代表用户权重,Time代表时 间权重。所有的待匹配交易共同组成交易需求集合P。同时为了避免搜索深度过大,使用depth 表示搜索深度。匹配算法包括以下步骤:The invention provides a priority cross-chain transaction matching algorithm. This algorithm is different from the algorithm in traditional matching theory. Cross-chain transaction matching is different from barter. In addition to type matching, it is also necessary to meet the amount matching, and the exchange rates of the transactions to be matched are different, and there are also one-to-many and many-to-many pairs. many situations. The algorithm performs differential matching on cross-chain transactions according to the priority of users who submit transaction requirements and the queuing time of transaction requirements. The storage format of each transaction is [CDid, CDnum, COid, COnum, Prior, Time], where CDid is The required exchange destination blockchain, CDnum is the amount of the exchange purpose, COid is the demanded exchange source blockchain, COnum is the amount provided for the exchange, the last Prior represents the user weight, and Time represents the time weight. All the transactions to be matched together form the transaction demand set P. At the same time, in order to avoid the search depth being too large, use depth to represent the search depth. The matching algorithm includes the following steps:

S11:从所有待匹配交易需求集合P中选出用户权重Prior和时间权重Time(交易需求 等待周期数)综合排序最高的交易需求,作为此次匹配的目标需求O;S11: Select the transaction requirement with the highest comprehensive ranking of the user weight Prior and the time weight Time (the number of transaction requirement waiting cycles) from all the transaction requirement sets P to be matched, as the target requirement O for this matching;

S12:根据目标需求O的目的区块链CDid搜索待匹配交易,找到所有源区块链COid为 目标需求O目的区块链CDid的需求,并将搜索结果按用户权重Prior和时间权重Time综合 排序;S12: Search for the transactions to be matched according to the target blockchain CDid of the target demand O, find all the source blockchain COids that are the target blockchain CDid requirements of the target demand O, and comprehensively sort the search results according to the user weight Prior and the time weight Time ;

S13:在S12的搜索结果中,从左往右寻找目的区块链CDid为目标需求O源区块链COid 的交易需求,每找到一个符合要求的需求,累加其转入CDnum和转出金额COnum,当和目 标需求的金额匹配,则匹配成功,匹配成功后会根据匹配成功的跨链交易中所有交易需求的 用户权重Prior和时间权重Time给跨链交易打分;S13: In the search results of S12, look for the target blockchain CDid from left to right as the target demand O source blockchain COid transaction demand, each time you find a demand that meets the requirements, accumulate its transfer CDnum and transfer amount COnum , when it matches the amount of the target demand, the match is successful. After the match is successful, the cross-chain transaction will be scored according to the user weight Prior and the time weight Time of all transaction requirements in the successfully matched cross-chain transaction;

S14:若S13中没有匹配成功,针对目标需求O中剩余的未匹配金额继续进行匹配。从 S12中搜索得到的交易需求列表中选取权重最大且未被S13选中的交易需求,以该交易需求 的目的区块链CDid作为目标需求新的目的区块链,CDnum也变为与该需求相同。目标需求 的源区块链COid不变,但金额COnum变为剩余未匹配金额。回到S12,搜索深度depth加一,重新进行搜索。为了避免搜索深度过大导致效率下降,设置最大搜索深度为10,当搜索深度depth大于10,该轮匹配失败并返回。S14: If the matching is not successful in S13, continue matching for the remaining unmatched amount in the target demand O. Select the transaction requirement with the largest weight and not selected by S13 from the transaction requirement list searched in S12, and use the target blockchain CDid of the transaction requirement as the new target blockchain of the target requirement, and CDnum also becomes the same as the requirement. . The source blockchain COid of the target demand remains unchanged, but the amount COnum becomes the remaining unmatched amount. Back to S12, the search depth depth is increased by one, and the search is performed again. In order to avoid the efficiency drop caused by too large search depth, the maximum search depth is set to 10. When the search depth is greater than 10, this round of matching fails and returns.

本发明还提供一种中继链方案,为了协调跨链事务并供用户提交和匹配交易需求。用户 提交跨链需求,必须先成为中继链的用户,中继链上的每个用户都拥有信誉值R和历史总收 益P,其中信誉值R反映了用户在中继链行为的诚信程度,用户按照规则参与跨链事务和共 识过程,信誉值R就会增加,否则就会减少。信誉值R会影响用户提交交易需求的用户优先 级和用户获得共识的概率。历史总收益P则表示了用户在中继链中参与共识所获的收益的总 和,目的是平衡用户间的收益,激发用户参与共识的热情,用户获得的历史总收益P越高, 其在以后获得的共识的概率就会越低。该中继链方案将交易匹配算法融入共识之中,达成共 识的用户除了获得打包权,还会获得交易匹配权。中继链的用户想要参加共识,必须要先加 入共识组,加入共识组的要求是信誉值Ri需大于等于当前共识组的平均信誉值R。具体的共 识过程如下:The present invention also provides a relay chain scheme for coordinating cross-chain transactions and for users to submit and match transaction requirements. To submit cross-chain requirements, a user must first become a user of the relay chain. Each user on the relay chain has a reputation value R and a historical total revenue P, where the reputation value R reflects the integrity of the user's behavior in the relay chain. Users participate in cross-chain transactions and consensus processes according to the rules, and the reputation value R will increase, otherwise it will decrease. The reputation value R will affect the user's priority for submitting transaction requirements and the probability that users obtain consensus. The historical total revenue P represents the sum of the benefits obtained by the users participating in the consensus in the relay chain. The purpose is to balance the benefits among users and stimulate the enthusiasm of users to participate in the consensus. The probability of obtaining consensus will be lower. The relay chain scheme integrates the transaction matching algorithm into the consensus, and the users who reach the consensus will not only obtain the packaging rights, but also the transaction matching rights. If the users of the relay chain want to participate in the consensus, they must first join the consensus group. The requirement for joining the consensus group is that the reputation value R i must be greater than or equal to the average reputation value R of the current consensus group. The specific consensus process is as follows:

S21:共识开始时,先计算共识组的平均收益P,记为:S21: At the beginning of the consensus, first calculate the average return P of the consensus group, which is recorded as:

Figure BDA0003494015220000071
Figure BDA0003494015220000071

其中,n为共识组中的用户总数,Pi为用户i的历史总收益。Among them, n is the total number of users in the consensus group, and P i is the historical total revenue of user i.

S22:根据历史总收益是否大于平均收益P,将共识组用户分为两组,G1和G2S22: According to whether the historical total revenue is greater than the average revenue P, the consensus group users are divided into two groups, G 1 and G 2 :

G1={x∈G|fx≥P}G 1 ={x∈G|f x ≥P}

G2={y∈G|0<fy<P}G 2 ={y∈G|0<f y <P}

其中,G为所有共识组用户组成的集合。Among them, G is the set composed of all consensus group users.

S23:分别统计G1和G2的用户个数n1和n2以及用户i的信誉值占整个共识组所有用户 总信誉值的比例,就可以得出用户i被选为共识代表的概率:S23: Count the number of users n 1 and n 2 of G 1 and G 2 and the ratio of the reputation value of user i to the total reputation value of all users in the entire consensus group, so that the probability of user i being selected as the consensus representative can be obtained:

Figure BDA0003494015220000072
Figure BDA0003494015220000072

其中,Ri为用户i的信誉值,Pi为用户i的历史总收益,n为共识组用户总数。Among them, Ri is the reputation value of user i , Pi is the historical total revenue of user i , and n is the total number of users in the consensus group.

S24:用户被选为共识用户后,获得下一周期的打包权和交易匹配权。共识用户打包当前 周期用户提交的交易需求,并调用匹配算法进行交易匹配,从中获取相应交易需求的佣金和 信誉值提升奖励。交易匹配成功S24: After the user is selected as the consensus user, he will obtain the packaging rights and transaction matching rights for the next cycle. Consensus users package the transaction requirements submitted by users in the current cycle, and call the matching algorithm for transaction matching, from which they can obtain commissions and credit value promotion rewards for the corresponding transaction requirements. Transaction matching is successful

最后,本发明提供一种基于交易匹配共识中继链的跨链方法。该方案将交易匹配共识的 中继链作为协调跨链交易的中枢,通过中继链的方式,避免了集中化的问题,同时通过多级 验证的方式,避免了现有中继链方案中需要存储大量异构区块链头部信息用于验证,且消息 交换过于集中的问题。中继链上的用户不仅拥有中继链上的账户,还需要绑定具体参与跨链 的区块链账户,如以太坊等,通过这种方式实现链之间的初步连接。中继链需要存储的信息 包括,用户提交的交易需求信息、匹配成功的跨链交易信息和子标志智能合约信息。其中的 三层结构为:位于中继链上的跨链事务实例,整体协调跨链交易,与子标志智能合约交互, 并存储子标志智能合约的区块信息来验证交易;位于每条具体区块链上的子标志智能合约, 职责为协调并验证当前链内的跨链子交易;位于每条具体区块链上的跨链子事务,负责具体 的转账操作,根据子标志智能合约的状态执行操作。其中的子标志智能合约是连接跨链事务 实例和跨链子事务的桥梁,也是保证跨链交易事务性的关键,它通过在四种状态(Public、Ready、 Abort、Commit)间切换来协调跨链交易,保证原子性。最终形成了一个集交易提交、匹配、 协调于一体的跨链方法,且保证了可扩展性和较高效率。图1为本发明实施例中子标志智能 合约状态转移图,如图1所示,子标志智能合约一共有四个状态,分别是public,代表子标志 智能合约已上链。Abort,代表跨链交易已中止;Ready,代表当前子标志智能合约所处链内的 相关事务已完成,等待其他参与跨链的区块链状态变更;Commit,代表所有子标志智能合约 都完成,进入正式执行阶段。而这些状态间的转换关系有四种,如下:Finally, the present invention provides a cross-chain method based on transaction matching consensus relay chain. The scheme uses the relay chain of transaction matching consensus as the center for coordinating cross-chain transactions. The problem of centralization is avoided by means of the relay chain. At the same time, the multi-level verification method avoids the need for existing relay chain schemes. A large amount of heterogeneous blockchain header information is stored for verification, and the message exchange is too centralized. Users on the relay chain not only have accounts on the relay chain, but also need to bind specific cross-chain blockchain accounts, such as Ethereum, etc., in this way to achieve the initial connection between the chains. The information that the relay chain needs to store includes the transaction demand information submitted by the user, the successfully matched cross-chain transaction information and the sub-flag smart contract information. The three-layer structure is: a cross-chain transaction instance located on the relay chain, which coordinates cross-chain transactions as a whole, interacts with the sub-flag smart contract, and stores the block information of the sub-flag smart contract to verify the transaction; it is located in each specific area. The sub-signature smart contract on the blockchain is responsible for coordinating and verifying cross-chain sub-transactions in the current chain; the cross-chain sub-transactions located on each specific blockchain are responsible for specific transfer operations and perform operations according to the status of the sub-signature smart contract . The sub-flag smart contract is a bridge connecting cross-chain transaction instances and cross-chain sub-transactions, and is also the key to ensuring cross-chain transaction transactionality. It coordinates cross-chain transactions by switching between four states (Public, Ready, Abort, Commit). Transactions are guaranteed to be atomic. Finally, a cross-chain method integrating transaction submission, matching and coordination is formed, and scalability and high efficiency are guaranteed. Figure 1 is a state transition diagram of the sub-flag smart contract according to the embodiment of the present invention. As shown in Figure 1, the sub-flag smart contract has a total of four states, which are public respectively, indicating that the sub-flag smart contract has been on the chain. Abort, means that the cross-chain transaction has been aborted; Ready, means that the relevant transactions in the chain where the current sub-flag smart contract is located has been completed, waiting for the status change of other blockchains participating in the cross-chain; Commit, means that all sub-flag smart contracts are completed, into the formal implementation phase. There are four transition relationships between these states, as follows:

1.Public到Ready。子标志智能合约收到来自用户状态转换请求,并且检查当前区块链中 所有参与跨链的用户均已正确提交对应跨链交易后,从Public转换为Ready,并向中继层提 供状态;1.Public to Ready. The sub-flag smart contract receives the state transition request from the user, and checks that all users participating in the cross-chain in the current blockchain have correctly submitted the corresponding cross-chain transaction, then converts from Public to Ready, and provides the state to the relay layer;

2.Public到Abort。当前链中有用户请求中止或收到中继层发来的abort消息,子智能合 约收到后,状态从Public转为Abort;2.Public to Abort. In the current chain, there is a user request to abort or an abort message sent by the relay layer is received. After the child smart contract is received, the status changes from Public to Abort;

3.Ready到Abort。处于Ready的标志智能合约收到收到中继层发来的abort消息,代表 有用户中止了跨链交易,状态从Ready转为Abort;3.Ready to Abort. The smart contract marked as Ready receives the abort message from the relay layer, which means that a user has aborted the cross-chain transaction, and the status changes from Ready to Abort;

4.Ready到Commit。处于Ready的标志智能合约收到收到中继层发来的Commit消息, 代表所有跨链子事务都已提交并上链,状态从Ready转为Commit;4.Ready to Commit. The smart contract in the Ready flag receives the Commit message from the relay layer, which means that all cross-chain sub-transactions have been submitted and uploaded to the chain, and the status has changed from Ready to Commit;

图2为本发明实施例中一种基于交易匹配共识的中继链的跨链方法流程图。如图所示, 用户想要通过本发明提供的方法执行跨链操作时,必须在中继链上拥有一个账户,且该账户 绑定了用户想要进行跨链操作的其他相关链上的账户,如区块链,以太坊等,具体的绑定方 式为用户提供对应账户的公钥,中继链使用该公钥加密一条随机字符串并返回给用户,若用 户能解密该字符串则绑定成功,否则失败。通过这种方式初步实现了不同链之间的关联,随 后跨链事务的相关操作均以该账户为主体。FIG. 2 is a flowchart of a relay chain cross-chain method based on transaction matching consensus in an embodiment of the present invention. As shown in the figure, when a user wants to perform a cross-chain operation through the method provided by the present invention, he must have an account on the relay chain, and the account is bound to the account on other relevant chains that the user wants to perform the cross-chain operation. , such as blockchain, Ethereum, etc. The specific binding method provides the user with the public key of the corresponding account. The relay chain uses the public key to encrypt a random string and returns it to the user. If the user can decrypt the string, it will be bound. success, otherwise fail. In this way, the association between different chains is initially realized, and subsequent operations related to cross-chain transactions are based on this account.

当进入交易提交匹配阶段,该阶段主要与中继链的共识相关,涉及到交易需求信息和匹 配结果信息上链和交易的匹配。用户提交跨链交易需求,提交内容包括源链、源地址、目的 链、目的地址、转出金额、转入金额。中继链收到用户提交的交易需求后,会在下一周期打 包交易需求并提交上链,具体负责打包的用户会在当前周期的共识中选出。跨链交易的匹配 和交易需求打包需要中继链的共识算法完成,中继链通过共识算法选出共识代表,共识代表 获得打包权和交易匹配权。共识代表通过交易匹配算法匹配交易需求,并将匹配结果打包上 链,然后分发给匹配成功的交易需求的提交用户,随后正式进入跨链阶段。中继链上的用户, 可以通过参与共识赚取佣金并提升信誉值。中继链上的共识组的用户参与共识,当成功当选 为共识代表时,该用户会获得打包权和交易匹配权。通过交易匹配算法来匹配交易,当交易 匹配完成后,共识代表会为每一个匹配的跨链交易在中继链上生成一个协调跨链事务的标志 智能合约,即跨链事务实例,每个合约会生成唯一的ID用于标识此次跨链,并将匹配信息发 送给相应的匹配成功的用户,同时也会打包上链当前周期用户提交的交易需求。When entering the transaction submission matching stage, this stage is mainly related to the consensus of the relay chain, involving the matching of transaction demand information and matching result information on the chain and transactions. Users submit cross-chain transaction requirements, and the submitted content includes source chain, source address, destination chain, destination address, transfer amount, and transfer amount. After receiving the transaction request submitted by the user, the relay chain will package the transaction request in the next cycle and submit it to the chain. The specific user responsible for packaging will be selected in the consensus of the current cycle. The matching of cross-chain transactions and the packaging of transaction requirements need to be completed by the consensus algorithm of the relay chain. The relay chain selects a consensus representative through the consensus algorithm, and the consensus representative obtains the packaging rights and transaction matching rights. Consensus means matching the transaction requirements through the transaction matching algorithm, packaging the matching results on the chain, and then distributing them to the submitted users who have successfully matched the transaction requirements, and then officially enters the cross-chain stage. Users on the relay chain can earn commissions and increase their reputation by participating in consensus. The users of the consensus group on the relay chain participate in the consensus. When successfully elected as the consensus representative, the user will obtain the packaging rights and transaction matching rights. Transactions are matched through the transaction matching algorithm. When the transaction matching is completed, the consensus representative will generate a sign smart contract for coordinating cross-chain transactions on the relay chain for each matching cross-chain transaction, that is, a cross-chain transaction instance. Each contract A unique ID will be generated to identify this cross-chain, and the matching information will be sent to the corresponding users who have successfully matched. At the same time, the transaction requirements submitted by users in the current cycle of the chain will also be packaged.

在达成共识且交易匹配成功后,进入准备阶段,准备阶段为协调阶段做前期的准备。中 继链会为所有匹配成功的跨链交易在中继链上生成一个跨链交易实例,用于协调该跨链交易, 同时会返回匹配成功的跨链交易给交易需求的提交账户,并为每条参与此次跨链的区块链指 定一个用户来提交链内的子标志智能合约用于协调每条链的子事务。当跨链交易实例和各子 标志智能合约都已提交上链,它们之间会进行状态同步,子标志智能合约会保存跨链事务实 例的ID,而跨链事务实例会保存所有子标志智能合约的block id和transaction id,并同步所 有子标志智能合约的状态为public。这一步的目的是,当子标志智能合约因为区块链分叉被 丢失时,跨链事务实例可以通过保存的信息快速验证。After a consensus is reached and the transaction is successfully matched, the preparation stage is entered, and the preparation stage makes preliminary preparations for the coordination stage. The relay chain will generate a cross-chain transaction instance on the relay chain for all successfully matched cross-chain transactions to coordinate the cross-chain transaction, and will return the successfully matched cross-chain transaction to the submission account of the transaction requirements, and provide Each blockchain participating in this cross-chain designates a user to submit the sub-signature smart contract within the chain to coordinate the sub-transactions of each chain. When the cross-chain transaction instance and each sub-flag smart contract have been submitted to the chain, state synchronization will be performed between them. The sub-flag smart contract will save the ID of the cross-chain transaction instance, and the cross-chain transaction instance will save all sub-flag smart contracts. The block id and transaction id, and synchronize the status of all sub-flag smart contracts to public. The purpose of this step is that when the sub-flag smart contract is lost due to the blockchain fork, the cross-chain transaction instance can be quickly verified by the saved information.

当有链中的子标志智能合约提交上链后,该链中的参与跨链的用户根据匹配结果提交相 关的具体子事务,并以子标志智能合约的状态作为子事务智能合约的触发依据,这一步各个 参与跨链的区块链并不强制同步进行,而是并行执行。提交完毕后,与子标志智能合约协调, 子标志智能合约会保存所有当前链中跨链子事务的block id和transactionid,而跨链子事务保 存所处链的标志智能合约的block id和transaction id。When the sub-flag smart contract in the chain is submitted to the chain, the users participating in the cross-chain in the chain submit the relevant specific sub-transactions according to the matching results, and use the status of the sub-flag smart contract as the trigger basis for the sub-transaction smart contract. In this step, each blockchain participating in the cross-chain is not forced to be synchronized, but executed in parallel. After the submission is completed, in coordination with the sub-flag smart contract, the sub-flag smart contract will save the block id and transaction id of all cross-chain sub-transactions in the current chain, and the cross-chain sub-transaction will save the block id and transaction id of the flag smart contract of the chain where it is located.

子标志智能合约会验证所处链上本次跨链事务的跨链子事务是否已提交且信息正确,如 果均无误,会向中继链上的跨链事务实例同步状态为Ready;若发现交易信息错误,则会向中 继链发送错误信息并中断交易,状态变为Abort;若有用户想中止交易,在向子标志智能合约 发起中断请求后,子标志智能合约会向中继链上的跨链事务实例同步状态为Abort。The sub-flag smart contract will verify whether the cross-chain sub-transaction of the current cross-chain transaction on the chain where it is located has been submitted and the information is correct. If all are correct, the synchronization status to the cross-chain transaction instance on the relay chain will be Ready; if transaction information is found If an error occurs, an error message will be sent to the relay chain and the transaction will be interrupted, and the status will change to Abort; if a user wants to abort the transaction, after an interruption request is sent to the sub-flag smart contract, the sub-flag smart contract will send an interrupt request to the cross-border on the relay chain. The synchronization state of the chain transaction instance is Abort.

准备阶段过后,正式进入到协调阶段,协调阶段涉及到跨链事务中具体的转账事宜。协 调阶段的流程如图3所示,跨链事务实例检测所有子标志智能合约的状态,当所有子标志智 能合约的状态都为Ready,向所有子标志智能合约发送状态转移指令,将状态转为Commit, 各链中的跨链子事务在检测到子标志智能合约的状态变为Commit后,会自动触发交易;若 有子标志智能合约的状态变为Abort,向所有子标志智能合约发送状态转移指令,将状态转为 Abort,各链中的跨链子事务在检测到子标志智能合约的状态变为Abort后,会自动中止交易。 若收到了子标志智能合约发来的交易信息错误,跨链事务实例会记录交易信息错误的用户, 降低其信誉值作为惩罚,并中止交易,向所有子标志智能合约发送状态转移指令,将状态转 为Abort。跨链子事务在检测到子标志智能合约的状态为Abort后,会中断交易,将锁定的虚 拟货币返回给相应用户。After the preparation stage, it officially enters the coordination stage, which involves specific transfer matters in cross-chain transactions. The process of the coordination phase is shown in Figure 3. The cross-chain transaction instance detects the status of all sub-flag smart contracts. When the status of all sub-flag smart contracts is Ready, a state transfer instruction is sent to all sub-flag smart contracts to change the state to Commit, the cross-chain sub-transaction in each chain will automatically trigger the transaction after detecting that the status of the sub-flag smart contract has changed to Commit; if the status of any sub-flag smart contract becomes Abort, it will send a state transfer instruction to all sub-flag smart contracts , change the status to Abort, and the cross-chain sub-transactions in each chain will automatically abort the transaction after detecting that the status of the sub-flag smart contract has changed to Abort. If the wrong transaction information sent by the sub-flag smart contract is received, the cross-chain transaction instance will record the user with wrong transaction information, reduce its reputation value as a penalty, and abort the transaction, send state transfer instructions to all sub-flag smart contracts, and transfer the state Convert to Abort. After the cross-chain sub-transaction detects that the status of the sub-flag smart contract is Abort, it will interrupt the transaction and return the locked virtual currency to the corresponding user.

图4为本发明实施例中跨链交易需求匹配流程图。如图所示,交易匹配开始时会对所有 已提交上链的跨链交易需求进行排序,排序的依据为提交需求用户的优先级Prior和交易需求 在链时间Time,从排序结果中选出优先级最大的交易需求即为本次交易匹配的目标需求O。 随后判断搜索深度depth是否大于10,这一步是为了提升搜索效率,搜索深度过大就说明匹 配成功的可能性较小。若搜索深度小于10,寻找所有源区块链COid为目标需求O的目的区 块链CDid的交易需求,并对搜索结果进行排序,从中选出目的区块链CDid等于目标需求源 COid区块链的交易需求,进行CDnum和COnum的金额匹配,如果金额匹配成功,则此次 交易匹配成功,否则,减去已匹配部分金额,继续匹配剩余金额。从上一步的搜索结果中, 选出排序最靠前且未被匹配的需求,更新目标需求O的目的区块链CDid为此需求的目的区 块链CDid,同时更新目标需求O的CDnum为此需求的CDnum,开始下一轮匹配。FIG. 4 is a flowchart of cross-chain transaction requirement matching in an embodiment of the present invention. As shown in the figure, at the beginning of transaction matching, all the cross-chain transaction requirements that have been submitted to the chain will be sorted. The sorting is based on the priority of the user submitting the requirements and the transaction requirements in the chain time Time, and the priority is selected from the sorting results. The largest transaction demand at the level is the target demand O matched by this transaction. Then judge whether the search depth depth is greater than 10. This step is to improve the search efficiency. If the search depth is too large, the possibility of successful matching is small. If the search depth is less than 10, find all the transaction requirements of the target blockchain CDid whose source blockchain COid is the target demand O, sort the search results, and select the target blockchain CDid equal to the target demand source COid blockchain If the amount matching is successful, the transaction matching is successful; otherwise, the matching amount is subtracted from the remaining amount and the remaining amount is continued. From the search results of the previous step, select the highest-ranked and unmatched requirements, update the target blockchain CDid of the target requirement O to the target blockchain CDid of this requirement, and update the CDnum of the target requirement O to this The required CDnum starts the next round of matching.

图5为本发明实施例中跨链交易需求匹配的实例示意图。交易需求的格式如图所示为六 元组[CDid,CDnum,COid,COnum,Prior,Time],其中CDid为需求的兑换目的区块链,CDnum 为兑换目的金额,COid为需求的兑换源区块链,COnum为兑换提供金额,最后的Prior代表 用户权重,Time代表时间权重。FIG. 5 is a schematic diagram of an example of cross-chain transaction requirement matching in an embodiment of the present invention. The format of the transaction requirement is shown in the figure as a six-tuple [CDid, CDnum, COid, COnum, Prior, Time], where CDid is the exchange destination blockchain of the demand, CDnum is the exchange destination amount, and COid is the exchange source area of the demand Blockchain, COnum provides the amount for exchange, the last Prior represents the user weight, and Time represents the time weight.

实例中目标需求O,目的为使用1BTC换取20ETH。首先以目标需求O的CDid BTC搜索所有待匹配交易需求中满足COid为BTC的交易需求,图中搜索结果为P1和P2,其中P1 和P2时间权重Time都为4,但P1的用户权重大于P2,所以P1在前。遍历搜索结果,查找 CDid和目标需求O的COid相同的交易需求,发现P1满足要求,随后比对P1和目标需求O 的CDnum和COnum,结果发现P1部分满足目标需求O,目标需求的CDnum和COnum更 新为0.5和10。继续搜索,发现没有满足CDid和目标需求O的COid相同的交易需求,于是 从搜索结果中选出第一个未被匹配的交易需求P2,P2的COnum刚好与目标需求O的CDnum 相同,此时目标需求O匹配完成,更新目标需求的CDid为P2的CDid ETC,CDnum为P2 的CDnum。得到新的目标需求O1,随后根据目标需求O1再进行一轮匹配,匹配深度变为 2,搜索得到P3和P4,其中P3和P4用户权重相同,但P3时间权重大于P4,所以P3在前。 P3和P4的CDid和COid满足要求,且CDnum和COnum和大于目标需求O2,此时匹配完 成,并在中继链上更新交易需求P4为[ETH,2,ETC,20,7,6]。In the example, the target demand is O, and the purpose is to exchange 1BTC for 20ETH. First, the CDid BTC of the target demand O is used to search all the transaction requirements to be matched that meet the transaction requirements whose COid is BTC. The search results in the figure are P1 and P2. The time weights of P1 and P2 are both 4, but the user weight of P1 is greater than that of P2. , so P1 comes first. Traverse the search results, find the transaction requirement with the same CDid and the COid of the target requirement O, find that P1 meets the requirements, then compare the CDnum and COnum of P1 and the target requirement O, and find that P1 partially meets the target requirement O, and the CDnum and COnum of the target requirement Updated for 0.5 and 10. Continue the search and find that there is no transaction requirement that meets the same transaction requirement as the COid of the target requirement O, so the first unmatched transaction requirement P2 is selected from the search results. The COnum of P2 is exactly the same as the CDnum of the target requirement O. At this time The target requirement O is matched, and the CDid of the updated target requirement is the CDid ETC of P2, and the CDnum is the CDnum of P2. A new target requirement O1 is obtained, and then another round of matching is performed according to the target requirement O1, the matching depth becomes 2, and the search results in P3 and P4, where the user weights of P3 and P4 are the same, but the time weight of P3 is greater than that of P4, so P3 comes first. The CDid and COid of P3 and P4 meet the requirements, and the sum of CDnum and COnum is greater than the target requirement O2. At this time, the matching is completed, and the transaction requirement P4 is updated on the relay chain to be [ETH, 2, ETC, 20, 7, 6].

最后说明的是,以上实施例仅用以说明本发明的技术方案而非限制,尽管参照较佳实施 例对本发明进行了详细说明,本领域的普通技术人员应当理解,可以对本发明的技术方案进 行修改或者等同替换,而不脱离本技术方案的宗旨和范围,其均应涵盖在本发明的权利要求 范围当中。Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit them. Although the present invention has been described in detail with reference to the preferred embodiments, those of ordinary skill in the art should understand that the technical solutions of the present invention can be Modifications or equivalent replacements, without departing from the spirit and scope of the technical solution, should all be included in the scope of the claims of the present invention.

Claims (7)

1. A block chain crossing interaction method based on a relay chain is characterized in that: the method comprises the following steps of matching transactions by using a transaction matching algorithm, coordinating transactions by using a relay chain, and verifying transactions by using intelligent contracts with sub-signs, and specifically comprises the following steps:
s1: a user joins a relay chain;
s2: the method comprises the steps that a relay chain user submits a transaction requirement, the transaction requirement is packaged and stored in a block on a relay chain, the user on the relay chain is matched through a transaction matching algorithm in a consensus algorithm, when cross-chain transaction matching is successful, a marked intelligent contract coordinating the cross-chain transaction at this time, namely a cross-chain transaction example, is generated on the relay chain, the contract generates a unique ID for identifying the cross-chain transaction at this time, and matching information is sent to the user successfully matched at this time;
s3: after matching is successful, entering a preparation stage, and preparing a relay chain and a block chain which specifically participates in chain crossing for the next actual chain crossing behavior;
s4: after all preparation works are finished, entering a coordination stage; the coordination phase is a specific execution process of the cross-chain transaction.
2. The relay chain-based inter-block chain interaction method according to claim 1, wherein: the step S1 specifically includes: in step S1, the user becomes the user of the relay chain first, and can submit the cross-chain requirement, and the relayEach user on the chain has a credit value R and a historical total profit P, wherein the credit value R reflects the integrity degree of the user in the relay chain behavior, the user participates in the cross-chain transaction and consensus process according to rules, the credit value R is increased, and otherwise, the credit value R is reduced; the reputation value R is used for influencing the user priority of the user submitting the transaction requirement and the probability of obtaining consensus by the user; the historical total profit P represents the sum of profits obtained by the users participating in the consensus in the relay chain, and is used for balancing the profits among the users and stimulating the enthusiasm of the users participating in the consensus, and the higher the historical total profit P is obtained by the users, the lower the probability of the consensus obtained by the users in the future is; the users who reach the consensus obtain the transaction matching right besides the packaging right; the users of the relay chain want to participate in the consensus, and need to join the consensus group first, and the requirement of joining the consensus group is the credit value RiAnd the average reputation value R is larger than or equal to the current consensus group.
3. The relay chain-based inter-block chain interaction method according to claim 1, wherein: the transaction matching algorithm in step S2 specifically includes: introducing user weight and Time weight, wherein the format of transaction requirements is [ CDid, CDnum, COid, COnum, Prior and Time ], wherein CDid is a required conversion destination block chain, CDnum is conversion destination amount, COid is a required conversion source block chain, COnum is conversion supply amount, Prior represents user weight, and Time represents Time weight; all transactions to be matched form a transaction requirement set P together; depth is used to represent the search depth.
4. The relay chain-based inter-block chain interaction method according to claim 3, wherein: the transaction matching algorithm of step S2 includes the following steps:
s211: selecting the transaction requirement with the highest comprehensive ranking of user weight Prior and Time weight Time from all the transaction requirement sets P to be matched as a target requirement O for the matching, wherein the Time weight Tme is the number of transaction requirement waiting cycles;
s212: searching the transaction to be matched according to the target block chain CDid of the target requirement O, finding out the requirement that all the source block chains COid are the target block chain CDid of the target requirement O, and comprehensively sequencing the search results according to the user weight Prior and the Time weight Time;
s213: in the search result of step S212, searching from left to right for a transaction requirement in which the target block chain CDid is the target requirement O source block chain COid, accumulating the transferred-in CDnum and the transferred-out amount of money cunm when finding a requirement meeting the requirement, matching successfully when matching with the amount of money of the target requirement, and scoring the cross-chain transaction according to the user weight Prior and the Time weight Time of all transaction requirements in the cross-chain transaction successfully matched;
s214: if the matching is not successful in the step S213, continuing to match the remaining unmatched money in the target requirement O; selecting the transaction requirement which has the largest weight and is not selected in the step S213 from the transaction requirement list searched in the step S212, and taking the destination block chain CDid of the transaction requirement as a new destination block chain of the target requirement, wherein CDnum is also the same as the requirement; the source block chain COid of the target demand is unchanged, but the amount COnum is changed into the remaining unmatched amount; returning to the step S212, adding one to the depth of search, and searching again; and setting the maximum search depth, and when the depth of the search is greater than the maximum search depth, failing the matching in the round and returning.
5. The relay chain-based inter-block chain interaction method according to claim 4, wherein: the consensus step of step S1 specifically includes the following steps:
s221: when the consensus starts, the average profit P of the consensus group is calculated and recorded as:
Figure FDA0003494015210000021
wherein n is the total number of users in the consensus group, PiThe historical total income of the user i;
s222: dividing users in the consensus group into two groups G according to whether the historical total income is greater than the average income P1And G2
G1={x∈G|fx≥P}
G2={y∈G|0<fy<P}
Wherein G is a set formed by all users in the consensus group;
s223: respectively count G1And G2Number of users n1And n2And the ratio of the reputation value of the user i to the total reputation value of all the users in the whole consensus group is obtained, and the probability that the user i is selected as the consensus representative is obtained:
Figure FDA0003494015210000022
wherein R isiIs the reputation value, P, of user iiThe historical total income of the user i is obtained, and n is the total number of the users in the consensus group;
s224: after the user is selected as a consensus user, obtaining the packing right and the transaction matching right of the next period; the consensus user packs the transaction requirements submitted by the users in the current period, and calls a matching algorithm to perform transaction matching, so as to obtain commission and reputation value promotion rewards of the corresponding transaction requirements; and after the transaction matching is successful, the matching information is distributed to the corresponding user.
6. The relay chain-based inter-block chain interaction method according to claim 1, wherein: step S3 specifically includes the following steps:
s31: after all sub-mark intelligent contracts participating in the chain are submitted, a user participating in the cross-chain in each chain submits related specific sub-transactions according to a matching result, and the state of the sub-mark intelligent contract is used as a triggering basis of the sub-transaction intelligent contract; after the submission is finished, coordinating with the intelligent contract with the sub-mark, wherein the intelligent contract with the sub-mark saves the block id and the transaction id of the cross-chain sub-transaction in all the current chains, and the cross-chain sub-transaction saves the block id and the transaction id of the intelligent contract marked in the chain in which the cross-chain sub-transaction is located;
s32: the intelligent contract with the sub-marks can verify whether the chain-crossing sub-transaction of the current chain-crossing transaction on the chain is submitted and the information is correct, and if the chain-crossing sub-transaction is not submitted and the information is correct, the synchronous state of the chain-crossing transaction to the relay chain is Ready; if a user wants to stop the transaction, after an interruption request is sent to the intelligent subconscriber contract, the synchronous state of the intelligent subconscriber contract to the cross-chain transaction instance on the relay chain is Abort;
s33: the cross-chain transaction example detects the states of all sub-mark intelligent contracts, when the states of all the sub-mark intelligent contracts are Ready, a state transfer instruction is sent to all the sub-mark intelligent contracts, the states are converted into Commit, and after the cross-chain sub-transactions in each chain detect that the states of the sub-mark intelligent contracts are changed into Commit, the transactions are automatically triggered; if the state of the intelligent contract with the sub-mark is changed into Abort, a state transition instruction is sent to all the intelligent contracts with the sub-mark, the state is changed into Abort, and after the chain-crossing sub-transactions in each chain detect that the state of the intelligent contract with the sub-mark is changed into Abort, the transaction is automatically stopped.
7. The method of claim 1, wherein the method comprises: step S4 specifically includes the following steps:
s41: the cross-chain transaction example regularly detects the states of all the sub-mark intelligent contracts recorded by the cross-chain transaction example, when the states of all the sub-mark intelligent contracts are Ready, a state transfer instruction is sent to all the sub-mark intelligent contracts, the states are converted into Commit, the cross-chain sub-transactions in each chain automatically trigger transactions after detecting that the states of the sub-mark intelligent contracts are changed into Commit, and the virtual money locked in the intelligent contracts is transferred to corresponding accounts;
s42: if the state of the intelligent contract with the sub-mark is changed into Abort, a state transfer instruction is sent to all the intelligent contracts with the sub-mark, the state is changed into Abort, and after chain-crossing sub-transactions in each chain detect that the state of the intelligent contract with the sub-mark is changed into Abort, the transaction is automatically stopped; if the transaction information sent by the intelligent sub-mark contract is wrong, the cross-chain transaction instance records the user with the wrong transaction information, reduces the credit value of the user as a punishment, stops the transaction, sends a state transfer instruction to all the intelligent sub-mark contracts and converts the state into an Abort; and after the cross-chain sub-transaction detects that the state of the sub-marker intelligent contract is Abort, interrupting the transaction and returning the locked virtual currency to the corresponding user.
CN202210112115.4A 2022-01-28 2022-01-28 A cross-blockchain interaction method based on relay chain Pending CN114493879A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210112115.4A CN114493879A (en) 2022-01-28 2022-01-28 A cross-blockchain interaction method based on relay chain

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210112115.4A CN114493879A (en) 2022-01-28 2022-01-28 A cross-blockchain interaction method based on relay chain

Publications (1)

Publication Number Publication Date
CN114493879A true CN114493879A (en) 2022-05-13

Family

ID=81479580

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210112115.4A Pending CN114493879A (en) 2022-01-28 2022-01-28 A cross-blockchain interaction method based on relay chain

Country Status (1)

Country Link
CN (1) CN114493879A (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114971629A (en) * 2022-05-23 2022-08-30 中国人民大学 Multi-heterogeneous-chain-oriented cross-chain system and cross-chain transaction incentive safety guarantee method
CN115309581A (en) * 2022-10-11 2022-11-08 人民法院信息技术服务中心 Heterogeneous block chain cross-chain transaction running state analysis method and device
CN115640357A (en) * 2022-10-13 2023-01-24 重庆邮电大学 A Notary Node Selection Method Based on Genetic Algorithm
CN117951217A (en) * 2022-10-20 2024-04-30 腾讯科技(深圳)有限公司 Cross-chain configuration method, device, equipment, system and medium based on multiple blockchains
US20240211940A1 (en) * 2020-08-06 2024-06-27 Citibank, N.A. Systems and methods for multi-entity blockchain-based event break prevention
US12417450B2 (en) 2020-08-06 2025-09-16 Citibank, N.A. Systems and methods for blockchain-based transaction break prevention

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107742210A (en) * 2017-10-13 2018-02-27 布比(北京)网络技术有限公司 A cross-chain transfer system and method between different blockchains
CN111754307A (en) * 2020-06-28 2020-10-09 铭数科技(青岛)有限公司 Multi-factor electricity transaction matching method and device based on blockchain
CN112491959A (en) * 2020-10-28 2021-03-12 杭州趣链科技有限公司 Cross-link resource exchange method, device and system based on relay link
CN112636930A (en) * 2020-12-31 2021-04-09 重庆邮电大学 Asset transaction method and system based on atomic exchange

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107742210A (en) * 2017-10-13 2018-02-27 布比(北京)网络技术有限公司 A cross-chain transfer system and method between different blockchains
CN111754307A (en) * 2020-06-28 2020-10-09 铭数科技(青岛)有限公司 Multi-factor electricity transaction matching method and device based on blockchain
CN112491959A (en) * 2020-10-28 2021-03-12 杭州趣链科技有限公司 Cross-link resource exchange method, device and system based on relay link
CN112636930A (en) * 2020-12-31 2021-04-09 重庆邮电大学 Asset transaction method and system based on atomic exchange

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20240211940A1 (en) * 2020-08-06 2024-06-27 Citibank, N.A. Systems and methods for multi-entity blockchain-based event break prevention
US12417450B2 (en) 2020-08-06 2025-09-16 Citibank, N.A. Systems and methods for blockchain-based transaction break prevention
CN114971629A (en) * 2022-05-23 2022-08-30 中国人民大学 Multi-heterogeneous-chain-oriented cross-chain system and cross-chain transaction incentive safety guarantee method
CN115309581A (en) * 2022-10-11 2022-11-08 人民法院信息技术服务中心 Heterogeneous block chain cross-chain transaction running state analysis method and device
CN115309581B (en) * 2022-10-11 2023-01-24 人民法院信息技术服务中心 A method and device for analyzing the running status of heterogeneous blockchain cross-chain transactions
CN115640357A (en) * 2022-10-13 2023-01-24 重庆邮电大学 A Notary Node Selection Method Based on Genetic Algorithm
CN117951217A (en) * 2022-10-20 2024-04-30 腾讯科技(深圳)有限公司 Cross-chain configuration method, device, equipment, system and medium based on multiple blockchains
CN117951217B (en) * 2022-10-20 2025-09-16 腾讯科技(深圳)有限公司 Cross-chain configuration method, device, equipment, system and medium based on multi-block chain

Similar Documents

Publication Publication Date Title
CN114493879A (en) A cross-blockchain interaction method based on relay chain
US11250518B2 (en) Method for secure ledger distribution and computer system using secure distributed ledger technology
Kwon et al. Cosmos whitepaper
TW201943250A (en) Cross-blockchain authentication method and apparatus, and electronic device
CN110689434A (en) Cross-block chain interaction method based on notary group
CN109949033A (en) Block chain-based secure transaction system and method
Zheng et al. Meepo: Multiple execution environments per organization in sharded consortium blockchain
TW201943235A (en) Cross-block chain authentication method and device, and electronic device
WO2018232493A1 (en) DOUBLE CHAIN BLOCK CHAINS NETWORK FOR REALIZING CHAIN TRANSACTIONS
CN120086900A (en) Computer-implemented systems and methods for managing transactions on a blockchain network
CN111612619A (en) A blockchain-based warehousing sharing platform and warehousing transaction method
CN109829824A (en) A kind of commodity transaction information sharing method based on block chain technology
CN111241590B (en) A database system, node and method
CN108924092A (en) Based on block chain can open arbitration distribution cloud storage method and system
CN110866753B (en) Third party settlement control method and device, electronic equipment and storage medium
KR20220088956A (en) Systems and methods for providing specialized proof of confidential knowledge
CN112581130B (en) A cross-chain transaction method based on multi-chain interconnection
CN110471931A (en) A kind of digital asset trade identity maintaining method based on transaction in assets chain
CN113448694A (en) Block chain consensus method for improving transaction processing capability
CN109523380A (en) Across chain method of commerce and device
KR20240022462A (en) Method and system for brokered cross-ledger stablecoin atomic swap using hashlock
CN116562875A (en) A Fast Off-Chain Transaction Method Based on State Channel
Ge et al. Shaduf++: Non-cycle and privacy-preserving payment channel rebalancing
Zhao et al. Safe and efficient delegated proof of stake consensus mechanism based on dynamic credit in electronic transaction
CN116415955A (en) Cross-chain transaction method and system based on combination of hash locking and notary

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载