当前位置:网站首页>Substrate 跨链技术源码级探索: XCVM的概览
Substrate 跨链技术源码级探索: XCVM的概览
2022-06-30 15:48:00 【InfoQ】
前提: XCM消息格式和版本
Xcm<Call>enum#[scale_info(bounds(), skip_type_params(Call))]pub enum Xcm<Call> { //...snippets WithdrawAsset(MultiAssets), ReserveAssetDeposited(MultiAssets), ReceiveTeleportedAsset(MultiAssets), //...snippets}
Tuple Struct#[scale_info(bounds(), skip_type_params(Call))]pub struct Xcm<Call>(pub Vec<Instruction<Call>>);
Instruction<Call>version: u8
message: the message, 必须在version确定的情况下有效
Version: u8 = 2,message: Vec<Instruction>, 因此, 一个完整的XCM消息就是2 byte的版本标识+SCALE编码的XCVM指令序列
- 一个XCM的最终执行效果, 取决于两个
XCVM是否恰当地初始化两个寄存器:Original Programme表示消息 和Original Origin表示消息来源
XCVM寄存器
XCVMProgramme
Vec<Instruction>Original ProgrammeXCVMProgramme Counter
存放类型: u32初始值:0ProgrammeProgrammeError
存放类型: Option<(u32, Error)>初始值: NoneProgramme CounterError HandlerVec<Instruction>ProgrammeAppendix
存放类型: Vec<Instruction>Error HandlerProgrammeOrigin
存放类型: Option<MultiLocation>NoneHolding Register
存放类型: MultiAssetsunspent非持久化Surplus Weight
存放类型: u64初始值:0Refunded Weight
存放类型: u64初始值: 0作用: Surplus WeightXCMXCVM
基本执行流程
XCVMfetch-dispatchProgramme寄存器为空时, 停机
- 从
Programme中拿到Programme Counter索引值指向的指令
- 如果指令存在, 则执行该指令, 并检查执行结果:
- 如果没有错误, 代表执行成功, 则将
Programme Counter加1
- 若发生错误, 则
- 设置
Error寄存器的值(错误发生的索引和错误类型)
- 将
Programme Counter置为0
- 将
Programme的内容替换为Error Handler的内容, 并清空Error Handler
- 如果指令不存在, 则:
Programme Counter置为0
- 将
Programme的内容替换为Appendix Register的内容
- 将
Error Handler中内容的预估权重, 加到Surplus Weight中去
- 清空
Appendix Register和Error Handler
- 与普通的
fetch/dispatch机制不同的是,XCVM的执行中有Error Handler和Appendix寄存器, 需要注意的是:
Error寄存器在程序执行完毕后不会被清空, 这样可以让Appendix寄存器可以使用Error中保留的值
- 无论程序执行成功与否,
Error Handler寄存器都会被清空, 这样保证前一个程序的错误处理逻辑不会影响后续的代码执行
注意
- 指令类型
Instruction是个标签联合类型(Rust中的enum), 每个指令由SCALE编码的以0为初始索引的指令列表中的位置+其操作构建而成, 需要注意
Origin术语在此处, 表示Origin寄存器中值代表的位置, 因此controlled by the Origin意思等同"由Origin寄存器中的值代表的地址控制
Holding术语表示Holding寄存器中的值, 因此reduce Holding by the asset等于"从Holding寄存器中减少资产
Appendix和Error Handler也是类似
on-chain术语, 应该理解为"在本地共识系统下的持久状态(within the persistent state of the local consensus system)", 不应该仅仅只当区块链的作为本地共识场景下对待.
Compact,Weight和QueryId类型应该理解为SCALE中定义的压缩整数类型
边栏推荐
- Anaconda下安装Jupyter notebook
- Headhunter 50, 000, I'll go to VC
- Interpretation of gaussdb's innovative features: partial result cache accelerates operators by caching intermediate results
- Etcd tutorial - Chapter 9 etcd implementation of distributed locks
- More dragon lizard self-developed features! Production available Anolis OS 8.6 officially released
- Talk about telecommuting | community essay solicitation
- Halcon knowledge: matrix topic [02]
- 【Verilog基础】十进制负数的八进制、十六进制表示
- RT-Thread 堆区大小设置
- Cmakelists Basics
猜你喜欢

Wechat emoticons are written into the judgment, and the OK and bomb you send may become "testimony in court"

备战数学建模36-时间序列模型2
![[wechat applet] the hosting environment of the applet](/img/ee/0f1dee4a26eb62c2268484c1b59edf.png)
[wechat applet] the hosting environment of the applet

Niuke network: longest continuous subarray with positive product

云技能提升好伙伴,亚马逊云师兄今天正式营业

There are so many kinds of coupons. First distinguish them clearly and then collect the wool!

I implement "stack" with C I

微信表情符号写入判决书,你发的OK、炸弹都可能成为“呈堂证供”

After 15 years of working on 21 types of hardware, where is Google?

Anaconda下安装Jupyter notebook
随机推荐
Anaconda下安装Jupyter notebook
招标公告:深圳市财政局数据库异地灾备项目
Symantec electronic sprint technology innovation board: Tan Jian, the actual controller, is an American who plans to raise 620million yuan
restartProcessIfVisible的流程
STL tutorial 7-set, pair pair pair group and functor
Lambda expression_ Stream stream_ File class
go-micro教程 — 第一章 快速入门
Half year inventory of new consumption in 2022: the industry is cold, but these nine tracks still attract gold
Niuke.com: minimum cost of climbing stairs
2022蓝桥杯国赛B组-费用报销-(线性dp|状态dp)
Niuke: how many different binary search trees are there
CGR 21 (D,E,F)
Undistorted resize using pil
After 15 years of working on 21 types of hardware, where is Google?
Deep learning - (2) several common loss functions
Cesium-1.72 learning (add points, lines, cubes, etc.)
Halcon knowledge: regional topics [07]
POJ Project Summer
dart:字符串replace相关的方法解决替换字符
MicroBlaze serial port learning · 2