当前位置:网站首页>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中定义的压缩整数类型
边栏推荐
- RTP sending PS stream zero copy scheme
- BC1.2 PD协议
- I implement "stack" with C I
- 删除有序数组中的重复项 II[双指针--多情况统一]
- Rong Lianyun launched rphone based on Tongxin UOS to create a new ecology of localization contact center
- Multi terminal collaboration of Huawei accounts to create a better internet life
- Mathematical modeling for war preparation 35 time series prediction model
- Hundreds of lines of code to implement a JSON parser
- Niuke.com: minimum cost of climbing stairs
- 微信表情符号写入判决书,你发的OK、炸弹都可能成为“呈堂证供”
猜你喜欢

MC Instruction Decoder
![[machine learning] K-means clustering analysis](/img/5f/3199fbd4ff2129d3e4ea518812c9e9.png)
[machine learning] K-means clustering analysis

The meaning of linetypes enumeration values (line_4, line_8, line_aa) in opencv

异常类_日志框架

备战数学建模35-时间序列预测模型

Etcd教程 — 第八章 Etcd之Compact、Watch和Lease API

八大基本排序(详解)

Cesium-1.72 learning (add points, lines, cubes, etc.)

Exception class_ Log frame

华为帐号多端协同,打造美好互联生活
随机推荐
备战数学建模35-时间序列预测模型
[wechat applet] basic use of common components (view/scroll-view/wiper, text/rich-text, button/image)
Implementation of aut, a self-developed transport layer protocol for sound network -- dev for dev column
Deep learning - (2) several common loss functions
9:第三章:电商工程分析:4:【通用模块】;(待写……)
Arcmap操作系列:80平面转经纬度84
IndexSearch
Exception class_ Log frame
Eight basic sorting (detailed explanation)
容联云首发基于统信UOS的Rphone,打造国产化联络中心新生态
Etcd教程 — 第八章 Etcd之Compact、Watch和Lease API
Tutoriel etcd - chapitre 8 API compacte, Watch et lease pour etcd
[Verilog quick start of Niuke online question series] ~ bit splitting and operation
新茶饮“死去活来”,供应商却“盆满钵满”?
Interpretation of gaussdb's innovative features: partial result cache accelerates operators by caching intermediate results
restartProcessIfVisible的流程
Mysql8 error: error 1410 (42000): you are not allowed to create a user with grant solution
Carry two load balancing notes and find them in the future
2020蓝桥杯国赛B组-搬砖-(贪心排序+01背包)
Cmakelists Basics