实验环境
两条平行链-链A(2008)和链B(2009)
一条中继链
实验目的
通过orml-xcm打开链A和链B之间的hrmpchannel
前提准备
平行链代理账户需要一定的中继链token,所以需要在中级链通过xcmPallet.limitedReserveTransferAssets()向指定的平行链发送代币
下图例子
平行链代理账户,这是通过paraid生成的账户,他是确定的账户。
para-id=2115的平行链代理账户是:5Ec4AhNzgnZ7jXzsdUAEbGBWu2GNfwppYZdf6P1JqNq6BntW
OpenHRMP
开通HRMPchannel的步骤:
发送方平行链发送一个初始化开放通道请求。
接收方平行链接受请求。
两条链需要互相交替进行操作,因为hrmp是单向的,如果需要进行跨链资产转账就需要打开双向的hrmp通道。
下面通过链A为Sender,链B为Recipient,以打开链A->链B的Hrmpchannel为例
链ASender2008
1.在中继链构造hrmp.hrmpInitOpenChannel()的结构体,并获取encodedcalldata。
这里有三个参数
Recipient接收者的ParaId
proposeMaxCapacity也是个限制的值
proposeMaxMessageSizexcm消息的大小限制
其中proposeMaxCapacityproposeMaxMessageSize的值不能设置的太大,必须要比中继链规定的最大配比要小,要不然会出错。通过中继链ChainState下的configuration.activeConfig()方法查找这项约束。
2.回到平行链,通过sudo构造ormlXcm.sendAsSovereign()
ormlXcm.sendAsSovereign(??dest:?XcmVersionedMultiLocation??{????V1:?{??????parents:?1??????interior:?Here????}??}????message:?XcmVersionedXcm??{????V2:???????}??????{????????BuyExecution:?{??????????fees:?{????????????id:?{??????????????Concrete:?{????????????????parents:?0????????????????interior:?Here??????????????}????????????}????????????fun:?{??????????????Fungible:?40,000,000,000????????????}??????????}??????????weightLimit:?Unlimited????????}??????}??????{????????Transact:?{??????????originType:?Native??????????requireWeightAtMost:?1,000,000,000??????????call:?{????????????encoded:???????????}????????}??????}??????{????????DepositAsset:?{??????????assets:?{????????????Wild:?All??????????}??????????maxAssets:?1??????????beneficiary:?{????????????parents:?0????????????interior:?{??????????????X1:?{????????????????Parachain:???????????????}????????????}??????????}????????}??????}????]??})
-hex-call>为上面我们构造的encodecalldata:0x1700d907000008000000e21f0000
为我们当前平行链的paraid:2008
交易成功之后,会在中继链执行encodecalldata的函数。
链BRecipient2009
1.在中继链构造hrmp.hrmpAcceptOpenChannel()的结构体,并获取encodedcalldata。
其中参数中的sender为发送者的paraid,也就是对应链A的paraid
2.回到平行链,通过sudo构造ormlXcm.sendAsSovereign()
ormlXcm.sendAsSovereign(??dest:?XcmVersionedMultiLocation??{????V1:?{??????parents:?1??????interior:?Here????}??}????message:?XcmVersionedXcm??{????V2:???????}??????{????????BuyExecution:?{??????????fees:?{????????????id:?{??????????????Concrete:?{????????????????parents:?0????????????????interior:?Here??????????????}????????????}????????????fun:?{??????????????Fungible:?40,000,000,000????????????}??????????}??????????weightLimit:?Unlimited????????}??????}??????{????????Transact:?{??????????originType:?Native??????????requireWeightAtMost:?1,000,000,000??????????call:?{????????????encoded:???????????}????????}??????}??????{????????DepositAsset:?{??????????assets:?{????????????Wild:?All??????????}??????????maxAssets:?1??????????beneficiary:?{????????????parents:?0????????????interior:?{??????????????X1:?{????????????????Parachain:???????????????}????????????}??????????}????????}??????}????]??})
为上面我们构造的encodecalldata:0x1701d8070000
为我们当前平行链的paraid:2009
发起交易后,在中继链可以查看到执行成功的日志。
检查是否成功打开HRMPChannel
1.查看中继链存储hrmp.hrmpOpenChannelRequestList()
2.观察中继链页面中parachains的in/out内容
参考链接
OpenHRMPChannel:
https://wiki.acala.network/build/development-guide/composable-chains/open-hrmp-channel
来源:金色财经
郑重声明: 本文版权归原作者所有, 转载文章仅为传播更多信息之目的, 如作者信息标记有误, 请第一时间联系我们修改或删除, 多谢。